From 47e37635f50c09b4f9a9ee7699e3120bab3e4088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 10 Apr 2016 04:29:29 +0200 Subject: NOISSUE split GUI stuff from logic library --- logic/tasks/SequentialTask.cpp | 55 ------------------------ logic/tasks/SequentialTask.h | 31 -------------- logic/tasks/Task.cpp | 88 -------------------------------------- logic/tasks/Task.h | 96 ------------------------------------------ logic/tasks/ThreadTask.cpp | 41 ------------------ logic/tasks/ThreadTask.h | 25 ----------- 6 files changed, 336 deletions(-) delete mode 100644 logic/tasks/SequentialTask.cpp delete mode 100644 logic/tasks/SequentialTask.h delete mode 100644 logic/tasks/Task.cpp delete mode 100644 logic/tasks/Task.h delete mode 100644 logic/tasks/ThreadTask.cpp delete mode 100644 logic/tasks/ThreadTask.h (limited to 'logic/tasks') diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp deleted file mode 100644 index ac0e7820..00000000 --- a/logic/tasks/SequentialTask.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "SequentialTask.h" - -SequentialTask::SequentialTask(QObject *parent) : Task(parent), m_currentIndex(-1) -{ -} - -void SequentialTask::addTask(std::shared_ptr task) -{ - m_queue.append(task); -} - -void SequentialTask::executeTask() -{ - m_currentIndex = -1; - startNext(); -} - -void SequentialTask::startNext() -{ - if (m_currentIndex != -1) - { - std::shared_ptr previous = m_queue[m_currentIndex]; - disconnect(previous.get(), 0, this, 0); - } - m_currentIndex++; - if (m_queue.isEmpty() || m_currentIndex >= m_queue.size()) - { - emitSucceeded(); - return; - } - std::shared_ptr 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(qint64, qint64))); - connect(next.get(), SIGNAL(succeeded()), this, SLOT(startNext())); - next->start(); -} - -void SequentialTask::subTaskFailed(const QString &msg) -{ - emitFailed(msg); -} -void SequentialTask::subTaskStatus(const QString &msg) -{ - setStatus(msg); -} -void SequentialTask::subTaskProgress(qint64 current, qint64 total) -{ - if(total == 0) - { - setProgress(0, 100); - return; - } - setProgress(current, total); -} diff --git a/logic/tasks/SequentialTask.h b/logic/tasks/SequentialTask.h deleted file mode 100644 index 69031095..00000000 --- a/logic/tasks/SequentialTask.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "Task.h" - -#include -#include - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT SequentialTask : public Task -{ - Q_OBJECT -public: - explicit SequentialTask(QObject *parent = 0); - - void addTask(std::shared_ptr task); - -protected: - void executeTask(); - -private -slots: - void startNext(); - void subTaskFailed(const QString &msg); - void subTaskStatus(const QString &msg); - void subTaskProgress(qint64 current, qint64 total); - -private: - QQueue > m_queue; - int m_currentIndex; -}; diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp deleted file mode 100644 index 3c4e3188..00000000 --- a/logic/tasks/Task.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Task.h" - -#include - -Task::Task(QObject *parent) : QObject(parent) -{ -} - -void Task::setStatus(const QString &new_status) -{ - if(m_status != new_status) - { - m_status = new_status; - emit status(m_status); - } -} - -void Task::setProgress(qint64 current, qint64 total) -{ - m_progress = current; - m_progressTotal = total; - emit progress(m_progress, m_progressTotal); -} - -void Task::start() -{ - m_running = true; - emit started(); - executeTask(); -} - -void Task::emitFailed(QString reason) -{ - m_running = false; - m_finished = true; - m_succeeded = false; - m_failReason = reason; - qCritical() << "Task failed: " << reason; - emit failed(reason); - emit finished(); -} - -void Task::emitSucceeded() -{ - if (!m_running) { return; } // Don't succeed twice. - m_running = false; - m_finished = true; - m_succeeded = true; - qDebug() << "Task succeeded"; - emit succeeded(); - emit finished(); -} - -bool Task::isRunning() const -{ - return m_running; -} - -bool Task::isFinished() const -{ - return m_finished; -} - -bool Task::successful() const -{ - return m_succeeded; -} - -QString Task::failReason() const -{ - return m_failReason; -} - diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h deleted file mode 100644 index 2b0ccbcd..00000000 --- a/logic/tasks/Task.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT Task : public QObject -{ - Q_OBJECT -public: - explicit Task(QObject *parent = 0); - virtual ~Task() {}; - - virtual bool isRunning() const; - - virtual bool isFinished() const; - - /*! - * True if this task was successful. - * If the task failed or is still running, returns false. - */ - virtual bool successful() const; - - /*! - * Returns the string that was passed to emitFailed as the error message when the task failed. - * If the task hasn't failed, returns an empty string. - */ - virtual QString failReason() const; - - virtual bool canAbort() const { return false; } - - QString getStatus() - { - return m_status; - } - - qint64 getProgress() - { - return m_progress; - } - - qint64 getTotalProgress() - { - return m_progressTotal; - } - -signals: - void started(); - void progress(qint64 current, qint64 total); - void finished(); - void succeeded(); - void failed(QString reason); - void status(QString status); - -public -slots: - virtual void start(); - virtual bool abort() { return false; }; - -protected: - virtual void executeTask() = 0; - -protected slots: - virtual void emitSucceeded(); - virtual void emitFailed(QString reason); - -public slots: - void setStatus(const QString &status); - void setProgress(qint64 current, qint64 total); - -protected: - bool m_running = false; - bool m_finished = false; - bool m_succeeded = false; - QString m_failReason = ""; - QString m_status; - int m_progress = 0; - int m_progressTotal = 100; -}; - diff --git a/logic/tasks/ThreadTask.cpp b/logic/tasks/ThreadTask.cpp deleted file mode 100644 index ddd1dee5..00000000 --- a/logic/tasks/ThreadTask.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "ThreadTask.h" -#include -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 deleted file mode 100644 index 718dbc91..00000000 --- a/logic/tasks/ThreadTask.h +++ /dev/null @@ -1,25 +0,0 @@ -#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 -- cgit v1.2.3