From b979d0ce5da515793a02802a6421ef607a498323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 18 Sep 2013 00:00:35 +0200 Subject: Implement legacy forge button! Many refactors of the task system. Progress dialog now accepts generic ProgressProvider objects --- gui/LegacyModEditDialog.cpp | 41 ++++++++++++++++- gui/LegacyModEditDialog.h | 2 + gui/LegacyModEditDialog.ui | 3 -- gui/OneSixModEditDialog.cpp | 22 +++++++-- gui/OneSixModEditDialog.h | 1 + gui/OneSixModEditDialog.ui | 2 +- gui/ProgressDialog.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++ gui/ProgressDialog.h | 62 +++++++++++++++++++++++++ gui/ProgressDialog.ui | 53 ++++++++++++++++++++++ gui/mainwindow.cpp | 8 ++-- gui/newinstancedialog.cpp | 2 +- gui/taskdialog.cpp | 107 ------------------------------------------- gui/taskdialog.h | 61 ------------------------- gui/taskdialog.ui | 53 ---------------------- gui/versionselectdialog.cpp | 19 +++----- gui/versionselectdialog.h | 5 +- gui/versionselectdialog.ui | 69 ---------------------------- 17 files changed, 298 insertions(+), 320 deletions(-) create mode 100644 gui/ProgressDialog.cpp create mode 100644 gui/ProgressDialog.h create mode 100644 gui/ProgressDialog.ui delete mode 100644 gui/taskdialog.cpp delete mode 100644 gui/taskdialog.h delete mode 100644 gui/taskdialog.ui (limited to 'gui') 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 +#include "logic/ModList.h" +#include "logic/lists/ForgeVersionList.h" + #include #include #include @@ -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(); + 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 #include "logic/LegacyInstance.h" +#include namespace Ui { class LegacyModEditDialog; @@ -64,4 +65,5 @@ private: QSharedPointer m_jarmods; QSharedPointer 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 @@ - - false - MCForge 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 +#include "logic/ModList.h" +#include "logic/OneSixVersion.h" +#include "logic/EnabledItemFilter.h" +#include "logic/lists/ForgeVersionList.h" +#include "gui/versionselectdialog.h" + #include #include #include #include #include -#include "logic/OneSixVersion.h" -#include 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 @@ - + Replace any current custom version with Minecraft Forge diff --git a/gui/ProgressDialog.cpp b/gui/ProgressDialog.cpp new file mode 100644 index 00000000..154ab1c0 --- /dev/null +++ b/gui/ProgressDialog.cpp @@ -0,0 +1,108 @@ +/* Copyright 2013 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 "ProgressDialog.h" +#include "ui_ProgressDialog.h" + +#include + +#include "logic/tasks/Task.h" + +ProgressDialog::ProgressDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ProgressDialog) +{ + ui->setupUi(this); + updateSize(); + + changeProgress(0,100); +} + +ProgressDialog::~ProgressDialog() +{ + delete ui; +} + +void ProgressDialog::updateSize() +{ + resize(QSize(480, minimumSizeHint().height())); +} + +int ProgressDialog::exec(ProgressProvider *task) +{ + this->task = task; + + // Connect signals. + connect(task, SIGNAL(started()), SLOT(onTaskStarted())); + 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, "start", Qt::QueuedConnection); + return QDialog::exec(); +} + +ProgressProvider* ProgressDialog::getTask() +{ + return task; +} + +void ProgressDialog::onTaskStarted() +{ + +} + +void ProgressDialog::onTaskFailed(QString failure) +{ + reject(); +} + +void ProgressDialog::onTaskSucceeded() +{ + accept(); +} + +void ProgressDialog::changeStatus(const QString &status) +{ + ui->statusLabel->setText(status); + updateSize(); +} + +void ProgressDialog::changeProgress(qint64 current, qint64 total) +{ + ui->taskProgressBar->setMaximum(total); + ui->taskProgressBar->setValue(current); +} + +void ProgressDialog::keyPressEvent(QKeyEvent* e) +{ + if (e->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(e); +} + +void ProgressDialog::closeEvent(QCloseEvent* e) +{ + if (task && task->isRunning()) + { + e->ignore(); + } + else + { + QDialog::closeEvent(e); + } +} diff --git a/gui/ProgressDialog.h b/gui/ProgressDialog.h new file mode 100644 index 00000000..ac6bb412 --- /dev/null +++ b/gui/ProgressDialog.h @@ -0,0 +1,62 @@ +/* Copyright 2013 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. + */ + +#ifndef TASKDIALOG_H +#define TASKDIALOG_H + +#include + +class ProgressProvider; + +namespace Ui { +class ProgressDialog; +} + +class ProgressDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProgressDialog(QWidget *parent = 0); + ~ProgressDialog(); + + void updateSize(); + + int exec(ProgressProvider* task); + + ProgressProvider* getTask(); + +public slots: + void onTaskStarted(); + void onTaskFailed(QString failure); + void onTaskSucceeded(); + + void changeStatus(const QString& status); + void changeProgress(qint64 current, qint64 total); + +signals: + + +protected: + virtual void keyPressEvent(QKeyEvent* e); + virtual void closeEvent(QCloseEvent* e); + +private: + Ui::ProgressDialog *ui; + + ProgressProvider* task; +}; + +#endif // TASKDIALOG_H diff --git a/gui/ProgressDialog.ui b/gui/ProgressDialog.ui new file mode 100644 index 00000000..a56d2a92 --- /dev/null +++ b/gui/ProgressDialog.ui @@ -0,0 +1,53 @@ + + + ProgressDialog + + + + 0 + 0 + 400 + 68 + + + + + 400 + 0 + + + + + 600 + 16777215 + + + + Please wait... + + + + + + Task Status... + + + true + + + + + + + 24 + + + false + + + + + + + + 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 diff --git a/gui/taskdialog.cpp b/gui/taskdialog.cpp deleted file mode 100644 index 8c745b38..00000000 --- a/gui/taskdialog.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright 2013 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 "taskdialog.h" -#include "ui_taskdialog.h" - -#include - -#include "logic/tasks/Task.h" - -TaskDialog::TaskDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::TaskDialog) -{ - ui->setupUi(this); - updateSize(); - - changeProgress(0); -} - -TaskDialog::~TaskDialog() -{ - delete ui; -} - -void TaskDialog::updateSize() -{ - resize(QSize(480, minimumSizeHint().height())); -} - -void TaskDialog::exec(Task *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))); - - // this makes sure that the task is started after the dialog is created - QMetaObject::invokeMethod(task, "startTask", Qt::QueuedConnection); - QDialog::exec(); -} - -Task* TaskDialog::getTask() -{ - return task; -} - -void TaskDialog::onTaskStarted() -{ - -} - -void TaskDialog::onTaskEnded() -{ - close(); -} - -void TaskDialog::changeStatus(const QString &status) -{ - ui->statusLabel->setText(status); - updateSize(); -} - -void TaskDialog::changeProgress(int progress) -{ - if (progress < 0) - progress = 0; - else if (progress > 100) - progress = 100; - - ui->taskProgressBar->setValue(progress); -} - -void TaskDialog::keyPressEvent(QKeyEvent* e) -{ - if (e->key() == Qt::Key_Escape) - return; - QDialog::keyPressEvent(e); -} - -void TaskDialog::closeEvent(QCloseEvent* e) -{ - if (task && task->isRunning()) - { - e->ignore(); - } - else - { - QDialog::closeEvent(e); - } -} diff --git a/gui/taskdialog.h b/gui/taskdialog.h deleted file mode 100644 index 3d31b7be..00000000 --- a/gui/taskdialog.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef TASKDIALOG_H -#define TASKDIALOG_H - -#include - -class Task; - -namespace Ui { -class TaskDialog; -} - -class TaskDialog : public QDialog -{ - Q_OBJECT - -public: - explicit TaskDialog(QWidget *parent = 0); - ~TaskDialog(); - - void updateSize(); - - void exec(Task* task); - - Task* getTask(); - -public slots: - void onTaskStarted(); - void onTaskEnded(); - - void changeStatus(const QString& status); - void changeProgress(int progress); - -signals: - - -protected: - virtual void keyPressEvent(QKeyEvent* e); - virtual void closeEvent(QCloseEvent* e); - -private: - Ui::TaskDialog *ui; - - Task* task; -}; - -#endif // TASKDIALOG_H diff --git a/gui/taskdialog.ui b/gui/taskdialog.ui deleted file mode 100644 index 1cdf7978..00000000 --- a/gui/taskdialog.ui +++ /dev/null @@ -1,53 +0,0 @@ - - - TaskDialog - - - - 0 - 0 - 400 - 58 - - - - - 400 - 0 - - - - - 600 - 16777215 - - - - Please wait... - - - - - - Task Status... - - - true - - - - - - - 24 - - - false - - - - - - - - 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 -#include +#include #include #include @@ -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 @@ -39,75 +39,6 @@ - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Show &snapshots? - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Show &Nostalgia? - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - -- cgit v1.2.3