r17923 by jghali - #11184: Downloaded DE dictionaries aren't available for selection

scribus-commit scribus-commit at lists.scribus.net
Fri Nov 30 23:22:36 UTC 2012


Author: jghali
Date: Fri Nov 30 23:22:36 2012
New Revision: 17923

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17923
Log:
#11184: Downloaded DE dictionaries aren't available for selection

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

Modified: trunk/Scribus/scribus/ui/prefs_spelling.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17923&path=/trunk/Scribus/scribus/ui/prefs_spelling.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_spelling.cpp (original)
+++ trunk/Scribus/scribus/ui/prefs_spelling.cpp Fri Nov 30 23:22:36 2012
@@ -165,30 +165,49 @@
 	disconnect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadDictListFinished()));
 	//qDebug()<<"Downloads All Finished";
 	QString userDictDir(ScPaths::getUserDictDir(true));
+	// List all downloaded files in order to handle identical
+	// affix files while reducing potential errors related to
+	// disk space
+	QStringList allFileList;
 	foreach(DictData d, downloadList)
 	{
+		allFileList += d.files.split(";", QString::SkipEmptyParts);
+	}
+	// Move downloaded files to destination
+	foreach(DictData d, downloadList)
+	{
 		QString basename = QFileInfo(d.url).fileName();
-		QString filename=downloadLocation+basename;
+		QString filename = downloadLocation+basename;
+		QStringList files = d.files.split(";", QString::SkipEmptyParts);
+		QString affixFile = affixFileName(files);
+		QString dictFile  = dictFileName(files);
 		//qDebug()<<filename;
 		if (d.filetype=="zip")
 		{
 			//qDebug()<<"zip data found"<<filename;
-			FileUnzip* fun = new FileUnzip(filename);
-			QStringList files=d.files.split(";", QString::SkipEmptyParts);
+			FileUnzip fun(filename);
 			foreach (QString s, files)
 			{
 				//qDebug()<<"Unzipping"<<userDictDir+s;
-				QString data=fun->getFileToPath(s, userDictDir);
-			}
-			delete fun;
+				QString data = fun.getFileToPath(s, userDictDir);
+				allFileList.removeOne(s);
+			}
 		}
 		if (d.filetype=="plain")
 		{
-			QStringList files=d.files.split(";", QString::SkipEmptyParts);
 			foreach (QString s, files)
 			{
 				//qDebug()<<"plain data found"<<downloadLocation<<userDictDir<<s;
-				moveFile(downloadLocation+s, userDictDir+s);
+				QString dstName = s;
+				if (dstName == affixFile)
+					dstName = QFileInfo(downloadLocation+dictFile).baseName() + ".aff";
+				allFileList.removeOne(s);
+				if (allFileList.contains(s))
+				{
+					copyFile(downloadLocation+s, userDictDir+dstName);
+					continue;
+				}
+				moveFile(downloadLocation+s, userDictDir+dstName);
 			}
 		}
 	}
@@ -284,3 +303,25 @@
 	availDictTableWidget->setHorizontalHeaderLabels(headers);
 	availDictTableWidget->resizeColumnsToContents();
 }
+
+QString Prefs_Spelling::affixFileName(QStringList files)
+{
+	for (int i = 0; i < files.count(); ++i)
+	{
+		const QString& file = files.at(i);
+		if (file.endsWith(".aff", Qt::CaseInsensitive))
+			return file;
+	}
+	return QString();
+}
+
+QString Prefs_Spelling::dictFileName(QStringList files)
+{
+	for (int i = 0; i < files.count(); ++i)
+	{
+		const QString& file = files.at(i);
+		if (file.endsWith(".dic", Qt::CaseInsensitive))
+			return file;
+	}
+	return QString();
+}

Modified: trunk/Scribus/scribus/ui/prefs_spelling.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17923&path=/trunk/Scribus/scribus/ui/prefs_spelling.h
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_spelling.h (original)
+++ trunk/Scribus/scribus/ui/prefs_spelling.h Fri Nov 30 23:22:36 2012
@@ -16,18 +16,19 @@
 
 class SCRIBUS_API Prefs_Spelling : public Prefs_Pane, Ui::Prefs_Spelling
 {
-		//TODO: Dict license showing, URL background unzipping, checksumming, pkg mgr platforms warning
-		struct DictData
-		{
-				QString lang;
-				QString version;
-				QString files;
-				QString url;
-				QString desc;
-				QString license;
-				QString filetype;
-				bool download;
-		};
+	//TODO: Dict license showing, URL background unzipping, checksumming, pkg mgr platforms warning
+	struct DictData
+	{
+		QString lang;
+		QString version;
+		QString files;
+		QString url;
+		QString desc;
+		QString license;
+		QString filetype;
+		bool download;
+	};
+
 	Q_OBJECT
 
 	public:
@@ -46,6 +47,10 @@
 		void downloadDictListFinished();
 		void downloadSpellDictsFinished();
 		void updateProgressBar();
+
+	private:
+		QString affixFileName(QStringList files);
+		QString dictFileName(QStringList files);
 		void setAvailDictsXMLFile(QString availDictsXMLDataFile);
 
 	protected:




More information about the scribus-commit mailing list