summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-01-01 19:21:58 +0100
committerPetr Mrázek <peterix@gmail.com>2014-01-01 19:21:58 +0100
commit0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6 (patch)
tree93a26eb1fa534984230e871253faaf3ec142f373
parentcf7335186d1aa3d99a32adb04a55c066161760c3 (diff)
downloadMultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar
MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar.gz
MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar.lz
MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar.xz
MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.zip
ThreadTask for all your ThreadNeeds
Use only when absolutely required.
-rw-r--r--CMakeLists.txt8
-rw-r--r--gui/MainWindow.cpp18
-rw-r--r--logic/assets/AssetsMigrateTask.cpp2
-rw-r--r--logic/tasks/ThreadTask.cpp41
-rw-r--r--logic/tasks/ThreadTask.h25
5 files changed, 85 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 896dd926..39ff15c0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,11 +47,13 @@ find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Test REQUIRED)
+find_package(Qt5Concurrent REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
+ ${Qt5Concurrent_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
)
@@ -398,6 +400,8 @@ logic/EnabledItemFilter.cpp
logic/tasks/ProgressProvider.h
logic/tasks/Task.h
logic/tasks/Task.cpp
+logic/tasks/ThreadTask.h
+logic/tasks/ThreadTask.cpp
logic/tasks/SequentialTask.h
logic/tasks/SequentialTask.cpp
@@ -512,8 +516,8 @@ ADD_EXECUTABLE(MultiMC MACOSX_BUNDLE WIN32 main.cpp ${MULTIMC_RCS})
# Link
TARGET_LINK_LIBRARIES(MultiMC MultiMC_common)
TARGET_LINK_LIBRARIES(MultiMC_common xz-embedded unpack200 quazip libUtil libSettings libGroupView ${MultiMC_LINK_ADDITIONAL_LIBS})
-QT5_USE_MODULES(MultiMC Core Widgets Network Xml ${MultiMC_QT_ADDITIONAL_MODULES})
-QT5_USE_MODULES(MultiMC_common Core Widgets Network Xml ${MultiMC_QT_ADDITIONAL_MODULES})
+QT5_USE_MODULES(MultiMC Core Widgets Network Xml Concurrent ${MultiMC_QT_ADDITIONAL_MODULES})
+QT5_USE_MODULES(MultiMC_common Core Widgets Network Xml Concurrent ${MultiMC_QT_ADDITIONAL_MODULES})
ADD_DEPENDENCIES(MultiMC_common MultiMCLauncher JavaCheck)
################################ INSTALLATION AND PACKAGING ################################
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 42470bb0..b55be903 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -90,6 +90,7 @@
#include "logic/assets/AssetsUtils.h"
#include "logic/assets/AssetsMigrateTask.h"
#include <logic/updater/UpdateChecker.h>
+#include <logic/tasks/ThreadTask.h>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
@@ -1169,14 +1170,17 @@ void MainWindow::checkMigrateLegacyAssets()
{
ProgressDialog migrateDlg(this);
AssetsMigrateTask migrateTask(legacyAssets, &migrateDlg);
-
- if (migrateDlg.exec(&migrateTask))
{
- QLOG_INFO() << "Assets migration task completed successfully";
- }
- else
- {
- QLOG_INFO() << "Assets migration task reported failure";
+ ThreadTask threadTask(&migrateTask);
+
+ if (migrateDlg.exec(&threadTask))
+ {
+ QLOG_INFO() << "Assets migration task completed successfully";
+ }
+ else
+ {
+ QLOG_INFO() << "Assets migration task reported failure";
+ }
}
}
else
diff --git a/logic/assets/AssetsMigrateTask.cpp b/logic/assets/AssetsMigrateTask.cpp
index be45718d..7c1f5204 100644
--- a/logic/assets/AssetsMigrateTask.cpp
+++ b/logic/assets/AssetsMigrateTask.cpp
@@ -4,6 +4,7 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QDirIterator>
+#include <QCryptographicHash>
#include "gui/dialogs/CustomMessageBox.h"
#include <QDesktopServices>
@@ -139,3 +140,4 @@ void AssetsMigrateTask::executeTask()
emitSucceeded();
}
}
+
diff --git a/logic/tasks/ThreadTask.cpp b/logic/tasks/ThreadTask.cpp
new file mode 100644
index 00000000..ddd1dee5
--- /dev/null
+++ b/logic/tasks/ThreadTask.cpp
@@ -0,0 +1,41 @@
+#include "ThreadTask.h"
+#include <QtConcurrentRun>
+ThreadTask::ThreadTask(Task * internal, QObject *parent) : Task(parent), m_internal(internal)
+{
+}
+
+void ThreadTask::start()
+{
+ connect(m_internal, SIGNAL(failed(QString)), SLOT(iternal_failed(QString)));
+ connect(m_internal, SIGNAL(progress(qint64,qint64)), SLOT(iternal_progress(qint64,qint64)));
+ connect(m_internal, SIGNAL(started()), SLOT(iternal_started()));
+ connect(m_internal, SIGNAL(status(QString)), SLOT(iternal_status(QString)));
+ connect(m_internal, SIGNAL(succeeded()), SLOT(iternal_succeeded()));
+ m_running = true;
+ QtConcurrent::run(m_internal, &Task::start);
+}
+
+void ThreadTask::iternal_failed(QString reason)
+{
+ emitFailed(reason);
+}
+
+void ThreadTask::iternal_progress(qint64 current, qint64 total)
+{
+ progress(current, total);
+}
+
+void ThreadTask::iternal_started()
+{
+ emit started();
+}
+
+void ThreadTask::iternal_status(QString status)
+{
+ setStatus(status);
+}
+
+void ThreadTask::iternal_succeeded()
+{
+ emitSucceeded();
+}
diff --git a/logic/tasks/ThreadTask.h b/logic/tasks/ThreadTask.h
new file mode 100644
index 00000000..718dbc91
--- /dev/null
+++ b/logic/tasks/ThreadTask.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "Task.h"
+
+class ThreadTask : public Task
+{
+ Q_OBJECT
+public:
+ explicit ThreadTask(Task * internal, QObject * parent = nullptr);
+
+protected:
+ void executeTask() {};
+
+public slots:
+ virtual void start();
+
+private slots:
+ void iternal_started();
+ void iternal_progress(qint64 current, qint64 total);
+ void iternal_succeeded();
+ void iternal_failed(QString reason);
+ void iternal_status(QString status);
+private:
+ Task * m_internal;
+}; \ No newline at end of file