From 7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 11 Sep 2013 23:43:17 +0200 Subject: Split OneSixVersion into parts. --- logic/OneSixUpdate.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'logic/OneSixUpdate.cpp') diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index ce71bde0..a58a9626 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -28,6 +28,7 @@ #include "lists/MinecraftVersionList.h" #include "VersionFactory.h" #include "OneSixVersion.h" +#include "OneSixLibrary.h" #include "OneSixInstance.h" #include "pathutils.h" -- cgit From d38b90530b3ba3a49c4eb072eb344ae2b0836913 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 16 Sep 2013 00:54:39 +0200 Subject: Forge version list implementation. Needs integration and testing. --- CMakeLists.txt | 18 +++- MultiMC.cpp | 45 ++++++++ MultiMC.h | 13 +++ gui/ModListView.cpp | 3 +- gui/OneSixModEditDialog.cpp | 12 ++- gui/OneSixModEditDialog.h | 1 + gui/OneSixModEditDialog.ui | 135 +++++++++++++++++++---- gui/lwjglselectdialog.cpp | 16 +-- gui/mainwindow.cpp | 12 +-- gui/newinstancedialog.cpp | 14 +-- gui/newinstancedialog.h | 8 +- gui/versionselectdialog.cpp | 14 +-- gui/versionselectdialog.h | 10 +- logic/BaseInstance.cpp | 5 +- logic/BaseInstance.h | 4 +- logic/BaseVersion.h | 45 ++++++++ logic/EnabledItemFilter.cpp | 30 ++++++ logic/EnabledItemFilter.h | 16 +++ logic/InstanceFactory.cpp | 10 +- logic/InstanceFactory.h | 6 +- logic/InstanceVersion.h | 68 ------------ logic/LegacyUpdate.cpp | 8 +- logic/MinecraftVersion.h | 29 +++-- logic/OneSixInstance.cpp | 21 +++- logic/OneSixInstance.h | 2 + logic/OneSixLibrary.cpp | 13 ++- logic/OneSixLibrary.h | 22 ++++ logic/OneSixUpdate.cpp | 47 +++++--- logic/OneSixVersion.cpp | 71 +++++++++++++ logic/OneSixVersion.h | 11 +- logic/lists/BaseVersionList.cpp | 123 +++++++++++++++++++++ logic/lists/BaseVersionList.h | 121 +++++++++++++++++++++ logic/lists/ForgeVersionList.cpp | 200 +++++++++++++++++++++++++++++++++++ logic/lists/ForgeVersionList.h | 98 +++++++++++++++++ logic/lists/InstVersionList.cpp | 129 ---------------------- logic/lists/InstVersionList.h | 121 --------------------- logic/lists/LwjglVersionList.cpp | 8 -- logic/lists/LwjglVersionList.h | 2 - logic/lists/MinecraftVersionList.cpp | 34 ++---- logic/lists/MinecraftVersionList.h | 21 ++-- 40 files changed, 1091 insertions(+), 475 deletions(-) create mode 100644 logic/BaseVersion.h create mode 100644 logic/EnabledItemFilter.cpp create mode 100644 logic/EnabledItemFilter.h delete mode 100644 logic/InstanceVersion.h create mode 100644 logic/lists/BaseVersionList.cpp create mode 100644 logic/lists/BaseVersionList.h create mode 100644 logic/lists/ForgeVersionList.cpp create mode 100644 logic/lists/ForgeVersionList.h delete mode 100644 logic/lists/InstVersionList.cpp delete mode 100644 logic/lists/InstVersionList.h (limited to 'logic/OneSixUpdate.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index feb46278..d4f0cbbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,7 @@ gui/LabeledToolButton.h gui/EditNotesDialog.h # Base classes and infrastructure -logic/InstanceVersion.h +logic/BaseVersion.h logic/MinecraftVersion.h logic/InstanceFactory.h logic/BaseUpdate.h @@ -216,10 +216,14 @@ logic/NostalgiaInstance.h # Lists logic/lists/InstanceList.h -logic/lists/InstVersionList.h +logic/lists/IconList.h +logic/lists/BaseVersionList.h logic/lists/MinecraftVersionList.h logic/lists/LwjglVersionList.h -logic/lists/IconList.h +logic/lists/ForgeVersionList.h + +# misc model/view +logic/EnabledItemFilter.h # Tasks logic/tasks/Task.h @@ -288,10 +292,14 @@ logic/NostalgiaInstance.cpp # Lists logic/lists/InstanceList.cpp -logic/lists/InstVersionList.cpp +logic/lists/IconList.cpp +logic/lists/BaseVersionList.cpp logic/lists/MinecraftVersionList.cpp logic/lists/LwjglVersionList.cpp -logic/lists/IconList.cpp +logic/lists/ForgeVersionList.cpp + +# misc model/view +logic/EnabledItemFilter.cpp # Tasks logic/tasks/Task.cpp diff --git a/MultiMC.cpp b/MultiMC.cpp index b49773a1..08e5ed25 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -9,6 +9,10 @@ #include "gui/mainwindow.h" #include "logic/lists/InstanceList.h" #include "logic/lists/IconList.h" +#include "logic/lists/LwjglVersionList.h" +#include "logic/lists/MinecraftVersionList.h" +#include "logic/lists/ForgeVersionList.h" + #include "logic/InstanceLauncher.h" #include "logic/net/HttpMetaCache.h" @@ -158,6 +162,21 @@ MultiMC::~MultiMC() delete m_qt_translator; m_qt_translator = nullptr; } + if(m_icons) + { + delete m_icons; + m_icons = nullptr; + } + if(m_lwjgllist) + { + delete m_lwjgllist; + m_lwjgllist = nullptr; + } + if(m_minecraftlist) + { + delete m_minecraftlist; + m_minecraftlist = nullptr; + } delete m_settings; delete m_metacache; } @@ -276,6 +295,32 @@ IconList* MultiMC::icons() return m_icons; } +LWJGLVersionList* MultiMC::lwjgllist() +{ + if ( !m_lwjgllist ) + { + m_lwjgllist = new LWJGLVersionList(); + } + return m_lwjgllist; +} +ForgeVersionList* MultiMC::forgelist() +{ + if ( !m_forgelist ) + { + m_forgelist = new ForgeVersionList(); + } + return m_forgelist; +} + +MinecraftVersionList* MultiMC::minecraftlist() +{ + if ( !m_minecraftlist ) + { + m_minecraftlist = new MinecraftVersionList(); + } + return m_minecraftlist; +} + int main(int argc, char *argv[]) { diff --git a/MultiMC.h b/MultiMC.h index 216c670b..d3e92584 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -4,11 +4,14 @@ #include "MultiMCVersion.h" #include "config.h" +class MinecraftVersionList; +class LWJGLVersionList; class HttpMetaCache; class SettingsObject; class InstanceList; class IconList; class QNetworkAccessManager; +class ForgeVersionList; #if defined(MMC) #undef MMC @@ -61,6 +64,12 @@ public: { return m_metacache; } + + LWJGLVersionList * lwjgllist(); + + ForgeVersionList * forgelist(); + + MinecraftVersionList * minecraftlist(); private: void initGlobalSettings(); @@ -76,5 +85,9 @@ private: QNetworkAccessManager * m_qnam = nullptr; HttpMetaCache * m_metacache = nullptr; Status m_status = MultiMC::Failed; + LWJGLVersionList * m_lwjgllist = nullptr; + ForgeVersionList * m_forgelist = nullptr; + MinecraftVersionList * m_minecraftlist = nullptr; + MultiMCVersion m_version = {VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD}; }; \ No newline at end of file diff --git a/gui/ModListView.cpp b/gui/ModListView.cpp index 34bd4af2..1d0e834c 100644 --- a/gui/ModListView.cpp +++ b/gui/ModListView.cpp @@ -30,6 +30,7 @@ void ModListView::setModel ( QAbstractItemModel* model ) auto head = header(); head->setStretchLastSection(false); head->setSectionResizeMode(0, QHeaderView::Stretch); - head->setSectionResizeMode(1, QHeaderView::ResizeToContents); + for(int i = 1; i < head->count(); i++) + head->setSectionResizeMode(i, QHeaderView::ResizeToContents); dropIndicatorPosition(); } diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index ab6ad5f0..f778127f 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -22,6 +22,8 @@ #include #include #include +#include "logic/OneSixVersion.h" +#include OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent): m_inst(inst), @@ -29,9 +31,15 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent) ui(new Ui::OneSixModEditDialog) { ui->setupUi(this); - //TODO: libraries! + //libraries! { - // yeah... here be the real dragons. + m_version = m_inst->getFullVersion(); + + auto filter = new EnabledItemFilter(this); + filter->setActive(true); + filter->setSourceModel(m_version.data()); + ui->libraryTreeView->setModel(filter); + ui->libraryTreeView->installEventFilter( this ); } // Loader mods { diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index 3430bd26..c637df01 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -46,6 +46,7 @@ protected: bool resourcePackListFilter( QKeyEvent* ev ); private: Ui::OneSixModEditDialog *ui; + QSharedPointer m_version; QSharedPointer m_mods; QSharedPointer m_resourcepacks; OneSixInstance * m_inst; diff --git a/gui/OneSixModEditDialog.ui b/gui/OneSixModEditDialog.ui index 3feca726..bffcaed0 100644 --- a/gui/OneSixModEditDialog.ui +++ b/gui/OneSixModEditDialog.ui @@ -6,15 +6,15 @@ 0 0 - 543 - 423 + 555 + 463 Dialog - - + + true @@ -28,26 +28,121 @@ 0 - - Qt::ElideNone - - - false - - Library + Version - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + + + + + + + Main Class: + + + + + + + + + + + + + + + + Replace any current custom version with Minecraft Forge + + + Install Forge + + + + + + + Create an customized copy of the base version + + + Customize + + + + + + + Revert to original base version + + + Revert + + + + + + + QFrame::Sunken + + + Qt::Horizontal + + + + + + + false + + + Add new libraries + + + &Add + + + + + + + false + + + Remove selected libraries + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + @@ -163,7 +258,7 @@ - + false diff --git a/gui/lwjglselectdialog.cpp b/gui/lwjglselectdialog.cpp index c3215b7b..7c424a6c 100644 --- a/gui/lwjglselectdialog.cpp +++ b/gui/lwjglselectdialog.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "MultiMC.h" #include "lwjglselectdialog.h" #include "ui_lwjglselectdialog.h" @@ -24,11 +25,12 @@ LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) : { ui->setupUi(this); ui->labelStatus->setVisible(false); - ui->lwjglListView->setModel(&LWJGLVersionList::get()); + auto lwjgllist = MMC->lwjgllist(); + ui->lwjglListView->setModel(lwjgllist); - connect(&LWJGLVersionList::get(), SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); - connect(&LWJGLVersionList::get(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); - loadingStateUpdated(LWJGLVersionList::get().isLoading()); + connect(lwjgllist, SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); + connect(lwjgllist, SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); + loadingStateUpdated(lwjgllist->isLoading()); } LWJGLSelectDialog::~LWJGLSelectDialog() @@ -38,15 +40,15 @@ LWJGLSelectDialog::~LWJGLSelectDialog() QString LWJGLSelectDialog::selectedVersion() const { - return LWJGLVersionList::get().data( + return MMC->lwjgllist()->data( ui->lwjglListView->selectionModel()->currentIndex(), Qt::DisplayRole).toString(); } void LWJGLSelectDialog::on_refreshButton_clicked() { - if (!LWJGLVersionList::get().isLoading()) - LWJGLVersionList::get().loadList(); + if (!MMC->lwjgllist()->isLoading()) + MMC->lwjgllist()->loadList(); } void LWJGLSelectDialog::loadingStateUpdated(bool loading) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 747df047..241df383 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -154,14 +154,14 @@ MainWindow::MainWindow ( QWidget *parent ) // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. { - if (!MinecraftVersionList::getMainList().isLoaded()) + if (!MMC->minecraftlist()->isLoaded()) { - m_versionLoadTask = MinecraftVersionList::getMainList().getLoadTask(); + m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); startTask(m_versionLoadTask); } - if (!LWJGLVersionList::get().isLoaded()) + if (!MMC->lwjgllist()->isLoaded()) { - LWJGLVersionList::get().loadList(); + MMC->lwjgllist()->loadList(); } assets_downloader = new OneSixAssets(); assets_downloader->start(); @@ -245,7 +245,7 @@ void MainWindow::instanceActivated ( QModelIndex index ) void MainWindow::on_actionAddInstance_triggered() { - if (!MinecraftVersionList::getMainList().isLoaded() && + if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && m_versionLoadTask->isRunning()) { QEventLoop waitLoop; @@ -604,7 +604,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() VersionSelectDialog vselect(m_selectedInstance->versionList(), this); if (vselect.exec() && vselect.selectedVersion()) { - m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor); + m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); } } diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp index ac3bcd7d..af2b11c5 100644 --- a/gui/newinstancedialog.cpp +++ b/gui/newinstancedialog.cpp @@ -18,7 +18,7 @@ #include "ui_newinstancedialog.h" #include "logic/InstanceFactory.h" -#include "logic/InstanceVersion.h" +#include "logic/BaseVersion.h" #include "logic/lists/IconList.h" #include "logic/lists/MinecraftVersionList.h" #include "logic/tasks/Task.h" @@ -48,7 +48,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) : taskDlg->exec(loadTask); } */ - setSelectedVersion(MinecraftVersionList::getMainList().getLatestStable()); + setSelectedVersion(MMC->minecraftlist()->getLatestStable()); InstIconKey = "infinity"; ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); } @@ -63,13 +63,13 @@ void NewInstanceDialog::updateDialogState() ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty() && m_selectedVersion); } -void NewInstanceDialog::setSelectedVersion(InstVersionPtr version) +void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version) { m_selectedVersion = version; if (m_selectedVersion) { - ui->versionTextBox->setText(version->name); + ui->versionTextBox->setText(version->name()); } else { @@ -89,18 +89,18 @@ QString NewInstanceDialog::iconKey() const return InstIconKey; } -InstVersionPtr NewInstanceDialog::selectedVersion() const +BaseVersionPtr NewInstanceDialog::selectedVersion() const { return m_selectedVersion; } void NewInstanceDialog::on_btnChangeVersion_clicked() { - VersionSelectDialog vselect(&MinecraftVersionList::getMainList(), this); + VersionSelectDialog vselect(MMC->minecraftlist(), this); vselect.exec(); if (vselect.result() == QDialog::Accepted) { - InstVersionPtr version = vselect.selectedVersion(); + BaseVersionPtr version = vselect.selectedVersion(); if (version) setSelectedVersion(version); } diff --git a/gui/newinstancedialog.h b/gui/newinstancedialog.h index e8c57024..408cf757 100644 --- a/gui/newinstancedialog.h +++ b/gui/newinstancedialog.h @@ -17,7 +17,7 @@ #define NEWINSTANCEDIALOG_H #include -#include "logic/InstanceVersion.h" +#include "logic/BaseVersion.h" namespace Ui { class NewInstanceDialog; @@ -33,13 +33,13 @@ public: void updateDialogState(); - void setSelectedVersion(InstVersionPtr version); + void setSelectedVersion(BaseVersionPtr version); void loadVersionList(); QString instName() const; QString iconKey() const; - InstVersionPtr selectedVersion() const; + BaseVersionPtr selectedVersion() const; private slots: void on_btnChangeVersion_clicked(); @@ -49,7 +49,7 @@ private slots: private: Ui::NewInstanceDialog *ui; - InstVersionPtr m_selectedVersion; + BaseVersionPtr m_selectedVersion; QString InstIconKey; }; diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp index 66d772b0..b14956fd 100644 --- a/gui/versionselectdialog.cpp +++ b/gui/versionselectdialog.cpp @@ -22,11 +22,11 @@ #include -#include -#include +#include +#include #include -VersionSelectDialog::VersionSelectDialog(InstVersionList *vlist, QWidget *parent) : +VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QWidget *parent) : QDialog(parent), ui(new Ui::VersionSelectDialog) { @@ -69,11 +69,11 @@ void VersionSelectDialog::loadList() taskDlg->exec(loadTask); } -InstVersionPtr VersionSelectDialog::selectedVersion() const +BaseVersionPtr VersionSelectDialog::selectedVersion() const { auto currentIndex = ui->listView->selectionModel()->currentIndex(); - auto variant = m_proxyModel->data(currentIndex, InstVersionList::VersionPointerRole); - return variant.value(); + auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole); + return variant.value(); } void VersionSelectDialog::on_refreshButton_clicked() @@ -83,7 +83,7 @@ void VersionSelectDialog::on_refreshButton_clicked() void VersionSelectDialog::updateFilterState() { - m_proxyModel->setFilterKeyColumn(InstVersionList::TypeColumn); + m_proxyModel->setFilterKeyColumn(BaseVersionList::TypeColumn); QStringList filteredTypes; if (!ui->filterSnapshotsCheckbox->isChecked()) diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h index b864aee1..57e4d0df 100644 --- a/gui/versionselectdialog.h +++ b/gui/versionselectdialog.h @@ -19,9 +19,9 @@ #include #include -#include "logic/InstanceVersion.h" +#include "logic/BaseVersion.h" -class InstVersionList; +class BaseVersionList; namespace Ui { @@ -33,7 +33,7 @@ class VersionSelectDialog : public QDialog Q_OBJECT public: - explicit VersionSelectDialog(InstVersionList *vlist, QWidget *parent = 0); + explicit VersionSelectDialog(BaseVersionList *vlist, QWidget *parent = 0); ~VersionSelectDialog(); virtual int exec(); @@ -41,7 +41,7 @@ public: //! Starts a task that loads the list. void loadList(); - InstVersionPtr selectedVersion() const; + BaseVersionPtr selectedVersion() const; private slots: void on_refreshButton_clicked(); @@ -51,7 +51,7 @@ private slots: private: Ui::VersionSelectDialog *ui; - InstVersionList *m_vlist; + BaseVersionList *m_vlist; QSortFilterProxyModel *m_proxyModel; }; diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index e166449f..10bb4573 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "MultiMC.h" #include "BaseInstance.h" #include "BaseInstance_p.h" @@ -131,9 +132,9 @@ InstanceList *BaseInstance::instList() const return NULL; } -InstVersionList *BaseInstance::versionList() const +BaseVersionList *BaseInstance::versionList() const { - return &MinecraftVersionList::getMainList(); + return MMC->minecraftlist(); } SettingsObject &BaseInstance::settings() const diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index cc9422be..fa317ba1 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -21,7 +21,7 @@ #include #include "inifile.h" -#include "lists/InstVersionList.h" +#include "lists/BaseVersionList.h" class QDialog; class BaseUpdate; @@ -134,7 +134,7 @@ public: * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. */ - virtual InstVersionList *versionList() const; + virtual BaseVersionList *versionList() const; /*! * \brief Gets this instance's settings object. diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h new file mode 100644 index 00000000..be717fee --- /dev/null +++ b/logic/BaseVersion.h @@ -0,0 +1,45 @@ +/* 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. + */ + +#pragma once +#include + +/*! + * An abstract base class for versions. + */ +struct BaseVersion +{ + /*! + * A string used to identify this version in config files. + * This should be unique within the version list or shenanigans will occur. + */ + virtual QString descriptor() = 0; + + /*! + * The name of this version as it is displayed to the user. + * For example: "1.5.1" + */ + virtual QString name() = 0; + + /*! + * This should return a string that describes + * the kind of version this is (Stable, Beta, Snapshot, whatever) + */ + virtual QString typeString() const = 0; +}; + +typedef QSharedPointer BaseVersionPtr; + +Q_DECLARE_METATYPE( BaseVersionPtr ) \ No newline at end of file diff --git a/logic/EnabledItemFilter.cpp b/logic/EnabledItemFilter.cpp new file mode 100644 index 00000000..6ecd0271 --- /dev/null +++ b/logic/EnabledItemFilter.cpp @@ -0,0 +1,30 @@ +#include "EnabledItemFilter.h" + +EnabledItemFilter::EnabledItemFilter(QObject* parent) + :QSortFilterProxyModel(parent) +{ + +} + +void EnabledItemFilter::setActive(bool active) +{ + m_active = active; + invalidateFilter(); +} + +bool EnabledItemFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + if(!m_active) + return true; + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + if(sourceModel()->flags(index) & Qt::ItemIsEnabled) + { + return true; + } + return false; +} + +bool EnabledItemFilter::lessThan(const QModelIndex& left, const QModelIndex& right) const +{ + return QSortFilterProxyModel::lessThan(left, right); +} diff --git a/logic/EnabledItemFilter.h b/logic/EnabledItemFilter.h new file mode 100644 index 00000000..cb6d4041 --- /dev/null +++ b/logic/EnabledItemFilter.h @@ -0,0 +1,16 @@ +#pragma once +#include + +class EnabledItemFilter : public QSortFilterProxyModel +{ + Q_OBJECT +public: + EnabledItemFilter(QObject *parent = 0); + void setActive(bool active); + +protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + bool lessThan(const QModelIndex &left, const QModelIndex &right) const; +private: + bool m_active = false; +}; \ No newline at end of file diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index f0630568..b5832ce5 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -22,7 +22,7 @@ #include "LegacyInstance.h" #include "OneSixInstance.h" #include "NostalgiaInstance.h" -#include "InstanceVersion.h" +#include "BaseVersion.h" #include "MinecraftVersion.h" #include "inifile.h" @@ -68,7 +68,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst } -InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, InstVersionPtr version, const QString& instDir ) +InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, BaseVersionPtr version, const QString& instDir ) { QDir rootDir(instDir); @@ -89,19 +89,19 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& case MinecraftVersion::Legacy: m_settings->set("InstanceType", "Legacy"); inst = new LegacyInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); + inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::OneSix: m_settings->set("InstanceType", "OneSix"); inst = new OneSixInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); + inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::Nostalgia: m_settings->set("InstanceType", "Nostalgia"); inst = new NostalgiaInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); + inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; default: diff --git a/logic/InstanceFactory.h b/logic/InstanceFactory.h index ed54f520..1c527749 100644 --- a/logic/InstanceFactory.h +++ b/logic/InstanceFactory.h @@ -19,9 +19,9 @@ #include #include -#include "InstanceVersion.h" +#include "BaseVersion.h" -class InstVersion; +class BaseVersion; class BaseInstance; /*! @@ -61,7 +61,7 @@ public: * - InstExists if the given instance directory is already an instance. * - CantCreateDir if the given instance directory cannot be created. */ - InstCreateError createInstance(BaseInstance *&inst, InstVersionPtr version, const QString &instDir); + InstCreateError createInstance(BaseInstance *&inst, BaseVersionPtr version, const QString &instDir); /*! * \brief Loads an instance from the given directory. diff --git a/logic/InstanceVersion.h b/logic/InstanceVersion.h deleted file mode 100644 index eecd9c4e..00000000 --- a/logic/InstanceVersion.h +++ /dev/null @@ -1,68 +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. - */ - -#pragma once -#include - -/*! - * An abstract base class for versions. - */ -struct InstVersion -{ - /*! - * Checks if this version is less (older) than the given version. - * \param other The version to compare this one to. - * \return True if this version is older than the given version. - */ - virtual bool operator<(const InstVersion &rhs) const - { - return timestamp < rhs.timestamp; - } - - /*! - * Checks if this version is greater (newer) than the given version. - * \param other The version to compare this one to. - * \return True if this version is newer than the given version. - */ - virtual bool operator>( const InstVersion& rhs ) const - { - return timestamp > rhs.timestamp; - } - - /*! - * A string used to identify this version in config files. - * This should be unique within the version list or shenanigans will occur. - */ - QString descriptor; - /*! - * The name of this version as it is displayed to the user. - * For example: "1.5.1" - */ - QString name; - /*! - * Gets the version's timestamp. - * This is primarily used for sorting versions in a list. - */ - qint64 timestamp; - - virtual QString typeString() const - { - return "InstVersion"; - } -}; - -typedef QSharedPointer InstVersionPtr; - -Q_DECLARE_METATYPE( InstVersionPtr ) \ No newline at end of file diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index b8e179a5..25be5e7d 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -34,15 +34,15 @@ void LegacyUpdate::lwjglStart() return; } - auto &list = LWJGLVersionList::get(); - if(!list.isLoaded()) + auto list = MMC->lwjgllist(); + if(!list->isLoaded()) { emitFailed("Too soon! Let the LWJGL list load :)"); return; } setStatus("Downloading new LWJGL."); - auto version = list.getVersion(lwjglVersion); + auto version = list->getVersion(lwjglVersion); if(!version) { emitFailed("Game update failed: the selected LWJGL version is invalid."); @@ -170,7 +170,7 @@ void LegacyUpdate::extractLwjgl() if (name.contains(nativesDir)) { int lastSlash = name.lastIndexOf('/'); - int lastBackSlash = name.lastIndexOf('/'); + int lastBackSlash = name.lastIndexOf('\\'); if(lastSlash != -1) name = name.mid(lastSlash+1); else if(lastBackSlash != -1) diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h index 27977262..53c2f5ef 100644 --- a/logic/MinecraftVersion.h +++ b/logic/MinecraftVersion.h @@ -15,17 +15,16 @@ #pragma once -#include "InstanceVersion.h" +#include "BaseVersion.h" #include -struct MinecraftVersion : public InstVersion +struct MinecraftVersion : public BaseVersion { - // From InstVersion: - /* - QString m_descriptor; - QString m_name; - qint64 m_timestamp; - */ + /*! + * Gets the version's timestamp. + * This is primarily used for sorting versions in a list. + */ + qint64 timestamp; /// The URL that this version will be downloaded from. maybe. QString download_url; @@ -44,6 +43,20 @@ struct MinecraftVersion : public InstVersion /// is this a snapshot? bool is_snapshot = false; + QString m_name; + + QString m_descriptor; + + virtual QString descriptor() + { + return m_descriptor; + } + + virtual QString name() + { + return m_name; + } + virtual QString typeString() const { QStringList pre_final; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index c926df60..7b038c46 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -214,6 +214,13 @@ bool OneSixInstance::shouldUpdate() const return true; } +bool OneSixInstance::versionIsCustom() +{ + QString verpath_custom = PathCombine(instanceRoot(), "custom.json"); + QFile versionfile(verpath_custom); + return versionfile.exists(); +} + QString OneSixInstance::currentVersionId() const { return intendedVersionId(); @@ -224,6 +231,13 @@ bool OneSixInstance::reloadFullVersion() I_D(OneSixInstance); QString verpath = PathCombine(instanceRoot(), "version.json"); + { + QString verpath_custom = PathCombine(instanceRoot(), "custom.json"); + QFile versionfile(verpath_custom); + if(versionfile.exists()) + verpath = verpath_custom; + } + QFile versionfile(verpath); if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly)) { @@ -264,7 +278,12 @@ bool OneSixInstance::menuActionEnabled ( QString action_name ) const QString OneSixInstance::getStatusbarDescription() { - return "One Six : " + intendedVersionId(); + QString descr = "One Six : " + intendedVersionId(); + if(versionIsCustom()) + { + descr + " (custom)"; + } + return descr; } QString OneSixInstance::loaderModsDir() const diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index a4c67ed1..72bde630 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -41,6 +41,8 @@ public: bool reloadFullVersion(); /// get the current full version info QSharedPointer getFullVersion(); + /// is the current version original, or custom? + bool versionIsCustom(); virtual QString defaultBaseJar() const; virtual QString defaultCustomBaseJar() const; diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index a109a7f0..a45a4aec 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -1,12 +1,13 @@ #include "OneSixLibrary.h" #include "OneSixRule.h" - +#include "OpSys.h" void OneSixLibrary::finalize() { QStringList parts = m_name.split ( ':' ); QString relative = parts[0]; relative.replace ( '.','/' ); relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2]; + if ( !m_is_native ) relative += ".jar"; else @@ -21,9 +22,12 @@ void OneSixLibrary::finalize() relative += ".jar"; } } + + m_decentname = parts[1]; + m_decentversion = parts[2]; m_storage_path = relative; m_download_path = m_base_url + relative; - + if ( m_rules.empty() ) { m_is_active = true; @@ -42,6 +46,11 @@ void OneSixLibrary::finalize() if ( m_is_native ) { m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem ); + m_decenttype = "Native"; + } + else + { + m_decenttype = "Java"; } } diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 856e409c..ac16d3d3 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -16,6 +16,12 @@ private: QList > m_rules; // derived values used for real things + /// a decent name fit for display + QString m_decentname; + /// a decent version fit for display + QString m_decentversion; + /// a decent type fit for display + QString m_decenttype; /// where to store the lib locally QString m_storage_path; /// where to download the lib from @@ -48,8 +54,24 @@ public: /// Set the library composite name void setName(QString name); + /// get a decent-looking name + QString name() + { + return m_decentname; + } + /// get a decent-looking version + QString version() + { + return m_decentversion; + } + /// what kind of library is it? (for display) + QString type() + { + return m_decenttype; + } /// Set the url base for downloads void setBaseUrl(QString base_url); + /// Call this to mark the library as 'native' (it's a zip archive with DLLs) void setIsNative(); /// Attach a name suffix to the specified OS native diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index a58a9626..67395818 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -49,7 +49,7 @@ void OneSixUpdate::executeTask() } // Get a pointer to the version object that corresponds to the instance's version. - targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast(); + targetVersion = MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast(); if(targetVersion == nullptr) { // don't do anything if it was invalid @@ -72,7 +72,7 @@ void OneSixUpdate::versionFileStart() setStatus("Getting the version files from Mojang."); QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); - urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".json"; + urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; auto job = new DownloadJob("Version index"); job->add(QUrl(urlstr)); specificVersionDownloadJob.reset(job); @@ -85,31 +85,46 @@ void OneSixUpdate::versionFileStart() void OneSixUpdate::versionFileFinished() { DownloadPtr DlJob = specificVersionDownloadJob->first(); + OneSixInstance * inst = (OneSixInstance *) m_inst; - QString version_id = targetVersion->descriptor; + QString version_id = targetVersion->descriptor(); QString inst_dir = m_inst->instanceRoot(); // save the version file in $instanceId/version.json { QString version1 = PathCombine(inst_dir, "/version.json"); ensureFilePathExists(version1); // FIXME: detect errors here, download to a temp file, swap - QFile vfile1 (version1); - vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly ); - vfile1.write(DlJob.dynamicCast()->m_data); - vfile1.close(); + QSaveFile vfile1 (version1); + if(!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly )) + { + emitFailed("Can't open " + version1 + " for writing."); + return; + } + auto data = DlJob.dynamicCast()->m_data; + qint64 actual = 0; + if((actual = vfile1.write(data)) != data.size()) + { + emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + data.size() + '.'); + return; + } + if(!vfile1.commit()) + { + emitFailed("Can't commit changes to " + version1); + return; + } } // the version is downloaded safely. update is 'done' at this point m_inst->setShouldUpdate(false); - // save the version file in versions/$version/$version.json - /* - //QString version2 = QString("versions/") + version_id + "/" + version_id + ".json"; - //ensurePathExists(version2); - //QFile vfile2 (version2); - //vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly ); - //vfile2.write(DlJob->m_data); - //vfile2.close(); - */ + + // delete any custom version inside the instance (it's no longer relevant, we did an update) + QString custom = PathCombine(inst_dir, "/custom.json"); + QFile finfo(custom); + if(finfo.exists()) + { + finfo.remove(); + } + inst->reloadFullVersion(); jarlibStart(); } diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 7ffe9a94..dc1b5d6f 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -28,3 +28,74 @@ QList > OneSixVersion::getActiveNativeLibs() } +QVariant OneSixVersion::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + int row = index.row(); + int column = index.column(); + + if(row < 0 || row >= libraries.size()) + return QVariant(); + + if(role == Qt::DisplayRole) + { + switch(column) + { + case 0: + return libraries[row]->name(); + case 1: + return libraries[row]->type(); + case 2: + return libraries[row]->version(); + default: + return QVariant(); + } + } + return QVariant(); +} + +Qt::ItemFlags OneSixVersion::flags(const QModelIndex& index) const +{ + if(!index.isValid()) + return Qt::NoItemFlags; + int row = index.row(); + if(libraries[row]->isActive()) + { + return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren; + } + else + { + return Qt::ItemNeverHasChildren; + } + //return QAbstractListModel::flags(index); +} + + +QVariant OneSixVersion::headerData ( int section, Qt::Orientation orientation, int role ) const +{ + if (role != Qt::DisplayRole || orientation != Qt::Horizontal) + return QVariant(); + switch (section) + { + case 0: + return QString("Name"); + case 1: + return QString("Type"); + case 2: + return QString("Version"); + default: + return QString(); + } +} + +int OneSixVersion::rowCount(const QModelIndex& parent) const +{ + return libraries.size(); +} + +int OneSixVersion::columnCount(const QModelIndex& parent) const +{ + return 3; +} diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 8f01f82d..6a6a5b4b 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -2,8 +2,14 @@ #include class OneSixLibrary; -class OneSixVersion +class OneSixVersion : public QAbstractListModel { +public: + virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; + virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const; + virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; + virtual int columnCount ( const QModelIndex& parent ) const; + virtual Qt::ItemFlags flags(const QModelIndex& index) const; public: /// the ID - determines which jar to use! ACTUALLY IMPORTANT! QString id; @@ -58,6 +64,7 @@ public: // QList rules; public: + OneSixVersion() { minimumLauncherVersion = 0xDEADBEEF; @@ -65,4 +72,4 @@ public: QList > getActiveNormalLibs(); QList > getActiveNativeLibs(); -}; \ No newline at end of file +}; diff --git a/logic/lists/BaseVersionList.cpp b/logic/lists/BaseVersionList.cpp new file mode 100644 index 00000000..61da5eeb --- /dev/null +++ b/logic/lists/BaseVersionList.cpp @@ -0,0 +1,123 @@ +/* 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 "logic/lists/BaseVersionList.h" +#include "logic/BaseVersion.h" + +BaseVersionList::BaseVersionList(QObject *parent) : + QAbstractListModel(parent) +{ +} + +BaseVersionPtr BaseVersionList::findVersion( const QString& descriptor ) +{ + for (int i = 0; i < count(); i++) + { + if (at(i)->descriptor() == descriptor) + return at(i); + } + return BaseVersionPtr(); +} + +BaseVersionPtr BaseVersionList::getLatestStable() const +{ + if (count() <= 0) + return BaseVersionPtr(); + else + return at(0); +} + +QVariant BaseVersionList::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + + BaseVersionPtr version = at(index.row()); + + switch (role) + { + case Qt::DisplayRole: + switch (index.column()) + { + case NameColumn: + return version->name(); + + case TypeColumn: + return version->typeString(); + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + return version->descriptor(); + + case VersionPointerRole: + return qVariantFromValue(version); + + default: + return QVariant(); + } +} + +QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, int role) const +{ + switch (role) + { + case Qt::DisplayRole: + switch (section) + { + case NameColumn: + return "Name"; + + case TypeColumn: + return "Type"; + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + switch (section) + { + case NameColumn: + return "The name of the version."; + + case TypeColumn: + return "The version's type."; + + default: + return QVariant(); + } + + default: + return QVariant(); + } +} + +int BaseVersionList::rowCount(const QModelIndex &parent) const +{ + // Return count + return count(); +} + +int BaseVersionList::columnCount(const QModelIndex &parent) const +{ + return 2; +} diff --git a/logic/lists/BaseVersionList.h b/logic/lists/BaseVersionList.h new file mode 100644 index 00000000..d37431ed --- /dev/null +++ b/logic/lists/BaseVersionList.h @@ -0,0 +1,121 @@ +/* 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. + */ + +#pragma once + +#include +#include +#include +#include + +#include "logic/BaseVersion.h" + +class Task; + +/*! + * \brief Class that each instance type's version list derives from. + * Version lists are the lists that keep track of the available game versions + * for that instance. This list will not be loaded on startup. It will be loaded + * when the list's load function is called. Before using the version list, you + * should check to see if it has been loaded yet and if not, load the list. + * + * Note that this class also inherits from QAbstractListModel. Methods from that + * class determine how this version list shows up in a list view. Said methods + * all have a default implementation, but they can be overridden by plugins to + * change the behavior of the list. + */ +class BaseVersionList : public QAbstractListModel +{ + Q_OBJECT +public: + enum ModelRoles + { + VersionPointerRole = 0x34B1CB48 + }; + + enum VListColumns + { + // First column - Name + NameColumn = 0, + + // Second column - Type + TypeColumn, + + // Third column - Timestamp + TimeColumn + }; + + explicit BaseVersionList(QObject *parent = 0); + + /*! + * \brief Gets a task that will reload the version list. + * Simply execute the task to load the list. + * The task returned by this function should reset the model when it's done. + * \return A pointer to a task that reloads the version list. + */ + virtual Task *getLoadTask() = 0; + + //! Checks whether or not the list is loaded. If this returns false, the list should be loaded. + virtual bool isLoaded() = 0; + + //! Gets the version at the given index. + virtual const BaseVersionPtr at(int i) const = 0; + + //! Returns the number of versions in the list. + virtual int count() const = 0; + + + //////// List Model Functions //////// + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual int rowCount(const QModelIndex &parent) const; + virtual int columnCount(const QModelIndex &parent) const; + + + /*! + * \brief Finds a version by its descriptor. + * \param The descriptor of the version to find. + * \return A const pointer to the version with the given descriptor. NULL if + * one doesn't exist. + */ + virtual BaseVersionPtr findVersion(const QString &descriptor); + + /*! + * \brief Gets the latest stable version of this instance type. + * This is the version that will be selected by default. + * By default, this is simply the first version in the list. + */ + virtual BaseVersionPtr getLatestStable() const; + + /*! + * Sorts the version list. + */ + virtual void sort() = 0; + +protected slots: + /*! + * Updates this list with the given list of versions. + * This is done by copying each version in the given list and inserting it + * into this one. + * We need to do this so that we can set the parents of the versions are set to this + * version list. This can't be done in the load task, because the versions the load + * task creates are on the load task's thread and Qt won't allow their parents + * to be set to something created on another thread. + * To get around that problem, we invoke this method on the GUI thread, which + * then copies the versions and sets their parents correctly. + * \param versions List of versions whose parents should be set. + */ + virtual void updateListData(QList versions) = 0; +}; diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp new file mode 100644 index 00000000..f45b8b6b --- /dev/null +++ b/logic/lists/ForgeVersionList.cpp @@ -0,0 +1,200 @@ +/* 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 "ForgeVersionList.h" +#include +#include "MultiMC.h" + +#include + +#include + +#include + +#define JSON_URL "http://files.minecraftforge.net/minecraftforge/json" + + +ForgeVersionList::ForgeVersionList(QObject* parent): BaseVersionList(parent) +{ + +} + +Task *ForgeVersionList::getLoadTask() +{ + return new ForgeListLoadTask(this); +} + +bool ForgeVersionList::isLoaded() +{ + return m_loaded; +} + +const BaseVersionPtr ForgeVersionList::at(int i) const +{ + return m_vlist.at(i); +} + +int ForgeVersionList::count() const +{ + return m_vlist.count(); +} +/* +bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) +{ + const BaseVersion & left = *first; + const BaseVersion & right = *second; + return left > right; +} + +void MinecraftVersionList::sort() +{ + beginResetModel(); + qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); + endResetModel(); +} +*/ +BaseVersionPtr ForgeVersionList::getLatestStable() const +{ + return BaseVersionPtr(); +} + +void ForgeVersionList::updateListData(QList versions) +{ + beginResetModel(); + m_vlist = versions; + m_loaded = true; + endResetModel(); + // NOW SORT!! + // sort(); +} + +void ForgeVersionList::sort() +{ + // NO-OP for now +} + + +ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList* vlist): Task() +{ + m_list = vlist; +} + + +void ForgeListLoadTask::executeTask() +{ + auto job = new DownloadJob("Version index"); + job->add(QUrl(JSON_URL)); + 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))); + listJob->start(); +} + +void ForgeListLoadTask::list_downloaded() +{ + auto DlJob = listJob->first(); + auto data = DlJob.dynamicCast()->m_data; + + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + DlJob.reset(); + + if (jsonError.error != QJsonParseError::NoError) + { + emitFailed("Error parsing version list JSON:" + jsonError.errorString()); + return; + } + + if(!jsonDoc.isObject()) + { + emitFailed("Error parsing version list JSON: jsonDoc is not an object"); + return; + } + + QJsonObject root = jsonDoc.object(); + + // Now, get the array of versions. + if(!root.value("builds").isArray()) + { + emitFailed("Error parsing version list JSON: version list object is missing 'builds' array"); + return; + } + QJsonArray builds = root.value("builds").toArray(); + + QList tempList; + for (int i = 0; i < builds.count(); i++) + { + // Load the version info. + if(!builds[i].isObject()) + { + //FIXME: log this somewhere + continue; + } + QJsonObject obj = builds[i].toObject(); + int build_nr = obj.value("build").toDouble(0); + if(!build_nr) + continue; + QJsonArray files = root.value("files").toArray(); + QString url, jobbuildver, mcver, buildtype, filename; + QString changelog_url, installer_url; + bool valid = false; + for(int j = 0; j < files.count(); j++) + { + if(!files[j].isObject()) + continue; + QJsonObject file = files[j].toObject(); + buildtype = file.value("buildtype").toString(); + if((buildtype == "client" || buildtype == "universal") && !valid) + { + mcver = file.value("mcver").toString(); + url = file.value("url").toString(); + jobbuildver = file.value("jobbuildver").toString(); + int lastSlash = url.lastIndexOf('/'); + filename = url.mid(lastSlash+1); + valid = true; + } + else if(buildtype == "changelog") + { + QString ext = file.value("ext").toString(); + if(ext.isEmpty()) + continue; + changelog_url = file.value("url").toString(); + } + else if(buildtype == "installer") + { + installer_url = file.value("url").toString(); + } + } + if(valid) + { + // Now, we construct the version object and add it to the list. + QSharedPointer fVersion(new ForgeVersion()); + fVersion->universal_url = url; + fVersion->changelog_url = changelog_url; + fVersion->installer_url = installer_url; + fVersion->jobbuildver = jobbuildver; + fVersion->mcver = mcver; + fVersion->filename = filename; + fVersion->m_buildnr = build_nr; + tempList.append(fVersion); + } + } + m_list->updateListData(tempList); + + emitSucceeded(); + return; +} diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h new file mode 100644 index 00000000..8d4a2d46 --- /dev/null +++ b/logic/lists/ForgeVersionList.h @@ -0,0 +1,98 @@ +/* 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. + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include "BaseVersionList.h" +#include "logic/tasks/Task.h" +#include "logic/net/DownloadJob.h" + +class ForgeVersion; +typedef QSharedPointer PtrForgeVersion; + +struct ForgeVersion : public BaseVersion +{ + virtual QString descriptor() + { + return filename; + }; + virtual QString name() + { + return "Forge " + jobbuildver + " (" + mcver + ")"; + }; + virtual QString typeString() const + { + if(installer_url.isEmpty()) + return "Universal"; + else + return "Installer"; + }; + + int m_buildnr = 0; + QString universal_url; + QString changelog_url; + QString installer_url; + QString jobbuildver; + QString mcver; + QString filename; +}; + +class ForgeVersionList : public BaseVersionList +{ + Q_OBJECT +public: + friend class ForgeListLoadTask; + + explicit ForgeVersionList(QObject *parent = 0); + + virtual Task *getLoadTask(); + virtual bool isLoaded(); + virtual const BaseVersionPtr at(int i) const; + virtual int count() const; + virtual void sort(); + + virtual BaseVersionPtr getLatestStable() const; + +protected: + QList m_vlist; + + bool m_loaded; + +protected slots: + virtual void updateListData(QList versions); +}; + +class ForgeListLoadTask : public Task +{ + Q_OBJECT + +public: + explicit ForgeListLoadTask(ForgeVersionList *vlist); + + virtual void executeTask(); + +protected slots: + void list_downloaded(); + +protected: + DownloadJobPtr listJob; + ForgeVersionList *m_list; +}; diff --git a/logic/lists/InstVersionList.cpp b/logic/lists/InstVersionList.cpp deleted file mode 100644 index 7dc67155..00000000 --- a/logic/lists/InstVersionList.cpp +++ /dev/null @@ -1,129 +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 "logic/lists/InstVersionList.h" -#include "logic/InstanceVersion.h" - -InstVersionList::InstVersionList(QObject *parent) : - QAbstractListModel(parent) -{ -} - -InstVersionPtr InstVersionList::findVersion( const QString& descriptor ) -{ - for (int i = 0; i < count(); i++) - { - if (at(i)->descriptor == descriptor) - return at(i); - } - return InstVersionPtr(); -} - -InstVersionPtr InstVersionList::getLatestStable() const -{ - if (count() <= 0) - return InstVersionPtr(); - else - return at(0); -} - -QVariant InstVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - - InstVersionPtr version = at(index.row()); - - switch (role) - { - case Qt::DisplayRole: - switch (index.column()) - { - case NameColumn: - return version->name; - - case TypeColumn: - return version->typeString(); - - case TimeColumn: - return version->timestamp; - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - return version->descriptor; - - case VersionPointerRole: - return qVariantFromValue(version); - - default: - return QVariant(); - } -} - -QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, int role) const -{ - switch (role) - { - case Qt::DisplayRole: - switch (section) - { - case NameColumn: - return "Name"; - - case TypeColumn: - return "Type"; - - case TimeColumn: - return "Time"; - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - switch (section) - { - case NameColumn: - return "The name of the version."; - - case TypeColumn: - return "The version's type."; - - default: - return QVariant(); - } - - default: - return QVariant(); - } -} - -int InstVersionList::rowCount(const QModelIndex &parent) const -{ - // Return count - return count(); -} - -int InstVersionList::columnCount(const QModelIndex &parent) const -{ - return 2; -} diff --git a/logic/lists/InstVersionList.h b/logic/lists/InstVersionList.h deleted file mode 100644 index bc6aa5d4..00000000 --- a/logic/lists/InstVersionList.h +++ /dev/null @@ -1,121 +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. - */ - -#pragma once - -#include -#include -#include -#include - -#include "logic/InstanceVersion.h" - -class Task; - -/*! - * \brief Class that each instance type's version list derives from. - * Version lists are the lists that keep track of the available game versions - * for that instance. This list will not be loaded on startup. It will be loaded - * when the list's load function is called. Before using the version list, you - * should check to see if it has been loaded yet and if not, load the list. - * - * Note that this class also inherits from QAbstractListModel. Methods from that - * class determine how this version list shows up in a list view. Said methods - * all have a default implementation, but they can be overridden by plugins to - * change the behavior of the list. - */ -class InstVersionList : public QAbstractListModel -{ - Q_OBJECT -public: - enum ModelRoles - { - VersionPointerRole = 0x34B1CB48 - }; - - enum VListColumns - { - // First column - Name - NameColumn = 0, - - // Second column - Type - TypeColumn, - - // Third column - Timestamp - TimeColumn - }; - - explicit InstVersionList(QObject *parent = 0); - - /*! - * \brief Gets a task that will reload the version list. - * Simply execute the task to load the list. - * The task returned by this function should reset the model when it's done. - * \return A pointer to a task that reloads the version list. - */ - virtual Task *getLoadTask() = 0; - - //! Checks whether or not the list is loaded. If this returns false, the list should be loaded. - virtual bool isLoaded() = 0; - - //! Gets the version at the given index. - virtual const InstVersionPtr at(int i) const = 0; - - //! Returns the number of versions in the list. - virtual int count() const = 0; - - - //////// List Model Functions //////// - virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - virtual int rowCount(const QModelIndex &parent) const; - virtual int columnCount(const QModelIndex &parent) const; - - - /*! - * \brief Finds a version by its descriptor. - * \param The descriptor of the version to find. - * \return A const pointer to the version with the given descriptor. NULL if - * one doesn't exist. - */ - virtual InstVersionPtr findVersion(const QString &descriptor); - - /*! - * \brief Gets the latest stable version of this instance type. - * This is the version that will be selected by default. - * By default, this is simply the first version in the list. - */ - virtual InstVersionPtr getLatestStable() const; - - /*! - * Sorts the version list. - */ - virtual void sort() = 0; - -protected slots: - /*! - * Updates this list with the given list of versions. - * This is done by copying each version in the given list and inserting it - * into this one. - * We need to do this so that we can set the parents of the versions are set to this - * version list. This can't be done in the load task, because the versions the load - * task creates are on the load task's thread and Qt won't allow their parents - * to be set to something created on another thread. - * To get around that problem, we invoke this method on the GUI thread, which - * then copies the versions and sets their parents correctly. - * \param versions List of versions whose parents should be set. - */ - virtual void updateListData(QList versions) = 0; -}; diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp index d7826a82..b3e2dab4 100644 --- a/logic/lists/LwjglVersionList.cpp +++ b/logic/lists/LwjglVersionList.cpp @@ -24,14 +24,6 @@ #define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss" -LWJGLVersionList mainVersionList; - -LWJGLVersionList &LWJGLVersionList::get() -{ - return mainVersionList; -} - - LWJGLVersionList::LWJGLVersionList(QObject *parent) : QAbstractListModel(parent) { diff --git a/logic/lists/LwjglVersionList.h b/logic/lists/LwjglVersionList.h index 638a0b67..23e92a1a 100644 --- a/logic/lists/LwjglVersionList.h +++ b/logic/lists/LwjglVersionList.h @@ -53,8 +53,6 @@ class LWJGLVersionList : public QAbstractListModel public: explicit LWJGLVersionList(QObject *parent = 0); - static LWJGLVersionList &get(); - bool isLoaded() { return m_vlist.length() > 0; } const PtrLWJGLVersion getVersion(const QString &versionName); diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 42fb1b50..86ba0792 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -34,10 +34,8 @@ #define ASSETS_URLBASE "http://assets.minecraft.net/" #define MCN_URLBASE "http://sonicrules.org/mcnweb.py" -MinecraftVersionList mcVList; - MinecraftVersionList::MinecraftVersionList(QObject *parent) : - InstVersionList(parent) + BaseVersionList(parent) { } @@ -52,7 +50,7 @@ bool MinecraftVersionList::isLoaded() return m_loaded; } -const InstVersionPtr MinecraftVersionList::at(int i) const +const BaseVersionPtr MinecraftVersionList::at(int i) const { return m_vlist.at(i); } @@ -62,11 +60,11 @@ int MinecraftVersionList::count() const return m_vlist.count(); } -bool cmpVersions(InstVersionPtr first, InstVersionPtr second) +bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) { - const InstVersion & left = *first; - const InstVersion & right = *second; - return left > right; + auto left = first.dynamicCast(); + auto right = second.dynamicCast(); + return left->timestamp > right->timestamp; } void MinecraftVersionList::sort() @@ -76,7 +74,7 @@ void MinecraftVersionList::sort() endResetModel(); } -InstVersionPtr MinecraftVersionList::getLatestStable() const +BaseVersionPtr MinecraftVersionList::getLatestStable() const { for (int i = 0; i < m_vlist.length(); i++) { @@ -86,15 +84,10 @@ InstVersionPtr MinecraftVersionList::getLatestStable() const return m_vlist.at(i); } } - return InstVersionPtr(); -} - -MinecraftVersionList &MinecraftVersionList::getMainList() -{ - return mcVList; + return BaseVersionPtr(); } -void MinecraftVersionList::updateListData(QList versions) +void MinecraftVersionList::updateListData(QList versions) { beginResetModel(); m_vlist = versions; @@ -214,7 +207,7 @@ void MCVListLoadTask::list_downloaded() } QJsonArray versions = root.value("versions").toArray(); - QList tempList; + QList tempList; for (int i = 0; i < versions.count(); i++) { bool is_snapshot = false; @@ -280,7 +273,7 @@ void MCVListLoadTask::list_downloaded() // Now, we construct the version object and add it to the list. QSharedPointer mcVersion(new MinecraftVersion()); - mcVersion->name = mcVersion->descriptor = versionID; + mcVersion->m_name = mcVersion->m_descriptor = versionID; mcVersion->timestamp = versionTime.toMSecsSinceEpoch(); mcVersion->download_url = dlUrl; mcVersion->is_latest = is_latest; @@ -293,8 +286,3 @@ void MCVListLoadTask::list_downloaded() emitSucceeded(); return; } - -// FIXME: we should have a local cache of the version list and a local cache of version data -bool MCVListLoadTask::loadFromVList() -{ -} diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h index 0477379f..8937ba7b 100644 --- a/logic/lists/MinecraftVersionList.h +++ b/logic/lists/MinecraftVersionList.h @@ -20,14 +20,14 @@ #include #include -#include "InstVersionList.h" +#include "BaseVersionList.h" #include "logic/tasks/Task.h" #include "logic/MinecraftVersion.h" class MCVListLoadTask; class QNetworkReply; -class MinecraftVersionList : public InstVersionList +class MinecraftVersionList : public BaseVersionList { Q_OBJECT public: @@ -37,25 +37,19 @@ public: virtual Task *getLoadTask(); virtual bool isLoaded(); - virtual const InstVersionPtr at(int i) const; + virtual const BaseVersionPtr at(int i) const; virtual int count() const; virtual void sort(); - virtual InstVersionPtr getLatestStable() const; - - /*! - * Gets the main version list instance. - */ - static MinecraftVersionList &getMainList(); - + virtual BaseVersionPtr getLatestStable() const; protected: - QList m_vlist; + QList m_vlist; bool m_loaded; protected slots: - virtual void updateListData(QList versions); + virtual void updateListData(QList versions); }; class MCVListLoadTask : public Task @@ -72,9 +66,6 @@ protected slots: void list_downloaded(); protected: - //! Loads versions from Mojang's official version list. - bool loadFromVList(); - QNetworkReply *vlistReply; MinecraftVersionList *m_list; MinecraftVersion *m_currentStable; -- cgit From b979d0ce5da515793a02802a6421ef607a498323 Mon Sep 17 00:00:00 2001 From: Petr Mrázek 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 --- CMakeLists.txt | 9 ++-- MultiMC.cpp | 1 + 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 ------------------------ logic/BaseUpdate.cpp | 4 +- logic/InstanceLauncher.cpp | 4 +- logic/LegacyUpdate.cpp | 6 +-- logic/OneSixUpdate.cpp | 4 +- logic/lists/ForgeVersionList.cpp | 93 +++++++++++++++++++++++++++----- logic/lists/ForgeVersionList.h | 10 ++-- logic/lists/MinecraftVersionList.h | 2 +- logic/net/DownloadJob.cpp | 2 + logic/net/DownloadJob.h | 19 ++++++- logic/tasks/ProgressProvider.h | 20 +++++++ logic/tasks/Task.cpp | 48 ++++++----------- logic/tasks/Task.h | 48 ++++++----------- 31 files changed, 474 insertions(+), 414 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 create mode 100644 logic/tasks/ProgressProvider.h (limited to 'logic/OneSixUpdate.cpp') 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 +#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 - - - - - - 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 #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 (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 (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(); + 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 PtrForgeVersion; +typedef QSharedPointer 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 m_vlist; + QList 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 versions); + virtual void updateListData(QList 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 + 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 DownloadJobPtr; @@ -12,12 +13,12 @@ typedef QSharedPointer 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 +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 ¤t, 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 #include +#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 -- cgit