From e178284172396ee51acb77c2daa8135b4855c12b Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 16 Jul 2014 00:13:40 +0200 Subject: [PATCH] Merge global settings and accounts into a pagedialog Also split external tools into it's own page --- CMakeLists.txt | 17 +- gui/MainWindow.cpp | 36 +-- gui/MainWindow.h | 3 + gui/pages/BasePageProvider.h | 41 ++++ .../global/AccountListPage.cpp} | 47 ++-- .../global/AccountListPage.h} | 33 ++- .../global/AccountListPage.ui} | 11 +- gui/pages/global/BaseSettingsPage.cpp | 28 +++ gui/pages/global/BaseSettingsPage.h | 35 +++ gui/pages/global/ExternalToolsPage.cpp | 177 ++++++++++++++ gui/pages/global/ExternalToolsPage.h | 66 +++++ gui/pages/global/ExternalToolsPage.ui | 145 +++++++++++ .../global/SettingsPage.cpp} | 227 +++--------------- .../global/SettingsPage.h} | 53 ++-- .../global/SettingsPage.ui} | 196 +-------------- 15 files changed, 637 insertions(+), 478 deletions(-) rename gui/{dialogs/AccountListDialog.cpp => pages/global/AccountListPage.cpp} (76%) rename gui/{dialogs/AccountListDialog.h => pages/global/AccountListPage.h} (71%) rename gui/{dialogs/AccountListDialog.ui => pages/global/AccountListPage.ui} (91%) create mode 100644 gui/pages/global/BaseSettingsPage.cpp create mode 100644 gui/pages/global/BaseSettingsPage.h create mode 100644 gui/pages/global/ExternalToolsPage.cpp create mode 100644 gui/pages/global/ExternalToolsPage.h create mode 100644 gui/pages/global/ExternalToolsPage.ui rename gui/{dialogs/SettingsDialog.cpp => pages/global/SettingsPage.cpp} (74%) rename gui/{dialogs/SettingsDialog.h => pages/global/SettingsPage.h} (75%) rename gui/{dialogs/SettingsDialog.ui => pages/global/SettingsPage.ui} (83%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac497f46..7cae21dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,12 +312,18 @@ SET(MULTIMC_SOURCES gui/pages/ScreenshotsPage.h gui/pages/OtherLogsPage.cpp gui/pages/OtherLogsPage.h + gui/pages/global/SettingsPage.cpp + gui/pages/global/SettingsPage.h + gui/pages/global/ExternalToolsPage.cpp + gui/pages/global/ExternalToolsPage.h + gui/pages/global/BaseSettingsPage.cpp + gui/pages/global/BaseSettingsPage.h + gui/pages/global/AccountListPage.cpp + gui/pages/global/AccountListPage.h # GUI - dialogs gui/dialogs/AboutDialog.cpp gui/dialogs/AboutDialog.h - gui/dialogs/AccountListDialog.cpp - gui/dialogs/AccountListDialog.h gui/dialogs/AccountSelectDialog.cpp gui/dialogs/AccountSelectDialog.h gui/dialogs/CopyInstanceDialog.cpp @@ -342,8 +348,6 @@ SET(MULTIMC_SOURCES gui/pagedialog/PageDialog.h gui/dialogs/ProgressDialog.cpp gui/dialogs/ProgressDialog.h - gui/dialogs/SettingsDialog.cpp - gui/dialogs/SettingsDialog.h gui/dialogs/UpdateDialog.cpp gui/dialogs/UpdateDialog.h gui/dialogs/VersionSelectDialog.cpp @@ -644,9 +648,11 @@ SET(MULTIMC_UIS gui/pages/NotesPage.ui gui/pages/ScreenshotsPage.ui gui/pages/OtherLogsPage.ui + gui/pages/global/SettingsPage.ui + gui/pages/global/ExternalToolsPage.ui + gui/pages/global/AccountListPage.ui # Dialogs - gui/dialogs/SettingsDialog.ui gui/dialogs/CopyInstanceDialog.ui gui/dialogs/NewInstanceDialog.ui gui/dialogs/AboutDialog.ui @@ -654,7 +660,6 @@ SET(MULTIMC_UIS gui/dialogs/LwjglSelectDialog.ui gui/dialogs/ProgressDialog.ui gui/dialogs/IconPickerDialog.ui - gui/dialogs/AccountListDialog.ui gui/dialogs/AccountSelectDialog.ui gui/dialogs/EditAccountDialog.ui gui/dialogs/LoginDialog.ui diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 1a92139c..81ee466b 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -49,7 +49,6 @@ #include "gui/widgets/LabeledToolButton.h" #include "widgets/ServerStatus.h" -#include "gui/dialogs/SettingsDialog.h" #include "gui/dialogs/NewInstanceDialog.h" #include "gui/dialogs/ProgressDialog.h" #include "gui/dialogs/AboutDialog.h" @@ -58,12 +57,15 @@ #include "gui/dialogs/LwjglSelectDialog.h" #include "gui/dialogs/IconPickerDialog.h" #include "gui/dialogs/CopyInstanceDialog.h" -#include "gui/dialogs/AccountListDialog.h" #include "gui/dialogs/AccountSelectDialog.h" #include "gui/dialogs/UpdateDialog.h" #include "gui/dialogs/EditAccountDialog.h" #include "gui/dialogs/NotificationDialog.h" +#include "gui/pages/global/SettingsPage.h" +#include "gui/pages/global/ExternalToolsPage.h" +#include "gui/pages/global/AccountListPage.h" + #include "gui/ConsoleWindow.h" #include "pagedialog/PageDialog.h" @@ -245,6 +247,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->mainToolBar->addAction(accountMenuButtonAction); + // set up global pages dialog + { + m_globalSettingsProvider = std::make_shared(tr("Settings")); + m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); + } + // Update the menu when the active account changes. // Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit. // Template hell sucks... @@ -937,16 +947,6 @@ void MainWindow::on_actionCheckUpdate_triggered() updater->checkForUpdate(true); } -void MainWindow::on_actionSettings_triggered() -{ - SettingsDialog dialog(this); - dialog.exec(); - // FIXME: quick HACK to make this work. improve, optimize. - proxymodel->invalidate(); - proxymodel->sort(0); - updateToolsMenu(); -} - template void ShowPageDialog(T raw_provider, QWidget * parent, QString open_page = QString()) { @@ -957,6 +957,15 @@ void ShowPageDialog(T raw_provider, QWidget * parent, QString open_page = QStrin dlg.exec(); } +void MainWindow::on_actionSettings_triggered() +{ + ShowPageDialog(m_globalSettingsProvider, this, "global-settings"); + // FIXME: quick HACK to make this work. improve, optimize. + proxymodel->invalidate(); + proxymodel->sort(0); + updateToolsMenu(); +} + void MainWindow::on_actionInstanceSettings_triggered() { ShowPageDialog(m_selectedInstance, this, "settings"); @@ -980,8 +989,7 @@ void MainWindow::on_actionScreenshots_triggered() void MainWindow::on_actionManageAccounts_triggered() { - AccountListDialog dialog(this); - dialog.exec(); + ShowPageDialog(m_globalSettingsProvider, this, "accounts"); } void MainWindow::on_actionReportBug_triggered() diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 36ef883b..32ad4daf 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -30,6 +30,7 @@ class QLabel; class MinecraftProcess; class ConsoleWindow; class BaseProfilerFactory; +class GenericPageProvider; namespace Ui { @@ -189,6 +190,8 @@ private: QToolButton *changeIconButton; QToolButton *newsLabel; + std::shared_ptr m_globalSettingsProvider; + InstancePtr m_selectedInstance; QString m_currentInstIcon; diff --git a/gui/pages/BasePageProvider.h b/gui/pages/BasePageProvider.h index cff9c8e7..5e5a11fb 100644 --- a/gui/pages/BasePageProvider.h +++ b/gui/pages/BasePageProvider.h @@ -17,6 +17,7 @@ #include "BasePage.h" #include +#include class BasePageProvider { @@ -25,4 +26,44 @@ public: virtual QString dialogTitle() = 0; }; +class GenericPageProvider : public BasePageProvider +{ + typedef std::function PageCreator; +public: + explicit GenericPageProvider(const QString &dialogTitle) + : m_dialogTitle(dialogTitle) + { + } + + QList getPages() override + { + QList pages; + for (PageCreator creator : m_creators) + { + pages.append(creator()); + } + return pages; + } + QString dialogTitle() override { return m_dialogTitle; } + + void setDialogTitle(const QString &title) + { + m_dialogTitle = title; + } + void addPageCreator(PageCreator page) + { + m_creators.append(page); + } + + template + void addPage() + { + addPageCreator([](){return new PageClass();}); + } + +private: + QList m_creators; + QString m_dialogTitle; +}; + typedef std::shared_ptr BasePageProviderPtr; diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/pages/global/AccountListPage.cpp similarity index 76% rename from gui/dialogs/AccountListDialog.cpp rename to gui/pages/global/AccountListPage.cpp index 688cffa8..cad7d5bc 100644 --- a/gui/dialogs/AccountListDialog.cpp +++ b/gui/pages/global/AccountListPage.cpp @@ -13,28 +13,28 @@ * limitations under the License. */ -#include "AccountListDialog.h" -#include "ui_AccountListDialog.h" +#include "AccountListPage.h" +#include "ui_AccountListPage.h" #include #include -#include -#include +#include "logic/net/NetJob.h" +#include "logic/net/URLConstants.h" -#include -#include -#include -#include -#include "CustomMessageBox.h" -#include -#include +#include "gui/dialogs/EditAccountDialog.h" +#include "gui/dialogs/ProgressDialog.h" +#include "gui/dialogs/AccountSelectDialog.h" +#include "gui/dialogs/LoginDialog.h" +#include "gui/dialogs/CustomMessageBox.h" +#include "logic/tasks/Task.h" +#include "logic/auth/YggdrasilTask.h" #include -AccountListDialog::AccountListDialog(QWidget *parent) - : QDialog(parent), ui(new Ui::AccountListDialog) +AccountListPage::AccountListPage(QWidget *parent) + : QDialog(parent), ui(new Ui::AccountListPage) { ui->setupUi(this); @@ -58,23 +58,23 @@ AccountListDialog::AccountListDialog(QWidget *parent) updateButtonStates(); } -AccountListDialog::~AccountListDialog() +AccountListPage::~AccountListPage() { delete ui; } -void AccountListDialog::listChanged() +void AccountListPage::listChanged() { updateButtonStates(); } -void AccountListDialog::on_addAccountBtn_clicked() +void AccountListPage::on_addAccountBtn_clicked() { addAccount(tr("Please enter your Mojang or Minecraft account username and password to add " "your account.")); } -void AccountListDialog::on_rmAccountBtn_clicked() +void AccountListPage::on_rmAccountBtn_clicked() { QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); if (selection.size() > 0) @@ -84,7 +84,7 @@ void AccountListDialog::on_rmAccountBtn_clicked() } } -void AccountListDialog::on_setDefaultBtn_clicked() +void AccountListPage::on_setDefaultBtn_clicked() { QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); if (selection.size() > 0) @@ -96,17 +96,12 @@ void AccountListDialog::on_setDefaultBtn_clicked() } } -void AccountListDialog::on_noDefaultBtn_clicked() +void AccountListPage::on_noDefaultBtn_clicked() { m_accounts->setActiveAccount(""); } -void AccountListDialog::on_closeBtnBox_rejected() -{ - close(); -} - -void AccountListDialog::updateButtonStates() +void AccountListPage::updateButtonStates() { // If there is no selection, disable buttons that require something selected. QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); @@ -117,7 +112,7 @@ void AccountListDialog::updateButtonStates() ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr); } -void AccountListDialog::addAccount(const QString &errMsg) +void AccountListPage::addAccount(const QString &errMsg) { // TODO: The login dialog isn't quite done yet MojangAccountPtr account = LoginDialog::newAccount(this, errMsg); diff --git a/gui/dialogs/AccountListDialog.h b/gui/pages/global/AccountListPage.h similarity index 71% rename from gui/dialogs/AccountListDialog.h rename to gui/pages/global/AccountListPage.h index fe0c8773..fd4724d1 100644 --- a/gui/dialogs/AccountListDialog.h +++ b/gui/pages/global/AccountListPage.h @@ -16,24 +16,42 @@ #pragma once #include - #include +#include "gui/pages/BasePage.h" + #include "logic/auth/MojangAccountList.h" namespace Ui { -class AccountListDialog; +class AccountListPage; } class AuthenticateTask; -class AccountListDialog : public QDialog +class AccountListPage : public QDialog, public BasePage { Q_OBJECT public: - explicit AccountListDialog(QWidget *parent = 0); - ~AccountListDialog(); + explicit AccountListPage(QWidget *parent = 0); + ~AccountListPage(); + + QString displayName() const override + { + return tr("Accounts"); + } + QIcon icon() const override + { + return QIcon::fromTheme("noaccount"); + } + QString id() const override + { + return "accounts"; + } + QString helpPage() const override + { + return "Accounts"; + } public slots: @@ -45,9 +63,6 @@ slots: void on_noDefaultBtn_clicked(); - // This will be sent when the "close" button is clicked. - void on_closeBtnBox_rejected(); - void listChanged(); //! Updates the states of the dialog's buttons. @@ -61,5 +76,5 @@ slots: void addAccount(const QString& errMsg=""); private: - Ui::AccountListDialog *ui; + Ui::AccountListPage *ui; }; diff --git a/gui/dialogs/AccountListDialog.ui b/gui/pages/global/AccountListPage.ui similarity index 91% rename from gui/dialogs/AccountListDialog.ui rename to gui/pages/global/AccountListPage.ui index 72682163..1e5b07eb 100644 --- a/gui/dialogs/AccountListDialog.ui +++ b/gui/pages/global/AccountListPage.ui @@ -1,7 +1,7 @@ - AccountListDialog - + AccountListPage + 0 @@ -82,13 +82,6 @@ - - - - QDialogButtonBox::Close - - - diff --git a/gui/pages/global/BaseSettingsPage.cpp b/gui/pages/global/BaseSettingsPage.cpp new file mode 100644 index 00000000..167b23c0 --- /dev/null +++ b/gui/pages/global/BaseSettingsPage.cpp @@ -0,0 +1,28 @@ +/* Copyright 2014 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 "BaseSettingsPage.h" + +#include "MultiMC.h" + +void BaseSettingsPage::opened() +{ + loadSettings(MMC->settings().get()); +} +bool BaseSettingsPage::apply() +{ + applySettings(MMC->settings().get()); + return true; +} diff --git a/gui/pages/global/BaseSettingsPage.h b/gui/pages/global/BaseSettingsPage.h new file mode 100644 index 00000000..55e5f2a4 --- /dev/null +++ b/gui/pages/global/BaseSettingsPage.h @@ -0,0 +1,35 @@ +/* Copyright 2014 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 "gui/pages/BasePage.h" + +class SettingsObject; + +class BaseSettingsPage : public BasePage +{ +public: + virtual ~BaseSettingsPage() + { + } + + void opened() override; + bool apply() override; + +protected: + virtual void loadSettings(SettingsObject *object) = 0; + virtual void applySettings(SettingsObject *object) = 0; +}; diff --git a/gui/pages/global/ExternalToolsPage.cpp b/gui/pages/global/ExternalToolsPage.cpp new file mode 100644 index 00000000..e0312ee5 --- /dev/null +++ b/gui/pages/global/ExternalToolsPage.cpp @@ -0,0 +1,177 @@ +/* Copyright 2014 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 "ExternalToolsPage.h" +#include "ui_ExternalToolsPage.h" + +#include +#include + +#include + +#include "logic/settings/SettingsObject.h" +#include "logic/tools/BaseProfiler.h" +#include "MultiMC.h" + +ExternalToolsPage::ExternalToolsPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::ExternalToolsPage) +{ + ui->setupUi(this); + + ui->mceditLink->setOpenExternalLinks(true); + ui->jvisualvmLink->setOpenExternalLinks(true); + ui->jprofilerLink->setOpenExternalLinks(true); +} + +ExternalToolsPage::~ExternalToolsPage() +{ + delete ui; +} + +void ExternalToolsPage::loadSettings(SettingsObject *object) +{ + ui->jprofilerPathEdit->setText(object->get("JProfilerPath").toString()); + ui->jvisualvmPathEdit->setText(object->get("JVisualVMPath").toString()); + ui->mceditPathEdit->setText(object->get("MCEditPath").toString()); +} +void ExternalToolsPage::applySettings(SettingsObject *object) +{ + object->set("JProfilerPath", ui->jprofilerPathEdit->text()); + object->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); + object->set("MCEditPath", ui->mceditPathEdit->text()); +} + +void ExternalToolsPage::on_jprofilerPathBtn_clicked() +{ + QString raw_dir = ui->jprofilerPathEdit->text(); + QString error; + do + { + raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Directory"), raw_dir); + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = NormalizePath(raw_dir); + if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JProfiler install:\n%1").arg(error)); + continue; + } + else + { + ui->jprofilerPathEdit->setText(cooked_dir); + break; + } + } while (1); +} +void ExternalToolsPage::on_jprofilerCheckBtn_clicked() +{ + QString error; + if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JProfiler install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("JProfiler setup seems to be OK")); + } +} + +void ExternalToolsPage::on_jvisualvmPathBtn_clicked() +{ + QString raw_dir = ui->jvisualvmPathEdit->text(); + QString error; + do + { + raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), raw_dir); + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = NormalizePath(raw_dir); + if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JVisualVM install:\n%1").arg(error)); + continue; + } + else + { + ui->jvisualvmPathEdit->setText(cooked_dir); + break; + } + } while (1); +} +void ExternalToolsPage::on_jvisualvmCheckBtn_clicked() +{ + QString error; + if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JVisualVM install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("JVisualVM setup seems to be OK")); + } +} + +void ExternalToolsPage::on_mceditPathBtn_clicked() +{ + QString raw_dir = ui->mceditPathEdit->text(); + QString error; + do + { +#ifdef Q_OS_OSX +#warning stuff + raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir); +#else + raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Directory"), raw_dir); +#endif + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = NormalizePath(raw_dir); + if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking MCEdit install:\n%1").arg(error)); + continue; + } + else + { + ui->mceditPathEdit->setText(cooked_dir); + break; + } + } while (1); +} +void ExternalToolsPage::on_mceditCheckBtn_clicked() +{ + QString error; + if (!MMC->tools()["mcedit"]->check(ui->mceditPathEdit->text(), &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking MCEdit install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("MCEdit setup seems to be OK")); + } +} diff --git a/gui/pages/global/ExternalToolsPage.h b/gui/pages/global/ExternalToolsPage.h new file mode 100644 index 00000000..1b35a92b --- /dev/null +++ b/gui/pages/global/ExternalToolsPage.h @@ -0,0 +1,66 @@ +/* Copyright 2014 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 "BaseSettingsPage.h" + +namespace Ui { +class ExternalToolsPage; +} + +class ExternalToolsPage : public QWidget, public BaseSettingsPage +{ + Q_OBJECT + +public: + explicit ExternalToolsPage(QWidget *parent = 0); + ~ExternalToolsPage(); + + QString displayName() const override + { + return tr("External Tools"); + } + QIcon icon() const override + { + return QIcon::fromTheme("plugin-blue"); + } + QString id() const override + { + return "external-tools"; + } + QString helpPage() const override + { + return "External-tools"; + } + +protected: + void loadSettings(SettingsObject *object) override; + void applySettings(SettingsObject *object) override; + +private: + Ui::ExternalToolsPage *ui; + +private +slots: + void on_jprofilerPathBtn_clicked(); + void on_jprofilerCheckBtn_clicked(); + void on_jvisualvmPathBtn_clicked(); + void on_jvisualvmCheckBtn_clicked(); + void on_mceditPathBtn_clicked(); + void on_mceditCheckBtn_clicked(); +}; diff --git a/gui/pages/global/ExternalToolsPage.ui b/gui/pages/global/ExternalToolsPage.ui new file mode 100644 index 00000000..96650f0f --- /dev/null +++ b/gui/pages/global/ExternalToolsPage.ui @@ -0,0 +1,145 @@ + + + ExternalToolsPage + + + + 0 + 0 + 494 + 562 + + + + Form + + + + + + JProfiler + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + <html><head/><body><p><a href="http://www.ej-technologies.com/products/jprofiler/overview.html"><span style=" text-decoration: underline; color:#0000ff;">http://www.ej-technologies.com/products/jprofiler/overview.html</span></a></p></body></html> + + + + + + + + + + JVisualVM + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + <html><head/><body><p><a href="http://visualvm.java.net/"><span style=" text-decoration: underline; color:#0000ff;">http://visualvm.java.net/</span></a></p></body></html> + + + + + + + + + + MCEdit + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + <html><head/><body><p><a href="http://www.mcedit.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.mcedit.net/</span></a></p></body></html> + + + + + + + + + + Qt::Vertical + + + + 20 + 160 + + + + + + + + + diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/pages/global/SettingsPage.cpp similarity index 74% rename from gui/dialogs/SettingsDialog.cpp rename to gui/pages/global/SettingsPage.cpp index 347cd67e..37b0539c 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/pages/global/SettingsPage.cpp @@ -13,10 +13,14 @@ * limitations under the License. */ -#include "MultiMC.h" +#include "SettingsPage.h" +#include "ui_SettingsPage.h" -#include "gui/dialogs/SettingsDialog.h" -#include "ui_SettingsDialog.h" +#include +#include +#include + +#include #include "gui/Platform.h" #include "gui/dialogs/VersionSelectDialog.h" @@ -33,10 +37,7 @@ #include "logic/tools/BaseProfiler.h" #include "logic/settings/SettingsObject.h" -#include -#include -#include -#include +#include "MultiMC.h" // FIXME: possibly move elsewhere enum InstSortMode @@ -47,7 +48,7 @@ enum InstSortMode Sort_LastLaunch }; -SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) +SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent), ui(new Ui::SettingsPage) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); @@ -61,11 +62,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se restoreGeometry( QByteArray::fromBase64(MMC->settings()->get("SettingsGeometry").toByteArray())); - loadSettings(MMC->settings().get()); - updateCheckboxStuff(); - QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this, - &SettingsDialog::refreshUpdateChannelList); + &SettingsPage::refreshUpdateChannelList); if (MMC->updateChecker()->hasChannels()) { @@ -76,28 +74,21 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se MMC->updateChecker()->updateChanList(false); } connect(ui->proxyGroup, SIGNAL(buttonClicked(int)), SLOT(proxyChanged(int))); - ui->mceditLink->setOpenExternalLinks(true); - ui->jvisualvmLink->setOpenExternalLinks(true); - ui->jprofilerLink->setOpenExternalLinks(true); } -SettingsDialog::~SettingsDialog() +SettingsPage::~SettingsPage() { delete ui; } -void SettingsDialog::showEvent(QShowEvent *ev) -{ - QDialog::showEvent(ev); -} -void SettingsDialog::closeEvent(QCloseEvent *ev) +void SettingsPage::closeEvent(QCloseEvent *ev) { MMC->settings()->set("SettingsGeometry", saveGeometry().toBase64()); - QDialog::closeEvent(ev); + QWidget::closeEvent(ev); } -void SettingsDialog::updateCheckboxStuff() +void SettingsPage::updateCheckboxStuff() { ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); @@ -107,7 +98,7 @@ void SettingsDialog::updateCheckboxStuff() !ui->proxyDefaultBtn->isChecked()); } -void SettingsDialog::on_ftbLauncherBrowseBtn_clicked() +void SettingsPage::on_ftbLauncherBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Launcher Directory"), ui->ftbLauncherBox->text()); @@ -119,8 +110,7 @@ void SettingsDialog::on_ftbLauncherBrowseBtn_clicked() ui->ftbLauncherBox->setText(cooked_dir); } } - -void SettingsDialog::on_ftbBrowseBtn_clicked() +void SettingsPage::on_ftbBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Directory"), ui->ftbBox->text()); @@ -133,7 +123,7 @@ void SettingsDialog::on_ftbBrowseBtn_clicked() } } -void SettingsDialog::on_instDirBrowseBtn_clicked() +void SettingsPage::on_instDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"), ui->instDirTextBox->text()); @@ -145,7 +135,7 @@ void SettingsDialog::on_instDirBrowseBtn_clicked() ui->instDirTextBox->setText(cooked_dir); } } -void SettingsDialog::on_iconsDirBrowseBtn_clicked() +void SettingsPage::on_iconsDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Directory"), ui->iconsDirTextBox->text()); @@ -157,8 +147,7 @@ void SettingsDialog::on_iconsDirBrowseBtn_clicked() ui->iconsDirTextBox->setText(cooked_dir); } } - -void SettingsDialog::on_modsDirBrowseBtn_clicked() +void SettingsPage::on_modsDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"), ui->modsDirTextBox->text()); @@ -170,8 +159,7 @@ void SettingsDialog::on_modsDirBrowseBtn_clicked() ui->modsDirTextBox->setText(cooked_dir); } } - -void SettingsDialog::on_lwjglDirBrowseBtn_clicked() +void SettingsPage::on_lwjglDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"), ui->lwjglDirTextBox->text()); @@ -184,7 +172,7 @@ void SettingsDialog::on_lwjglDirBrowseBtn_clicked() } } -void SettingsDialog::on_jsonEditorBrowseBtn_clicked() +void SettingsPage::on_jsonEditorBrowseBtn_clicked() { QString raw_file = QFileDialog::getOpenFileName( this, tr("JSON Editor"), @@ -214,33 +202,18 @@ void SettingsDialog::on_jsonEditorBrowseBtn_clicked() } } -void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) +void SettingsPage::on_maximizedCheckBox_clicked(bool checked) { Q_UNUSED(checked); updateCheckboxStuff(); } -void SettingsDialog::on_buttonBox_accepted() -{ - applySettings(MMC->settings().get()); - - // Apply proxy settings - MMC->updateProxySettings(); - - MMC->settings()->set("SettingsGeometry", saveGeometry().toBase64()); -} - -void SettingsDialog::on_buttonBox_rejected() -{ - MMC->settings()->set("SettingsGeometry", saveGeometry().toBase64()); -} - -void SettingsDialog::proxyChanged(int) +void SettingsPage::proxyChanged(int) { updateCheckboxStuff(); } -void SettingsDialog::refreshUpdateChannelList() +void SettingsPage::refreshUpdateChannelList() { // Stop listening for selection changes. It's going to change a lot while we update it and // we don't need to update the @@ -285,12 +258,12 @@ void SettingsDialog::refreshUpdateChannelList() ui->updateChannelComboBox->setEnabled(true); } -void SettingsDialog::updateChannelSelectionChanged(int index) +void SettingsPage::updateChannelSelectionChanged(int index) { refreshUpdateChannelDesc(); } -void SettingsDialog::refreshUpdateChannelDesc() +void SettingsPage::refreshUpdateChannelDesc() { // Get the channel list. QList channelList = MMC->updateChecker()->getChannelList(); @@ -312,7 +285,7 @@ void SettingsDialog::refreshUpdateChannelDesc() } } -void SettingsDialog::applySettings(SettingsObject *s) +void SettingsPage::applySettings(SettingsObject *s) { // Language s->set("Language", @@ -421,14 +394,8 @@ void SettingsDialog::applySettings(SettingsObject *s) } s->set("PostExitCommand", ui->postExitCmdTextBox->text()); - - // Profilers - s->set("JProfilerPath", ui->jprofilerPathEdit->text()); - s->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); - s->set("MCEditPath", ui->mceditPathEdit->text()); } - -void SettingsDialog::loadSettings(SettingsObject *s) +void SettingsPage::loadSettings(SettingsObject *s) { // Language ui->languageBox->clear(); @@ -524,14 +491,9 @@ void SettingsDialog::loadSettings(SettingsObject *s) // Custom Commands ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); - - // Profilers - ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString()); - ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString()); - ui->mceditPathEdit->setText(s->get("MCEditPath").toString()); } -void SettingsDialog::on_javaDetectBtn_clicked() +void SettingsPage::on_javaDetectBtn_clicked() { JavaVersionPtr java; @@ -545,8 +507,7 @@ void SettingsDialog::on_javaDetectBtn_clicked() ui->javaPathTextBox->setText(java->path); } } - -void SettingsDialog::on_javaBrowseBtn_clicked() +void SettingsPage::on_javaBrowseBtn_clicked() { QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable")); if (!dir.isNull()) @@ -554,8 +515,7 @@ void SettingsDialog::on_javaBrowseBtn_clicked() ui->javaPathTextBox->setText(dir); } } - -void SettingsDialog::on_javaTestBtn_clicked() +void SettingsPage::on_javaTestBtn_clicked() { checker.reset(new JavaChecker()); connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this, @@ -564,7 +524,7 @@ void SettingsDialog::on_javaTestBtn_clicked() checker->performCheck(); } -void SettingsDialog::checkFinished(JavaCheckResult result) +void SettingsPage::checkFinished(JavaCheckResult result) { if (result.valid) { @@ -585,126 +545,3 @@ void SettingsDialog::checkFinished(JavaCheckResult result) "or set the path to the java executable.")); } } - -void SettingsDialog::on_jprofilerPathBtn_clicked() -{ - QString raw_dir = ui->jprofilerPathEdit->text(); - QString error; - do - { - raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Directory"), raw_dir); - if (raw_dir.isEmpty()) - { - break; - } - QString cooked_dir = NormalizePath(raw_dir); - if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); - continue; - } - else - { - ui->jprofilerPathEdit->setText(cooked_dir); - break; - } - } while (1); -} -void SettingsDialog::on_jprofilerCheckBtn_clicked() -{ - QString error; - if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); - } - else - { - QMessageBox::information(this, tr("OK"), tr("JProfiler setup seems to be OK")); - } -} - -void SettingsDialog::on_jvisualvmPathBtn_clicked() -{ - QString raw_dir = ui->jvisualvmPathEdit->text(); - QString error; - do - { - raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), raw_dir); - if (raw_dir.isEmpty()) - { - break; - } - QString cooked_dir = NormalizePath(raw_dir); - if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); - continue; - } - else - { - ui->jvisualvmPathEdit->setText(cooked_dir); - break; - } - } while (1); -} -void SettingsDialog::on_jvisualvmCheckBtn_clicked() -{ - QString error; - if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); - } - else - { - QMessageBox::information(this, tr("OK"), tr("JVisualVM setup seems to be OK")); - } -} - -void SettingsDialog::on_mceditPathBtn_clicked() -{ - QString raw_dir = ui->mceditPathEdit->text(); - QString error; - do - { -#ifdef Q_OS_OSX -#warning stuff - raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir); -#else - raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Directory"), raw_dir); -#endif - if (raw_dir.isEmpty()) - { - break; - } - QString cooked_dir = NormalizePath(raw_dir); - if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking MCEdit install:\n%1").arg(error)); - continue; - } - else - { - ui->mceditPathEdit->setText(cooked_dir); - break; - } - } while (1); -} - -void SettingsDialog::on_mceditCheckBtn_clicked() -{ - QString error; - if (!MMC->tools()["mcedit"]->check(ui->mceditPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking MCEdit install:\n%1").arg(error)); - } - else - { - QMessageBox::information(this, tr("OK"), tr("MCEdit setup seems to be OK")); - } -} diff --git a/gui/dialogs/SettingsDialog.h b/gui/pages/global/SettingsPage.h similarity index 75% rename from gui/dialogs/SettingsDialog.h rename to gui/pages/global/SettingsPage.h index c65e9fb5..46a38ec7 100644 --- a/gui/dialogs/SettingsDialog.h +++ b/gui/pages/global/SettingsPage.h @@ -19,69 +19,68 @@ #include #include "logic/java/JavaChecker.h" +#include "BaseSettingsPage.h" class SettingsObject; namespace Ui { -class SettingsDialog; +class SettingsPage; } -class SettingsDialog : public QDialog +class SettingsPage : public QWidget, public BaseSettingsPage { Q_OBJECT public: - explicit SettingsDialog(QWidget *parent = 0); - ~SettingsDialog(); + explicit SettingsPage(QWidget *parent = 0); + ~SettingsPage(); + + QString displayName() const override + { + return tr("Settings"); + } + QIcon icon() const override + { + return QIcon::fromTheme("settings"); + } + QString id() const override + { + return "global-settings"; + } + QString helpPage() const override + { + return "Global-settings"; + } void updateCheckboxStuff(); - void applySettings(SettingsObject *s); - void loadSettings(SettingsObject *s); protected: - virtual void showEvent(QShowEvent *ev); + void applySettings(SettingsObject *s) override; + void loadSettings(SettingsObject *s) override; virtual void closeEvent(QCloseEvent *ev); private slots: void on_ftbLauncherBrowseBtn_clicked(); - void on_ftbBrowseBtn_clicked(); void on_instDirBrowseBtn_clicked(); - void on_modsDirBrowseBtn_clicked(); - void on_lwjglDirBrowseBtn_clicked(); - + void on_iconsDirBrowseBtn_clicked(); void on_jsonEditorBrowseBtn_clicked(); - void on_iconsDirBrowseBtn_clicked(); - void on_maximizedCheckBox_clicked(bool checked); - void on_buttonBox_accepted(); - - void on_buttonBox_rejected(); - void on_javaDetectBtn_clicked(); - void on_javaTestBtn_clicked(); - void on_javaBrowseBtn_clicked(); void checkFinished(JavaCheckResult result); - void on_jprofilerPathBtn_clicked(); - void on_jprofilerCheckBtn_clicked(); - void on_jvisualvmPathBtn_clicked(); - void on_jvisualvmCheckBtn_clicked(); - void on_mceditPathBtn_clicked(); - void on_mceditCheckBtn_clicked(); - /*! * Updates the list of update channels in the combo box. */ @@ -96,7 +95,7 @@ slots: void proxyChanged(int); private: - Ui::SettingsDialog *ui; + Ui::SettingsPage *ui; std::shared_ptr checker; /*! diff --git a/gui/dialogs/SettingsDialog.ui b/gui/pages/global/SettingsPage.ui similarity index 83% rename from gui/dialogs/SettingsDialog.ui rename to gui/pages/global/SettingsPage.ui index 94b81dd7..ed1d8cda 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/pages/global/SettingsPage.ui @@ -1,7 +1,7 @@ - SettingsDialog - + SettingsPage + 0 @@ -23,9 +23,6 @@ :/icons/toolbar/settings:/icons/toolbar/settings - - true - @@ -926,147 +923,6 @@ - - - External Tools - - - - - - JProfiler - - - - - - - - - - - ... - - - - - - - - - Check - - - - - - - <html><head/><body><p><a href="http://www.ej-technologies.com/products/jprofiler/overview.html"><span style=" text-decoration: underline; color:#0000ff;">http://www.ej-technologies.com/products/jprofiler/overview.html</span></a></p></body></html> - - - - - - - - - - JVisualVM - - - - - - - - - - - ... - - - - - - - - - Check - - - - - - - <html><head/><body><p><a href="http://visualvm.java.net/"><span style=" text-decoration: underline; color:#0000ff;">http://visualvm.java.net/</span></a></p></body></html> - - - - - - - - - - MCEdit - - - - - - - - - - - ... - - - - - - - - - Check - - - - - - - <html><head/><body><p><a href="http://www.mcedit.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.mcedit.net/</span></a></p></body></html> - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - @@ -1119,53 +975,9 @@ proxyPortEdit proxyUserEdit proxyPassEdit - jprofilerPathEdit - jprofilerPathBtn - jprofilerCheckBtn - jvisualvmPathEdit - jvisualvmPathBtn - jvisualvmCheckBtn - mceditPathEdit - mceditPathBtn - mceditCheckBtn - - - - - - buttonBox - accepted() - SettingsDialog - accept() - - - 257 - 410 - - - 157 - 274 - - - - - buttonBox - rejected() - SettingsDialog - reject() - - - 325 - 410 - - - 286 - 274 - - - - + +