r20410 by craig -

scribus-commit scribus-commit at lists.scribus.net
Sun Sep 20 21:55:23 UTC 2015


Author: craig
Date: Sun Sep 20 21:55:23 2015
New Revision: 20410

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20410
Log:
#12937: Add licence popup to Resource Manager, part 1

Added:
    trunk/Scribus/scribus/ui/resourcemanagerlicense.cpp   (with props)
    trunk/Scribus/scribus/ui/resourcemanagerlicense.h   (with props)
    trunk/Scribus/scribus/ui/resourcemanagerlicensebase.ui   (with props)
Modified:
    trunk/Scribus/scribus/CMakeLists.txt
    trunk/Scribus/scribus/ui/resourcemanager.cpp
    trunk/Scribus/scribus/ui/resourcemanager.h
    trunk/Scribus/scribus/ui/resourcemanagerbase.ui

Modified: trunk/Scribus/scribus/CMakeLists.txt
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20410&path=/trunk/Scribus/scribus/CMakeLists.txt
==============================================================================
--- trunk/Scribus/scribus/CMakeLists.txt	(original)
+++ trunk/Scribus/scribus/CMakeLists.txt	Sun Sep 20 21:55:23 2015
@@ -180,6 +180,7 @@
 	ui/replacecolors.ui
 	ui/replaceonecolor.ui
 	ui/resourcemanagerbase.ui
+	ui/resourcemanagerlicensebase.ui
 	ui/selectobjects.ui
 	ui/shortcutwidget.ui
 	ui/smcellstylewidget.ui
@@ -461,6 +462,7 @@
 	ui/replacecolors.h
 	ui/replaceonecolor.h
 	ui/resourcemanager.h
+	ui/resourcemanagerlicense.h
 	ui/rulermover.h
 	ui/scdockpalette.h
 	ui/scescapecatcher.h
@@ -920,6 +922,7 @@
 	ui/replacecolors.cpp
 	ui/replaceonecolor.cpp
 	ui/resourcemanager.cpp
+	ui/resourcemanagerlicense.cpp
 	ui/rulermover.cpp
 	ui/sccolorslider.cpp
 	ui/sccombobox.cpp

Modified: trunk/Scribus/scribus/ui/resourcemanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20410&path=/trunk/Scribus/scribus/ui/resourcemanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.cpp	(original)
+++ trunk/Scribus/scribus/ui/resourcemanager.cpp	Sun Sep 20 21:55:23 2015
@@ -33,6 +33,7 @@
 #include "downloadmanager/scdlmgr.h"
 #include "langmgr.h"
 #include "resourcemanager.h"
+#include "resourcemanagerlicense.h"
 #include "scpaths.h"
 #include "scribusapp.h"
 #include "third_party/zip/scribus_zip.h"
@@ -51,6 +52,7 @@
 
 	connect(categoryComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryChanged()));
 	connect(updateAvailableButton, SIGNAL(clicked()), this, SLOT(updateDownloadLists()));
+	connect(showLicenseButton, SIGNAL(clicked()), this, SLOT(showLicense()));
 	connect(downloadButton, SIGNAL(clicked()), this, SLOT(startDownload()));
 }
 
@@ -137,7 +139,7 @@
 
 	installedTableWidget->clear();
 	installedTableWidget->setRowCount(dictionaryMap.count());
-	installedTableWidget->setColumnCount(3);
+	installedTableWidget->setColumnCount(4);
 	installedTableWidget->setSortingEnabled(false);
 	QMapIterator<QString, QString> i(dictionaryMap);
 	int row=0;
@@ -156,10 +158,14 @@
 		 newItem3->setFlags(newItem1->flags());
 		 newItem3->setToolTip(i.value());
 		 installedTableWidget->setItem(row, column++, newItem3);
+		 QTableWidgetItem *newItem4 = new QTableWidgetItem(i.value());
+		 newItem4->setFlags(newItem1->flags());
+		 newItem4->setToolTip(i.value());
+		 installedTableWidget->setItem(row, column++, newItem4);
 		 ++row;
 	}
 	QStringList headers;
-	headers << tr("Language") << tr("Code") << tr("Location");
+	headers << tr("Language") << tr("Code") << tr("Location") << tr("Licence");
 	installedTableWidget->setHorizontalHeaderLabels(headers);
 	installedTableWidget->resizeColumnsToContents();
 	installedTableWidget->setSortingEnabled(true);
@@ -371,6 +377,106 @@
 		return;
 	}
 	availableTableWidget->setRowCount(dictList.count());
+	availableTableWidget->setColumnCount(5);
+	availableTableWidget->setSortingEnabled(false);
+	int row=0;
+	foreach(DownloadItem d, dictList)
+	{
+		int column=0;
+		//qDebug()<<d.version<<d.files<<d.url<<d.desc<<d.license;
+		QTableWidgetItem *newItem1 = new QTableWidgetItem(d.desc);
+		newItem1->setFlags(newItem1->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
+		availableTableWidget->setItem(row, column++, newItem1);
+		QTableWidgetItem *newItem2 = new QTableWidgetItem(d.lang);
+		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("Language") << tr("Code") << tr("Installed") << tr("License") << tr("Download");
+	availableTableWidget->setHorizontalHeaderLabels(headers);
+	availableTableWidget->resizeColumnsToContents();
+	availableTableWidget->setSortingEnabled(true);
+	availableTableWidget->sortByColumn(0, Qt::AscendingOrder);
+	downloadButton->setEnabled(true);
+}
+
+void ResourceManager::updateAvailableSpell()
+{
+	QFile dataFile(ScPaths::downloadDir() + dataFiles[RM_SPELL]);
+	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_SPELL]).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;
+	}
+	dictList.clear();
+	QDomElement docElem = doc.documentElement();
+	QDomNode n = docElem.firstChild();
+	while( !n.isNull() )
+	{
+		QDomElement e = n.toElement();
+		if( !e.isNull() )
+		{
+			if (e.tagName()=="dictionary")
+			{
+				if (e.hasAttribute("type") && e.hasAttribute("filetype"))
+				{
+					if (e.attribute("type")=="spell")
+					{
+						struct DownloadItem d;
+						d.desc=e.attribute("description");
+						d.download=false;
+						d.files=e.attribute("files");
+						d.extractfiles=e.attribute("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())
+							dictList.append(d);
+						//else
+						//	qDebug()<<"hysettings : availDicts : invalid URL"<<d.url;
+					}
+				}
+			}
+		}
+		n = n.nextSibling();
+	}
+	availableTableWidget->clear();
+	if(dictList.isEmpty())
+	{
+		downloadButton->setEnabled(false);
+		return;
+	}
+	availableTableWidget->setRowCount(dictList.count());
 	availableTableWidget->setColumnCount(4);
 	availableTableWidget->setSortingEnabled(false);
 	int row=0;
@@ -403,106 +509,33 @@
 	downloadButton->setEnabled(true);
 }
 
-void ResourceManager::updateAvailableSpell()
-{
-	QFile dataFile(ScPaths::downloadDir() + dataFiles[RM_SPELL]);
-	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_SPELL]).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;
-	}
-	dictList.clear();
-	QDomElement docElem = doc.documentElement();
-	QDomNode n = docElem.firstChild();
-	while( !n.isNull() )
-	{
-		QDomElement e = n.toElement();
-		if( !e.isNull() )
-		{
-			if (e.tagName()=="dictionary")
-			{
-				if (e.hasAttribute("type") && e.hasAttribute("filetype"))
-				{
-					if (e.attribute("type")=="spell")
-					{
-						struct DownloadItem d;
-						d.desc=e.attribute("description");
-						d.download=false;
-						d.files=e.attribute("files");
-						d.extractfiles=e.attribute("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())
-							dictList.append(d);
-						//else
-						//	qDebug()<<"hysettings : availDicts : invalid URL"<<d.url;
-					}
-				}
-			}
-		}
-		n = n.nextSibling();
-	}
+void ResourceManager::updateAvailableTemplates()
+{
 	availableTableWidget->clear();
-	if(dictList.isEmpty())
-	{
-		downloadButton->setEnabled(false);
-		return;
-	}
-	availableTableWidget->setRowCount(dictList.count());
-	availableTableWidget->setColumnCount(4);
-	availableTableWidget->setSortingEnabled(false);
-	int row=0;
-	foreach(DownloadItem d, dictList)
-	{
-		int column=0;
-		//qDebug()<<d.version<<d.files<<d.url<<d.desc<<d.license;
-		QTableWidgetItem *newItem1 = new QTableWidgetItem(d.desc);
-		newItem1->setFlags(newItem1->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
-		availableTableWidget->setItem(row, column++, newItem1);
-		QTableWidgetItem *newItem2 = new QTableWidgetItem(d.lang);
-		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();
-		newItem4->setFlags(newItem1->flags());
-		newItem4->setCheckState(d.download ? Qt::Checked : Qt::Unchecked);
-		availableTableWidget->setItem(row, column++, newItem4);
-		++row;
-	}
-	QStringList headers;
-	headers << tr("Language") << tr("Code") << tr("Installed") << tr("Download");
-	availableTableWidget->setHorizontalHeaderLabels(headers);
-	availableTableWidget->resizeColumnsToContents();
-	availableTableWidget->setSortingEnabled(true);
-	availableTableWidget->sortByColumn(0, Qt::AscendingOrder);
-	downloadButton->setEnabled(true);
-}
-
-void ResourceManager::updateAvailableTemplates()
-{
-	availableTableWidget->clear();
+}
+
+QString ResourceManager::findDestinationFolder()
+{
+	QString destinationFolder;
+	int category = categoryComboBox->currentData().toInt();
+	switch (category)
+	{
+		case RM_FONTS:
+			destinationFolder=ScPaths::getUserFontDir(true);
+			break;
+		case RM_HYPH:
+			destinationFolder=ScPaths::getUserDictDir(ScPaths::Hyph, true);
+			break;
+		case RM_SPELL:
+			destinationFolder=ScPaths::getUserDictDir(ScPaths::Spell, true);
+			break;
+		case RM_TEMPLATES:
+			//temporary
+			destinationFolder=ScPaths::getTempFileDir();
+			//TODO!!!! destinationFolder=ScPaths::getUserDictDir(true);
+			break;
+	}
+	return destinationFolder;
 }
 
 void ResourceManager::categoryChanged()
@@ -674,7 +707,7 @@
 
 void ResourceManager::updateProgressBar()
 {
-	downloadProgressBar->setValue(downloadProgressBar->value()+1);
+	downloadProgressBar->setValue(downloadProgressBar->value() + 1);
 }
 
 void ResourceManager::startDownload()
@@ -683,9 +716,9 @@
 	QStringList filesToDownload;
 	for (int i=0; i<rows; ++i)
 	{
-		QTableWidgetItem *dlItem=availableTableWidget->item(i,3);
+		QTableWidgetItem *dlItem=availableTableWidget->item(i, 4);
 		if (dlItem->checkState()==Qt::Checked)
-			filesToDownload<<availableTableWidget->item(i,0)->text();
+			filesToDownload<<availableTableWidget->item(i, 0)->text();
 	}
 	if (filesToDownload.isEmpty())
 		return;
@@ -698,25 +731,8 @@
 	int dlCount=0;
 
 	//Set up destination
-	QString destinationFolder;
+	QString destinationFolder=findDestinationFolder();
 	int category = categoryComboBox->currentData().toInt();
-	switch (category)
-	{
-		case RM_FONTS:
-			destinationFolder=ScPaths::getUserFontDir(true);
-			break;
-		case RM_HYPH:
-			destinationFolder=ScPaths::getUserDictDir(ScPaths::Hyph, true);
-			break;
-		case RM_SPELL:
-			destinationFolder=ScPaths::getUserDictDir(ScPaths::Spell, true);
-			break;
-		case RM_TEMPLATES:
-			//temporary
-			destinationFolder=ScPaths::getTempFileDir();
-			//TODO!!!! destinationFolder=ScPaths::getUserDictDir(true);
-			break;
-	}
 	switch (category)
 	{
 		case RM_FONTS:
@@ -797,3 +813,76 @@
 	}
 }
 
+void ResourceManager::showLicense()
+{
+	bool localFile=false;
+	int rows=availableTableWidget->rowCount();
+	QString licenceFileName;
+	QString lang;
+	for (int i=0; i<rows; ++i)
+	{
+		QTableWidgetItem *dlItemI=availableTableWidget->item(i, 2);
+		QTableWidgetItem *dlItemL=availableTableWidget->item(i, 3);
+		localFile=dlItemI->checkState();
+		if (dlItemL->isSelected())
+		{
+			licenceFileName = dlItemL->text();
+			lang = availableTableWidget->item(i, 0)->text();
+			break;
+		}
+	}
+	if (!licenceFileName.isEmpty())
+	{
+		bool doDownload=true;
+		QString data;
+		//Set up destination
+		if (localFile)
+		{
+			QString destinationFolder=findDestinationFolder();
+			QFile dataFile(destinationFolder + licenceFileName);
+			QTextStream ts(&dataFile);
+			if (dataFile.exists())
+			{
+				dataFile.open(QIODevice::ReadOnly);
+				data = ts.readAll();
+				dataFile.close();
+				doDownload=false;
+			}
+		}
+		if (doDownload)
+		{
+			QStringList filesToDownload;
+			filesToDownload<<lang;
+			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(downloadFilesFinished()));
+						ScQApp->dlManager()->startDownloads();
+					}
+					sleep(10);
+					QFile dataFile(ScPaths::getTempFileDir() + licenceFileName);
+					QTextStream ts(&dataFile);
+					if (dataFile.exists())
+					{
+						dataFile.open(QIODevice::ReadOnly);
+						data = ts.readAll();
+						dataFile.close();
+						doDownload=false;
+					}
+				}
+			}
+		}
+		//temp fake return as data ihas not been downloaded
+		if (doDownload)
+			return;
+		ResourceManagerLicense* rml = new ResourceManagerLicense(parentWidget());
+		rml->setText(data);
+		if (rml->exec())
+			rml->deleteLater();
+	}
+}
+

Modified: trunk/Scribus/scribus/ui/resourcemanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20410&path=/trunk/Scribus/scribus/ui/resourcemanager.h
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.h	(original)
+++ trunk/Scribus/scribus/ui/resourcemanager.h	Sun Sep 20 21:55:23 2015
@@ -84,6 +84,7 @@
 		QList <DownloadItem> downloadList;
 		QString affixFileName(QStringList files);
 		QString dictFileName(QStringList files);
+		QString findDestinationFolder();
 
 	protected slots:
 		void categoryChanged();
@@ -92,6 +93,7 @@
 		void downloadFilesFinished();
 		void updateProgressBar();
 		void startDownload();
+		void showLicense();
 
 };
 

Modified: trunk/Scribus/scribus/ui/resourcemanagerbase.ui
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20410&path=/trunk/Scribus/scribus/ui/resourcemanagerbase.ui
==============================================================================
Binary files - no diff available.




More information about the scribus-commit mailing list