From 8e44ab2338f4ca63d58de4b3329c384df9d6c053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 19 Mar 2018 02:36:12 +0100 Subject: NOISSUE redo new instance dialog --- application/CMakeLists.txt | 85 +-- application/FtbListModel.cpp | 2 + application/InstancePageProvider.h | 22 +- application/InstanceWindow.cpp | 2 +- application/MainWindow.cpp | 44 +- application/MainWindow.h | 5 +- application/MultiMC.cpp | 2 + application/SettingsUI.h | 2 +- application/VersionProxyModel.cpp | 71 +-- application/VersionProxyModel.h | 19 +- application/dialogs/ChooseFtbPackDialog.cpp | 88 ---- application/dialogs/ChooseFtbPackDialog.h | 34 -- application/dialogs/ChooseFtbPackDialog.ui | 119 ----- application/dialogs/NewInstanceDialog.cpp | 263 +++------- application/dialogs/NewInstanceDialog.h | 43 +- application/dialogs/NewInstanceDialog.ui | 346 +------------ application/dialogs/VersionSelectDialog.cpp | 4 +- application/pagedialog/PageDialog.cpp | 11 +- application/pagedialog/PageDialog.h | 3 +- application/pages/BasePage.h | 15 +- application/pages/BasePageProvider.h | 4 +- application/pages/InstanceSettingsPage.cpp | 251 --------- application/pages/InstanceSettingsPage.h | 74 --- application/pages/InstanceSettingsPage.ui | 393 -------------- application/pages/LegacyUpgradePage.cpp | 45 -- application/pages/LegacyUpgradePage.h | 64 --- application/pages/LegacyUpgradePage.ui | 47 -- application/pages/LogPage.cpp | 312 ----------- application/pages/LogPage.h | 86 ---- application/pages/LogPage.ui | 182 ------- application/pages/ModFolderPage.cpp | 210 -------- application/pages/ModFolderPage.h | 108 ---- application/pages/ModFolderPage.ui | 180 ------- application/pages/NotesPage.cpp | 21 - application/pages/NotesPage.h | 60 --- application/pages/NotesPage.ui | 57 --- application/pages/OtherLogsPage.cpp | 313 ----------- application/pages/OtherLogsPage.h | 81 --- application/pages/OtherLogsPage.ui | 150 ------ application/pages/ResourcePackPage.h | 21 - application/pages/ScreenshotsPage.cpp | 372 -------------- application/pages/ScreenshotsPage.h | 84 --- application/pages/ScreenshotsPage.ui | 106 ---- application/pages/TexturePackPage.h | 19 - application/pages/VersionPage.cpp | 570 --------------------- application/pages/VersionPage.h | 95 ---- application/pages/VersionPage.ui | 318 ------------ application/pages/WorldListPage.cpp | 330 ------------ application/pages/WorldListPage.h | 96 ---- application/pages/WorldListPage.ui | 168 ------ application/pages/global/PackagesPage.cpp | 2 +- application/pages/global/PackagesPage.h | 2 +- .../pages/instance/InstanceSettingsPage.cpp | 251 +++++++++ application/pages/instance/InstanceSettingsPage.h | 74 +++ application/pages/instance/InstanceSettingsPage.ui | 393 ++++++++++++++ application/pages/instance/LegacyUpgradePage.cpp | 50 ++ application/pages/instance/LegacyUpgradePage.h | 64 +++ application/pages/instance/LegacyUpgradePage.ui | 47 ++ application/pages/instance/LogPage.cpp | 312 +++++++++++ application/pages/instance/LogPage.h | 86 ++++ application/pages/instance/LogPage.ui | 182 +++++++ application/pages/instance/ModFolderPage.cpp | 210 ++++++++ application/pages/instance/ModFolderPage.h | 108 ++++ application/pages/instance/ModFolderPage.ui | 180 +++++++ application/pages/instance/NotesPage.cpp | 21 + application/pages/instance/NotesPage.h | 60 +++ application/pages/instance/NotesPage.ui | 57 +++ application/pages/instance/OtherLogsPage.cpp | 313 +++++++++++ application/pages/instance/OtherLogsPage.h | 81 +++ application/pages/instance/OtherLogsPage.ui | 150 ++++++ application/pages/instance/ResourcePackPage.h | 21 + application/pages/instance/ScreenshotsPage.cpp | 372 ++++++++++++++ application/pages/instance/ScreenshotsPage.h | 84 +++ application/pages/instance/ScreenshotsPage.ui | 106 ++++ application/pages/instance/TexturePackPage.h | 19 + application/pages/instance/VersionPage.cpp | 570 +++++++++++++++++++++ application/pages/instance/VersionPage.h | 95 ++++ application/pages/instance/VersionPage.ui | 318 ++++++++++++ application/pages/instance/WorldListPage.cpp | 330 ++++++++++++ application/pages/instance/WorldListPage.h | 96 ++++ application/pages/instance/WorldListPage.ui | 168 ++++++ application/pages/modplatform/FTBPage.cpp | 152 ++++++ application/pages/modplatform/FTBPage.h | 86 ++++ application/pages/modplatform/FTBPage.ui | 61 +++ application/pages/modplatform/ImportPage.cpp | 125 +++++ application/pages/modplatform/ImportPage.h | 70 +++ application/pages/modplatform/ImportPage.ui | 52 ++ application/pages/modplatform/TechnicPage.cpp | 29 ++ application/pages/modplatform/TechnicPage.h | 61 +++ application/pages/modplatform/TechnicPage.ui | 48 ++ application/pages/modplatform/TwitchPage.cpp | 29 ++ application/pages/modplatform/TwitchPage.h | 61 +++ application/pages/modplatform/TwitchPage.ui | 48 ++ application/pages/modplatform/VanillaPage.cpp | 114 +++++ application/pages/modplatform/VanillaPage.h | 75 +++ application/pages/modplatform/VanillaPage.ui | 149 ++++++ application/resources/multimc/multimc.qrc | 6 + application/resources/multimc/scalable/technic.svg | 1 + application/resources/multimc/scalable/twitch.svg | 63 +++ application/widgets/InstanceCardWidget.ui | 61 +++ application/widgets/JavaSettingsWidget.cpp | 4 +- application/widgets/PageContainer.cpp | 3 +- application/widgets/PageContainer.h | 10 +- application/widgets/VersionSelectWidget.cpp | 23 +- application/widgets/VersionSelectWidget.h | 6 +- 105 files changed, 6401 insertions(+), 5755 deletions(-) delete mode 100644 application/dialogs/ChooseFtbPackDialog.cpp delete mode 100644 application/dialogs/ChooseFtbPackDialog.h delete mode 100644 application/dialogs/ChooseFtbPackDialog.ui delete mode 100644 application/pages/InstanceSettingsPage.cpp delete mode 100644 application/pages/InstanceSettingsPage.h delete mode 100644 application/pages/InstanceSettingsPage.ui delete mode 100644 application/pages/LegacyUpgradePage.cpp delete mode 100644 application/pages/LegacyUpgradePage.h delete mode 100644 application/pages/LegacyUpgradePage.ui delete mode 100644 application/pages/LogPage.cpp delete mode 100644 application/pages/LogPage.h delete mode 100644 application/pages/LogPage.ui delete mode 100644 application/pages/ModFolderPage.cpp delete mode 100644 application/pages/ModFolderPage.h delete mode 100644 application/pages/ModFolderPage.ui delete mode 100644 application/pages/NotesPage.cpp delete mode 100644 application/pages/NotesPage.h delete mode 100644 application/pages/NotesPage.ui delete mode 100644 application/pages/OtherLogsPage.cpp delete mode 100644 application/pages/OtherLogsPage.h delete mode 100644 application/pages/OtherLogsPage.ui delete mode 100644 application/pages/ResourcePackPage.h delete mode 100644 application/pages/ScreenshotsPage.cpp delete mode 100644 application/pages/ScreenshotsPage.h delete mode 100644 application/pages/ScreenshotsPage.ui delete mode 100644 application/pages/TexturePackPage.h delete mode 100644 application/pages/VersionPage.cpp delete mode 100644 application/pages/VersionPage.h delete mode 100644 application/pages/VersionPage.ui delete mode 100644 application/pages/WorldListPage.cpp delete mode 100644 application/pages/WorldListPage.h delete mode 100644 application/pages/WorldListPage.ui create mode 100644 application/pages/instance/InstanceSettingsPage.cpp create mode 100644 application/pages/instance/InstanceSettingsPage.h create mode 100644 application/pages/instance/InstanceSettingsPage.ui create mode 100644 application/pages/instance/LegacyUpgradePage.cpp create mode 100644 application/pages/instance/LegacyUpgradePage.h create mode 100644 application/pages/instance/LegacyUpgradePage.ui create mode 100644 application/pages/instance/LogPage.cpp create mode 100644 application/pages/instance/LogPage.h create mode 100644 application/pages/instance/LogPage.ui create mode 100644 application/pages/instance/ModFolderPage.cpp create mode 100644 application/pages/instance/ModFolderPage.h create mode 100644 application/pages/instance/ModFolderPage.ui create mode 100644 application/pages/instance/NotesPage.cpp create mode 100644 application/pages/instance/NotesPage.h create mode 100644 application/pages/instance/NotesPage.ui create mode 100644 application/pages/instance/OtherLogsPage.cpp create mode 100644 application/pages/instance/OtherLogsPage.h create mode 100644 application/pages/instance/OtherLogsPage.ui create mode 100644 application/pages/instance/ResourcePackPage.h create mode 100644 application/pages/instance/ScreenshotsPage.cpp create mode 100644 application/pages/instance/ScreenshotsPage.h create mode 100644 application/pages/instance/ScreenshotsPage.ui create mode 100644 application/pages/instance/TexturePackPage.h create mode 100644 application/pages/instance/VersionPage.cpp create mode 100644 application/pages/instance/VersionPage.h create mode 100644 application/pages/instance/VersionPage.ui create mode 100644 application/pages/instance/WorldListPage.cpp create mode 100644 application/pages/instance/WorldListPage.h create mode 100644 application/pages/instance/WorldListPage.ui create mode 100644 application/pages/modplatform/FTBPage.cpp create mode 100644 application/pages/modplatform/FTBPage.h create mode 100644 application/pages/modplatform/FTBPage.ui create mode 100644 application/pages/modplatform/ImportPage.cpp create mode 100644 application/pages/modplatform/ImportPage.h create mode 100644 application/pages/modplatform/ImportPage.ui create mode 100644 application/pages/modplatform/TechnicPage.cpp create mode 100644 application/pages/modplatform/TechnicPage.h create mode 100644 application/pages/modplatform/TechnicPage.ui create mode 100644 application/pages/modplatform/TwitchPage.cpp create mode 100644 application/pages/modplatform/TwitchPage.h create mode 100644 application/pages/modplatform/TwitchPage.ui create mode 100644 application/pages/modplatform/VanillaPage.cpp create mode 100644 application/pages/modplatform/VanillaPage.h create mode 100644 application/pages/modplatform/VanillaPage.ui create mode 100644 application/resources/multimc/scalable/technic.svg create mode 100644 application/resources/multimc/scalable/twitch.svg create mode 100644 application/widgets/InstanceCardWidget.ui (limited to 'application') diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 48c1a359..5eeca240 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 68a68794..d79bcac0 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 b13ce93d..9dda7859 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 2e876fea..5895ca3a 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 542d1da6..60742412 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()) - { - instanceFromFtbPack(newInstDlg.getFtbPackDownloader(), newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey()); - } - else if (modpackUrl.isValid()) - { - instanceFromZipPack(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), modpackUrl); - } - else + InstanceTask * creationTask = newInstDlg.extractTask(); + if(creationTask) { - instanceFromVersion(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), newInstDlg.selectedVersion()); + instanceFromInstanceTask(creationTask); } } diff --git a/application/MainWindow.h b/application/MainWindow.h index e9897606..609df4ca 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 230d757f..4236fbcf 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 5b8badf2..0d14fbee 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 0dbc4ef6..c180adf2 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 4441ea6b..33a0d1ea 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 b1deae6e..00000000 --- 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 f9f3dd08..00000000 --- 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 f590a4cd..00000000 --- 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 eee3991c..f0783603 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(); - if(!url.isEmpty()) - { - ui->modpackBox->setChecked(true); - ui->modpackEdit->setText(url); - } + m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok); + m_buttons->button(QDialogButtonBox::Ok)->setDefault(true); - ftbPackDownloader = new FtbPackDownloader(); + connect(m_buttons->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept); + connect(m_buttons->button(QDialogButtonBox::Help), &QPushButton::clicked, m_container, &PageContainer::help); - connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &NewInstanceDialog::ftbPackDataDownloadSuccessfully); - connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &NewInstanceDialog::ftbPackDataDownloadFailed); + m_container = new PageContainer(this); + m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding); + ui->verticalLayout->insertWidget(2, m_container); - ftbPackDownloader->fetchModpacks(false); + m_container->addButtons(m_buttons); + m_buttons->setFocus(); + + if(!url.isEmpty()) + { + m_container->selectPage("import"); + importPage->setUrl(url); + } 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()); - } - } -} - -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()); + qDebug() << "New instance dialog close approved"; + MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64()); + qDebug() << "New instance dialog geometry saved"; + QDialog::closeEvent(event); } - 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 f1fe26f4..ca134d32 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; - - bool m_versionSetByUser = false; - bool ftbModpackRequested = false; + Ui::NewInstanceDialog *ui = nullptr; + PageContainer * m_container = nullptr; + QDialogButtonBox * m_buttons = nullptr; - 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 428b9c57..7fb19ff5 100644 --- a/application/dialogs/NewInstanceDialog.ui +++ b/application/dialogs/NewInstanceDialog.ui @@ -9,8 +9,8 @@ 0 0 - 281 - 407 + 730 + 127 @@ -25,357 +25,63 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 80 - 80 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Name - - - - - - - Qt::Horizontal - - - - - - - - - &Group: - - - groupBox - - - - + + - - - 0 - 0 - - true - - - - - - - - false - + + - Install FTB Pack - - - - - - - ... - - - - - - - false - - - ... - - - - - - - false - - - ... - - - - - - - false + &Group: - - No Pack choosen + + groupBox - - - - Impor&t Modpack (local file or link): - - + + - - + + - Vani&lla Minecraft (select version): - - - true + &Name: - - - - - - true - - - - - - - false - - - http:// + + instNameTextBox - - - - (Loading Pack data...) + + + + + 80 + 80 + - - - 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 a44572cc..1ed81e79 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 b201de85..1b5284d2 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 67cd290e..a287f9c9 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 63a26239..d4547770 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 0ebcff7a..1cc7458a 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/InstanceSettingsPage.cpp b/application/pages/InstanceSettingsPage.cpp deleted file mode 100644 index 71e90a32..00000000 --- a/application/pages/InstanceSettingsPage.cpp +++ /dev/null @@ -1,251 +0,0 @@ -#include "InstanceSettingsPage.h" -#include "ui_InstanceSettingsPage.h" - -#include -#include -#include - -#include "dialogs/VersionSelectDialog.h" -#include "JavaCommon.h" -#include "MultiMC.h" - -#include -#include -#include -#include - -InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) - : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst) -{ - m_settings = inst->settings(); - ui->setupUi(this); - auto sysMB = Sys::getSystemRam() / Sys::megabyte; - ui->maxMemSpinBox->setMaximum(sysMB); - loadSettings(); -} - -bool InstanceSettingsPage::shouldDisplay() const -{ - return !m_instance->isRunning(); -} - -InstanceSettingsPage::~InstanceSettingsPage() -{ - delete ui; -} - -bool InstanceSettingsPage::apply() -{ - applySettings(); - return true; -} - -void InstanceSettingsPage::applySettings() -{ - SettingsObject::Lock lock(m_settings); - - // Console - bool console = ui->consoleSettingsBox->isChecked(); - m_settings->set("OverrideConsole", console); - if (console) - { - m_settings->set("ShowConsole", ui->showConsoleCheck->isChecked()); - m_settings->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); - m_settings->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked()); - } - else - { - m_settings->reset("ShowConsole"); - m_settings->reset("AutoCloseConsole"); - m_settings->reset("ShowConsoleOnError"); - } - - // Window Size - bool window = ui->windowSizeGroupBox->isChecked(); - m_settings->set("OverrideWindow", window); - if (window) - { - m_settings->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); - m_settings->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); - m_settings->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); - } - else - { - m_settings->reset("LaunchMaximized"); - m_settings->reset("MinecraftWinWidth"); - m_settings->reset("MinecraftWinHeight"); - } - - // Memory - bool memory = ui->memoryGroupBox->isChecked(); - m_settings->set("OverrideMemory", memory); - if (memory) - { - int min = ui->minMemSpinBox->value(); - int max = ui->maxMemSpinBox->value(); - if(min < max) - { - m_settings->set("MinMemAlloc", min); - m_settings->set("MaxMemAlloc", max); - } - else - { - m_settings->set("MinMemAlloc", max); - m_settings->set("MaxMemAlloc", min); - } - m_settings->set("PermGen", ui->permGenSpinBox->value()); - } - else - { - m_settings->reset("MinMemAlloc"); - m_settings->reset("MaxMemAlloc"); - m_settings->reset("PermGen"); - } - - // Java Install Settings - bool javaInstall = ui->javaSettingsGroupBox->isChecked(); - m_settings->set("OverrideJavaLocation", javaInstall); - if (javaInstall) - { - m_settings->set("JavaPath", ui->javaPathTextBox->text()); - } - else - { - m_settings->reset("JavaPath"); - } - - // Java arguments - bool javaArgs = ui->javaArgumentsGroupBox->isChecked(); - m_settings->set("OverrideJavaArgs", javaArgs); - if(javaArgs) - { - m_settings->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " ")); - JavaCommon::checkJVMArgs(m_settings->get("JvmArgs").toString(), this->parentWidget()); - } - else - { - m_settings->reset("JvmArgs"); - } - - // old generic 'override both' is removed. - m_settings->reset("OverrideJava"); - - // Custom Commands - bool custcmd = ui->customCommands->checked(); - m_settings->set("OverrideCommands", custcmd); - if (custcmd) - { - m_settings->set("PreLaunchCommand", ui->customCommands->prelaunchCommand()); - m_settings->set("WrapperCommand", ui->customCommands->wrapperCommand()); - m_settings->set("PostExitCommand", ui->customCommands->postexitCommand()); - } - else - { - m_settings->reset("PreLaunchCommand"); - m_settings->reset("WrapperCommand"); - m_settings->reset("PostExitCommand"); - } -} - -void InstanceSettingsPage::loadSettings() -{ - // Console - ui->consoleSettingsBox->setChecked(m_settings->get("OverrideConsole").toBool()); - ui->showConsoleCheck->setChecked(m_settings->get("ShowConsole").toBool()); - ui->autoCloseConsoleCheck->setChecked(m_settings->get("AutoCloseConsole").toBool()); - ui->showConsoleErrorCheck->setChecked(m_settings->get("ShowConsoleOnError").toBool()); - - // Window Size - ui->windowSizeGroupBox->setChecked(m_settings->get("OverrideWindow").toBool()); - ui->maximizedCheckBox->setChecked(m_settings->get("LaunchMaximized").toBool()); - ui->windowWidthSpinBox->setValue(m_settings->get("MinecraftWinWidth").toInt()); - ui->windowHeightSpinBox->setValue(m_settings->get("MinecraftWinHeight").toInt()); - - // Memory - ui->memoryGroupBox->setChecked(m_settings->get("OverrideMemory").toBool()); - int min = m_settings->get("MinMemAlloc").toInt(); - int max = m_settings->get("MaxMemAlloc").toInt(); - if(min < max) - { - ui->minMemSpinBox->setValue(min); - ui->maxMemSpinBox->setValue(max); - } - else - { - ui->minMemSpinBox->setValue(max); - ui->maxMemSpinBox->setValue(min); - } - ui->permGenSpinBox->setValue(m_settings->get("PermGen").toInt()); - - // Java Settings - bool overrideJava = m_settings->get("OverrideJava").toBool(); - bool overrideLocation = m_settings->get("OverrideJavaLocation").toBool() || overrideJava; - bool overrideArgs = m_settings->get("OverrideJavaArgs").toBool() || overrideJava; - - ui->javaSettingsGroupBox->setChecked(overrideLocation); - ui->javaPathTextBox->setText(m_settings->get("JavaPath").toString()); - - ui->javaArgumentsGroupBox->setChecked(overrideArgs); - ui->jvmArgsTextBox->setPlainText(m_settings->get("JvmArgs").toString()); - - // Custom commands - ui->customCommands->initialize( - true, - m_settings->get("OverrideCommands").toBool(), - m_settings->get("PreLaunchCommand").toString(), - m_settings->get("WrapperCommand").toString(), - m_settings->get("PostExitCommand").toString() - ); -} - -void InstanceSettingsPage::on_javaDetectBtn_clicked() -{ - JavaInstallPtr java; - - VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true); - vselect.setResizeOn(2); - vselect.exec(); - - if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) - { - java = std::dynamic_pointer_cast(vselect.selectedVersion()); - ui->javaPathTextBox->setText(java->path); - } -} - -void InstanceSettingsPage::on_javaBrowseBtn_clicked() -{ - QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - - // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if(raw_path.isEmpty()) - { - return; - } - QString cooked_path = FS::NormalizePath(raw_path); - - QFileInfo javaInfo(cooked_path);; - if(!javaInfo.exists() || !javaInfo.isExecutable()) - { - return; - } - ui->javaPathTextBox->setText(cooked_path); -} - -void InstanceSettingsPage::on_javaTestBtn_clicked() -{ - if(checker) - { - return; - } - checker.reset(new JavaCommon::TestCheck( - this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->toPlainText().replace("\n", " "), - ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value())); - connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished())); - checker->run(); -} - -void InstanceSettingsPage::checkerFinished() -{ - checker.reset(); -} diff --git a/application/pages/InstanceSettingsPage.h b/application/pages/InstanceSettingsPage.h deleted file mode 100644 index 4959bdbe..00000000 --- a/application/pages/InstanceSettingsPage.h +++ /dev/null @@ -1,74 +0,0 @@ -/* 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 "java/JavaChecker.h" -#include "BaseInstance.h" -#include -#include "BasePage.h" -#include "JavaCommon.h" -#include "MultiMC.h" - -class JavaChecker; -namespace Ui -{ -class InstanceSettingsPage; -} - -class InstanceSettingsPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit InstanceSettingsPage(BaseInstance *inst, QWidget *parent = 0); - virtual ~InstanceSettingsPage(); - virtual QString displayName() const override - { - return tr("Settings"); - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon("instance-settings"); - } - virtual QString id() const override - { - return "settings"; - } - virtual bool apply() override; - virtual QString helpPage() const override - { - return "Instance-settings"; - } - virtual bool shouldDisplay() const override; - -private slots: - void on_javaDetectBtn_clicked(); - void on_javaTestBtn_clicked(); - void on_javaBrowseBtn_clicked(); - - void applySettings(); - void loadSettings(); - - void checkerFinished(); - -private: - Ui::InstanceSettingsPage *ui; - BaseInstance *m_instance; - SettingsObjectPtr m_settings; - unique_qobject_ptr checker; -}; diff --git a/application/pages/InstanceSettingsPage.ui b/application/pages/InstanceSettingsPage.ui deleted file mode 100644 index 0c180df3..00000000 --- a/application/pages/InstanceSettingsPage.ui +++ /dev/null @@ -1,393 +0,0 @@ - - - InstanceSettingsPage - - - - 0 - 0 - 553 - 522 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QTabWidget::Rounded - - - 0 - - - - Java - - - - - - true - - - Java insta&llation - - - true - - - false - - - - - - - - - Auto-detect... - - - - - - - Browse... - - - - - - - Test - - - - - - - - - - true - - - Memor&y - - - true - - - false - - - - - - Minimum memory allocation: - - - - - - - The maximum amount of memory Minecraft is allowed to use. - - - MB - - - 128 - - - 65536 - - - 128 - - - 1024 - - - - - - - The amount of memory Minecraft is started with. - - - MB - - - 128 - - - 65536 - - - 128 - - - 256 - - - - - - - The amount of memory available to store loaded Java classes. - - - MB - - - 64 - - - 999999999 - - - 8 - - - 64 - - - - - - - PermGen: - - - - - - - Maximum memory allocation: - - - - - - - Note: Permgen is set automatically by Java 8 and later - - - - - - - - - - true - - - Java argumen&ts - - - true - - - false - - - - - - - - - - - - - Game windows - - - - - - true - - - Game Window - - - true - - - false - - - - - - Start Minecraft maximized? - - - - - - - - - Window height: - - - - - - - Window width: - - - - - - - 1 - - - 65536 - - - 1 - - - 854 - - - - - - - 1 - - - 65536 - - - 480 - - - - - - - - - - - - true - - - Conso&le Settings - - - true - - - false - - - - - - Show console while the game is running? - - - - - - - Automatically close console when the game quits? - - - - - - - Show console when the game crashes? - - - - - - - - - - Qt::Vertical - - - - 88 - 125 - - - - - - - - - Custom commands - - - - - - - - - - - - - - CustomCommands - QWidget -
widgets/CustomCommands.h
- 1 -
-
- - settingsTabs - javaSettingsGroupBox - javaPathTextBox - javaDetectBtn - javaBrowseBtn - javaTestBtn - memoryGroupBox - minMemSpinBox - maxMemSpinBox - permGenSpinBox - javaArgumentsGroupBox - jvmArgsTextBox - windowSizeGroupBox - maximizedCheckBox - windowWidthSpinBox - windowHeightSpinBox - consoleSettingsBox - showConsoleCheck - autoCloseConsoleCheck - showConsoleErrorCheck - - - -
diff --git a/application/pages/LegacyUpgradePage.cpp b/application/pages/LegacyUpgradePage.cpp deleted file mode 100644 index a8f4a08c..00000000 --- a/application/pages/LegacyUpgradePage.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "LegacyUpgradePage.h" -#include "ui_LegacyUpgradePage.h" - -#include "minecraft/legacy/LegacyInstance.h" -#include "minecraft/legacy/LegacyUpgradeTask.h" -#include "MultiMC.h" -#include "FolderInstanceProvider.h" -#include "dialogs/CustomMessageBox.h" -#include "dialogs/ProgressDialog.h" - -LegacyUpgradePage::LegacyUpgradePage(InstancePtr inst, QWidget *parent) - : QWidget(parent), ui(new Ui::LegacyUpgradePage), m_inst(inst) -{ - ui->setupUi(this); -} - -LegacyUpgradePage::~LegacyUpgradePage() -{ - delete ui; -} - -void LegacyUpgradePage::runModalTask(Task *task) -{ - connect(task, &Task::failed, [this](QString reason) - { - CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Warning)->show(); - }); - ProgressDialog loadDialog(this); - loadDialog.setSkipButton(true, tr("Abort")); - if(loadDialog.execWithTask(task) == QDialog::Accepted) - { - m_container->requestClose(); - } -} - -void LegacyUpgradePage::on_upgradeButton_clicked() -{ - std::unique_ptr task(MMC->folderProvider()->legacyUpgradeTask(m_inst)); - runModalTask(task.get()); -} - -bool LegacyUpgradePage::shouldDisplay() const -{ - return !m_inst->isRunning(); -} diff --git a/application/pages/LegacyUpgradePage.h b/application/pages/LegacyUpgradePage.h deleted file mode 100644 index 3e1abe93..00000000 --- a/application/pages/LegacyUpgradePage.h +++ /dev/null @@ -1,64 +0,0 @@ -/* 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 "minecraft/legacy/LegacyInstance.h" -#include "pages/BasePage.h" -#include -#include "tasks/Task.h" - -namespace Ui -{ -class LegacyUpgradePage; -} - -class LegacyUpgradePage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit LegacyUpgradePage(InstancePtr inst, QWidget *parent = 0); - virtual ~LegacyUpgradePage(); - virtual QString displayName() const override - { - return tr("Upgrade"); - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon("checkupdate"); - } - virtual QString id() const override - { - return "upgrade"; - } - virtual QString helpPage() const override - { - return "Legacy-upgrade"; - } - virtual bool shouldDisplay() const override; - -private slots: - void on_upgradeButton_clicked(); - -private: - void runModalTask(Task *task); - -private: - Ui::LegacyUpgradePage *ui; - InstancePtr m_inst; -}; diff --git a/application/pages/LegacyUpgradePage.ui b/application/pages/LegacyUpgradePage.ui deleted file mode 100644 index a94ee039..00000000 --- a/application/pages/LegacyUpgradePage.ui +++ /dev/null @@ -1,47 +0,0 @@ - - - LegacyUpgradePage - - - - 0 - 0 - 546 - 405 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - <html><body><h1>Upgrade is required</h1><p>MultiMC now supports old Minecraft versions and all the required features in the new (OneSix) instance format. As a consequence, the old (Legacy) format has been entirely disabled and old instances need to be upgraded.</p><p>The upgrade will create a new instance with the same contents as the current one, in the new format. The original instance will remain untouched, in case anything goes wrong in the process.</p><p>Please report any issues on our <a href="https://github.com/MultiMC/MultiMC5/issues">github issues page</a>.</p><p>There is also a <a href="https://discord.gg/GtPmv93">discord channel for testing here</a>.</p></body></html> - - - true - - - - - - - Upgrade the instance - - - - - - - - diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp deleted file mode 100644 index 0fa1ee67..00000000 --- a/application/pages/LogPage.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include "LogPage.h" -#include "ui_LogPage.h" - -#include "MultiMC.h" - -#include -#include -#include - -#include "launch/LaunchTask.h" -#include -#include "GuiUtil.h" -#include - -class LogFormatProxyModel : public QIdentityProxyModel -{ -public: - LogFormatProxyModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) - { - } - QVariant data(const QModelIndex &index, int role) const override - { - switch(role) - { - case Qt::FontRole: - return m_font; - case Qt::TextColorRole: - { - MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); - return m_colors->getFront(level); - } - case Qt::BackgroundRole: - { - MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); - return m_colors->getBack(level); - } - default: - return QIdentityProxyModel::data(index, role); - } - } - - void setFont(QFont font) - { - m_font = font; - } - - void setColors(LogColorCache* colors) - { - m_colors.reset(colors); - } - - QModelIndex find(const QModelIndex &start, const QString &value, bool reverse) const - { - QModelIndex parentIndex = parent(start); - auto compare = [&](int r) -> QModelIndex - { - QModelIndex idx = index(r, start.column(), parentIndex); - if (!idx.isValid() || idx == start) - { - return QModelIndex(); - } - QVariant v = data(idx, Qt::DisplayRole); - QString t = v.toString(); - if (t.contains(value, Qt::CaseInsensitive)) - return idx; - return QModelIndex(); - }; - if(reverse) - { - int from = start.row(); - int to = 0; - - for (int i = 0; i < 2; ++i) - { - for (int r = from; (r >= to); --r) - { - auto idx = compare(r); - if(idx.isValid()) - return idx; - } - // prepare for the next iteration - from = rowCount() - 1; - to = start.row(); - } - } - else - { - int from = start.row(); - int to = rowCount(parentIndex); - - for (int i = 0; i < 2; ++i) - { - for (int r = from; (r < to); ++r) - { - auto idx = compare(r); - if(idx.isValid()) - return idx; - } - // prepare for the next iteration - from = 0; - to = start.row(); - } - } - return QModelIndex(); - } -private: - QFont m_font; - std::unique_ptr m_colors; -}; - -LogPage::LogPage(InstancePtr instance, QWidget *parent) - : QWidget(parent), ui(new Ui::LogPage), m_instance(instance) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - - m_proxy = new LogFormatProxyModel(this); - // set up text colors in the log proxy and adapt them to the current theme foreground and background - { - auto origForeground = ui->text->palette().color(ui->text->foregroundRole()); - auto origBackground = ui->text->palette().color(ui->text->backgroundRole()); - m_proxy->setColors(new LogColorCache(origForeground, origBackground)); - } - - // set up fonts in the log proxy - { - QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); - bool conversionOk = false; - int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk); - if(!conversionOk) - { - fontSize = 11; - } - m_proxy->setFont(QFont(fontFamily, fontSize)); - } - - ui->text->setModel(m_proxy); - - // set up instance and launch process recognition - { - auto launchTask = m_instance->getLaunchTask(); - if(launchTask) - { - setInstanceLaunchTaskChanged(launchTask, true); - } - connect(m_instance.get(), &BaseInstance::launchTaskChanged, this, &LogPage::onInstanceLaunchTaskChanged); - } - - auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); - connect(findShortcut, SIGNAL(activated()), SLOT(findActivated())); - auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this); - connect(findNextShortcut, SIGNAL(activated()), SLOT(findNextActivated())); - connect(ui->searchBar, SIGNAL(returnPressed()), SLOT(on_findButton_clicked())); - auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this); - connect(findPreviousShortcut, SIGNAL(activated()), SLOT(findPreviousActivated())); -} - -LogPage::~LogPage() -{ - delete ui; -} - -void LogPage::modelStateToUI() -{ - if(m_model->wrapLines()) - { - ui->text->setWordWrap(true); - ui->wrapCheckbox->setCheckState(Qt::Checked); - } - else - { - ui->text->setWordWrap(false); - ui->wrapCheckbox->setCheckState(Qt::Unchecked); - } - if(m_model->suspended()) - { - ui->trackLogCheckbox->setCheckState(Qt::Unchecked); - } - else - { - ui->trackLogCheckbox->setCheckState(Qt::Checked); - } -} - -void LogPage::UIToModelState() -{ - if(!m_model) - { - return; - } - m_model->setLineWrap(ui->wrapCheckbox->checkState() == Qt::Checked); - m_model->suspend(ui->trackLogCheckbox->checkState() != Qt::Checked); -} - -void LogPage::setInstanceLaunchTaskChanged(std::shared_ptr proc, bool initial) -{ - m_process = proc; - if(m_process) - { - m_model = proc->getLogModel(); - m_proxy->setSourceModel(m_model.get()); - if(initial) - { - modelStateToUI(); - } - else - { - UIToModelState(); - } - } - else - { - m_proxy->setSourceModel(nullptr); - m_model.reset(); - } -} - -void LogPage::onInstanceLaunchTaskChanged(std::shared_ptr proc) -{ - setInstanceLaunchTaskChanged(proc, false); -} - -bool LogPage::apply() -{ - return true; -} - -bool LogPage::shouldDisplay() const -{ - return m_instance->isRunning() || m_proxy->rowCount() > 0; -} - -void LogPage::on_btnPaste_clicked() -{ - if(!m_model) - return; - - //FIXME: turn this into a proper task and move the upload logic out of GuiUtil! - m_model->append(MessageLevel::MultiMC, tr("MultiMC: Log upload triggered at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date))); - auto url = GuiUtil::uploadPaste(m_model->toPlainText(), this); - if(!url.isEmpty()) - { - m_model->append(MessageLevel::MultiMC, tr("MultiMC: Log uploaded to: %1").arg(url)); - } - else - { - m_model->append(MessageLevel::Error, tr("MultiMC: Log upload failed!")); - } -} - -void LogPage::on_btnCopy_clicked() -{ - if(!m_model) - return; - m_model->append(MessageLevel::MultiMC, QString("Clipboard copy at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date))); - GuiUtil::setClipboardText(m_model->toPlainText()); -} - -void LogPage::on_btnClear_clicked() -{ - if(!m_model) - return; - m_model->clear(); - m_container->refreshContainer(); -} - -void LogPage::on_btnBottom_clicked() -{ - ui->text->scrollToBottom(); -} - -void LogPage::on_trackLogCheckbox_clicked(bool checked) -{ - if(!m_model) - return; - m_model->suspend(!checked); -} - -void LogPage::on_wrapCheckbox_clicked(bool checked) -{ - ui->text->setWordWrap(checked); - if(!m_model) - return; - m_model->setLineWrap(checked); -} - -void LogPage::on_findButton_clicked() -{ - auto modifiers = QApplication::keyboardModifiers(); - bool reverse = modifiers & Qt::ShiftModifier; - ui->text->findNext(ui->searchBar->text(), reverse); -} - -void LogPage::findNextActivated() -{ - ui->text->findNext(ui->searchBar->text(), false); -} - -void LogPage::findPreviousActivated() -{ - ui->text->findNext(ui->searchBar->text(), true); -} - -void LogPage::findActivated() -{ - // focus the search bar if it doesn't have focus - if (!ui->searchBar->hasFocus()) - { - ui->searchBar->setFocus(); - ui->searchBar->selectAll(); - } -} diff --git a/application/pages/LogPage.h b/application/pages/LogPage.h deleted file mode 100644 index b830118e..00000000 --- a/application/pages/LogPage.h +++ /dev/null @@ -1,86 +0,0 @@ -/* 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 "BaseInstance.h" -#include "launch/LaunchTask.h" -#include "BasePage.h" -#include - -namespace Ui -{ -class LogPage; -} -class QTextCharFormat; -class LogFormatProxyModel; - -class LogPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit LogPage(InstancePtr instance, QWidget *parent = 0); - virtual ~LogPage(); - virtual QString displayName() const override - { - return tr("Minecraft Log"); - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon("log"); - } - virtual QString id() const override - { - return "console"; - } - virtual bool apply() override; - virtual QString helpPage() const override - { - return "Minecraft-Logs"; - } - virtual bool shouldDisplay() const override; - -private slots: - void on_btnPaste_clicked(); - void on_btnCopy_clicked(); - void on_btnClear_clicked(); - void on_btnBottom_clicked(); - - void on_trackLogCheckbox_clicked(bool checked); - void on_wrapCheckbox_clicked(bool checked); - - void on_findButton_clicked(); - void findActivated(); - void findNextActivated(); - void findPreviousActivated(); - - void onInstanceLaunchTaskChanged(std::shared_ptr proc); - -private: - void modelStateToUI(); - void UIToModelState(); - void setInstanceLaunchTaskChanged(std::shared_ptr proc, bool initial); - -private: - Ui::LogPage *ui; - InstancePtr m_instance; - std::shared_ptr m_process; - - LogFormatProxyModel * m_proxy; - shared_qobject_ptr m_model; -}; diff --git a/application/pages/LogPage.ui b/application/pages/LogPage.ui deleted file mode 100644 index 4843d7c3..00000000 --- a/application/pages/LogPage.ui +++ /dev/null @@ -1,182 +0,0 @@ - - - LogPage - - - - 0 - 0 - 825 - 782 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - false - - - true - - - - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - false - - - - - - - - - Keep updating - - - true - - - - - - - Wrap lines - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Copy the whole log into the clipboard - - - &Copy - - - - - - - Upload the log to paste.ee - it will stay online for a month - - - Upload - - - - - - - Clear the log - - - Clear - - - - - - - - - Search: - - - - - - - Find - - - - - - - - - - Scroll all the way to bottom - - - Bottom - - - - - - - Qt::Vertical - - - - - - - - - - - - LogView - QPlainTextEdit -
widgets/LogView.h
-
-
- - tabWidget - trackLogCheckbox - wrapCheckbox - btnCopy - btnPaste - btnClear - text - searchBar - findButton - - - -
diff --git a/application/pages/ModFolderPage.cpp b/application/pages/ModFolderPage.cpp deleted file mode 100644 index 2b3f4416..00000000 --- a/application/pages/ModFolderPage.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* 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. - */ - -#include "ModFolderPage.h" -#include "ui_ModFolderPage.h" - -#include -#include -#include -#include - -#include "MultiMC.h" -#include "dialogs/CustomMessageBox.h" -#include "dialogs/ModEditDialogCommon.h" -#include -#include "minecraft/ModList.h" -#include "minecraft/Mod.h" -#include "minecraft/VersionFilterData.h" -#include "minecraft/ComponentList.h" -#include - -ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, - QString iconName, QString displayName, QString helpPage, - QWidget *parent) - : QWidget(parent), ui(new Ui::ModFolderPage) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - m_inst = inst; - m_mods = mods; - m_id = id; - m_displayName = displayName; - m_iconName = iconName; - m_helpName = helpPage; - m_fileSelectionFilter = "%1 (*.zip *.jar)"; - m_filterModel = new QSortFilterProxyModel(this); - m_filterModel->setDynamicSortFilter(true); - m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive); - m_filterModel->setSourceModel(m_mods.get()); - m_filterModel->setFilterKeyColumn(-1); - ui->modTreeView->setModel(m_filterModel); - ui->modTreeView->installEventFilter(this); - ui->modTreeView->sortByColumn(1, Qt::AscendingOrder); - auto smodel = ui->modTreeView->selectionModel(); - connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent); - connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged ); -} - -void ModFolderPage::opened() -{ - m_mods->startWatching(); -} - -void ModFolderPage::closed() -{ - m_mods->stopWatching(); -} - -void ModFolderPage::on_filterTextChanged(const QString& newContents) -{ - m_viewFilter = newContents; - m_filterModel->setFilterFixedString(m_viewFilter); -} - - -CoreModFolderPage::CoreModFolderPage(BaseInstance *inst, std::shared_ptr mods, - QString id, QString iconName, QString displayName, - QString helpPage, QWidget *parent) - : ModFolderPage(inst, mods, id, iconName, displayName, helpPage, parent) -{ -} - -ModFolderPage::~ModFolderPage() -{ - m_mods->stopWatching(); - delete ui; -} - -bool ModFolderPage::shouldDisplay() const -{ - if (m_inst) - return !m_inst->isRunning(); - return true; -} - -bool CoreModFolderPage::shouldDisplay() const -{ - if (ModFolderPage::shouldDisplay()) - { - auto inst = dynamic_cast(m_inst); - if (!inst) - return true; - auto version = inst->getComponentList(); - if (!version) - return true; - if(!version->getComponent("net.minecraftforge")) - { - return false; - } - if(!version->getComponent("net.minecraft")) - { - return false; - } - if(version->getComponent("net.minecraft")->getReleaseDateTime() < g_VersionFilterData.legacyCutoffDate) - { - return true; - } - } - return false; -} - -bool ModFolderPage::modListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmModBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addModBtn_clicked(); - return true; - default: - break; - } - return QWidget::eventFilter(ui->modTreeView, keyEvent); -} - -bool ModFolderPage::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QWidget::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->modTreeView) - return modListFilter(keyEvent); - return QWidget::eventFilter(obj, ev); -} - -void ModFolderPage::on_addModBtn_clicked() -{ - auto list = GuiUtil::BrowseForFiles( - m_helpName, - tr("Select %1", - "Select whatever type of files the page contains. Example: 'Loader Mods'") - .arg(m_displayName), - m_fileSelectionFilter.arg(m_displayName), MMC->settings()->get("CentralModsDir").toString(), - this->parentWidget()); - if (!list.empty()) - { - for (auto filename : list) - { - m_mods->installMod(filename); - } - } -} - -void ModFolderPage::on_enableModBtn_clicked() -{ - auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); - m_mods->enableMods(selection.indexes(), true); -} - -void ModFolderPage::on_disableModBtn_clicked() -{ - auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); - m_mods->enableMods(selection.indexes(), false); -} - -void ModFolderPage::on_rmModBtn_clicked() -{ - auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); - m_mods->deleteMods(selection.indexes()); -} - -void ModFolderPage::on_configFolderBtn_clicked() -{ - DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true); -} - -void ModFolderPage::on_viewModBtn_clicked() -{ - DesktopServices::openDirectory(m_mods->dir().absolutePath(), true); -} - -void ModFolderPage::modCurrent(const QModelIndex ¤t, const QModelIndex &previous) -{ - if (!current.isValid()) - { - ui->frame->clear(); - return; - } - auto sourceCurrent = m_filterModel->mapToSource(current); - int row = sourceCurrent.row(); - Mod &m = m_mods->operator[](row); - ui->frame->updateWithMod(m); -} diff --git a/application/pages/ModFolderPage.h b/application/pages/ModFolderPage.h deleted file mode 100644 index 02282c41..00000000 --- a/application/pages/ModFolderPage.h +++ /dev/null @@ -1,108 +0,0 @@ -/* 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 "minecraft/MinecraftInstance.h" -#include "BasePage.h" -#include - -class ModList; -namespace Ui -{ -class ModFolderPage; -} - -class ModFolderPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit ModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, - QString iconName, QString displayName, QString helpPage = "", - QWidget *parent = 0); - virtual ~ModFolderPage(); - - void setFilter(const QString & filter) - { - m_fileSelectionFilter = filter; - } - - virtual QString displayName() const override - { - return m_displayName; - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon(m_iconName); - } - virtual QString id() const override - { - return m_id; - } - virtual QString helpPage() const override - { - return m_helpName; - } - virtual bool shouldDisplay() const override; - - virtual void opened() override; - virtual void closed() override; -protected: - bool eventFilter(QObject *obj, QEvent *ev) override; - bool modListFilter(QKeyEvent *ev); - -protected: - BaseInstance *m_inst; - -protected: - Ui::ModFolderPage *ui; - std::shared_ptr m_mods; - QSortFilterProxyModel *m_filterModel; - QString m_iconName; - QString m_id; - QString m_displayName; - QString m_helpName; - QString m_fileSelectionFilter; - QString m_viewFilter; - -public -slots: - void modCurrent(const QModelIndex ¤t, const QModelIndex &previous); - -private -slots: - void on_filterTextChanged(const QString & newContents); - void on_addModBtn_clicked(); - void on_rmModBtn_clicked(); - void on_viewModBtn_clicked(); - void on_enableModBtn_clicked(); - void on_disableModBtn_clicked(); - void on_configFolderBtn_clicked(); -}; - -class CoreModFolderPage : public ModFolderPage -{ -public: - explicit CoreModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, - QString iconName, QString displayName, QString helpPage = "", - QWidget *parent = 0); - virtual ~CoreModFolderPage() - { - } - virtual bool shouldDisplay() const; -}; diff --git a/application/pages/ModFolderPage.ui b/application/pages/ModFolderPage.ui deleted file mode 100644 index b5597bdc..00000000 --- a/application/pages/ModFolderPage.ui +++ /dev/null @@ -1,180 +0,0 @@ - - - ModFolderPage - - - - 0 - 0 - 723 - 532 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - 0 - - - - Tab 1 - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Enable - - - - - - - Disable - - - - - - - Open the 'config' folder in the system file manager. - - - View configs - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - 0 - 0 - - - - - - - - - - true - - - - - - - Filter: - - - - - - - - 0 - 0 - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - - - - - - ModListView - QTreeView -
widgets/ModListView.h
-
- - MCModInfoFrame - QFrame -
widgets/MCModInfoFrame.h
- 1 -
-
- - tabWidget - modTreeView - filterEdit - addModBtn - rmModBtn - enableModBtn - disableModBtn - configFolderBtn - viewModBtn - - - -
diff --git a/application/pages/NotesPage.cpp b/application/pages/NotesPage.cpp deleted file mode 100644 index 48bb468c..00000000 --- a/application/pages/NotesPage.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "NotesPage.h" -#include "ui_NotesPage.h" - -NotesPage::NotesPage(BaseInstance *inst, QWidget *parent) - : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - ui->noteEditor->setText(m_inst->notes()); -} - -NotesPage::~NotesPage() -{ - delete ui; -} - -bool NotesPage::apply() -{ - m_inst->setNotes(ui->noteEditor->toPlainText()); - return true; -} diff --git a/application/pages/NotesPage.h b/application/pages/NotesPage.h deleted file mode 100644 index eab446ad..00000000 --- a/application/pages/NotesPage.h +++ /dev/null @@ -1,60 +0,0 @@ -/* 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 "BaseInstance.h" -#include "BasePage.h" -#include - -namespace Ui -{ -class NotesPage; -} - -class NotesPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit NotesPage(BaseInstance *inst, QWidget *parent = 0); - virtual ~NotesPage(); - virtual QString displayName() const override - { - return tr("Notes"); - } - virtual QIcon icon() const override - { - auto icon = MMC->getThemedIcon("notes"); - if(icon.isNull()) - icon = MMC->getThemedIcon("news"); - return icon; - } - virtual QString id() const override - { - return "notes"; - } - virtual bool apply() override; - virtual QString helpPage() const override - { - return "Notes"; - } - -private: - Ui::NotesPage *ui; - BaseInstance *m_inst; -}; diff --git a/application/pages/NotesPage.ui b/application/pages/NotesPage.ui deleted file mode 100644 index 88cca92f..00000000 --- a/application/pages/NotesPage.ui +++ /dev/null @@ -1,57 +0,0 @@ - - - NotesPage - - - - 0 - 0 - 731 - 538 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - Qt::ScrollBarAlwaysOn - - - false - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - - - - diff --git a/application/pages/OtherLogsPage.cpp b/application/pages/OtherLogsPage.cpp deleted file mode 100644 index 2141e0cc..00000000 --- a/application/pages/OtherLogsPage.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* 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. - */ - -#include "OtherLogsPage.h" -#include "ui_OtherLogsPage.h" - -#include - -#include "GuiUtil.h" -#include "RecursiveFileSystemWatcher.h" -#include -#include -#include - -OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent) - : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), - m_watcher(new RecursiveFileSystemWatcher(this)) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - - m_watcher->setMatcher(fileFilter); - m_watcher->setRootDir(QDir::current().absoluteFilePath(m_path)); - - connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this, &OtherLogsPage::populateSelectLogBox); - populateSelectLogBox(); - - auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); - connect(findShortcut, &QShortcut::activated, this, &OtherLogsPage::findActivated); - - auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this); - connect(findNextShortcut, &QShortcut::activated, this, &OtherLogsPage::findNextActivated); - - auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this); - connect(findPreviousShortcut, &QShortcut::activated, this, &OtherLogsPage::findPreviousActivated); - - connect(ui->searchBar, &QLineEdit::returnPressed, this, &OtherLogsPage::on_findButton_clicked); -} - -OtherLogsPage::~OtherLogsPage() -{ - delete ui; -} - -void OtherLogsPage::opened() -{ - m_watcher->enable(); -} -void OtherLogsPage::closed() -{ - m_watcher->disable(); -} - -void OtherLogsPage::populateSelectLogBox() -{ - ui->selectLogBox->clear(); - ui->selectLogBox->addItems(m_watcher->files()); - if (m_currentFile.isEmpty()) - { - setControlsEnabled(false); - ui->selectLogBox->setCurrentIndex(-1); - } - else - { - const int index = ui->selectLogBox->findText(m_currentFile); - if (index != -1) - { - ui->selectLogBox->setCurrentIndex(index); - setControlsEnabled(true); - } - else - { - setControlsEnabled(false); - } - } -} - -void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index) -{ - QString file; - if (index != -1) - { - file = ui->selectLogBox->itemText(index); - } - - if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_path, file))) - { - m_currentFile = QString(); - ui->text->clear(); - setControlsEnabled(false); - } - else - { - m_currentFile = file; - on_btnReload_clicked(); - setControlsEnabled(true); - } -} - -void OtherLogsPage::on_btnReload_clicked() -{ - if(m_currentFile.isEmpty()) - { - setControlsEnabled(false); - return; - } - QFile file(FS::PathCombine(m_path, m_currentFile)); - if (!file.open(QFile::ReadOnly)) - { - setControlsEnabled(false); - ui->btnReload->setEnabled(true); // allow reload - m_currentFile = QString(); - QMessageBox::critical(this, tr("Error"), tr("Unable to open %1 for reading: %2") - .arg(m_currentFile, file.errorString())); - } - else - { - auto setPlainText = [&](const QString & text) - { - QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); - bool conversionOk = false; - int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk); - if(!conversionOk) - { - fontSize = 11; - } - QTextDocument *doc = ui->text->document(); - doc->setDefaultFont(QFont(fontFamily, fontSize)); - ui->text->setPlainText(text); - }; - auto showTooBig = [&]() - { - setPlainText( - tr("The file (%1) is too big. You may want to open it in a viewer optimized " - "for large files.").arg(file.fileName())); - }; - if(file.size() > (1024ll * 1024ll * 12ll)) - { - showTooBig(); - return; - } - QString content; - if(file.fileName().endsWith(".gz")) - { - QByteArray temp; - if(!GZip::unzip(file.readAll(), temp)) - { - setPlainText( - tr("The file (%1) is not readable.").arg(file.fileName())); - return; - } - content = QString::fromUtf8(temp); - } - else - { - content = QString::fromUtf8(file.readAll()); - } - if (content.size() >= 50000000ll) - { - showTooBig(); - return; - } - setPlainText(content); - } -} - -void OtherLogsPage::on_btnPaste_clicked() -{ - GuiUtil::uploadPaste(ui->text->toPlainText(), this); -} - -void OtherLogsPage::on_btnCopy_clicked() -{ - GuiUtil::setClipboardText(ui->text->toPlainText()); -} - -void OtherLogsPage::on_btnDelete_clicked() -{ - if(m_currentFile.isEmpty()) - { - setControlsEnabled(false); - return; - } - if (QMessageBox::question(this, tr("Delete"), - tr("Do you really want to delete %1?").arg(m_currentFile), - QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) - { - return; - } - QFile file(FS::PathCombine(m_path, m_currentFile)); - if (!file.remove()) - { - QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2") - .arg(m_currentFile, file.errorString())); - } -} - - - -void OtherLogsPage::on_btnClean_clicked() -{ - auto toDelete = m_watcher->files(); - if(toDelete.isEmpty()) - { - return; - } - QMessageBox *messageBox = new QMessageBox(this); - messageBox->setWindowTitle(tr("Clean up")); - if(toDelete.size() > 5) - { - messageBox->setText(tr("Do you really want to delete all log files?")); - messageBox->setDetailedText(toDelete.join('\n')); - } - else - { - messageBox->setText(tr("Do you really want to delete these files?\n%1").arg(toDelete.join('\n'))); - } - messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - messageBox->setDefaultButton(QMessageBox::Ok); - messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); - messageBox->setIcon(QMessageBox::Question); - messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction); - - if (messageBox->exec() != QMessageBox::Ok) - { - return; - } - QStringList failed; - for(auto item: toDelete) - { - QFile file(FS::PathCombine(m_path, item)); - if (!file.remove()) - { - failed.push_back(item); - } - } - if(!failed.empty()) - { - QMessageBox *messageBox = new QMessageBox(this); - messageBox->setWindowTitle(tr("Error")); - if(failed.size() > 5) - { - messageBox->setText(tr("Couldn't delete some files!")); - messageBox->setDetailedText(failed.join('\n')); - } - else - { - messageBox->setText(tr("Couldn't delete some files:\n%1").arg(failed.join('\n'))); - } - messageBox->setStandardButtons(QMessageBox::Ok); - messageBox->setDefaultButton(QMessageBox::Ok); - messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); - messageBox->setIcon(QMessageBox::Critical); - messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction); - messageBox->exec(); - } -} - - -void OtherLogsPage::setControlsEnabled(const bool enabled) -{ - ui->btnReload->setEnabled(enabled); - ui->btnDelete->setEnabled(enabled); - ui->btnCopy->setEnabled(enabled); - ui->btnPaste->setEnabled(enabled); - ui->text->setEnabled(enabled); - ui->btnClean->setEnabled(enabled); -} - -// FIXME: HACK, use LogView instead? -static void findNext(QPlainTextEdit * _this, const QString& what, bool reverse) -{ - _this->find(what, reverse ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0)); -} - -void OtherLogsPage::on_findButton_clicked() -{ - auto modifiers = QApplication::keyboardModifiers(); - bool reverse = modifiers & Qt::ShiftModifier; - findNext(ui->text, ui->searchBar->text(), reverse); -} - -void OtherLogsPage::findNextActivated() -{ - findNext(ui->text, ui->searchBar->text(), false); -} - -void OtherLogsPage::findPreviousActivated() -{ - findNext(ui->text, ui->searchBar->text(), true); -} - -void OtherLogsPage::findActivated() -{ - // focus the search bar if it doesn't have focus - if (!ui->searchBar->hasFocus()) - { - ui->searchBar->setFocus(); - ui->searchBar->selectAll(); - } -} diff --git a/application/pages/OtherLogsPage.h b/application/pages/OtherLogsPage.h deleted file mode 100644 index 157f5e9d..00000000 --- a/application/pages/OtherLogsPage.h +++ /dev/null @@ -1,81 +0,0 @@ -/* 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 "BasePage.h" -#include -#include - -namespace Ui -{ -class OtherLogsPage; -} - -class RecursiveFileSystemWatcher; - -class OtherLogsPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent = 0); - ~OtherLogsPage(); - - QString id() const override - { - return "logs"; - } - QString displayName() const override - { - return tr("Other logs"); - } - QIcon icon() const override - { - return MMC->getThemedIcon("log"); - } - QString helpPage() const override - { - return "Minecraft-Logs"; - } - void opened() override; - void closed() override; - -private slots: - void populateSelectLogBox(); - void on_selectLogBox_currentIndexChanged(const int index); - void on_btnReload_clicked(); - void on_btnPaste_clicked(); - void on_btnCopy_clicked(); - void on_btnDelete_clicked(); - void on_btnClean_clicked(); - - void on_findButton_clicked(); - void findActivated(); - void findNextActivated(); - void findPreviousActivated(); - -private: - void setControlsEnabled(const bool enabled); - -private: - Ui::OtherLogsPage *ui; - QString m_path; - QString m_currentFile; - IPathMatcher::Ptr m_fileFilter; - RecursiveFileSystemWatcher *m_watcher; -}; diff --git a/application/pages/OtherLogsPage.ui b/application/pages/OtherLogsPage.ui deleted file mode 100644 index 56ff3b62..00000000 --- a/application/pages/OtherLogsPage.ui +++ /dev/null @@ -1,150 +0,0 @@ - - - OtherLogsPage - - - - 0 - 0 - 657 - 538 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - - - - Find - - - - - - - false - - - Qt::ScrollBarAlwaysOn - - - true - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - Copy the whole log into the clipboard - - - &Copy - - - - - - - Clear the log - - - Delete - - - - - - - Upload the log to paste.ee - it will stay online for a month - - - Upload - - - - - - - Clear the log - - - Clean - - - - - - - Reload - - - - - - - - 0 - 0 - - - - - - - - - - Search: - - - - - - - - - - - tabWidget - selectLogBox - btnReload - btnCopy - btnPaste - btnDelete - btnClean - text - searchBar - findButton - - - - diff --git a/application/pages/ResourcePackPage.h b/application/pages/ResourcePackPage.h deleted file mode 100644 index 19dc78da..00000000 --- a/application/pages/ResourcePackPage.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include "ModFolderPage.h" -#include "ui_ModFolderPage.h" - -class ResourcePackPage : public ModFolderPage -{ -public: - explicit ResourcePackPage(MinecraftInstance *instance, QWidget *parent = 0) - : ModFolderPage(instance, instance->resourcePackList(), "resourcepacks", - "resourcepacks", tr("Resource packs"), "Resource-packs", parent) - { - ui->configFolderBtn->setHidden(true); - } - - virtual ~ResourcePackPage() {} - virtual bool shouldDisplay() const override - { - return !m_inst->traits().contains("no-texturepacks") && - !m_inst->traits().contains("texturepacks"); - } -}; diff --git a/application/pages/ScreenshotsPage.cpp b/application/pages/ScreenshotsPage.cpp deleted file mode 100644 index 7d32576a..00000000 --- a/application/pages/ScreenshotsPage.cpp +++ /dev/null @@ -1,372 +0,0 @@ -#include "ScreenshotsPage.h" -#include "ui_ScreenshotsPage.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "dialogs/ProgressDialog.h" -#include "dialogs/CustomMessageBox.h" -#include "net/NetJob.h" -#include "screenshots/ImgurUpload.h" -#include "screenshots/ImgurAlbumCreation.h" -#include "tasks/SequentialTask.h" - -#include "RWStorage.h" -#include -#include - -typedef RWStorage SharedIconCache; -typedef std::shared_ptr SharedIconCachePtr; - -class ThumbnailingResult : public QObject -{ - Q_OBJECT -public slots: - inline void emitResultsReady(const QString &path) { emit resultsReady(path); } - inline void emitResultsFailed(const QString &path) { emit resultsFailed(path); } -signals: - void resultsReady(const QString &path); - void resultsFailed(const QString &path); -}; - -class ThumbnailRunnable : public QRunnable -{ -public: - ThumbnailRunnable(QString path, SharedIconCachePtr cache) - { - m_path = path; - m_cache = cache; - } - void run() - { - QFileInfo info(m_path); - if (info.isDir()) - return; - if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0)) - return; - int tries = 5; - while (tries) - { - if (!m_cache->stale(m_path)) - return; - QImage image(m_path); - if (image.isNull()) - { - QThread::msleep(500); - tries--; - continue; - } - QImage small; - if (image.width() > image.height()) - small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); - else - small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); - QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); - QImage square(QSize(256, 256), QImage::Format_ARGB32); - square.fill(Qt::transparent); - - QPainter painter(&square); - painter.drawImage(offset, small); - painter.end(); - - QIcon icon(QPixmap::fromImage(square)); - m_cache->add(m_path, icon); - m_resultEmitter.emitResultsReady(m_path); - return; - } - m_resultEmitter.emitResultsFailed(m_path); - } - QString m_path; - SharedIconCachePtr m_cache; - ThumbnailingResult m_resultEmitter; -}; - -// this is about as elegant and well written as a bag of bricks with scribbles done by insane -// asylum patients. -class FilterModel : public QIdentityProxyModel -{ - Q_OBJECT -public: - explicit FilterModel(QObject *parent = 0) : QIdentityProxyModel(parent) - { - m_thumbnailingPool.setMaxThreadCount(4); - m_thumbnailCache = std::make_shared(); - m_thumbnailCache->add("placeholder", MMC->getThemedIcon("screenshot-placeholder")); - connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); - // FIXME: the watched file set is not updated when files are removed - } - virtual ~FilterModel() { m_thumbnailingPool.waitForDone(500); } - virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const - { - auto model = sourceModel(); - if (!model) - return QVariant(); - if (role == Qt::DisplayRole || role == Qt::EditRole) - { - QVariant result = sourceModel()->data(mapToSource(proxyIndex), role); - return result.toString().remove(QRegExp("\\.png$")); - } - if (role == Qt::DecorationRole) - { - QVariant result = - sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole); - QString filePath = result.toString(); - QIcon temp; - if (!watched.contains(filePath)) - { - ((QFileSystemWatcher &)watcher).addPath(filePath); - ((QSet &)watched).insert(filePath); - } - if (m_thumbnailCache->get(filePath, temp)) - { - return temp; - } - if (!m_failed.contains(filePath)) - { - ((FilterModel *)this)->thumbnailImage(filePath); - } - return (m_thumbnailCache->get("placeholder")); - } - return sourceModel()->data(mapToSource(proxyIndex), role); - } - virtual bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) - { - auto model = sourceModel(); - if (!model) - return false; - if (role != Qt::EditRole) - return false; - // FIXME: this is a workaround for a bug in QFileSystemModel, where it doesn't - // sort after renames - { - ((QFileSystemModel *)model)->setNameFilterDisables(true); - ((QFileSystemModel *)model)->setNameFilterDisables(false); - } - return model->setData(mapToSource(index), value.toString() + ".png", role); - } - -private: - void thumbnailImage(QString path) - { - auto runnable = new ThumbnailRunnable(path, m_thumbnailCache); - connect(&(runnable->m_resultEmitter), SIGNAL(resultsReady(QString)), - SLOT(thumbnailReady(QString))); - connect(&(runnable->m_resultEmitter), SIGNAL(resultsFailed(QString)), - SLOT(thumbnailFailed(QString))); - ((QThreadPool &)m_thumbnailingPool).start(runnable); - } -private slots: - void thumbnailReady(QString path) { emit layoutChanged(); } - void thumbnailFailed(QString path) { m_failed.insert(path); } - void fileChanged(QString filepath) - { - m_thumbnailCache->setStale(filepath); - thumbnailImage(filepath); - // reinsert the path... - watcher.removePath(filepath); - watcher.addPath(filepath); - } - -private: - SharedIconCachePtr m_thumbnailCache; - QThreadPool m_thumbnailingPool; - QSet m_failed; - QSet watched; - QFileSystemWatcher watcher; -}; - -class CenteredEditingDelegate : public QStyledItemDelegate -{ -public: - explicit CenteredEditingDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} - virtual ~CenteredEditingDelegate() {} - virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const - { - auto widget = QStyledItemDelegate::createEditor(parent, option, index); - auto foo = dynamic_cast(widget); - if (foo) - { - foo->setAlignment(Qt::AlignHCenter); - foo->setFrame(true); - foo->setMaximumWidth(192); - } - return widget; - } -}; - -ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent) - : QWidget(parent), ui(new Ui::ScreenshotsPage) -{ - m_model.reset(new QFileSystemModel()); - m_filterModel.reset(new FilterModel()); - m_filterModel->setSourceModel(m_model.get()); - m_model->setFilter(QDir::Files | QDir::Writable | QDir::Readable); - m_model->setReadOnly(false); - m_model->setNameFilters({"*.png"}); - m_model->setNameFilterDisables(false); - m_folder = path; - m_valid = FS::ensureFolderPathExists(m_folder); - - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - ui->listView->setIconSize(QSize(128, 128)); - ui->listView->setGridSize(QSize(192, 160)); - ui->listView->setSpacing(9); - // ui->listView->setUniformItemSizes(true); - ui->listView->setLayoutMode(QListView::Batched); - ui->listView->setViewMode(QListView::IconMode); - ui->listView->setResizeMode(QListView::Adjust); - ui->listView->installEventFilter(this); - ui->listView->setEditTriggers(0); - ui->listView->setItemDelegate(new CenteredEditingDelegate(this)); - connect(ui->listView, SIGNAL(activated(QModelIndex)), SLOT(onItemActivated(QModelIndex))); -} - -bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt) -{ - if (obj != ui->listView) - return QWidget::eventFilter(obj, evt); - if (evt->type() != QEvent::KeyPress) - { - return QWidget::eventFilter(obj, evt); - } - QKeyEvent *keyEvent = static_cast(evt); - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_deleteBtn_clicked(); - return true; - case Qt::Key_F2: - on_renameBtn_clicked(); - return true; - default: - break; - } - return QWidget::eventFilter(obj, evt); -} - -ScreenshotsPage::~ScreenshotsPage() -{ - delete ui; -} - -void ScreenshotsPage::onItemActivated(QModelIndex index) -{ - if (!index.isValid()) - return; - auto info = m_model->fileInfo(index); - QString fileName = info.absoluteFilePath(); - DesktopServices::openFile(info.absoluteFilePath()); -} - -void ScreenshotsPage::on_viewFolderBtn_clicked() -{ - DesktopServices::openDirectory(m_folder, true); -} - -void ScreenshotsPage::on_uploadBtn_clicked() -{ - auto selection = ui->listView->selectionModel()->selectedRows(); - if (selection.isEmpty()) - return; - - QList uploaded; - auto job = NetJobPtr(new NetJob("Screenshot Upload")); - for (auto item : selection) - { - auto info = m_model->fileInfo(item); - auto screenshot = std::make_shared(info); - uploaded.push_back(screenshot); - job->addNetAction(ImgurUpload::make(screenshot)); - } - SequentialTask task; - auto albumTask = NetJobPtr(new NetJob("Imgur Album Creation")); - auto imgurAlbum = ImgurAlbumCreation::make(uploaded); - albumTask->addNetAction(imgurAlbum); - task.addTask(job.unwrap()); - task.addTask(albumTask.unwrap()); - m_uploadActive = true; - ProgressDialog prog(this); - if (prog.execWithTask(&task) != QDialog::Accepted) - { - CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), - tr("Unknown error"), QMessageBox::Warning)->exec(); - } - else - { - auto link = QString("https://imgur.com/a/%1").arg(imgurAlbum->id()); - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(link); - CustomMessageBox::selectable( - this, - tr("Upload finished"), - tr("The link to the uploaded album has been placed in your clipboard.") .arg(link), - QMessageBox::Information - )->exec(); - } - m_uploadActive = false; -} - -void ScreenshotsPage::on_deleteBtn_clicked() -{ - auto mbox = CustomMessageBox::selectable( - this, tr("Are you sure?"), tr("This will delete all selected screenshots."), - QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No); - std::unique_ptr box(mbox); - - if (box->exec() != QMessageBox::Yes) - return; - - auto selected = ui->listView->selectionModel()->selectedIndexes(); - for (auto item : selected) - { - m_model->remove(item); - } -} - -void ScreenshotsPage::on_renameBtn_clicked() -{ - auto selection = ui->listView->selectionModel()->selectedIndexes(); - if (selection.isEmpty()) - return; - ui->listView->edit(selection[0]); - // TODO: mass renaming -} - -void ScreenshotsPage::opened() -{ - if(!m_valid) - { - m_valid = FS::ensureFolderPathExists(m_folder); - } - if (m_valid) - { - QString path = QDir(m_folder).absolutePath(); - auto idx = m_model->setRootPath(path); - if(idx.isValid()) - { - ui->listView->setModel(m_filterModel.get()); - ui->listView->setRootIndex(m_filterModel->mapFromSource(idx)); - } - else - { - ui->listView->setModel(nullptr); - } - } -} - -#include "ScreenshotsPage.moc" diff --git a/application/pages/ScreenshotsPage.h b/application/pages/ScreenshotsPage.h deleted file mode 100644 index c3ccbdee..00000000 --- a/application/pages/ScreenshotsPage.h +++ /dev/null @@ -1,84 +0,0 @@ -/* 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 "BasePage.h" -#include - -class QFileSystemModel; -class QIdentityProxyModel; -namespace Ui -{ -class ScreenshotsPage; -} - -struct ScreenShot; -class ScreenshotList; -class ImgurAlbumCreation; - -class ScreenshotsPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit ScreenshotsPage(QString path, QWidget *parent = 0); - virtual ~ScreenshotsPage(); - - virtual void opened() override; - - enum - { - NothingDone = 0x42 - }; - - virtual bool eventFilter(QObject *, QEvent *) override; - virtual QString displayName() const override - { - return tr("Screenshots"); - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon("screenshots"); - } - virtual QString id() const override - { - return "screenshots"; - } - virtual QString helpPage() const override - { - return "Screenshots-management"; - } - virtual bool apply() override - { - return !m_uploadActive; - } -private slots: - void on_uploadBtn_clicked(); - void on_deleteBtn_clicked(); - void on_renameBtn_clicked(); - void on_viewFolderBtn_clicked(); - void onItemActivated(QModelIndex); - -private: - Ui::ScreenshotsPage *ui; - std::shared_ptr m_model; - std::shared_ptr m_filterModel; - QString m_folder; - bool m_valid = false; - bool m_uploadActive = false; -}; diff --git a/application/pages/ScreenshotsPage.ui b/application/pages/ScreenshotsPage.ui deleted file mode 100644 index d05c4384..00000000 --- a/application/pages/ScreenshotsPage.ui +++ /dev/null @@ -1,106 +0,0 @@ - - - ScreenshotsPage - - - - 0 - 0 - 723 - 532 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::SelectRows - - - - - - - - - &Upload - - - - - - - &Delete - - - - - - - &Rename - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - - listView - uploadBtn - deleteBtn - renameBtn - viewFolderBtn - - - - diff --git a/application/pages/TexturePackPage.h b/application/pages/TexturePackPage.h deleted file mode 100644 index b03614f0..00000000 --- a/application/pages/TexturePackPage.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "ModFolderPage.h" -#include "ui_ModFolderPage.h" - -class TexturePackPage : public ModFolderPage -{ -public: - explicit TexturePackPage(MinecraftInstance *instance, QWidget *parent = 0) - : ModFolderPage(instance, instance->texturePackList(), "texturepacks", "resourcepacks", - tr("Texture packs"), "Texture-packs", parent) - { - ui->configFolderBtn->setHidden(true); - } - virtual ~TexturePackPage() {} - virtual bool shouldDisplay() const override - { - return m_inst->traits().contains("texturepacks"); - } -}; diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp deleted file mode 100644 index 00ae0a7e..00000000 --- a/application/pages/VersionPage.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/* 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. - */ - -#include "MultiMC.h" - -#include -#include -#include - -#include "VersionPage.h" -#include "ui_VersionPage.h" - -#include "dialogs/CustomMessageBox.h" -#include "dialogs/VersionSelectDialog.h" -#include "dialogs/NewComponentDialog.h" -#include "dialogs/ModEditDialogCommon.h" - -#include "dialogs/ProgressDialog.h" -#include - -#include -#include -#include -#include -#include - -#include "minecraft/ComponentList.h" -#include "minecraft/auth/MojangAccountList.h" -#include "minecraft/Mod.h" -#include "icons/IconList.h" -#include "Exception.h" - -#include "MultiMC.h" - -#include -#include - -class IconProxy : public QIdentityProxyModel -{ - Q_OBJECT -public: - - IconProxy(QWidget *parentWidget) : QIdentityProxyModel(parentWidget) - { - connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone); - m_parentWidget = parentWidget; - } - - virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override - { - QVariant var = QIdentityProxyModel::data(mapToSource(proxyIndex), role); - int column = proxyIndex.column(); - if(column == 0 && role == Qt::DecorationRole && m_parentWidget) - { - if(!var.isNull()) - { - auto string = var.toString(); - if(string == "warning") - { - return MMC->getThemedIcon("status-yellow"); - } - else if(string == "error") - { - return MMC->getThemedIcon("status-bad"); - } - } - return MMC->getThemedIcon("status-good"); - } - return var; - } -private slots: - void widgetGone() - { - m_parentWidget = nullptr; - } - -private: - QWidget *m_parentWidget = nullptr; -}; - -QIcon VersionPage::icon() const -{ - return MMC->icons()->getIcon(m_inst->iconKey()); -} -bool VersionPage::shouldDisplay() const -{ - return !m_inst->isRunning(); -} - -VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) - : QWidget(parent), ui(new Ui::VersionPage), m_inst(inst) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - m_profile = m_inst->getComponentList(); - - reloadComponentList(); - - if (m_profile) - { - auto proxy = new IconProxy(ui->packageView); - proxy->setSourceModel(m_profile.get()); - ui->packageView->setModel(proxy); - ui->packageView->installEventFilter(this); - ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection); - connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent); - auto smodel = ui->packageView->selectionModel(); - connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent); - updateVersionControls(); - // select first item. - preselect(0); - } - else - { - disableVersionControls(); - } - connect(m_inst, &MinecraftInstance::versionReloaded, this, - &VersionPage::updateVersionControls); -} - -VersionPage::~VersionPage() -{ - delete ui; -} - -void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous) -{ - if (!current.isValid()) - { - ui->frame->clear(); - return; - } - int row = current.row(); - auto patch = m_profile->getComponent(row); - auto severity = patch->getProblemSeverity(); - switch(severity) - { - case ProblemSeverity::Warning: - ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName())); - break; - case ProblemSeverity::Error: - ui->frame->setModText(tr("%1 has issues!").arg(patch->getName())); - break; - default: - case ProblemSeverity::None: - ui->frame->clear(); - return; - } - - auto &problems = patch->getProblems(); - QString problemOut; - for (auto &problem: problems) - { - if(problem.m_severity == ProblemSeverity::Error) - { - problemOut += tr("Error: "); - } - else if(problem.m_severity == ProblemSeverity::Warning) - { - problemOut += tr("Warning: "); - } - problemOut += problem.m_description; - problemOut += "\n"; - } - ui->frame->setModDescription(problemOut); -} - - -void VersionPage::updateVersionControls() -{ - ui->forgeBtn->setEnabled(true); - ui->liteloaderBtn->setEnabled(true); - updateButtons(); -} - -void VersionPage::disableVersionControls() -{ - ui->forgeBtn->setEnabled(false); - ui->liteloaderBtn->setEnabled(false); - ui->reloadBtn->setEnabled(false); - updateButtons(); -} - -bool VersionPage::reloadComponentList() -{ - try - { - m_profile->reload(Net::Mode::Online); - return true; - } - catch (Exception &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - return false; - } - catch (...) - { - QMessageBox::critical( - this, tr("Error"), - tr("Couldn't load the instance profile.")); - return false; - } -} - -void VersionPage::on_reloadBtn_clicked() -{ - reloadComponentList(); - m_container->refreshContainer(); -} - -void VersionPage::on_removeBtn_clicked() -{ - if (ui->packageView->currentIndex().isValid()) - { - // FIXME: use actual model, not reloading. - if (!m_profile->remove(ui->packageView->currentIndex().row())) - { - QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); - } - } - updateButtons(); - reloadComponentList(); - m_container->refreshContainer(); -} - -void VersionPage::on_modBtn_clicked() -{ - if(m_container) - { - m_container->selectPage("mods"); - } -} - -void VersionPage::on_jarmodBtn_clicked() -{ - auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget()); - if(!list.empty()) - { - m_profile->installJarMods(list); - } - updateButtons(); -} - -void VersionPage::on_jarBtn_clicked() -{ - auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget()); - if(!jarPath.isEmpty()) - { - m_profile->installCustomJar(jarPath); - } - updateButtons(); -} - -void VersionPage::on_moveUpBtn_clicked() -{ - try - { - m_profile->move(currentRow(), ComponentList::MoveUp); - } - catch (Exception &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - } - updateButtons(); -} - -void VersionPage::on_moveDownBtn_clicked() -{ - try - { - m_profile->move(currentRow(), ComponentList::MoveDown); - } - catch (Exception &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - } - updateButtons(); -} - -void VersionPage::on_changeVersionBtn_clicked() -{ - auto versionRow = currentRow(); - if(versionRow == -1) - { - return; - } - auto patch = m_profile->getComponent(versionRow); - auto name = patch->getName(); - auto list = patch->getVersionList(); - if(!list) - { - return; - } - auto uid = list->uid(); - // FIXME: this is a horrible HACK. Get version filtering information from the actual metadata... - if(uid == "net.minecraftforge") - { - on_forgeBtn_clicked(); - return; - } - else if (uid == "com.mumfrey.liteloader") - { - on_liteloaderBtn_clicked(); - return; - } - VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this); - auto currentVersion = patch->getVersion(); - if(!currentVersion.isEmpty()) - { - vselect.setCurrentVersion(currentVersion); - } - if (!vselect.exec() || !vselect.selectedVersion()) - return; - - qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor(); - bool important = false; - if(uid == "net.minecraft") - { - important = true; - } - m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important); - m_profile->resolve(Net::Mode::Online); - m_container->refreshContainer(); -} - -void VersionPage::on_downloadBtn_clicked() -{ - if (!MMC->accounts()->anyAccountIsValid()) - { - CustomMessageBox::selectable( - this, tr("Error"), - tr("MultiMC cannot download Minecraft or update instances unless you have at least " - "one account added.\nPlease add your Mojang or Minecraft account."), - QMessageBox::Warning)->show(); - return; - } - - auto updateTask = m_inst->createUpdateTask(Net::Mode::Online); - if (!updateTask) - { - return; - } - ProgressDialog tDialog(this); - connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); - // FIXME: unused return value - tDialog.execWithTask(updateTask.get()); - updateButtons(); - m_container->refreshContainer(); -} - -void VersionPage::on_forgeBtn_clicked() -{ - auto vlist = ENV.metadataIndex()->get("net.minecraftforge"); - if(!vlist) - { - return; - } - VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this); - vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); - vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); - vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!")); - - auto currentVersion = m_profile->getComponentVersion("net.minecraftforge"); - if(!currentVersion.isEmpty()) - { - vselect.setCurrentVersion(currentVersion); - } - - if (vselect.exec() && vselect.selectedVersion()) - { - auto vsn = vselect.selectedVersion(); - m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor()); - m_profile->resolve(Net::Mode::Online); - // m_profile->installVersion(); - preselect(m_profile->rowCount(QModelIndex())-1); - m_container->refreshContainer(); - } -} - -void VersionPage::on_addEmptyBtn_clicked() -{ - NewComponentDialog compdialog(QString(), QString(), this); - QStringList blacklist; - for(int i = 0; i < m_profile->rowCount(); i++) - { - auto comp = m_profile->getComponent(i); - blacklist.push_back(comp->getID()); - } - compdialog.setBlacklist(blacklist); - if (compdialog.exec()) - { - qDebug() << "name:" << compdialog.name(); - qDebug() << "uid:" << compdialog.uid(); - m_profile->installEmpty(compdialog.uid(), compdialog.name()); - } -} - -void VersionPage::on_liteloaderBtn_clicked() -{ - auto vlist = ENV.metadataIndex()->get("com.mumfrey.liteloader"); - if(!vlist) - { - return; - } - VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this); - vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); - vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); - vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!")); - - auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader"); - if(!currentVersion.isEmpty()) - { - vselect.setCurrentVersion(currentVersion); - } - - if (vselect.exec() && vselect.selectedVersion()) - { - auto vsn = vselect.selectedVersion(); - m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor()); - m_profile->resolve(Net::Mode::Online); - // m_profile->installVersion(vselect.selectedVersion()); - preselect(m_profile->rowCount(QModelIndex())-1); - m_container->refreshContainer(); - } -} - -void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous) -{ - currentIdx = current.row(); - updateButtons(currentIdx); -} - -void VersionPage::preselect(int row) -{ - if(row < 0) - { - row = 0; - } - if(row >= m_profile->rowCount(QModelIndex())) - { - row = m_profile->rowCount(QModelIndex()) - 1; - } - if(row < 0) - { - return; - } - auto model_index = m_profile->index(row); - ui->packageView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); - updateButtons(row); -} - -void VersionPage::updateButtons(int row) -{ - if(row == -1) - row = currentRow(); - auto patch = m_profile->getComponent(row); - if (!patch) - { - ui->removeBtn->setDisabled(true); - ui->moveDownBtn->setDisabled(true); - ui->moveUpBtn->setDisabled(true); - ui->changeVersionBtn->setDisabled(true); - ui->editBtn->setDisabled(true); - ui->customizeBtn->setDisabled(true); - ui->revertBtn->setDisabled(true); - } - else - { - ui->removeBtn->setEnabled(patch->isRemovable()); - ui->moveDownBtn->setEnabled(patch->isMoveable()); - ui->moveUpBtn->setEnabled(patch->isMoveable()); - ui->changeVersionBtn->setEnabled(patch->isVersionChangeable()); - ui->editBtn->setEnabled(patch->isCustom()); - ui->customizeBtn->setEnabled(patch->isCustomizable()); - ui->revertBtn->setEnabled(patch->isRevertible()); - } -} - -void VersionPage::onGameUpdateError(QString error) -{ - CustomMessageBox::selectable(this, tr("Error updating instance"), error, - QMessageBox::Warning)->show(); -} - -Component * VersionPage::current() -{ - auto row = currentRow(); - if(row < 0) - { - return nullptr; - } - return m_profile->getComponent(row); -} - -int VersionPage::currentRow() -{ - if (ui->packageView->selectionModel()->selectedRows().isEmpty()) - { - return -1; - } - return ui->packageView->selectionModel()->selectedRows().first().row(); -} - -void VersionPage::on_customizeBtn_clicked() -{ - auto version = currentRow(); - if(version == -1) - { - return; - } - auto patch = m_profile->getComponent(version); - if(!patch->getVersionFile()) - { - // TODO: wait for the update task to finish here... - return; - } - if(!m_profile->customize(version)) - { - // TODO: some error box here - } - updateButtons(); - preselect(currentIdx); -} - -void VersionPage::on_editBtn_clicked() -{ - auto version = current(); - if(!version) - { - return; - } - auto filename = version->getFilename(); - if(!QFileInfo::exists(filename)) - { - qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!"; - return; - } - MMC->openJsonEditor(filename); -} - -void VersionPage::on_revertBtn_clicked() -{ - auto version = currentRow(); - if(version == -1) - { - return; - } - if(!m_profile->revertToBase(version)) - { - // TODO: some error box here - } - updateButtons(); - preselect(currentIdx); - m_container->refreshContainer(); -} - -#include "VersionPage.moc" - diff --git a/application/pages/VersionPage.h b/application/pages/VersionPage.h deleted file mode 100644 index 49620c56..00000000 --- a/application/pages/VersionPage.h +++ /dev/null @@ -1,95 +0,0 @@ -/* 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 "minecraft/MinecraftInstance.h" -#include "minecraft/ComponentList.h" -#include "BasePage.h" - -namespace Ui -{ -class VersionPage; -} - -class VersionPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit VersionPage(MinecraftInstance *inst, QWidget *parent = 0); - virtual ~VersionPage(); - virtual QString displayName() const override - { - return tr("Version"); - } - virtual QIcon icon() const override; - virtual QString id() const override - { - return "version"; - } - virtual QString helpPage() const override - { - return "Instance-Version"; - } - virtual bool shouldDisplay() const override; - -private slots: - void on_forgeBtn_clicked(); - void on_addEmptyBtn_clicked(); - void on_liteloaderBtn_clicked(); - void on_reloadBtn_clicked(); - void on_removeBtn_clicked(); - void on_moveUpBtn_clicked(); - void on_moveDownBtn_clicked(); - void on_jarmodBtn_clicked(); - void on_jarBtn_clicked(); - void on_revertBtn_clicked(); - void on_editBtn_clicked(); - void on_modBtn_clicked(); - void on_customizeBtn_clicked(); - void on_downloadBtn_clicked(); - - void updateVersionControls(); - void disableVersionControls(); - void on_changeVersionBtn_clicked(); - -private: - Component * current(); - int currentRow(); - void updateButtons(int row = -1); - void preselect(int row = 0); - int doUpdate(); - -protected: - /// FIXME: this shouldn't be necessary! - bool reloadComponentList(); - -private: - Ui::VersionPage *ui; - std::shared_ptr m_profile; - MinecraftInstance *m_inst; - int currentIdx = 0; - -public slots: - void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); - -private slots: - void onGameUpdateError(QString error); - void packageCurrent(const QModelIndex ¤t, const QModelIndex &previous); - -}; diff --git a/application/pages/VersionPage.ui b/application/pages/VersionPage.ui deleted file mode 100644 index d54dd840..00000000 --- a/application/pages/VersionPage.ui +++ /dev/null @@ -1,318 +0,0 @@ - - - VersionPage - - - - 0 - 0 - 870 - 1008 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - false - - - true - - - - - - - - - Selection - - - Qt::AlignCenter - - - - - - - Change version of the selected package. - - - Change version - - - - - - - Make the selected package apply sooner. - - - Move up - - - - - - - Make the selected package apply later. - - - Move down - - - - - - - Remove selected package from the instance. - - - Remove - - - - - - - - - - Edit - - - Qt::AlignCenter - - - - - - - Customize selected package. - - - Customize - - - - - - - Edit selected package. - - - Edit - - - - - - - Revert the selected package to default. - - - Revert - - - - - - - - - - Install - - - Qt::AlignCenter - - - - - - - Install the Minecraft Forge package. - - - Install Forge - - - - - - - Install the LiteLoader package. - - - Install LiteLoader - - - - - - - Install normal mods. - - - Install mods - - - - - - - - - - Advanced - - - Qt::AlignCenter - - - - - - - Add a mod into the Minecraft jar file. - - - Add to Minecraft.jar - - - - - - - Replace Minecraft.jar - - - - - - - Add Empty - - - - - - - Reload all packages. - - - Reload - - - - - - - Download the files needed to launch the instance now. - - - Download All - - - - - - - Qt::Vertical - - - - 111 - 13 - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - - ModListView - QTreeView -
widgets/ModListView.h
-
- - LineSeparator - QWidget -
widgets/LineSeparator.h
- 1 -
- - MCModInfoFrame - QFrame -
widgets/MCModInfoFrame.h
- 1 -
-
- - packageView - changeVersionBtn - moveUpBtn - moveDownBtn - removeBtn - customizeBtn - editBtn - revertBtn - forgeBtn - liteloaderBtn - modBtn - jarmodBtn - jarBtn - addEmptyBtn - reloadBtn - downloadBtn - tabWidget - - - -
diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp deleted file mode 100644 index 56a7e791..00000000 --- a/application/pages/WorldListPage.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* Copyright 2015-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. - */ - -#include "WorldListPage.h" -#include "ui_WorldListPage.h" -#include "minecraft/WorldList.h" -#include -#include "dialogs/ModEditDialogCommon.h" -#include -#include -#include -#include -#include -#include -#include - -#include "MultiMC.h" -#include -#include -#include - -WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, - QString iconName, QString displayName, QString helpPage, - QWidget *parent) - : QWidget(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds), m_iconName(iconName), m_id(id), m_displayName(displayName), m_helpName(helpPage) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this); - proxy->setSortCaseSensitivity(Qt::CaseInsensitive); - proxy->setSourceModel(m_worlds.get()); - ui->worldTreeView->setSortingEnabled(true); - ui->worldTreeView->setModel(proxy); - ui->worldTreeView->installEventFilter(this); - - auto head = ui->worldTreeView->header(); - - head->setSectionResizeMode(0, QHeaderView::Stretch); - head->setSectionResizeMode(1, QHeaderView::ResizeToContents); - connect(ui->worldTreeView->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, - SLOT(worldChanged(const QModelIndex &, const QModelIndex &))); - worldChanged(QModelIndex(), QModelIndex()); -} - -void WorldListPage::opened() -{ - m_worlds->startWatching(); -} - -void WorldListPage::closed() -{ - m_worlds->stopWatching(); -} - -WorldListPage::~WorldListPage() -{ - m_worlds->stopWatching(); - delete ui; -} - -bool WorldListPage::shouldDisplay() const -{ - return true; -} - -bool WorldListPage::worldListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmWorldBtn_clicked(); - return true; - default: - break; - } - return QWidget::eventFilter(ui->worldTreeView, keyEvent); -} - -bool WorldListPage::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QWidget::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->worldTreeView) - return worldListFilter(keyEvent); - return QWidget::eventFilter(obj, ev); -} - -void WorldListPage::on_rmWorldBtn_clicked() -{ - auto proxiedIndex = getSelectedWorld(); - - if(!proxiedIndex.isValid()) - return; - - auto result = QMessageBox::question(this, - tr("Are you sure?"), - tr("This will remove the selected world permenantly.\n" - "The world will be gone forever (A LONG TIME).\n" - "\n" - "Do you want to continue?")); - if(result != QMessageBox::Yes) - { - return; - } - m_worlds->stopWatching(); - m_worlds->deleteWorld(proxiedIndex.row()); - m_worlds->startWatching(); -} - -void WorldListPage::on_viewFolderBtn_clicked() -{ - DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true); -} - -QModelIndex WorldListPage::getSelectedWorld() -{ - auto index = ui->worldTreeView->selectionModel()->currentIndex(); - - auto proxy = (QSortFilterProxyModel *) ui->worldTreeView->model(); - return proxy->mapToSource(index); -} - -void WorldListPage::on_copySeedBtn_clicked() -{ - QModelIndex index = getSelectedWorld(); - - if (!index.isValid()) - { - return; - } - int64_t seed = m_worlds->data(index, WorldList::SeedRole).toLongLong(); - MMC->clipboard()->setText(QString::number(seed)); -} - -void WorldListPage::on_mcEditBtn_clicked() -{ - if(m_mceditStarting) - return; - - auto mcedit = MMC->mcedit(); - - const QString mceditPath = mcedit->path(); - - QModelIndex index = getSelectedWorld(); - - if (!index.isValid()) - { - return; - } - - if(!worldSafetyNagQuestion()) - return; - - auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString(); - - auto program = mcedit->getProgramPath(); - if(program.size()) - { -#ifdef Q_OS_WIN32 - if(!QProcess::startDetached(program, {fullPath}, mceditPath)) - { - mceditError(); - } -#else - m_mceditProcess.reset(new LoggedProcess()); - m_mceditProcess->setDetachable(true); - connect(m_mceditProcess.get(), &LoggedProcess::stateChanged, this, &WorldListPage::mceditState); - m_mceditProcess->start(program, {fullPath}); - m_mceditProcess->setWorkingDirectory(mceditPath); - m_mceditStarting = true; -#endif - } - else - { - QMessageBox::warning( - this->parentWidget(), - tr("No MCEdit found or set up!"), - tr("You do not have MCEdit set up or it was moved.\nYou can set it up in the global settings.") - ); - } -} - -void WorldListPage::mceditError() -{ - QMessageBox::warning( - this->parentWidget(), - tr("MCEdit failed to start!"), - tr("MCEdit failed to start.\nIt may be necessary to reinstall it.") - ); -} - -void WorldListPage::mceditState(LoggedProcess::State state) -{ - bool failed = false; - switch(state) - { - case LoggedProcess::NotRunning: - case LoggedProcess::Starting: - return; - case LoggedProcess::FailedToStart: - case LoggedProcess::Crashed: - case LoggedProcess::Aborted: - { - failed = true; - } - case LoggedProcess::Running: - case LoggedProcess::Finished: - { - m_mceditStarting = false; - break; - } - } - if(failed) - { - mceditError(); - } -} - -void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &previous) -{ - QModelIndex index = getSelectedWorld(); - bool enable = index.isValid(); - ui->copySeedBtn->setEnabled(enable); - ui->mcEditBtn->setEnabled(enable); - ui->rmWorldBtn->setEnabled(enable); - ui->copyBtn->setEnabled(enable); - ui->renameBtn->setEnabled(enable); -} - -void WorldListPage::on_addBtn_clicked() -{ - auto list = GuiUtil::BrowseForFiles( - m_helpName, - tr("Select a Minecraft world zip"), - tr("Minecraft World Zip File (*.zip)"), QString(), this->parentWidget()); - if (!list.empty()) - { - m_worlds->stopWatching(); - for (auto filename : list) - { - m_worlds->installWorld(QFileInfo(filename)); - } - m_worlds->startWatching(); - } -} - -bool WorldListPage::isWorldSafe(QModelIndex) -{ - return !m_inst->isRunning(); -} - -bool WorldListPage::worldSafetyNagQuestion() -{ - if(!isWorldSafe(getSelectedWorld())) - { - auto result = QMessageBox::question(this, tr("Copy World"), tr("Changing a world while Minecraft is running is potentially unsafe.\nDo you wish to proceed?")); - if(result == QMessageBox::No) - { - return false; - } - } - return true; -} - - -void WorldListPage::on_copyBtn_clicked() -{ - QModelIndex index = getSelectedWorld(); - if (!index.isValid()) - { - return; - } - - if(!worldSafetyNagQuestion()) - return; - - auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); - auto world = (World *) worldVariant.value(); - bool ok = false; - QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new name for the copy."), QLineEdit::Normal, world->name(), &ok); - - if (ok && name.length() > 0) - { - world->install(m_worlds->dir().absolutePath(), name); - } -} - -void WorldListPage::on_renameBtn_clicked() -{ - QModelIndex index = getSelectedWorld(); - if (!index.isValid()) - { - return; - } - - if(!worldSafetyNagQuestion()) - return; - - auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); - auto world = (World *) worldVariant.value(); - - bool ok = false; - QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new world name."), QLineEdit::Normal, world->name(), &ok); - - if (ok && name.length() > 0) - { - world->rename(name); - } -} - -void WorldListPage::on_refreshBtn_clicked() -{ - m_worlds->update(); -} diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h deleted file mode 100644 index d0aa6150..00000000 --- a/application/pages/WorldListPage.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2015-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 "minecraft/MinecraftInstance.h" -#include "BasePage.h" -#include -#include - -class WorldList; -namespace Ui -{ -class WorldListPage; -} - -class WorldListPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, - QString iconName, QString displayName, QString helpPage = "", - QWidget *parent = 0); - virtual ~WorldListPage(); - - virtual QString displayName() const override - { - return m_displayName; - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon(m_iconName); - } - virtual QString id() const override - { - return m_id; - } - virtual QString helpPage() const override - { - return m_helpName; - } - virtual bool shouldDisplay() const override; - - virtual void opened() override; - virtual void closed() override; - -protected: - bool eventFilter(QObject *obj, QEvent *ev) override; - bool worldListFilter(QKeyEvent *ev); - -protected: - BaseInstance *m_inst; - -private: - QModelIndex getSelectedWorld(); - bool isWorldSafe(QModelIndex index); - bool worldSafetyNagQuestion(); - void mceditError(); - -private: - Ui::WorldListPage *ui; - std::shared_ptr m_worlds; - unique_qobject_ptr m_mceditProcess; - bool m_mceditStarting = false; - QString m_iconName; - QString m_id; - QString m_displayName; - QString m_helpName; - -private slots: - void on_copySeedBtn_clicked(); - void on_mcEditBtn_clicked(); - void on_rmWorldBtn_clicked(); - void on_addBtn_clicked(); - void on_copyBtn_clicked(); - void on_renameBtn_clicked(); - void on_refreshBtn_clicked(); - void on_viewFolderBtn_clicked(); - void worldChanged(const QModelIndex ¤t, const QModelIndex &previous); - void mceditState(LoggedProcess::State state); -}; diff --git a/application/pages/WorldListPage.ui b/application/pages/WorldListPage.ui deleted file mode 100644 index 0018ddf3..00000000 --- a/application/pages/WorldListPage.ui +++ /dev/null @@ -1,168 +0,0 @@ - - - WorldListPage - - - - 0 - 0 - 723 - 532 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - - - Add - - - - - - - - - - Rename - - - - - - - Copy - - - - - - - &Remove - - - - - - - MCEdit - - - - - - - - - - Copy Seed - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Refresh - - - - - - - &View Folder - - - - - - - - - - 0 - 0 - - - - true - - - QAbstractItemView::DragDrop - - - true - - - true - - - false - - - - - - - - - - - - LineSeparator - QWidget -
widgets/LineSeparator.h
- 1 -
-
- - tabWidget - worldTreeView - addBtn - renameBtn - copyBtn - rmWorldBtn - mcEditBtn - copySeedBtn - refreshBtn - viewFolderBtn - - - -
diff --git a/application/pages/global/PackagesPage.cpp b/application/pages/global/PackagesPage.cpp index 5fd4934c..7cf1e3f5 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 2afbcf8e..ad155d9e 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/instance/InstanceSettingsPage.cpp b/application/pages/instance/InstanceSettingsPage.cpp new file mode 100644 index 00000000..71e90a32 --- /dev/null +++ b/application/pages/instance/InstanceSettingsPage.cpp @@ -0,0 +1,251 @@ +#include "InstanceSettingsPage.h" +#include "ui_InstanceSettingsPage.h" + +#include +#include +#include + +#include "dialogs/VersionSelectDialog.h" +#include "JavaCommon.h" +#include "MultiMC.h" + +#include +#include +#include +#include + +InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) + : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst) +{ + m_settings = inst->settings(); + ui->setupUi(this); + auto sysMB = Sys::getSystemRam() / Sys::megabyte; + ui->maxMemSpinBox->setMaximum(sysMB); + loadSettings(); +} + +bool InstanceSettingsPage::shouldDisplay() const +{ + return !m_instance->isRunning(); +} + +InstanceSettingsPage::~InstanceSettingsPage() +{ + delete ui; +} + +bool InstanceSettingsPage::apply() +{ + applySettings(); + return true; +} + +void InstanceSettingsPage::applySettings() +{ + SettingsObject::Lock lock(m_settings); + + // Console + bool console = ui->consoleSettingsBox->isChecked(); + m_settings->set("OverrideConsole", console); + if (console) + { + m_settings->set("ShowConsole", ui->showConsoleCheck->isChecked()); + m_settings->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); + m_settings->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked()); + } + else + { + m_settings->reset("ShowConsole"); + m_settings->reset("AutoCloseConsole"); + m_settings->reset("ShowConsoleOnError"); + } + + // Window Size + bool window = ui->windowSizeGroupBox->isChecked(); + m_settings->set("OverrideWindow", window); + if (window) + { + m_settings->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); + m_settings->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); + m_settings->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); + } + else + { + m_settings->reset("LaunchMaximized"); + m_settings->reset("MinecraftWinWidth"); + m_settings->reset("MinecraftWinHeight"); + } + + // Memory + bool memory = ui->memoryGroupBox->isChecked(); + m_settings->set("OverrideMemory", memory); + if (memory) + { + int min = ui->minMemSpinBox->value(); + int max = ui->maxMemSpinBox->value(); + if(min < max) + { + m_settings->set("MinMemAlloc", min); + m_settings->set("MaxMemAlloc", max); + } + else + { + m_settings->set("MinMemAlloc", max); + m_settings->set("MaxMemAlloc", min); + } + m_settings->set("PermGen", ui->permGenSpinBox->value()); + } + else + { + m_settings->reset("MinMemAlloc"); + m_settings->reset("MaxMemAlloc"); + m_settings->reset("PermGen"); + } + + // Java Install Settings + bool javaInstall = ui->javaSettingsGroupBox->isChecked(); + m_settings->set("OverrideJavaLocation", javaInstall); + if (javaInstall) + { + m_settings->set("JavaPath", ui->javaPathTextBox->text()); + } + else + { + m_settings->reset("JavaPath"); + } + + // Java arguments + bool javaArgs = ui->javaArgumentsGroupBox->isChecked(); + m_settings->set("OverrideJavaArgs", javaArgs); + if(javaArgs) + { + m_settings->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " ")); + JavaCommon::checkJVMArgs(m_settings->get("JvmArgs").toString(), this->parentWidget()); + } + else + { + m_settings->reset("JvmArgs"); + } + + // old generic 'override both' is removed. + m_settings->reset("OverrideJava"); + + // Custom Commands + bool custcmd = ui->customCommands->checked(); + m_settings->set("OverrideCommands", custcmd); + if (custcmd) + { + m_settings->set("PreLaunchCommand", ui->customCommands->prelaunchCommand()); + m_settings->set("WrapperCommand", ui->customCommands->wrapperCommand()); + m_settings->set("PostExitCommand", ui->customCommands->postexitCommand()); + } + else + { + m_settings->reset("PreLaunchCommand"); + m_settings->reset("WrapperCommand"); + m_settings->reset("PostExitCommand"); + } +} + +void InstanceSettingsPage::loadSettings() +{ + // Console + ui->consoleSettingsBox->setChecked(m_settings->get("OverrideConsole").toBool()); + ui->showConsoleCheck->setChecked(m_settings->get("ShowConsole").toBool()); + ui->autoCloseConsoleCheck->setChecked(m_settings->get("AutoCloseConsole").toBool()); + ui->showConsoleErrorCheck->setChecked(m_settings->get("ShowConsoleOnError").toBool()); + + // Window Size + ui->windowSizeGroupBox->setChecked(m_settings->get("OverrideWindow").toBool()); + ui->maximizedCheckBox->setChecked(m_settings->get("LaunchMaximized").toBool()); + ui->windowWidthSpinBox->setValue(m_settings->get("MinecraftWinWidth").toInt()); + ui->windowHeightSpinBox->setValue(m_settings->get("MinecraftWinHeight").toInt()); + + // Memory + ui->memoryGroupBox->setChecked(m_settings->get("OverrideMemory").toBool()); + int min = m_settings->get("MinMemAlloc").toInt(); + int max = m_settings->get("MaxMemAlloc").toInt(); + if(min < max) + { + ui->minMemSpinBox->setValue(min); + ui->maxMemSpinBox->setValue(max); + } + else + { + ui->minMemSpinBox->setValue(max); + ui->maxMemSpinBox->setValue(min); + } + ui->permGenSpinBox->setValue(m_settings->get("PermGen").toInt()); + + // Java Settings + bool overrideJava = m_settings->get("OverrideJava").toBool(); + bool overrideLocation = m_settings->get("OverrideJavaLocation").toBool() || overrideJava; + bool overrideArgs = m_settings->get("OverrideJavaArgs").toBool() || overrideJava; + + ui->javaSettingsGroupBox->setChecked(overrideLocation); + ui->javaPathTextBox->setText(m_settings->get("JavaPath").toString()); + + ui->javaArgumentsGroupBox->setChecked(overrideArgs); + ui->jvmArgsTextBox->setPlainText(m_settings->get("JvmArgs").toString()); + + // Custom commands + ui->customCommands->initialize( + true, + m_settings->get("OverrideCommands").toBool(), + m_settings->get("PreLaunchCommand").toString(), + m_settings->get("WrapperCommand").toString(), + m_settings->get("PostExitCommand").toString() + ); +} + +void InstanceSettingsPage::on_javaDetectBtn_clicked() +{ + JavaInstallPtr java; + + VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true); + vselect.setResizeOn(2); + vselect.exec(); + + if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) + { + java = std::dynamic_pointer_cast(vselect.selectedVersion()); + ui->javaPathTextBox->setText(java->path); + } +} + +void InstanceSettingsPage::on_javaBrowseBtn_clicked() +{ + QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); + + // do not allow current dir - it's dirty. Do not allow dirs that don't exist + if(raw_path.isEmpty()) + { + return; + } + QString cooked_path = FS::NormalizePath(raw_path); + + QFileInfo javaInfo(cooked_path);; + if(!javaInfo.exists() || !javaInfo.isExecutable()) + { + return; + } + ui->javaPathTextBox->setText(cooked_path); +} + +void InstanceSettingsPage::on_javaTestBtn_clicked() +{ + if(checker) + { + return; + } + checker.reset(new JavaCommon::TestCheck( + this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->toPlainText().replace("\n", " "), + ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value())); + connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished())); + checker->run(); +} + +void InstanceSettingsPage::checkerFinished() +{ + checker.reset(); +} diff --git a/application/pages/instance/InstanceSettingsPage.h b/application/pages/instance/InstanceSettingsPage.h new file mode 100644 index 00000000..c5d7d3b6 --- /dev/null +++ b/application/pages/instance/InstanceSettingsPage.h @@ -0,0 +1,74 @@ +/* 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 "java/JavaChecker.h" +#include "BaseInstance.h" +#include +#include "pages/BasePage.h" +#include "JavaCommon.h" +#include "MultiMC.h" + +class JavaChecker; +namespace Ui +{ +class InstanceSettingsPage; +} + +class InstanceSettingsPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit InstanceSettingsPage(BaseInstance *inst, QWidget *parent = 0); + virtual ~InstanceSettingsPage(); + virtual QString displayName() const override + { + return tr("Settings"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("instance-settings"); + } + virtual QString id() const override + { + return "settings"; + } + virtual bool apply() override; + virtual QString helpPage() const override + { + return "Instance-settings"; + } + virtual bool shouldDisplay() const override; + +private slots: + void on_javaDetectBtn_clicked(); + void on_javaTestBtn_clicked(); + void on_javaBrowseBtn_clicked(); + + void applySettings(); + void loadSettings(); + + void checkerFinished(); + +private: + Ui::InstanceSettingsPage *ui; + BaseInstance *m_instance; + SettingsObjectPtr m_settings; + unique_qobject_ptr checker; +}; diff --git a/application/pages/instance/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui new file mode 100644 index 00000000..0c180df3 --- /dev/null +++ b/application/pages/instance/InstanceSettingsPage.ui @@ -0,0 +1,393 @@ + + + InstanceSettingsPage + + + + 0 + 0 + 553 + 522 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QTabWidget::Rounded + + + 0 + + + + Java + + + + + + true + + + Java insta&llation + + + true + + + false + + + + + + + + + Auto-detect... + + + + + + + Browse... + + + + + + + Test + + + + + + + + + + true + + + Memor&y + + + true + + + false + + + + + + Minimum memory allocation: + + + + + + + The maximum amount of memory Minecraft is allowed to use. + + + MB + + + 128 + + + 65536 + + + 128 + + + 1024 + + + + + + + The amount of memory Minecraft is started with. + + + MB + + + 128 + + + 65536 + + + 128 + + + 256 + + + + + + + The amount of memory available to store loaded Java classes. + + + MB + + + 64 + + + 999999999 + + + 8 + + + 64 + + + + + + + PermGen: + + + + + + + Maximum memory allocation: + + + + + + + Note: Permgen is set automatically by Java 8 and later + + + + + + + + + + true + + + Java argumen&ts + + + true + + + false + + + + + + + + + + + + + Game windows + + + + + + true + + + Game Window + + + true + + + false + + + + + + Start Minecraft maximized? + + + + + + + + + Window height: + + + + + + + Window width: + + + + + + + 1 + + + 65536 + + + 1 + + + 854 + + + + + + + 1 + + + 65536 + + + 480 + + + + + + + + + + + + true + + + Conso&le Settings + + + true + + + false + + + + + + Show console while the game is running? + + + + + + + Automatically close console when the game quits? + + + + + + + Show console when the game crashes? + + + + + + + + + + Qt::Vertical + + + + 88 + 125 + + + + + + + + + Custom commands + + + + + + + + + + + + + + CustomCommands + QWidget +
widgets/CustomCommands.h
+ 1 +
+
+ + settingsTabs + javaSettingsGroupBox + javaPathTextBox + javaDetectBtn + javaBrowseBtn + javaTestBtn + memoryGroupBox + minMemSpinBox + maxMemSpinBox + permGenSpinBox + javaArgumentsGroupBox + jvmArgsTextBox + windowSizeGroupBox + maximizedCheckBox + windowWidthSpinBox + windowHeightSpinBox + consoleSettingsBox + showConsoleCheck + autoCloseConsoleCheck + showConsoleErrorCheck + + + +
diff --git a/application/pages/instance/LegacyUpgradePage.cpp b/application/pages/instance/LegacyUpgradePage.cpp new file mode 100644 index 00000000..f808ab88 --- /dev/null +++ b/application/pages/instance/LegacyUpgradePage.cpp @@ -0,0 +1,50 @@ +#include "LegacyUpgradePage.h" +#include "ui_LegacyUpgradePage.h" + +#include "minecraft/legacy/LegacyInstance.h" +#include "minecraft/legacy/LegacyUpgradeTask.h" +#include "MultiMC.h" +#include "FolderInstanceProvider.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ProgressDialog.h" + +LegacyUpgradePage::LegacyUpgradePage(InstancePtr inst, QWidget *parent) + : QWidget(parent), ui(new Ui::LegacyUpgradePage), m_inst(inst) +{ + ui->setupUi(this); +} + +LegacyUpgradePage::~LegacyUpgradePage() +{ + delete ui; +} + +void LegacyUpgradePage::runModalTask(Task *task) +{ + connect(task, &Task::failed, [this](QString reason) + { + CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Warning)->show(); + }); + ProgressDialog loadDialog(this); + loadDialog.setSkipButton(true, tr("Abort")); + if(loadDialog.execWithTask(task) == QDialog::Accepted) + { + m_container->requestClose(); + } +} + +void LegacyUpgradePage::on_upgradeButton_clicked() +{ + 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()); +} + +bool LegacyUpgradePage::shouldDisplay() const +{ + return !m_inst->isRunning(); +} diff --git a/application/pages/instance/LegacyUpgradePage.h b/application/pages/instance/LegacyUpgradePage.h new file mode 100644 index 00000000..3e1abe93 --- /dev/null +++ b/application/pages/instance/LegacyUpgradePage.h @@ -0,0 +1,64 @@ +/* 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 "minecraft/legacy/LegacyInstance.h" +#include "pages/BasePage.h" +#include +#include "tasks/Task.h" + +namespace Ui +{ +class LegacyUpgradePage; +} + +class LegacyUpgradePage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit LegacyUpgradePage(InstancePtr inst, QWidget *parent = 0); + virtual ~LegacyUpgradePage(); + virtual QString displayName() const override + { + return tr("Upgrade"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("checkupdate"); + } + virtual QString id() const override + { + return "upgrade"; + } + virtual QString helpPage() const override + { + return "Legacy-upgrade"; + } + virtual bool shouldDisplay() const override; + +private slots: + void on_upgradeButton_clicked(); + +private: + void runModalTask(Task *task); + +private: + Ui::LegacyUpgradePage *ui; + InstancePtr m_inst; +}; diff --git a/application/pages/instance/LegacyUpgradePage.ui b/application/pages/instance/LegacyUpgradePage.ui new file mode 100644 index 00000000..a94ee039 --- /dev/null +++ b/application/pages/instance/LegacyUpgradePage.ui @@ -0,0 +1,47 @@ + + + LegacyUpgradePage + + + + 0 + 0 + 546 + 405 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + <html><body><h1>Upgrade is required</h1><p>MultiMC now supports old Minecraft versions and all the required features in the new (OneSix) instance format. As a consequence, the old (Legacy) format has been entirely disabled and old instances need to be upgraded.</p><p>The upgrade will create a new instance with the same contents as the current one, in the new format. The original instance will remain untouched, in case anything goes wrong in the process.</p><p>Please report any issues on our <a href="https://github.com/MultiMC/MultiMC5/issues">github issues page</a>.</p><p>There is also a <a href="https://discord.gg/GtPmv93">discord channel for testing here</a>.</p></body></html> + + + true + + + + + + + Upgrade the instance + + + + + + + + diff --git a/application/pages/instance/LogPage.cpp b/application/pages/instance/LogPage.cpp new file mode 100644 index 00000000..0fa1ee67 --- /dev/null +++ b/application/pages/instance/LogPage.cpp @@ -0,0 +1,312 @@ +#include "LogPage.h" +#include "ui_LogPage.h" + +#include "MultiMC.h" + +#include +#include +#include + +#include "launch/LaunchTask.h" +#include +#include "GuiUtil.h" +#include + +class LogFormatProxyModel : public QIdentityProxyModel +{ +public: + LogFormatProxyModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) + { + } + QVariant data(const QModelIndex &index, int role) const override + { + switch(role) + { + case Qt::FontRole: + return m_font; + case Qt::TextColorRole: + { + MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); + return m_colors->getFront(level); + } + case Qt::BackgroundRole: + { + MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); + return m_colors->getBack(level); + } + default: + return QIdentityProxyModel::data(index, role); + } + } + + void setFont(QFont font) + { + m_font = font; + } + + void setColors(LogColorCache* colors) + { + m_colors.reset(colors); + } + + QModelIndex find(const QModelIndex &start, const QString &value, bool reverse) const + { + QModelIndex parentIndex = parent(start); + auto compare = [&](int r) -> QModelIndex + { + QModelIndex idx = index(r, start.column(), parentIndex); + if (!idx.isValid() || idx == start) + { + return QModelIndex(); + } + QVariant v = data(idx, Qt::DisplayRole); + QString t = v.toString(); + if (t.contains(value, Qt::CaseInsensitive)) + return idx; + return QModelIndex(); + }; + if(reverse) + { + int from = start.row(); + int to = 0; + + for (int i = 0; i < 2; ++i) + { + for (int r = from; (r >= to); --r) + { + auto idx = compare(r); + if(idx.isValid()) + return idx; + } + // prepare for the next iteration + from = rowCount() - 1; + to = start.row(); + } + } + else + { + int from = start.row(); + int to = rowCount(parentIndex); + + for (int i = 0; i < 2; ++i) + { + for (int r = from; (r < to); ++r) + { + auto idx = compare(r); + if(idx.isValid()) + return idx; + } + // prepare for the next iteration + from = 0; + to = start.row(); + } + } + return QModelIndex(); + } +private: + QFont m_font; + std::unique_ptr m_colors; +}; + +LogPage::LogPage(InstancePtr instance, QWidget *parent) + : QWidget(parent), ui(new Ui::LogPage), m_instance(instance) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + + m_proxy = new LogFormatProxyModel(this); + // set up text colors in the log proxy and adapt them to the current theme foreground and background + { + auto origForeground = ui->text->palette().color(ui->text->foregroundRole()); + auto origBackground = ui->text->palette().color(ui->text->backgroundRole()); + m_proxy->setColors(new LogColorCache(origForeground, origBackground)); + } + + // set up fonts in the log proxy + { + QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); + bool conversionOk = false; + int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk); + if(!conversionOk) + { + fontSize = 11; + } + m_proxy->setFont(QFont(fontFamily, fontSize)); + } + + ui->text->setModel(m_proxy); + + // set up instance and launch process recognition + { + auto launchTask = m_instance->getLaunchTask(); + if(launchTask) + { + setInstanceLaunchTaskChanged(launchTask, true); + } + connect(m_instance.get(), &BaseInstance::launchTaskChanged, this, &LogPage::onInstanceLaunchTaskChanged); + } + + auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); + connect(findShortcut, SIGNAL(activated()), SLOT(findActivated())); + auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this); + connect(findNextShortcut, SIGNAL(activated()), SLOT(findNextActivated())); + connect(ui->searchBar, SIGNAL(returnPressed()), SLOT(on_findButton_clicked())); + auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this); + connect(findPreviousShortcut, SIGNAL(activated()), SLOT(findPreviousActivated())); +} + +LogPage::~LogPage() +{ + delete ui; +} + +void LogPage::modelStateToUI() +{ + if(m_model->wrapLines()) + { + ui->text->setWordWrap(true); + ui->wrapCheckbox->setCheckState(Qt::Checked); + } + else + { + ui->text->setWordWrap(false); + ui->wrapCheckbox->setCheckState(Qt::Unchecked); + } + if(m_model->suspended()) + { + ui->trackLogCheckbox->setCheckState(Qt::Unchecked); + } + else + { + ui->trackLogCheckbox->setCheckState(Qt::Checked); + } +} + +void LogPage::UIToModelState() +{ + if(!m_model) + { + return; + } + m_model->setLineWrap(ui->wrapCheckbox->checkState() == Qt::Checked); + m_model->suspend(ui->trackLogCheckbox->checkState() != Qt::Checked); +} + +void LogPage::setInstanceLaunchTaskChanged(std::shared_ptr proc, bool initial) +{ + m_process = proc; + if(m_process) + { + m_model = proc->getLogModel(); + m_proxy->setSourceModel(m_model.get()); + if(initial) + { + modelStateToUI(); + } + else + { + UIToModelState(); + } + } + else + { + m_proxy->setSourceModel(nullptr); + m_model.reset(); + } +} + +void LogPage::onInstanceLaunchTaskChanged(std::shared_ptr proc) +{ + setInstanceLaunchTaskChanged(proc, false); +} + +bool LogPage::apply() +{ + return true; +} + +bool LogPage::shouldDisplay() const +{ + return m_instance->isRunning() || m_proxy->rowCount() > 0; +} + +void LogPage::on_btnPaste_clicked() +{ + if(!m_model) + return; + + //FIXME: turn this into a proper task and move the upload logic out of GuiUtil! + m_model->append(MessageLevel::MultiMC, tr("MultiMC: Log upload triggered at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date))); + auto url = GuiUtil::uploadPaste(m_model->toPlainText(), this); + if(!url.isEmpty()) + { + m_model->append(MessageLevel::MultiMC, tr("MultiMC: Log uploaded to: %1").arg(url)); + } + else + { + m_model->append(MessageLevel::Error, tr("MultiMC: Log upload failed!")); + } +} + +void LogPage::on_btnCopy_clicked() +{ + if(!m_model) + return; + m_model->append(MessageLevel::MultiMC, QString("Clipboard copy at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date))); + GuiUtil::setClipboardText(m_model->toPlainText()); +} + +void LogPage::on_btnClear_clicked() +{ + if(!m_model) + return; + m_model->clear(); + m_container->refreshContainer(); +} + +void LogPage::on_btnBottom_clicked() +{ + ui->text->scrollToBottom(); +} + +void LogPage::on_trackLogCheckbox_clicked(bool checked) +{ + if(!m_model) + return; + m_model->suspend(!checked); +} + +void LogPage::on_wrapCheckbox_clicked(bool checked) +{ + ui->text->setWordWrap(checked); + if(!m_model) + return; + m_model->setLineWrap(checked); +} + +void LogPage::on_findButton_clicked() +{ + auto modifiers = QApplication::keyboardModifiers(); + bool reverse = modifiers & Qt::ShiftModifier; + ui->text->findNext(ui->searchBar->text(), reverse); +} + +void LogPage::findNextActivated() +{ + ui->text->findNext(ui->searchBar->text(), false); +} + +void LogPage::findPreviousActivated() +{ + ui->text->findNext(ui->searchBar->text(), true); +} + +void LogPage::findActivated() +{ + // focus the search bar if it doesn't have focus + if (!ui->searchBar->hasFocus()) + { + ui->searchBar->setFocus(); + ui->searchBar->selectAll(); + } +} diff --git a/application/pages/instance/LogPage.h b/application/pages/instance/LogPage.h new file mode 100644 index 00000000..2229418d --- /dev/null +++ b/application/pages/instance/LogPage.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 "BaseInstance.h" +#include "launch/LaunchTask.h" +#include "pages/BasePage.h" +#include + +namespace Ui +{ +class LogPage; +} +class QTextCharFormat; +class LogFormatProxyModel; + +class LogPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit LogPage(InstancePtr instance, QWidget *parent = 0); + virtual ~LogPage(); + virtual QString displayName() const override + { + return tr("Minecraft Log"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("log"); + } + virtual QString id() const override + { + return "console"; + } + virtual bool apply() override; + virtual QString helpPage() const override + { + return "Minecraft-Logs"; + } + virtual bool shouldDisplay() const override; + +private slots: + void on_btnPaste_clicked(); + void on_btnCopy_clicked(); + void on_btnClear_clicked(); + void on_btnBottom_clicked(); + + void on_trackLogCheckbox_clicked(bool checked); + void on_wrapCheckbox_clicked(bool checked); + + void on_findButton_clicked(); + void findActivated(); + void findNextActivated(); + void findPreviousActivated(); + + void onInstanceLaunchTaskChanged(std::shared_ptr proc); + +private: + void modelStateToUI(); + void UIToModelState(); + void setInstanceLaunchTaskChanged(std::shared_ptr proc, bool initial); + +private: + Ui::LogPage *ui; + InstancePtr m_instance; + std::shared_ptr m_process; + + LogFormatProxyModel * m_proxy; + shared_qobject_ptr m_model; +}; diff --git a/application/pages/instance/LogPage.ui b/application/pages/instance/LogPage.ui new file mode 100644 index 00000000..4843d7c3 --- /dev/null +++ b/application/pages/instance/LogPage.ui @@ -0,0 +1,182 @@ + + + LogPage + + + + 0 + 0 + 825 + 782 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + false + + + true + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + false + + + + + + + + + Keep updating + + + true + + + + + + + Wrap lines + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Copy the whole log into the clipboard + + + &Copy + + + + + + + Upload the log to paste.ee - it will stay online for a month + + + Upload + + + + + + + Clear the log + + + Clear + + + + + + + + + Search: + + + + + + + Find + + + + + + + + + + Scroll all the way to bottom + + + Bottom + + + + + + + Qt::Vertical + + + + + + + + + + + + LogView + QPlainTextEdit +
widgets/LogView.h
+
+
+ + tabWidget + trackLogCheckbox + wrapCheckbox + btnCopy + btnPaste + btnClear + text + searchBar + findButton + + + +
diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp new file mode 100644 index 00000000..90155df3 --- /dev/null +++ b/application/pages/instance/ModFolderPage.cpp @@ -0,0 +1,210 @@ +/* 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. + */ + +#include "ModFolderPage.h" +#include "ui_ModFolderPage.h" + +#include +#include +#include +#include + +#include "MultiMC.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ModEditDialogCommon.h" +#include +#include "minecraft/ModList.h" +#include "minecraft/Mod.h" +#include "minecraft/VersionFilterData.h" +#include "minecraft/ComponentList.h" +#include + +ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, + QString iconName, QString displayName, QString helpPage, + QWidget *parent) + : QWidget(parent), ui(new Ui::ModFolderPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + m_inst = inst; + m_mods = mods; + m_id = id; + m_displayName = displayName; + m_iconName = iconName; + m_helpName = helpPage; + m_fileSelectionFilter = "%1 (*.zip *.jar)"; + m_filterModel = new QSortFilterProxyModel(this); + m_filterModel->setDynamicSortFilter(true); + m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive); + m_filterModel->setSourceModel(m_mods.get()); + m_filterModel->setFilterKeyColumn(-1); + ui->modTreeView->setModel(m_filterModel); + ui->modTreeView->installEventFilter(this); + ui->modTreeView->sortByColumn(1, Qt::AscendingOrder); + auto smodel = ui->modTreeView->selectionModel(); + connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent); + connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged ); +} + +void ModFolderPage::openedImpl() +{ + m_mods->startWatching(); +} + +void ModFolderPage::closedImpl() +{ + m_mods->stopWatching(); +} + +void ModFolderPage::on_filterTextChanged(const QString& newContents) +{ + m_viewFilter = newContents; + m_filterModel->setFilterFixedString(m_viewFilter); +} + + +CoreModFolderPage::CoreModFolderPage(BaseInstance *inst, std::shared_ptr mods, + QString id, QString iconName, QString displayName, + QString helpPage, QWidget *parent) + : ModFolderPage(inst, mods, id, iconName, displayName, helpPage, parent) +{ +} + +ModFolderPage::~ModFolderPage() +{ + m_mods->stopWatching(); + delete ui; +} + +bool ModFolderPage::shouldDisplay() const +{ + if (m_inst) + return !m_inst->isRunning(); + return true; +} + +bool CoreModFolderPage::shouldDisplay() const +{ + if (ModFolderPage::shouldDisplay()) + { + auto inst = dynamic_cast(m_inst); + if (!inst) + return true; + auto version = inst->getComponentList(); + if (!version) + return true; + if(!version->getComponent("net.minecraftforge")) + { + return false; + } + if(!version->getComponent("net.minecraft")) + { + return false; + } + if(version->getComponent("net.minecraft")->getReleaseDateTime() < g_VersionFilterData.legacyCutoffDate) + { + return true; + } + } + return false; +} + +bool ModFolderPage::modListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmModBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addModBtn_clicked(); + return true; + default: + break; + } + return QWidget::eventFilter(ui->modTreeView, keyEvent); +} + +bool ModFolderPage::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QWidget::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->modTreeView) + return modListFilter(keyEvent); + return QWidget::eventFilter(obj, ev); +} + +void ModFolderPage::on_addModBtn_clicked() +{ + auto list = GuiUtil::BrowseForFiles( + m_helpName, + tr("Select %1", + "Select whatever type of files the page contains. Example: 'Loader Mods'") + .arg(m_displayName), + m_fileSelectionFilter.arg(m_displayName), MMC->settings()->get("CentralModsDir").toString(), + this->parentWidget()); + if (!list.empty()) + { + for (auto filename : list) + { + m_mods->installMod(filename); + } + } +} + +void ModFolderPage::on_enableModBtn_clicked() +{ + auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); + m_mods->enableMods(selection.indexes(), true); +} + +void ModFolderPage::on_disableModBtn_clicked() +{ + auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); + m_mods->enableMods(selection.indexes(), false); +} + +void ModFolderPage::on_rmModBtn_clicked() +{ + auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); + m_mods->deleteMods(selection.indexes()); +} + +void ModFolderPage::on_configFolderBtn_clicked() +{ + DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true); +} + +void ModFolderPage::on_viewModBtn_clicked() +{ + DesktopServices::openDirectory(m_mods->dir().absolutePath(), true); +} + +void ModFolderPage::modCurrent(const QModelIndex ¤t, const QModelIndex &previous) +{ + if (!current.isValid()) + { + ui->frame->clear(); + return; + } + auto sourceCurrent = m_filterModel->mapToSource(current); + int row = sourceCurrent.row(); + Mod &m = m_mods->operator[](row); + ui->frame->updateWithMod(m); +} diff --git a/application/pages/instance/ModFolderPage.h b/application/pages/instance/ModFolderPage.h new file mode 100644 index 00000000..15e728cb --- /dev/null +++ b/application/pages/instance/ModFolderPage.h @@ -0,0 +1,108 @@ +/* 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 "minecraft/MinecraftInstance.h" +#include "pages/BasePage.h" +#include + +class ModList; +namespace Ui +{ +class ModFolderPage; +} + +class ModFolderPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit ModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, + QString iconName, QString displayName, QString helpPage = "", + QWidget *parent = 0); + virtual ~ModFolderPage(); + + void setFilter(const QString & filter) + { + m_fileSelectionFilter = filter; + } + + virtual QString displayName() const override + { + return m_displayName; + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon(m_iconName); + } + virtual QString id() const override + { + return m_id; + } + virtual QString helpPage() const override + { + return m_helpName; + } + virtual bool shouldDisplay() const override; + + virtual void openedImpl() override; + virtual void closedImpl() override; +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; + bool modListFilter(QKeyEvent *ev); + +protected: + BaseInstance *m_inst; + +protected: + Ui::ModFolderPage *ui; + std::shared_ptr m_mods; + QSortFilterProxyModel *m_filterModel; + QString m_iconName; + QString m_id; + QString m_displayName; + QString m_helpName; + QString m_fileSelectionFilter; + QString m_viewFilter; + +public +slots: + void modCurrent(const QModelIndex ¤t, const QModelIndex &previous); + +private +slots: + void on_filterTextChanged(const QString & newContents); + void on_addModBtn_clicked(); + void on_rmModBtn_clicked(); + void on_viewModBtn_clicked(); + void on_enableModBtn_clicked(); + void on_disableModBtn_clicked(); + void on_configFolderBtn_clicked(); +}; + +class CoreModFolderPage : public ModFolderPage +{ +public: + explicit CoreModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, + QString iconName, QString displayName, QString helpPage = "", + QWidget *parent = 0); + virtual ~CoreModFolderPage() + { + } + virtual bool shouldDisplay() const; +}; diff --git a/application/pages/instance/ModFolderPage.ui b/application/pages/instance/ModFolderPage.ui new file mode 100644 index 00000000..b5597bdc --- /dev/null +++ b/application/pages/instance/ModFolderPage.ui @@ -0,0 +1,180 @@ + + + ModFolderPage + + + + 0 + 0 + 723 + 532 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + 0 + 0 + + + + Tab 1 + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Enable + + + + + + + Disable + + + + + + + Open the 'config' folder in the system file manager. + + + View configs + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + 0 + 0 + + + + + + + + + + true + + + + + + + Filter: + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + + + + + + ModListView + QTreeView +
widgets/ModListView.h
+
+ + MCModInfoFrame + QFrame +
widgets/MCModInfoFrame.h
+ 1 +
+
+ + tabWidget + modTreeView + filterEdit + addModBtn + rmModBtn + enableModBtn + disableModBtn + configFolderBtn + viewModBtn + + + +
diff --git a/application/pages/instance/NotesPage.cpp b/application/pages/instance/NotesPage.cpp new file mode 100644 index 00000000..48bb468c --- /dev/null +++ b/application/pages/instance/NotesPage.cpp @@ -0,0 +1,21 @@ +#include "NotesPage.h" +#include "ui_NotesPage.h" + +NotesPage::NotesPage(BaseInstance *inst, QWidget *parent) + : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + ui->noteEditor->setText(m_inst->notes()); +} + +NotesPage::~NotesPage() +{ + delete ui; +} + +bool NotesPage::apply() +{ + m_inst->setNotes(ui->noteEditor->toPlainText()); + return true; +} diff --git a/application/pages/instance/NotesPage.h b/application/pages/instance/NotesPage.h new file mode 100644 index 00000000..4a25f9b1 --- /dev/null +++ b/application/pages/instance/NotesPage.h @@ -0,0 +1,60 @@ +/* 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 "BaseInstance.h" +#include "pages/BasePage.h" +#include + +namespace Ui +{ +class NotesPage; +} + +class NotesPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit NotesPage(BaseInstance *inst, QWidget *parent = 0); + virtual ~NotesPage(); + virtual QString displayName() const override + { + return tr("Notes"); + } + virtual QIcon icon() const override + { + auto icon = MMC->getThemedIcon("notes"); + if(icon.isNull()) + icon = MMC->getThemedIcon("news"); + return icon; + } + virtual QString id() const override + { + return "notes"; + } + virtual bool apply() override; + virtual QString helpPage() const override + { + return "Notes"; + } + +private: + Ui::NotesPage *ui; + BaseInstance *m_inst; +}; diff --git a/application/pages/instance/NotesPage.ui b/application/pages/instance/NotesPage.ui new file mode 100644 index 00000000..88cca92f --- /dev/null +++ b/application/pages/instance/NotesPage.ui @@ -0,0 +1,57 @@ + + + NotesPage + + + + 0 + 0 + 731 + 538 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + Qt::ScrollBarAlwaysOn + + + false + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + + diff --git a/application/pages/instance/OtherLogsPage.cpp b/application/pages/instance/OtherLogsPage.cpp new file mode 100644 index 00000000..10cb1145 --- /dev/null +++ b/application/pages/instance/OtherLogsPage.cpp @@ -0,0 +1,313 @@ +/* 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. + */ + +#include "OtherLogsPage.h" +#include "ui_OtherLogsPage.h" + +#include + +#include "GuiUtil.h" +#include "RecursiveFileSystemWatcher.h" +#include +#include +#include + +OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent) + : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), + m_watcher(new RecursiveFileSystemWatcher(this)) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + + m_watcher->setMatcher(fileFilter); + m_watcher->setRootDir(QDir::current().absoluteFilePath(m_path)); + + connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this, &OtherLogsPage::populateSelectLogBox); + populateSelectLogBox(); + + auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); + connect(findShortcut, &QShortcut::activated, this, &OtherLogsPage::findActivated); + + auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this); + connect(findNextShortcut, &QShortcut::activated, this, &OtherLogsPage::findNextActivated); + + auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this); + connect(findPreviousShortcut, &QShortcut::activated, this, &OtherLogsPage::findPreviousActivated); + + connect(ui->searchBar, &QLineEdit::returnPressed, this, &OtherLogsPage::on_findButton_clicked); +} + +OtherLogsPage::~OtherLogsPage() +{ + delete ui; +} + +void OtherLogsPage::openedImpl() +{ + m_watcher->enable(); +} +void OtherLogsPage::closedImpl() +{ + m_watcher->disable(); +} + +void OtherLogsPage::populateSelectLogBox() +{ + ui->selectLogBox->clear(); + ui->selectLogBox->addItems(m_watcher->files()); + if (m_currentFile.isEmpty()) + { + setControlsEnabled(false); + ui->selectLogBox->setCurrentIndex(-1); + } + else + { + const int index = ui->selectLogBox->findText(m_currentFile); + if (index != -1) + { + ui->selectLogBox->setCurrentIndex(index); + setControlsEnabled(true); + } + else + { + setControlsEnabled(false); + } + } +} + +void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index) +{ + QString file; + if (index != -1) + { + file = ui->selectLogBox->itemText(index); + } + + if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_path, file))) + { + m_currentFile = QString(); + ui->text->clear(); + setControlsEnabled(false); + } + else + { + m_currentFile = file; + on_btnReload_clicked(); + setControlsEnabled(true); + } +} + +void OtherLogsPage::on_btnReload_clicked() +{ + if(m_currentFile.isEmpty()) + { + setControlsEnabled(false); + return; + } + QFile file(FS::PathCombine(m_path, m_currentFile)); + if (!file.open(QFile::ReadOnly)) + { + setControlsEnabled(false); + ui->btnReload->setEnabled(true); // allow reload + m_currentFile = QString(); + QMessageBox::critical(this, tr("Error"), tr("Unable to open %1 for reading: %2") + .arg(m_currentFile, file.errorString())); + } + else + { + auto setPlainText = [&](const QString & text) + { + QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); + bool conversionOk = false; + int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk); + if(!conversionOk) + { + fontSize = 11; + } + QTextDocument *doc = ui->text->document(); + doc->setDefaultFont(QFont(fontFamily, fontSize)); + ui->text->setPlainText(text); + }; + auto showTooBig = [&]() + { + setPlainText( + tr("The file (%1) is too big. You may want to open it in a viewer optimized " + "for large files.").arg(file.fileName())); + }; + if(file.size() > (1024ll * 1024ll * 12ll)) + { + showTooBig(); + return; + } + QString content; + if(file.fileName().endsWith(".gz")) + { + QByteArray temp; + if(!GZip::unzip(file.readAll(), temp)) + { + setPlainText( + tr("The file (%1) is not readable.").arg(file.fileName())); + return; + } + content = QString::fromUtf8(temp); + } + else + { + content = QString::fromUtf8(file.readAll()); + } + if (content.size() >= 50000000ll) + { + showTooBig(); + return; + } + setPlainText(content); + } +} + +void OtherLogsPage::on_btnPaste_clicked() +{ + GuiUtil::uploadPaste(ui->text->toPlainText(), this); +} + +void OtherLogsPage::on_btnCopy_clicked() +{ + GuiUtil::setClipboardText(ui->text->toPlainText()); +} + +void OtherLogsPage::on_btnDelete_clicked() +{ + if(m_currentFile.isEmpty()) + { + setControlsEnabled(false); + return; + } + if (QMessageBox::question(this, tr("Delete"), + tr("Do you really want to delete %1?").arg(m_currentFile), + QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) + { + return; + } + QFile file(FS::PathCombine(m_path, m_currentFile)); + if (!file.remove()) + { + QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2") + .arg(m_currentFile, file.errorString())); + } +} + + + +void OtherLogsPage::on_btnClean_clicked() +{ + auto toDelete = m_watcher->files(); + if(toDelete.isEmpty()) + { + return; + } + QMessageBox *messageBox = new QMessageBox(this); + messageBox->setWindowTitle(tr("Clean up")); + if(toDelete.size() > 5) + { + messageBox->setText(tr("Do you really want to delete all log files?")); + messageBox->setDetailedText(toDelete.join('\n')); + } + else + { + messageBox->setText(tr("Do you really want to delete these files?\n%1").arg(toDelete.join('\n'))); + } + messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox->setDefaultButton(QMessageBox::Ok); + messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); + messageBox->setIcon(QMessageBox::Question); + messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction); + + if (messageBox->exec() != QMessageBox::Ok) + { + return; + } + QStringList failed; + for(auto item: toDelete) + { + QFile file(FS::PathCombine(m_path, item)); + if (!file.remove()) + { + failed.push_back(item); + } + } + if(!failed.empty()) + { + QMessageBox *messageBox = new QMessageBox(this); + messageBox->setWindowTitle(tr("Error")); + if(failed.size() > 5) + { + messageBox->setText(tr("Couldn't delete some files!")); + messageBox->setDetailedText(failed.join('\n')); + } + else + { + messageBox->setText(tr("Couldn't delete some files:\n%1").arg(failed.join('\n'))); + } + messageBox->setStandardButtons(QMessageBox::Ok); + messageBox->setDefaultButton(QMessageBox::Ok); + messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); + messageBox->setIcon(QMessageBox::Critical); + messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction); + messageBox->exec(); + } +} + + +void OtherLogsPage::setControlsEnabled(const bool enabled) +{ + ui->btnReload->setEnabled(enabled); + ui->btnDelete->setEnabled(enabled); + ui->btnCopy->setEnabled(enabled); + ui->btnPaste->setEnabled(enabled); + ui->text->setEnabled(enabled); + ui->btnClean->setEnabled(enabled); +} + +// FIXME: HACK, use LogView instead? +static void findNext(QPlainTextEdit * _this, const QString& what, bool reverse) +{ + _this->find(what, reverse ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0)); +} + +void OtherLogsPage::on_findButton_clicked() +{ + auto modifiers = QApplication::keyboardModifiers(); + bool reverse = modifiers & Qt::ShiftModifier; + findNext(ui->text, ui->searchBar->text(), reverse); +} + +void OtherLogsPage::findNextActivated() +{ + findNext(ui->text, ui->searchBar->text(), false); +} + +void OtherLogsPage::findPreviousActivated() +{ + findNext(ui->text, ui->searchBar->text(), true); +} + +void OtherLogsPage::findActivated() +{ + // focus the search bar if it doesn't have focus + if (!ui->searchBar->hasFocus()) + { + ui->searchBar->setFocus(); + ui->searchBar->selectAll(); + } +} diff --git a/application/pages/instance/OtherLogsPage.h b/application/pages/instance/OtherLogsPage.h new file mode 100644 index 00000000..ac01ef0a --- /dev/null +++ b/application/pages/instance/OtherLogsPage.h @@ -0,0 +1,81 @@ +/* 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 + +namespace Ui +{ +class OtherLogsPage; +} + +class RecursiveFileSystemWatcher; + +class OtherLogsPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent = 0); + ~OtherLogsPage(); + + QString id() const override + { + return "logs"; + } + QString displayName() const override + { + return tr("Other logs"); + } + QIcon icon() const override + { + return MMC->getThemedIcon("log"); + } + QString helpPage() const override + { + return "Minecraft-Logs"; + } + void openedImpl() override; + void closedImpl() override; + +private slots: + void populateSelectLogBox(); + void on_selectLogBox_currentIndexChanged(const int index); + void on_btnReload_clicked(); + void on_btnPaste_clicked(); + void on_btnCopy_clicked(); + void on_btnDelete_clicked(); + void on_btnClean_clicked(); + + void on_findButton_clicked(); + void findActivated(); + void findNextActivated(); + void findPreviousActivated(); + +private: + void setControlsEnabled(const bool enabled); + +private: + Ui::OtherLogsPage *ui; + QString m_path; + QString m_currentFile; + IPathMatcher::Ptr m_fileFilter; + RecursiveFileSystemWatcher *m_watcher; +}; diff --git a/application/pages/instance/OtherLogsPage.ui b/application/pages/instance/OtherLogsPage.ui new file mode 100644 index 00000000..56ff3b62 --- /dev/null +++ b/application/pages/instance/OtherLogsPage.ui @@ -0,0 +1,150 @@ + + + OtherLogsPage + + + + 0 + 0 + 657 + 538 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + + + + Find + + + + + + + false + + + Qt::ScrollBarAlwaysOn + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + Copy the whole log into the clipboard + + + &Copy + + + + + + + Clear the log + + + Delete + + + + + + + Upload the log to paste.ee - it will stay online for a month + + + Upload + + + + + + + Clear the log + + + Clean + + + + + + + Reload + + + + + + + + 0 + 0 + + + + + + + + + + Search: + + + + + + + + + + + tabWidget + selectLogBox + btnReload + btnCopy + btnPaste + btnDelete + btnClean + text + searchBar + findButton + + + + diff --git a/application/pages/instance/ResourcePackPage.h b/application/pages/instance/ResourcePackPage.h new file mode 100644 index 00000000..19dc78da --- /dev/null +++ b/application/pages/instance/ResourcePackPage.h @@ -0,0 +1,21 @@ +#pragma once +#include "ModFolderPage.h" +#include "ui_ModFolderPage.h" + +class ResourcePackPage : public ModFolderPage +{ +public: + explicit ResourcePackPage(MinecraftInstance *instance, QWidget *parent = 0) + : ModFolderPage(instance, instance->resourcePackList(), "resourcepacks", + "resourcepacks", tr("Resource packs"), "Resource-packs", parent) + { + ui->configFolderBtn->setHidden(true); + } + + virtual ~ResourcePackPage() {} + virtual bool shouldDisplay() const override + { + return !m_inst->traits().contains("no-texturepacks") && + !m_inst->traits().contains("texturepacks"); + } +}; diff --git a/application/pages/instance/ScreenshotsPage.cpp b/application/pages/instance/ScreenshotsPage.cpp new file mode 100644 index 00000000..71458386 --- /dev/null +++ b/application/pages/instance/ScreenshotsPage.cpp @@ -0,0 +1,372 @@ +#include "ScreenshotsPage.h" +#include "ui_ScreenshotsPage.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "dialogs/ProgressDialog.h" +#include "dialogs/CustomMessageBox.h" +#include "net/NetJob.h" +#include "screenshots/ImgurUpload.h" +#include "screenshots/ImgurAlbumCreation.h" +#include "tasks/SequentialTask.h" + +#include "RWStorage.h" +#include +#include + +typedef RWStorage SharedIconCache; +typedef std::shared_ptr SharedIconCachePtr; + +class ThumbnailingResult : public QObject +{ + Q_OBJECT +public slots: + inline void emitResultsReady(const QString &path) { emit resultsReady(path); } + inline void emitResultsFailed(const QString &path) { emit resultsFailed(path); } +signals: + void resultsReady(const QString &path); + void resultsFailed(const QString &path); +}; + +class ThumbnailRunnable : public QRunnable +{ +public: + ThumbnailRunnable(QString path, SharedIconCachePtr cache) + { + m_path = path; + m_cache = cache; + } + void run() + { + QFileInfo info(m_path); + if (info.isDir()) + return; + if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0)) + return; + int tries = 5; + while (tries) + { + if (!m_cache->stale(m_path)) + return; + QImage image(m_path); + if (image.isNull()) + { + QThread::msleep(500); + tries--; + continue; + } + QImage small; + if (image.width() > image.height()) + small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); + else + small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); + QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); + QImage square(QSize(256, 256), QImage::Format_ARGB32); + square.fill(Qt::transparent); + + QPainter painter(&square); + painter.drawImage(offset, small); + painter.end(); + + QIcon icon(QPixmap::fromImage(square)); + m_cache->add(m_path, icon); + m_resultEmitter.emitResultsReady(m_path); + return; + } + m_resultEmitter.emitResultsFailed(m_path); + } + QString m_path; + SharedIconCachePtr m_cache; + ThumbnailingResult m_resultEmitter; +}; + +// this is about as elegant and well written as a bag of bricks with scribbles done by insane +// asylum patients. +class FilterModel : public QIdentityProxyModel +{ + Q_OBJECT +public: + explicit FilterModel(QObject *parent = 0) : QIdentityProxyModel(parent) + { + m_thumbnailingPool.setMaxThreadCount(4); + m_thumbnailCache = std::make_shared(); + m_thumbnailCache->add("placeholder", MMC->getThemedIcon("screenshot-placeholder")); + connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); + // FIXME: the watched file set is not updated when files are removed + } + virtual ~FilterModel() { m_thumbnailingPool.waitForDone(500); } + virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const + { + auto model = sourceModel(); + if (!model) + return QVariant(); + if (role == Qt::DisplayRole || role == Qt::EditRole) + { + QVariant result = sourceModel()->data(mapToSource(proxyIndex), role); + return result.toString().remove(QRegExp("\\.png$")); + } + if (role == Qt::DecorationRole) + { + QVariant result = + sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole); + QString filePath = result.toString(); + QIcon temp; + if (!watched.contains(filePath)) + { + ((QFileSystemWatcher &)watcher).addPath(filePath); + ((QSet &)watched).insert(filePath); + } + if (m_thumbnailCache->get(filePath, temp)) + { + return temp; + } + if (!m_failed.contains(filePath)) + { + ((FilterModel *)this)->thumbnailImage(filePath); + } + return (m_thumbnailCache->get("placeholder")); + } + return sourceModel()->data(mapToSource(proxyIndex), role); + } + virtual bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole) + { + auto model = sourceModel(); + if (!model) + return false; + if (role != Qt::EditRole) + return false; + // FIXME: this is a workaround for a bug in QFileSystemModel, where it doesn't + // sort after renames + { + ((QFileSystemModel *)model)->setNameFilterDisables(true); + ((QFileSystemModel *)model)->setNameFilterDisables(false); + } + return model->setData(mapToSource(index), value.toString() + ".png", role); + } + +private: + void thumbnailImage(QString path) + { + auto runnable = new ThumbnailRunnable(path, m_thumbnailCache); + connect(&(runnable->m_resultEmitter), SIGNAL(resultsReady(QString)), + SLOT(thumbnailReady(QString))); + connect(&(runnable->m_resultEmitter), SIGNAL(resultsFailed(QString)), + SLOT(thumbnailFailed(QString))); + ((QThreadPool &)m_thumbnailingPool).start(runnable); + } +private slots: + void thumbnailReady(QString path) { emit layoutChanged(); } + void thumbnailFailed(QString path) { m_failed.insert(path); } + void fileChanged(QString filepath) + { + m_thumbnailCache->setStale(filepath); + thumbnailImage(filepath); + // reinsert the path... + watcher.removePath(filepath); + watcher.addPath(filepath); + } + +private: + SharedIconCachePtr m_thumbnailCache; + QThreadPool m_thumbnailingPool; + QSet m_failed; + QSet watched; + QFileSystemWatcher watcher; +}; + +class CenteredEditingDelegate : public QStyledItemDelegate +{ +public: + explicit CenteredEditingDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} + virtual ~CenteredEditingDelegate() {} + virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const + { + auto widget = QStyledItemDelegate::createEditor(parent, option, index); + auto foo = dynamic_cast(widget); + if (foo) + { + foo->setAlignment(Qt::AlignHCenter); + foo->setFrame(true); + foo->setMaximumWidth(192); + } + return widget; + } +}; + +ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent) + : QWidget(parent), ui(new Ui::ScreenshotsPage) +{ + m_model.reset(new QFileSystemModel()); + m_filterModel.reset(new FilterModel()); + m_filterModel->setSourceModel(m_model.get()); + m_model->setFilter(QDir::Files | QDir::Writable | QDir::Readable); + m_model->setReadOnly(false); + m_model->setNameFilters({"*.png"}); + m_model->setNameFilterDisables(false); + m_folder = path; + m_valid = FS::ensureFolderPathExists(m_folder); + + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + ui->listView->setIconSize(QSize(128, 128)); + ui->listView->setGridSize(QSize(192, 160)); + ui->listView->setSpacing(9); + // ui->listView->setUniformItemSizes(true); + ui->listView->setLayoutMode(QListView::Batched); + ui->listView->setViewMode(QListView::IconMode); + ui->listView->setResizeMode(QListView::Adjust); + ui->listView->installEventFilter(this); + ui->listView->setEditTriggers(0); + ui->listView->setItemDelegate(new CenteredEditingDelegate(this)); + connect(ui->listView, SIGNAL(activated(QModelIndex)), SLOT(onItemActivated(QModelIndex))); +} + +bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt) +{ + if (obj != ui->listView) + return QWidget::eventFilter(obj, evt); + if (evt->type() != QEvent::KeyPress) + { + return QWidget::eventFilter(obj, evt); + } + QKeyEvent *keyEvent = static_cast(evt); + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_deleteBtn_clicked(); + return true; + case Qt::Key_F2: + on_renameBtn_clicked(); + return true; + default: + break; + } + return QWidget::eventFilter(obj, evt); +} + +ScreenshotsPage::~ScreenshotsPage() +{ + delete ui; +} + +void ScreenshotsPage::onItemActivated(QModelIndex index) +{ + if (!index.isValid()) + return; + auto info = m_model->fileInfo(index); + QString fileName = info.absoluteFilePath(); + DesktopServices::openFile(info.absoluteFilePath()); +} + +void ScreenshotsPage::on_viewFolderBtn_clicked() +{ + DesktopServices::openDirectory(m_folder, true); +} + +void ScreenshotsPage::on_uploadBtn_clicked() +{ + auto selection = ui->listView->selectionModel()->selectedRows(); + if (selection.isEmpty()) + return; + + QList uploaded; + auto job = NetJobPtr(new NetJob("Screenshot Upload")); + for (auto item : selection) + { + auto info = m_model->fileInfo(item); + auto screenshot = std::make_shared(info); + uploaded.push_back(screenshot); + job->addNetAction(ImgurUpload::make(screenshot)); + } + SequentialTask task; + auto albumTask = NetJobPtr(new NetJob("Imgur Album Creation")); + auto imgurAlbum = ImgurAlbumCreation::make(uploaded); + albumTask->addNetAction(imgurAlbum); + task.addTask(job.unwrap()); + task.addTask(albumTask.unwrap()); + m_uploadActive = true; + ProgressDialog prog(this); + if (prog.execWithTask(&task) != QDialog::Accepted) + { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), + tr("Unknown error"), QMessageBox::Warning)->exec(); + } + else + { + auto link = QString("https://imgur.com/a/%1").arg(imgurAlbum->id()); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(link); + CustomMessageBox::selectable( + this, + tr("Upload finished"), + tr("The link to the uploaded album has been placed in your clipboard.") .arg(link), + QMessageBox::Information + )->exec(); + } + m_uploadActive = false; +} + +void ScreenshotsPage::on_deleteBtn_clicked() +{ + auto mbox = CustomMessageBox::selectable( + this, tr("Are you sure?"), tr("This will delete all selected screenshots."), + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No); + std::unique_ptr box(mbox); + + if (box->exec() != QMessageBox::Yes) + return; + + auto selected = ui->listView->selectionModel()->selectedIndexes(); + for (auto item : selected) + { + m_model->remove(item); + } +} + +void ScreenshotsPage::on_renameBtn_clicked() +{ + auto selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.isEmpty()) + return; + ui->listView->edit(selection[0]); + // TODO: mass renaming +} + +void ScreenshotsPage::openedImpl() +{ + if(!m_valid) + { + m_valid = FS::ensureFolderPathExists(m_folder); + } + if (m_valid) + { + QString path = QDir(m_folder).absolutePath(); + auto idx = m_model->setRootPath(path); + if(idx.isValid()) + { + ui->listView->setModel(m_filterModel.get()); + ui->listView->setRootIndex(m_filterModel->mapFromSource(idx)); + } + else + { + ui->listView->setModel(nullptr); + } + } +} + +#include "ScreenshotsPage.moc" diff --git a/application/pages/instance/ScreenshotsPage.h b/application/pages/instance/ScreenshotsPage.h new file mode 100644 index 00000000..e31fb8b4 --- /dev/null +++ b/application/pages/instance/ScreenshotsPage.h @@ -0,0 +1,84 @@ +/* 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 + +class QFileSystemModel; +class QIdentityProxyModel; +namespace Ui +{ +class ScreenshotsPage; +} + +struct ScreenShot; +class ScreenshotList; +class ImgurAlbumCreation; + +class ScreenshotsPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit ScreenshotsPage(QString path, QWidget *parent = 0); + virtual ~ScreenshotsPage(); + + virtual void openedImpl() override; + + enum + { + NothingDone = 0x42 + }; + + virtual bool eventFilter(QObject *, QEvent *) override; + virtual QString displayName() const override + { + return tr("Screenshots"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("screenshots"); + } + virtual QString id() const override + { + return "screenshots"; + } + virtual QString helpPage() const override + { + return "Screenshots-management"; + } + virtual bool apply() override + { + return !m_uploadActive; + } +private slots: + void on_uploadBtn_clicked(); + void on_deleteBtn_clicked(); + void on_renameBtn_clicked(); + void on_viewFolderBtn_clicked(); + void onItemActivated(QModelIndex); + +private: + Ui::ScreenshotsPage *ui; + std::shared_ptr m_model; + std::shared_ptr m_filterModel; + QString m_folder; + bool m_valid = false; + bool m_uploadActive = false; +}; diff --git a/application/pages/instance/ScreenshotsPage.ui b/application/pages/instance/ScreenshotsPage.ui new file mode 100644 index 00000000..d05c4384 --- /dev/null +++ b/application/pages/instance/ScreenshotsPage.ui @@ -0,0 +1,106 @@ + + + ScreenshotsPage + + + + 0 + 0 + 723 + 532 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectRows + + + + + + + + + &Upload + + + + + + + &Delete + + + + + + + &Rename + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + + listView + uploadBtn + deleteBtn + renameBtn + viewFolderBtn + + + + diff --git a/application/pages/instance/TexturePackPage.h b/application/pages/instance/TexturePackPage.h new file mode 100644 index 00000000..b03614f0 --- /dev/null +++ b/application/pages/instance/TexturePackPage.h @@ -0,0 +1,19 @@ +#pragma once +#include "ModFolderPage.h" +#include "ui_ModFolderPage.h" + +class TexturePackPage : public ModFolderPage +{ +public: + explicit TexturePackPage(MinecraftInstance *instance, QWidget *parent = 0) + : ModFolderPage(instance, instance->texturePackList(), "texturepacks", "resourcepacks", + tr("Texture packs"), "Texture-packs", parent) + { + ui->configFolderBtn->setHidden(true); + } + virtual ~TexturePackPage() {} + virtual bool shouldDisplay() const override + { + return m_inst->traits().contains("texturepacks"); + } +}; diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp new file mode 100644 index 00000000..00ae0a7e --- /dev/null +++ b/application/pages/instance/VersionPage.cpp @@ -0,0 +1,570 @@ +/* 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. + */ + +#include "MultiMC.h" + +#include +#include +#include + +#include "VersionPage.h" +#include "ui_VersionPage.h" + +#include "dialogs/CustomMessageBox.h" +#include "dialogs/VersionSelectDialog.h" +#include "dialogs/NewComponentDialog.h" +#include "dialogs/ModEditDialogCommon.h" + +#include "dialogs/ProgressDialog.h" +#include + +#include +#include +#include +#include +#include + +#include "minecraft/ComponentList.h" +#include "minecraft/auth/MojangAccountList.h" +#include "minecraft/Mod.h" +#include "icons/IconList.h" +#include "Exception.h" + +#include "MultiMC.h" + +#include +#include + +class IconProxy : public QIdentityProxyModel +{ + Q_OBJECT +public: + + IconProxy(QWidget *parentWidget) : QIdentityProxyModel(parentWidget) + { + connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone); + m_parentWidget = parentWidget; + } + + virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override + { + QVariant var = QIdentityProxyModel::data(mapToSource(proxyIndex), role); + int column = proxyIndex.column(); + if(column == 0 && role == Qt::DecorationRole && m_parentWidget) + { + if(!var.isNull()) + { + auto string = var.toString(); + if(string == "warning") + { + return MMC->getThemedIcon("status-yellow"); + } + else if(string == "error") + { + return MMC->getThemedIcon("status-bad"); + } + } + return MMC->getThemedIcon("status-good"); + } + return var; + } +private slots: + void widgetGone() + { + m_parentWidget = nullptr; + } + +private: + QWidget *m_parentWidget = nullptr; +}; + +QIcon VersionPage::icon() const +{ + return MMC->icons()->getIcon(m_inst->iconKey()); +} +bool VersionPage::shouldDisplay() const +{ + return !m_inst->isRunning(); +} + +VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) + : QWidget(parent), ui(new Ui::VersionPage), m_inst(inst) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + m_profile = m_inst->getComponentList(); + + reloadComponentList(); + + if (m_profile) + { + auto proxy = new IconProxy(ui->packageView); + proxy->setSourceModel(m_profile.get()); + ui->packageView->setModel(proxy); + ui->packageView->installEventFilter(this); + ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection); + connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent); + auto smodel = ui->packageView->selectionModel(); + connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent); + updateVersionControls(); + // select first item. + preselect(0); + } + else + { + disableVersionControls(); + } + connect(m_inst, &MinecraftInstance::versionReloaded, this, + &VersionPage::updateVersionControls); +} + +VersionPage::~VersionPage() +{ + delete ui; +} + +void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous) +{ + if (!current.isValid()) + { + ui->frame->clear(); + return; + } + int row = current.row(); + auto patch = m_profile->getComponent(row); + auto severity = patch->getProblemSeverity(); + switch(severity) + { + case ProblemSeverity::Warning: + ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName())); + break; + case ProblemSeverity::Error: + ui->frame->setModText(tr("%1 has issues!").arg(patch->getName())); + break; + default: + case ProblemSeverity::None: + ui->frame->clear(); + return; + } + + auto &problems = patch->getProblems(); + QString problemOut; + for (auto &problem: problems) + { + if(problem.m_severity == ProblemSeverity::Error) + { + problemOut += tr("Error: "); + } + else if(problem.m_severity == ProblemSeverity::Warning) + { + problemOut += tr("Warning: "); + } + problemOut += problem.m_description; + problemOut += "\n"; + } + ui->frame->setModDescription(problemOut); +} + + +void VersionPage::updateVersionControls() +{ + ui->forgeBtn->setEnabled(true); + ui->liteloaderBtn->setEnabled(true); + updateButtons(); +} + +void VersionPage::disableVersionControls() +{ + ui->forgeBtn->setEnabled(false); + ui->liteloaderBtn->setEnabled(false); + ui->reloadBtn->setEnabled(false); + updateButtons(); +} + +bool VersionPage::reloadComponentList() +{ + try + { + m_profile->reload(Net::Mode::Online); + return true; + } + catch (Exception &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + return false; + } + catch (...) + { + QMessageBox::critical( + this, tr("Error"), + tr("Couldn't load the instance profile.")); + return false; + } +} + +void VersionPage::on_reloadBtn_clicked() +{ + reloadComponentList(); + m_container->refreshContainer(); +} + +void VersionPage::on_removeBtn_clicked() +{ + if (ui->packageView->currentIndex().isValid()) + { + // FIXME: use actual model, not reloading. + if (!m_profile->remove(ui->packageView->currentIndex().row())) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); + } + } + updateButtons(); + reloadComponentList(); + m_container->refreshContainer(); +} + +void VersionPage::on_modBtn_clicked() +{ + if(m_container) + { + m_container->selectPage("mods"); + } +} + +void VersionPage::on_jarmodBtn_clicked() +{ + auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget()); + if(!list.empty()) + { + m_profile->installJarMods(list); + } + updateButtons(); +} + +void VersionPage::on_jarBtn_clicked() +{ + auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget()); + if(!jarPath.isEmpty()) + { + m_profile->installCustomJar(jarPath); + } + updateButtons(); +} + +void VersionPage::on_moveUpBtn_clicked() +{ + try + { + m_profile->move(currentRow(), ComponentList::MoveUp); + } + catch (Exception &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } + updateButtons(); +} + +void VersionPage::on_moveDownBtn_clicked() +{ + try + { + m_profile->move(currentRow(), ComponentList::MoveDown); + } + catch (Exception &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } + updateButtons(); +} + +void VersionPage::on_changeVersionBtn_clicked() +{ + auto versionRow = currentRow(); + if(versionRow == -1) + { + return; + } + auto patch = m_profile->getComponent(versionRow); + auto name = patch->getName(); + auto list = patch->getVersionList(); + if(!list) + { + return; + } + auto uid = list->uid(); + // FIXME: this is a horrible HACK. Get version filtering information from the actual metadata... + if(uid == "net.minecraftforge") + { + on_forgeBtn_clicked(); + return; + } + else if (uid == "com.mumfrey.liteloader") + { + on_liteloaderBtn_clicked(); + return; + } + VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this); + auto currentVersion = patch->getVersion(); + if(!currentVersion.isEmpty()) + { + vselect.setCurrentVersion(currentVersion); + } + if (!vselect.exec() || !vselect.selectedVersion()) + return; + + qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor(); + bool important = false; + if(uid == "net.minecraft") + { + important = true; + } + m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important); + m_profile->resolve(Net::Mode::Online); + m_container->refreshContainer(); +} + +void VersionPage::on_downloadBtn_clicked() +{ + if (!MMC->accounts()->anyAccountIsValid()) + { + CustomMessageBox::selectable( + this, tr("Error"), + tr("MultiMC cannot download Minecraft or update instances unless you have at least " + "one account added.\nPlease add your Mojang or Minecraft account."), + QMessageBox::Warning)->show(); + return; + } + + auto updateTask = m_inst->createUpdateTask(Net::Mode::Online); + if (!updateTask) + { + return; + } + ProgressDialog tDialog(this); + connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); + // FIXME: unused return value + tDialog.execWithTask(updateTask.get()); + updateButtons(); + m_container->refreshContainer(); +} + +void VersionPage::on_forgeBtn_clicked() +{ + auto vlist = ENV.metadataIndex()->get("net.minecraftforge"); + if(!vlist) + { + return; + } + VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this); + vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); + vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); + vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!")); + + auto currentVersion = m_profile->getComponentVersion("net.minecraftforge"); + if(!currentVersion.isEmpty()) + { + vselect.setCurrentVersion(currentVersion); + } + + if (vselect.exec() && vselect.selectedVersion()) + { + auto vsn = vselect.selectedVersion(); + m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor()); + m_profile->resolve(Net::Mode::Online); + // m_profile->installVersion(); + preselect(m_profile->rowCount(QModelIndex())-1); + m_container->refreshContainer(); + } +} + +void VersionPage::on_addEmptyBtn_clicked() +{ + NewComponentDialog compdialog(QString(), QString(), this); + QStringList blacklist; + for(int i = 0; i < m_profile->rowCount(); i++) + { + auto comp = m_profile->getComponent(i); + blacklist.push_back(comp->getID()); + } + compdialog.setBlacklist(blacklist); + if (compdialog.exec()) + { + qDebug() << "name:" << compdialog.name(); + qDebug() << "uid:" << compdialog.uid(); + m_profile->installEmpty(compdialog.uid(), compdialog.name()); + } +} + +void VersionPage::on_liteloaderBtn_clicked() +{ + auto vlist = ENV.metadataIndex()->get("com.mumfrey.liteloader"); + if(!vlist) + { + return; + } + VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this); + vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); + vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); + vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!")); + + auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader"); + if(!currentVersion.isEmpty()) + { + vselect.setCurrentVersion(currentVersion); + } + + if (vselect.exec() && vselect.selectedVersion()) + { + auto vsn = vselect.selectedVersion(); + m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor()); + m_profile->resolve(Net::Mode::Online); + // m_profile->installVersion(vselect.selectedVersion()); + preselect(m_profile->rowCount(QModelIndex())-1); + m_container->refreshContainer(); + } +} + +void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous) +{ + currentIdx = current.row(); + updateButtons(currentIdx); +} + +void VersionPage::preselect(int row) +{ + if(row < 0) + { + row = 0; + } + if(row >= m_profile->rowCount(QModelIndex())) + { + row = m_profile->rowCount(QModelIndex()) - 1; + } + if(row < 0) + { + return; + } + auto model_index = m_profile->index(row); + ui->packageView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + updateButtons(row); +} + +void VersionPage::updateButtons(int row) +{ + if(row == -1) + row = currentRow(); + auto patch = m_profile->getComponent(row); + if (!patch) + { + ui->removeBtn->setDisabled(true); + ui->moveDownBtn->setDisabled(true); + ui->moveUpBtn->setDisabled(true); + ui->changeVersionBtn->setDisabled(true); + ui->editBtn->setDisabled(true); + ui->customizeBtn->setDisabled(true); + ui->revertBtn->setDisabled(true); + } + else + { + ui->removeBtn->setEnabled(patch->isRemovable()); + ui->moveDownBtn->setEnabled(patch->isMoveable()); + ui->moveUpBtn->setEnabled(patch->isMoveable()); + ui->changeVersionBtn->setEnabled(patch->isVersionChangeable()); + ui->editBtn->setEnabled(patch->isCustom()); + ui->customizeBtn->setEnabled(patch->isCustomizable()); + ui->revertBtn->setEnabled(patch->isRevertible()); + } +} + +void VersionPage::onGameUpdateError(QString error) +{ + CustomMessageBox::selectable(this, tr("Error updating instance"), error, + QMessageBox::Warning)->show(); +} + +Component * VersionPage::current() +{ + auto row = currentRow(); + if(row < 0) + { + return nullptr; + } + return m_profile->getComponent(row); +} + +int VersionPage::currentRow() +{ + if (ui->packageView->selectionModel()->selectedRows().isEmpty()) + { + return -1; + } + return ui->packageView->selectionModel()->selectedRows().first().row(); +} + +void VersionPage::on_customizeBtn_clicked() +{ + auto version = currentRow(); + if(version == -1) + { + return; + } + auto patch = m_profile->getComponent(version); + if(!patch->getVersionFile()) + { + // TODO: wait for the update task to finish here... + return; + } + if(!m_profile->customize(version)) + { + // TODO: some error box here + } + updateButtons(); + preselect(currentIdx); +} + +void VersionPage::on_editBtn_clicked() +{ + auto version = current(); + if(!version) + { + return; + } + auto filename = version->getFilename(); + if(!QFileInfo::exists(filename)) + { + qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!"; + return; + } + MMC->openJsonEditor(filename); +} + +void VersionPage::on_revertBtn_clicked() +{ + auto version = currentRow(); + if(version == -1) + { + return; + } + if(!m_profile->revertToBase(version)) + { + // TODO: some error box here + } + updateButtons(); + preselect(currentIdx); + m_container->refreshContainer(); +} + +#include "VersionPage.moc" + diff --git a/application/pages/instance/VersionPage.h b/application/pages/instance/VersionPage.h new file mode 100644 index 00000000..85304ea5 --- /dev/null +++ b/application/pages/instance/VersionPage.h @@ -0,0 +1,95 @@ +/* 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 "minecraft/MinecraftInstance.h" +#include "minecraft/ComponentList.h" +#include "pages/BasePage.h" + +namespace Ui +{ +class VersionPage; +} + +class VersionPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit VersionPage(MinecraftInstance *inst, QWidget *parent = 0); + virtual ~VersionPage(); + virtual QString displayName() const override + { + return tr("Version"); + } + virtual QIcon icon() const override; + virtual QString id() const override + { + return "version"; + } + virtual QString helpPage() const override + { + return "Instance-Version"; + } + virtual bool shouldDisplay() const override; + +private slots: + void on_forgeBtn_clicked(); + void on_addEmptyBtn_clicked(); + void on_liteloaderBtn_clicked(); + void on_reloadBtn_clicked(); + void on_removeBtn_clicked(); + void on_moveUpBtn_clicked(); + void on_moveDownBtn_clicked(); + void on_jarmodBtn_clicked(); + void on_jarBtn_clicked(); + void on_revertBtn_clicked(); + void on_editBtn_clicked(); + void on_modBtn_clicked(); + void on_customizeBtn_clicked(); + void on_downloadBtn_clicked(); + + void updateVersionControls(); + void disableVersionControls(); + void on_changeVersionBtn_clicked(); + +private: + Component * current(); + int currentRow(); + void updateButtons(int row = -1); + void preselect(int row = 0); + int doUpdate(); + +protected: + /// FIXME: this shouldn't be necessary! + bool reloadComponentList(); + +private: + Ui::VersionPage *ui; + std::shared_ptr m_profile; + MinecraftInstance *m_inst; + int currentIdx = 0; + +public slots: + void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); + +private slots: + void onGameUpdateError(QString error); + void packageCurrent(const QModelIndex ¤t, const QModelIndex &previous); + +}; diff --git a/application/pages/instance/VersionPage.ui b/application/pages/instance/VersionPage.ui new file mode 100644 index 00000000..d54dd840 --- /dev/null +++ b/application/pages/instance/VersionPage.ui @@ -0,0 +1,318 @@ + + + VersionPage + + + + 0 + 0 + 870 + 1008 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + false + + + true + + + + + + + + + Selection + + + Qt::AlignCenter + + + + + + + Change version of the selected package. + + + Change version + + + + + + + Make the selected package apply sooner. + + + Move up + + + + + + + Make the selected package apply later. + + + Move down + + + + + + + Remove selected package from the instance. + + + Remove + + + + + + + + + + Edit + + + Qt::AlignCenter + + + + + + + Customize selected package. + + + Customize + + + + + + + Edit selected package. + + + Edit + + + + + + + Revert the selected package to default. + + + Revert + + + + + + + + + + Install + + + Qt::AlignCenter + + + + + + + Install the Minecraft Forge package. + + + Install Forge + + + + + + + Install the LiteLoader package. + + + Install LiteLoader + + + + + + + Install normal mods. + + + Install mods + + + + + + + + + + Advanced + + + Qt::AlignCenter + + + + + + + Add a mod into the Minecraft jar file. + + + Add to Minecraft.jar + + + + + + + Replace Minecraft.jar + + + + + + + Add Empty + + + + + + + Reload all packages. + + + Reload + + + + + + + Download the files needed to launch the instance now. + + + Download All + + + + + + + Qt::Vertical + + + + 111 + 13 + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + ModListView + QTreeView +
widgets/ModListView.h
+
+ + LineSeparator + QWidget +
widgets/LineSeparator.h
+ 1 +
+ + MCModInfoFrame + QFrame +
widgets/MCModInfoFrame.h
+ 1 +
+
+ + packageView + changeVersionBtn + moveUpBtn + moveDownBtn + removeBtn + customizeBtn + editBtn + revertBtn + forgeBtn + liteloaderBtn + modBtn + jarmodBtn + jarBtn + addEmptyBtn + reloadBtn + downloadBtn + tabWidget + + + +
diff --git a/application/pages/instance/WorldListPage.cpp b/application/pages/instance/WorldListPage.cpp new file mode 100644 index 00000000..539d26a0 --- /dev/null +++ b/application/pages/instance/WorldListPage.cpp @@ -0,0 +1,330 @@ +/* Copyright 2015-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. + */ + +#include "WorldListPage.h" +#include "ui_WorldListPage.h" +#include "minecraft/WorldList.h" +#include +#include "dialogs/ModEditDialogCommon.h" +#include +#include +#include +#include +#include +#include +#include + +#include "MultiMC.h" +#include +#include +#include + +WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, + QString iconName, QString displayName, QString helpPage, + QWidget *parent) + : QWidget(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds), m_iconName(iconName), m_id(id), m_displayName(displayName), m_helpName(helpPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this); + proxy->setSortCaseSensitivity(Qt::CaseInsensitive); + proxy->setSourceModel(m_worlds.get()); + ui->worldTreeView->setSortingEnabled(true); + ui->worldTreeView->setModel(proxy); + ui->worldTreeView->installEventFilter(this); + + auto head = ui->worldTreeView->header(); + + head->setSectionResizeMode(0, QHeaderView::Stretch); + head->setSectionResizeMode(1, QHeaderView::ResizeToContents); + connect(ui->worldTreeView->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, + SLOT(worldChanged(const QModelIndex &, const QModelIndex &))); + worldChanged(QModelIndex(), QModelIndex()); +} + +void WorldListPage::openedImpl() +{ + m_worlds->startWatching(); +} + +void WorldListPage::closedImpl() +{ + m_worlds->stopWatching(); +} + +WorldListPage::~WorldListPage() +{ + m_worlds->stopWatching(); + delete ui; +} + +bool WorldListPage::shouldDisplay() const +{ + return true; +} + +bool WorldListPage::worldListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmWorldBtn_clicked(); + return true; + default: + break; + } + return QWidget::eventFilter(ui->worldTreeView, keyEvent); +} + +bool WorldListPage::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QWidget::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->worldTreeView) + return worldListFilter(keyEvent); + return QWidget::eventFilter(obj, ev); +} + +void WorldListPage::on_rmWorldBtn_clicked() +{ + auto proxiedIndex = getSelectedWorld(); + + if(!proxiedIndex.isValid()) + return; + + auto result = QMessageBox::question(this, + tr("Are you sure?"), + tr("This will remove the selected world permenantly.\n" + "The world will be gone forever (A LONG TIME).\n" + "\n" + "Do you want to continue?")); + if(result != QMessageBox::Yes) + { + return; + } + m_worlds->stopWatching(); + m_worlds->deleteWorld(proxiedIndex.row()); + m_worlds->startWatching(); +} + +void WorldListPage::on_viewFolderBtn_clicked() +{ + DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true); +} + +QModelIndex WorldListPage::getSelectedWorld() +{ + auto index = ui->worldTreeView->selectionModel()->currentIndex(); + + auto proxy = (QSortFilterProxyModel *) ui->worldTreeView->model(); + return proxy->mapToSource(index); +} + +void WorldListPage::on_copySeedBtn_clicked() +{ + QModelIndex index = getSelectedWorld(); + + if (!index.isValid()) + { + return; + } + int64_t seed = m_worlds->data(index, WorldList::SeedRole).toLongLong(); + MMC->clipboard()->setText(QString::number(seed)); +} + +void WorldListPage::on_mcEditBtn_clicked() +{ + if(m_mceditStarting) + return; + + auto mcedit = MMC->mcedit(); + + const QString mceditPath = mcedit->path(); + + QModelIndex index = getSelectedWorld(); + + if (!index.isValid()) + { + return; + } + + if(!worldSafetyNagQuestion()) + return; + + auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString(); + + auto program = mcedit->getProgramPath(); + if(program.size()) + { +#ifdef Q_OS_WIN32 + if(!QProcess::startDetached(program, {fullPath}, mceditPath)) + { + mceditError(); + } +#else + m_mceditProcess.reset(new LoggedProcess()); + m_mceditProcess->setDetachable(true); + connect(m_mceditProcess.get(), &LoggedProcess::stateChanged, this, &WorldListPage::mceditState); + m_mceditProcess->start(program, {fullPath}); + m_mceditProcess->setWorkingDirectory(mceditPath); + m_mceditStarting = true; +#endif + } + else + { + QMessageBox::warning( + this->parentWidget(), + tr("No MCEdit found or set up!"), + tr("You do not have MCEdit set up or it was moved.\nYou can set it up in the global settings.") + ); + } +} + +void WorldListPage::mceditError() +{ + QMessageBox::warning( + this->parentWidget(), + tr("MCEdit failed to start!"), + tr("MCEdit failed to start.\nIt may be necessary to reinstall it.") + ); +} + +void WorldListPage::mceditState(LoggedProcess::State state) +{ + bool failed = false; + switch(state) + { + case LoggedProcess::NotRunning: + case LoggedProcess::Starting: + return; + case LoggedProcess::FailedToStart: + case LoggedProcess::Crashed: + case LoggedProcess::Aborted: + { + failed = true; + } + case LoggedProcess::Running: + case LoggedProcess::Finished: + { + m_mceditStarting = false; + break; + } + } + if(failed) + { + mceditError(); + } +} + +void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + QModelIndex index = getSelectedWorld(); + bool enable = index.isValid(); + ui->copySeedBtn->setEnabled(enable); + ui->mcEditBtn->setEnabled(enable); + ui->rmWorldBtn->setEnabled(enable); + ui->copyBtn->setEnabled(enable); + ui->renameBtn->setEnabled(enable); +} + +void WorldListPage::on_addBtn_clicked() +{ + auto list = GuiUtil::BrowseForFiles( + m_helpName, + tr("Select a Minecraft world zip"), + tr("Minecraft World Zip File (*.zip)"), QString(), this->parentWidget()); + if (!list.empty()) + { + m_worlds->stopWatching(); + for (auto filename : list) + { + m_worlds->installWorld(QFileInfo(filename)); + } + m_worlds->startWatching(); + } +} + +bool WorldListPage::isWorldSafe(QModelIndex) +{ + return !m_inst->isRunning(); +} + +bool WorldListPage::worldSafetyNagQuestion() +{ + if(!isWorldSafe(getSelectedWorld())) + { + auto result = QMessageBox::question(this, tr("Copy World"), tr("Changing a world while Minecraft is running is potentially unsafe.\nDo you wish to proceed?")); + if(result == QMessageBox::No) + { + return false; + } + } + return true; +} + + +void WorldListPage::on_copyBtn_clicked() +{ + QModelIndex index = getSelectedWorld(); + if (!index.isValid()) + { + return; + } + + if(!worldSafetyNagQuestion()) + return; + + auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); + auto world = (World *) worldVariant.value(); + bool ok = false; + QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new name for the copy."), QLineEdit::Normal, world->name(), &ok); + + if (ok && name.length() > 0) + { + world->install(m_worlds->dir().absolutePath(), name); + } +} + +void WorldListPage::on_renameBtn_clicked() +{ + QModelIndex index = getSelectedWorld(); + if (!index.isValid()) + { + return; + } + + if(!worldSafetyNagQuestion()) + return; + + auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); + auto world = (World *) worldVariant.value(); + + bool ok = false; + QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new world name."), QLineEdit::Normal, world->name(), &ok); + + if (ok && name.length() > 0) + { + world->rename(name); + } +} + +void WorldListPage::on_refreshBtn_clicked() +{ + m_worlds->update(); +} diff --git a/application/pages/instance/WorldListPage.h b/application/pages/instance/WorldListPage.h new file mode 100644 index 00000000..71b87bda --- /dev/null +++ b/application/pages/instance/WorldListPage.h @@ -0,0 +1,96 @@ +/* Copyright 2015-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 "minecraft/MinecraftInstance.h" +#include "pages/BasePage.h" +#include +#include + +class WorldList; +namespace Ui +{ +class WorldListPage; +} + +class WorldListPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, + QString iconName, QString displayName, QString helpPage = "", + QWidget *parent = 0); + virtual ~WorldListPage(); + + virtual QString displayName() const override + { + return m_displayName; + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon(m_iconName); + } + virtual QString id() const override + { + return m_id; + } + virtual QString helpPage() const override + { + return m_helpName; + } + virtual bool shouldDisplay() const override; + + virtual void openedImpl() override; + virtual void closedImpl() override; + +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; + bool worldListFilter(QKeyEvent *ev); + +protected: + BaseInstance *m_inst; + +private: + QModelIndex getSelectedWorld(); + bool isWorldSafe(QModelIndex index); + bool worldSafetyNagQuestion(); + void mceditError(); + +private: + Ui::WorldListPage *ui; + std::shared_ptr m_worlds; + unique_qobject_ptr m_mceditProcess; + bool m_mceditStarting = false; + QString m_iconName; + QString m_id; + QString m_displayName; + QString m_helpName; + +private slots: + void on_copySeedBtn_clicked(); + void on_mcEditBtn_clicked(); + void on_rmWorldBtn_clicked(); + void on_addBtn_clicked(); + void on_copyBtn_clicked(); + void on_renameBtn_clicked(); + void on_refreshBtn_clicked(); + void on_viewFolderBtn_clicked(); + void worldChanged(const QModelIndex ¤t, const QModelIndex &previous); + void mceditState(LoggedProcess::State state); +}; diff --git a/application/pages/instance/WorldListPage.ui b/application/pages/instance/WorldListPage.ui new file mode 100644 index 00000000..0018ddf3 --- /dev/null +++ b/application/pages/instance/WorldListPage.ui @@ -0,0 +1,168 @@ + + + WorldListPage + + + + 0 + 0 + 723 + 532 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + + + Add + + + + + + + + + + Rename + + + + + + + Copy + + + + + + + &Remove + + + + + + + MCEdit + + + + + + + + + + Copy Seed + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Refresh + + + + + + + &View Folder + + + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::DragDrop + + + true + + + true + + + false + + + + + + + + + + + + LineSeparator + QWidget +
widgets/LineSeparator.h
+ 1 +
+
+ + tabWidget + worldTreeView + addBtn + renameBtn + copyBtn + rmWorldBtn + mcEditBtn + copySeedBtn + refreshBtn + viewFolderBtn + + + +
diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp new file mode 100644 index 00000000..a8ec6577 --- /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 00000000..f7d6ca8b --- /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 00000000..c54fc392 --- /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 00000000..545ca38d --- /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 00000000..8f62e6b1 --- /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 00000000..eb63cbe9 --- /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 00000000..c0f4faa5 --- /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 00000000..5b0f16a6 --- /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 00000000..6bb6e9e0 --- /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 00000000..a264c2f7 --- /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 00000000..8e072917 --- /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 00000000..19178505 --- /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 00000000..013ca426 --- /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 00000000..3f9d20ec --- /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 00000000..713d04a0 --- /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 780e458d..bea3a325 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 00000000..827b590a --- /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 00000000..80999380 --- /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 00000000..3ea3e85f --- /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 13cd27e7..13fad72a 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 0f78329a..4dbd7fb2 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 96eac80a..ea9f8ce1 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 2a7cbfb7..ce1141b6 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 3ea0b4f5..c134887f 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); -- cgit v1.2.3