From b258eac215c791b2a8eed10cecbbf9551c87f0b9 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 22 Nov 2021 03:55:16 +0100 Subject: NOISSUE continue reshuffling the codebase --- launcher/ui/pages/BasePage.h | 58 ++ launcher/ui/pages/BasePageContainer.h | 10 + launcher/ui/pages/BasePageProvider.h | 68 ++ launcher/ui/pages/global/AccountListPage.cpp | 260 +++++++ launcher/ui/pages/global/AccountListPage.h | 85 +++ launcher/ui/pages/global/AccountListPage.ui | 129 ++++ launcher/ui/pages/global/CustomCommandsPage.cpp | 51 ++ launcher/ui/pages/global/CustomCommandsPage.h | 55 ++ launcher/ui/pages/global/ExternalToolsPage.cpp | 233 +++++++ launcher/ui/pages/global/ExternalToolsPage.h | 74 ++ launcher/ui/pages/global/ExternalToolsPage.ui | 194 ++++++ launcher/ui/pages/global/JavaPage.cpp | 153 ++++ launcher/ui/pages/global/JavaPage.h | 72 ++ launcher/ui/pages/global/JavaPage.ui | 260 +++++++ launcher/ui/pages/global/LanguagePage.cpp | 51 ++ launcher/ui/pages/global/LanguagePage.h | 60 ++ launcher/ui/pages/global/LauncherPage.cpp | 466 +++++++++++++ launcher/ui/pages/global/LauncherPage.h | 103 +++ launcher/ui/pages/global/LauncherPage.ui | 584 ++++++++++++++++ launcher/ui/pages/global/MinecraftPage.cpp | 91 +++ launcher/ui/pages/global/MinecraftPage.h | 70 ++ launcher/ui/pages/global/MinecraftPage.ui | 196 ++++++ launcher/ui/pages/global/PasteEEPage.cpp | 81 +++ launcher/ui/pages/global/PasteEEPage.h | 62 ++ launcher/ui/pages/global/PasteEEPage.ui | 128 ++++ launcher/ui/pages/global/ProxyPage.cpp | 106 +++ launcher/ui/pages/global/ProxyPage.h | 66 ++ launcher/ui/pages/global/ProxyPage.ui | 203 ++++++ launcher/ui/pages/instance/GameOptionsPage.cpp | 37 + launcher/ui/pages/instance/GameOptionsPage.h | 63 ++ launcher/ui/pages/instance/GameOptionsPage.ui | 88 +++ .../ui/pages/instance/InstanceSettingsPage.cpp | 341 +++++++++ launcher/ui/pages/instance/InstanceSettingsPage.h | 76 ++ launcher/ui/pages/instance/InstanceSettingsPage.ui | 548 +++++++++++++++ launcher/ui/pages/instance/LegacyUpgradePage.cpp | 51 ++ launcher/ui/pages/instance/LegacyUpgradePage.h | 64 ++ launcher/ui/pages/instance/LegacyUpgradePage.ui | 47 ++ launcher/ui/pages/instance/LogPage.cpp | 330 +++++++++ launcher/ui/pages/instance/LogPage.h | 86 +++ launcher/ui/pages/instance/LogPage.ui | 182 +++++ launcher/ui/pages/instance/ModFolderPage.cpp | 366 ++++++++++ launcher/ui/pages/instance/ModFolderPage.h | 120 ++++ launcher/ui/pages/instance/ModFolderPage.ui | 164 +++++ launcher/ui/pages/instance/NotesPage.cpp | 21 + launcher/ui/pages/instance/NotesPage.h | 60 ++ launcher/ui/pages/instance/NotesPage.ui | 49 ++ launcher/ui/pages/instance/OtherLogsPage.cpp | 314 +++++++++ launcher/ui/pages/instance/OtherLogsPage.h | 81 +++ launcher/ui/pages/instance/OtherLogsPage.ui | 150 ++++ launcher/ui/pages/instance/ResourcePackPage.h | 23 + launcher/ui/pages/instance/ScreenshotsPage.cpp | 423 ++++++++++++ launcher/ui/pages/instance/ScreenshotsPage.h | 89 +++ launcher/ui/pages/instance/ScreenshotsPage.ui | 87 +++ launcher/ui/pages/instance/ServersPage.cpp | 768 +++++++++++++++++++++ launcher/ui/pages/instance/ServersPage.h | 94 +++ launcher/ui/pages/instance/ServersPage.ui | 194 ++++++ launcher/ui/pages/instance/ShaderPackPage.h | 22 + launcher/ui/pages/instance/TexturePackPage.h | 22 + launcher/ui/pages/instance/VersionPage.cpp | 641 +++++++++++++++++ launcher/ui/pages/instance/VersionPage.h | 104 +++ launcher/ui/pages/instance/VersionPage.ui | 285 ++++++++ launcher/ui/pages/instance/WorldListPage.cpp | 412 +++++++++++ launcher/ui/pages/instance/WorldListPage.h | 99 +++ launcher/ui/pages/instance/WorldListPage.ui | 161 +++++ launcher/ui/pages/modplatform/ImportPage.cpp | 132 ++++ launcher/ui/pages/modplatform/ImportPage.h | 70 ++ launcher/ui/pages/modplatform/ImportPage.ui | 52 ++ launcher/ui/pages/modplatform/VanillaPage.cpp | 103 +++ launcher/ui/pages/modplatform/VanillaPage.h | 75 ++ launcher/ui/pages/modplatform/VanillaPage.ui | 169 +++++ .../modplatform/atlauncher/AtlFilterModel.cpp | 81 +++ .../pages/modplatform/atlauncher/AtlFilterModel.h | 34 + .../pages/modplatform/atlauncher/AtlListModel.cpp | 193 ++++++ .../ui/pages/modplatform/atlauncher/AtlListModel.h | 52 ++ .../atlauncher/AtlOptionalModDialog.cpp | 209 ++++++ .../modplatform/atlauncher/AtlOptionalModDialog.h | 66 ++ .../modplatform/atlauncher/AtlOptionalModDialog.ui | 65 ++ .../ui/pages/modplatform/atlauncher/AtlPage.cpp | 171 +++++ launcher/ui/pages/modplatform/atlauncher/AtlPage.h | 86 +++ .../ui/pages/modplatform/atlauncher/AtlPage.ui | 92 +++ launcher/ui/pages/modplatform/flame/FlameModel.cpp | 258 +++++++ launcher/ui/pages/modplatform/flame/FlameModel.h | 76 ++ launcher/ui/pages/modplatform/flame/FlamePage.cpp | 186 +++++ launcher/ui/pages/modplatform/flame/FlamePage.h | 80 +++ launcher/ui/pages/modplatform/flame/FlamePage.ui | 90 +++ .../ui/pages/modplatform/ftb/FtbFilterModel.cpp | 76 ++ launcher/ui/pages/modplatform/ftb/FtbFilterModel.h | 35 + launcher/ui/pages/modplatform/ftb/FtbListModel.cpp | 278 ++++++++ launcher/ui/pages/modplatform/ftb/FtbListModel.h | 61 ++ launcher/ui/pages/modplatform/ftb/FtbPage.cpp | 150 ++++ launcher/ui/pages/modplatform/ftb/FtbPage.h | 83 +++ launcher/ui/pages/modplatform/ftb/FtbPage.ui | 79 +++ .../ui/pages/modplatform/legacy_ftb/ListModel.cpp | 259 +++++++ .../ui/pages/modplatform/legacy_ftb/ListModel.h | 78 +++ launcher/ui/pages/modplatform/legacy_ftb/Page.cpp | 371 ++++++++++ launcher/ui/pages/modplatform/legacy_ftb/Page.h | 119 ++++ launcher/ui/pages/modplatform/legacy_ftb/Page.ui | 135 ++++ .../ui/pages/modplatform/technic/TechnicData.h | 42 ++ .../ui/pages/modplatform/technic/TechnicModel.cpp | 237 +++++++ .../ui/pages/modplatform/technic/TechnicModel.h | 70 ++ .../ui/pages/modplatform/technic/TechnicPage.cpp | 201 ++++++ .../ui/pages/modplatform/technic/TechnicPage.h | 78 +++ .../ui/pages/modplatform/technic/TechnicPage.ui | 95 +++ 103 files changed, 15418 insertions(+) create mode 100644 launcher/ui/pages/BasePage.h create mode 100644 launcher/ui/pages/BasePageContainer.h create mode 100644 launcher/ui/pages/BasePageProvider.h create mode 100644 launcher/ui/pages/global/AccountListPage.cpp create mode 100644 launcher/ui/pages/global/AccountListPage.h create mode 100644 launcher/ui/pages/global/AccountListPage.ui create mode 100644 launcher/ui/pages/global/CustomCommandsPage.cpp create mode 100644 launcher/ui/pages/global/CustomCommandsPage.h create mode 100644 launcher/ui/pages/global/ExternalToolsPage.cpp create mode 100644 launcher/ui/pages/global/ExternalToolsPage.h create mode 100644 launcher/ui/pages/global/ExternalToolsPage.ui create mode 100644 launcher/ui/pages/global/JavaPage.cpp create mode 100644 launcher/ui/pages/global/JavaPage.h create mode 100644 launcher/ui/pages/global/JavaPage.ui create mode 100644 launcher/ui/pages/global/LanguagePage.cpp create mode 100644 launcher/ui/pages/global/LanguagePage.h create mode 100644 launcher/ui/pages/global/LauncherPage.cpp create mode 100644 launcher/ui/pages/global/LauncherPage.h create mode 100644 launcher/ui/pages/global/LauncherPage.ui create mode 100644 launcher/ui/pages/global/MinecraftPage.cpp create mode 100644 launcher/ui/pages/global/MinecraftPage.h create mode 100644 launcher/ui/pages/global/MinecraftPage.ui create mode 100644 launcher/ui/pages/global/PasteEEPage.cpp create mode 100644 launcher/ui/pages/global/PasteEEPage.h create mode 100644 launcher/ui/pages/global/PasteEEPage.ui create mode 100644 launcher/ui/pages/global/ProxyPage.cpp create mode 100644 launcher/ui/pages/global/ProxyPage.h create mode 100644 launcher/ui/pages/global/ProxyPage.ui create mode 100644 launcher/ui/pages/instance/GameOptionsPage.cpp create mode 100644 launcher/ui/pages/instance/GameOptionsPage.h create mode 100644 launcher/ui/pages/instance/GameOptionsPage.ui create mode 100644 launcher/ui/pages/instance/InstanceSettingsPage.cpp create mode 100644 launcher/ui/pages/instance/InstanceSettingsPage.h create mode 100644 launcher/ui/pages/instance/InstanceSettingsPage.ui create mode 100644 launcher/ui/pages/instance/LegacyUpgradePage.cpp create mode 100644 launcher/ui/pages/instance/LegacyUpgradePage.h create mode 100644 launcher/ui/pages/instance/LegacyUpgradePage.ui create mode 100644 launcher/ui/pages/instance/LogPage.cpp create mode 100644 launcher/ui/pages/instance/LogPage.h create mode 100644 launcher/ui/pages/instance/LogPage.ui create mode 100644 launcher/ui/pages/instance/ModFolderPage.cpp create mode 100644 launcher/ui/pages/instance/ModFolderPage.h create mode 100644 launcher/ui/pages/instance/ModFolderPage.ui create mode 100644 launcher/ui/pages/instance/NotesPage.cpp create mode 100644 launcher/ui/pages/instance/NotesPage.h create mode 100644 launcher/ui/pages/instance/NotesPage.ui create mode 100644 launcher/ui/pages/instance/OtherLogsPage.cpp create mode 100644 launcher/ui/pages/instance/OtherLogsPage.h create mode 100644 launcher/ui/pages/instance/OtherLogsPage.ui create mode 100644 launcher/ui/pages/instance/ResourcePackPage.h create mode 100644 launcher/ui/pages/instance/ScreenshotsPage.cpp create mode 100644 launcher/ui/pages/instance/ScreenshotsPage.h create mode 100644 launcher/ui/pages/instance/ScreenshotsPage.ui create mode 100644 launcher/ui/pages/instance/ServersPage.cpp create mode 100644 launcher/ui/pages/instance/ServersPage.h create mode 100644 launcher/ui/pages/instance/ServersPage.ui create mode 100644 launcher/ui/pages/instance/ShaderPackPage.h create mode 100644 launcher/ui/pages/instance/TexturePackPage.h create mode 100644 launcher/ui/pages/instance/VersionPage.cpp create mode 100644 launcher/ui/pages/instance/VersionPage.h create mode 100644 launcher/ui/pages/instance/VersionPage.ui create mode 100644 launcher/ui/pages/instance/WorldListPage.cpp create mode 100644 launcher/ui/pages/instance/WorldListPage.h create mode 100644 launcher/ui/pages/instance/WorldListPage.ui create mode 100644 launcher/ui/pages/modplatform/ImportPage.cpp create mode 100644 launcher/ui/pages/modplatform/ImportPage.h create mode 100644 launcher/ui/pages/modplatform/ImportPage.ui create mode 100644 launcher/ui/pages/modplatform/VanillaPage.cpp create mode 100644 launcher/ui/pages/modplatform/VanillaPage.h create mode 100644 launcher/ui/pages/modplatform/VanillaPage.ui create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.h create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlListModel.h create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.ui create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlPage.h create mode 100644 launcher/ui/pages/modplatform/atlauncher/AtlPage.ui create mode 100644 launcher/ui/pages/modplatform/flame/FlameModel.cpp create mode 100644 launcher/ui/pages/modplatform/flame/FlameModel.h create mode 100644 launcher/ui/pages/modplatform/flame/FlamePage.cpp create mode 100644 launcher/ui/pages/modplatform/flame/FlamePage.h create mode 100644 launcher/ui/pages/modplatform/flame/FlamePage.ui create mode 100644 launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp create mode 100644 launcher/ui/pages/modplatform/ftb/FtbFilterModel.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbListModel.cpp create mode 100644 launcher/ui/pages/modplatform/ftb/FtbListModel.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbPage.cpp create mode 100644 launcher/ui/pages/modplatform/ftb/FtbPage.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbPage.ui create mode 100644 launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp create mode 100644 launcher/ui/pages/modplatform/legacy_ftb/ListModel.h create mode 100644 launcher/ui/pages/modplatform/legacy_ftb/Page.cpp create mode 100644 launcher/ui/pages/modplatform/legacy_ftb/Page.h create mode 100644 launcher/ui/pages/modplatform/legacy_ftb/Page.ui create mode 100644 launcher/ui/pages/modplatform/technic/TechnicData.h create mode 100644 launcher/ui/pages/modplatform/technic/TechnicModel.cpp create mode 100644 launcher/ui/pages/modplatform/technic/TechnicModel.h create mode 100644 launcher/ui/pages/modplatform/technic/TechnicPage.cpp create mode 100644 launcher/ui/pages/modplatform/technic/TechnicPage.h create mode 100644 launcher/ui/pages/modplatform/technic/TechnicPage.ui (limited to 'launcher/ui/pages') diff --git a/launcher/ui/pages/BasePage.h b/launcher/ui/pages/BasePage.h new file mode 100644 index 00000000..408965d0 --- /dev/null +++ b/launcher/ui/pages/BasePage.h @@ -0,0 +1,58 @@ +/* Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +#include "BasePageContainer.h" + +class BasePage +{ +public: + virtual ~BasePage() {} + virtual QString id() const = 0; + virtual QString displayName() const = 0; + virtual QIcon icon() const = 0; + virtual bool apply() { return true; } + virtual bool shouldDisplay() const { return true; } + virtual QString helpPage() const { return QString(); } + void opened() + { + isOpened = true; + openedImpl(); + } + void closed() + { + isOpened = false; + closedImpl(); + } + virtual void openedImpl() {} + virtual void closedImpl() {} + virtual void setParentContainer(BasePageContainer * container) + { + m_container = container; + }; +public: + int stackIndex = -1; + int listIndex = -1; +protected: + BasePageContainer * m_container = nullptr; + bool isOpened = false; +}; + +typedef std::shared_ptr BasePagePtr; diff --git a/launcher/ui/pages/BasePageContainer.h b/launcher/ui/pages/BasePageContainer.h new file mode 100644 index 00000000..f8c7adeb --- /dev/null +++ b/launcher/ui/pages/BasePageContainer.h @@ -0,0 +1,10 @@ +#pragma once + +class BasePageContainer +{ +public: + virtual ~BasePageContainer(){}; + virtual bool selectPage(QString pageId) = 0; + virtual void refreshContainer() = 0; + virtual bool requestClose() = 0; +}; diff --git a/launcher/ui/pages/BasePageProvider.h b/launcher/ui/pages/BasePageProvider.h new file mode 100644 index 00000000..873e8dce --- /dev/null +++ b/launcher/ui/pages/BasePageProvider.h @@ -0,0 +1,68 @@ +/* Copyright 2013-2021 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 "ui/pages/BasePage.h" +#include +#include + +class BasePageProvider +{ +public: + virtual QList getPages() = 0; + virtual QString dialogTitle() = 0; +}; + +class GenericPageProvider : public BasePageProvider +{ + typedef std::function PageCreator; +public: + explicit GenericPageProvider(const QString &dialogTitle) + : m_dialogTitle(dialogTitle) + { + } + virtual ~GenericPageProvider() {} + + 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; +}; diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp new file mode 100644 index 00000000..816dce47 --- /dev/null +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -0,0 +1,260 @@ +/* Copyright 2013-2021 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 "AccountListPage.h" +#include "ui_AccountListPage.h" + +#include +#include + +#include + +#include "net/NetJob.h" + +#include "ui/dialogs/ProgressDialog.h" +#include "ui/dialogs/LoginDialog.h" +#include "ui/dialogs/MSALoginDialog.h" +#include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/SkinUploadDialog.h" + +#include "tasks/Task.h" +#include "minecraft/auth/AccountTask.h" +#include "minecraft/services/SkinDelete.h" + +#include "Application.h" + +#include "BuildConfig.h" + +#include "Secrets.h" + +AccountListPage::AccountListPage(QWidget *parent) + : QMainWindow(parent), ui(new Ui::AccountListPage) +{ + ui->setupUi(this); + ui->listView->setEmptyString(tr( + "Welcome!\n" + "If you're new here, you can click the \"Add\" button to add your Mojang or Minecraft account." + )); + ui->listView->setEmptyMode(VersionListView::String); + ui->listView->setContextMenuPolicy(Qt::CustomContextMenu); + + m_accounts = APPLICATION->accounts(); + + ui->listView->setModel(m_accounts.get()); + ui->listView->header()->setSectionResizeMode(0, QHeaderView::Stretch); + ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch); + ui->listView->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents); + ui->listView->setSelectionMode(QAbstractItemView::SingleSelection); + + // Expand the account column + + QItemSelectionModel *selectionModel = ui->listView->selectionModel(); + + connect(selectionModel, &QItemSelectionModel::selectionChanged, [this](const QItemSelection &sel, const QItemSelection &dsel) { + updateButtonStates(); + }); + connect(ui->listView, &VersionListView::customContextMenuRequested, this, &AccountListPage::ShowContextMenu); + + connect(m_accounts.get(), &AccountList::listChanged, this, &AccountListPage::listChanged); + connect(m_accounts.get(), &AccountList::listActivityChanged, this, &AccountListPage::listChanged); + connect(m_accounts.get(), &AccountList::defaultAccountChanged, this, &AccountListPage::listChanged); + + updateButtonStates(); + + // Xbox authentication won't work without a client identifier, so disable the button if it is missing + ui->actionAddMicrosoft->setVisible(Secrets::hasMSAClientID()); +} + +AccountListPage::~AccountListPage() +{ + delete ui; +} + +void AccountListPage::ShowContextMenu(const QPoint& pos) +{ + auto menu = ui->toolBar->createContextMenu(this, tr("Context menu")); + menu->exec(ui->listView->mapToGlobal(pos)); + delete menu; +} + +void AccountListPage::changeEvent(QEvent* event) +{ + if (event->type() == QEvent::LanguageChange) + { + ui->retranslateUi(this); + } + QMainWindow::changeEvent(event); +} + +QMenu * AccountListPage::createPopupMenu() +{ + QMenu* filteredMenu = QMainWindow::createPopupMenu(); + filteredMenu->removeAction(ui->toolBar->toggleViewAction() ); + return filteredMenu; +} + + +void AccountListPage::listChanged() +{ + updateButtonStates(); +} + +void AccountListPage::on_actionAddMojang_triggered() +{ + MinecraftAccountPtr account = LoginDialog::newAccount( + this, + tr("Please enter your Mojang account email and password to add your account.") + ); + + if (account) + { + m_accounts->addAccount(account); + if (m_accounts->count() == 1) { + m_accounts->setDefaultAccount(account); + } + } +} + +void AccountListPage::on_actionAddMicrosoft_triggered() +{ + if(BuildConfig.BUILD_PLATFORM == "osx64") { + CustomMessageBox::selectable( + this, + tr("Microsoft Accounts not available"), + tr( + "Microsoft accounts are only usable on macOS 10.13 or newer, with fully updated MultiMC.\n\n" + "Please update both your operating system and MultiMC." + ), + QMessageBox::Warning + )->exec(); + return; + } + MinecraftAccountPtr account = MSALoginDialog::newAccount( + this, + tr("Please enter your Mojang account email and password to add your account.") + ); + + if (account) + { + m_accounts->addAccount(account); + if (m_accounts->count() == 1) { + m_accounts->setDefaultAccount(account); + } + } +} + +void AccountListPage::on_actionRemove_triggered() +{ + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) + { + QModelIndex selected = selection.first(); + m_accounts->removeAccount(selected); + } +} + +void AccountListPage::on_actionRefresh_triggered() { + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) { + QModelIndex selected = selection.first(); + MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value(); + AuthSessionPtr session = std::make_shared(); + auto task = account->refresh(session); + if (task) { + ProgressDialog progDialog(this); + progDialog.execWithTask(task.get()); + // TODO: respond to results of the task + } + } +} + + +void AccountListPage::on_actionSetDefault_triggered() +{ + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) + { + QModelIndex selected = selection.first(); + MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value(); + m_accounts->setDefaultAccount(account); + } +} + +void AccountListPage::on_actionNoDefault_triggered() +{ + m_accounts->setDefaultAccount(nullptr); +} + +void AccountListPage::updateButtonStates() +{ + // If there is no selection, disable buttons that require something selected. + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + bool hasSelection = selection.size() > 0; + bool accountIsReady = false; + if (hasSelection) + { + QModelIndex selected = selection.first(); + MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value(); + accountIsReady = !account->isActive(); + } + ui->actionRemove->setEnabled(accountIsReady); + ui->actionSetDefault->setEnabled(accountIsReady); + ui->actionUploadSkin->setEnabled(accountIsReady); + ui->actionDeleteSkin->setEnabled(accountIsReady); + ui->actionRefresh->setEnabled(accountIsReady); + + if(m_accounts->defaultAccount().get() == nullptr) { + ui->actionNoDefault->setEnabled(false); + ui->actionNoDefault->setChecked(true); + } + else { + ui->actionNoDefault->setEnabled(true); + ui->actionNoDefault->setChecked(false); + } +} + +void AccountListPage::on_actionUploadSkin_triggered() +{ + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) + { + QModelIndex selected = selection.first(); + MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value(); + SkinUploadDialog dialog(account, this); + dialog.exec(); + } +} + +void AccountListPage::on_actionDeleteSkin_triggered() +{ + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() <= 0) + return; + + QModelIndex selected = selection.first(); + AuthSessionPtr session = std::make_shared(); + MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value(); + auto login = account->refresh(session); + ProgressDialog prog(this); + if (prog.execWithTask((Task*)login.get()) != QDialog::Accepted) { + CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to login!"), QMessageBox::Warning)->exec(); + return; + } + auto deleteSkinTask = std::make_shared(this, session); + if (prog.execWithTask((Task*)deleteSkinTask.get()) != QDialog::Accepted) { + CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to delete current skin!"), QMessageBox::Warning)->exec(); + return; + } +} diff --git a/launcher/ui/pages/global/AccountListPage.h b/launcher/ui/pages/global/AccountListPage.h new file mode 100644 index 00000000..1c65e708 --- /dev/null +++ b/launcher/ui/pages/global/AccountListPage.h @@ -0,0 +1,85 @@ +/* Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "ui/pages/BasePage.h" + +#include "minecraft/auth/AccountList.h" +#include "Application.h" + +namespace Ui +{ +class AccountListPage; +} + +class AuthenticateTask; + +class AccountListPage : public QMainWindow, public BasePage +{ + Q_OBJECT +public: + explicit AccountListPage(QWidget *parent = 0); + ~AccountListPage(); + + QString displayName() const override + { + return tr("Accounts"); + } + QIcon icon() const override + { + auto icon = APPLICATION->getThemedIcon("accounts"); + if(icon.isNull()) + { + icon = APPLICATION->getThemedIcon("noaccount"); + } + return icon; + } + QString id() const override + { + return "accounts"; + } + QString helpPage() const override + { + return "Getting-Started#adding-an-account"; + } + +public slots: + void on_actionAddMojang_triggered(); + void on_actionAddMicrosoft_triggered(); + void on_actionRemove_triggered(); + void on_actionRefresh_triggered(); + void on_actionSetDefault_triggered(); + void on_actionNoDefault_triggered(); + void on_actionUploadSkin_triggered(); + void on_actionDeleteSkin_triggered(); + + void listChanged(); + + //! Updates the states of the dialog's buttons. + void updateButtonStates(); + +protected slots: + void ShowContextMenu(const QPoint &pos); + +private: + void changeEvent(QEvent * event) override; + QMenu * createPopupMenu() override; + shared_qobject_ptr m_accounts; + Ui::AccountListPage *ui; +}; diff --git a/launcher/ui/pages/global/AccountListPage.ui b/launcher/ui/pages/global/AccountListPage.ui new file mode 100644 index 00000000..29738c02 --- /dev/null +++ b/launcher/ui/pages/global/AccountListPage.ui @@ -0,0 +1,129 @@ + + + AccountListPage + + + + 0 + 0 + 800 + 600 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + false + + + false + + + true + + + false + + + + + + + + RightToolBarArea + + + false + + + + + + + + + + + + + + Add Mojang + + + + + Remove + + + + + Set Default + + + + + true + + + No Default + + + + + Upload Skin + + + + + Delete Skin + + + Delete the currently active skin and go back to the default one + + + + + Add Microsoft + + + + + Refresh + + + Refresh the account tokens + + + + + + VersionListView + QTreeView +
ui/widgets/VersionListView.h
+
+ + WideBar + QToolBar +
ui/widgets/WideBar.h
+
+
+ + +
diff --git a/launcher/ui/pages/global/CustomCommandsPage.cpp b/launcher/ui/pages/global/CustomCommandsPage.cpp new file mode 100644 index 00000000..8541e3c1 --- /dev/null +++ b/launcher/ui/pages/global/CustomCommandsPage.cpp @@ -0,0 +1,51 @@ +#include "CustomCommandsPage.h" +#include +#include +#include + +CustomCommandsPage::CustomCommandsPage(QWidget* parent): QWidget(parent) +{ + + auto verticalLayout = new QVBoxLayout(this); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + verticalLayout->setContentsMargins(0, 0, 0, 0); + + auto tabWidget = new QTabWidget(this); + tabWidget->setObjectName(QStringLiteral("tabWidget")); + commands = new CustomCommands(this); + commands->setContentsMargins(6, 6, 6, 6); + tabWidget->addTab(commands, "Foo"); + tabWidget->tabBar()->hide(); + verticalLayout->addWidget(tabWidget); + loadSettings(); +} + +CustomCommandsPage::~CustomCommandsPage() +{ +} + +bool CustomCommandsPage::apply() +{ + applySettings(); + return true; +} + +void CustomCommandsPage::applySettings() +{ + auto s = APPLICATION->settings(); + s->set("PreLaunchCommand", commands->prelaunchCommand()); + s->set("WrapperCommand", commands->wrapperCommand()); + s->set("PostExitCommand", commands->postexitCommand()); +} + +void CustomCommandsPage::loadSettings() +{ + auto s = APPLICATION->settings(); + commands->initialize( + false, + true, + s->get("PreLaunchCommand").toString(), + s->get("WrapperCommand").toString(), + s->get("PostExitCommand").toString() + ); +} diff --git a/launcher/ui/pages/global/CustomCommandsPage.h b/launcher/ui/pages/global/CustomCommandsPage.h new file mode 100644 index 00000000..a1155e0e --- /dev/null +++ b/launcher/ui/pages/global/CustomCommandsPage.h @@ -0,0 +1,55 @@ +/* Copyright 2018-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "ui/pages/BasePage.h" +#include +#include "ui/widgets/CustomCommands.h" + +class CustomCommandsPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit CustomCommandsPage(QWidget *parent = 0); + ~CustomCommandsPage(); + + QString displayName() const override + { + return tr("Custom Commands"); + } + QIcon icon() const override + { + return APPLICATION->getThemedIcon("custom-commands"); + } + QString id() const override + { + return "custom-commands"; + } + QString helpPage() const override + { + return "Custom-commands"; + } + bool apply() override; + +private: + void applySettings(); + void loadSettings(); + CustomCommands * commands; +}; diff --git a/launcher/ui/pages/global/ExternalToolsPage.cpp b/launcher/ui/pages/global/ExternalToolsPage.cpp new file mode 100644 index 00000000..41d900aa --- /dev/null +++ b/launcher/ui/pages/global/ExternalToolsPage.cpp @@ -0,0 +1,233 @@ +/* Copyright 2013-2021 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 + +#include "settings/SettingsObject.h" +#include "tools/BaseProfiler.h" +#include +#include "Application.h" +#include + +ExternalToolsPage::ExternalToolsPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::ExternalToolsPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + + #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + ui->jsonEditorTextBox->setClearButtonEnabled(true); + #endif + + ui->mceditLink->setOpenExternalLinks(true); + ui->jvisualvmLink->setOpenExternalLinks(true); + ui->jprofilerLink->setOpenExternalLinks(true); + loadSettings(); +} + +ExternalToolsPage::~ExternalToolsPage() +{ + delete ui; +} + +void ExternalToolsPage::loadSettings() +{ + auto s = APPLICATION->settings(); + ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString()); + ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString()); + ui->mceditPathEdit->setText(s->get("MCEditPath").toString()); + + // Editors + ui->jsonEditorTextBox->setText(s->get("JsonEditor").toString()); +} +void ExternalToolsPage::applySettings() +{ + auto s = APPLICATION->settings(); + + s->set("JProfilerPath", ui->jprofilerPathEdit->text()); + s->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); + s->set("MCEditPath", ui->mceditPathEdit->text()); + + // Editors + QString jsonEditor = ui->jsonEditorTextBox->text(); + if (!jsonEditor.isEmpty() && + (!QFileInfo(jsonEditor).exists() || !QFileInfo(jsonEditor).isExecutable())) + { + QString found = QStandardPaths::findExecutable(jsonEditor); + if (!found.isEmpty()) + { + jsonEditor = found; + } + } + s->set("JsonEditor", jsonEditor); +} + +void ExternalToolsPage::on_jprofilerPathBtn_clicked() +{ + QString raw_dir = ui->jprofilerPathEdit->text(); + QString error; + do + { + raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Folder"), raw_dir); + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = FS::NormalizePath(raw_dir); + if (!APPLICATION->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 (!APPLICATION->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 = FS::NormalizePath(raw_dir); + if (!APPLICATION->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 (!APPLICATION->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 + raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir); +#else + raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Folder"), raw_dir); +#endif + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = FS::NormalizePath(raw_dir); + if (!APPLICATION->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 (!APPLICATION->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")); + } +} + +void ExternalToolsPage::on_jsonEditorBrowseBtn_clicked() +{ + QString raw_file = QFileDialog::getOpenFileName( + this, tr("JSON Editor"), + ui->jsonEditorTextBox->text().isEmpty() +#if defined(Q_OS_LINUX) + ? QString("/usr/bin") +#else + ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() +#endif + : ui->jsonEditorTextBox->text()); + + if (raw_file.isEmpty()) + { + return; + } + QString cooked_file = FS::NormalizePath(raw_file); + + // it has to exist and be an executable + if (QFileInfo(cooked_file).exists() && QFileInfo(cooked_file).isExecutable()) + { + ui->jsonEditorTextBox->setText(cooked_file); + } + else + { + QMessageBox::warning(this, tr("Invalid"), + tr("The file chosen does not seem to be an executable")); + } +} + +bool ExternalToolsPage::apply() +{ + applySettings(); + return true; +} diff --git a/launcher/ui/pages/global/ExternalToolsPage.h b/launcher/ui/pages/global/ExternalToolsPage.h new file mode 100644 index 00000000..5ae6148d --- /dev/null +++ b/launcher/ui/pages/global/ExternalToolsPage.h @@ -0,0 +1,74 @@ +/* Copyright 2013-2021 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 "ui/pages/BasePage.h" +#include + +namespace Ui { +class ExternalToolsPage; +} + +class ExternalToolsPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit ExternalToolsPage(QWidget *parent = 0); + ~ExternalToolsPage(); + + QString displayName() const override + { + return tr("External Tools"); + } + QIcon icon() const override + { + auto icon = APPLICATION->getThemedIcon("externaltools"); + if(icon.isNull()) + { + icon = APPLICATION->getThemedIcon("loadermods"); + } + return icon; + } + QString id() const override + { + return "external-tools"; + } + QString helpPage() const override + { + return "Tools"; + } + virtual bool apply() override; + +private: + void loadSettings(); + void applySettings(); + +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(); + void on_jsonEditorBrowseBtn_clicked(); +}; diff --git a/launcher/ui/pages/global/ExternalToolsPage.ui b/launcher/ui/pages/global/ExternalToolsPage.ui new file mode 100644 index 00000000..e79e9388 --- /dev/null +++ b/launcher/ui/pages/global/ExternalToolsPage.ui @@ -0,0 +1,194 @@ + + + ExternalToolsPage + + + + 0 + 0 + 673 + 751 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + JProfiler + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + <html><head/><body><p><a href="https://www.ej-technologies.com/products/jprofiler/overview.html">https://www.ej-technologies.com/products/jprofiler/overview.html</a></p></body></html> + + + + + + + + + + JVisualVM + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + <html><head/><body><p><a href="https://visualvm.github.io/">https://visualvm.github.io/</a></p></body></html> + + + + + + + + + + MCEdit + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + <html><head/><body><p><a href="https://www.mcedit.net/">https://www.mcedit.net/</a></p></body></html> + + + + + + + + + + External Editors (leave empty for system default) + + + + + + + + + Text Editor: + + + + + + + ... + + + + + + + + + + Qt::Vertical + + + + 20 + 216 + + + + + + + + + + + + + diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp new file mode 100644 index 00000000..bd79f11a --- /dev/null +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -0,0 +1,153 @@ +/* Copyright 2013-2021 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 "JavaPage.h" +#include "JavaCommon.h" +#include "ui_JavaPage.h" + +#include +#include +#include +#include + +#include "ui/dialogs/VersionSelectDialog.h" + +#include "java/JavaUtils.h" +#include "java/JavaInstallList.h" + +#include "settings/SettingsObject.h" +#include +#include "Application.h" +#include + +JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + ui->maxMemSpinBox->setMaximum(sysMiB); + loadSettings(); +} + +JavaPage::~JavaPage() +{ + delete ui; +} + +bool JavaPage::apply() +{ + applySettings(); + return true; +} + +void JavaPage::applySettings() +{ + auto s = APPLICATION->settings(); + + // Memory + int min = ui->minMemSpinBox->value(); + int max = ui->maxMemSpinBox->value(); + if(min < max) + { + s->set("MinMemAlloc", min); + s->set("MaxMemAlloc", max); + } + else + { + s->set("MinMemAlloc", max); + s->set("MaxMemAlloc", min); + } + s->set("PermGen", ui->permGenSpinBox->value()); + + // Java Settings + s->set("JavaPath", ui->javaPathTextBox->text()); + s->set("JvmArgs", ui->jvmArgsTextBox->text()); + JavaCommon::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget()); +} +void JavaPage::loadSettings() +{ + auto s = APPLICATION->settings(); + // Memory + int min = s->get("MinMemAlloc").toInt(); + int max = s->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(s->get("PermGen").toInt()); + + // Java Settings + ui->javaPathTextBox->setText(s->get("JavaPath").toString()); + ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); +} + +void JavaPage::on_javaDetectBtn_clicked() +{ + JavaInstallPtr java; + + VersionSelectDialog vselect(APPLICATION->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 JavaPage::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 JavaPage::on_javaTestBtn_clicked() +{ + if(checker) + { + return; + } + checker.reset(new JavaCommon::TestCheck( + this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->text(), + ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value())); + connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished())); + checker->run(); +} + +void JavaPage::checkerFinished() +{ + checker.reset(); +} diff --git a/launcher/ui/pages/global/JavaPage.h b/launcher/ui/pages/global/JavaPage.h new file mode 100644 index 00000000..8f9b3323 --- /dev/null +++ b/launcher/ui/pages/global/JavaPage.h @@ -0,0 +1,72 @@ +/* Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include "ui/pages/BasePage.h" +#include "JavaCommon.h" +#include +#include + +class SettingsObject; + +namespace Ui +{ +class JavaPage; +} + +class JavaPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit JavaPage(QWidget *parent = 0); + ~JavaPage(); + + QString displayName() const override + { + return tr("Java"); + } + QIcon icon() const override + { + return APPLICATION->getThemedIcon("java"); + } + QString id() const override + { + return "java-settings"; + } + QString helpPage() const override + { + return "Java-settings"; + } + bool apply() override; + +private: + void applySettings(); + void loadSettings(); + +private +slots: + void on_javaDetectBtn_clicked(); + void on_javaTestBtn_clicked(); + void on_javaBrowseBtn_clicked(); + void checkerFinished(); + +private: + Ui::JavaPage *ui; + unique_qobject_ptr checker; +}; diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui new file mode 100644 index 00000000..b67e9994 --- /dev/null +++ b/launcher/ui/pages/global/JavaPage.ui @@ -0,0 +1,260 @@ + + + JavaPage + + + + 0 + 0 + 545 + 580 + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + Memory + + + + + + The maximum amount of memory Minecraft is allowed to use. + + + MiB + + + 128 + + + 65536 + + + 128 + + + 1024 + + + + + + + Minimum memory allocation: + + + + + + + Maximum memory allocation: + + + + + + + The amount of memory Minecraft is started with. + + + MiB + + + 128 + + + 65536 + + + 128 + + + 256 + + + + + + + PermGen: + + + + + + + The amount of memory available to store loaded Java classes. + + + MiB + + + 64 + + + 999999999 + + + 8 + + + 64 + + + + + + + + + + Java Runtime + + + + + + + 0 + 0 + + + + Java path: + + + + + + + + + + + + + 0 + 0 + +