r19787 by craig - Update dl mgr again
scribus-commit
scribus-commit at lists.scribus.net
Tue Feb 3 19:41:12 UTC 2015
Author: craig
Date: Tue Feb 3 19:41:12 2015
New Revision: 19787
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19787
Log:
Update dl mgr again
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/scribusstructs.h
trunk/Scribus/scribus/ui/prefs_spelling.cpp
Modified: trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19787&path=/trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp Tue Feb 3 19:41:12 2015
@@ -12,9 +12,12 @@
ScDLManager::ScDLManager(QObject *parent)
: QObject(parent)
{
+ dlID=0;
thread=new ScDLThread();
- connect(thread, SIGNAL(received(const QString &)), this, SLOT(updateText(const QString&)));
+// 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(finished()), this, SIGNAL(finished()));
+// connect(thread, SIGNAL(finished()), this, SLOT(moveFinishedDownloads()));
}
ScDLManager::~ScDLManager()
@@ -26,16 +29,45 @@
void ScDLManager::addURL(const QUrl &url, bool overwrite, const QString& downloadLocation, const QString& destinationLocation)
{
+ DownloadData d;
+ d.id=dlID++;
+ d.name=url.fileName();
+ d.url=url;
+ d.downloadLocation=downloadLocation;
+ d.destinationLocation=destinationLocation;
+ d.state=DownloadData::New;
+ fileList.append(d);
+
thread->addURL(url, overwrite, downloadLocation, destinationLocation);
}
void ScDLManager::addURL(const QString &url, bool overwrite, const QString &downloadLocation, const QString& destinationLocation)
{
+ DownloadData d;
+ d.id=dlID++;
+ d.name=QUrl(url).fileName();
+ d.url=url;
+ d.downloadLocation=downloadLocation;
+ d.destinationLocation=destinationLocation;
+ d.state=DownloadData::New;
+ fileList.append(d);
+
thread->addURL(QUrl(url), overwrite, downloadLocation, destinationLocation);
}
void ScDLManager::addURLs(const QStringList &urlList, bool overwrite, const QString &downloadLocation, const QString& destinationLocation)
{
+ foreach(QString s, urlList)
+ {
+ DownloadData d;
+ d.id=dlID++;
+ d.name=QUrl(s).fileName();
+ d.url=s;
+ d.downloadLocation=downloadLocation;
+ d.destinationLocation=destinationLocation;
+ d.state=DownloadData::New;
+ fileList.append(d);
+ }
thread->addURLs(urlList, overwrite, downloadLocation, destinationLocation);
}
@@ -45,14 +77,66 @@
thread->startDownloads();
}
-void ScDLManager::updateText(const QString& t)
+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;
+ i.value().state=DownloadData::Successful;
+ }
+ }
+}
+
+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;
+ i.value().state=DownloadData::Failed;
+ }
+ }
}
void ScDLManager::moveFinishedDownloads()
{
+ QMutableListIterator<DownloadData> i(fileList);
+ while (i.hasNext())
+ {
+ i.next();
+ 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;
+ else
+ qDebug()<<"Need to move"<<i.value().name<<"from"<<i.value().downloadLocation<<"to"<<i.value().destinationLocation;
+ }
+ break;
+ case DownloadData::Failed:
+ qDebug()<<i.value().name<<"failed :(.";
+ break;
+ default:
+ qDebug()<<"case d state default"<<i.value().url;
+ break;
+ }
+ }
+
/*
QStringList allFileList;
foreach(DictData d, fileList)
Modified: trunk/Scribus/scribus/downloadmanager/scdlmgr.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19787&path=/trunk/Scribus/scribus/downloadmanager/scdlmgr.h
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlmgr.h (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlmgr.h Tue Feb 3 19:41:12 2015
@@ -29,7 +29,8 @@
void startDownloads();
public slots:
- void updateText(const QString& t);
+ void dlReceived(const QString& t);
+ void dlFailed(const QString& t);
protected slots:
void moveFinishedDownloads();
@@ -37,10 +38,11 @@
signals:
void finished();
void fileReceived(const QString& t);
+ void fileFailed(const QString& t);
private:
ScDLThread *thread;
-
+ int dlID;
QList <DownloadData> fileList;
};
Modified: trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19787&path=/trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlthread.cpp (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlthread.cpp Tue Feb 3 19:41:12 2015
@@ -133,14 +133,17 @@
output.close();
if (currentDownload->error())
+ {
qDebug()<<"Failed: "<<qPrintable(currentDownload->errorString());
+ emit failed(output.fileName());
+ }
else
{
printf("Succeeded.\n");
qDebug()<<"Saving file:"<<qPrintable(output.fileName());
++downloadedCount;
+ emit received(output.fileName());
}
- emit (received(output.fileName()));
currentDownload->deleteLater();
startNextDownload();
}
Modified: trunk/Scribus/scribus/downloadmanager/scdlthread.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19787&path=/trunk/Scribus/scribus/downloadmanager/scdlthread.h
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlthread.h (original)
+++ trunk/Scribus/scribus/downloadmanager/scdlthread.h Tue Feb 3 19:41:12 2015
@@ -27,6 +27,7 @@
void finished();
void runSignal();
void received(const QString &);
+ void failed(const QString &);
private slots:
void startNextDownload();
Modified: trunk/Scribus/scribus/scribusstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19787&path=/trunk/Scribus/scribus/scribusstructs.h
==============================================================================
--- trunk/Scribus/scribus/scribusstructs.h (original)
+++ trunk/Scribus/scribus/scribusstructs.h Tue Feb 3 19:41:12 2015
@@ -385,10 +385,12 @@
struct DownloadData
{
+ int id;
+ QUrl url;
QString name;
QString downloadLocation;
QString destinationLocation;
- typedef enum {Started, Paused, Finished} DownloadState;
+ typedef enum {New, Started, Paused, Finished, Successful, Failed} DownloadState;
DownloadState state;
};
Modified: trunk/Scribus/scribus/ui/prefs_spelling.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19787&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 19:41:12 2015
@@ -73,7 +73,7 @@
if (dlItem->checkState()==Qt::Checked)
dlLangs<<availDictTableWidget->item(i,1)->text();
}
- qDebug()<<dlLangs;
+ //qDebug()<<dlLangs;
downloadList.clear();
downloadProgressBar->setValue(0);
downloadProgressBar->setVisible(true);
@@ -107,6 +107,7 @@
downloadProgressBar->setRange(0, i);
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();
}
}
More information about the scribus-commit
mailing list