summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-02-25 01:52:58 +0100
committerPetr Mrázek <peterix@gmail.com>2014-02-25 01:52:58 +0100
commitacff15562431d5d9e9f091ed7cf912f5fe34a61a (patch)
treee78502e7eda84696632be9b6539d386b829053b2 /logic
parent49dc9695f5204bb80a91214c411bcb1b868ee0db (diff)
parent9d4e840a6e1a7169a2863fa1ff1812f8fe19e615 (diff)
downloadMultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar.gz
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar.lz
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.tar.xz
MultiMC-acff15562431d5d9e9f091ed7cf912f5fe34a61a.zip
Merge branch 'feature_screenshots' into integration_json_and_tools
Conflicts: logic/net/URLConstants.h Resolve issues with multiple definitions of URL constants by moving them to their own object file.
Diffstat (limited to 'logic')
-rw-r--r--logic/net/URLConstants.cpp19
-rw-r--r--logic/net/URLConstants.h30
-rw-r--r--logic/screenshots/ImgurAlbumCreation.cpp90
-rw-r--r--logic/screenshots/ImgurAlbumCreation.h42
-rw-r--r--logic/screenshots/ImgurUpload.cpp106
-rw-r--r--logic/screenshots/ImgurUpload.h30
-rw-r--r--logic/screenshots/Screenshot.cpp14
-rw-r--r--logic/screenshots/Screenshot.h19
-rw-r--r--logic/screenshots/ScreenshotList.cpp113
-rw-r--r--logic/screenshots/ScreenshotList.h70
-rw-r--r--logic/tasks/SequentialTask.cpp15
-rw-r--r--logic/tasks/SequentialTask.h4
12 files changed, 531 insertions, 21 deletions
diff --git a/logic/net/URLConstants.cpp b/logic/net/URLConstants.cpp
new file mode 100644
index 00000000..14b28085
--- /dev/null
+++ b/logic/net/URLConstants.cpp
@@ -0,0 +1,19 @@
+#include "URLConstants.h"
+namespace URLConstants
+{
+const QString AWS_DOWNLOAD_BASE("s3.amazonaws.com/Minecraft.Download/");
+const QString AWS_DOWNLOAD_VERSIONS(AWS_DOWNLOAD_BASE + "versions/");
+const QString AWS_DOWNLOAD_LIBRARIES(AWS_DOWNLOAD_BASE + "libraries/");
+const QString AWS_DOWNLOAD_INDEXES(AWS_DOWNLOAD_BASE + "indexes/");
+const QString ASSETS_BASE("assets.minecraft.net/");
+const QString RESOURCE_BASE("resources.download.minecraft.net/");
+const QString LIBRARY_BASE("libraries.minecraft.net/");
+const QString SKINS_BASE("skins.minecraft.net/MinecraftSkins/");
+const QString AUTH_BASE("authserver.mojang.com/");
+const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/json");
+const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
+const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
+const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
+const QString LITELOADER_URL("http://dl.liteloader.com/versions/versions.json");
+const QString IMGUR_BASE_URL("https://api.imgur.com/3/");
+} \ No newline at end of file
diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h
index 07b35c4f..c1064115 100644
--- a/logic/net/URLConstants.h
+++ b/logic/net/URLConstants.h
@@ -19,19 +19,19 @@
namespace URLConstants
{
-const QString AWS_DOWNLOAD_BASE("s3.amazonaws.com/Minecraft.Download/");
-const QString AWS_DOWNLOAD_VERSIONS(AWS_DOWNLOAD_BASE + "versions/");
-const QString AWS_DOWNLOAD_LIBRARIES(AWS_DOWNLOAD_BASE + "libraries/");
-const QString AWS_DOWNLOAD_INDEXES(AWS_DOWNLOAD_BASE + "indexes/");
-const QString ASSETS_BASE("assets.minecraft.net/");
-//const QString MCN_BASE("sonicrules.org/mcnweb.py");
-const QString RESOURCE_BASE("resources.download.minecraft.net/");
-const QString LIBRARY_BASE("libraries.minecraft.net/");
-const QString SKINS_BASE("skins.minecraft.net/MinecraftSkins/");
-const QString AUTH_BASE("authserver.mojang.com/");
-const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/json");
-const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
-const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
-const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
-const QString LITELOADER_URL("http://dl.liteloader.com/versions/versions.json");
+extern const QString AWS_DOWNLOAD_BASE;
+extern const QString AWS_DOWNLOAD_VERSIONS;
+extern const QString AWS_DOWNLOAD_LIBRARIES;
+extern const QString AWS_DOWNLOAD_INDEXES;
+extern const QString ASSETS_BASE;
+extern const QString RESOURCE_BASE;
+extern const QString LIBRARY_BASE;
+extern const QString SKINS_BASE;
+extern const QString AUTH_BASE;
+extern const QString FORGE_LEGACY_URL;
+extern const QString FORGE_GRADLE_URL;
+extern const QString MOJANG_STATUS_URL;
+extern const QString MOJANG_STATUS_NEWS_URL;
+extern const QString LITELOADER_URL;
+extern const QString IMGUR_BASE_URL;
}
diff --git a/logic/screenshots/ImgurAlbumCreation.cpp b/logic/screenshots/ImgurAlbumCreation.cpp
new file mode 100644
index 00000000..e473952e
--- /dev/null
+++ b/logic/screenshots/ImgurAlbumCreation.cpp
@@ -0,0 +1,90 @@
+#include "ImgurAlbumCreation.h"
+
+#include <QNetworkRequest>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QUrl>
+
+#include "logic/screenshots//ScreenshotList.h"
+#include "logic/net/URLConstants.h"
+#include "MultiMC.h"
+#include "logger/QsLog.h"
+
+ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
+{
+ m_url = URLConstants::IMGUR_BASE_URL + "album.json";
+ m_status = Job_NotStarted;
+}
+
+void ImgurAlbumCreation::start()
+{
+ m_status = Job_InProgress;
+ QNetworkRequest request(m_url);
+ request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
+ request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
+ request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
+ request.setRawHeader("Accept", "application/json");
+
+ QStringList ids;
+ for (auto shot : m_screenshots)
+ {
+ ids.append(shot->imgurId);
+ }
+
+ const QByteArray data = "ids=" + ids.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden";
+
+ auto worker = MMC->qnam();
+ QNetworkReply *rep = worker->post(request, data);
+
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
+ connect(rep, &QNetworkReply::uploadProgress, this, &ImgurAlbumCreation::downloadProgress);
+ connect(rep, &QNetworkReply::finished, this, &ImgurAlbumCreation::downloadFinished);
+ connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
+ SLOT(downloadError(QNetworkReply::NetworkError)));
+}
+void ImgurAlbumCreation::downloadError(QNetworkReply::NetworkError error)
+{
+ QLOG_DEBUG() << m_reply->errorString();
+ m_status = Job_Failed;
+}
+void ImgurAlbumCreation::downloadFinished()
+{
+ if (m_status != Job_Failed)
+ {
+ QByteArray data = m_reply->readAll();
+ m_reply.reset();
+ QJsonParseError jsonError;
+ QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
+ if (jsonError.error != QJsonParseError::NoError)
+ {
+ QLOG_DEBUG() << jsonError.errorString();
+ emit failed(m_index_within_job);
+ return;
+ }
+ auto object = doc.object();
+ if (!object.value("success").toBool())
+ {
+ QLOG_DEBUG() << doc.toJson();
+ emit failed(m_index_within_job);
+ return;
+ }
+ m_deleteHash = object.value("data").toObject().value("deletehash").toString();
+ m_id = object.value("data").toObject().value("id").toString();
+ m_status = Job_Finished;
+ emit succeeded(m_index_within_job);
+ return;
+ }
+ else
+ {
+ QLOG_DEBUG() << m_reply->readAll();
+ m_reply.reset();
+ emit failed(m_index_within_job);
+ return;
+ }
+}
+void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
+{
+ m_total_progress = bytesTotal;
+ m_progress = bytesReceived;
+ emit progress(m_index_within_job, bytesReceived, bytesTotal);
+}
diff --git a/logic/screenshots/ImgurAlbumCreation.h b/logic/screenshots/ImgurAlbumCreation.h
new file mode 100644
index 00000000..6e8fbe94
--- /dev/null
+++ b/logic/screenshots/ImgurAlbumCreation.h
@@ -0,0 +1,42 @@
+#pragma once
+#include "logic/net/NetAction.h"
+#include "Screenshot.h"
+
+typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
+class ImgurAlbumCreation : public NetAction
+{
+public:
+ explicit ImgurAlbumCreation(QList<ScreenshotPtr> screenshots);
+ static ImgurAlbumCreationPtr make(QList<ScreenshotPtr> screenshots)
+ {
+ return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots));
+ }
+
+ QString deleteHash() const
+ {
+ return m_deleteHash;
+ }
+ QString id() const
+ {
+ return m_id;
+ }
+
+protected
+slots:
+ virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+ virtual void downloadError(QNetworkReply::NetworkError error);
+ virtual void downloadFinished();
+ virtual void downloadReadyRead()
+ {
+ }
+
+public
+slots:
+ virtual void start();
+
+private:
+ QList<ScreenshotPtr> m_screenshots;
+
+ QString m_deleteHash;
+ QString m_id;
+};
diff --git a/logic/screenshots/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp
new file mode 100644
index 00000000..62033ef5
--- /dev/null
+++ b/logic/screenshots/ImgurUpload.cpp
@@ -0,0 +1,106 @@
+#include "ImgurUpload.h"
+
+#include <QNetworkRequest>
+#include <QHttpMultiPart>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QHttpPart>
+#include <QFile>
+#include <QUrl>
+
+#include "logic/screenshots/ScreenshotList.h"
+#include "logic/net/URLConstants.h"
+#include "MultiMC.h"
+#include "logger/QsLog.h"
+
+ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot)
+{
+ m_url = URLConstants::IMGUR_BASE_URL + "upload.json";
+ m_status = Job_NotStarted;
+}
+
+void ImgurUpload::start()
+{
+ m_status = Job_InProgress;
+ QNetworkRequest request(m_url);
+ request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
+ request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
+ request.setRawHeader("Accept", "application/json");
+
+ QFile f(m_shot->file);
+ if (!f.open(QFile::ReadOnly))
+ {
+ emit failed(m_index_within_job);
+ return;
+ }
+
+ QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
+ QHttpPart filePart;
+ filePart.setBody(f.readAll().toBase64());
+ filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png");
+ filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\"");
+ multipart->append(filePart);
+ QHttpPart typePart;
+ typePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"type\"");
+ typePart.setBody("base64");
+ multipart->append(typePart);
+ QHttpPart namePart;
+ namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\"");
+ namePart.setBody(m_shot->timestamp.toString(Qt::ISODate).toUtf8());
+ multipart->append(namePart);
+
+ auto worker = MMC->qnam();
+ QNetworkReply *rep = worker->post(request, multipart);
+
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
+ connect(rep, &QNetworkReply::uploadProgress, this, &ImgurUpload::downloadProgress);
+ connect(rep, &QNetworkReply::finished, this, &ImgurUpload::downloadFinished);
+ connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
+ SLOT(downloadError(QNetworkReply::NetworkError)));
+}
+void ImgurUpload::downloadError(QNetworkReply::NetworkError error)
+{
+ QLOG_DEBUG() << m_reply->errorString();
+ m_status = Job_Failed;
+}
+void ImgurUpload::downloadFinished()
+{
+ if (m_status != Job_Failed)
+ {
+ QByteArray data = m_reply->readAll();
+ m_reply.reset();
+ QJsonParseError jsonError;
+ QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
+ if (jsonError.error != QJsonParseError::NoError)
+ {
+ QLOG_DEBUG() << jsonError.errorString();
+ emit failed(m_index_within_job);
+ return;
+ }
+ auto object = doc.object();
+ if (!object.value("success").toBool())
+ {
+ QLOG_DEBUG() << doc.toJson();
+ emit failed(m_index_within_job);
+ return;
+ }
+ m_shot->imgurId = object.value("data").toObject().value("id").toString();
+ m_shot->url = object.value("data").toObject().value("link").toString();
+ m_status = Job_Finished;
+ emit succeeded(m_index_within_job);
+ return;
+ }
+ else
+ {
+ QLOG_DEBUG() << m_reply->readAll();
+ m_reply.reset();
+ emit failed(m_index_within_job);
+ return;
+ }
+}
+void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
+{
+ m_total_progress = bytesTotal;
+ m_progress = bytesReceived;
+ emit progress(m_index_within_job, bytesReceived, bytesTotal);
+}
diff --git a/logic/screenshots/ImgurUpload.h b/logic/screenshots/ImgurUpload.h
new file mode 100644
index 00000000..1111a8d0
--- /dev/null
+++ b/logic/screenshots/ImgurUpload.h
@@ -0,0 +1,30 @@
+#pragma once
+#include "logic/net/NetAction.h"
+#include "Screenshot.h"
+
+typedef std::shared_ptr<class ImgurUpload> ImgurUploadPtr;
+class ImgurUpload : public NetAction
+{
+public:
+ explicit ImgurUpload(ScreenshotPtr shot);
+ static ImgurUploadPtr make(ScreenshotPtr shot)
+ {
+ return ImgurUploadPtr(new ImgurUpload(shot));
+ }
+
+protected
+slots:
+ virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+ virtual void downloadError(QNetworkReply::NetworkError error);
+ virtual void downloadFinished();
+ virtual void downloadReadyRead()
+ {
+ }
+
+public
+slots:
+ virtual void start();
+
+private:
+ ScreenshotPtr m_shot;
+};
diff --git a/logic/screenshots/Screenshot.cpp b/logic/screenshots/Screenshot.cpp
new file mode 100644
index 00000000..882e491f
--- /dev/null
+++ b/logic/screenshots/Screenshot.cpp
@@ -0,0 +1,14 @@
+#include "Screenshot.h"
+#include <QImage>
+#include <QIcon>
+QIcon ScreenShot::getImage()
+{
+ if(!imageloaded)
+ {
+ QImage image(file);
+ QImage thumbnail = image.scaledToWidth(256, Qt::SmoothTransformation);
+ m_image = QIcon(QPixmap::fromImage(thumbnail));
+ imageloaded = true;
+ }
+ return m_image;
+}
diff --git a/logic/screenshots/Screenshot.h b/logic/screenshots/Screenshot.h
new file mode 100644
index 00000000..815c0d47
--- /dev/null
+++ b/logic/screenshots/Screenshot.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <QDateTime>
+#include <QString>
+#include <memory>
+#include <QIcon>
+
+struct ScreenShot
+{
+ QIcon getImage();
+ QIcon m_image;
+ bool imageloaded = false;
+ QDateTime timestamp;
+ QString file;
+ QString url;
+ QString imgurId;
+};
+
+typedef std::shared_ptr<ScreenShot> ScreenshotPtr;
diff --git a/logic/screenshots/ScreenshotList.cpp b/logic/screenshots/ScreenshotList.cpp
new file mode 100644
index 00000000..8a64dc36
--- /dev/null
+++ b/logic/screenshots/ScreenshotList.cpp
@@ -0,0 +1,113 @@
+#include "ScreenshotList.h"
+#include "gui/dialogs/ScreenshotDialog.h"
+
+#include <QDir>
+#include <QIcon>
+#include <QList>
+#include "gui/dialogs/ProgressDialog.h"
+#include "gui/dialogs/CustomMessageBox.h"
+
+ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent)
+ : QAbstractListModel(parent), m_instance(instance)
+{
+}
+
+int ScreenshotList::rowCount(const QModelIndex &) const
+{
+ return m_screenshots.size();
+}
+
+QVariant ScreenshotList::data(const QModelIndex &index, int role) const
+{
+ if (index.row() >= m_screenshots.size() || index.row() < 0)
+ return QVariant();
+
+ switch (role)
+ {
+ case Qt::DecorationRole:
+ return m_screenshots.at(index.row())->getImage();
+ case Qt::DisplayRole:
+ return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
+ case Qt::ToolTipRole:
+ return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
+ case Qt::TextAlignmentRole:
+ return (int)(Qt::AlignHCenter | Qt::AlignVCenter);
+ default:
+ return QVariant();
+ }
+}
+
+QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ return QVariant();
+}
+
+Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const
+{
+ return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
+}
+
+Task *ScreenshotList::load()
+{
+ return new ScreenshotLoadTask(this);
+}
+
+ScreenshotLoadTask::ScreenshotLoadTask(ScreenshotList *list) : m_list(list)
+{
+}
+
+ScreenshotLoadTask::~ScreenshotLoadTask()
+{
+}
+
+void ScreenshotLoadTask::executeTask()
+{
+ auto dir = QDir(m_list->instance()->minecraftRoot());
+ if (!dir.cd("screenshots"))
+ {
+ emitFailed("Selected instance does not have any screenshots!");
+ return;
+ }
+ dir.setNameFilters(QStringList() << "*.png");
+ this->m_results.clear();
+ for (auto file : dir.entryList())
+ {
+ ScreenShot *shot = new ScreenShot();
+ shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png");
+ shot->file = dir.absoluteFilePath(file);
+ m_results.append(ScreenshotPtr(shot));
+ }
+ m_list->loadShots(m_results);
+ emitSucceeded();
+}
+
+void ScreenshotList::deleteSelected(ScreenshotDialog *dialog)
+{
+ auto screens = dialog->selected();
+ if (screens.isEmpty())
+ {
+ return;
+ }
+ beginResetModel();
+ QList<std::shared_ptr<ScreenShot>>::const_iterator it;
+ for (it = screens.cbegin(); it != screens.cend(); it++)
+ {
+ auto shot = *it;
+ if (!QFile(shot->file).remove())
+ {
+ CustomMessageBox::selectable(dialog, tr("Error!"),
+ tr("Failed to delete screenshots!"),
+ QMessageBox::Warning)->exec();
+ break;
+ }
+ }
+ ProgressDialog refresh(dialog);
+ Task *t = load();
+ if (refresh.exec(t) != QDialog::Accepted)
+ {
+ CustomMessageBox::selectable(dialog, tr("Error!"),
+ tr("Unable to refresh list: %1").arg(t->failReason()),
+ QMessageBox::Warning)->exec();
+ }
+ endResetModel();
+}
diff --git a/logic/screenshots/ScreenshotList.h b/logic/screenshots/ScreenshotList.h
new file mode 100644
index 00000000..ca6314e9
--- /dev/null
+++ b/logic/screenshots/ScreenshotList.h
@@ -0,0 +1,70 @@
+#pragma once
+
+#include <QAbstractListModel>
+#include "logic/BaseInstance.h"
+#include "logic/tasks/Task.h"
+
+#include "Screenshot.h"
+
+class ScreenshotList : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ ScreenshotList(BaseInstance *instance, QObject *parent = 0);
+
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+ int rowCount(const QModelIndex &parent) const;
+
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+
+ Task *load();
+
+ void loadShots(QList<ScreenshotPtr> shots)
+ {
+ m_screenshots = shots;
+ }
+
+ QList<ScreenshotPtr> screenshots() const
+ {
+ return m_screenshots;
+ }
+
+ BaseInstance *instance() const
+ {
+ return m_instance;
+ }
+
+ void deleteSelected(class ScreenshotDialog *dialog);
+
+signals:
+
+public
+slots:
+
+private:
+ QList<ScreenshotPtr> m_screenshots;
+ BaseInstance *m_instance;
+};
+
+class ScreenshotLoadTask : public Task
+{
+ Q_OBJECT
+
+public:
+ explicit ScreenshotLoadTask(ScreenshotList *list);
+ ~ScreenshotLoadTask();
+
+ QList<ScreenshotPtr> screenShots() const
+ {
+ return m_results;
+ }
+
+protected:
+ virtual void executeTask();
+
+private:
+ ScreenshotList *m_list;
+ QList<ScreenshotPtr> m_results;
+};
diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp
index 63025eee..e0f8fcdd 100644
--- a/logic/tasks/SequentialTask.cpp
+++ b/logic/tasks/SequentialTask.cpp
@@ -28,7 +28,7 @@ void SequentialTask::getProgress(qint64 &current, qint64 &total)
}
}
-void SequentialTask::addTask(std::shared_ptr<Task> task)
+void SequentialTask::addTask(std::shared_ptr<ProgressProvider> task)
{
m_queue.append(task);
}
@@ -43,7 +43,7 @@ void SequentialTask::startNext()
{
if (m_currentIndex != -1)
{
- std::shared_ptr<Task> previous = m_queue[m_currentIndex];
+ std::shared_ptr<ProgressProvider> previous = m_queue[m_currentIndex];
disconnect(previous.get(), 0, this, 0);
}
m_currentIndex++;
@@ -52,7 +52,7 @@ void SequentialTask::startNext()
emitSucceeded();
return;
}
- std::shared_ptr<Task> next = m_queue[m_currentIndex];
+ std::shared_ptr<ProgressProvider> next = m_queue[m_currentIndex];
connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString)));
connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString)));
connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress()));
@@ -73,5 +73,12 @@ void SequentialTask::subTaskProgress()
{
qint64 current, total;
getProgress(current, total);
- setProgress(100 * current / total);
+ if (total == 0)
+ {
+ setProgress(0);
+ }
+ else
+ {
+ setProgress(100 * current / total);
+ }
}
diff --git a/logic/tasks/SequentialTask.h b/logic/tasks/SequentialTask.h
index 7f046928..c405dca3 100644
--- a/logic/tasks/SequentialTask.h
+++ b/logic/tasks/SequentialTask.h
@@ -14,7 +14,7 @@ public:
virtual QString getStatus() const;
virtual void getProgress(qint64 &current, qint64 &total);
- void addTask(std::shared_ptr<Task> task);
+ void addTask(std::shared_ptr<ProgressProvider> task);
protected:
void executeTask();
@@ -27,6 +27,6 @@ slots:
void subTaskProgress();
private:
- QQueue<std::shared_ptr<Task> > m_queue;
+ QQueue<std::shared_ptr<ProgressProvider> > m_queue;
int m_currentIndex;
};