r19789 by craig - Moving of downloaded files to correct destinaton now managed by download manager and not spelling preferences. Now removes broken downloads too.

scribus-commit scribus-commit at lists.scribus.net
Tue Feb 3 22:19:42 UTC 2015


Author: craig
Date: Tue Feb  3 22:19:42 2015
New Revision: 19789

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19789
Log:
Moving of downloaded files to correct destinaton now managed by download manager and not spelling preferences. Now removes broken downloads too.

Modified:
    trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
    trunk/Scribus/scribus/downloadmanager/scdlmgr.h
    trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
    trunk/Scribus/scribus/downloadmanager/scdlthread.h
    trunk/Scribus/scribus/scribusapp.cpp
    trunk/Scribus/scribus/ui/prefs_spelling.cpp

Modified: trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19789&path=/trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp Tue Feb  3 22:19:42 2015
@@ -9,13 +9,16 @@
 
 #include <stdio.h>
 
+#include "util_file.h"
+
 ScDLManager::ScDLManager(QObject *parent)
 	: QObject(parent)
 {
 	dlID=0;
 	thread=new ScDLThread();
-	connect(thread, SIGNAL(received(const QString &)), this, SLOT(dlReceived(const QString&)));
-	connect(thread, SIGNAL(failed(const QString &)), this, SLOT(dlFailed(const QString&)));
+	connect(thread, SIGNAL(fileReceived(const QString &)), this, SLOT(dlReceived(const QString&)));
+	connect(thread, SIGNAL(fileFailed(const QString &)), this, SLOT(dlFailed(const QString&)));
+	connect(thread, SIGNAL(fileStarted(const QString &)), this, SLOT(dlStarted(const QString &)));
 	connect(thread, SIGNAL(finished()), this, SIGNAL(finished()));
 	connect(thread, SIGNAL(finished()), this, SLOT(moveFinishedDownloads()));
 }
@@ -73,40 +76,54 @@
 
 void ScDLManager::startDownloads()
 {
-	qDebug()<<"Manager starting downloads...";
+	//qDebug()<<"Manager starting downloads...";
 	thread->startDownloads();
 }
 
-void ScDLManager::dlReceived(const QString& t)
-{
-	emit fileReceived(t);
-	qDebug()<<"File Received:"<<t;
-	QMutableListIterator<DownloadData> i(fileList);
-	while (i.hasNext())
-	{
-		i.next();
-		//if (d.state==DownloadData::Started && d.downloadLocation+d.name==t)
-		if (i.value().downloadLocation+i.value().name==t)
-		{
-			qDebug()<<"success"<<i.value().downloadLocation+i.value().name<<t;
+void ScDLManager::dlStarted(const QString& filename)
+{
+	//qDebug()<<"File Started:"<<filename;
+	QMutableListIterator<DownloadData> i(fileList);
+	while (i.hasNext())
+	{
+		i.next();
+		if (i.value().state!=DownloadData::Successful && i.value().state!=DownloadData::Failed && i.value().downloadLocation+i.value().name==filename)
+		{
+			//qDebug()<<"starting"<<i.value().downloadLocation+i.value().name<<filename;
+			i.value().state=DownloadData::Started;
+			break;
+		}
+	}
+}
+
+void ScDLManager::dlReceived(const QString& filename)
+{
+	emit fileReceived(filename);
+	//qDebug()<<"File Received:"<<filename;
+	QMutableListIterator<DownloadData> i(fileList);
+	while (i.hasNext())
+	{
+		i.next();
+		if (i.value().state==DownloadData::Started && i.value().downloadLocation+i.value().name==filename)
+		{
+			//qDebug()<<"success"<<i.value().downloadLocation+i.value().name<<filename;
 			i.value().state=DownloadData::Successful;
 			break;
 		}
 	}
 }
 
-void ScDLManager::dlFailed(const QString& t)
-{
-	emit fileFailed(t);
-	qDebug()<<"File Failed:"<<t;
-	QMutableListIterator<DownloadData> i(fileList);
-	while (i.hasNext())
-	{
-		i.next();
-		//if (d.state==DownloadData::Started && d.downloadLocation+d.name==t)
-		if (i.value().downloadLocation+i.value().name==t)
-		{
-			qDebug()<<"fail"<<i.value().downloadLocation+i.value().name<<t;
+void ScDLManager::dlFailed(const QString& filename)
+{
+	emit fileFailed(filename);
+	//qDebug()<<"File Failed:"<<filename;
+	QMutableListIterator<DownloadData> i(fileList);
+	while (i.hasNext())
+	{
+		i.next();
+		if (i.value().state==DownloadData::Started && i.value().downloadLocation+i.value().name==filename)
+		{
+			//qDebug()<<"fail"<<i.value().downloadLocation+i.value().name<<filename;
 			i.value().state=DownloadData::Failed;
 			break;
 		}
@@ -119,22 +136,25 @@
 	while (i.hasNext())
 	{
 		i.next();
-		qDebug()<<"moveFinishedDownloads"<<i.value().name<<i.value().url;
+		//qDebug()<<"moveFinishedDownloads"<<i.value().name<<i.value().url;
 		switch (i.value().state)
 		{
 			case DownloadData::Successful:
 				{
 					if (i.value().downloadLocation==i.value().destinationLocation)
-						qDebug()<<i.value().name<<"is in"<<i.value().downloadLocation<<"which is the same as"<<i.value().destinationLocation;
+						;//qDebug()<<i.value().name<<"is in"<<i.value().downloadLocation<<"which is the same as"<<i.value().destinationLocation;
 					else
-						qDebug()<<"Need to move"<<i.value().name<<"from"<<i.value().downloadLocation<<"to"<<i.value().destinationLocation;
+					{
+						//qDebug()<<"Need to move"<<i.value().name<<"from"<<i.value().downloadLocation<<"to"<<i.value().destinationLocation;
+						moveFile(i.value().downloadLocation+i.value().name, i.value().destinationLocation+i.value().name);
+					}
 				}
 				break;
 			case DownloadData::Failed:
-				qDebug()<<i.value().name<<"failed :(.";
+				//qDebug()<<i.value().name<<"failed :(.";
 				break;
 			default:
-				qDebug()<<"case d state default"<<i.value().url;
+				//qDebug()<<"case d state default"<<i.value().url;
 				break;
 		}
 	}

Modified: trunk/Scribus/scribus/downloadmanager/scdlmgr.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19789&path=/trunk/Scribus/scribus/downloadmanager/scdlmgr.h
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlmgr.h (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlmgr.h Tue Feb  3 22:19:42 2015
@@ -29,8 +29,9 @@
 		void startDownloads();
 
 	public slots:
-		void dlReceived(const QString& t);
-		void dlFailed(const QString& t);
+		void dlStarted(const QString& filename);
+		void dlReceived(const QString& filename);
+		void dlFailed(const QString& filename);
 
 	protected slots:
 		void moveFinishedDownloads();

Modified: trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19789&path=/trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlthread.cpp (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlthread.cpp Tue Feb  3 22:19:42 2015
@@ -28,7 +28,7 @@
 
 void ScDLThread::addURL(const QUrl &url, bool overwrite, const QString& location, const QString& destinationLocation)
 {
-	qDebug()<<"ScDLThread::addURL:"<<url;
+	//qDebug()<<"ScDLThread::addURL:"<<url;
 	if (!urlOK(url))
 		return;
 	QString l(QDir::cleanPath(location));
@@ -40,7 +40,7 @@
 
 void ScDLThread::addURLs(const QStringList &urlList, bool overwrite, const QString& location, const QString& destinationLocation)
 {
-	qDebug()<<"ScDLThread::addURLs:"<<urlList;
+	//qDebug()<<"ScDLThread::addURLs:"<<urlList;
 	m_urlList=urlList;
 	QString l(QDir::cleanPath(location));
 	if (!l.endsWith("/"))
@@ -59,7 +59,7 @@
 {
 	if (downloadQueue.isEmpty())
 	{
-		qDebug()<<"No more downloads left";
+		//qDebug()<<"No more downloads left";
 		emit finished();
 		return;
 	}
@@ -97,7 +97,7 @@
 {
 	if (downloadQueue.isEmpty())
 	{
-		qDebug()<<downloadedCount<<"/"<<totalCount<<"files downloaded successfully";
+		//qDebug()<<downloadedCount<<"/"<<totalCount<<"files downloaded successfully";
 		downloadedCount=totalCount=0;
 		emit finished();
 		return;
@@ -107,25 +107,25 @@
 	QString filename = saveFileName(urlPair.first, urlPair.second, true);
 	if (filename.isEmpty())
 	{
-		qDebug()<<"File name empty for url:"<<urlPair.first.toEncoded().constData();
+		//qDebug()<<"File name empty for url:"<<urlPair.first.toEncoded().constData();
 		return;
 	}
 	output.setFileName(filename);
 	if (!output.open(QIODevice::WriteOnly))
 	{
-		qDebug()<<"Problem opening save file '"<<qPrintable(filename)<<"' for download '"
-			   <<urlPair.first.toEncoded().constData()<<"': "<<qPrintable(output.errorString());
+		//qDebug()<<"Problem opening save file '"<<qPrintable(filename)<<"' for download '"
+		//	   <<urlPair.first.toEncoded().constData()<<"': "<<qPrintable(output.errorString());
 
 		startNextDownload();
 		return;
 	}
-
+	emit fileStarted(output.fileName());
 	QNetworkRequest request(urlPair.first);
 	currentDownload = manager.get(request);
 	connect(currentDownload, SIGNAL(finished()), SLOT(downloadFinished()));
 	connect(currentDownload, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
 
-	qDebug()<<"Downloading:"<<urlPair.first.toEncoded().constData();
+	//qDebug()<<"Downloading:"<<urlPair.first.toEncoded().constData();
 }
 
 void ScDLThread::downloadFinished()
@@ -134,15 +134,16 @@
 
 	if (currentDownload->error())
 	{
-		qDebug()<<"Failed: "<<qPrintable(currentDownload->errorString());
-		emit failed(output.fileName());
+		//qDebug()<<"Failed: "<<qPrintable(currentDownload->errorString());
+		emit fileFailed(output.fileName());
+		if (output.exists())
+			output.remove();
 	}
 	else
 	{
-		printf("Succeeded.\n");
-		qDebug()<<"Saving file:"<<qPrintable(output.fileName());
+		//qDebug()<<"Saving file:"<<qPrintable(output.fileName());
 		++downloadedCount;
-		emit received(output.fileName());
+		emit fileReceived(output.fileName());
 	}
 	currentDownload->deleteLater();
 	startNextDownload();
@@ -164,7 +165,7 @@
 	//TODO: Add some more URL checks
 	if (!url.isValid() || url.isEmpty() || url.host().isEmpty())
 	{
-		qDebug()<<"URL invalid:"<<url;
+		//qDebug()<<"URL invalid:"<<url;
 		return false;
 	}
 	return true;

Modified: trunk/Scribus/scribus/downloadmanager/scdlthread.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19789&path=/trunk/Scribus/scribus/downloadmanager/scdlthread.h
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlthread.h (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlthread.h Tue Feb  3 22:19:42 2015
@@ -26,8 +26,9 @@
 	signals:
 		void finished();
 		void runSignal();
-		void received(const QString &);
-		void failed(const QString &);
+		void fileStarted(const QString &);
+		void fileReceived(const QString &);
+		void fileFailed(const QString &);
 
 	private slots:
 		void startNextDownload();

Modified: trunk/Scribus/scribus/scribusapp.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19789&path=/trunk/Scribus/scribus/scribusapp.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusapp.cpp (original)
+++ trunk/Scribus/scribus/scribusapp.cpp Tue Feb  3 22:19:42 2015
@@ -130,7 +130,7 @@
 void ScribusQApp::initDLMgr()
 {
 	m_scDLMgr = new ScDLManager(this);
-	connect(m_scDLMgr, SIGNAL(fileReceived(const QString&)), SLOT(downloadComplete(const QString&)));
+	//connect(m_scDLMgr, SIGNAL(fileReceived(const QString&)), SLOT(downloadComplete(const QString&)));
 }
 
 void ScribusQApp::parseCommandLine()
@@ -591,7 +591,7 @@
 
 void ScribusQApp::downloadComplete(const QString &t)
 {
-	qDebug()<<"ScribusQApp: download finished:"<<t;
+	//qDebug()<<"ScribusQApp: download finished:"<<t;
 }
 
 bool ScribusQApp::event(QEvent *event)

Modified: trunk/Scribus/scribus/ui/prefs_spelling.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19789&path=/trunk/Scribus/scribus/ui/prefs_spelling.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_spelling.cpp (original)
+++ trunk/Scribus/scribus/ui/prefs_spelling.cpp Tue Feb  3 22:19:42 2015
@@ -64,7 +64,6 @@
 void Prefs_Spelling::downloadSpellDicts()
 {
 	spellDownloadButton->setEnabled(false);
-	qDebug()<<"Now attempting downloads";
 	int rows=availDictTableWidget->rowCount();
 	QStringList dlLangs;
 	for (int i=0; i<rows; ++i)
@@ -105,7 +104,7 @@
 	if (i>0)
 	{
 		downloadProgressBar->setRange(0, i);
-		connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadSpellDictsFinished()));
+		//connect(ScQApp->dlManager(), SIGNAL(finished()), this, SLOT(downloadSpellDictsFinished()));
 		connect(ScQApp->dlManager(), SIGNAL(fileReceived(const QString&)), this, SLOT(updateProgressBar()));
 		connect(ScQApp->dlManager(), SIGNAL(fileFailed(const QString&)), this, SLOT(updateProgressBar()));
 		ScQApp->dlManager()->startDownloads();
@@ -129,7 +128,7 @@
 	{
 		 i.next();
 		 int column=0;
-		 qDebug()<<i.key()<<i.value()<<LanguageManager::instance()->getLangFromAbbrev(i.key(), false);
+		 //qDebug()<<i.key()<<i.value()<<LanguageManager::instance()->getLangFromAbbrev(i.key(), false);
 		 QTableWidgetItem *newItem1 = new QTableWidgetItem(LanguageManager::instance()->getLangFromAbbrev(i.key()));
 		 newItem1->setFlags(newItem1->flags() & ~Qt::ItemIsEditable);
 		 dictTableWidget->setItem(row, column++, newItem1);




More information about the scribus-commit mailing list