diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index e40f188ee..c6daef6fd 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -8,14 +8,10 @@ set(CORE_SOURCES BaseInstaller.cpp BaseVersionList.h BaseVersionList.cpp - InstanceCreationTask.h - InstanceCreationTask.cpp - InstanceCopyTask.h - InstanceCopyTask.cpp - InstanceImportTask.h - InstanceImportTask.cpp InstanceList.h InstanceList.cpp + InstanceTask.h + InstanceTask.cpp LoggedProcess.h LoggedProcess.cpp MessageLevel.cpp @@ -32,6 +28,14 @@ set(CORE_SOURCES MMCStrings.h MMCStrings.cpp + # Basic instance manipulation tasks (derived from InstanceTask) + InstanceCreationTask.h + InstanceCreationTask.cpp + InstanceCopyTask.h + InstanceCopyTask.cpp + InstanceImportTask.h + InstanceImportTask.cpp + # Use tracking separate from memory management Usable.h @@ -42,6 +46,10 @@ set(CORE_SOURCES Env.h Env.cpp + # String filters + Filter.h + Filter.cpp + # JSON parsing helpers Json.h Json.cpp diff --git a/api/logic/Filter.cpp b/api/logic/Filter.cpp new file mode 100644 index 000000000..7f6667aef --- /dev/null +++ b/api/logic/Filter.cpp @@ -0,0 +1,31 @@ +#include "Filter.h" + +Filter::~Filter(){} + +ContainsFilter::ContainsFilter(const QString& pattern) : pattern(pattern){} +ContainsFilter::~ContainsFilter(){} +bool ContainsFilter::accepts(const QString& value) +{ + return value.contains(pattern); +} + +ExactFilter::ExactFilter(const QString& pattern) : pattern(pattern){} +ExactFilter::~ExactFilter(){} +bool ExactFilter::accepts(const QString& value) +{ + return value.contains(pattern); +} + +RegexpFilter::RegexpFilter(const QString& regexp, bool invert) + :invert(invert) +{ + pattern.setPattern(regexp); + pattern.optimize(); +} +RegexpFilter::~RegexpFilter(){} +bool RegexpFilter::accepts(const QString& value) +{ + auto match = pattern.match(value); + bool matched = match.hasMatch(); + return invert ? (!matched) : (matched); +} diff --git a/api/logic/Filter.h b/api/logic/Filter.h new file mode 100644 index 000000000..8de7d8f9e --- /dev/null +++ b/api/logic/Filter.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +#include "multimc_logic_export.h" + +class MULTIMC_LOGIC_EXPORT Filter +{ +public: + virtual ~Filter(); + virtual bool accepts(const QString & value) = 0; +}; + +class MULTIMC_LOGIC_EXPORT ContainsFilter: public Filter +{ +public: + ContainsFilter(const QString &pattern); + virtual ~ContainsFilter(); + bool accepts(const QString & value) override; +private: + QString pattern; +}; + +class MULTIMC_LOGIC_EXPORT ExactFilter: public Filter +{ +public: + ExactFilter(const QString &pattern); + virtual ~ExactFilter(); + bool accepts(const QString & value) override; +private: + QString pattern; +}; + +class MULTIMC_LOGIC_EXPORT RegexpFilter: public Filter +{ +public: + RegexpFilter(const QString ®exp, bool invert); + virtual ~RegexpFilter(); + bool accepts(const QString & value) override; +private: + QRegularExpression pattern; + bool invert = false; +}; diff --git a/api/logic/FolderInstanceProvider.cpp b/api/logic/FolderInstanceProvider.cpp index 52e23254f..69ba6c825 100644 --- a/api/logic/FolderInstanceProvider.cpp +++ b/api/logic/FolderInstanceProvider.cpp @@ -412,46 +412,13 @@ private: QTimer m_backoffTimer; }; -#include "InstanceImportTask.h" -Task * FolderInstanceProvider::zipImportTask(const QUrl sourceUrl, const QString& instName, const QString& instGroup, const QString& instIcon) +#include "InstanceTask.h" +Task * FolderInstanceProvider::wrapInstanceTask(InstanceTask * task) { auto stagingPath = getStagedInstancePath(); - auto task = new InstanceImportTask(m_globalSettings, sourceUrl, stagingPath, instName, instIcon, instGroup); - return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup); -} - -#include "InstanceCreationTask.h" -Task * FolderInstanceProvider::creationTask(BaseVersionPtr version, const QString& instName, const QString& instGroup, const QString& instIcon) -{ - auto stagingPath = getStagedInstancePath(); - auto task = new InstanceCreationTask(m_globalSettings, stagingPath, version, instName, instIcon, instGroup); - return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup); -} - -#include -Task * FolderInstanceProvider::ftbCreationTask(FtbPackDownloader *downloader, const QString& instName, const QString& instGroup, const QString& instIcon) -{ - auto stagingPath = getStagedInstancePath(); - auto task = new FtbPackInstallTask(downloader, m_globalSettings, stagingPath, instName, instIcon, instGroup); - return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup); -} - -#include "InstanceCopyTask.h" -Task * FolderInstanceProvider::copyTask(const InstancePtr& oldInstance, const QString& instName, const QString& instGroup, const QString& instIcon, bool copySaves) -{ - auto stagingPath = getStagedInstancePath(); - auto task = new InstanceCopyTask(m_globalSettings, stagingPath, oldInstance, instName, instIcon, instGroup, copySaves); - return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup); -} - -// FIXME: find a better place for this -#include "minecraft/legacy/LegacyUpgradeTask.h" -Task * FolderInstanceProvider::legacyUpgradeTask(const InstancePtr& oldInstance) -{ - auto stagingPath = getStagedInstancePath(); - QString newName = tr("%1 (Migrated)").arg(oldInstance->name()); - auto task = new LegacyUpgradeTask(m_globalSettings, stagingPath, oldInstance, newName); - return new FolderInstanceStaging(this, task, stagingPath, newName, oldInstance->group()); + task->setStagingPath(stagingPath); + task->setParentSettings(m_globalSettings); + return new FolderInstanceStaging(this, task, stagingPath, task->name(), task->group()); } QString FolderInstanceProvider::getStagedInstancePath() diff --git a/api/logic/FolderInstanceProvider.h b/api/logic/FolderInstanceProvider.h index 2641a46b2..e13dcfe9c 100644 --- a/api/logic/FolderInstanceProvider.h +++ b/api/logic/FolderInstanceProvider.h @@ -2,9 +2,9 @@ #include "BaseInstanceProvider.h" #include -#include class QFileSystemWatcher; +class InstanceTask; class MULTIMC_LOGIC_EXPORT FolderInstanceProvider : public BaseInstanceProvider { @@ -20,6 +20,7 @@ public: InstancePtr loadInstance(const InstanceId& id) override; + /* // create instance in this provider Task * creationTask(BaseVersionPtr version, const QString &instName, const QString &instGroup, const QString &instIcon); @@ -34,6 +35,10 @@ public: // migrate an instance to the current format Task * legacyUpgradeTask(const InstancePtr& oldInstance); +*/ + + // Wrap an instance creation task in some more task machinery and make it ready to be used + Task * wrapInstanceTask(InstanceTask * task); /** * Create a new empty staging area for instance creation and @return a path/key top commit it later. diff --git a/api/logic/InstanceCopyTask.cpp b/api/logic/InstanceCopyTask.cpp index 9ede65f5b..62c22362b 100644 --- a/api/logic/InstanceCopyTask.cpp +++ b/api/logic/InstanceCopyTask.cpp @@ -6,14 +6,9 @@ #include "pathmatcher/RegexpMatcher.h" #include -InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString& instName, const QString& instIcon, const QString& instGroup, bool copySaves) +InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves) { - m_globalSettings = settings; - m_stagingPath = stagingPath; m_origInstance = origInstance; - m_instName = instName; - m_instIcon = instIcon; - m_instGroup = instGroup; if(!copySaves) { diff --git a/api/logic/InstanceCopyTask.h b/api/logic/InstanceCopyTask.h index dc46bfec3..a8dc9783e 100644 --- a/api/logic/InstanceCopyTask.h +++ b/api/logic/InstanceCopyTask.h @@ -9,16 +9,15 @@ #include "settings/SettingsObject.h" #include "BaseVersion.h" #include "BaseInstance.h" - +#include "InstanceTask.h" class BaseInstanceProvider; -class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public Task +class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public InstanceTask { Q_OBJECT public: - explicit InstanceCopyTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString &instName, - const QString &instIcon, const QString &instGroup, bool copySaves); + explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves); protected: //! Entry point for tasks. @@ -27,15 +26,8 @@ protected: void copyAborted(); private: /* data */ - SettingsObjectPtr m_globalSettings; InstancePtr m_origInstance; - QString m_instName; - QString m_instIcon; - QString m_instGroup; - QString m_stagingPath; QFuture m_copyFuture; QFutureWatcher m_copyFutureWatcher; std::unique_ptr m_matcher; }; - - diff --git a/api/logic/InstanceCreationTask.cpp b/api/logic/InstanceCreationTask.cpp index 8a68815af..6dc2496cb 100644 --- a/api/logic/InstanceCreationTask.cpp +++ b/api/logic/InstanceCreationTask.cpp @@ -7,14 +7,8 @@ #include "minecraft/MinecraftInstance.h" #include "minecraft/ComponentList.h" -InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, const QString & stagingPath, BaseVersionPtr version, - const QString& instName, const QString& instIcon, const QString& instGroup) +InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version) { - m_globalSettings = settings; - m_stagingPath = stagingPath; - m_instName = instName; - m_instIcon = instIcon; - m_instGroup = instGroup; m_version = version; } diff --git a/api/logic/InstanceCreationTask.h b/api/logic/InstanceCreationTask.h index 49fd46157..e06eacbb0 100644 --- a/api/logic/InstanceCreationTask.h +++ b/api/logic/InstanceCreationTask.h @@ -6,24 +6,18 @@ #include #include "settings/SettingsObject.h" #include "BaseVersion.h" +#include "InstanceTask.h" -class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public Task +class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public InstanceTask { Q_OBJECT public: - explicit InstanceCreationTask(SettingsObjectPtr settings, const QString & stagingPath, BaseVersionPtr version, const QString &instName, - const QString &instIcon, const QString &instGroup); + explicit InstanceCreationTask(BaseVersionPtr version); protected: //! Entry point for tasks. virtual void executeTask() override; private: /* data */ - SettingsObjectPtr m_globalSettings; - QString m_stagingPath; BaseVersionPtr m_version; - QString m_instName; - QString m_instIcon; - QString m_instGroup; }; - diff --git a/api/logic/InstanceImportTask.cpp b/api/logic/InstanceImportTask.cpp index 7fae97b8c..b5375cbc1 100644 --- a/api/logic/InstanceImportTask.cpp +++ b/api/logic/InstanceImportTask.cpp @@ -16,15 +16,9 @@ #include "modplatform/flame/PackManifest.h" #include "Json.h" -InstanceImportTask::InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, const QString & stagingPath, - const QString &instName, const QString &instIcon, const QString &instGroup) +InstanceImportTask::InstanceImportTask(const QUrl sourceUrl) { - m_globalSettings = settings; m_sourceUrl = sourceUrl; - m_stagingPath = stagingPath; - m_instName = instName; - m_instIcon = instIcon; - m_instGroup = instGroup; } void InstanceImportTask::executeTask() diff --git a/api/logic/InstanceImportTask.h b/api/logic/InstanceImportTask.h index 99397009d..06778dfeb 100644 --- a/api/logic/InstanceImportTask.h +++ b/api/logic/InstanceImportTask.h @@ -1,6 +1,6 @@ #pragma once -#include "tasks/Task.h" +#include "InstanceTask.h" #include "multimc_logic_export.h" #include "net/NetJob.h" #include @@ -16,12 +16,11 @@ namespace Flame class FileResolvingTask; } -class MULTIMC_LOGIC_EXPORT InstanceImportTask : public Task +class MULTIMC_LOGIC_EXPORT InstanceImportTask : public InstanceTask { Q_OBJECT public: - explicit InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, const QString & stagingPath, const QString &instName, - const QString &instIcon, const QString &instGroup); + explicit InstanceImportTask(const QUrl sourceUrl); protected: //! Entry point for tasks. @@ -40,16 +39,11 @@ private slots: void extractAborted(); private: /* data */ - SettingsObjectPtr m_globalSettings; NetJobPtr m_filesNetJob; shared_qobject_ptr m_modIdResolver; QUrl m_sourceUrl; QString m_archivePath; bool m_downloadRequired = false; - QString m_instName; - QString m_instIcon; - QString m_instGroup; - QString m_stagingPath; std::unique_ptr m_packZip; QFuture m_extractFuture; QFutureWatcher m_extractFutureWatcher; diff --git a/api/logic/InstanceTask.cpp b/api/logic/InstanceTask.cpp new file mode 100644 index 000000000..dd132877f --- /dev/null +++ b/api/logic/InstanceTask.cpp @@ -0,0 +1,9 @@ +#include "InstanceTask.h" + +InstanceTask::InstanceTask() +{ +} + +InstanceTask::~InstanceTask() +{ +} diff --git a/api/logic/InstanceTask.h b/api/logic/InstanceTask.h new file mode 100644 index 000000000..8fc98eb70 --- /dev/null +++ b/api/logic/InstanceTask.h @@ -0,0 +1,55 @@ +#pragma once + +#include "tasks/Task.h" +#include "multimc_logic_export.h" +#include "settings/SettingsObject.h" + +class BaseInstanceProvider; + +class MULTIMC_LOGIC_EXPORT InstanceTask : public Task +{ + Q_OBJECT +public: + explicit InstanceTask(); + virtual ~InstanceTask(); + + void setParentSettings(SettingsObjectPtr settings) + { + m_globalSettings = settings; + } + + void setStagingPath(const QString &stagingPath) + { + m_stagingPath = stagingPath; + } + + void setName(const QString &name) + { + m_instName = name; + } + QString name() const + { + return m_instName; + } + + void setIcon(const QString &icon) + { + m_instIcon = icon; + } + + void setGroup(const QString &group) + { + m_instGroup = group; + } + QString group() const + { + return m_instGroup; + } + +protected: /* data */ + SettingsObjectPtr m_globalSettings; + QString m_instName; + QString m_instIcon; + QString m_instGroup; + QString m_stagingPath; +}; diff --git a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp index 9fc6d92b2..5cc3b5d9a 100644 --- a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp +++ b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp @@ -10,12 +10,9 @@ #include "minecraft/ComponentList.h" #include "classparser.h" -LegacyUpgradeTask::LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName) +LegacyUpgradeTask::LegacyUpgradeTask(InstancePtr origInstance) { - m_globalSettings = settings; - m_stagingPath = stagingPath; m_origInstance = origInstance; - m_newName = newName; } void LegacyUpgradeTask::executeTask() @@ -70,7 +67,7 @@ void LegacyUpgradeTask::copyFinished() // NOTE: this scope ensures the instance is fully saved before we emitSucceeded { MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath); - inst.setName(m_newName); + inst.setName(m_instName); inst.init(); QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId()); diff --git a/api/logic/minecraft/legacy/LegacyUpgradeTask.h b/api/logic/minecraft/legacy/LegacyUpgradeTask.h index 56896385c..a93dd0d9d 100644 --- a/api/logic/minecraft/legacy/LegacyUpgradeTask.h +++ b/api/logic/minecraft/legacy/LegacyUpgradeTask.h @@ -1,6 +1,6 @@ #pragma once -#include "tasks/Task.h" +#include "InstanceTask.h" #include "multimc_logic_export.h" #include "net/NetJob.h" #include @@ -13,11 +13,11 @@ class BaseInstanceProvider; -class MULTIMC_LOGIC_EXPORT LegacyUpgradeTask : public Task +class MULTIMC_LOGIC_EXPORT LegacyUpgradeTask : public InstanceTask { Q_OBJECT public: - explicit LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName); + explicit LegacyUpgradeTask(InstancePtr origInstance); protected: //! Entry point for tasks. @@ -26,13 +26,7 @@ protected: void copyAborted(); private: /* data */ - SettingsObjectPtr m_globalSettings; InstancePtr m_origInstance; - QString m_stagingPath; - QString m_newName; QFuture m_copyFuture; QFutureWatcher m_copyFutureWatcher; }; - - - diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.cpp b/api/logic/modplatform/ftb/FtbPackDownloader.cpp index caadd4ae5..3e274c9e2 100644 --- a/api/logic/modplatform/ftb/FtbPackDownloader.cpp +++ b/api/logic/modplatform/ftb/FtbPackDownloader.cpp @@ -3,36 +3,25 @@ #include "FtbPackFetchTask.h" #include "Env.h" -FtbPackDownloader::FtbPackDownloader() { +FtbPackDownloader::FtbPackDownloader() +{ done = false; fetching = false; } -FtbPackDownloader::~FtbPackDownloader(){ +FtbPackDownloader::~FtbPackDownloader() +{ } -bool FtbPackDownloader::isValidPackSelected(){ - FtbModpack dummy; - dummy.name = "__INVALID__"; - - FtbModpack other = fetchedPacks.value(selected.name, dummy); - if(other.name == "__INVALID__") { - return false; - } - - return other.oldVersions.contains(selectedVersion) && !other.broken; -} - -QString FtbPackDownloader::getSuggestedInstanceName() { - return selected.name; -} - -FtbModpackList FtbPackDownloader::getModpacks() { +FtbModpackList FtbPackDownloader::getModpacks() +{ return static_cast(fetchedPacks.values()); } -void FtbPackDownloader::fetchModpacks(bool force = false){ - if(fetching || (!force && done)) { +void FtbPackDownloader::fetchModpacks(bool force = false) +{ + if(fetching || (!force && done)) + { qDebug() << "Skipping modpack refetch because done or already fetching [done =>" << done << "| fetching =>" << fetching << "]"; return; } @@ -46,8 +35,10 @@ void FtbPackDownloader::fetchModpacks(bool force = false){ } -void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) { - for(int i = 0; i < modpacks.size(); i++) { +void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) +{ + for(int i = 0; i < modpacks.size(); i++) + { fetchedPacks.insert(modpacks.at(i).name, modpacks.at(i)); } @@ -57,53 +48,10 @@ void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) { fetchTask->deleteLater(); } -void FtbPackDownloader::fetchFailed(QString reason) { +void FtbPackDownloader::fetchFailed(QString reason) +{ qWarning() << "Failed to fetch FtbData" << reason; fetching = false; emit packFetchFailed(); fetchTask->deleteLater(); } - -void FtbPackDownloader::selectPack(FtbModpack modpack, QString version) { - selected = modpack; - selectedVersion = version; -} - -FtbModpack FtbPackDownloader::getSelectedPack() { - return selected; -} - -void FtbPackDownloader::downloadSelected(MetaEntryPtr cache) { - NetJob *job = new NetJob("Downlad FTB Pack"); - - cache->setStale(true); - QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1/%2/%3").arg(selected.dir, selectedVersion.replace(".", "_"), selected.file); - job->addNetAction(Net::Download::makeCached(url, cache)); - downloadPath = cache->getFullPath(); - - netJobContainer.reset(job); - - connect(job, &NetJob::succeeded, this, &FtbPackDownloader::_downloadSucceeded); - connect(job, &NetJob::failed, this, &FtbPackDownloader::_downloadFailed); - connect(job, &NetJob::progress, this, &FtbPackDownloader::_downloadProgress); - job->start(); -} - -void FtbPackDownloader::_downloadSucceeded() { - netJobContainer.reset(); - emit downloadSucceded(downloadPath); -} - -void FtbPackDownloader::_downloadProgress(qint64 current, qint64 total) { - emit downloadProgress(current, total); -} - -void FtbPackDownloader::_downloadFailed(QString reason) { - netJobContainer.reset(); - emit downloadFailed(reason); -} - -NetJobPtr FtbPackDownloader::getNetJob() -{ - return netJobContainer; -} diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.h b/api/logic/modplatform/ftb/FtbPackDownloader.h index c5cc9bd23..cf7eb567c 100644 --- a/api/logic/modplatform/ftb/FtbPackDownloader.h +++ b/api/logic/modplatform/ftb/FtbPackDownloader.h @@ -11,54 +11,29 @@ #pragma once -class FtbPackDownloader; -class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject { - +class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject +{ Q_OBJECT +public: + FtbPackDownloader(); + virtual ~FtbPackDownloader(); + + void fetchModpacks(bool force); + FtbModpackList getModpacks(); + +signals: + void ready(); + void packFetchFailed(); + +private slots: + void fetchSuccess(FtbModpackList modlist); + void fetchFailed(QString reason); + private: QMap fetchedPacks; bool fetching = false; bool done = false; - FtbModpack selected; - QString selectedVersion; - QString downloadPath; - FtbPackFetchTask *fetchTask = 0; - NetJobPtr netJobContainer; - - void _downloadSucceeded(); - void _downloadFailed(QString reason); - void _downloadProgress(qint64 current, qint64 total); - -private slots: - void fetchSuccess(FtbModpackList modlist); - void fetchFailed(QString reason); - -public: - FtbPackDownloader(); - ~FtbPackDownloader(); - - bool isValidPackSelected(); - void selectPack(FtbModpack modpack, QString version); - - FtbModpack getSelectedPack(); - - void fetchModpacks(bool force); - void downloadSelected(MetaEntryPtr cache); - - QString getSuggestedInstanceName(); - - FtbModpackList getModpacks(); - NetJobPtr getNetJob(); - -signals: - void ready(); - void packFetchFailed(); - - void downloadSucceded(QString archivePath); - void downloadFailed(QString reason); - void downloadProgress(qint64 current, qint64 total); - }; diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp index 9e1511860..30253bb93 100644 --- a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp +++ b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp @@ -58,6 +58,8 @@ void FtbPackFetchTask::fileDownloadFinished(){ modpack.mods = element.attribute("mods"); modpack.image = element.attribute("image"); modpack.oldVersions = element.attribute("oldVersions").split(";"); + modpack.broken = false; + modpack.bugged = false; //remove empty if the xml is bugged for(QString curr : modpack.oldVersions) { diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.h b/api/logic/modplatform/ftb/FtbPackFetchTask.h index 3cfac4ed1..a2e4b5ab8 100644 --- a/api/logic/modplatform/ftb/FtbPackFetchTask.h +++ b/api/logic/modplatform/ftb/FtbPackFetchTask.h @@ -12,7 +12,7 @@ class MULTIMC_LOGIC_EXPORT FtbPackFetchTask : public QObject { public: FtbPackFetchTask(); - ~FtbPackFetchTask(); + virtual ~FtbPackFetchTask(); void fetch(); diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp index 530f72ca8..e3bb2340c 100644 --- a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp +++ b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp @@ -9,52 +9,65 @@ #include "minecraft/ComponentList.h" #include "minecraft/GradleSpecifier.h" -FtbPackInstallTask::FtbPackInstallTask(FtbPackDownloader *downloader, SettingsObjectPtr settings, - const QString &stagingPath, const QString &instName, const QString &instIcon, const QString &instGroup) : - m_globalSettings(settings), m_stagingPath(stagingPath), m_instName(instName), m_instIcon(instIcon), m_instGroup(instGroup) +FtbPackInstallTask::FtbPackInstallTask(FtbModpack pack, QString version) { - m_downloader = downloader; + m_pack = pack; + m_version = version; } -void FtbPackInstallTask::executeTask() { +void FtbPackInstallTask::executeTask() +{ downloadPack(); } -void FtbPackInstallTask::downloadPack(){ - FtbModpack toInstall = m_downloader->getSelectedPack(); - setStatus(tr("Downloading zip for %1").arg(toInstall.name)); +void FtbPackInstallTask::downloadPack() +{ + setStatus(tr("Downloading zip for %1").arg(m_pack.name)); - auto entry = ENV.metacache()->resolveEntry("general", "FTBPacks/" + toInstall.name); - m_downloader->downloadSelected(entry); + auto entry = ENV.metacache()->resolveEntry("general", "FTBPacks/" + m_pack.name); + NetJob *job = new NetJob("Downlad FTB Pack"); + + entry->setStale(true); + QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file); + job->addNetAction(Net::Download::makeCached(url, entry)); + archivePath = entry->getFullPath(); + + netJobContainer.reset(job); + connect(job, &NetJob::succeeded, this, &FtbPackInstallTask::onDownloadSucceeded); + connect(job, &NetJob::failed, this, &FtbPackInstallTask::onDownloadFailed); + connect(job, &NetJob::progress, this, &FtbPackInstallTask::onDownloadProgress); + job->start(); - connect(m_downloader, &FtbPackDownloader::downloadSucceded, this, &FtbPackInstallTask::onDownloadSucceeded); - connect(m_downloader, &FtbPackDownloader::downloadProgress, this, &FtbPackInstallTask::onDownloadProgress); - connect(m_downloader, &FtbPackDownloader::downloadFailed, this,&FtbPackInstallTask::onDownloadFailed); progress(1, 4); } -void FtbPackInstallTask::onDownloadSucceeded(QString archivePath){ +void FtbPackInstallTask::onDownloadSucceeded() +{ abortable = false; - unzip(archivePath); + unzip(); } -void FtbPackInstallTask::onDownloadFailed(QString reason) { +void FtbPackInstallTask::onDownloadFailed(QString reason) +{ emitFailed(reason); } -void FtbPackInstallTask::onDownloadProgress(qint64 current, qint64 total){ +void FtbPackInstallTask::onDownloadProgress(qint64 current, qint64 total) +{ abortable = true; progress(current, total * 4); - setStatus(tr("Downloading zip for %1 (%2\%)").arg(m_downloader->getSelectedPack().name).arg(current / 10)); + setStatus(tr("Downloading zip for %1 (%2\%)").arg(m_pack.name).arg(current / 10)); } -void FtbPackInstallTask::unzip(QString archivePath) { +void FtbPackInstallTask::unzip() +{ progress(2, 4); setStatus(tr("Extracting modpack")); QDir extractDir(m_stagingPath); m_packZip.reset(new QuaZip(archivePath)); - if(!m_packZip->open(QuaZip::mdUnzip)) { + if(!m_packZip->open(QuaZip::mdUnzip)) + { emitFailed(tr("Failed to open modpack file %1!").arg(archivePath)); return; } @@ -65,22 +78,26 @@ void FtbPackInstallTask::unzip(QString archivePath) { m_extractFutureWatcher.setFuture(m_extractFuture); } -void FtbPackInstallTask::onUnzipFinished() { +void FtbPackInstallTask::onUnzipFinished() +{ install(); } -void FtbPackInstallTask::onUnzipCanceled() { +void FtbPackInstallTask::onUnzipCanceled() +{ emitAborted(); } -void FtbPackInstallTask::install() { +void FtbPackInstallTask::install() +{ progress(3, 4); - FtbModpack toInstall = m_downloader->getSelectedPack(); setStatus(tr("Installing modpack")); QDir unzipMcDir(m_stagingPath + "/unzip/minecraft"); - if(unzipMcDir.exists()) { + if(unzipMcDir.exists()) + { //ok, found minecraft dir, move contents to instance dir - if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft")) { + if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft")) + { emitFailed(tr("Failed to move unzipped minecraft!")); return; } @@ -94,14 +111,15 @@ void FtbPackInstallTask::install() { MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath); auto components = instance.getComponentList(); components->buildingFromScratch(); - components->setComponentVersion("net.minecraft", toInstall.mcVersion, true); + components->setComponentVersion("net.minecraft", m_pack.mcVersion, true); bool fallback = true; //handle different versions QFile packJson(m_stagingPath + "/.minecraft/pack.json"); QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods"); - if(packJson.exists()) { + if(packJson.exists()) + { packJson.open(QIODevice::ReadOnly | QIODevice::Text); QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll()); packJson.close(); @@ -109,15 +127,17 @@ void FtbPackInstallTask::install() { //we only care about the libs QJsonArray libs = doc.object().value("libraries").toArray(); - foreach (const QJsonValue &value, libs) { + foreach (const QJsonValue &value, libs) + { QString nameValue = value.toObject().value("name").toString(); - if(!nameValue.startsWith("net.minecraftforge")) { + if(!nameValue.startsWith("net.minecraftforge")) + { continue; } GradleSpecifier forgeVersion(nameValue); - components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(toInstall.mcVersion, "").replace("-", "")); + components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", "")); packJson.remove(); fallback = false; break; @@ -125,7 +145,8 @@ void FtbPackInstallTask::install() { } - if(jarmodDir.exists()) { + if(jarmodDir.exists()) + { qDebug() << "Found jarmods, installing..."; QStringList jarmods; @@ -142,7 +163,8 @@ void FtbPackInstallTask::install() { //just nuke unzip directory, it s not needed anymore FS::deletePath(m_stagingPath + "/unzip"); - if(fallback) { + if(fallback) + { //TODO: Some fallback mechanism... or just keep failing! emitFailed(tr("No installation method found!")); return; @@ -154,7 +176,8 @@ void FtbPackInstallTask::install() { instance.init(); instance.setName(m_instName); - if(m_instIcon == "default") { + if(m_instIcon == "default") + { m_instIcon = "ftb_logo"; } instance.setIconKey(m_instIcon); @@ -166,8 +189,9 @@ void FtbPackInstallTask::install() { bool FtbPackInstallTask::abort() { - if(abortable) { - return m_downloader->getNetJob()->abort(); + if(abortable) + { + return netJobContainer->abort(); } return false; } diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.h b/api/logic/modplatform/ftb/FtbPackInstallTask.h index 7d6e5276f..64f4809d1 100644 --- a/api/logic/modplatform/ftb/FtbPackInstallTask.h +++ b/api/logic/modplatform/ftb/FtbPackInstallTask.h @@ -1,5 +1,5 @@ #pragma once -#include "tasks/Task.h" +#include "InstanceTask.h" #include "modplatform/ftb/FtbPackDownloader.h" #include "BaseInstanceProvider.h" #include "net/NetJob.h" @@ -9,47 +9,41 @@ #include "meta/Version.h" #include "meta/VersionList.h" -class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public Task { +class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask { Q_OBJECT public: - explicit FtbPackInstallTask(FtbPackDownloader *downloader, SettingsObjectPtr settings, const QString &stagingPath, const QString &instName, - const QString &instIcon, const QString &instGroup); + explicit FtbPackInstallTask(FtbModpack pack, QString version); + virtual ~FtbPackInstallTask(){} + bool abort() override; protected: //! Entry point for tasks. virtual void executeTask() override; -private: /* data */ - SettingsObjectPtr m_globalSettings; - QString m_stagingPath; - QString m_instName; - QString m_instIcon; - QString m_instGroup; - NetJobPtr m_netJobPtr; - - FtbPackDownloader *m_downloader; - - std::unique_ptr m_packZip; - QFuture m_extractFuture; - QFutureWatcher m_extractFutureWatcher; - +private: void downloadPack(); - void unzip(QString archivePath); + void unzip(); void install(); - bool moveRecursively(QString source, QString dest); - - bool abortable = false; - private slots: - void onDownloadSucceeded(QString archivePath); + void onDownloadSucceeded(); void onDownloadFailed(QString reason); void onDownloadProgress(qint64 current, qint64 total); void onUnzipFinished(); void onUnzipCanceled(); +private: /* data */ + bool abortable = false; + std::unique_ptr m_packZip; + QFuture m_extractFuture; + QFutureWatcher m_extractFutureWatcher; + NetJobPtr netJobContainer; + QString archivePath; + + FtbModpack m_pack; + QString m_version; }; diff --git a/api/logic/modplatform/ftb/PackHelpers.h b/api/logic/modplatform/ftb/PackHelpers.h index f761ed6bc..b184ed330 100644 --- a/api/logic/modplatform/ftb/PackHelpers.h +++ b/api/logic/modplatform/ftb/PackHelpers.h @@ -17,8 +17,8 @@ struct FtbModpack { QString dir; QString file; //<- Url in the xml, but doesn't make much sense - bool bugged = false; - bool broken = false; + bool bugged = true; + bool broken = true; }; //We need it for the proxy model Q_DECLARE_METATYPE(FtbModpack) diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 48c1a359f..5eeca2409 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -80,29 +80,32 @@ SET(MULTIMC_SOURCES JavaCommon.h JavaCommon.cpp - # GUI - page dialog pages + # GUI - paged dialog base pages/BasePage.h pages/BasePageContainer.h - pages/VersionPage.cpp - pages/VersionPage.h - pages/TexturePackPage.h - pages/ResourcePackPage.h - pages/ModFolderPage.cpp - pages/ModFolderPage.h - pages/NotesPage.cpp - pages/NotesPage.h - pages/LogPage.cpp - pages/LogPage.h - pages/InstanceSettingsPage.cpp - pages/InstanceSettingsPage.h - pages/ScreenshotsPage.cpp - pages/ScreenshotsPage.h - pages/OtherLogsPage.cpp - pages/OtherLogsPage.h - pages/LegacyUpgradePage.cpp - pages/LegacyUpgradePage.h - pages/WorldListPage.cpp - pages/WorldListPage.h + pages/BasePageProvider.h + + # GUI - instance pages + pages/instance/VersionPage.cpp + pages/instance/VersionPage.h + pages/instance/TexturePackPage.h + pages/instance/ResourcePackPage.h + pages/instance/ModFolderPage.cpp + pages/instance/ModFolderPage.h + pages/instance/NotesPage.cpp + pages/instance/NotesPage.h + pages/instance/LogPage.cpp + pages/instance/LogPage.h + pages/instance/InstanceSettingsPage.cpp + pages/instance/InstanceSettingsPage.h + pages/instance/ScreenshotsPage.cpp + pages/instance/ScreenshotsPage.h + pages/instance/OtherLogsPage.cpp + pages/instance/OtherLogsPage.h + pages/instance/LegacyUpgradePage.cpp + pages/instance/LegacyUpgradePage.h + pages/instance/WorldListPage.cpp + pages/instance/WorldListPage.h # GUI - global settings pages pages/global/AccountListPage.cpp @@ -124,6 +127,18 @@ SET(MULTIMC_SOURCES pages/global/PackagesPage.cpp pages/global/PackagesPage.h + # GUI - platform pages + pages/modplatform/VanillaPage.cpp + pages/modplatform/VanillaPage.h + pages/modplatform/FTBPage.cpp + pages/modplatform/FTBPage.h + pages/modplatform/TwitchPage.cpp + pages/modplatform/TwitchPage.h + pages/modplatform/TechnicPage.cpp + pages/modplatform/TechnicPage.h + pages/modplatform/ImportPage.cpp + pages/modplatform/ImportPage.h + # GUI - dialogs dialogs/AboutDialog.cpp dialogs/AboutDialog.h @@ -159,8 +174,6 @@ SET(MULTIMC_SOURCES dialogs/VersionSelectDialog.h dialogs/SkinUploadDialog.cpp dialogs/SkinUploadDialog.h - dialogs/ChooseFtbPackDialog.cpp - dialogs/ChooseFtbPackDialog.h # GUI - widgets @@ -210,15 +223,15 @@ SET(MULTIMC_SOURCES ######## UIs ######## SET(MULTIMC_UIS # Instance pages - pages/VersionPage.ui - pages/ModFolderPage.ui - pages/LogPage.ui - pages/InstanceSettingsPage.ui - pages/NotesPage.ui - pages/ScreenshotsPage.ui - pages/OtherLogsPage.ui - pages/LegacyUpgradePage.ui - pages/WorldListPage.ui + pages/instance/VersionPage.ui + pages/instance/ModFolderPage.ui + pages/instance/LogPage.ui + pages/instance/InstanceSettingsPage.ui + pages/instance/NotesPage.ui + pages/instance/ScreenshotsPage.ui + pages/instance/OtherLogsPage.ui + pages/instance/LegacyUpgradePage.ui + pages/instance/WorldListPage.ui # Global settings pages pages/global/AccountListPage.ui @@ -230,6 +243,13 @@ SET(MULTIMC_UIS pages/global/PasteEEPage.ui pages/global/PackagesPage.ui + # Platform pages + pages/modplatform/VanillaPage.ui + pages/modplatform/FTBPage.ui + pages/modplatform/TwitchPage.ui + pages/modplatform/TechnicPage.ui + pages/modplatform/ImportPage.ui + # Dialogs dialogs/CopyInstanceDialog.ui dialogs/NewComponentDialog.ui @@ -244,7 +264,6 @@ SET(MULTIMC_UIS dialogs/UpdateDialog.ui dialogs/NotificationDialog.ui dialogs/SkinUploadDialog.ui - dialogs/ChooseFtbPackDialog.ui # Widgets/other widgets/CustomCommands.ui diff --git a/application/FtbListModel.cpp b/application/FtbListModel.cpp index 68a687943..d79bcac06 100644 --- a/application/FtbListModel.cpp +++ b/application/FtbListModel.cpp @@ -108,7 +108,9 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const void FtbListModel::fill(FtbModpackList modpacks) { + beginResetModel(); this->modpacks = modpacks; + endResetModel(); } FtbModpack FtbListModel::at(int row) diff --git a/application/InstancePageProvider.h b/application/InstancePageProvider.h index b13ce93dc..9dda78597 100644 --- a/application/InstancePageProvider.h +++ b/application/InstancePageProvider.h @@ -3,18 +3,18 @@ #include "minecraft/legacy/LegacyInstance.h" #include #include "pages/BasePage.h" -#include "pages/LogPage.h" -#include "pages/VersionPage.h" -#include "pages/ModFolderPage.h" -#include "pages/ResourcePackPage.h" -#include "pages/TexturePackPage.h" -#include "pages/NotesPage.h" -#include "pages/ScreenshotsPage.h" -#include "pages/InstanceSettingsPage.h" -#include "pages/OtherLogsPage.h" #include "pages/BasePageProvider.h" -#include "pages/LegacyUpgradePage.h" -#include "pages/WorldListPage.h" +#include "pages/instance/LogPage.h" +#include "pages/instance/VersionPage.h" +#include "pages/instance/ModFolderPage.h" +#include "pages/instance/ResourcePackPage.h" +#include "pages/instance/TexturePackPage.h" +#include "pages/instance/NotesPage.h" +#include "pages/instance/ScreenshotsPage.h" +#include "pages/instance/InstanceSettingsPage.h" +#include "pages/instance/OtherLogsPage.h" +#include "pages/instance/LegacyUpgradePage.h" +#include "pages/instance/WorldListPage.h" class InstancePageProvider : public QObject, public BasePageProvider diff --git a/application/InstanceWindow.cpp b/application/InstanceWindow.cpp index 2e876feac..5895ca3a4 100644 --- a/application/InstanceWindow.cpp +++ b/application/InstanceWindow.cpp @@ -47,7 +47,7 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget *parent) // Add page container { auto provider = std::make_shared(m_instance); - m_container = new PageContainer(provider, "console", this); + m_container = new PageContainer(provider.get(), "console", this); m_container->setParentContainer(this); setCentralWidget(m_container); } diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 542d1da6a..60742412a 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -90,6 +90,7 @@ #include #include "UpdateController.h" #include "KonamiCode.h" +#include // WHY: to hold the pre-translation strings together with the T pointer, so it can be retranslated without a lot of ugly code template @@ -1267,26 +1268,9 @@ void MainWindow::runModalTask(Task *task) loadDialog.execWithTask(task); } -void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url) +void MainWindow::instanceFromInstanceTask(InstanceTask *rawTask) { - std::unique_ptr task(MMC->folderProvider()->zipImportTask(url, instName, instGroup, instIcon)); - runModalTask(task.get()); - - // FIXME: handle instance selection after creation - // finalizeInstance(newInstance); -} - -void MainWindow::instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version) -{ - std::unique_ptr task(MMC->folderProvider()->creationTask(version, instName, instGroup, instIcon)); - runModalTask(task.get()); - - // FIXME: handle instance selection after creation - // finalizeInstance(newInstance); -} - -void MainWindow::instanceFromFtbPack(FtbPackDownloader *downloader, QString instName, QString instGroup, QString instIcon) { - std::unique_ptr task(MMC->folderProvider()->ftbCreationTask(downloader, instName, instGroup, instIcon)); + std::unique_ptr task(MMC->folderProvider()->wrapInstanceTask(rawTask)); runModalTask(task.get()); // FIXME: handle instance selection after creation @@ -1302,8 +1286,11 @@ void MainWindow::on_actionCopyInstance_triggered() if (!copyInstDlg.exec()) return; - std::unique_ptr task(MMC->folderProvider()->copyTask(m_selectedInstance, copyInstDlg.instName(), copyInstDlg.instGroup(), - copyInstDlg.iconKey(), copyInstDlg.shouldCopySaves())); + auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.shouldCopySaves()); + copyTask->setName(copyInstDlg.instName()); + copyTask->setGroup(copyInstDlg.instGroup()); + copyTask->setIcon(copyInstDlg.iconKey()); + std::unique_ptr task(MMC->folderProvider()->wrapInstanceTask(copyTask)); runModalTask(task.get()); // FIXME: handle instance selection after creation @@ -1366,19 +1353,10 @@ void MainWindow::addInstance(QString url) MMC->settings()->set("LastUsedGroupForNewInstance", newInstDlg.instGroup()); - const QUrl modpackUrl = newInstDlg.modpackUrl(); - - if(newInstDlg.isFtbModpackRequested()) + InstanceTask * creationTask = newInstDlg.extractTask(); + if(creationTask) { - instanceFromFtbPack(newInstDlg.getFtbPackDownloader(), newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey()); - } - else if (modpackUrl.isValid()) - { - instanceFromZipPack(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), modpackUrl); - } - else - { - instanceFromVersion(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), newInstDlg.selectedVersion()); + instanceFromInstanceTask(creationTask); } } diff --git a/application/MainWindow.h b/application/MainWindow.h index e9897606f..609df4ca1 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -39,6 +39,7 @@ class BaseProfilerFactory; class GroupView; class ServerStatus; class KonamiCode; +class InstanceTask; class MainWindow : public QMainWindow { @@ -187,9 +188,7 @@ private: void setSelectedInstanceById(const QString &id); void runModalTask(Task *task); - void instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version); - void instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url); - void instanceFromFtbPack(FtbPackDownloader *downloader, QString instName, QString instGroup, QString instIcon); + void instanceFromInstanceTask(InstanceTask *task); void finalizeInstance(InstancePtr inst); private: diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 230d757f4..4236fbcfa 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -497,6 +497,8 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) m_settings->registerSetting("PagedGeometry", ""); + m_settings->registerSetting("NewInstanceGeometry", ""); + m_settings->registerSetting("UpdateDialogGeometry", ""); // paste.ee API key diff --git a/application/SettingsUI.h b/application/SettingsUI.h index 5b8badf21..0d14fbee4 100644 --- a/application/SettingsUI.h +++ b/application/SettingsUI.h @@ -19,7 +19,7 @@ void ShowPageDialog(T raw_provider, QWidget * parent, QString open_page = QStrin return; { SettingsObject::Lock lock(MMC->settings()); - PageDialog dlg(provider, open_page, parent); + PageDialog dlg(provider.get(), open_page, parent); dlg.exec(); } } diff --git a/application/VersionProxyModel.cpp b/application/VersionProxyModel.cpp index 0dbc4ef62..c180adf2a 100644 --- a/application/VersionProxyModel.cpp +++ b/application/VersionProxyModel.cpp @@ -20,34 +20,21 @@ public: const auto &filters = m_parent->filters(); for (auto it = filters.begin(); it != filters.end(); ++it) { - auto role = it.key(); auto idx = sourceModel()->index(source_row, 0, source_parent); - auto data = sourceModel()->data(idx, role); - - switch(role) + auto data = sourceModel()->data(idx, it.key()); + auto match = data.toString(); + if(!it.value()->accepts(match)) { - case BaseVersionList::ParentVersionRole: - case BaseVersionList::VersionIdRole: - // TODO: work with metadata here. Previous implementation based on the Version class is not sufficient - default: - { - auto match = data.toString(); - if(it.value().exact) - { - if (match != it.value().string) - { - return false; - } - } - else if (match.contains(it.value().string)) - { - return false; - } - } + return false; } } return true; } + + void filterChanged() + { + invalidateFilter(); + } private: VersionProxyModel *m_parent; }; @@ -56,12 +43,12 @@ VersionProxyModel::VersionProxyModel(QObject *parent) : QAbstractProxyModel(pare { filterModel = new VersionFilterModel(this); connect(filterModel, &QAbstractItemModel::dataChanged, this, &VersionProxyModel::sourceDataChanged); + connect(filterModel, &QAbstractItemModel::rowsAboutToBeInserted, this, &VersionProxyModel::sourceRowsAboutToBeInserted); + connect(filterModel, &QAbstractItemModel::rowsInserted, this, &VersionProxyModel::sourceRowsInserted); + connect(filterModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &VersionProxyModel::sourceRowsAboutToBeRemoved); + connect(filterModel, &QAbstractItemModel::rowsRemoved, this, &VersionProxyModel::sourceRowsRemoved); // FIXME: implement when needed /* - connect(replacing, &QAbstractItemModel::rowsAboutToBeInserted, this, &VersionProxyModel::sourceRowsAboutToBeInserted); - connect(replacing, &QAbstractItemModel::rowsInserted, this, &VersionProxyModel::sourceRowsInserted); - connect(replacing, &QAbstractItemModel::rowsAboutToBeRemoved, this, &VersionProxyModel::sourceRowsAboutToBeRemoved); - connect(replacing, &QAbstractItemModel::rowsRemoved, this, &VersionProxyModel::sourceRowsRemoved); connect(replacing, &QAbstractItemModel::rowsAboutToBeMoved, this, &VersionProxyModel::sourceRowsAboutToBeMoved); connect(replacing, &QAbstractItemModel::rowsMoved, this, &VersionProxyModel::sourceRowsMoved); connect(replacing, &QAbstractItemModel::layoutAboutToBeChanged, this, &VersionProxyModel::sourceLayoutAboutToBeChanged); @@ -390,16 +377,13 @@ QModelIndex VersionProxyModel::getVersion(const QString& version) const void VersionProxyModel::clearFilters() { m_filters.clear(); - filterModel->invalidate(); + filterModel->filterChanged(); } -void VersionProxyModel::setFilter(const BaseVersionList::ModelRoles column, const QString &filter, const bool exact) +void VersionProxyModel::setFilter(const BaseVersionList::ModelRoles column, Filter * f) { - Filter f; - f.string = filter; - f.exact = exact; - m_filters[column] = f; - filterModel->invalidate(); + m_filters[column].reset(f); + filterModel->filterChanged(); } const VersionProxyModel::FilterMap &VersionProxyModel::filters() const @@ -417,4 +401,25 @@ void VersionProxyModel::sourceReset() endResetModel(); } +void VersionProxyModel::sourceRowsAboutToBeInserted(const QModelIndex& parent, int first, int last) +{ + beginInsertRows(parent, first, last); +} + +void VersionProxyModel::sourceRowsInserted(const QModelIndex& parent, int first, int last) +{ + endInsertRows(); +} + +void VersionProxyModel::sourceRowsAboutToBeRemoved(const QModelIndex& parent, int first, int last) +{ + beginRemoveRows(parent, first, last); +} + +void VersionProxyModel::sourceRowsRemoved(const QModelIndex& parent, int first, int last) +{ + endRemoveRows(); +} + + #include "VersionProxyModel.moc" diff --git a/application/VersionProxyModel.h b/application/VersionProxyModel.h index 4441ea6b3..33a0d1eac 100644 --- a/application/VersionProxyModel.h +++ b/application/VersionProxyModel.h @@ -2,17 +2,15 @@ #include #include "BaseVersionList.h" +#include + class VersionFilterModel; class VersionProxyModel: public QAbstractProxyModel { Q_OBJECT public: - struct Filter - { - QString string; - bool exact = false; - }; + enum Column { Name, @@ -22,7 +20,7 @@ public: Architecture, Path }; - typedef QHash FilterMap; + typedef QHash> FilterMap; public: VersionProxyModel ( QObject* parent = 0 ); @@ -39,16 +37,23 @@ public: virtual void setSourceModel(QAbstractItemModel *sourceModel) override; const FilterMap &filters() const; - void setFilter(const BaseVersionList::ModelRoles column, const QString &filter, const bool exact); + void setFilter(const BaseVersionList::ModelRoles column, Filter * filter); void clearFilters(); QModelIndex getRecommended() const; QModelIndex getVersion(const QString & version) const; private slots: void sourceDataChanged(const QModelIndex &source_top_left,const QModelIndex &source_bottom_right); + void sourceAboutToBeReset(); void sourceReset(); + void sourceRowsAboutToBeInserted(const QModelIndex &parent, int first, int last); + void sourceRowsInserted(const QModelIndex &parent, int first, int last); + + void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last); + void sourceRowsRemoved(const QModelIndex &parent, int first, int last); + private: QList m_columns; FilterMap m_filters; diff --git a/application/dialogs/ChooseFtbPackDialog.cpp b/application/dialogs/ChooseFtbPackDialog.cpp deleted file mode 100644 index b1deae6ee..000000000 --- a/application/dialogs/ChooseFtbPackDialog.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "ChooseFtbPackDialog.h" -#include - -ChooseFtbPackDialog::ChooseFtbPackDialog(FtbModpackList modpacks) : ui(new Ui::ChooseFtbPackDialog) -{ - ui->setupUi(this); - - filterModel = new FtbFilterModel(this); - listModel = new FtbListModel(this); - filterModel->setSourceModel(listModel); - listModel->fill(modpacks); - - ui->packList->setModel(filterModel); - ui->packList->setSortingEnabled(true); - ui->packList->header()->hide(); - ui->packList->setIndentation(0); - - filterModel->setSorting(FtbFilterModel::Sorting::ByName); - - for(int i = 0; i < filterModel->getAvailableSortings().size(); i++){ - ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); - } - - ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting())); - - connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onSortingSelectionChanged); - connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &ChooseFtbPackDialog::onVersionSelectionItemChanged); - connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ChooseFtbPackDialog::onPackSelectionChanged); - - ui->modpackInfo->setOpenExternalLinks(true); - - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); -} - -ChooseFtbPackDialog::~ChooseFtbPackDialog() -{ - delete ui; -} - -void ChooseFtbPackDialog::onPackSelectionChanged(QModelIndex now, QModelIndex prev) -{ - ui->packVersionSelection->clear(); - FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value(); - - ui->modpackInfo->setHtml("Pack by " + selectedPack.author + "" + "
Minecraft " + selectedPack.mcVersion + "
" - "
" + selectedPack.description + "
  • " + selectedPack.mods.replace(";", "
  • ") + "
"); - - bool currentAdded = false; - - for(int i = 0; i < selectedPack.oldVersions.size(); i++) { - if(selectedPack.currentVersion == selectedPack.oldVersions.at(i)) { - currentAdded = true; - } - ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i)); - } - - if(!currentAdded) { - ui->packVersionSelection->addItem(selectedPack.currentVersion); - } - - selected = selectedPack; - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!selected.broken); -} - -void ChooseFtbPackDialog::onVersionSelectionItemChanged(QString data) -{ - if(data.isNull() || data.isEmpty()) { - selectedVersion = ""; - return; - } - - selectedVersion = data; -} - -FtbModpack ChooseFtbPackDialog::getSelectedModpack() -{ - return selected; -} - -QString ChooseFtbPackDialog::getSelectedVersion() -{ - return selectedVersion; -} - -void ChooseFtbPackDialog::onSortingSelectionChanged(QString data) -{ - filterModel->setSorting(filterModel->getAvailableSortings().value(data)); -} diff --git a/application/dialogs/ChooseFtbPackDialog.h b/application/dialogs/ChooseFtbPackDialog.h deleted file mode 100644 index f9f3dd083..000000000 --- a/application/dialogs/ChooseFtbPackDialog.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include -#include -#include "ui_ChooseFtbPackDialog.h" -#include "FtbListModel.h" - -namespace Ui { - class ChooseFtbPackDialog; -} - -class ChooseFtbPackDialog : public QDialog { - - Q_OBJECT - -private: - Ui::ChooseFtbPackDialog *ui; - FtbModpack selected; - QString selectedVersion; - FtbListModel* listModel; - FtbFilterModel* filterModel; - -private slots: - void onSortingSelectionChanged(QString data); - void onVersionSelectionItemChanged(QString data); - void onPackSelectionChanged(QModelIndex first, QModelIndex second); -public: - ChooseFtbPackDialog(FtbModpackList packs); - ~ChooseFtbPackDialog(); - - FtbModpack getSelectedModpack(); - QString getSelectedVersion(); -}; diff --git a/application/dialogs/ChooseFtbPackDialog.ui b/application/dialogs/ChooseFtbPackDialog.ui deleted file mode 100644 index f590a4cdd..000000000 --- a/application/dialogs/ChooseFtbPackDialog.ui +++ /dev/null @@ -1,119 +0,0 @@ - - - ChooseFtbPackDialog - - - - 0 - 0 - 700 - 437 - - - - - 0 - 0 - - - - false - - - - - - Version selected: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - true - - - false - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - false - - - - - - - - 0 - 0 - - - - - - - - - - - - - buttonBox - accepted() - ChooseFtbPackDialog - accept() - - - 211 - 173 - - - 889 - 501 - - - - - buttonBox - rejected() - ChooseFtbPackDialog - reject() - - - 225 - 162 - - - 524 - 458 - - - - - diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp index eee3991ca..f0783603c 100644 --- a/application/dialogs/NewInstanceDialog.cpp +++ b/application/dialogs/NewInstanceDialog.cpp @@ -25,80 +25,30 @@ #include "VersionSelectDialog.h" #include "ProgressDialog.h" #include "IconPickerDialog.h" -#include "ChooseFtbPackDialog.h" #include #include #include #include +#include -#include -#include - -class UrlValidator : public QValidator -{ -public: - using QValidator::QValidator; - - State validate(QString &in, int &pos) const - { - const QUrl url(in); - if (url.isValid() && !url.isRelative() && !url.isEmpty()) - { - return Acceptable; - } - else if (QFile::exists(in)) - { - return Acceptable; - } - else - { - return Intermediate; - } - } -}; +#include "widgets/PageContainer.h" +#include +#include +#include +#include +#include NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent) : QDialog(parent), ui(new Ui::NewInstanceDialog) { ui->setupUi(this); - resize(minimumSizeHint()); - layout()->setSizeConstraint(QLayout::SetFixedSize); - auto vlist = ENV.metadataIndex()->get("net.minecraft"); - if(vlist->isLoaded()) - { - setSelectedVersion(vlist->getRecommended()); - } - else - { - vlist->load(Net::Mode::Online); - auto task = vlist->getLoadTask(); - if(vlist->isLoaded()) - { - setSelectedVersion(vlist->getRecommended()); - } - if(task) - { - connect(task.get(), &Task::succeeded, this, &NewInstanceDialog::versionListUpdated); - } - } + setWindowIcon(MMC->getThemedIcon("new")); InstIconKey = "default"; ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); - ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); - - ui->instNameTextBox->setAlignment(Qt::AlignHCenter); - - connect(ui->modpackEdit, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState); - connect(ui->modpackBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); - - connect(ui->versionBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); - connect(ui->versionTextBox, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState); - - connect(ui->ftbBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); - auto groups = MMC->instances()->getGroups().toSet(); auto groupList = QStringList(groups.toList()); groupList.sort(Qt::CaseInsensitive); @@ -113,32 +63,47 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString } ui->groupBox->setCurrentIndex(index); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); - ui->buttonBox->setFocus(); - originalPlaceholderText = ui->instNameTextBox->placeholderText(); + m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok); + m_buttons->button(QDialogButtonBox::Ok)->setDefault(true); + + connect(m_buttons->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept); + connect(m_buttons->button(QDialogButtonBox::Help), &QPushButton::clicked, m_container, &PageContainer::help); + + m_container = new PageContainer(this); + m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding); + ui->verticalLayout->insertWidget(2, m_container); + + m_container->addButtons(m_buttons); + m_buttons->setFocus(); + if(!url.isEmpty()) { - ui->modpackBox->setChecked(true); - ui->modpackEdit->setText(url); + m_container->selectPage("import"); + importPage->setUrl(url); } - ftbPackDownloader = new FtbPackDownloader(); - - connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &NewInstanceDialog::ftbPackDataDownloadSuccessfully); - connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &NewInstanceDialog::ftbPackDataDownloadFailed); - - ftbPackDownloader->fetchModpacks(false); - updateDialogState(); + + restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("NewInstanceGeometry").toByteArray())); } -void NewInstanceDialog::versionListUpdated() +QList NewInstanceDialog::getPages() { - if(!m_versionSetByUser) + importPage = new ImportPage(this); + return { - auto vlist = ENV.metadataIndex()->get("net.minecraft"); - setSelectedVersion(vlist->getRecommended()); - } + new VanillaPage(this), + new FTBPage(this), + importPage, + new TwitchPage(this), + new TechnicPage(this) + }; +} + +QString NewInstanceDialog::dialogTitle() +{ + return tr("New Instance"); } NewInstanceDialog::~NewInstanceDialog() @@ -146,58 +111,29 @@ NewInstanceDialog::~NewInstanceDialog() delete ui; } -void NewInstanceDialog::updateDialogState() +void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task) { - QString suggestedName; - if(ui->versionBox->isChecked()) - { - suggestedName = ui->versionTextBox->text(); - } - else if (ui->modpackBox->isChecked()) - { - auto url = QUrl::fromUserInput(ui->modpackEdit->text()); - QFileInfo fi(url.fileName()); - suggestedName = fi.completeBaseName(); - } - else if (ui->ftbBox->isChecked()) - { - if(ftbPackDownloader->isValidPackSelected()) { - suggestedName = ftbPackDownloader->getSuggestedInstanceName(); - ui->labelFtbPack->setText(selectedPack.name); - } + creationTask.reset(task); + ui->instNameTextBox->setPlaceholderText(name); - } - - ftbModpackRequested = ui->ftbBox->isChecked(); - - if(suggestedName.isEmpty()) - { - ui->instNameTextBox->setPlaceholderText(originalPlaceholderText); - } - else - { - ui->instNameTextBox->setPlaceholderText(suggestedName); - } - bool allowOK = !instName().isEmpty() && ( - (ui->versionBox->isChecked() && m_selectedVersion) || - (ui->modpackBox->isChecked() && ui->modpackEdit->hasAcceptableInput()) || - (ui->ftbBox->isChecked() && ftbPackDownloader && ftbPackDownloader->isValidPackSelected() ) - ); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(allowOK); + auto allowOK = task && !instName().isEmpty(); + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK); } -void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version) +InstanceTask * NewInstanceDialog::extractTask() { - m_selectedVersion = version; + InstanceTask * extracted = creationTask.get(); + creationTask.release(); + extracted->setName(instName()); + extracted->setGroup(instGroup()); + extracted->setIcon(iconKey()); + return extracted; +} - if (m_selectedVersion) - { - ui->versionTextBox->setText(version->descriptor()); - } - else - { - ui->versionTextBox->setText(""); - } +void NewInstanceDialog::updateDialogState() +{ + auto allowOK = creationTask && !instName().isEmpty(); + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK); } QString NewInstanceDialog::instName() const @@ -208,7 +144,7 @@ QString NewInstanceDialog::instName() const return result.trimmed(); } result = ui->instNameTextBox->placeholderText(); - if(result.size() && result != originalPlaceholderText) + if(result.size()) { return result.trimmed(); } @@ -223,45 +159,6 @@ QString NewInstanceDialog::iconKey() const { return InstIconKey; } -QUrl NewInstanceDialog::modpackUrl() const -{ - if (ui->modpackBox->isChecked()) - { - const QUrl url(ui->modpackEdit->text()); - if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) - { - return url; - } - else - { - return QUrl::fromLocalFile(ui->modpackEdit->text()); - } - } - else - { - return QUrl(); - } -} - -BaseVersionPtr NewInstanceDialog::selectedVersion() const -{ - return m_selectedVersion; -} - -void NewInstanceDialog::on_btnChangeVersion_clicked() -{ - VersionSelectDialog vselect(ENV.metadataIndex()->get("net.minecraft").get(), tr("Change Minecraft version"), this); - vselect.exec(); - if (vselect.result() == QDialog::Accepted) - { - BaseVersionPtr version = vselect.selectedVersion(); - if (version) - { - m_versionSetByUser = true; - setSelectedVersion(version); - } - } -} void NewInstanceDialog::on_iconButton_clicked() { @@ -280,46 +177,14 @@ void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) updateDialogState(); } -void NewInstanceDialog::on_modpackBtn_clicked() +void NewInstanceDialog::closeEvent(QCloseEvent* event) { - const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)")); - if (url.isValid()) + qDebug() << "New instance dialog close requested"; + if (m_container->prepareToClose()) { - if (url.isLocalFile()) - { - ui->modpackEdit->setText(url.toLocalFile()); - } - else - { - ui->modpackEdit->setText(url.toString()); - } + qDebug() << "New instance dialog close approved"; + MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64()); + qDebug() << "New instance dialog geometry saved"; + QDialog::closeEvent(event); } } - -bool NewInstanceDialog::isFtbModpackRequested() { - return ftbModpackRequested; -} - -FtbPackDownloader *NewInstanceDialog::getFtbPackDownloader() { - return ftbPackDownloader; -} - -void NewInstanceDialog::on_btnChooseFtbPack_clicked() { - ChooseFtbPackDialog dl(ftbPackDownloader->getModpacks()); - dl.exec(); - if(dl.result() == QDialog::Accepted) { - selectedPack = dl.getSelectedModpack(); - ftbPackDownloader->selectPack(selectedPack, dl.getSelectedVersion()); - } - updateDialogState(); -} - -void NewInstanceDialog::ftbPackDataDownloadSuccessfully() { - ui->packDataDownloadStatus->setText(tr("(Data download complete)")); - ui->ftbBox->setEnabled(true); -} - -void NewInstanceDialog::ftbPackDataDownloadFailed() { - ui->packDataDownloadStatus->setText(tr("(Data download failed)")); -} - diff --git a/application/dialogs/NewInstanceDialog.h b/application/dialogs/NewInstanceDialog.h index f1fe26f44..ca134d32c 100644 --- a/application/dialogs/NewInstanceDialog.h +++ b/application/dialogs/NewInstanceDialog.h @@ -18,15 +18,19 @@ #include #include "BaseVersion.h" -#include "modplatform/ftb/FtbPackDownloader.h" -#include "modplatform/ftb/PackHelpers.h" +#include "pages/BasePageProvider.h" +#include "InstanceTask.h" namespace Ui { class NewInstanceDialog; } -class NewInstanceDialog : public QDialog +class PageContainer; +class QDialogButtonBox; +class ImportPage; + +class NewInstanceDialog : public QDialog, public BasePageProvider { Q_OBJECT @@ -36,39 +40,28 @@ public: void updateDialogState(); - void setSelectedVersion(BaseVersionPtr version); + void setSuggestedPack(const QString & name = QString(), InstanceTask * task = nullptr); + InstanceTask * extractTask(); + + QString dialogTitle() override; + QList getPages() override; QString instName() const; QString instGroup() const; QString iconKey() const; - QUrl modpackUrl() const; - BaseVersionPtr selectedVersion() const; - - bool isFtbModpackRequested(); - FtbPackDownloader* getFtbPackDownloader(); private slots: - void on_btnChangeVersion_clicked(); void on_iconButton_clicked(); - void on_modpackBtn_clicked(); - void on_btnChooseFtbPack_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); - void versionListUpdated(); - - void ftbPackDataDownloadSuccessfully(); - void ftbPackDataDownloadFailed(); + virtual void closeEvent(QCloseEvent *event); private: - Ui::NewInstanceDialog *ui; + Ui::NewInstanceDialog *ui = nullptr; + PageContainer * m_container = nullptr; + QDialogButtonBox * m_buttons = nullptr; - bool m_versionSetByUser = false; - bool ftbModpackRequested = false; - - BaseVersionPtr m_selectedVersion; QString InstIconKey; - QString originalPlaceholderText; - - FtbPackDownloader* ftbPackDownloader; - FtbModpack selectedPack; + ImportPage *importPage = nullptr; + std::unique_ptr creationTask; }; diff --git a/application/dialogs/NewInstanceDialog.ui b/application/dialogs/NewInstanceDialog.ui index 428b9c571..7fb19ff5c 100644 --- a/application/dialogs/NewInstanceDialog.ui +++ b/application/dialogs/NewInstanceDialog.ui @@ -9,8 +9,8 @@ 0 0 - 281 - 407 + 730 + 127 @@ -25,21 +25,38 @@ - - - - - Qt::Horizontal + + + + + true - - - 40 - 20 - - - + - + + + + &Group: + + + groupBox + + + + + + + + + + &Name: + + + instNameTextBox + + + + @@ -49,28 +66,8 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Name - - - @@ -78,304 +75,13 @@ - - - - - - &Group: - - - groupBox - - - - - - - - 0 - 0 - - - - true - - - - - - - - - - - false - - - Install FTB Pack - - - - - - - ... - - - - - - - false - - - ... - - - - - - - false - - - ... - - - - - - - false - - - No Pack choosen - - - - - - - Impor&t Modpack (local file or link): - - - - - - - Vani&lla Minecraft (select version): - - - true - - - - - - - true - - - - - - - false - - - http:// - - - - - - - (Loading Pack data...) - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - FocusLineEdit - QLineEdit -
widgets/FocusLineEdit.h
-
-
+ iconButton instNameTextBox groupBox - versionBox - versionTextBox - btnChangeVersion - modpackBox - modpackEdit - modpackBtn - iconButton - - - buttonBox - accepted() - NewInstanceDialog - accept() - - - 266 - 378 - - - 157 - 274 - - - - - buttonBox - rejected() - NewInstanceDialog - reject() - - - 271 - 378 - - - 280 - 274 - - - - - modpackBox - toggled(bool) - modpackEdit - setEnabled(bool) - - - 91 - 251 - - - 240 - 278 - - - - - modpackBox - toggled(bool) - modpackBtn - setEnabled(bool) - - - 139 - 251 - - - 270 - 278 - - - - - versionBox - toggled(bool) - versionTextBox - setEnabled(bool) - - - 93 - 195 - - - 223 - 224 - - - - - versionBox - toggled(bool) - btnChangeVersion - setEnabled(bool) - - - 104 - 198 - - - 270 - 224 - - - - - ftbBox - toggled(bool) - btnChooseFtbPack - setEnabled(bool) - - - 67 - 301 - - - 254 - 327 - - - - - ftbBox - toggled(bool) - labelFtbPack - setEnabled(bool) - - - 81 - 310 - - - 73 - 334 - - - - + diff --git a/application/dialogs/VersionSelectDialog.cpp b/application/dialogs/VersionSelectDialog.cpp index a44572cc0..1ed81e79c 100644 --- a/application/dialogs/VersionSelectDialog.cpp +++ b/application/dialogs/VersionSelectDialog.cpp @@ -40,7 +40,7 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, m_verticalLayout = new QVBoxLayout(this); m_verticalLayout->setObjectName(QStringLiteral("verticalLayout")); - m_versionWidget = new VersionSelectWidget(vlist, parent); + m_versionWidget = new VersionSelectWidget(parent); m_verticalLayout->addWidget(m_versionWidget); m_horizontalLayout = new QHBoxLayout(); @@ -107,7 +107,7 @@ void VersionSelectDialog::setResizeOn(int column) int VersionSelectDialog::exec() { QDialog::open(); - m_versionWidget->initialize(); + m_versionWidget->initialize(m_vlist); return QDialog::exec(); } diff --git a/application/pagedialog/PageDialog.cpp b/application/pagedialog/PageDialog.cpp index b201de858..1b5284d20 100644 --- a/application/pagedialog/PageDialog.cpp +++ b/application/pagedialog/PageDialog.cpp @@ -25,7 +25,7 @@ #include "widgets/IconLabel.h" #include "widgets/PageContainer.h" -PageDialog::PageDialog(BasePageProviderPtr pageProvider, QString defaultId, QWidget *parent) +PageDialog::PageDialog(BasePageProvider *pageProvider, QString defaultId, QWidget *parent) : QDialog(parent) { setWindowTitle(pageProvider->dialogTitle()); @@ -37,17 +37,14 @@ PageDialog::PageDialog(BasePageProviderPtr pageProvider, QString defaultId, QWid mainLayout->setContentsMargins(0, 0, 0, 0); setLayout(mainLayout); - QDialogButtonBox *buttons = - new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close); + QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close); buttons->button(QDialogButtonBox::Close)->setDefault(true); m_container->addButtons(buttons); connect(buttons->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(close())); - connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), m_container, - SLOT(help())); + connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), m_container, SLOT(help())); - restoreGeometry( - QByteArray::fromBase64(MMC->settings()->get("PagedGeometry").toByteArray())); + restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("PagedGeometry").toByteArray())); } void PageDialog::closeEvent(QCloseEvent *event) diff --git a/application/pagedialog/PageDialog.h b/application/pagedialog/PageDialog.h index 67cd290e7..a287f9c9b 100644 --- a/application/pagedialog/PageDialog.h +++ b/application/pagedialog/PageDialog.h @@ -23,8 +23,7 @@ class PageDialog : public QDialog { Q_OBJECT public: - explicit PageDialog(BasePageProviderPtr pageProvider, QString defaultId = QString(), - QWidget *parent = 0); + explicit PageDialog(BasePageProvider *pageProvider, QString defaultId = QString(), QWidget *parent = 0); virtual ~PageDialog() {} private diff --git a/application/pages/BasePage.h b/application/pages/BasePage.h index 63a262399..d4547770f 100644 --- a/application/pages/BasePage.h +++ b/application/pages/BasePage.h @@ -31,8 +31,18 @@ public: virtual bool apply() { return true; } virtual bool shouldDisplay() const { return true; } virtual QString helpPage() const { return QString(); } - virtual void opened() {} - virtual void closed() {} + void opened() + { + isOpened = true; + openedImpl(); + } + void closed() + { + isOpened = false; + closedImpl(); + } + virtual void openedImpl() {} + virtual void closedImpl() {} virtual void setParentContainer(BasePageContainer * container) { m_container = container; @@ -42,6 +52,7 @@ public: int listIndex = -1; protected: BasePageContainer * m_container = nullptr; + bool isOpened = false; }; typedef std::shared_ptr BasePagePtr; diff --git a/application/pages/BasePageProvider.h b/application/pages/BasePageProvider.h index 0ebcff7ab..1cc7458a4 100644 --- a/application/pages/BasePageProvider.h +++ b/application/pages/BasePageProvider.h @@ -15,7 +15,7 @@ #pragma once -#include "BasePage.h" +#include "pages/BasePage.h" #include #include @@ -65,5 +65,3 @@ private: QList m_creators; QString m_dialogTitle; }; - -typedef std::shared_ptr BasePageProviderPtr; diff --git a/application/pages/global/PackagesPage.cpp b/application/pages/global/PackagesPage.cpp index 5fd4934c6..7cf1e3f51 100644 --- a/application/pages/global/PackagesPage.cpp +++ b/application/pages/global/PackagesPage.cpp @@ -218,7 +218,7 @@ void PackagesPage::updateVersion() } } -void PackagesPage::opened() +void PackagesPage::openedImpl() { ENV.metadataIndex()->load(Net::Mode::Offline); } diff --git a/application/pages/global/PackagesPage.h b/application/pages/global/PackagesPage.h index 2afbcf8e7..ad155d9e9 100644 --- a/application/pages/global/PackagesPage.h +++ b/application/pages/global/PackagesPage.h @@ -36,7 +36,7 @@ public: QString id() const override { return "packages-global"; } QString displayName() const override { return tr("Packages"); } QIcon icon() const override; - void opened() override; + void openedImpl() override; private slots: void on_refreshIndexBtn_clicked(); diff --git a/application/pages/InstanceSettingsPage.cpp b/application/pages/instance/InstanceSettingsPage.cpp similarity index 100% rename from application/pages/InstanceSettingsPage.cpp rename to application/pages/instance/InstanceSettingsPage.cpp diff --git a/application/pages/InstanceSettingsPage.h b/application/pages/instance/InstanceSettingsPage.h similarity index 98% rename from application/pages/InstanceSettingsPage.h rename to application/pages/instance/InstanceSettingsPage.h index 4959bdbe9..c5d7d3b62 100644 --- a/application/pages/InstanceSettingsPage.h +++ b/application/pages/instance/InstanceSettingsPage.h @@ -20,7 +20,7 @@ #include "java/JavaChecker.h" #include "BaseInstance.h" #include -#include "BasePage.h" +#include "pages/BasePage.h" #include "JavaCommon.h" #include "MultiMC.h" diff --git a/application/pages/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui similarity index 100% rename from application/pages/InstanceSettingsPage.ui rename to application/pages/instance/InstanceSettingsPage.ui diff --git a/application/pages/LegacyUpgradePage.cpp b/application/pages/instance/LegacyUpgradePage.cpp similarity index 77% rename from application/pages/LegacyUpgradePage.cpp rename to application/pages/instance/LegacyUpgradePage.cpp index a8f4a08ca..f808ab889 100644 --- a/application/pages/LegacyUpgradePage.cpp +++ b/application/pages/instance/LegacyUpgradePage.cpp @@ -35,7 +35,12 @@ void LegacyUpgradePage::runModalTask(Task *task) void LegacyUpgradePage::on_upgradeButton_clicked() { - std::unique_ptr task(MMC->folderProvider()->legacyUpgradeTask(m_inst)); + QString newName = tr("%1 (Migrated)").arg(m_inst->name()); + auto upgradeTask = new LegacyUpgradeTask(m_inst); + upgradeTask->setName(newName); + upgradeTask->setGroup(m_inst->group()); + upgradeTask->setIcon(m_inst->iconKey()); + std::unique_ptr task(MMC->folderProvider()->wrapInstanceTask(upgradeTask)); runModalTask(task.get()); } diff --git a/application/pages/LegacyUpgradePage.h b/application/pages/instance/LegacyUpgradePage.h similarity index 100% rename from application/pages/LegacyUpgradePage.h rename to application/pages/instance/LegacyUpgradePage.h diff --git a/application/pages/LegacyUpgradePage.ui b/application/pages/instance/LegacyUpgradePage.ui similarity index 100% rename from application/pages/LegacyUpgradePage.ui rename to application/pages/instance/LegacyUpgradePage.ui diff --git a/application/pages/LogPage.cpp b/application/pages/instance/LogPage.cpp similarity index 100% rename from application/pages/LogPage.cpp rename to application/pages/instance/LogPage.cpp diff --git a/application/pages/LogPage.h b/application/pages/instance/LogPage.h similarity index 98% rename from application/pages/LogPage.h rename to application/pages/instance/LogPage.h index b830118e5..2229418de 100644 --- a/application/pages/LogPage.h +++ b/application/pages/instance/LogPage.h @@ -19,7 +19,7 @@ #include "BaseInstance.h" #include "launch/LaunchTask.h" -#include "BasePage.h" +#include "pages/BasePage.h" #include namespace Ui diff --git a/application/pages/LogPage.ui b/application/pages/instance/LogPage.ui similarity index 100% rename from application/pages/LogPage.ui rename to application/pages/instance/LogPage.ui diff --git a/application/pages/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp similarity index 98% rename from application/pages/ModFolderPage.cpp rename to application/pages/instance/ModFolderPage.cpp index 2b3f44160..90155df32 100644 --- a/application/pages/ModFolderPage.cpp +++ b/application/pages/instance/ModFolderPage.cpp @@ -59,12 +59,12 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr mods, connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged ); } -void ModFolderPage::opened() +void ModFolderPage::openedImpl() { m_mods->startWatching(); } -void ModFolderPage::closed() +void ModFolderPage::closedImpl() { m_mods->stopWatching(); } diff --git a/application/pages/ModFolderPage.h b/application/pages/instance/ModFolderPage.h similarity index 96% rename from application/pages/ModFolderPage.h rename to application/pages/instance/ModFolderPage.h index 02282c41a..15e728cb9 100644 --- a/application/pages/ModFolderPage.h +++ b/application/pages/instance/ModFolderPage.h @@ -18,7 +18,7 @@ #include #include "minecraft/MinecraftInstance.h" -#include "BasePage.h" +#include "pages/BasePage.h" #include class ModList; @@ -60,8 +60,8 @@ public: } virtual bool shouldDisplay() const override; - virtual void opened() override; - virtual void closed() override; + virtual void openedImpl() override; + virtual void closedImpl() override; protected: bool eventFilter(QObject *obj, QEvent *ev) override; bool modListFilter(QKeyEvent *ev); diff --git a/application/pages/ModFolderPage.ui b/application/pages/instance/ModFolderPage.ui similarity index 100% rename from application/pages/ModFolderPage.ui rename to application/pages/instance/ModFolderPage.ui diff --git a/application/pages/NotesPage.cpp b/application/pages/instance/NotesPage.cpp similarity index 100% rename from application/pages/NotesPage.cpp rename to application/pages/instance/NotesPage.cpp diff --git a/application/pages/NotesPage.h b/application/pages/instance/NotesPage.h similarity index 97% rename from application/pages/NotesPage.h rename to application/pages/instance/NotesPage.h index eab446ad4..4a25f9b14 100644 --- a/application/pages/NotesPage.h +++ b/application/pages/instance/NotesPage.h @@ -18,7 +18,7 @@ #include #include "BaseInstance.h" -#include "BasePage.h" +#include "pages/BasePage.h" #include namespace Ui diff --git a/application/pages/NotesPage.ui b/application/pages/instance/NotesPage.ui similarity index 100% rename from application/pages/NotesPage.ui rename to application/pages/instance/NotesPage.ui diff --git a/application/pages/OtherLogsPage.cpp b/application/pages/instance/OtherLogsPage.cpp similarity index 99% rename from application/pages/OtherLogsPage.cpp rename to application/pages/instance/OtherLogsPage.cpp index 2141e0cc4..10cb1145c 100644 --- a/application/pages/OtherLogsPage.cpp +++ b/application/pages/instance/OtherLogsPage.cpp @@ -54,11 +54,11 @@ OtherLogsPage::~OtherLogsPage() delete ui; } -void OtherLogsPage::opened() +void OtherLogsPage::openedImpl() { m_watcher->enable(); } -void OtherLogsPage::closed() +void OtherLogsPage::closedImpl() { m_watcher->disable(); } diff --git a/application/pages/OtherLogsPage.h b/application/pages/instance/OtherLogsPage.h similarity index 95% rename from application/pages/OtherLogsPage.h rename to application/pages/instance/OtherLogsPage.h index 157f5e9dd..ac01ef0a4 100644 --- a/application/pages/OtherLogsPage.h +++ b/application/pages/instance/OtherLogsPage.h @@ -17,7 +17,7 @@ #include -#include "BasePage.h" +#include "pages/BasePage.h" #include #include @@ -52,8 +52,8 @@ public: { return "Minecraft-Logs"; } - void opened() override; - void closed() override; + void openedImpl() override; + void closedImpl() override; private slots: void populateSelectLogBox(); diff --git a/application/pages/OtherLogsPage.ui b/application/pages/instance/OtherLogsPage.ui similarity index 100% rename from application/pages/OtherLogsPage.ui rename to application/pages/instance/OtherLogsPage.ui diff --git a/application/pages/ResourcePackPage.h b/application/pages/instance/ResourcePackPage.h similarity index 100% rename from application/pages/ResourcePackPage.h rename to application/pages/instance/ResourcePackPage.h diff --git a/application/pages/ScreenshotsPage.cpp b/application/pages/instance/ScreenshotsPage.cpp similarity index 99% rename from application/pages/ScreenshotsPage.cpp rename to application/pages/instance/ScreenshotsPage.cpp index 7d32576a2..714583866 100644 --- a/application/pages/ScreenshotsPage.cpp +++ b/application/pages/instance/ScreenshotsPage.cpp @@ -347,7 +347,7 @@ void ScreenshotsPage::on_renameBtn_clicked() // TODO: mass renaming } -void ScreenshotsPage::opened() +void ScreenshotsPage::openedImpl() { if(!m_valid) { diff --git a/application/pages/ScreenshotsPage.h b/application/pages/instance/ScreenshotsPage.h similarity index 96% rename from application/pages/ScreenshotsPage.h rename to application/pages/instance/ScreenshotsPage.h index c3ccbdeed..e31fb8b4f 100644 --- a/application/pages/ScreenshotsPage.h +++ b/application/pages/instance/ScreenshotsPage.h @@ -17,7 +17,7 @@ #include -#include "BasePage.h" +#include "pages/BasePage.h" #include class QFileSystemModel; @@ -39,7 +39,7 @@ public: explicit ScreenshotsPage(QString path, QWidget *parent = 0); virtual ~ScreenshotsPage(); - virtual void opened() override; + virtual void openedImpl() override; enum { diff --git a/application/pages/ScreenshotsPage.ui b/application/pages/instance/ScreenshotsPage.ui similarity index 100% rename from application/pages/ScreenshotsPage.ui rename to application/pages/instance/ScreenshotsPage.ui diff --git a/application/pages/TexturePackPage.h b/application/pages/instance/TexturePackPage.h similarity index 100% rename from application/pages/TexturePackPage.h rename to application/pages/instance/TexturePackPage.h diff --git a/application/pages/VersionPage.cpp b/application/pages/instance/VersionPage.cpp similarity index 100% rename from application/pages/VersionPage.cpp rename to application/pages/instance/VersionPage.cpp diff --git a/application/pages/VersionPage.h b/application/pages/instance/VersionPage.h similarity index 98% rename from application/pages/VersionPage.h rename to application/pages/instance/VersionPage.h index 49620c565..85304ea5a 100644 --- a/application/pages/VersionPage.h +++ b/application/pages/instance/VersionPage.h @@ -19,7 +19,7 @@ #include "minecraft/MinecraftInstance.h" #include "minecraft/ComponentList.h" -#include "BasePage.h" +#include "pages/BasePage.h" namespace Ui { diff --git a/application/pages/VersionPage.ui b/application/pages/instance/VersionPage.ui similarity index 100% rename from application/pages/VersionPage.ui rename to application/pages/instance/VersionPage.ui diff --git a/application/pages/WorldListPage.cpp b/application/pages/instance/WorldListPage.cpp similarity index 99% rename from application/pages/WorldListPage.cpp rename to application/pages/instance/WorldListPage.cpp index 56a7e7919..539d26a02 100644 --- a/application/pages/WorldListPage.cpp +++ b/application/pages/instance/WorldListPage.cpp @@ -55,12 +55,12 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worl worldChanged(QModelIndex(), QModelIndex()); } -void WorldListPage::opened() +void WorldListPage::openedImpl() { m_worlds->startWatching(); } -void WorldListPage::closed() +void WorldListPage::closedImpl() { m_worlds->stopWatching(); } diff --git a/application/pages/WorldListPage.h b/application/pages/instance/WorldListPage.h similarity index 95% rename from application/pages/WorldListPage.h rename to application/pages/instance/WorldListPage.h index d0aa61502..71b87bda5 100644 --- a/application/pages/WorldListPage.h +++ b/application/pages/instance/WorldListPage.h @@ -18,7 +18,7 @@ #include #include "minecraft/MinecraftInstance.h" -#include "BasePage.h" +#include "pages/BasePage.h" #include #include @@ -56,8 +56,8 @@ public: } virtual bool shouldDisplay() const override; - virtual void opened() override; - virtual void closed() override; + virtual void openedImpl() override; + virtual void closedImpl() override; protected: bool eventFilter(QObject *obj, QEvent *ev) override; diff --git a/application/pages/WorldListPage.ui b/application/pages/instance/WorldListPage.ui similarity index 100% rename from application/pages/WorldListPage.ui rename to application/pages/instance/WorldListPage.ui diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp new file mode 100644 index 000000000..a8ec65778 --- /dev/null +++ b/application/pages/modplatform/FTBPage.cpp @@ -0,0 +1,152 @@ +#include "FTBPage.h" +#include "ui_FTBPage.h" + +#include "MultiMC.h" +#include "FolderInstanceProvider.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/NewInstanceDialog.h" +#include "modplatform/ftb/FtbPackDownloader.h" +#include "modplatform/ftb/FtbPackInstallTask.h" +#include + +FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage) +{ + ui->setupUi(this); + ftbPackDownloader = new FtbPackDownloader(); + + connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &FTBPage::ftbPackDataDownloadSuccessfully); + connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &FTBPage::ftbPackDataDownloadFailed); + + filterModel = new FtbFilterModel(this); + listModel = new FtbListModel(this); + filterModel->setSourceModel(listModel); + + ui->packList->setModel(filterModel); + ui->packList->setSortingEnabled(true); + ui->packList->header()->hide(); + ui->packList->setIndentation(0); + + filterModel->setSorting(FtbFilterModel::Sorting::ByName); + + for(int i = 0; i < filterModel->getAvailableSortings().size(); i++) + { + ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); + } + + ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting())); + + connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged); + connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged); + connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPackSelectionChanged); + + ui->modpackInfo->setOpenExternalLinks(true); +} + +FTBPage::~FTBPage() +{ + delete ui; + if(ftbPackDownloader) + { + ftbPackDownloader->deleteLater(); + } +} + +bool FTBPage::shouldDisplay() const +{ + return true; +} + +void FTBPage::openedImpl() +{ + if(!initialized) + { + ftbPackDownloader->fetchModpacks(false); + initialized = true; + } + suggestCurrent(); +} + +void FTBPage::suggestCurrent() +{ + if(isOpened) + { + if(!selected.broken) + { + dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion)); + } + else + { + dialog->setSuggestedPack(); + } + } +} + +FtbPackDownloader *FTBPage::getFtbPackDownloader() +{ + return ftbPackDownloader; +} + +void FTBPage::ftbPackDataDownloadSuccessfully() +{ + listModel->fill(ftbPackDownloader->getModpacks()); +} + +void FTBPage::ftbPackDataDownloadFailed() +{ + qDebug() << "Stuff went missing while grabbing FTB pack list or something..."; +} + +void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev) +{ + ui->packVersionSelection->clear(); + FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value(); + + ui->modpackInfo->setHtml("Pack by " + selectedPack.author + "" + "
Minecraft " + selectedPack.mcVersion + "
" + "
" + selectedPack.description + "
  • " + selectedPack.mods.replace(";", "
  • ") + "
"); + + bool currentAdded = false; + + for(int i = 0; i < selectedPack.oldVersions.size(); i++) + { + if(selectedPack.currentVersion == selectedPack.oldVersions.at(i)) + { + currentAdded = true; + } + ui->packVersionSelection->addItem(selectedPack.oldVersions.at(i)); + } + + if(!currentAdded) + { + ui->packVersionSelection->addItem(selectedPack.currentVersion); + } + + selected = selectedPack; + suggestCurrent(); +} + +void FTBPage::onVersionSelectionItemChanged(QString data) +{ + if(data.isNull() || data.isEmpty()) + { + selectedVersion = ""; + return; + } + + selectedVersion = data; +} + +FtbModpack FTBPage::getSelectedModpack() +{ + return selected; +} + +QString FTBPage::getSelectedVersion() +{ + return selectedVersion; +} + +void FTBPage::onSortingSelectionChanged(QString data) +{ + filterModel->setSorting(filterModel->getAvailableSortings().value(data)); +} diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h new file mode 100644 index 000000000..f7d6ca8b8 --- /dev/null +++ b/application/pages/modplatform/FTBPage.h @@ -0,0 +1,86 @@ +/* Copyright 2013-2018 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 "pages/BasePage.h" +#include +#include "tasks/Task.h" +#include "modplatform/ftb/PackHelpers.h" + +namespace Ui +{ +class FTBPage; +} + +class FtbListModel; +class FtbFilterModel; +class FtbPackDownloader; +class NewInstanceDialog; + +class FTBPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit FTBPage(NewInstanceDialog * dialog, QWidget *parent = 0); + virtual ~FTBPage(); + QString displayName() const override + { + return tr("FTB Legacy"); + } + QIcon icon() const override + { + return MMC->getThemedIcon("ftb_logo"); + } + QString id() const override + { + return "ftb"; + } + QString helpPage() const override + { + return "FTB-platform"; + } + bool shouldDisplay() const override; + void openedImpl() override; + + FtbPackDownloader* getFtbPackDownloader(); + FtbModpack getSelectedModpack(); + QString getSelectedVersion(); + +private: + void suggestCurrent(); + +private slots: + void ftbPackDataDownloadSuccessfully(); + void ftbPackDataDownloadFailed(); + void onSortingSelectionChanged(QString data); + void onVersionSelectionItemChanged(QString data); + void onPackSelectionChanged(QModelIndex first, QModelIndex second); + +private: + bool initialized = false; + FtbPackDownloader* ftbPackDownloader = nullptr; + FtbModpack selectedPack; + FtbModpack selected; + QString selectedVersion; + FtbListModel* listModel = nullptr; + FtbFilterModel* filterModel = nullptr; + NewInstanceDialog* dialog = nullptr; + + Ui::FTBPage *ui = nullptr; +}; diff --git a/application/pages/modplatform/FTBPage.ui b/application/pages/modplatform/FTBPage.ui new file mode 100644 index 000000000..c54fc392b --- /dev/null +++ b/application/pages/modplatform/FTBPage.ui @@ -0,0 +1,61 @@ + + + FTBPage + + + + 0 + 0 + 801 + 674 + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + 0 + + + + + + + + Version selected: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + + + + + diff --git a/application/pages/modplatform/ImportPage.cpp b/application/pages/modplatform/ImportPage.cpp new file mode 100644 index 000000000..545ca38d1 --- /dev/null +++ b/application/pages/modplatform/ImportPage.cpp @@ -0,0 +1,125 @@ +#include "ImportPage.h" +#include "ui_ImportPage.h" + +#include "MultiMC.h" +#include "FolderInstanceProvider.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ProgressDialog.h" +#include "dialogs/NewInstanceDialog.h" +#include +#include + +class UrlValidator : public QValidator +{ +public: + using QValidator::QValidator; + + State validate(QString &in, int &pos) const + { + const QUrl url(in); + if (url.isValid() && !url.isRelative() && !url.isEmpty()) + { + return Acceptable; + } + else if (QFile::exists(in)) + { + return Acceptable; + } + else + { + return Intermediate; + } + } +}; + +ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog) +{ + ui->setupUi(this); + ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); + connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState); +} + +ImportPage::~ImportPage() +{ + delete ui; +} + +bool ImportPage::shouldDisplay() const +{ + return true; +} + +void ImportPage::openedImpl() +{ + updateState(); +} + +void ImportPage::updateState() +{ + if(!isOpened) + { + return; + } + if(ui->modpackEdit->hasAcceptableInput()) + { + QString input = ui->modpackEdit->text(); + auto url = QUrl::fromUserInput(input); + if(url.isLocalFile()) + { + // FIXME: actually do some validation of what's inside here... this is fake AF + QFileInfo fi(input); + if(fi.exists() && fi.suffix() == "zip") + { + QFileInfo fi(url.fileName()); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url)); + } + } + else + { + // hook, line and sinker. + QFileInfo fi(url.fileName()); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url)); + } + } + else + { + dialog->setSuggestedPack(); + } +} + +void ImportPage::setUrl(const QString& url) +{ + ui->modpackEdit->setText(url); + updateState(); +} + +void ImportPage::on_modpackBtn_clicked() +{ + const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)")); + if (url.isValid()) + { + if (url.isLocalFile()) + { + ui->modpackEdit->setText(url.toLocalFile()); + } + else + { + ui->modpackEdit->setText(url.toString()); + } + } +} + + +QUrl ImportPage::modpackUrl() const +{ + const QUrl url(ui->modpackEdit->text()); + if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) + { + return url; + } + else + { + return QUrl::fromLocalFile(ui->modpackEdit->text()); + } +} diff --git a/application/pages/modplatform/ImportPage.h b/application/pages/modplatform/ImportPage.h new file mode 100644 index 000000000..8f62e6b1a --- /dev/null +++ b/application/pages/modplatform/ImportPage.h @@ -0,0 +1,70 @@ +/* Copyright 2013-2018 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 "pages/BasePage.h" +#include +#include "tasks/Task.h" + +namespace Ui +{ +class ImportPage; +} + +class NewInstanceDialog; + +class ImportPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0); + virtual ~ImportPage(); + virtual QString displayName() const override + { + return tr("Import from zip"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("viewfolder"); + } + virtual QString id() const override + { + return "import"; + } + virtual QString helpPage() const override + { + return "Zip-import"; + } + virtual bool shouldDisplay() const override; + + void setUrl(const QString & url); + void openedImpl() override; + +private slots: + void on_modpackBtn_clicked(); + void updateState(); + +private: + QUrl modpackUrl() const; + +private: + Ui::ImportPage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; +}; + diff --git a/application/pages/modplatform/ImportPage.ui b/application/pages/modplatform/ImportPage.ui new file mode 100644 index 000000000..eb63cbe90 --- /dev/null +++ b/application/pages/modplatform/ImportPage.ui @@ -0,0 +1,52 @@ + + + ImportPage + + + + 0 + 0 + 546 + 405 + + + + + + + Browse + + + + + + + http:// + + + + + + + Local file or link to a direct download: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/application/pages/modplatform/TechnicPage.cpp b/application/pages/modplatform/TechnicPage.cpp new file mode 100644 index 000000000..c0f4faa54 --- /dev/null +++ b/application/pages/modplatform/TechnicPage.cpp @@ -0,0 +1,29 @@ +#include "TechnicPage.h" +#include "ui_TechnicPage.h" + +#include "MultiMC.h" +#include "FolderInstanceProvider.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ProgressDialog.h" +#include "dialogs/NewInstanceDialog.h" + +TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog) +{ + ui->setupUi(this); +} + +TechnicPage::~TechnicPage() +{ + delete ui; +} + +bool TechnicPage::shouldDisplay() const +{ + return true; +} + +void TechnicPage::openedImpl() +{ + dialog->setSuggestedPack(); +} diff --git a/application/pages/modplatform/TechnicPage.h b/application/pages/modplatform/TechnicPage.h new file mode 100644 index 000000000..5b0f16a6b --- /dev/null +++ b/application/pages/modplatform/TechnicPage.h @@ -0,0 +1,61 @@ +/* Copyright 2013-2018 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 "pages/BasePage.h" +#include +#include "tasks/Task.h" + +namespace Ui +{ +class TechnicPage; +} + +class NewInstanceDialog; + +class TechnicPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0); + virtual ~TechnicPage(); + virtual QString displayName() const override + { + return tr("Technic"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("technic"); + } + virtual QString id() const override + { + return "technic"; + } + virtual QString helpPage() const override + { + return "Technic-platform"; + } + virtual bool shouldDisplay() const override; + + void openedImpl() override; + +private: + Ui::TechnicPage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; +}; diff --git a/application/pages/modplatform/TechnicPage.ui b/application/pages/modplatform/TechnicPage.ui new file mode 100644 index 000000000..6bb6e9e0f --- /dev/null +++ b/application/pages/modplatform/TechnicPage.ui @@ -0,0 +1,48 @@ + + + TechnicPage + + + + 0 + 0 + 546 + 405 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 40 + + + + ¯\_(ツ)_/¯ + + + Qt::PlainText + + + Qt::AlignCenter + + + + + + + + diff --git a/application/pages/modplatform/TwitchPage.cpp b/application/pages/modplatform/TwitchPage.cpp new file mode 100644 index 000000000..a264c2f7c --- /dev/null +++ b/application/pages/modplatform/TwitchPage.cpp @@ -0,0 +1,29 @@ +#include "TwitchPage.h" +#include "ui_TwitchPage.h" + +#include "MultiMC.h" +#include "FolderInstanceProvider.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ProgressDialog.h" +#include "dialogs/NewInstanceDialog.h" + +TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog) +{ + ui->setupUi(this); +} + +TwitchPage::~TwitchPage() +{ + delete ui; +} + +bool TwitchPage::shouldDisplay() const +{ + return true; +} + +void TwitchPage::openedImpl() +{ + dialog->setSuggestedPack(); +} diff --git a/application/pages/modplatform/TwitchPage.h b/application/pages/modplatform/TwitchPage.h new file mode 100644 index 000000000..8e0729172 --- /dev/null +++ b/application/pages/modplatform/TwitchPage.h @@ -0,0 +1,61 @@ +/* Copyright 2013-2018 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 "pages/BasePage.h" +#include +#include "tasks/Task.h" + +namespace Ui +{ +class TwitchPage; +} + +class NewInstanceDialog; + +class TwitchPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0); + virtual ~TwitchPage(); + virtual QString displayName() const override + { + return tr("Twitch"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("twitch"); + } + virtual QString id() const override + { + return "twitch"; + } + virtual QString helpPage() const override + { + return "Twitch-platform"; + } + virtual bool shouldDisplay() const override; + + void openedImpl() override; + +private: + Ui::TwitchPage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; +}; diff --git a/application/pages/modplatform/TwitchPage.ui b/application/pages/modplatform/TwitchPage.ui new file mode 100644 index 000000000..191785059 --- /dev/null +++ b/application/pages/modplatform/TwitchPage.ui @@ -0,0 +1,48 @@ + + + TwitchPage + + + + 0 + 0 + 546 + 405 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 40 + + + + ¯\_(ツ)_/¯ + + + Qt::PlainText + + + Qt::AlignCenter + + + + + + + + diff --git a/application/pages/modplatform/VanillaPage.cpp b/application/pages/modplatform/VanillaPage.cpp new file mode 100644 index 000000000..013ca4261 --- /dev/null +++ b/application/pages/modplatform/VanillaPage.cpp @@ -0,0 +1,114 @@ +#include "VanillaPage.h" +#include "ui_VanillaPage.h" + +#include "MultiMC.h" +#include "FolderInstanceProvider.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ProgressDialog.h" + +#include +#include +#include +#include +#include +#include + +VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent) + : QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedVersion); + filterChanged(); + connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); + connect(ui->betaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); + connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); + connect(ui->oldSnapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); + connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged); +} + +void VanillaPage::openedImpl() +{ + if(!initialized) + { + auto vlist = ENV.metadataIndex()->get("net.minecraft"); + ui->versionList->initialize(vlist.get()); + if(vlist->isLoaded()) + { + setSelectedVersion(vlist->getRecommended()); + } + else + { + vlist->load(Net::Mode::Online); + auto task = vlist->getLoadTask(); + if(vlist->isLoaded()) + { + setSelectedVersion(vlist->getRecommended()); + } + if(task) + { + connect(task.get(), &Task::succeeded, this, &VanillaPage::versionListUpdated); + } + } + initialized = true; + } + else + { + suggestCurrent(); + } +} + +void VanillaPage::filterChanged() +{ + QStringList out; + if(ui->alphaFilter->isChecked()) + out << "(old_alpha)"; + if(ui->betaFilter->isChecked()) + out << "(old_beta)"; + if(ui->snapshotFilter->isChecked()) + out << "(snapshot)"; + if(ui->oldSnapshotFilter->isChecked()) + out << "(old_snapshot)"; + if(ui->releaseFilter->isChecked()) + out << "(release)"; + auto regexp = out.join('|'); + ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false)); +} + +VanillaPage::~VanillaPage() +{ + delete ui; +} + +bool VanillaPage::shouldDisplay() const +{ + return true; +} + +BaseVersionPtr VanillaPage::selectedVersion() const +{ + return m_selectedVersion; +} + +void VanillaPage::versionListUpdated() +{ + if(!m_versionSetByUser) + { + auto vlist = ENV.metadataIndex()->get("net.minecraft"); + setSelectedVersion(vlist->getRecommended()); + } +} + +void VanillaPage::suggestCurrent() +{ + if(m_selectedVersion && isOpened) + { + dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion)); + } +} + +void VanillaPage::setSelectedVersion(BaseVersionPtr version) +{ + m_selectedVersion = version; + suggestCurrent(); +} diff --git a/application/pages/modplatform/VanillaPage.h b/application/pages/modplatform/VanillaPage.h new file mode 100644 index 000000000..3f9d20ec0 --- /dev/null +++ b/application/pages/modplatform/VanillaPage.h @@ -0,0 +1,75 @@ +/* Copyright 2013-2018 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 "pages/BasePage.h" +#include +#include "tasks/Task.h" + +namespace Ui +{ +class VanillaPage; +} + +class NewInstanceDialog; + +class VanillaPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit VanillaPage(NewInstanceDialog *dialog, QWidget *parent = 0); + virtual ~VanillaPage(); + virtual QString displayName() const override + { + return tr("Vanilla"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("minecraft"); + } + virtual QString id() const override + { + return "vanilla"; + } + virtual QString helpPage() const override + { + return "Vanilla-platform"; + } + virtual bool shouldDisplay() const override; + void openedImpl() override; + + BaseVersionPtr selectedVersion() const; + +public slots: + void setSelectedVersion(BaseVersionPtr version); + +private slots: + void versionListUpdated(); + void filterChanged(); + +private: + void suggestCurrent(); + +private: + bool initialized = false; + NewInstanceDialog *dialog = nullptr; + Ui::VanillaPage *ui = nullptr; + bool m_versionSetByUser = false; + BaseVersionPtr m_selectedVersion; +}; diff --git a/application/pages/modplatform/VanillaPage.ui b/application/pages/modplatform/VanillaPage.ui new file mode 100644 index 000000000..713d04a09 --- /dev/null +++ b/application/pages/modplatform/VanillaPage.ui @@ -0,0 +1,149 @@ + + + VanillaPage + + + + 0 + 0 + 815 + 607 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + + + Filter + + + Qt::AlignCenter + + + + + + + Releases + + + true + + + true + + + + + + + Snapshots + + + true + + + + + + + Old Snapshots + + + true + + + + + + + Betas + + + true + + + + + + + Alphas + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Refresh + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + VersionSelectWidget + QWidget +
widgets/VersionSelectWidget.h
+ 1 +
+
+ + +
diff --git a/application/resources/multimc/multimc.qrc b/application/resources/multimc/multimc.qrc index 780e458d1..bea3a3255 100644 --- a/application/resources/multimc/multimc.qrc +++ b/application/resources/multimc/multimc.qrc @@ -11,6 +11,12 @@ scalable/reddit-alien.svg + + scalable/twitch.svg + + + scalable/technic.svg + scalable/proxy.svg diff --git a/application/resources/multimc/scalable/technic.svg b/application/resources/multimc/scalable/technic.svg new file mode 100644 index 000000000..827b590a6 --- /dev/null +++ b/application/resources/multimc/scalable/technic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/application/resources/multimc/scalable/twitch.svg b/application/resources/multimc/scalable/twitch.svg new file mode 100644 index 000000000..809993804 --- /dev/null +++ b/application/resources/multimc/scalable/twitch.svg @@ -0,0 +1,63 @@ + + + + + + image/svg+xml + + Glitch + + + + + + + + Glitch + + diff --git a/application/widgets/InstanceCardWidget.ui b/application/widgets/InstanceCardWidget.ui new file mode 100644 index 000000000..3ea3e85f9 --- /dev/null +++ b/application/widgets/InstanceCardWidget.ui @@ -0,0 +1,61 @@ + + + InstanceCardWidget + + + + 0 + 0 + 473 + 118 + + + + Form + + + + + + + 80 + 80 + + + + + + + + &Name: + + + instNameTextBox + + + + + + + + + + &Group: + + + groupBox + + + + + + + true + + + + + + + + diff --git a/application/widgets/JavaSettingsWidget.cpp b/application/widgets/JavaSettingsWidget.cpp index 13cd27e77..13fad72ab 100644 --- a/application/widgets/JavaSettingsWidget.cpp +++ b/application/widgets/JavaSettingsWidget.cpp @@ -41,7 +41,7 @@ void JavaSettingsWidget::setupUi() m_verticalLayout = new QVBoxLayout(this); m_verticalLayout->setObjectName(QStringLiteral("verticalLayout")); - m_versionWidget = new VersionSelectWidget(MMC->javalist().get(), this); + m_versionWidget = new VersionSelectWidget(this); m_versionWidget->setResizeOn(2); m_verticalLayout->addWidget(m_versionWidget); @@ -116,7 +116,7 @@ void JavaSettingsWidget::setupUi() void JavaSettingsWidget::initialize() { - m_versionWidget->initialize(); + m_versionWidget->initialize(MMC->javalist().get()); auto s = MMC->settings(); // Memory observedMinMemory = s->get("MinMemAlloc").toInt(); diff --git a/application/widgets/PageContainer.cpp b/application/widgets/PageContainer.cpp index 0f78329af..4dbd7fb2e 100644 --- a/application/widgets/PageContainer.cpp +++ b/application/widgets/PageContainer.cpp @@ -53,7 +53,7 @@ protected: } }; -PageContainer::PageContainer(BasePageProviderPtr pageProvider, QString defaultId, +PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId, QWidget *parent) : QWidget(parent) { @@ -158,6 +158,7 @@ void PageContainer::createUI() m_layout->addWidget(m_pageList, 0, 0, 2, 1); m_layout->addLayout(m_pageStack, 1, 1, 1, 1); m_layout->setColumnStretch(1, 4); + m_layout->setContentsMargins(0, 0, 0, 0); setLayout(m_layout); } diff --git a/application/widgets/PageContainer.h b/application/widgets/PageContainer.h index 96eac80a2..ea9f8ce16 100644 --- a/application/widgets/PageContainer.h +++ b/application/widgets/PageContainer.h @@ -35,7 +35,7 @@ class PageContainer : public QWidget, public BasePageContainer { Q_OBJECT public: - explicit PageContainer(BasePageProviderPtr pageProvider, QString defaultId = QString(), + explicit PageContainer(BasePageProvider *pageProvider, QString defaultId = QString(), QWidget *parent = 0); virtual ~PageContainer() {} @@ -67,11 +67,13 @@ public: private: void createUI(); -private -slots: + +public slots: + void help(); + +private slots: void currentChanged(const QModelIndex ¤t); void showPage(int row); - void help(); private: BasePageContainer * m_container = nullptr; diff --git a/application/widgets/VersionSelectWidget.cpp b/application/widgets/VersionSelectWidget.cpp index 2a7cbfb78..ce1141b65 100644 --- a/application/widgets/VersionSelectWidget.cpp +++ b/application/widgets/VersionSelectWidget.cpp @@ -6,8 +6,8 @@ #include #include -VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent) - : QWidget(parent), m_vlist(vlist) +VersionSelectWidget::VersionSelectWidget(QWidget* parent) + : QWidget(parent) { setObjectName(QStringLiteral("VersionSelectWidget")); verticalLayout = new QVBoxLayout(this); @@ -15,7 +15,6 @@ VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent verticalLayout->setContentsMargins(0, 0, 0, 0); m_proxyModel = new VersionProxyModel(this); - m_proxyModel->setSourceModel(vlist); listView = new VersionListView(this); listView->setObjectName(QStringLiteral("listView")); @@ -27,8 +26,6 @@ VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent listView->header()->setCascadingSectionResizes(true); listView->header()->setStretchLastSection(false); listView->setModel(m_proxyModel); - listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); verticalLayout->addWidget(listView); sneakyProgressBar = new QProgressBar(this); @@ -67,8 +64,13 @@ void VersionSelectWidget::setResizeOn(int column) listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); } -void VersionSelectWidget::initialize() +void VersionSelectWidget::initialize(BaseVersionList *vlist) { + m_vlist = vlist; + m_proxyModel->setSourceModel(vlist); + listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); + if (!m_vlist->isLoaded()) { loadList(); @@ -185,10 +187,15 @@ BaseVersionPtr VersionSelectWidget::selectedVersion() const void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter) { - m_proxyModel->setFilter(role, filter, true); + m_proxyModel->setFilter(role, new ExactFilter(filter)); } void VersionSelectWidget::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter) { - m_proxyModel->setFilter(role, filter, false); + m_proxyModel->setFilter(role, new ContainsFilter(filter)); +} + +void VersionSelectWidget::setFilter(BaseVersionList::ModelRoles role, Filter *filter) +{ + m_proxyModel->setFilter(role, filter); } diff --git a/application/widgets/VersionSelectWidget.h b/application/widgets/VersionSelectWidget.h index 3ea0b4f53..c134887fe 100644 --- a/application/widgets/VersionSelectWidget.h +++ b/application/widgets/VersionSelectWidget.h @@ -23,16 +23,17 @@ class VersionProxyModel; class VersionListView; class QVBoxLayout; class QProgressBar; +class Filter; class VersionSelectWidget: public QWidget { Q_OBJECT public: - explicit VersionSelectWidget(BaseVersionList *vlist, QWidget *parent = 0); + explicit VersionSelectWidget(QWidget *parent = 0); ~VersionSelectWidget(); //! loads the list if needed. - void initialize(); + void initialize(BaseVersionList *vlist); //! Starts a task that loads the list. void loadList(); @@ -45,6 +46,7 @@ public: void setCurrentVersion(const QString & version); void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter); void setExactFilter(BaseVersionList::ModelRoles role, QString filter); + void setFilter(BaseVersionList::ModelRoles role, Filter *filter); void setEmptyString(QString emptyString); void setEmptyErrorString(QString emptyErrorString); void setResizeOn(int column);