r21081 by craig -
scribus-commit
scribus-commit at lists.scribus.net
Sat Mar 12 23:04:54 UTC 2016
Author: craig
Date: Sat Mar 12 23:04:54 2016
New Revision: 21081
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21081
Log:
Allow user to download swatch files in Resource Manager
Modified:
trunk/Scribus/scribus/colorsetmanager.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
trunk/Scribus/scribus/scpaths.cpp
trunk/Scribus/scribus/scpaths.h
trunk/Scribus/scribus/ui/resourcemanager.cpp
trunk/Scribus/scribus/ui/resourcemanager.h
Modified: trunk/Scribus/scribus/colorsetmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21081&path=/trunk/Scribus/scribus/colorsetmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/colorsetmanager.cpp (original)
+++ trunk/Scribus/scribus/colorsetmanager.cpp Sat Mar 12 23:04:54 2016
@@ -222,7 +222,7 @@
void ColorSetManager::findUserPalettes(QTreeWidgetItem* parent)
{
userPalettes.clear();
- searchDir(ScPaths::getApplicationDataDir() + "swatches/", userPalettes, parent);
+ searchDir(ScPaths::getUserSwatchFilesDir(true), userPalettes, parent);
}
QStringList ColorSetManager::paletteNames()
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21081&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp Sat Mar 12 23:04:54 2016
@@ -2651,6 +2651,7 @@
case PageItem::Spiral:
case PageItem::Multiple:
case PageItem::Table:
+ case PageItem::NoteFrame:
Q_ASSERT(false);
break;
}
Modified: trunk/Scribus/scribus/scpaths.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21081&path=/trunk/Scribus/scribus/scpaths.cpp
==============================================================================
--- trunk/Scribus/scribus/scpaths.cpp (original)
+++ trunk/Scribus/scribus/scpaths.cpp Sat Mar 12 23:04:54 2016
@@ -529,35 +529,46 @@
dictSuffix = "hyph/";
if (dictType == ScPaths::Spell)
dictSuffix = "spell/";
- QDir userDictDirectory(getApplicationDataDir() + "dicts/" + dictSuffix);
+ QDir useFilesDirectory(getApplicationDataDir() + "dicts/" + dictSuffix);
if(createIfNotExists)
{
- if (!userDictDirectory.exists())
- userDictDirectory.mkpath(userDictDirectory.absolutePath());
- }
- return userDictDirectory.absolutePath()+"/";
+ if (!useFilesDirectory.exists())
+ useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
+ }
+ return useFilesDirectory.absolutePath()+"/";
}
QString ScPaths::getUserFontDir(bool createIfNotExists)
{
- QDir userDictDirectory(getApplicationDataDir() + "fonts/");
+ QDir useFilesDirectory(getApplicationDataDir() + "fonts/");
if(createIfNotExists)
{
- if (!userDictDirectory.exists())
- userDictDirectory.mkpath(userDictDirectory.absolutePath());
- }
- return userDictDirectory.absolutePath()+"/";
+ if (!useFilesDirectory.exists())
+ useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
+ }
+ return useFilesDirectory.absolutePath()+"/";
}
QString ScPaths::getUserHelpFilesDir(bool createIfNotExists)
{
- QDir userHelpDocsDirectory(getApplicationDataDir() + "helpfiles/");
+ QDir useFilesDirectory(getApplicationDataDir() + "helpfiles/");
if(createIfNotExists)
{
- if (!userHelpDocsDirectory.exists())
- userHelpDocsDirectory.mkpath(userHelpDocsDirectory.absolutePath());
- }
- return userHelpDocsDirectory.absolutePath()+"/";
+ if (!useFilesDirectory.exists())
+ useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
+ }
+ return useFilesDirectory.absolutePath()+"/";
+}
+
+QString ScPaths::getUserSwatchFilesDir(bool createIfNotExists)
+{
+ QDir useFilesDirectory(getApplicationDataDir() + "swatches/");
+ if(createIfNotExists)
+ {
+ if (!useFilesDirectory.exists())
+ useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
+ }
+ return useFilesDirectory.absolutePath()+"/";
}
QString ScPaths::getUserDocumentDir(void)
Modified: trunk/Scribus/scribus/scpaths.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21081&path=/trunk/Scribus/scribus/scpaths.h
==============================================================================
--- trunk/Scribus/scribus/scpaths.h (original)
+++ trunk/Scribus/scribus/scpaths.h Sat Mar 12 23:04:54 2016
@@ -78,6 +78,8 @@
static QString getUserFontDir(bool createIfNotExists);
/** @brief Return path to application data dir for downloaded docs*/
static QString getUserHelpFilesDir(bool createIfNotExists);
+ /** @brief Return path to application data dir for downloaded swatches*/
+ static QString getUserSwatchFilesDir(bool createIfNotExists);
/** @brief Return path to image cache dir*/
static QString getImageCacheDir(void);
/** @brief Return path to plugin data dir*/
Modified: trunk/Scribus/scribus/ui/resourcemanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21081&path=/trunk/Scribus/scribus/ui/resourcemanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.cpp (original)
+++ trunk/Scribus/scribus/ui/resourcemanager.cpp Sat Mar 12 23:04:54 2016
@@ -76,6 +76,7 @@
resourceCategories.insert(RM_HYPH, tr("Hyphenation Dictionaries"));
resourceCategories.insert(RM_SPELL, tr("Spelling Dictionaries"));
resourceCategories.insert(RM_HELP, tr("Help Manuals"));
+ resourceCategories.insert(RM_SWATCHES, tr("Swatches"));
//resourceCategories.insert(RM_TEMPLATES, tr("Templates"));
//resourceCategories.insert(RM_PROFILES, tr("Color Profiles"));
// resourceCategories.insert(RM_TEST, tr("Test"));
@@ -85,6 +86,7 @@
dataFiles.insert(RM_HYPH, "scribus_hyph_dicts.xml");
dataFiles.insert(RM_SPELL, "scribus_spell_dicts.xml");
dataFiles.insert(RM_HELP, "scribus_help.xml");
+ dataFiles.insert(RM_SWATCHES, "scribus_swatches.xml");
//dataFiles.insert(RM_TEMPLATES, "scribus_templates.xml");
//dataFiles.insert(RM_PROFILES, "scribus_profiles.xml");
// dataFiles.insert(RM_TEST, "test.txt");
@@ -205,6 +207,12 @@
}
void ResourceManager::updateInstalledHelp()
+{
+ dictionaryMap.clear();
+ installedTableWidget->clear();
+}
+
+void ResourceManager::updateInstalledSwatches()
{
dictionaryMap.clear();
installedTableWidget->clear();
@@ -614,6 +622,103 @@
downloadButton->setEnabled(true);
}
+void ResourceManager::updateAvailableSwatches()
+{
+ QFile dataFile(ScPaths::downloadDir() + dataFiles[RM_SWATCHES]);
+ if (!dataFile.exists())
+ return;
+ dataFile.open(QIODevice::ReadOnly);
+ QTextStream ts(&dataFile);
+ ts.setCodec(QTextCodec::codecForName("UTF-8"));
+ QString errorMsg;
+ int eline;
+ int ecol;
+ QDomDocument doc( QString(dataFiles[RM_SWATCHES]).remove(".xml") );
+ QString data(ts.readAll());
+ dataFile.close();
+ if ( !doc.setContent( data, &errorMsg, &eline, &ecol ))
+ {
+ if (data.toLower().contains("404 not found"))
+ qDebug()<<"File not found on server";
+ else
+ qDebug()<<"Could not open file"<<dataFile.fileName();
+ return;
+ }
+ swatchList.clear();
+ QDomElement docElem = doc.documentElement();
+ QDomNode n = docElem.firstChild();
+ while( !n.isNull() )
+ {
+ QDomElement e = n.toElement();
+ if( !e.isNull() )
+ {
+ if (e.tagName()=="swatch")
+ {
+ if (e.hasAttribute("type") && e.hasAttribute("filetype"))
+ {
+ //if (e.attribute("type")=="scribusofficial")
+ {
+ struct DownloadItem d;
+ d.desc=e.attribute("description");
+ d.download=false;
+ d.files=e.attribute("files");
+ d.extractfiles="";
+ d.url=e.attribute("URL");
+ d.version=e.attribute("version");
+ d.lang=e.attribute("language");
+ d.license=e.attribute("license");
+ d.filetype=e.attribute("filetype");
+ d.type=e.attribute("type");
+ QUrl url(d.url);
+ if (url.isValid() && !url.isEmpty() && !url.host().isEmpty())
+ swatchList.append(d);
+ }
+ }
+ }
+ }
+ n = n.nextSibling();
+ }
+ availableTableWidget->clear();
+ if(swatchList.isEmpty())
+ {
+ downloadButton->setEnabled(false);
+ return;
+ }
+ availableTableWidget->setRowCount(swatchList.count());
+ availableTableWidget->setColumnCount(5);
+ availableTableWidget->setSortingEnabled(false);
+ int row=0;
+ foreach(DownloadItem d, swatchList)
+ {
+ int column=0;
+ QTableWidgetItem *newItem1 = new QTableWidgetItem(d.desc);
+ newItem1->setFlags(newItem1->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
+ availableTableWidget->setItem(row, column++, newItem1);
+ QTableWidgetItem *newItem2 = new QTableWidgetItem("");
+ newItem2->setFlags(newItem1->flags());
+ availableTableWidget->setItem(row, column++, newItem2);
+ QTableWidgetItem *newItem3 = new QTableWidgetItem();
+ newItem3->setCheckState(dictionaryMap.contains(d.lang) ? Qt::Checked : Qt::Unchecked);
+ newItem3->setFlags(newItem1->flags() & ~Qt::ItemIsUserCheckable);
+ availableTableWidget->setItem(row, column++, newItem3);
+ QTableWidgetItem *newItem4 = new QTableWidgetItem(d.license);
+ availableTableWidget->setItem(row, column++, newItem4);
+ newItem4->setFlags(newItem4->flags() & ~Qt::ItemIsEditable);
+ QTableWidgetItem *newItem5 = new QTableWidgetItem();
+ newItem5->setFlags(newItem1->flags());
+ newItem5->setCheckState(d.download ? Qt::Checked : Qt::Unchecked);
+ availableTableWidget->setItem(row, column++, newItem5);
+ ++row;
+ }
+ QStringList headers;
+ headers << tr("Description") << tr("") << tr("Installed") << tr("License") << tr("Download");
+ availableTableWidget->setHorizontalHeaderLabels(headers);
+ availableTableWidget->resizeColumnsToContents();
+ availableTableWidget->setSortingEnabled(true);
+ availableTableWidget->sortByColumn(0, Qt::AscendingOrder);
+ downloadButton->setEnabled(true);
+}
+
void ResourceManager::updateAvailableTest()
{
availableTableWidget->clear();
@@ -642,6 +747,9 @@
case RM_HELP:
destinationFolder=ScPaths::getUserHelpFilesDir(true);
break;
+ case RM_SWATCHES:
+ destinationFolder=ScPaths::getUserSwatchFilesDir(true);
+ break;
case RM_TEST:
destinationFolder=ScPaths::downloadDir();
break;
@@ -673,6 +781,10 @@
case RM_HELP:
updateInstalledHelp();
updateAvailableHelp();
+ break;
+ case RM_SWATCHES:
+ updateInstalledSwatches();
+ updateAvailableSwatches();
break;
case RM_TEST:
updateInstalledTest();
@@ -709,28 +821,39 @@
disconnect(ScQApp->dlManager(), SIGNAL(fileDownloadProgress(qint64, qint64)), this, SLOT(updateProgressData(qint64, qint64)));
int category = categoryComboBox->currentData().toInt();
+ bool fileOk=checkFileHash(ScPaths::downloadDir(), dataFiles[category], dataFiles[category] + ".sha256", QCryptographicHash::Sha256);
switch (category)
{
case RM_FONTS:
- updateAvailableFonts();
+ if (fileOk)
+ updateAvailableFonts();
break;
case RM_HYPH:
- updateAvailableHyph();
+ if (fileOk)
+ updateAvailableHyph();
break;
case RM_SPELL:
- updateAvailableSpell();
+ if (fileOk)
+ updateAvailableSpell();
break;
case RM_TEMPLATES:
- updateAvailableTemplates();
+ if (fileOk)
+ updateAvailableTemplates();
break;
case RM_HELP:
- if (checkFileHash(ScPaths::downloadDir(), dataFiles[RM_HELP], dataFiles[RM_HELP] + ".sha256", QCryptographicHash::Sha256))
+ if (fileOk)
updateAvailableHelp();
else
- qDebug()<<"Failure :(";
+ qDebug()<<"Help Failure :(";
+ break;
+ case RM_SWATCHES:
+ if (fileOk)
+ updateAvailableSwatches();
+ else
+ qDebug()<<"Swatch Failure :(";
break;
case RM_TEST:
- if (checkFileHash(ScPaths::downloadDir(), dataFiles[RM_TEST], dataFiles[RM_TEST] + ".sha256", QCryptographicHash::Sha256))
+ if (fileOk)
qDebug()<<"Success!!!";
else
qDebug()<<"Failure :(";
@@ -969,7 +1092,7 @@
int dlCount=0;
//Set up destination
- QString destinationFolder=findDestinationFolder();
+ QString destinationFolder(findDestinationFolder());
int category = categoryComboBox->currentData().toInt();
switch (category)
{
@@ -1060,6 +1183,28 @@
}
}
break;
+ case RM_SWATCHES:
+ foreach(DownloadItem d, swatchList)
+ {
+// qDebug()<<d.desc;
+ if (filesToDownload.contains(d.desc))
+ {
+ if (d.filetype=="zip")
+ {
+// qDebug()<<"zip type:"<<d.url<<d.files;
+ QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+ foreach (QString s, plainURLs)
+ {
+ ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder);
+ ScQApp->dlManager()->addURL(d.url+"/"+s+".sha256", true, ScPaths::downloadDir(), destinationFolder);
+ dlCount+=2;
+ }
+ downloadList.append(d);
+ d.download=true;
+ }
+ }
+ }
+ break;
default:
break;
}
@@ -1093,6 +1238,7 @@
break;
}
}
+ qDebug()<<lang<<licenceFileName;
if (!licenceFileName.isEmpty())
{
bool doDownload=true;
@@ -1117,19 +1263,42 @@
QStringList filesToDownload;
filesToDownload<<lang;
//There's only one here... foreach?
- foreach(DownloadItem d, dictList)
+ int category = categoryComboBox->currentData().toInt();
+ switch (category)
{
- if (filesToDownload.contains(d.desc))
- {
- if (d.filetype=="plain")
- {
- ScQApp->dlManager()->addURL(d.url+"/"+licenceFileName, true, ScPaths::downloadDir(), ScPaths::getTempFileDir());
- connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadLicenseFinished()));
- connect(ScQApp->dlManager(), SIGNAL(fileReceived(const QString&)), this, SLOT(downloadLicenseFileFinished(const QString&)));
- connect(ScQApp->dlManager(), SIGNAL(fileFailed(const QString&)), this, SLOT(downloadLicenseFileFailed(const QString&)));
- ScQApp->dlManager()->startDownloads();
- }
- }
+ case RM_HYPH:
+ case RM_SPELL:
+ foreach(DownloadItem d, dictList)
+ {
+ if (filesToDownload.contains(d.desc))
+ {
+ if (d.filetype=="plain")
+ {
+ ScQApp->dlManager()->addURL(d.url+"/"+licenceFileName, true, ScPaths::downloadDir(), ScPaths::getTempFileDir());
+ connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadLicenseFinished()));
+ connect(ScQApp->dlManager(), SIGNAL(fileReceived(const QString&)), this, SLOT(downloadLicenseFileFinished(const QString&)));
+ connect(ScQApp->dlManager(), SIGNAL(fileFailed(const QString&)), this, SLOT(downloadLicenseFileFailed(const QString&)));
+ ScQApp->dlManager()->startDownloads();
+ }
+ }
+ }
+ break;
+ case RM_SWATCHES:
+ foreach(DownloadItem d, swatchList)
+ {
+ if (filesToDownload.contains(d.desc))
+ {
+// if (d.filetype=="plain")
+ {
+ ScQApp->dlManager()->addURL(d.url+"/"+licenceFileName, true, ScPaths::downloadDir(), ScPaths::getTempFileDir());
+ connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadLicenseFinished()));
+ connect(ScQApp->dlManager(), SIGNAL(fileReceived(const QString&)), this, SLOT(downloadLicenseFileFinished(const QString&)));
+ connect(ScQApp->dlManager(), SIGNAL(fileFailed(const QString&)), this, SLOT(downloadLicenseFileFailed(const QString&)));
+ ScQApp->dlManager()->startDownloads();
+ }
+ }
+ }
+ break;
}
}
}
Modified: trunk/Scribus/scribus/ui/resourcemanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21081&path=/trunk/Scribus/scribus/ui/resourcemanager.h
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.h (original)
+++ trunk/Scribus/scribus/ui/resourcemanager.h Sat Mar 12 23:04:54 2016
@@ -46,6 +46,7 @@
RM_SPELL,
RM_TEMPLATES,
RM_HELP,
+ RM_SWATCHES,
RM_TEST=99
};
public:
@@ -64,6 +65,7 @@
void updateInstalledSpell();
void updateInstalledTemplates();
void updateInstalledHelp();
+ void updateInstalledSwatches();
void updateInstalledTest();
void updateAvailableFonts();
@@ -71,6 +73,7 @@
void updateAvailableSpell();
void updateAvailableTemplates();
void updateAvailableHelp();
+ void updateAvailableSwatches();
void updateAvailableTest();
QString currentCategory;
@@ -83,6 +86,7 @@
QList <DownloadItem> fontList;
QList <DownloadItem> templateList;
QList <DownloadItem> helpList;
+ QList <DownloadItem> swatchList;
QList <DownloadItem> profileList;
QList <DownloadItem> downloadList;
QList <DownloadItem> testList;
More information about the scribus-commit
mailing list