summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-09-18 00:00:35 +0200
committerPetr Mrázek <peterix@gmail.com>2013-09-18 00:00:35 +0200
commitb979d0ce5da515793a02802a6421ef607a498323 (patch)
tree1431d15e7a3e89e87708564a5be9fea05a5647ab
parentd38b90530b3ba3a49c4eb072eb344ae2b0836913 (diff)
downloadMultiMC-b979d0ce5da515793a02802a6421ef607a498323.tar
MultiMC-b979d0ce5da515793a02802a6421ef607a498323.tar.gz
MultiMC-b979d0ce5da515793a02802a6421ef607a498323.tar.lz
MultiMC-b979d0ce5da515793a02802a6421ef607a498323.tar.xz
MultiMC-b979d0ce5da515793a02802a6421ef607a498323.zip
Implement legacy forge button!
Many refactors of the task system. Progress dialog now accepts generic ProgressProvider objects
-rw-r--r--CMakeLists.txt9
-rw-r--r--MultiMC.cpp1
-rw-r--r--gui/LegacyModEditDialog.cpp41
-rw-r--r--gui/LegacyModEditDialog.h2
-rw-r--r--gui/LegacyModEditDialog.ui3
-rw-r--r--gui/OneSixModEditDialog.cpp22
-rw-r--r--gui/OneSixModEditDialog.h1
-rw-r--r--gui/OneSixModEditDialog.ui2
-rw-r--r--gui/ProgressDialog.cpp (renamed from gui/taskdialog.cpp)57
-rw-r--r--gui/ProgressDialog.h (renamed from gui/taskdialog.h)23
-rw-r--r--gui/ProgressDialog.ui (renamed from gui/taskdialog.ui)6
-rw-r--r--gui/mainwindow.cpp8
-rw-r--r--gui/newinstancedialog.cpp2
-rw-r--r--gui/versionselectdialog.cpp19
-rw-r--r--gui/versionselectdialog.h5
-rw-r--r--gui/versionselectdialog.ui69
-rw-r--r--logic/BaseUpdate.cpp4
-rw-r--r--logic/InstanceLauncher.cpp4
-rw-r--r--logic/LegacyUpdate.cpp6
-rw-r--r--logic/OneSixUpdate.cpp4
-rw-r--r--logic/lists/ForgeVersionList.cpp93
-rw-r--r--logic/lists/ForgeVersionList.h10
-rw-r--r--logic/lists/MinecraftVersionList.h2
-rw-r--r--logic/net/DownloadJob.cpp2
-rw-r--r--logic/net/DownloadJob.h19
-rw-r--r--logic/tasks/ProgressProvider.h20
-rw-r--r--logic/tasks/Task.cpp48
-rw-r--r--logic/tasks/Task.h48
28 files changed, 295 insertions, 235 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d4f0cbbf..7f09e324 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -156,7 +156,7 @@ gui/mainwindow.h
gui/settingsdialog.h
gui/newinstancedialog.h
gui/logindialog.h
-gui/taskdialog.h
+gui/ProgressDialog.h
gui/aboutdialog.h
gui/consolewindow.h
gui/instancedelegate.h
@@ -228,6 +228,7 @@ logic/EnabledItemFilter.h
# Tasks
logic/tasks/Task.h
logic/tasks/LoginTask.h
+logic/tasks/ProgressProvider.h
)
@@ -239,13 +240,14 @@ gui/mainwindow.cpp
gui/settingsdialog.cpp
gui/newinstancedialog.cpp
gui/logindialog.cpp
-gui/taskdialog.cpp
gui/aboutdialog.cpp
gui/consolewindow.cpp
gui/instancedelegate.cpp
gui/versionselectdialog.cpp
gui/lwjglselectdialog.cpp
gui/instancesettings.cpp
+
+gui/ProgressDialog.cpp
gui/IconPickerDialog.cpp
gui/LegacyModEditDialog.cpp
gui/OneSixModEditDialog.cpp
@@ -313,12 +315,13 @@ gui/mainwindow.ui
gui/settingsdialog.ui
gui/newinstancedialog.ui
gui/logindialog.ui
-gui/taskdialog.ui
gui/aboutdialog.ui
gui/consolewindow.ui
gui/versionselectdialog.ui
gui/lwjglselectdialog.ui
gui/instancesettings.ui
+
+gui/ProgressDialog.ui
gui/IconPickerDialog.ui
gui/LegacyModEditDialog.ui
gui/OneSixModEditDialog.ui
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 08e5ed25..4b5b40b2 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -282,6 +282,7 @@ void MultiMC::initHttpMetaCache()
m_metacache->addBase("assets", QDir("assets").absolutePath());
m_metacache->addBase("versions", QDir("versions").absolutePath());
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
+ m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
m_metacache->Load();
}
diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp
index c336f837..ac7f7f25 100644
--- a/gui/LegacyModEditDialog.cpp
+++ b/gui/LegacyModEditDialog.cpp
@@ -13,10 +13,15 @@
* limitations under the License.
*/
+#include "MultiMC.h"
#include "LegacyModEditDialog.h"
#include "ModEditDialogCommon.h"
+#include "versionselectdialog.h"
+#include "ProgressDialog.h"
#include "ui_LegacyModEditDialog.h"
-#include <logic/ModList.h>
+#include "logic/ModList.h"
+#include "logic/lists/ForgeVersionList.h"
+
#include <pathutils.h>
#include <QFileDialog>
#include <QDebug>
@@ -194,7 +199,39 @@ void LegacyModEditDialog::on_addCoreBtn_clicked()
}
void LegacyModEditDialog::on_addForgeBtn_clicked()
{
-
+ VersionSelectDialog vselect(MMC->forgelist(), this);
+ vselect.setFilter(1, m_inst->intendedVersionId());
+ if (vselect.exec() && vselect.selectedVersion())
+ {
+ ForgeVersionPtr forge = vselect.selectedVersion().dynamicCast<ForgeVersion>();
+ if(!forge)
+ return;
+ auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename);
+ if(entry->stale)
+ {
+ DownloadJob * fjob = new DownloadJob("Forge download");
+ fjob->add(forge->universal_url, entry);
+ ProgressDialog dlg(this);
+ dlg.exec(fjob);
+ if(dlg.result() == QDialog::Accepted)
+ {
+ m_jarmods->stopWatching();
+ m_jarmods->installMod(QFileInfo(entry->getFullPath()));
+ m_jarmods->startWatching();
+ }
+ else
+ {
+ // failed to download forge :/
+ }
+ }
+ else
+ {
+ m_jarmods->stopWatching();
+ m_jarmods->installMod(QFileInfo(entry->getFullPath()));
+ m_jarmods->startWatching();
+ }
+ //m_selectedInstance->setIntendedVersionId(->descriptor());
+ }
}
void LegacyModEditDialog::on_addJarBtn_clicked()
{
diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h
index bc9ebac0..b824a86a 100644
--- a/gui/LegacyModEditDialog.h
+++ b/gui/LegacyModEditDialog.h
@@ -17,6 +17,7 @@
#include <QDialog>
#include "logic/LegacyInstance.h"
+#include <logic/net/DownloadJob.h>
namespace Ui {
class LegacyModEditDialog;
@@ -64,4 +65,5 @@ private:
QSharedPointer<ModList> m_jarmods;
QSharedPointer<ModList> m_texturepacks;
LegacyInstance * m_inst;
+ DownloadJobPtr forgeJob;
};
diff --git a/gui/LegacyModEditDialog.ui b/gui/LegacyModEditDialog.ui
index bd147c85..73b767dc 100644
--- a/gui/LegacyModEditDialog.ui
+++ b/gui/LegacyModEditDialog.ui
@@ -52,9 +52,6 @@
</item>
<item>
<widget class="QPushButton" name="addForgeBtn">
- <property name="enabled">
- <bool>false</bool>
- </property>
<property name="text">
<string>MCForge</string>
</property>
diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp
index f778127f..fad9d2e2 100644
--- a/gui/OneSixModEditDialog.cpp
+++ b/gui/OneSixModEditDialog.cpp
@@ -12,18 +12,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#include "MultiMC.h"
#include "OneSixModEditDialog.h"
#include "ModEditDialogCommon.h"
#include "ui_OneSixModEditDialog.h"
-#include <logic/ModList.h>
+#include "logic/ModList.h"
+#include "logic/OneSixVersion.h"
+#include "logic/EnabledItemFilter.h"
+#include "logic/lists/ForgeVersionList.h"
+#include "gui/versionselectdialog.h"
+
#include <pathutils.h>
#include <QFileDialog>
#include <QDebug>
#include <QEvent>
#include <QKeyEvent>
-#include "logic/OneSixVersion.h"
-#include <logic/EnabledItemFilter.h>
OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent):
m_inst(inst),
@@ -66,6 +69,17 @@ OneSixModEditDialog::~OneSixModEditDialog()
delete ui;
}
+void OneSixModEditDialog::on_forgeBtn_clicked()
+{
+ VersionSelectDialog vselect(MMC->forgelist(), this);
+ vselect.setFilter(1, m_inst->currentVersionId());
+ if (vselect.exec() && vselect.selectedVersion())
+ {
+ //m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor());
+ }
+}
+
+
bool OneSixModEditDialog::loaderListFilter ( QKeyEvent* keyEvent )
{
switch(keyEvent->key())
diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h
index c637df01..d14c842c 100644
--- a/gui/OneSixModEditDialog.h
+++ b/gui/OneSixModEditDialog.h
@@ -40,6 +40,7 @@ private slots:
void on_viewResPackBtn_clicked();
// Questionable: SettingsDialog doesn't need this for some reason?
void on_buttonBox_rejected();
+ void on_forgeBtn_clicked();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
bool loaderListFilter( QKeyEvent* ev );
diff --git a/gui/OneSixModEditDialog.ui b/gui/OneSixModEditDialog.ui
index bffcaed0..aadaf3ae 100644
--- a/gui/OneSixModEditDialog.ui
+++ b/gui/OneSixModEditDialog.ui
@@ -64,7 +64,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
- <widget class="QPushButton" name="forgeBrn">
+ <widget class="QPushButton" name="forgeBtn">
<property name="toolTip">
<string>Replace any current custom version with Minecraft Forge</string>
</property>
diff --git a/gui/taskdialog.cpp b/gui/ProgressDialog.cpp
index 8c745b38..154ab1c0 100644
--- a/gui/taskdialog.cpp
+++ b/gui/ProgressDialog.cpp
@@ -13,88 +13,89 @@
* limitations under the License.
*/
-#include "taskdialog.h"
-#include "ui_taskdialog.h"
+#include "ProgressDialog.h"
+#include "ui_ProgressDialog.h"
#include <QKeyEvent>
#include "logic/tasks/Task.h"
-TaskDialog::TaskDialog(QWidget *parent) :
+ProgressDialog::ProgressDialog(QWidget *parent) :
QDialog(parent),
- ui(new Ui::TaskDialog)
+ ui(new Ui::ProgressDialog)
{
ui->setupUi(this);
updateSize();
- changeProgress(0);
+ changeProgress(0,100);
}
-TaskDialog::~TaskDialog()
+ProgressDialog::~ProgressDialog()
{
delete ui;
}
-void TaskDialog::updateSize()
+void ProgressDialog::updateSize()
{
resize(QSize(480, minimumSizeHint().height()));
}
-void TaskDialog::exec(Task *task)
+int ProgressDialog::exec(ProgressProvider *task)
{
this->task = task;
// Connect signals.
connect(task, SIGNAL(started()), SLOT(onTaskStarted()));
- connect(task, SIGNAL(failed(QString)), SLOT(onTaskEnded()));
- connect(task, SIGNAL(succeeded()), SLOT(onTaskEnded()));
- connect(task, SIGNAL(statusChanged(const QString&)), SLOT(changeStatus(const QString&)));
- connect(task, SIGNAL(progressChanged(int)), SLOT(changeProgress(int)));
+ connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString)));
+ connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded()));
+ connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString&)));
+ connect(task, SIGNAL(progress(qint64,qint64)), SLOT(changeProgress(qint64,qint64)));
// this makes sure that the task is started after the dialog is created
- QMetaObject::invokeMethod(task, "startTask", Qt::QueuedConnection);
- QDialog::exec();
+ QMetaObject::invokeMethod(task, "start", Qt::QueuedConnection);
+ return QDialog::exec();
}
-Task* TaskDialog::getTask()
+ProgressProvider* ProgressDialog::getTask()
{
return task;
}
-void TaskDialog::onTaskStarted()
+void ProgressDialog::onTaskStarted()
{
}
-void TaskDialog::onTaskEnded()
+void ProgressDialog::onTaskFailed(QString failure)
{
- close();
+ reject();
}
-void TaskDialog::changeStatus(const QString &status)
+void ProgressDialog::onTaskSucceeded()
+{
+ accept();
+}
+
+void ProgressDialog::changeStatus(const QString &status)
{
ui->statusLabel->setText(status);
updateSize();
}
-void TaskDialog::changeProgress(int progress)
+void ProgressDialog::changeProgress(qint64 current, qint64 total)
{
- if (progress < 0)
- progress = 0;
- else if (progress > 100)
- progress = 100;
-
- ui->taskProgressBar->setValue(progress);
+ ui->taskProgressBar->setMaximum(total);
+ ui->taskProgressBar->setValue(current);
}
-void TaskDialog::keyPressEvent(QKeyEvent* e)
+void ProgressDialog::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape)
return;
QDialog::keyPressEvent(e);
}
-void TaskDialog::closeEvent(QCloseEvent* e)
+void ProgressDialog::closeEvent(QCloseEvent* e)
{
if (task && task->isRunning())
{
diff --git a/gui/taskdialog.h b/gui/ProgressDialog.h
index 3d31b7be..ac6bb412 100644
--- a/gui/taskdialog.h
+++ b/gui/ProgressDialog.h
@@ -18,32 +18,33 @@
#include <QDialog>
-class Task;
+class ProgressProvider;
namespace Ui {
-class TaskDialog;
+class ProgressDialog;
}
-class TaskDialog : public QDialog
+class ProgressDialog : public QDialog
{
Q_OBJECT
public:
- explicit TaskDialog(QWidget *parent = 0);
- ~TaskDialog();
+ explicit ProgressDialog(QWidget *parent = 0);
+ ~ProgressDialog();
void updateSize();
- void exec(Task* task);
+ int exec(ProgressProvider* task);
- Task* getTask();
+ ProgressProvider* getTask();
public slots:
void onTaskStarted();
- void onTaskEnded();
+ void onTaskFailed(QString failure);
+ void onTaskSucceeded();
void changeStatus(const QString& status);
- void changeProgress(int progress);
+ void changeProgress(qint64 current, qint64 total);
signals:
@@ -53,9 +54,9 @@ protected:
virtual void closeEvent(QCloseEvent* e);
private:
- Ui::TaskDialog *ui;
+ Ui::ProgressDialog *ui;
- Task* task;
+ ProgressProvider* task;
};
#endif // TASKDIALOG_H
diff --git a/gui/taskdialog.ui b/gui/ProgressDialog.ui
index 1cdf7978..a56d2a92 100644
--- a/gui/taskdialog.ui
+++ b/gui/ProgressDialog.ui
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>TaskDialog</class>
- <widget class="QDialog" name="TaskDialog">
+ <class>ProgressDialog</class>
+ <widget class="QDialog" name="ProgressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
- <height>58</height>
+ <height>68</height>
</rect>
</property>
<property name="minimumSize">
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 241df383..6f707236 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -42,7 +42,7 @@
#include "gui/settingsdialog.h"
#include "gui/newinstancedialog.h"
#include "gui/logindialog.h"
-#include "gui/taskdialog.h"
+#include "gui/ProgressDialog.h"
#include "gui/aboutdialog.h"
#include "gui/versionselectdialog.h"
#include "gui/lwjglselectdialog.h"
@@ -479,7 +479,7 @@ void MainWindow::doLogin(const QString& errorMsg)
{
UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()};
- TaskDialog* tDialog = new TaskDialog(this);
+ ProgressDialog* tDialog = new ProgressDialog(this);
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection);
connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection);
@@ -512,7 +512,7 @@ void MainWindow::onLoginComplete()
}
else
{
- TaskDialog *tDialog = new TaskDialog(this);
+ ProgressDialog *tDialog = new ProgressDialog(this);
connect(updateTask, SIGNAL(succeeded()),SLOT(onGameUpdateComplete()));
connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
tDialog->exec(updateTask);
@@ -575,7 +575,7 @@ void MainWindow::startTask(Task *task)
connect(task, SIGNAL(started()), SLOT(taskStart()));
connect(task, SIGNAL(succeeded()), SLOT(taskEnd()));
connect(task, SIGNAL(failed(QString)), SLOT(taskEnd()));
- task->startTask();
+ task->start();
}
diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp
index af2b11c5..6604d03b 100644
--- a/gui/newinstancedialog.cpp
+++ b/gui/newinstancedialog.cpp
@@ -24,7 +24,7 @@
#include "logic/tasks/Task.h"
#include "versionselectdialog.h"
-#include "taskdialog.h"
+#include "ProgressDialog.h"
#include "IconPickerDialog.h"
#include <QLayout>
diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp
index b14956fd..1e60c7d9 100644
--- a/gui/versionselectdialog.cpp
+++ b/gui/versionselectdialog.cpp
@@ -20,7 +20,7 @@
#include <QDebug>
-#include <gui/taskdialog.h>
+#include <gui/ProgressDialog.h>
#include <logic/BaseVersion.h>
#include <logic/lists/BaseVersionList.h>
@@ -41,11 +41,6 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QWidget *parent
ui->listView->setModel(m_proxyModel);
ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->listView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
-
- connect(ui->filterSnapshotsCheckbox, SIGNAL(clicked()), SLOT(updateFilterState()));
- connect(ui->filterMCNostalgiaCheckbox, SIGNAL(clicked()), SLOT(updateFilterState()));
-
- updateFilterState();
}
VersionSelectDialog::~VersionSelectDialog()
@@ -63,7 +58,7 @@ int VersionSelectDialog::exec()
void VersionSelectDialog::loadList()
{
- TaskDialog *taskDlg = new TaskDialog(this);
+ ProgressDialog *taskDlg = new ProgressDialog(this);
Task *loadTask = m_vlist->getLoadTask();
loadTask->setParent(taskDlg);
taskDlg->exec(loadTask);
@@ -81,10 +76,11 @@ void VersionSelectDialog::on_refreshButton_clicked()
loadList();
}
-void VersionSelectDialog::updateFilterState()
+void VersionSelectDialog::setFilter(int column, QString filter)
{
- m_proxyModel->setFilterKeyColumn(BaseVersionList::TypeColumn);
-
+ m_proxyModel->setFilterKeyColumn(column);
+ m_proxyModel->setFilterFixedString(filter);
+ /*
QStringList filteredTypes;
if (!ui->filterSnapshotsCheckbox->isChecked())
filteredTypes += "Snapshot";
@@ -96,6 +92,5 @@ void VersionSelectDialog::updateFilterState()
regexStr = QString("^((?!%1).)*$").arg(filteredTypes.join('|'));
qDebug() << "Filter:" << regexStr;
-
- m_proxyModel->setFilterRegExp(regexStr);
+ */
}
diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h
index 57e4d0df..0bb1745a 100644
--- a/gui/versionselectdialog.h
+++ b/gui/versionselectdialog.h
@@ -43,11 +43,10 @@ public:
BaseVersionPtr selectedVersion() const;
+ void setFilter(int column, QString filter);
+
private slots:
void on_refreshButton_clicked();
-
- void updateFilterState();
-
private:
Ui::VersionSelectDialog *ui;
diff --git a/gui/versionselectdialog.ui b/gui/versionselectdialog.ui
index 02937794..222f29cf 100644
--- a/gui/versionselectdialog.ui
+++ b/gui/versionselectdialog.ui
@@ -40,75 +40,6 @@
</widget>
</item>
<item>
- <layout class="QHBoxLayout" name="filterCheckboxLayout1">
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QCheckBox" name="filterSnapshotsCheckbox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Show &amp;snapshots?</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QCheckBox" name="filterMCNostalgiaCheckbox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Show &amp;Nostalgia?</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_3">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="refreshButton">
diff --git a/logic/BaseUpdate.cpp b/logic/BaseUpdate.cpp
index b086ab14..02b29d32 100644
--- a/logic/BaseUpdate.cpp
+++ b/logic/BaseUpdate.cpp
@@ -7,7 +7,5 @@ BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent )
void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total)
{
- // The progress on the current file is current / total
- float currentDLProgress = (float) current / (float) total;
- setProgress((int)(currentDLProgress * 100)); // convert to percentage
+ emit progress(current, total);
} \ No newline at end of file
diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp
index a0557b37..f2f792c9 100644
--- a/logic/InstanceLauncher.cpp
+++ b/logic/InstanceLauncher.cpp
@@ -3,7 +3,7 @@
#include <iostream>
#include "gui/logindialog.h"
-#include "gui/taskdialog.h"
+#include "gui/ProgressDialog.h"
#include "gui/consolewindow.h"
#include "logic/tasks/LoginTask.h"
#include "logic/MinecraftProcess.h"
@@ -48,7 +48,7 @@ void InstanceLauncher::doLogin ( const QString& errorMsg )
{
UserInfo uInfo {loginDlg->getUsername(), loginDlg->getPassword() };
- TaskDialog* tDialog = new TaskDialog ( nullptr );
+ ProgressDialog* tDialog = new ProgressDialog ( nullptr );
LoginTask* loginTask = new LoginTask ( uInfo, tDialog );
connect ( loginTask, SIGNAL ( succeeded() ),SLOT ( onLoginComplete() ), Qt::QueuedConnection );
connect ( loginTask, SIGNAL ( failed ( QString ) ),SLOT ( doLogin ( QString ) ), Qt::QueuedConnection );
diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp
index 25be5e7d..0f58e3e3 100644
--- a/logic/LegacyUpdate.cpp
+++ b/logic/LegacyUpdate.cpp
@@ -59,7 +59,7 @@ void LegacyUpdate::lwjglStart()
QNetworkReply * rep = worker->get ( req );
m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
- connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
connect(worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*)));
//connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError)));
}
@@ -97,7 +97,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
req.setRawHeader("Host", hostname.toLatin1());
req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)");
QNetworkReply * rep = worker->get(req);
- connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
return;
}
@@ -232,7 +232,7 @@ void LegacyUpdate::jarStart()
legacyDownloadJob.reset(dljob);
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
connect(dljob, SIGNAL(failed()), SLOT(jarFailed()));
- connect(dljob, SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ connect(dljob, SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
legacyDownloadJob->start();
}
diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp
index 67395818..298ad28a 100644
--- a/logic/OneSixUpdate.cpp
+++ b/logic/OneSixUpdate.cpp
@@ -78,7 +78,7 @@ void OneSixUpdate::versionFileStart()
specificVersionDownloadJob.reset(job);
connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), SLOT(versionFileFinished()));
connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
- connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
specificVersionDownloadJob->start();
}
@@ -171,7 +171,7 @@ void OneSixUpdate::jarlibStart()
}
connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished()));
connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed()));
- connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
jarlibDownloadJob->start();
}
diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp
index f45b8b6b..412c04fe 100644
--- a/logic/lists/ForgeVersionList.cpp
+++ b/logic/lists/ForgeVersionList.cpp
@@ -50,21 +50,90 @@ int ForgeVersionList::count() const
{
return m_vlist.count();
}
-/*
-bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
+
+int ForgeVersionList::columnCount(const QModelIndex& parent) const
{
- const BaseVersion & left = *first;
- const BaseVersion & right = *second;
- return left > right;
+ return 3;
}
-void MinecraftVersionList::sort()
+QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
{
- beginResetModel();
- qSort(m_vlist.begin(), m_vlist.end(), cmpVersions);
- endResetModel();
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() > count())
+ return QVariant();
+
+ auto version = m_vlist[index.row()].dynamicCast<ForgeVersion>();
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (index.column())
+ {
+ case 0:
+ return version->name();
+
+ case 1:
+ return version->mcver;
+
+ case 2:
+ return version->typeString();
+ default:
+ return QVariant();
+ }
+
+ case Qt::ToolTipRole:
+ return version->descriptor();
+
+ case VersionPointerRole:
+ return qVariantFromValue(m_vlist[index.row()]);
+
+ default:
+ return QVariant();
+ }
}
-*/
+
+QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (section)
+ {
+ case 0:
+ return "Version";
+
+ case 1:
+ return "Minecraft";
+
+ case 2:
+ return "Type";
+
+ default:
+ return QVariant();
+ }
+
+ case Qt::ToolTipRole:
+ switch (section)
+ {
+ case 0:
+ return "The name of the version.";
+
+ case 1:
+ return "Minecraft version";
+
+ case 2:
+ return "The version's type.";
+
+ default:
+ return QVariant();
+ }
+
+ default:
+ return QVariant();
+ }
+}
+
BaseVersionPtr ForgeVersionList::getLatestStable() const
{
return BaseVersionPtr();
@@ -99,7 +168,7 @@ void ForgeListLoadTask::executeTask()
listJob.reset(job);
connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded()));
connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
- connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
listJob->start();
}
@@ -148,7 +217,7 @@ void ForgeListLoadTask::list_downloaded()
int build_nr = obj.value("build").toDouble(0);
if(!build_nr)
continue;
- QJsonArray files = root.value("files").toArray();
+ QJsonArray files = obj.value("files").toArray();
QString url, jobbuildver, mcver, buildtype, filename;
QString changelog_url, installer_url;
bool valid = false;
diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h
index 8d4a2d46..ca6b27bc 100644
--- a/logic/lists/ForgeVersionList.h
+++ b/logic/lists/ForgeVersionList.h
@@ -26,7 +26,7 @@
#include "logic/net/DownloadJob.h"
class ForgeVersion;
-typedef QSharedPointer<ForgeVersion> PtrForgeVersion;
+typedef QSharedPointer<ForgeVersion> ForgeVersionPtr;
struct ForgeVersion : public BaseVersion
{
@@ -36,7 +36,7 @@ struct ForgeVersion : public BaseVersion
};
virtual QString name()
{
- return "Forge " + jobbuildver + " (" + mcver + ")";
+ return "Forge " + jobbuildver;
};
virtual QString typeString() const
{
@@ -71,8 +71,12 @@ public:
virtual BaseVersionPtr getLatestStable() const;
+ virtual QVariant data(const QModelIndex& index, int role) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ virtual int columnCount(const QModelIndex& parent) const;
+
protected:
- QList<BaseVersionPtr > m_vlist;
+ QList<BaseVersionPtr> m_vlist;
bool m_loaded;
diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h
index 8937ba7b..fb28ddfe 100644
--- a/logic/lists/MinecraftVersionList.h
+++ b/logic/lists/MinecraftVersionList.h
@@ -49,7 +49,7 @@ protected:
bool m_loaded;
protected slots:
- virtual void updateListData(QList<BaseVersionPtr > versions);
+ virtual void updateListData(QList<BaseVersionPtr> versions);
};
class MCVListLoadTask : public Task
diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp
index 9b083b6b..3acba050 100644
--- a/logic/net/DownloadJob.cpp
+++ b/logic/net/DownloadJob.cpp
@@ -5,6 +5,8 @@
#include "ByteArrayDownload.h"
#include "CacheDownload.h"
+#include <QDebug>
+
ByteArrayDownloadPtr DownloadJob::add ( QUrl url )
{
ByteArrayDownloadPtr ptr (new ByteArrayDownload(url));
diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h
index 69a49e59..c8f6a9d7 100644
--- a/logic/net/DownloadJob.h
+++ b/logic/net/DownloadJob.h
@@ -5,6 +5,7 @@
#include "FileDownload.h"
#include "CacheDownload.h"
#include "HttpMetaCache.h"
+#include "logic/tasks/ProgressProvider.h"
class DownloadJob;
typedef QSharedPointer<DownloadJob> DownloadJobPtr;
@@ -12,12 +13,12 @@ typedef QSharedPointer<DownloadJob> DownloadJobPtr;
/**
* A single file for the downloader/cache to process.
*/
-class DownloadJob : public QObject
+class DownloadJob : public ProgressProvider
{
Q_OBJECT
public:
explicit DownloadJob(QString job_name)
- :QObject(), m_job_name(job_name){};
+ :ProgressProvider(), m_job_name(job_name){};
ByteArrayDownloadPtr add(QUrl url);
FileDownloadPtr add(QUrl url, QString rel_target_path);
@@ -37,6 +38,19 @@ public:
{
return downloads.size();
}
+ virtual void getProgress(qint64& current, qint64& total)
+ {
+ current = current_progress;
+ total = total_progress;
+ };
+ virtual QString getStatus() const
+ {
+ return m_job_name;
+ };
+ virtual bool isRunning() const
+ {
+ return m_running;
+ };
signals:
void started();
void progress(qint64 current, qint64 total);
@@ -56,5 +70,6 @@ private:
qint64 total_progress = 0;
int num_succeeded = 0;
int num_failed = 0;
+ bool m_running = false;
};
diff --git a/logic/tasks/ProgressProvider.h b/logic/tasks/ProgressProvider.h
new file mode 100644
index 00000000..e158eb54
--- /dev/null
+++ b/logic/tasks/ProgressProvider.h
@@ -0,0 +1,20 @@
+#pragma once
+#include <QObject>
+class ProgressProvider : public QObject
+{
+ Q_OBJECT
+protected:
+ explicit ProgressProvider(QObject* parent = 0): QObject(parent){}
+signals:
+ void started();
+ void progress(qint64 current, qint64 total);
+ void succeeded();
+ void failed(QString reason);
+ void status(QString status);
+public:
+ virtual QString getStatus() const = 0;
+ virtual void getProgress(qint64 &current, qint64 &total) = 0;
+ virtual bool isRunning() const = 0;
+public slots:
+ virtual void start() = 0;
+};
diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp
index 7c148591..c75bcb8f 100644
--- a/logic/tasks/Task.cpp
+++ b/logic/tasks/Task.cpp
@@ -16,70 +16,56 @@
#include "Task.h"
Task::Task(QObject *parent) :
- QObject(parent)
+ ProgressProvider(parent)
{
}
QString Task::getStatus() const
{
- return status;
+ return m_status;
}
-void Task::setStatus(const QString &status)
+void Task::setStatus(const QString &new_status)
{
- this->status = status;
- emitStatusChange(status);
+ m_status = new_status;
+ emit status(new_status);
}
-int Task::getProgress() const
+void Task::setProgress(int new_progress)
{
- return progress;
+ m_progress = new_progress;
+ emit progress(new_progress, 100);
}
-void Task::setProgress(int progress)
+void Task::getProgress(qint64& current, qint64& total)
{
- this->progress = progress;
- emitProgressChange(progress);
+ current = m_progress;
+ total = 100;
}
-void Task::startTask()
-{
- emitStarted();
- executeTask();
-}
-void Task::emitStarted()
+void Task::start()
{
- running = true;
+ m_running = true;
emit started();
+ executeTask();
}
void Task::emitFailed(QString reason)
{
- running = false;
+ m_running = false;
emit failed(reason);
}
void Task::emitSucceeded()
{
- running = false;
+ m_running = false;
emit succeeded();
}
bool Task::isRunning() const
{
- return running;
-}
-
-
-void Task::emitStatusChange(const QString &status)
-{
- emit statusChanged(status);
-}
-
-void Task::emitProgressChange(int progress)
-{
- emit progressChanged(progress);
+ return m_running;
}
diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h
index 91852b0f..cfe71c51 100644
--- a/logic/tasks/Task.h
+++ b/logic/tasks/Task.h
@@ -13,53 +13,37 @@
* limitations under the License.
*/
-#ifndef TASK_H
-#define TASK_H
+#pragma once
#include <QObject>
#include <QString>
+#include "ProgressProvider.h"
-class Task : public QObject
+class Task : public ProgressProvider
{
Q_OBJECT
public:
explicit Task(QObject *parent = 0);
- QString getStatus() const;
- int getProgress() const;
- bool isRunning() const;
+ virtual QString getStatus() const;
+ virtual void getProgress(qint64& current, qint64& total);
+ virtual bool isRunning() const;
public slots:
- void startTask();
-
-protected slots:
- void setStatus(const QString& status);
- void setProgress(int progress);
-
-signals:
- void started();
- void failed(QString reason);
- void succeeded();
-
- void statusChanged(Task* task, const QString& status);
- void progressChanged(Task* task, int progress);
-
- void statusChanged(const QString& status);
- void progressChanged(int progress);
+ virtual void start();
protected:
virtual void executeTask() = 0;
- virtual void emitStarted();
- virtual void emitFailed(QString reason);
virtual void emitSucceeded();
+ virtual void emitFailed(QString reason);
+
+protected slots:
+ void setStatus(const QString& status);
+ void setProgress(int progress);
- virtual void emitStatusChange(const QString &status);
- virtual void emitProgressChange(int progress);
-
- QString status;
- int progress;
- bool running = false;
+protected:
+ QString m_status;
+ int m_progress = 0;
+ bool m_running = false;
};
-
-#endif // TASK_H