r21368 by craig -

scribus-commit scribus-commit at lists.scribus.net
Mon Jun 6 20:29:22 UTC 2016


Author: craig
Date: Mon Jun  6 20:29:22 2016
New Revision: 21368

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21368
Log:
Fix downloaded font detection in Resource Manager

Modified:
    trunk/Scribus/scribus/ui/resourcemanager.cpp
    trunk/Scribus/scribus/ui/resourcemanager.h

Modified: trunk/Scribus/scribus/ui/resourcemanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21368&path=/trunk/Scribus/scribus/ui/resourcemanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.cpp	(original)
+++ trunk/Scribus/scribus/ui/resourcemanager.cpp	Mon Jun  6 20:29:22 2016
@@ -104,6 +104,65 @@
 		categoryComboBox->addItem(i.value(), i.key());
 	}
 	categoryChanged();
+}
+
+void ResourceManager::readAvailableFonts()
+{
+	QFile dataFile(ScPaths::downloadDir() + dataFiles[RM_FONTS]);
+	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( dataFiles[RM_FONTS] );
+	QString data(ts.readAll());
+	dataFile.close();
+	if ( !doc.setContent( data, &errorMsg, &eline, &ecol ))
+	{
+//		qDebug()<<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;
+	}
+	availableList.clear();
+	QDomElement docElem = doc.documentElement();
+	QDomNode n = docElem.firstChild();
+	while( !n.isNull() )
+	{
+		QDomElement e = n.toElement();
+		if( !e.isNull() )
+		{
+			if (e.tagName()=="font")
+			{
+				if (e.hasAttribute("type") && e.hasAttribute("filetype"))
+				{
+					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.movetofile=e.attribute("movetofilename");
+					d.type=e.attribute("type").toUpper();
+					QUrl url(d.url);
+					if (url.isValid() && !url.isEmpty() && !url.host().isEmpty())
+						availableList.append(d);
+//					else
+//						qDebug()<<"rm : availFonts : invalid URL"<<d.url;
+				}
+			}
+		}
+		n = n.nextSibling();
+	}
 }
 
 void ResourceManager::readAvailableHelp()
@@ -225,10 +284,44 @@
 
 void ResourceManager::updateInstalledFonts()
 {
+	dictionaryMap.clear();
+	QString fontDir(findDestinationFolder());
+	foreach(DownloadItem d, availableList)
+	{
+		if (d.filetype!="zip")
+		{
+			if (QFileInfo::exists(fontDir+d.files))
+				dictionaryMap.insert(d.desc, fontDir+d.files);
+		}
+		else
+		{
+			QFileInfo zfi(d.files);
+			if (QFileInfo::exists(fontDir+zfi.baseName()))
+				dictionaryMap.insert(d.desc, fontDir+zfi.baseName());
+		}
+	}
+
 	installedTableWidget->clear();
+	installedTableWidget->setRowCount(dictionaryMap.count());
+	installedTableWidget->setColumnCount(2);
 	installedTableWidget->setSortingEnabled(false);
+
+	QMapIterator<QString, QString> i(dictionaryMap);
+	int row=0;
+	while (i.hasNext())
+	{
+		i.next();
+		int column=0;
+		QTableWidgetItem *newItem1 = new QTableWidgetItem(i.key());
+		newItem1->setFlags(newItem1->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
+		installedTableWidget->setItem(row, column++, newItem1);
+		QTableWidgetItem *newItem2 = new QTableWidgetItem(i.value());
+		newItem2->setFlags(newItem1->flags());
+		installedTableWidget->setItem(row, column++, newItem2);
+		++row;
+	}
 	QStringList headers;
-	headers << tr("Description") << tr("Type") << tr("Installed") << tr("Download");
+	headers << tr("Description") << tr("Location") ;
 	installedTableWidget->setHorizontalHeaderLabels(headers);
 	installedTableWidget->resizeColumnsToContents();
 	installedTableWidget->setSortingEnabled(true);
@@ -393,7 +486,6 @@
 	QStringList headers;
 	headers << tr("Description") << tr("Location") ;
 	installedTableWidget->setHorizontalHeaderLabels(headers);
-
 	installedTableWidget->resizeColumnsToContents();
 	installedTableWidget->setSortingEnabled(true);
 	installedTableWidget->sortByColumn(0, Qt::AscendingOrder);
@@ -407,61 +499,7 @@
 
 void ResourceManager::updateAvailableFonts()
 {
-	QFile dataFile(ScPaths::downloadDir() + dataFiles[RM_FONTS]);
-	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( dataFiles[RM_FONTS] );
-	QString data(ts.readAll());
-	dataFile.close();
-	if ( !doc.setContent( data, &errorMsg, &eline, &ecol ))
-	{
-//		qDebug()<<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;
-	}
-	availableList.clear();
-	QDomElement docElem = doc.documentElement();
-	QDomNode n = docElem.firstChild();
-	while( !n.isNull() )
-	{
-		QDomElement e = n.toElement();
-		if( !e.isNull() )
-		{
-			if (e.tagName()=="font")
-			{
-				if (e.hasAttribute("type") && e.hasAttribute("filetype"))
-				{
-					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.movetofile=e.attribute("movetofilename");
-					d.type=e.attribute("type").toUpper();
-					QUrl url(d.url);
-					if (url.isValid() && !url.isEmpty() && !url.host().isEmpty())
-						availableList.append(d);
-//					else
-//						qDebug()<<"rm : availFonts : invalid URL"<<d.url;
-				}
-			}
-		}
-		n = n.nextSibling();
-	}
+
 	availableTableWidget->clear();
 	if(availableList.isEmpty())
 	{
@@ -483,7 +521,7 @@
 		newItem2->setFlags(newItem1->flags());
 		availableTableWidget->setItem(row, column++, newItem2);
 		QTableWidgetItem *newItem3 = new QTableWidgetItem();
-		newItem3->setCheckState(dictionaryMap.contains(d.lang) ? Qt::Checked : Qt::Unchecked);
+		newItem3->setCheckState(dictionaryMap.contains(d.desc) ? Qt::Checked : Qt::Unchecked);
 		newItem3->setFlags(newItem1->flags() & ~Qt::ItemIsUserCheckable);
 		availableTableWidget->setItem(row, column++, newItem3);
 		QTableWidgetItem *newItem4 = new QTableWidgetItem();
@@ -836,6 +874,7 @@
 	switch (category)
 	{
 		case RM_FONTS:
+			readAvailableFonts();
 			updateInstalledFonts();
 			updateAvailableFonts();
 			break;

Modified: trunk/Scribus/scribus/ui/resourcemanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21368&path=/trunk/Scribus/scribus/ui/resourcemanager.h
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.h	(original)
+++ trunk/Scribus/scribus/ui/resourcemanager.h	Mon Jun  6 20:29:22 2016
@@ -60,6 +60,7 @@
 		void languageChange();
 
 	protected:
+		void readAvailableFonts();
 		void readAvailableHelp();
 		void readAvailablePalettes();
 




More information about the scribus-commit mailing list