summaryrefslogtreecommitdiffstats
path: root/application/pages
diff options
context:
space:
mode:
authorThomas Groman <tgroman@nuegia.net>2019-09-19 00:41:48 -0700
committerThomas Groman <tgroman@nuegia.net>2019-09-19 00:41:48 -0700
commit32b3ed0a1362a4b0798ad71fac3450fb77cb7e41 (patch)
tree7be7a2f602e6a5af7bc2db86bef9cf2a659c3d3d /application/pages
parent5fb2c6334e7d5237db11695b4c0ec0f2d1e47c88 (diff)
downloadMultiMC-32b3ed0a1362a4b0798ad71fac3450fb77cb7e41.tar
MultiMC-32b3ed0a1362a4b0798ad71fac3450fb77cb7e41.tar.gz
MultiMC-32b3ed0a1362a4b0798ad71fac3450fb77cb7e41.tar.lz
MultiMC-32b3ed0a1362a4b0798ad71fac3450fb77cb7e41.tar.xz
MultiMC-32b3ed0a1362a4b0798ad71fac3450fb77cb7e41.zip
merged from 0.6.7 codebase
Diffstat (limited to 'application/pages')
-rw-r--r--application/pages/BasePage.h56
-rw-r--r--application/pages/BasePageContainer.h8
-rw-r--r--application/pages/BasePageProvider.h67
-rw-r--r--application/pages/global/AccountListPage.cpp194
-rw-r--r--application/pages/global/AccountListPage.h83
-rw-r--r--application/pages/global/AccountListPage.ui182
-rw-r--r--application/pages/global/CustomCommandsPage.cpp49
-rw-r--r--application/pages/global/CustomCommandsPage.h48
-rw-r--r--application/pages/global/ExternalToolsPage.cpp307
-rw-r--r--application/pages/global/ExternalToolsPage.h72
-rw-r--r--application/pages/global/ExternalToolsPage.ui4
-rw-r--r--application/pages/global/JavaPage.cpp167
-rw-r--r--application/pages/global/JavaPage.h58
-rw-r--r--application/pages/global/LanguagePage.cpp51
-rw-r--r--application/pages/global/LanguagePage.h60
-rw-r--r--application/pages/global/MinecraftPage.cpp45
-rw-r--r--application/pages/global/MinecraftPage.h52
-rw-r--r--application/pages/global/MultiMCPage.cpp565
-rw-r--r--application/pages/global/MultiMCPage.h100
-rw-r--r--application/pages/global/MultiMCPage.ui15
-rw-r--r--application/pages/global/PackagesPage.cpp288
-rw-r--r--application/pages/global/PackagesPage.h40
-rw-r--r--application/pages/global/PasteEEPage.cpp63
-rw-r--r--application/pages/global/PasteEEPage.h52
-rw-r--r--application/pages/global/ProxyPage.cpp97
-rw-r--r--application/pages/global/ProxyPage.h52
-rw-r--r--application/pages/instance/GameOptionsPage.cpp40
-rw-r--r--application/pages/instance/GameOptionsPage.h63
-rw-r--r--application/pages/instance/GameOptionsPage.ui88
-rw-r--r--application/pages/instance/InstanceSettingsPage.cpp422
-rw-r--r--application/pages/instance/InstanceSettingsPage.h66
-rw-r--r--application/pages/instance/InstanceSettingsPage.ui15
-rw-r--r--application/pages/instance/LegacyUpgradePage.cpp44
-rw-r--r--application/pages/instance/LegacyUpgradePage.h50
-rw-r--r--application/pages/instance/LogPage.cpp446
-rw-r--r--application/pages/instance/LogPage.h82
-rw-r--r--application/pages/instance/ModFolderPage.cpp377
-rw-r--r--application/pages/instance/ModFolderPage.h129
-rw-r--r--application/pages/instance/ModFolderPage.ui275
-rw-r--r--application/pages/instance/NotesPage.cpp13
-rw-r--r--application/pages/instance/NotesPage.h52
-rw-r--r--application/pages/instance/NotesPage.ui40
-rw-r--r--application/pages/instance/OtherLogsPage.cpp420
-rw-r--r--application/pages/instance/OtherLogsPage.h78
-rw-r--r--application/pages/instance/ResourcePackPage.h25
-rw-r--r--application/pages/instance/ScreenshotsPage.cpp608
-rw-r--r--application/pages/instance/ScreenshotsPage.h91
-rw-r--r--application/pages/instance/ScreenshotsPage.ui162
-rw-r--r--application/pages/instance/ServersPage.cpp760
-rw-r--r--application/pages/instance/ServersPage.h93
-rw-r--r--application/pages/instance/ServersPage.ui191
-rw-r--r--application/pages/instance/TexturePackPage.h23
-rw-r--r--application/pages/instance/VersionPage.cpp971
-rw-r--r--application/pages/instance/VersionPage.h108
-rw-r--r--application/pages/instance/VersionPage.ui516
-rw-r--r--application/pages/instance/WorldListPage.cpp432
-rw-r--r--application/pages/instance/WorldListPage.h105
-rw-r--r--application/pages/instance/WorldListPage.ui266
-rw-r--r--application/pages/modplatform/FTBPage.cpp434
-rw-r--r--application/pages/modplatform/FTBPage.h104
-rw-r--r--application/pages/modplatform/FTBPage.ui159
-rw-r--r--application/pages/modplatform/FtbListModel.cpp275
-rw-r--r--application/pages/modplatform/FtbListModel.h68
-rw-r--r--application/pages/modplatform/ImportPage.cpp161
-rw-r--r--application/pages/modplatform/ImportPage.h56
-rw-r--r--application/pages/modplatform/TechnicPage.cpp13
-rw-r--r--application/pages/modplatform/TechnicPage.h50
-rw-r--r--application/pages/modplatform/TwitchPage.cpp47
-rw-r--r--application/pages/modplatform/TwitchPage.h58
-rw-r--r--application/pages/modplatform/TwitchPage.ui33
-rw-r--r--application/pages/modplatform/VanillaPage.cpp94
-rw-r--r--application/pages/modplatform/VanillaPage.h64
-rw-r--r--application/pages/modplatform/VanillaPage.ui20
73 files changed, 6747 insertions, 4715 deletions
diff --git a/application/pages/BasePage.h b/application/pages/BasePage.h
index d4547770..2ad56d71 100644
--- a/application/pages/BasePage.h
+++ b/application/pages/BasePage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,35 +24,35 @@
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;
- };
+ 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;
+ int stackIndex = -1;
+ int listIndex = -1;
protected:
- BasePageContainer * m_container = nullptr;
- bool isOpened = false;
+ BasePageContainer * m_container = nullptr;
+ bool isOpened = false;
};
typedef std::shared_ptr<BasePage> BasePagePtr;
diff --git a/application/pages/BasePageContainer.h b/application/pages/BasePageContainer.h
index ff7315c2..f8c7adeb 100644
--- a/application/pages/BasePageContainer.h
+++ b/application/pages/BasePageContainer.h
@@ -3,8 +3,8 @@
class BasePageContainer
{
public:
- virtual ~BasePageContainer(){};
- virtual bool selectPage(QString pageId) = 0;
- virtual void refreshContainer() = 0;
- virtual bool requestClose() = 0;
+ virtual ~BasePageContainer(){};
+ virtual bool selectPage(QString pageId) = 0;
+ virtual void refreshContainer() = 0;
+ virtual bool requestClose() = 0;
};
diff --git a/application/pages/BasePageProvider.h b/application/pages/BasePageProvider.h
index 1cc7458a..ad29f163 100644
--- a/application/pages/BasePageProvider.h
+++ b/application/pages/BasePageProvider.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,46 +22,47 @@
class BasePageProvider
{
public:
- virtual QList<BasePage *> getPages() = 0;
- virtual QString dialogTitle() = 0;
+ virtual QList<BasePage *> getPages() = 0;
+ virtual QString dialogTitle() = 0;
};
class GenericPageProvider : public BasePageProvider
{
- typedef std::function<BasePage *()> PageCreator;
+ typedef std::function<BasePage *()> PageCreator;
public:
- explicit GenericPageProvider(const QString &dialogTitle)
- : m_dialogTitle(dialogTitle)
- {
- }
+ explicit GenericPageProvider(const QString &dialogTitle)
+ : m_dialogTitle(dialogTitle)
+ {
+ }
+ virtual ~GenericPageProvider() {}
- QList<BasePage *> getPages() override
- {
- QList<BasePage *> pages;
- for (PageCreator creator : m_creators)
- {
- pages.append(creator());
- }
- return pages;
- }
- QString dialogTitle() override { return m_dialogTitle; }
+ QList<BasePage *> getPages() override
+ {
+ QList<BasePage *> 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);
- }
+ void setDialogTitle(const QString &title)
+ {
+ m_dialogTitle = title;
+ }
+ void addPageCreator(PageCreator page)
+ {
+ m_creators.append(page);
+ }
- template<typename PageClass>
- void addPage()
- {
- addPageCreator([](){return new PageClass();});
- }
+ template<typename PageClass>
+ void addPage()
+ {
+ addPageCreator([](){return new PageClass();});
+ }
private:
- QList<PageCreator> m_creators;
- QString m_dialogTitle;
+ QList<PageCreator> m_creators;
+ QString m_dialogTitle;
};
diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp
index 63943174..c14134f3 100644
--- a/application/pages/global/AccountListPage.cpp
+++ b/application/pages/global/AccountListPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
#include "ui_AccountListPage.h"
#include <QItemSelectionModel>
+#include <QMenu>
#include <QDebug>
@@ -34,120 +35,159 @@
#include "MultiMC.h"
AccountListPage::AccountListPage(QWidget *parent)
- : QWidget(parent), ui(new Ui::AccountListPage)
+ : QMainWindow(parent), ui(new Ui::AccountListPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+ 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 = MMC->accounts();
+ m_accounts = MMC->accounts();
- ui->listView->setModel(m_accounts.get());
- ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ ui->listView->setModel(m_accounts.get());
+ ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
- // Expand the account column
- ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
+ // Expand the account column
+ ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
- QItemSelectionModel *selectionModel = ui->listView->selectionModel();
+ QItemSelectionModel *selectionModel = ui->listView->selectionModel();
- connect(selectionModel, &QItemSelectionModel::selectionChanged,
- [this](const QItemSelection &sel, const QItemSelection &dsel)
- { updateButtonStates(); });
+ connect(selectionModel, &QItemSelectionModel::selectionChanged, [this](const QItemSelection &sel, const QItemSelection &dsel) {
+ updateButtonStates();
+ });
+ connect(ui->listView, &VersionListView::customContextMenuRequested, this, &AccountListPage::ShowContextMenu);
- connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
- connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
+ connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
+ connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
- updateButtonStates();
+ updateButtonStates();
}
AccountListPage::~AccountListPage()
{
- delete ui;
+ 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();
+ updateButtonStates();
}
-void AccountListPage::on_addAccountBtn_clicked()
+void AccountListPage::on_actionAdd_triggered()
{
- addAccount(tr("Please enter your Mojang or Minecraft account username and password to add "
- "your account."));
+ addAccount(tr("Please enter your Mojang or Minecraft account username and password to add "
+ "your account."));
}
-void AccountListPage::on_rmAccountBtn_clicked()
+void AccountListPage::on_actionRemove_triggered()
{
- QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
- if (selection.size() > 0)
- {
- QModelIndex selected = selection.first();
- m_accounts->removeAccount(selected);
- }
+ QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
+ if (selection.size() > 0)
+ {
+ QModelIndex selected = selection.first();
+ m_accounts->removeAccount(selected);
+ }
}
-void AccountListPage::on_setDefaultBtn_clicked()
+void AccountListPage::on_actionSetDefault_triggered()
{
- QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
- if (selection.size() > 0)
- {
- QModelIndex selected = selection.first();
- MojangAccountPtr account =
- selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
- m_accounts->setActiveAccount(account->username());
- }
+ QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
+ if (selection.size() > 0)
+ {
+ QModelIndex selected = selection.first();
+ MojangAccountPtr account =
+ selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
+ m_accounts->setActiveAccount(account->username());
+ }
}
-void AccountListPage::on_noDefaultBtn_clicked()
+void AccountListPage::on_actionNoDefault_triggered()
{
- m_accounts->setActiveAccount("");
+ m_accounts->setActiveAccount("");
}
void AccountListPage::updateButtonStates()
{
- // If there is no selection, disable buttons that require something selected.
- QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
-
- ui->rmAccountBtn->setEnabled(selection.size() > 0);
- ui->setDefaultBtn->setEnabled(selection.size() > 0);
- ui->uploadSkinBtn->setEnabled(selection.size() > 0);
+ // If there is no selection, disable buttons that require something selected.
+ QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
+
+ ui->actionRemove->setEnabled(selection.size() > 0);
+ ui->actionSetDefault->setEnabled(selection.size() > 0);
+ ui->actionUploadSkin->setEnabled(selection.size() > 0);
+
+ if(m_accounts->activeAccount().get() == nullptr) {
+ ui->actionNoDefault->setEnabled(false);
+ ui->actionNoDefault->setChecked(true);
+ }
+ else {
+ ui->actionNoDefault->setEnabled(true);
+ ui->actionNoDefault->setChecked(false);
+ }
- ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr);
}
void AccountListPage::addAccount(const QString &errMsg)
{
- // TODO: The login dialog isn't quite done yet
- MojangAccountPtr account = LoginDialog::newAccount(this, errMsg);
-
- if (account != nullptr)
- {
- m_accounts->addAccount(account);
- if (m_accounts->count() == 1)
- m_accounts->setActiveAccount(account->username());
-
- // Grab associated player skins
- auto job = new NetJob("Player skins: " + account->username());
-
- for (AccountProfile profile : account->profiles())
- {
- auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
- auto action = Net::Download::makeCached(QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
- job->addNetAction(action);
- meta->setStale(true);
- }
-
- job->start();
- }
+ // TODO: The login dialog isn't quite done yet
+ MojangAccountPtr account = LoginDialog::newAccount(this, errMsg);
+
+ if (account != nullptr)
+ {
+ m_accounts->addAccount(account);
+ if (m_accounts->count() == 1)
+ m_accounts->setActiveAccount(account->username());
+
+ // Grab associated player skins
+ auto job = new NetJob("Player skins: " + account->username());
+
+ for (AccountProfile profile : account->profiles())
+ {
+ auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
+ auto action = Net::Download::makeCached(QUrl(URLConstants::SKINS_BASE + profile.id + ".png"), meta);
+ job->addNetAction(action);
+ meta->setStale(true);
+ }
+
+ job->start();
+ }
}
-void AccountListPage::on_uploadSkinBtn_clicked()
+void AccountListPage::on_actionUploadSkin_triggered()
{
- QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
- if (selection.size() > 0)
- {
- QModelIndex selected = selection.first();
- MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
- SkinUploadDialog dialog(account, this);
- dialog.exec();
- }
+ QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
+ if (selection.size() > 0)
+ {
+ QModelIndex selected = selection.first();
+ MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
+ SkinUploadDialog dialog(account, this);
+ dialog.exec();
+ }
}
diff --git a/application/pages/global/AccountListPage.h b/application/pages/global/AccountListPage.h
index fa5561fe..4c8bc00b 100644
--- a/application/pages/global/AccountListPage.h
+++ b/application/pages/global/AccountListPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
#pragma once
-#include <QDialog>
+#include <QMainWindow>
#include <memory>
#include "pages/BasePage.h"
@@ -30,59 +30,64 @@ class AccountListPage;
class AuthenticateTask;
-class AccountListPage : public QWidget, public BasePage
+class AccountListPage : public QMainWindow, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit AccountListPage(QWidget *parent = 0);
- ~AccountListPage();
-
- QString displayName() const override
- {
- return tr("Accounts");
- }
- QIcon icon() const override
- {
- auto icon = MMC->getThemedIcon("accounts");
- if(icon.isNull())
- {
- icon = MMC->getThemedIcon("noaccount");
- }
- return icon;
- }
- QString id() const override
- {
- return "accounts";
- }
- QString helpPage() const override
- {
- return "Getting-Started#adding-an-account";
- }
+ explicit AccountListPage(QWidget *parent = 0);
+ ~AccountListPage();
+
+ QString displayName() const override
+ {
+ return tr("Accounts");
+ }
+ QIcon icon() const override
+ {
+ auto icon = MMC->getThemedIcon("accounts");
+ if(icon.isNull())
+ {
+ icon = MMC->getThemedIcon("noaccount");
+ }
+ return icon;
+ }
+ QString id() const override
+ {
+ return "accounts";
+ }
+ QString helpPage() const override
+ {
+ return "Getting-Started#adding-an-account";
+ }
+
+private:
+ void changeEvent(QEvent * event) override;
+ QMenu * createPopupMenu() override;
public
slots:
- void on_addAccountBtn_clicked();
+ void on_actionAdd_triggered();
- void on_rmAccountBtn_clicked();
+ void on_actionRemove_triggered();
- void on_setDefaultBtn_clicked();
+ void on_actionSetDefault_triggered();
- void on_noDefaultBtn_clicked();
+ void on_actionNoDefault_triggered();
- void on_uploadSkinBtn_clicked();
+ void on_actionUploadSkin_triggered();
- void listChanged();
+ void listChanged();
- //! Updates the states of the dialog's buttons.
- void updateButtonStates();
+ //! Updates the states of the dialog's buttons.
+ void updateButtonStates();
protected:
- std::shared_ptr<MojangAccountList> m_accounts;
+ std::shared_ptr<MojangAccountList> m_accounts;
protected
slots:
- void addAccount(const QString& errMsg="");
+ void ShowContextMenu(const QPoint &pos);
+ void addAccount(const QString& errMsg="");
private:
- Ui::AccountListPage *ui;
+ Ui::AccountListPage *ui;
};
diff --git a/application/pages/global/AccountListPage.ui b/application/pages/global/AccountListPage.ui
index f4e87680..433c1f7f 100644
--- a/application/pages/global/AccountListPage.ui
+++ b/application/pages/global/AccountListPage.ui
@@ -1,122 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AccountListPage</class>
- <widget class="QWidget" name="AccountListPage">
+ <widget class="QMainWindow" name="AccountListPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>694</width>
- <height>609</height>
+ <width>800</width>
+ <height>600</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <property name="leftMargin">
- <number>0</number>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="VersionListView" name="listView"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="WideBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>RightToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionAdd"/>
+ <addaction name="actionRemove"/>
+ <addaction name="actionSetDefault"/>
+ <addaction name="actionNoDefault"/>
+ <addaction name="actionUploadSkin"/>
+ </widget>
+ <action name="actionAdd">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </action>
+ <action name="actionRemove">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </action>
+ <action name="actionSetDefault">
+ <property name="text">
+ <string>Set Default</string>
</property>
- <property name="topMargin">
- <number>0</number>
+ </action>
+ <action name="actionNoDefault">
+ <property name="checkable">
+ <bool>true</bool>
</property>
- <property name="rightMargin">
- <number>0</number>
+ <property name="text">
+ <string>No Default</string>
</property>
- <property name="bottomMargin">
- <number>0</number>
+ </action>
+ <action name="actionUploadSkin">
+ <property name="text">
+ <string>Upload Skin</string>
</property>
- <item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
- </property>
- <widget class="QWidget" name="tab">
- <attribute name="title">
- <string notr="true">Tab 1</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="welcomeLabel">
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Welcome! If you're new here, you can click the &amp;quot;Add&amp;quot; button to add your Mojang or Minecraft account.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QTreeView" name="listView"/>
- </item>
- <item>
- <layout class="QVBoxLayout" name="manageAcctsBtnBox">
- <item>
- <widget class="QPushButton" name="addAccountBtn">
- <property name="text">
- <string>&amp;Add</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="rmAccountBtn">
- <property name="text">
- <string>&amp;Remove</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="buttonSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="setDefaultBtn">
- <property name="toolTip">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the currently selected account as the active account. The active account is the account that is used to log in (unless it is overridden in an instance-specific setting).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="text">
- <string>&amp;Set Default</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="noDefaultBtn">
- <property name="toolTip">
- <string>Set no default account. This will cause MultiMC to prompt you to select an account every time you launch an instance that doesn't have its own default set.</string>
- </property>
- <property name="text">
- <string>&amp;No Default</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="uploadSkinBtn">
- <property name="toolTip">
- <string>Opens a dialog to select and upload a skin image to the selected account.</string>
- </property>
- <property name="text">
- <string>&amp;Upload Skin</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
+ </action>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>VersionListView</class>
+ <extends>QTreeView</extends>
+ <header>widgets/VersionListView.h</header>
+ </customwidget>
+ <customwidget>
+ <class>WideBar</class>
+ <extends>QToolBar</extends>
+ <header>widgets/WideBar.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>
diff --git a/application/pages/global/CustomCommandsPage.cpp b/application/pages/global/CustomCommandsPage.cpp
index 1352b6be..3b182319 100644
--- a/application/pages/global/CustomCommandsPage.cpp
+++ b/application/pages/global/CustomCommandsPage.cpp
@@ -6,17 +6,18 @@
CustomCommandsPage::CustomCommandsPage(QWidget* parent): QWidget(parent)
{
- auto verticalLayout = new QVBoxLayout(this);
- verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
- verticalLayout->setContentsMargins(0, 0, 0, 0);
+ 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);
- tabWidget->addTab(commands, "Foo");
- tabWidget->tabBar()->hide();
- verticalLayout->addWidget(tabWidget);
- loadSettings();
+ 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()
@@ -25,26 +26,26 @@ CustomCommandsPage::~CustomCommandsPage()
bool CustomCommandsPage::apply()
{
- applySettings();
- return true;
+ applySettings();
+ return true;
}
void CustomCommandsPage::applySettings()
{
- auto s = MMC->settings();
- s->set("PreLaunchCommand", commands->prelaunchCommand());
- s->set("WrapperCommand", commands->wrapperCommand());
- s->set("PostExitCommand", commands->postexitCommand());
+ auto s = MMC->settings();
+ s->set("PreLaunchCommand", commands->prelaunchCommand());
+ s->set("WrapperCommand", commands->wrapperCommand());
+ s->set("PostExitCommand", commands->postexitCommand());
}
void CustomCommandsPage::loadSettings()
{
- auto s = MMC->settings();
- commands->initialize(
- false,
- true,
- s->get("PreLaunchCommand").toString(),
- s->get("WrapperCommand").toString(),
- s->get("PostExitCommand").toString()
- );
+ auto s = MMC->settings();
+ commands->initialize(
+ false,
+ true,
+ s->get("PreLaunchCommand").toString(),
+ s->get("WrapperCommand").toString(),
+ s->get("PostExitCommand").toString()
+ );
}
diff --git a/application/pages/global/CustomCommandsPage.h b/application/pages/global/CustomCommandsPage.h
index 52256ed3..a9047e63 100644
--- a/application/pages/global/CustomCommandsPage.h
+++ b/application/pages/global/CustomCommandsPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2018-2018 MultiMC Contributors
+/* Copyright 2018-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,32 +24,32 @@
class CustomCommandsPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit CustomCommandsPage(QWidget *parent = 0);
- ~CustomCommandsPage();
+ explicit CustomCommandsPage(QWidget *parent = 0);
+ ~CustomCommandsPage();
- QString displayName() const override
- {
- return tr("Custom Commands");
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("custom-commands");
- }
- QString id() const override
- {
- return "custom-commands";
- }
- QString helpPage() const override
- {
- return "Custom-commands";
- }
- bool apply() override;
+ QString displayName() const override
+ {
+ return tr("Custom Commands");
+ }
+ QIcon icon() const override
+ {
+ return MMC->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;
+ void applySettings();
+ void loadSettings();
+ CustomCommands * commands;
};
diff --git a/application/pages/global/ExternalToolsPage.cpp b/application/pages/global/ExternalToolsPage.cpp
index 20887b54..7de6f858 100644
--- a/application/pages/global/ExternalToolsPage.cpp
+++ b/application/pages/global/ExternalToolsPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QStandardPaths>
+#include <QTabBar>
#include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h"
@@ -28,206 +29,206 @@
#include <QTabBar>
ExternalToolsPage::ExternalToolsPage(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::ExternalToolsPage)
+ QWidget(parent),
+ ui(new Ui::ExternalToolsPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
- #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
- ui->jsonEditorTextBox->setClearButtonEnabled(true);
- #endif
+ #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();
+ ui->mceditLink->setOpenExternalLinks(true);
+ ui->jvisualvmLink->setOpenExternalLinks(true);
+ ui->jprofilerLink->setOpenExternalLinks(true);
+ loadSettings();
}
ExternalToolsPage::~ExternalToolsPage()
{
- delete ui;
+ delete ui;
}
void ExternalToolsPage::loadSettings()
{
- auto s = MMC->settings();
- ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString());
- ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString());
- ui->mceditPathEdit->setText(s->get("MCEditPath").toString());
+ auto s = MMC->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());
+ // Editors
+ ui->jsonEditorTextBox->setText(s->get("JsonEditor").toString());
}
void ExternalToolsPage::applySettings()
{
- auto s = MMC->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);
+ auto s = MMC->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 (!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);
+ 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 (!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"));
- }
+ 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 = FS::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);
+ 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 (!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"));
- }
+ 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
- {
+ QString raw_dir = ui->mceditPathEdit->text();
+ QString error;
+ do
+ {
#ifdef Q_OS_OSX
- raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir);
+ raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir);
#else
- raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Folder"), raw_dir);
+ raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Folder"), raw_dir);
#endif
- if (raw_dir.isEmpty())
- {
- break;
- }
- QString cooked_dir = FS::NormalizePath(raw_dir);
- if (!MMC->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);
+ if (raw_dir.isEmpty())
+ {
+ break;
+ }
+ QString cooked_dir = FS::NormalizePath(raw_dir);
+ if (!MMC->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->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"));
- }
+ QString error;
+ if (!MMC->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()
+ QString raw_file = QFileDialog::getOpenFileName(
+ this, tr("JSON Editor"),
+ ui->jsonEditorTextBox->text().isEmpty()
#if defined(Q_OS_LINUX)
- ? QString("/usr/bin")
+ ? QString("/usr/bin")
#else
- ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first()
+ ? 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"));
- }
+ : 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;
+ applySettings();
+ return true;
}
diff --git a/application/pages/global/ExternalToolsPage.h b/application/pages/global/ExternalToolsPage.h
index de46d8a6..06e64273 100644
--- a/application/pages/global/ExternalToolsPage.h
+++ b/application/pages/global/ExternalToolsPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,49 +26,49 @@ class ExternalToolsPage;
class ExternalToolsPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit ExternalToolsPage(QWidget *parent = 0);
- ~ExternalToolsPage();
+ explicit ExternalToolsPage(QWidget *parent = 0);
+ ~ExternalToolsPage();
- QString displayName() const override
- {
- return tr("External Tools");
- }
- QIcon icon() const override
- {
- auto icon = MMC->getThemedIcon("externaltools");
- if(icon.isNull())
- {
- icon = MMC->getThemedIcon("loadermods");
- }
- return icon;
- }
- QString id() const override
- {
- return "external-tools";
- }
- QString helpPage() const override
- {
- return "Tools";
- }
- virtual bool apply() override;
+ QString displayName() const override
+ {
+ return tr("External Tools");
+ }
+ QIcon icon() const override
+ {
+ auto icon = MMC->getThemedIcon("externaltools");
+ if(icon.isNull())
+ {
+ icon = MMC->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();
+ void loadSettings();
+ void applySettings();
private:
- Ui::ExternalToolsPage *ui;
+ 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();
+ 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/application/pages/global/ExternalToolsPage.ui b/application/pages/global/ExternalToolsPage.ui
index 5f19898b..e79e9388 100644
--- a/application/pages/global/ExternalToolsPage.ui
+++ b/application/pages/global/ExternalToolsPage.ui
@@ -63,7 +63,7 @@
<item>
<widget class="QLabel" name="jprofilerLink">
<property name="text">
- <string notr="true">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;http://www.ej-technologies.com/products/jprofiler/overview.html&quot;&gt;http://www.ej-technologies.com/products/jprofiler/overview.html&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string notr="true">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://www.ej-technologies.com/products/jprofiler/overview.html&quot;&gt;https://www.ej-technologies.com/products/jprofiler/overview.html&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -137,7 +137,7 @@
<item>
<widget class="QLabel" name="mceditLink">
<property name="text">
- <string notr="true">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;http://www.mcedit.net/&quot;&gt;http://www.mcedit.net/&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string notr="true">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://www.mcedit.net/&quot;&gt;https://www.mcedit.net/&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
diff --git a/application/pages/global/JavaPage.cpp b/application/pages/global/JavaPage.cpp
index ce733778..211dc929 100644
--- a/application/pages/global/JavaPage.cpp
+++ b/application/pages/global/JavaPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QDir>
+#include <QTabBar>
#include "dialogs/VersionSelectDialog.h"
@@ -34,120 +35,120 @@
JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
- auto sysMB = Sys::getSystemRam() / Sys::megabyte;
- ui->maxMemSpinBox->setMaximum(sysMB);
- loadSettings();
+ auto sysMB = Sys::getSystemRam() / Sys::megabyte;
+ ui->maxMemSpinBox->setMaximum(sysMB);
+ loadSettings();
}
JavaPage::~JavaPage()
{
- delete ui;
+ delete ui;
}
bool JavaPage::apply()
{
- applySettings();
- return true;
+ applySettings();
+ return true;
}
void JavaPage::applySettings()
{
- auto s = MMC->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());
+ auto s = MMC->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 = MMC->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());
+ auto s = MMC->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;
+ JavaInstallPtr java;
- VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true);
- vselect.setResizeOn(2);
- vselect.exec();
+ 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<JavaInstall>(vselect.selectedVersion());
- ui->javaPathTextBox->setText(java->path);
- }
+ if (vselect.result() == QDialog::Accepted && vselect.selectedVersion())
+ {
+ java = std::dynamic_pointer_cast<JavaInstall>(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);
+ 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();
+ 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();
+ checker.reset();
}
diff --git a/application/pages/global/JavaPage.h b/application/pages/global/JavaPage.h
index e3a9f37f..3efebb78 100644
--- a/application/pages/global/JavaPage.h
+++ b/application/pages/global/JavaPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,42 +31,42 @@ class JavaPage;
class JavaPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit JavaPage(QWidget *parent = 0);
- ~JavaPage();
+ explicit JavaPage(QWidget *parent = 0);
+ ~JavaPage();
- QString displayName() const override
- {
- return tr("Java");
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("java");
- }
- QString id() const override
- {
- return "java-settings";
- }
- QString helpPage() const override
- {
- return "Java-settings";
- }
- bool apply() override;
+ QString displayName() const override
+ {
+ return tr("Java");
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("java");
+ }
+ QString id() const override
+ {
+ return "java-settings";
+ }
+ QString helpPage() const override
+ {
+ return "Java-settings";
+ }
+ bool apply() override;
private:
- void applySettings();
- void loadSettings();
+ void applySettings();
+ void loadSettings();
private
slots:
- void on_javaDetectBtn_clicked();
- void on_javaTestBtn_clicked();
- void on_javaBrowseBtn_clicked();
- void checkerFinished();
+ void on_javaDetectBtn_clicked();
+ void on_javaTestBtn_clicked();
+ void on_javaBrowseBtn_clicked();
+ void checkerFinished();
private:
- Ui::JavaPage *ui;
- unique_qobject_ptr<JavaCommon::TestCheck> checker;
+ Ui::JavaPage *ui;
+ unique_qobject_ptr<JavaCommon::TestCheck> checker;
};
diff --git a/application/pages/global/LanguagePage.cpp b/application/pages/global/LanguagePage.cpp
new file mode 100644
index 00000000..ae3168cc
--- /dev/null
+++ b/application/pages/global/LanguagePage.cpp
@@ -0,0 +1,51 @@
+#include "LanguagePage.h"
+
+#include "widgets/LanguageSelectionWidget.h"
+#include <QVBoxLayout>
+
+LanguagePage::LanguagePage(QWidget* parent) :
+ QWidget(parent)
+{
+ setObjectName(QStringLiteral("languagePage"));
+ auto layout = new QVBoxLayout(this);
+ mainWidget = new LanguageSelectionWidget(this);
+ layout->setContentsMargins(0,0,0,0);
+ layout->addWidget(mainWidget);
+ retranslate();
+}
+
+LanguagePage::~LanguagePage()
+{
+}
+
+bool LanguagePage::apply()
+{
+ applySettings();
+ return true;
+}
+
+void LanguagePage::applySettings()
+{
+ auto settings = MMC->settings();
+ QString key = mainWidget->getSelectedLanguageKey();
+ settings->set("Language", key);
+}
+
+void LanguagePage::loadSettings()
+{
+ // NIL
+}
+
+void LanguagePage::retranslate()
+{
+ mainWidget->retranslate();
+}
+
+void LanguagePage::changeEvent(QEvent* event)
+{
+ if (event->type() == QEvent::LanguageChange)
+ {
+ retranslate();
+ }
+ QWidget::changeEvent(event);
+}
diff --git a/application/pages/global/LanguagePage.h b/application/pages/global/LanguagePage.h
new file mode 100644
index 00000000..c4df2ea9
--- /dev/null
+++ b/application/pages/global/LanguagePage.h
@@ -0,0 +1,60 @@
+/* Copyright 2013-2019 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 <memory>
+#include "pages/BasePage.h"
+#include <MultiMC.h>
+#include <QWidget>
+
+class LanguageSelectionWidget;
+
+class LanguagePage : public QWidget, public BasePage
+{
+ Q_OBJECT
+
+public:
+ explicit LanguagePage(QWidget *parent = 0);
+ virtual ~LanguagePage();
+
+ QString displayName() const override
+ {
+ return tr("Language");
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("language");
+ }
+ QString id() const override
+ {
+ return "language-settings";
+ }
+ QString helpPage() const override
+ {
+ return "Language-settings";
+ }
+ bool apply() override;
+
+ void changeEvent(QEvent * ) override;
+
+private:
+ void applySettings();
+ void loadSettings();
+ void retranslate();
+
+private:
+ LanguageSelectionWidget *mainWidget;
+};
diff --git a/application/pages/global/MinecraftPage.cpp b/application/pages/global/MinecraftPage.cpp
index 4efc2fa0..5e0d9625 100644
--- a/application/pages/global/MinecraftPage.cpp
+++ b/application/pages/global/MinecraftPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
#include <QMessageBox>
#include <QDir>
+#include <QTabBar>
#include "settings/SettingsObject.h"
#include "MultiMC.h"
@@ -25,52 +26,52 @@
MinecraftPage::MinecraftPage(QWidget *parent) : QWidget(parent), ui(new Ui::MinecraftPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
- loadSettings();
- updateCheckboxStuff();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
+ loadSettings();
+ updateCheckboxStuff();
}
MinecraftPage::~MinecraftPage()
{
- delete ui;
+ delete ui;
}
bool MinecraftPage::apply()
{
- applySettings();
- return true;
+ applySettings();
+ return true;
}
void MinecraftPage::updateCheckboxStuff()
{
- ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
- ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
+ ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
+ ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
}
void MinecraftPage::on_maximizedCheckBox_clicked(bool checked)
{
- Q_UNUSED(checked);
- updateCheckboxStuff();
+ Q_UNUSED(checked);
+ updateCheckboxStuff();
}
void MinecraftPage::applySettings()
{
- auto s = MMC->settings();
+ auto s = MMC->settings();
- // Window Size
- s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
- s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
- s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
+ // Window Size
+ s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
+ s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
+ s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
}
void MinecraftPage::loadSettings()
{
- auto s = MMC->settings();
+ auto s = MMC->settings();
- // Window Size
- ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool());
- ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt());
- ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt());
+ // Window Size
+ ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool());
+ ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt());
+ ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt());
}
diff --git a/application/pages/global/MinecraftPage.h b/application/pages/global/MinecraftPage.h
index d1abd6fe..39265fbe 100644
--- a/application/pages/global/MinecraftPage.h
+++ b/application/pages/global/MinecraftPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,40 +31,40 @@ class MinecraftPage;
class MinecraftPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit MinecraftPage(QWidget *parent = 0);
- ~MinecraftPage();
+ explicit MinecraftPage(QWidget *parent = 0);
+ ~MinecraftPage();
- QString displayName() const override
- {
- return tr("Minecraft");
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("minecraft");
- }
- QString id() const override
- {
- return "minecraft-settings";
- }
- QString helpPage() const override
- {
- return "Minecraft-settings";
- }
- bool apply() override;
+ QString displayName() const override
+ {
+ return tr("Minecraft");
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("minecraft");
+ }
+ QString id() const override
+ {
+ return "minecraft-settings";
+ }
+ QString helpPage() const override
+ {
+ return "Minecraft-settings";
+ }
+ bool apply() override;
private:
- void updateCheckboxStuff();
- void applySettings();
- void loadSettings();
+ void updateCheckboxStuff();
+ void applySettings();
+ void loadSettings();
private
slots:
- void on_maximizedCheckBox_clicked(bool checked);
+ void on_maximizedCheckBox_clicked(bool checked);
private:
- Ui::MinecraftPage *ui;
+ Ui::MinecraftPage *ui;
};
diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp
index 21e8123c..d10d4caa 100644
--- a/application/pages/global/MultiMCPage.cpp
+++ b/application/pages/global/MultiMCPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,208 +32,190 @@
// FIXME: possibly move elsewhere
enum InstSortMode
{
- // Sort alphabetically by name.
- Sort_Name,
- // Sort by which instance was launched most recently.
- Sort_LastLaunch
+ // Sort alphabetically by name.
+ Sort_Name,
+ // Sort by which instance was launched most recently.
+ Sort_LastLaunch
};
MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCPage)
{
- ui->setupUi(this);
- auto origForeground = ui->fontPreview->palette().color(ui->fontPreview->foregroundRole());
- auto origBackground = ui->fontPreview->palette().color(ui->fontPreview->backgroundRole());
- m_colors.reset(new LogColorCache(origForeground, origBackground));
-
- ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name);
- ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch);
-
- defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
-
- m_languageModel = MMC->translations();
- loadSettings();
-
- if(BuildConfig.UPDATER_ENABLED)
- {
- QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this,
- &MultiMCPage::refreshUpdateChannelList);
-
- if (MMC->updateChecker()->hasChannels())
- {
- refreshUpdateChannelList();
- }
- else
- {
- MMC->updateChecker()->updateChanList(false);
- }
- }
- else
- {
- ui->updateSettingsBox->setHidden(true);
- }
-/* // Analytics
- if(BuildConfig.ANALYTICS_ID.isEmpty())
- {
- ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->analyticsTab));
- }
-*/ connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
- connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
- connect(ui->languageBox, SIGNAL(currentIndexChanged(int)), SLOT(languageIndexChanged(int)));
+ ui->setupUi(this);
+ auto origForeground = ui->fontPreview->palette().color(ui->fontPreview->foregroundRole());
+ auto origBackground = ui->fontPreview->palette().color(ui->fontPreview->backgroundRole());
+ m_colors.reset(new LogColorCache(origForeground, origBackground));
+
+ ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name);
+ ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch);
+
+ defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
+
+ m_languageModel = MMC->translations();
+ loadSettings();
+
+ if(BuildConfig.UPDATER_ENABLED)
+ {
+ QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this,
+ &MultiMCPage::refreshUpdateChannelList);
+
+ if (MMC->updateChecker()->hasChannels())
+ {
+ refreshUpdateChannelList();
+ }
+ else
+ {
+ MMC->updateChecker()->updateChanList(false);
+ }
+ }
+ else
+ {
+ ui->updateSettingsBox->setHidden(true);
+ }
+ connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
+ connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
}
MultiMCPage::~MultiMCPage()
{
- delete ui;
+ delete ui;
}
bool MultiMCPage::apply()
{
- applySettings();
- return true;
+ applySettings();
+ return true;
}
void MultiMCPage::on_instDirBrowseBtn_clicked()
{
- QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Folder"), ui->instDirTextBox->text());
-
- // do not allow current dir - it's dirty. Do not allow dirs that don't exist
- if (!raw_dir.isEmpty() && QDir(raw_dir).exists())
- {
- QString cooked_dir = FS::NormalizePath(raw_dir);
- if (FS::checkProblemticPathJava(QDir(cooked_dir)))
- {
- QMessageBox warning;
- warning.setText(tr("You're trying to specify an instance folder which\'s path "
- "contains at least one \'!\'. "
- "Java is known to cause problems if that is the case, your "
- "instances (probably) won't start!"));
- warning.setInformativeText(
- tr("Do you really want to use this path? "
- "Selecting \"No\" will close this and not alter your instance path."));
- warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- int result = warning.exec();
- if (result == QMessageBox::Yes)
- {
- ui->instDirTextBox->setText(cooked_dir);
- }
- }
- else
- {
- ui->instDirTextBox->setText(cooked_dir);
- }
- }
+ QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Folder"), ui->instDirTextBox->text());
+
+ // do not allow current dir - it's dirty. Do not allow dirs that don't exist
+ if (!raw_dir.isEmpty() && QDir(raw_dir).exists())
+ {
+ QString cooked_dir = FS::NormalizePath(raw_dir);
+ if (FS::checkProblemticPathJava(QDir(cooked_dir)))
+ {
+ QMessageBox warning;
+ warning.setText(tr("You're trying to specify an instance folder which\'s path "
+ "contains at least one \'!\'. "
+ "Java is known to cause problems if that is the case, your "
+ "instances (probably) won't start!"));
+ warning.setInformativeText(
+ tr("Do you really want to use this path? "
+ "Selecting \"No\" will close this and not alter your instance path."));
+ warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ int result = warning.exec();
+ if (result == QMessageBox::Yes)
+ {
+ ui->instDirTextBox->setText(cooked_dir);
+ }
+ }
+ else
+ {
+ ui->instDirTextBox->setText(cooked_dir);
+ }
+ }
}
void MultiMCPage::on_iconsDirBrowseBtn_clicked()
{
- QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Folder"), ui->iconsDirTextBox->text());
-
- // do not allow current dir - it's dirty. Do not allow dirs that don't exist
- if (!raw_dir.isEmpty() && QDir(raw_dir).exists())
- {
- QString cooked_dir = FS::NormalizePath(raw_dir);
- ui->iconsDirTextBox->setText(cooked_dir);
- }
+ QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Folder"), ui->iconsDirTextBox->text());
+
+ // do not allow current dir - it's dirty. Do not allow dirs that don't exist
+ if (!raw_dir.isEmpty() && QDir(raw_dir).exists())
+ {
+ QString cooked_dir = FS::NormalizePath(raw_dir);
+ ui->iconsDirTextBox->setText(cooked_dir);
+ }
}
void MultiMCPage::on_modsDirBrowseBtn_clicked()
{
- QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Folder"), ui->modsDirTextBox->text());
-
- // do not allow current dir - it's dirty. Do not allow dirs that don't exist
- if (!raw_dir.isEmpty() && QDir(raw_dir).exists())
- {
- QString cooked_dir = FS::NormalizePath(raw_dir);
- ui->modsDirTextBox->setText(cooked_dir);
- }
-}
-
-void MultiMCPage::languageIndexChanged(int index)
-{
- auto languageCode = ui->languageBox->itemData(ui->languageBox->currentIndex()).toString();
- if(languageCode.isEmpty())
- {
- qWarning() << "Unknown language at index" << index;
- return;
- }
- auto translations = MMC->translations();
- translations->selectLanguage(languageCode);
- translations->updateLanguage(languageCode);
+ QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Folder"), ui->modsDirTextBox->text());
+
+ // do not allow current dir - it's dirty. Do not allow dirs that don't exist
+ if (!raw_dir.isEmpty() && QDir(raw_dir).exists())
+ {
+ QString cooked_dir = FS::NormalizePath(raw_dir);
+ ui->modsDirTextBox->setText(cooked_dir);
+ }
}
void MultiMCPage::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
- // description label constantly.
- QObject::disconnect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this,
- SLOT(updateChannelSelectionChanged(int)));
-
- QList<UpdateChecker::ChannelListEntry> channelList = MMC->updateChecker()->getChannelList();
- ui->updateChannelComboBox->clear();
- int selection = -1;
- for (int i = 0; i < channelList.count(); i++)
- {
- UpdateChecker::ChannelListEntry entry = channelList.at(i);
-
- // When it comes to selection, we'll rely on the indexes of a channel entry being the
- // same in the
- // combo box as it is in the update checker's channel list.
- // This probably isn't very safe, but the channel list doesn't change often enough (or
- // at all) for
- // this to be a big deal. Hope it doesn't break...
- ui->updateChannelComboBox->addItem(entry.name);
-
- // If the update channel we just added was the selected one, set the current index in
- // the combo box to it.
- if (entry.id == m_currentUpdateChannel)
- {
- qDebug() << "Selected index" << i << "channel id" << m_currentUpdateChannel;
- selection = i;
- }
- }
-
- ui->updateChannelComboBox->setCurrentIndex(selection);
-
- // Start listening for selection changes again and update the description label.
- QObject::connect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this,
- SLOT(updateChannelSelectionChanged(int)));
- refreshUpdateChannelDesc();
-
- // Now that we've updated the channel list, we can enable the combo box.
- // It starts off disabled so that if the channel list hasn't been loaded, it will be
- // disabled.
- ui->updateChannelComboBox->setEnabled(true);
+ // Stop listening for selection changes. It's going to change a lot while we update it and
+ // we don't need to update the
+ // description label constantly.
+ QObject::disconnect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this,
+ SLOT(updateChannelSelectionChanged(int)));
+
+ QList<UpdateChecker::ChannelListEntry> channelList = MMC->updateChecker()->getChannelList();
+ ui->updateChannelComboBox->clear();
+ int selection = -1;
+ for (int i = 0; i < channelList.count(); i++)
+ {
+ UpdateChecker::ChannelListEntry entry = channelList.at(i);
+
+ // When it comes to selection, we'll rely on the indexes of a channel entry being the
+ // same in the
+ // combo box as it is in the update checker's channel list.
+ // This probably isn't very safe, but the channel list doesn't change often enough (or
+ // at all) for
+ // this to be a big deal. Hope it doesn't break...
+ ui->updateChannelComboBox->addItem(entry.name);
+
+ // If the update channel we just added was the selected one, set the current index in
+ // the combo box to it.
+ if (entry.id == m_currentUpdateChannel)
+ {
+ qDebug() << "Selected index" << i << "channel id" << m_currentUpdateChannel;
+ selection = i;
+ }
+ }
+
+ ui->updateChannelComboBox->setCurrentIndex(selection);
+
+ // Start listening for selection changes again and update the description label.
+ QObject::connect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this,
+ SLOT(updateChannelSelectionChanged(int)));
+ refreshUpdateChannelDesc();
+
+ // Now that we've updated the channel list, we can enable the combo box.
+ // It starts off disabled so that if the channel list hasn't been loaded, it will be
+ // disabled.
+ ui->updateChannelComboBox->setEnabled(true);
}
void MultiMCPage::updateChannelSelectionChanged(int index)
{
- refreshUpdateChannelDesc();
+ refreshUpdateChannelDesc();
}
void MultiMCPage::refreshUpdateChannelDesc()
{
- // Get the channel list.
- QList<UpdateChecker::ChannelListEntry> channelList = MMC->updateChecker()->getChannelList();
- int selectedIndex = ui->updateChannelComboBox->currentIndex();
- if (selectedIndex < 0)
- {
- return;
- }
- if (selectedIndex < channelList.count())
- {
- // Find the channel list entry with the given index.
- UpdateChecker::ChannelListEntry selected = channelList.at(selectedIndex);
-
- // Set the description text.
- ui->updateChannelDescLabel->setText(selected.description);
-
- // Set the currently selected channel ID.
- m_currentUpdateChannel = selected.id;
- }
+ // Get the channel list.
+ QList<UpdateChecker::ChannelListEntry> channelList = MMC->updateChecker()->getChannelList();
+ int selectedIndex = ui->updateChannelComboBox->currentIndex();
+ if (selectedIndex < 0)
+ {
+ return;
+ }
+ if (selectedIndex < channelList.count())
+ {
+ // Find the channel list entry with the given index.
+ UpdateChecker::ChannelListEntry selected = channelList.at(selectedIndex);
+
+ // Set the description text.
+ ui->updateChannelDescLabel->setText(selected.description);
+
+ // Set the currently selected channel ID.
+ m_currentUpdateChannel = selected.id;
+ }
}
void MultiMCPage::applySettings()
{
+<<<<<<< HEAD
auto s = MMC->settings();
// Language
@@ -434,39 +416,232 @@ void MultiMCPage::loadSettings()
{
ui->analyticsCheck->setChecked(s->get("Analytics").toBool());
} */
+=======
+ auto s = MMC->settings();
+
+ if (ui->resetNotificationsBtn->isChecked())
+ {
+ s->set("ShownNotifications", QString());
+ }
+
+ // Updates
+ s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked());
+ s->set("UpdateChannel", m_currentUpdateChannel);
+ auto original = s->get("IconTheme").toString();
+ //FIXME: make generic
+ switch (ui->themeComboBox->currentIndex())
+ {
+ case 1:
+ s->set("IconTheme", "pe_dark");
+ break;
+ case 2:
+ s->set("IconTheme", "pe_light");
+ break;
+ case 3:
+ s->set("IconTheme", "pe_blue");
+ break;
+ case 4:
+ s->set("IconTheme", "pe_colored");
+ break;
+ case 5:
+ s->set("IconTheme", "OSX");
+ break;
+ case 6:
+ s->set("IconTheme", "iOS");
+ break;
+ case 7:
+ s->set("IconTheme", "flat");
+ break;
+ case 8:
+ s->set("IconTheme", "custom");
+ break;
+ case 0:
+ default:
+ s->set("IconTheme", "multimc");
+ break;
+ }
+
+ if(original != s->get("IconTheme"))
+ {
+ MMC->setIconTheme(s->get("IconTheme").toString());
+ }
+
+ auto originalAppTheme = s->get("ApplicationTheme").toString();
+ auto newAppTheme = ui->themeComboBoxColors->currentData().toString();
+ if(originalAppTheme != newAppTheme)
+ {
+ s->set("ApplicationTheme", newAppTheme);
+ MMC->setApplicationTheme(newAppTheme, false);
+ }
+
+ // Console settings
+ s->set("ShowConsole", ui->showConsoleCheck->isChecked());
+ s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
+ s->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked());
+ QString consoleFontFamily = ui->consoleFont->currentFont().family();
+ s->set("ConsoleFont", consoleFontFamily);
+ s->set("ConsoleFontSize", ui->fontSizeBox->value());
+ s->set("ConsoleMaxLines", ui->lineLimitSpinBox->value());
+ s->set("ConsoleOverflowStop", ui->checkStopLogging->checkState() != Qt::Unchecked);
+
+ // Folders
+ // TODO: Offer to move instances to new instance folder.
+ s->set("InstanceDir", ui->instDirTextBox->text());
+ s->set("CentralModsDir", ui->modsDirTextBox->text());
+ s->set("IconsDir", ui->iconsDirTextBox->text());
+
+ auto sortMode = (InstSortMode)ui->sortingModeGroup->checkedId();
+ switch (sortMode)
+ {
+ case Sort_LastLaunch:
+ s->set("InstSortMode", "LastLaunch");
+ break;
+ case Sort_Name:
+ default:
+ s->set("InstSortMode", "Name");
+ break;
+ }
+
+ // Analytics
+ if(!BuildConfig.ANALYTICS_ID.isEmpty())
+ {
+ s->set("Analytics", ui->analyticsCheck->isChecked());
+ }
+}
+void MultiMCPage::loadSettings()
+{
+ auto s = MMC->settings();
+ // Updates
+ ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool());
+ m_currentUpdateChannel = s->get("UpdateChannel").toString();
+ //FIXME: make generic
+ auto theme = s->get("IconTheme").toString();
+ if (theme == "pe_dark")
+ {
+ ui->themeComboBox->setCurrentIndex(1);
+ }
+ else if (theme == "pe_light")
+ {
+ ui->themeComboBox->setCurrentIndex(2);
+ }
+ else if (theme == "pe_blue")
+ {
+ ui->themeComboBox->setCurrentIndex(3);
+ }
+ else if (theme == "pe_colored")
+ {
+ ui->themeComboBox->setCurrentIndex(4);
+ }
+ else if (theme == "OSX")
+ {
+ ui->themeComboBox->setCurrentIndex(5);
+ }
+ else if (theme == "iOS")
+ {
+ ui->themeComboBox->setCurrentIndex(6);
+ }
+ else if (theme == "flat")
+ {
+ ui->themeComboBox->setCurrentIndex(7);
+ }
+ else if (theme == "custom")
+ {
+ ui->themeComboBox->setCurrentIndex(8);
+ }
+ else
+ {
+ ui->themeComboBox->setCurrentIndex(0);
+ }
+
+ {
+ auto currentTheme = s->get("ApplicationTheme").toString();
+ auto themes = MMC->getValidApplicationThemes();
+ int idx = 0;
+ for(auto &theme: themes)
+ {
+ ui->themeComboBoxColors->addItem(theme->name(), theme->id());
+ if(currentTheme == theme->id())
+ {
+ ui->themeComboBoxColors->setCurrentIndex(idx);
+ }
+ idx++;
+ }
+ }
+
+ // Console settings
+ ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
+ ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
+ ui->showConsoleErrorCheck->setChecked(s->get("ShowConsoleOnError").toBool());
+ QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
+ QFont consoleFont(fontFamily);
+ ui->consoleFont->setCurrentFont(consoleFont);
+
+ bool conversionOk = true;
+ int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
+ if(!conversionOk)
+ {
+ fontSize = 11;
+ }
+ ui->fontSizeBox->setValue(fontSize);
+ refreshFontPreview();
+ ui->lineLimitSpinBox->setValue(s->get("ConsoleMaxLines").toInt());
+ ui->checkStopLogging->setChecked(s->get("ConsoleOverflowStop").toBool());
+
+ // Folders
+ ui->instDirTextBox->setText(s->get("InstanceDir").toString());
+ ui->modsDirTextBox->setText(s->get("CentralModsDir").toString());
+ ui->iconsDirTextBox->setText(s->get("IconsDir").toString());
+
+ QString sortMode = s->get("InstSortMode").toString();
+
+ if (sortMode == "LastLaunch")
+ {
+ ui->sortLastLaunchedBtn->setChecked(true);
+ }
+ else
+ {
+ ui->sortByNameBtn->setChecked(true);
+ }
+
+ // Analytics
+ if(!BuildConfig.ANALYTICS_ID.isEmpty())
+ {
+ ui->analyticsCheck->setChecked(s->get("Analytics").toBool());
+ }
+>>>>>>> origin/stable
}
void MultiMCPage::refreshFontPreview()
{
- int fontSize = ui->fontSizeBox->value();
- QString fontFamily = ui->consoleFont->currentFont().family();
- ui->fontPreview->clear();
- defaultFormat->setFont(QFont(fontFamily, fontSize));
- {
- QTextCharFormat format(*defaultFormat);
- format.setForeground(m_colors->getFront(MessageLevel::Error));
- // append a paragraph/line
- auto workCursor = ui->fontPreview->textCursor();
- workCursor.movePosition(QTextCursor::End);
- workCursor.insertText(tr("[Something/ERROR] A spooky error!"), format);
- workCursor.insertBlock();
- }
- {
- QTextCharFormat format(*defaultFormat);
- format.setForeground(m_colors->getFront(MessageLevel::Message));
- // append a paragraph/line
- auto workCursor = ui->fontPreview->textCursor();
- workCursor.movePosition(QTextCursor::End);
- workCursor.insertText(tr("[Test/INFO] A harmless message..."), format);
- workCursor.insertBlock();
- }
- {
- QTextCharFormat format(*defaultFormat);
- format.setForeground(m_colors->getFront(MessageLevel::Warning));
- // append a paragraph/line
- auto workCursor = ui->fontPreview->textCursor();
- workCursor.movePosition(QTextCursor::End);
- workCursor.insertText(tr("[Something/WARN] A not so spooky warning."), format);
- workCursor.insertBlock();
- }
+ int fontSize = ui->fontSizeBox->value();
+ QString fontFamily = ui->consoleFont->currentFont().family();
+ ui->fontPreview->clear();
+ defaultFormat->setFont(QFont(fontFamily, fontSize));
+ {
+ QTextCharFormat format(*defaultFormat);
+ format.setForeground(m_colors->getFront(MessageLevel::Error));
+ // append a paragraph/line
+ auto workCursor = ui->fontPreview->textCursor();
+ workCursor.movePosition(QTextCursor::End);
+ workCursor.insertText(tr("[Something/ERROR] A spooky error!"), format);
+ workCursor.insertBlock();
+ }
+ {
+ QTextCharFormat format(*defaultFormat);
+ format.setForeground(m_colors->getFront(MessageLevel::Message));
+ // append a paragraph/line
+ auto workCursor = ui->fontPreview->textCursor();
+ workCursor.movePosition(QTextCursor::End);
+ workCursor.insertText(tr("[Test/INFO] A harmless message..."), format);
+ workCursor.insertBlock();
+ }
+ {
+ QTextCharFormat format(*defaultFormat);
+ format.setForeground(m_colors->getFront(MessageLevel::Warning));
+ // append a paragraph/line
+ auto workCursor = ui->fontPreview->textCursor();
+ workCursor.movePosition(QTextCursor::End);
+ workCursor.insertText(tr("[Something/WARN] A not so spooky warning."), format);
+ workCursor.insertBlock();
+ }
}
diff --git a/application/pages/global/MultiMCPage.h b/application/pages/global/MultiMCPage.h
index d5194c0e..27a801be 100644
--- a/application/pages/global/MultiMCPage.h
+++ b/application/pages/global/MultiMCPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,71 +34,69 @@ class MultiMCPage;
class MultiMCPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit MultiMCPage(QWidget *parent = 0);
- ~MultiMCPage();
-
- QString displayName() const override
- {
- return "MultiMC";
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("multimc");
- }
- QString id() const override
- {
- return "multimc-settings";
- }
- QString helpPage() const override
- {
- return "MultiMC-settings";
- }
- bool apply() override;
+ explicit MultiMCPage(QWidget *parent = 0);
+ ~MultiMCPage();
+
+ QString displayName() const override
+ {
+ return "MultiMC";
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("multimc");
+ }
+ QString id() const override
+ {
+ return "multimc-settings";
+ }
+ QString helpPage() const override
+ {
+ return "MultiMC-settings";
+ }
+ bool apply() override;
private:
- void applySettings();
- void loadSettings();
+ void applySettings();
+ void loadSettings();
private
slots:
- void on_instDirBrowseBtn_clicked();
- void on_modsDirBrowseBtn_clicked();
- void on_iconsDirBrowseBtn_clicked();
+ void on_instDirBrowseBtn_clicked();
+ void on_modsDirBrowseBtn_clicked();
+ void on_iconsDirBrowseBtn_clicked();
- void languageIndexChanged(int index);
+ /*!
+ * Updates the list of update channels in the combo box.
+ */
+ void refreshUpdateChannelList();
- /*!
- * Updates the list of update channels in the combo box.
- */
- void refreshUpdateChannelList();
+ /*!
+ * Updates the channel description label.
+ */
+ void refreshUpdateChannelDesc();
- /*!
- * Updates the channel description label.
- */
- void refreshUpdateChannelDesc();
+ /*!
+ * Updates the font preview
+ */
+ void refreshFontPreview();
- /*!
- * Updates the font preview
- */
- void refreshFontPreview();
-
- void updateChannelSelectionChanged(int index);
+ void updateChannelSelectionChanged(int index);
private:
- Ui::MultiMCPage *ui;
+ Ui::MultiMCPage *ui;
- /*!
- * Stores the currently selected update channel.
- */
- QString m_currentUpdateChannel;
+ /*!
+ * Stores the currently selected update channel.
+ */
+ QString m_currentUpdateChannel;
- // default format for the font preview...
- QTextCharFormat *defaultFormat;
+ // default format for the font preview...
+ QTextCharFormat *defaultFormat;
- std::unique_ptr<LogColorCache> m_colors;
+ std::unique_ptr<LogColorCache> m_colors;
- std::shared_ptr<TranslationsModel> m_languageModel;
+ std::shared_ptr<TranslationsModel> m_languageModel;
};
diff --git a/application/pages/global/MultiMCPage.ui b/application/pages/global/MultiMCPage.ui
index 124401c3..ea034919 100644
--- a/application/pages/global/MultiMCPage.ui
+++ b/application/pages/global/MultiMCPage.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>467</width>
+ <width>514</width>
<height>629</height>
</rect>
</property>
@@ -229,18 +229,6 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBox_2">
- <property name="title">
- <string>Language:</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QComboBox" name="languageBox"/>
- </item>
- </layout>
- </widget>
- </item>
- <item>
<widget class="QGroupBox" name="themeBox">
<property name="title">
<string>Theme</string>
@@ -570,7 +558,6 @@
<tabstop>resetNotificationsBtn</tabstop>
<tabstop>sortLastLaunchedBtn</tabstop>
<tabstop>sortByNameBtn</tabstop>
- <tabstop>languageBox</tabstop>
<tabstop>themeComboBox</tabstop>
<tabstop>themeComboBoxColors</tabstop>
<tabstop>showConsoleCheck</tabstop>
diff --git a/application/pages/global/PackagesPage.cpp b/application/pages/global/PackagesPage.cpp
index 7cf1e3f5..1bbbed7a 100644
--- a/application/pages/global/PackagesPage.cpp
+++ b/application/pages/global/PackagesPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2015-2018 MultiMC Contributors
+/* Copyright 2015-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,192 +33,192 @@ using namespace Meta;
static QString formatRequires(const VersionPtr &version)
{
- QStringList lines;
- auto & reqs = version->requires();
- auto iter = reqs.begin();
- while (iter != reqs.end())
- {
- auto &uid = iter->uid;
- auto &version = iter->equalsVersion;
- const QString readable = ENV.metadataIndex()->hasUid(uid) ? ENV.metadataIndex()->get(uid)->humanReadable() : uid;
- if(!version.isEmpty())
- {
- lines.append(QString("%1 (%2)").arg(readable, version));
- }
- else
- {
- lines.append(QString("%1").arg(readable));
- }
- iter++;
- }
- return lines.join('\n');
+ QStringList lines;
+ auto & reqs = version->requires();
+ auto iter = reqs.begin();
+ while (iter != reqs.end())
+ {
+ auto &uid = iter->uid;
+ auto &version = iter->equalsVersion;
+ const QString readable = ENV.metadataIndex()->hasUid(uid) ? ENV.metadataIndex()->get(uid)->humanReadable() : uid;
+ if(!version.isEmpty())
+ {
+ lines.append(QString("%1 (%2)").arg(readable, version));
+ }
+ else
+ {
+ lines.append(QString("%1").arg(readable));
+ }
+ iter++;
+ }
+ return lines.join('\n');
}
PackagesPage::PackagesPage(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::PackagesPage)
+ QWidget(parent),
+ ui(new Ui::PackagesPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
-
- m_fileProxy = new QSortFilterProxyModel(this);
- m_fileProxy->setSortRole(Qt::DisplayRole);
- m_fileProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
- m_fileProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
- m_fileProxy->setFilterRole(Qt::DisplayRole);
- m_fileProxy->setFilterKeyColumn(0);
- m_fileProxy->sort(0);
- m_fileProxy->setSourceModel(ENV.metadataIndex().get());
- ui->indexView->setModel(m_fileProxy);
-
- m_filterProxy = new QSortFilterProxyModel(this);
- m_filterProxy->setSortRole(VersionList::SortRole);
- m_filterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
- m_filterProxy->setFilterRole(Qt::DisplayRole);
- m_filterProxy->setFilterKeyColumn(0);
- m_filterProxy->sort(0, Qt::DescendingOrder);
- ui->versionsView->setModel(m_filterProxy);
-
- m_versionProxy = new VersionProxyModel(this);
- m_filterProxy->setSourceModel(m_versionProxy);
-
- connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateCurrentVersionList);
- connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateVersion);
- connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &PackagesPage::versionListDataChanged);
-
- updateCurrentVersionList(QModelIndex());
- updateVersion();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
+
+ m_fileProxy = new QSortFilterProxyModel(this);
+ m_fileProxy->setSortRole(Qt::DisplayRole);
+ m_fileProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
+ m_fileProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ m_fileProxy->setFilterRole(Qt::DisplayRole);
+ m_fileProxy->setFilterKeyColumn(0);
+ m_fileProxy->sort(0);
+ m_fileProxy->setSourceModel(ENV.metadataIndex().get());
+ ui->indexView->setModel(m_fileProxy);
+
+ m_filterProxy = new QSortFilterProxyModel(this);
+ m_filterProxy->setSortRole(VersionList::SortRole);
+ m_filterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ m_filterProxy->setFilterRole(Qt::DisplayRole);
+ m_filterProxy->setFilterKeyColumn(0);
+ m_filterProxy->sort(0, Qt::DescendingOrder);
+ ui->versionsView->setModel(m_filterProxy);
+
+ m_versionProxy = new VersionProxyModel(this);
+ m_filterProxy->setSourceModel(m_versionProxy);
+
+ connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateCurrentVersionList);
+ connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateVersion);
+ connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &PackagesPage::versionListDataChanged);
+
+ updateCurrentVersionList(QModelIndex());
+ updateVersion();
}
PackagesPage::~PackagesPage()
{
- delete ui;
+ delete ui;
}
QIcon PackagesPage::icon() const
{
- return MMC->getThemedIcon("packages");
+ return MMC->getThemedIcon("packages");
}
void PackagesPage::on_refreshIndexBtn_clicked()
{
- ENV.metadataIndex()->load(Net::Mode::Online);
+ ENV.metadataIndex()->load(Net::Mode::Online);
}
void PackagesPage::on_refreshFileBtn_clicked()
{
- VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value<VersionListPtr>();
- if (!list)
- {
- return;
- }
- list->load(Net::Mode::Online);
+ VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value<VersionListPtr>();
+ if (!list)
+ {
+ return;
+ }
+ list->load(Net::Mode::Online);
}
void PackagesPage::on_refreshVersionBtn_clicked()
{
- VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value<VersionPtr>();
- if (!version)
- {
- return;
- }
- version->load(Net::Mode::Online);
+ VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value<VersionPtr>();
+ if (!version)
+ {
+ return;
+ }
+ version->load(Net::Mode::Online);
}
void PackagesPage::on_fileSearchEdit_textChanged(const QString &search)
{
- if (search.isEmpty())
- {
- m_fileProxy->setFilterFixedString(QString());
- }
- else
- {
- QStringList parts = search.split(' ');
- std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape);
- m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*");
- }
+ if (search.isEmpty())
+ {
+ m_fileProxy->setFilterFixedString(QString());
+ }
+ else
+ {
+ QStringList parts = search.split(' ');
+ std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape);
+ m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*");
+ }
}
void PackagesPage::on_versionSearchEdit_textChanged(const QString &search)
{
- if (search.isEmpty())
- {
- m_filterProxy->setFilterFixedString(QString());
- }
- else
- {
- QStringList parts = search.split(' ');
- std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape);
- m_filterProxy->setFilterRegExp(".*" + parts.join(".*") + ".*");
- }
+ if (search.isEmpty())
+ {
+ m_filterProxy->setFilterFixedString(QString());
+ }
+ else
+ {
+ QStringList parts = search.split(' ');
+ std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape);
+ m_filterProxy->setFilterRegExp(".*" + parts.join(".*") + ".*");
+ }
}
void PackagesPage::updateCurrentVersionList(const QModelIndex &index)
{
- if (index.isValid())
- {
- VersionListPtr list = index.data(Index::ListPtrRole).value<VersionListPtr>();
- ui->versionsBox->setEnabled(true);
- ui->refreshFileBtn->setEnabled(true);
- ui->fileUidLabel->setEnabled(true);
- ui->fileUid->setText(list->uid());
- ui->fileNameLabel->setEnabled(true);
- ui->fileName->setText(list->name());
- m_versionProxy->setSourceModel(list.get());
- ui->refreshFileBtn->setText(tr("Refresh %1").arg(list->humanReadable()));
- list->load(Net::Mode::Offline);
- }
- else
- {
- ui->versionsBox->setEnabled(false);
- ui->refreshFileBtn->setEnabled(false);
- ui->fileUidLabel->setEnabled(false);
- ui->fileUid->clear();
- ui->fileNameLabel->setEnabled(false);
- ui->fileName->clear();
- m_versionProxy->setSourceModel(nullptr);
- ui->refreshFileBtn->setText(tr("Refresh"));
- }
+ if (index.isValid())
+ {
+ VersionListPtr list = index.data(Index::ListPtrRole).value<VersionListPtr>();
+ ui->versionsBox->setEnabled(true);
+ ui->refreshFileBtn->setEnabled(true);
+ ui->fileUidLabel->setEnabled(true);
+ ui->fileUid->setText(list->uid());
+ ui->fileNameLabel->setEnabled(true);
+ ui->fileName->setText(list->name());
+ m_versionProxy->setSourceModel(list.get());
+ ui->refreshFileBtn->setText(tr("Refresh %1").arg(list->humanReadable()));
+ list->load(Net::Mode::Offline);
+ }
+ else
+ {
+ ui->versionsBox->setEnabled(false);
+ ui->refreshFileBtn->setEnabled(false);
+ ui->fileUidLabel->setEnabled(false);
+ ui->fileUid->clear();
+ ui->fileNameLabel->setEnabled(false);
+ ui->fileName->clear();
+ m_versionProxy->setSourceModel(nullptr);
+ ui->refreshFileBtn->setText(tr("Refresh"));
+ }
}
void PackagesPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br)
{
- if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex()))
- {
- updateVersion();
- }
+ if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex()))
+ {
+ updateVersion();
+ }
}
void PackagesPage::updateVersion()
{
- VersionPtr version = std::dynamic_pointer_cast<Version>(
- ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>());
- if (version)
- {
- ui->refreshVersionBtn->setEnabled(true);
- ui->versionVersionLabel->setEnabled(true);
- ui->versionVersion->setText(version->version());
- ui->versionTimeLabel->setEnabled(true);
- ui->versionTime->setText(version->time().toString("yyyy-MM-dd HH:mm"));
- ui->versionTypeLabel->setEnabled(true);
- ui->versionType->setText(version->type());
- ui->versionRequiresLabel->setEnabled(true);
- ui->versionRequires->setText(formatRequires(version));
- ui->refreshVersionBtn->setText(tr("Refresh %1").arg(version->version()));
- }
- else
- {
- ui->refreshVersionBtn->setEnabled(false);
- ui->versionVersionLabel->setEnabled(false);
- ui->versionVersion->clear();
- ui->versionTimeLabel->setEnabled(false);
- ui->versionTime->clear();
- ui->versionTypeLabel->setEnabled(false);
- ui->versionType->clear();
- ui->versionRequiresLabel->setEnabled(false);
- ui->versionRequires->clear();
- ui->refreshVersionBtn->setText(tr("Refresh"));
- }
+ VersionPtr version = std::dynamic_pointer_cast<Version>(
+ ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>());
+ if (version)
+ {
+ ui->refreshVersionBtn->setEnabled(true);
+ ui->versionVersionLabel->setEnabled(true);
+ ui->versionVersion->setText(version->version());
+ ui->versionTimeLabel->setEnabled(true);
+ ui->versionTime->setText(version->time().toString("yyyy-MM-dd HH:mm"));
+ ui->versionTypeLabel->setEnabled(true);
+ ui->versionType->setText(version->type());
+ ui->versionRequiresLabel->setEnabled(true);
+ ui->versionRequires->setText(formatRequires(version));
+ ui->refreshVersionBtn->setText(tr("Refresh %1").arg(version->version()));
+ }
+ else
+ {
+ ui->refreshVersionBtn->setEnabled(false);
+ ui->versionVersionLabel->setEnabled(false);
+ ui->versionVersion->clear();
+ ui->versionTimeLabel->setEnabled(false);
+ ui->versionTime->clear();
+ ui->versionTypeLabel->setEnabled(false);
+ ui->versionType->clear();
+ ui->versionRequiresLabel->setEnabled(false);
+ ui->versionRequires->clear();
+ ui->refreshVersionBtn->setText(tr("Refresh"));
+ }
}
void PackagesPage::openedImpl()
{
- ENV.metadataIndex()->load(Net::Mode::Offline);
+ ENV.metadataIndex()->load(Net::Mode::Offline);
}
diff --git a/application/pages/global/PackagesPage.h b/application/pages/global/PackagesPage.h
index ad155d9e..872961a5 100644
--- a/application/pages/global/PackagesPage.h
+++ b/application/pages/global/PackagesPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2015-2018 MultiMC Contributors
+/* Copyright 2015-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,30 +28,30 @@ class VersionProxyModel;
class PackagesPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit PackagesPage(QWidget *parent = 0);
- ~PackagesPage();
+ explicit PackagesPage(QWidget *parent = 0);
+ ~PackagesPage();
- QString id() const override { return "packages-global"; }
- QString displayName() const override { return tr("Packages"); }
- QIcon icon() const override;
- void openedImpl() override;
+ QString id() const override { return "packages-global"; }
+ QString displayName() const override { return tr("Packages"); }
+ QIcon icon() const override;
+ void openedImpl() override;
private slots:
- void on_refreshIndexBtn_clicked();
- void on_refreshFileBtn_clicked();
- void on_refreshVersionBtn_clicked();
- void on_fileSearchEdit_textChanged(const QString &search);
- void on_versionSearchEdit_textChanged(const QString &search);
- void updateCurrentVersionList(const QModelIndex &index);
- void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br);
+ void on_refreshIndexBtn_clicked();
+ void on_refreshFileBtn_clicked();
+ void on_refreshVersionBtn_clicked();
+ void on_fileSearchEdit_textChanged(const QString &search);
+ void on_versionSearchEdit_textChanged(const QString &search);
+ void updateCurrentVersionList(const QModelIndex &index);
+ void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br);
private:
- Ui::PackagesPage *ui;
- QSortFilterProxyModel *m_fileProxy;
- QSortFilterProxyModel *m_filterProxy;
- VersionProxyModel *m_versionProxy;
+ Ui::PackagesPage *ui;
+ QSortFilterProxyModel *m_fileProxy;
+ QSortFilterProxyModel *m_filterProxy;
+ VersionProxyModel *m_versionProxy;
- void updateVersion();
+ void updateVersion();
};
diff --git a/application/pages/global/PasteEEPage.cpp b/application/pages/global/PasteEEPage.cpp
index 83dd6411..5355d63a 100644
--- a/application/pages/global/PasteEEPage.cpp
+++ b/application/pages/global/PasteEEPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QStandardPaths>
+#include <QTabBar>
#include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h"
@@ -26,56 +27,56 @@
#include <QTabBar>
PasteEEPage::PasteEEPage(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::PasteEEPage)
+ QWidget(parent),
+ ui(new Ui::PasteEEPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();\
- connect(ui->customAPIkeyEdit, &QLineEdit::textEdited, this, &PasteEEPage::textEdited);
- loadSettings();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();\
+ connect(ui->customAPIkeyEdit, &QLineEdit::textEdited, this, &PasteEEPage::textEdited);
+ loadSettings();
}
PasteEEPage::~PasteEEPage()
{
- delete ui;
+ delete ui;
}
void PasteEEPage::loadSettings()
{
- auto s = MMC->settings();
- QString keyToUse = s->get("PasteEEAPIKey").toString();
- if(keyToUse == "multimc")
- {
- ui->multimcButton->setChecked(true);
- }
- else
- {
- ui->customButton->setChecked(true);
- ui->customAPIkeyEdit->setText(keyToUse);
- }
+ auto s = MMC->settings();
+ QString keyToUse = s->get("PasteEEAPIKey").toString();
+ if(keyToUse == "multimc")
+ {
+ ui->multimcButton->setChecked(true);
+ }
+ else
+ {
+ ui->customButton->setChecked(true);
+ ui->customAPIkeyEdit->setText(keyToUse);
+ }
}
void PasteEEPage::applySettings()
{
- auto s = MMC->settings();
+ auto s = MMC->settings();
- QString pasteKeyToUse;
- if (ui->customButton->isChecked())
- pasteKeyToUse = ui->customAPIkeyEdit->text();
- else
- {
- pasteKeyToUse = "multimc";
- }
- s->set("PasteEEAPIKey", pasteKeyToUse);
+ QString pasteKeyToUse;
+ if (ui->customButton->isChecked())
+ pasteKeyToUse = ui->customAPIkeyEdit->text();
+ else
+ {
+ pasteKeyToUse = "multimc";
+ }
+ s->set("PasteEEAPIKey", pasteKeyToUse);
}
bool PasteEEPage::apply()
{
- applySettings();
- return true;
+ applySettings();
+ return true;
}
void PasteEEPage::textEdited(const QString& text)
{
- ui->customButton->setChecked(true);
+ ui->customButton->setChecked(true);
}
diff --git a/application/pages/global/PasteEEPage.h b/application/pages/global/PasteEEPage.h
index 1b152577..78cf41f4 100644
--- a/application/pages/global/PasteEEPage.h
+++ b/application/pages/global/PasteEEPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,37 +26,37 @@ class PasteEEPage;
class PasteEEPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit PasteEEPage(QWidget *parent = 0);
- ~PasteEEPage();
-
- QString displayName() const override
- {
- return tr("Log Upload");
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("log");
- }
- QString id() const override
- {
- return "log-upload";
- }
- QString helpPage() const override
- {
- return "Log-Upload";
- }
- virtual bool apply() override;
+ explicit PasteEEPage(QWidget *parent = 0);
+ ~PasteEEPage();
+
+ QString displayName() const override
+ {
+ return tr("Log Upload");
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("log");
+ }
+ QString id() const override
+ {
+ return "log-upload";
+ }
+ QString helpPage() const override
+ {
+ return "Log-Upload";
+ }
+ virtual bool apply() override;
private:
- void loadSettings();
- void applySettings();
+ void loadSettings();
+ void applySettings();
private slots:
- void textEdited(const QString &text);
+ void textEdited(const QString &text);
private:
- Ui::PasteEEPage *ui;
+ Ui::PasteEEPage *ui;
};
diff --git a/application/pages/global/ProxyPage.cpp b/application/pages/global/ProxyPage.cpp
index 7dbcb860..ee56a54e 100644
--- a/application/pages/global/ProxyPage.cpp
+++ b/application/pages/global/ProxyPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,81 +16,86 @@
#include "ProxyPage.h"
#include "ui_ProxyPage.h"
+#include <QTabBar>
+
#include "settings/SettingsObject.h"
#include "MultiMC.h"
-#include <QTabBar>
+#include "Env.h"
ProxyPage::ProxyPage(QWidget *parent) : QWidget(parent), ui(new Ui::ProxyPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
- loadSettings();
- updateCheckboxStuff();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
+ loadSettings();
+ updateCheckboxStuff();
- connect(ui->proxyGroup, SIGNAL(buttonClicked(int)), SLOT(proxyChanged(int)));
+ connect(ui->proxyGroup, SIGNAL(buttonClicked(int)), SLOT(proxyChanged(int)));
}
ProxyPage::~ProxyPage()
{
- delete ui;
+ delete ui;
}
bool ProxyPage::apply()
{
- applySettings();
- return true;
+ applySettings();
+ return true;
}
void ProxyPage::updateCheckboxStuff()
{
- ui->proxyAddrBox->setEnabled(!ui->proxyNoneBtn->isChecked() &&
- !ui->proxyDefaultBtn->isChecked());
- ui->proxyAuthBox->setEnabled(!ui->proxyNoneBtn->isChecked() &&
- !ui->proxyDefaultBtn->isChecked());
+ ui->proxyAddrBox->setEnabled(!ui->proxyNoneBtn->isChecked() &&
+ !ui->proxyDefaultBtn->isChecked());
+ ui->proxyAuthBox->setEnabled(!ui->proxyNoneBtn->isChecked() &&
+ !ui->proxyDefaultBtn->isChecked());
}
void ProxyPage::proxyChanged(int)
{
- updateCheckboxStuff();
+ updateCheckboxStuff();
}
void ProxyPage::applySettings()
{
- auto s = MMC->settings();
+ auto s = MMC->settings();
+
+ // Proxy
+ QString proxyType = "None";
+ if (ui->proxyDefaultBtn->isChecked())
+ proxyType = "Default";
+ else if (ui->proxyNoneBtn->isChecked())
+ proxyType = "None";
+ else if (ui->proxySOCKS5Btn->isChecked())
+ proxyType = "SOCKS5";
+ else if (ui->proxyHTTPBtn->isChecked())
+ proxyType = "HTTP";
- // Proxy
- QString proxyType = "None";
- if (ui->proxyDefaultBtn->isChecked())
- proxyType = "Default";
- else if (ui->proxyNoneBtn->isChecked())
- proxyType = "None";
- else if (ui->proxySOCKS5Btn->isChecked())
- proxyType = "SOCKS5";
- else if (ui->proxyHTTPBtn->isChecked())
- proxyType = "HTTP";
+ s->set("ProxyType", proxyType);
+ s->set("ProxyAddr", ui->proxyAddrEdit->text());
+ s->set("ProxyPort", ui->proxyPortEdit->value());
+ s->set("ProxyUser", ui->proxyUserEdit->text());
+ s->set("ProxyPass", ui->proxyPassEdit->text());
- s->set("ProxyType", proxyType);
- s->set("ProxyAddr", ui->proxyAddrEdit->text());
- s->set("ProxyPort", ui->proxyPortEdit->value());
- s->set("ProxyUser", ui->proxyUserEdit->text());
- s->set("ProxyPass", ui->proxyPassEdit->text());
+ ENV.updateProxySettings(proxyType, ui->proxyAddrEdit->text(), ui->proxyPortEdit->value(),
+ ui->proxyUserEdit->text(), ui->proxyPassEdit->text());
}
void ProxyPage::loadSettings()
{
- auto s = MMC->settings();
- // Proxy
- QString proxyType = s->get("ProxyType").toString();
- if (proxyType == "Default")
- ui->proxyDefaultBtn->setChecked(true);
- else if (proxyType == "None")
- ui->proxyNoneBtn->setChecked(true);
- else if (proxyType == "SOCKS5")
- ui->proxySOCKS5Btn->setChecked(true);
- else if (proxyType == "HTTP")
- ui->proxyHTTPBtn->setChecked(true);
+ auto s = MMC->settings();
+ // Proxy
+ QString proxyType = s->get("ProxyType").toString();
+ if (proxyType == "Default")
+ ui->proxyDefaultBtn->setChecked(true);
+ else if (proxyType == "None")
+ ui->proxyNoneBtn->setChecked(true);
+ else if (proxyType == "SOCKS5")
+ ui->proxySOCKS5Btn->setChecked(true);
+ else if (proxyType == "HTTP")
+ ui->proxyHTTPBtn->setChecked(true);
- ui->proxyAddrEdit->setText(s->get("ProxyAddr").toString());
- ui->proxyPortEdit->setValue(s->get("ProxyPort").value<qint16>());
- ui->proxyUserEdit->setText(s->get("ProxyUser").toString());
- ui->proxyPassEdit->setText(s->get("ProxyPass").toString());
+ ui->proxyAddrEdit->setText(s->get("ProxyAddr").toString());
+ ui->proxyPortEdit->setValue(s->get("ProxyPort").value<qint16>());
+ ui->proxyUserEdit->setText(s->get("ProxyUser").toString());
+ ui->proxyPassEdit->setText(s->get("ProxyPass").toString());
}
diff --git a/application/pages/global/ProxyPage.h b/application/pages/global/ProxyPage.h
index 565c2857..d87bc120 100644
--- a/application/pages/global/ProxyPage.h
+++ b/application/pages/global/ProxyPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,39 +28,39 @@ class ProxyPage;
class ProxyPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit ProxyPage(QWidget *parent = 0);
- ~ProxyPage();
+ explicit ProxyPage(QWidget *parent = 0);
+ ~ProxyPage();
- QString displayName() const override
- {
- return tr("Proxy");
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("proxy");
- }
- QString id() const override
- {
- return "proxy-settings";
- }
- QString helpPage() const override
- {
- return "Proxy-settings";
- }
- bool apply() override;
+ QString displayName() const override
+ {
+ return tr("Proxy");
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("proxy");
+ }
+ QString id() const override
+ {
+ return "proxy-settings";
+ }
+ QString helpPage() const override
+ {
+ return "Proxy-settings";
+ }
+ bool apply() override;
private:
- void updateCheckboxStuff();
- void applySettings();
- void loadSettings();
+ void updateCheckboxStuff();
+ void applySettings();
+ void loadSettings();
private
slots:
- void proxyChanged(int);
+ void proxyChanged(int);
private:
- Ui::ProxyPage *ui;
+ Ui::ProxyPage *ui;
};
diff --git a/application/pages/instance/GameOptionsPage.cpp b/application/pages/instance/GameOptionsPage.cpp
new file mode 100644
index 00000000..5555fc79
--- /dev/null
+++ b/application/pages/instance/GameOptionsPage.cpp
@@ -0,0 +1,40 @@
+#include "GameOptionsPage.h"
+#include "ui_GameOptionsPage.h"
+#include "minecraft/MinecraftInstance.h"
+#include "minecraft/gameoptions/GameOptions.h"
+
+GameOptionsPage::GameOptionsPage(MinecraftInstance * inst, QWidget* parent)
+ : QWidget(parent), ui(new Ui::GameOptionsPage)
+{
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
+ m_model = inst->gameOptionsModel();
+ ui->optionsView->setModel(m_model.get());
+ auto head = ui->optionsView->header();
+ if(head->count())
+ {
+ head->setSectionResizeMode(0, QHeaderView::ResizeToContents);
+ for(int i = 1; i < head->count(); i++)
+ {
+ head->setSectionResizeMode(i, QHeaderView::Stretch);
+ }
+ }
+}
+
+GameOptionsPage::~GameOptionsPage()
+{
+ // m_model->save();
+}
+
+void GameOptionsPage::openedImpl()
+{
+ // m_model->observe();
+}
+
+void GameOptionsPage::closedImpl()
+{
+ // m_model->unobserve();
+}
+
+#include "GameOptionsPage.moc"
+
diff --git a/application/pages/instance/GameOptionsPage.h b/application/pages/instance/GameOptionsPage.h
new file mode 100644
index 00000000..ae47747f
--- /dev/null
+++ b/application/pages/instance/GameOptionsPage.h
@@ -0,0 +1,63 @@
+/* Copyright 2013-2019 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 <QWidget>
+#include <QString>
+
+#include "pages/BasePage.h"
+#include <MultiMC.h>
+
+namespace Ui
+{
+class GameOptionsPage;
+}
+
+class GameOptions;
+class MinecraftInstance;
+
+class GameOptionsPage : public QWidget, public BasePage
+{
+ Q_OBJECT
+
+public:
+ explicit GameOptionsPage(MinecraftInstance *inst, QWidget *parent = 0);
+ virtual ~GameOptionsPage();
+
+ void openedImpl() override;
+ void closedImpl() override;
+
+ virtual QString displayName() const override
+ {
+ return tr("Game Options");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("settings");
+ }
+ virtual QString id() const override
+ {
+ return "gameoptions";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Game-Options-management";
+ }
+
+private: // data
+ Ui::GameOptionsPage *ui = nullptr;
+ std::shared_ptr<GameOptions> m_model;
+};
diff --git a/application/pages/instance/GameOptionsPage.ui b/application/pages/instance/GameOptionsPage.ui
new file mode 100644
index 00000000..f0a5ce0e
--- /dev/null
+++ b/application/pages/instance/GameOptionsPage.ui
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>GameOptionsPage</class>
+ <widget class="QWidget" name="GameOptionsPage">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>706</width>
+ <height>575</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string notr="true">Tab 1</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0" colspan="2">
+ <widget class="QTreeView" name="optionsView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>64</width>
+ <height>64</height>
+ </size>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>tabWidget</tabstop>
+ <tabstop>optionsView</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/application/pages/instance/InstanceSettingsPage.cpp b/application/pages/instance/InstanceSettingsPage.cpp
index 71e90a32..b7b0a863 100644
--- a/application/pages/instance/InstanceSettingsPage.cpp
+++ b/application/pages/instance/InstanceSettingsPage.cpp
@@ -15,237 +15,271 @@
#include <widgets/CustomCommands.h>
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
- : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
+ : 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();
+ m_settings = inst->settings();
+ ui->setupUi(this);
+ auto sysMB = Sys::getSystemRam() / Sys::megabyte;
+ ui->maxMemSpinBox->setMaximum(sysMB);
+ connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
+ connect(MMC, &MultiMC::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
+ connect(MMC, &MultiMC::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
+ loadSettings();
}
bool InstanceSettingsPage::shouldDisplay() const
{
- return !m_instance->isRunning();
+ return !m_instance->isRunning();
}
InstanceSettingsPage::~InstanceSettingsPage()
{
- delete ui;
+ delete ui;
+}
+
+void InstanceSettingsPage::globalSettingsButtonClicked(bool)
+{
+ switch(ui->settingsTabs->currentIndex()) {
+ case 0:
+ MMC->ShowGlobalSettings(this, "java-settings");
+ return;
+ case 1:
+ MMC->ShowGlobalSettings(this, "minecraft-settings");
+ return;
+ case 2:
+ MMC->ShowGlobalSettings(this, "custom-commands");
+ return;
+ }
}
bool InstanceSettingsPage::apply()
{
- applySettings();
- return true;
+ 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");
- }
+ 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()
- );
+ // 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());
+ bool permGenVisible = m_settings->get("PermGenVisible").toBool();
+ ui->permGenSpinBox->setVisible(permGenVisible);
+ ui->labelPermGen->setVisible(permGenVisible);
+ ui->labelPermgenNote->setVisible(permGenVisible);
+
+
+ // 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;
+ JavaInstallPtr java;
- VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true);
- vselect.setResizeOn(2);
- vselect.exec();
+ 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<JavaInstall>(vselect.selectedVersion());
- ui->javaPathTextBox->setText(java->path);
- }
+ if (vselect.result() == QDialog::Accepted && vselect.selectedVersion())
+ {
+ java = std::dynamic_pointer_cast<JavaInstall>(vselect.selectedVersion());
+ ui->javaPathTextBox->setText(java->path);
+ bool visible = java->id.requiresPermGen() && m_settings->get("OverrideMemory").toBool();
+ ui->permGenSpinBox->setVisible(visible);
+ ui->labelPermGen->setVisible(visible);
+ ui->labelPermgenNote->setVisible(visible);
+ m_settings->set("PermGenVisible", visible);
+ }
}
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);
+ 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);
+
+ // custom Java could be anything... enable perm gen option
+ ui->permGenSpinBox->setVisible(true);
+ ui->labelPermGen->setVisible(true);
+ ui->labelPermgenNote->setVisible(true);
+ m_settings->set("PermGenVisible", true);
}
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();
+ 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();
+ checker.reset();
}
diff --git a/application/pages/instance/InstanceSettingsPage.h b/application/pages/instance/InstanceSettingsPage.h
index c5d7d3b6..c3c78fd5 100644
--- a/application/pages/instance/InstanceSettingsPage.h
+++ b/application/pages/instance/InstanceSettingsPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,43 +32,45 @@ class InstanceSettingsPage;
class InstanceSettingsPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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 on_javaDetectBtn_clicked();
+ void on_javaTestBtn_clicked();
+ void on_javaBrowseBtn_clicked();
- void applySettings();
- void loadSettings();
+ void applySettings();
+ void loadSettings();
- void checkerFinished();
+ void checkerFinished();
+
+ void globalSettingsButtonClicked(bool checked);
private:
- Ui::InstanceSettingsPage *ui;
- BaseInstance *m_instance;
- SettingsObjectPtr m_settings;
- unique_qobject_ptr<JavaCommon::TestCheck> checker;
+ Ui::InstanceSettingsPage *ui;
+ BaseInstance *m_instance;
+ SettingsObjectPtr m_settings;
+ unique_qobject_ptr<JavaCommon::TestCheck> checker;
};
diff --git a/application/pages/instance/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui
index 0c180df3..d6de53ee 100644
--- a/application/pages/instance/InstanceSettingsPage.ui
+++ b/application/pages/instance/InstanceSettingsPage.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>553</width>
- <height>522</height>
+ <width>738</width>
+ <height>804</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -24,6 +24,16 @@
<number>0</number>
</property>
<item>
+ <widget class="QCommandLinkButton" name="openGlobalJavaSettingsButton">
+ <property name="text">
+ <string>Open Global Settings</string>
+ </property>
+ <property name="description">
+ <string>The settings here are overrides for global settings.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QTabWidget" name="settingsTabs">
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
@@ -367,6 +377,7 @@
</customwidget>
</customwidgets>
<tabstops>
+ <tabstop>openGlobalJavaSettingsButton</tabstop>
<tabstop>settingsTabs</tabstop>
<tabstop>javaSettingsGroupBox</tabstop>
<tabstop>javaPathTextBox</tabstop>
diff --git a/application/pages/instance/LegacyUpgradePage.cpp b/application/pages/instance/LegacyUpgradePage.cpp
index f808ab88..af800b03 100644
--- a/application/pages/instance/LegacyUpgradePage.cpp
+++ b/application/pages/instance/LegacyUpgradePage.cpp
@@ -1,50 +1,50 @@
#include "LegacyUpgradePage.h"
#include "ui_LegacyUpgradePage.h"
+#include "InstanceList.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)
+ : QWidget(parent), ui(new Ui::LegacyUpgradePage), m_inst(inst)
{
- ui->setupUi(this);
+ ui->setupUi(this);
}
LegacyUpgradePage::~LegacyUpgradePage()
{
- delete ui;
+ 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();
- }
+ 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> task(MMC->folderProvider()->wrapInstanceTask(upgradeTask));
- runModalTask(task.get());
+ QString newName = tr("%1 (Migrated)").arg(m_inst->name());
+ auto upgradeTask = new LegacyUpgradeTask(m_inst);
+ upgradeTask->setName(newName);
+ upgradeTask->setGroup(MMC->instances()->getInstanceGroup(m_inst->id()));
+ upgradeTask->setIcon(m_inst->iconKey());
+ unique_qobject_ptr<Task> task(MMC->instances()->wrapInstanceTask(upgradeTask));
+ runModalTask(task.get());
}
bool LegacyUpgradePage::shouldDisplay() const
{
- return !m_inst->isRunning();
+ return !m_inst->isRunning();
}
diff --git a/application/pages/instance/LegacyUpgradePage.h b/application/pages/instance/LegacyUpgradePage.h
index 3e1abe93..4f86a721 100644
--- a/application/pages/instance/LegacyUpgradePage.h
+++ b/application/pages/instance/LegacyUpgradePage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,36 +29,36 @@ class LegacyUpgradePage;
class LegacyUpgradePage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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();
+ void on_upgradeButton_clicked();
private:
- void runModalTask(Task *task);
+ void runModalTask(Task *task);
private:
- Ui::LegacyUpgradePage *ui;
- InstancePtr m_inst;
+ Ui::LegacyUpgradePage *ui;
+ InstancePtr m_inst;
};
diff --git a/application/pages/instance/LogPage.cpp b/application/pages/instance/LogPage.cpp
index 0fa1ee67..94ada424 100644
--- a/application/pages/instance/LogPage.cpp
+++ b/application/pages/instance/LogPage.cpp
@@ -15,298 +15,298 @@
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();
- }
+ 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<LogColorCache> m_colors;
+ QFont m_font;
+ std::unique_ptr<LogColorCache> m_colors;
};
LogPage::LogPage(InstancePtr instance, QWidget *parent)
- : QWidget(parent), ui(new Ui::LogPage), m_instance(instance)
+ : 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()));
+ 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;
+ 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);
- }
+ 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);
+ 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<LaunchTask> proc, bool initial)
+void LogPage::setInstanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> 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();
- }
+ 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<LaunchTask> proc)
+void LogPage::onInstanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc)
{
- setInstanceLaunchTaskChanged(proc, false);
+ setInstanceLaunchTaskChanged(proc, false);
}
bool LogPage::apply()
{
- return true;
+ return true;
}
bool LogPage::shouldDisplay() const
{
- return m_instance->isRunning() || m_proxy->rowCount() > 0;
+ 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!"));
- }
+ 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());
+ 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();
+ if(!m_model)
+ return;
+ m_model->clear();
+ m_container->refreshContainer();
}
void LogPage::on_btnBottom_clicked()
{
- ui->text->scrollToBottom();
+ ui->text->scrollToBottom();
}
void LogPage::on_trackLogCheckbox_clicked(bool checked)
{
- if(!m_model)
- return;
- m_model->suspend(!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);
+ 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);
+ 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);
+ ui->text->findNext(ui->searchBar->text(), false);
}
void LogPage::findPreviousActivated()
{
- ui->text->findNext(ui->searchBar->text(), true);
+ 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();
- }
+ // 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
index 2229418d..9c3b56a9 100644
--- a/application/pages/instance/LogPage.h
+++ b/application/pages/instance/LogPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,56 +31,56 @@ class LogFormatProxyModel;
class LogPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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_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_trackLogCheckbox_clicked(bool checked);
+ void on_wrapCheckbox_clicked(bool checked);
- void on_findButton_clicked();
- void findActivated();
- void findNextActivated();
- void findPreviousActivated();
+ void on_findButton_clicked();
+ void findActivated();
+ void findNextActivated();
+ void findPreviousActivated();
- void onInstanceLaunchTaskChanged(std::shared_ptr<LaunchTask> proc);
+ void onInstanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc);
private:
- void modelStateToUI();
- void UIToModelState();
- void setInstanceLaunchTaskChanged(std::shared_ptr<LaunchTask> proc, bool initial);
+ void modelStateToUI();
+ void UIToModelState();
+ void setInstanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc, bool initial);
private:
- Ui::LogPage *ui;
- InstancePtr m_instance;
- std::shared_ptr<LaunchTask> m_process;
+ Ui::LogPage *ui;
+ InstancePtr m_instance;
+ shared_qobject_ptr<LaunchTask> m_process;
- LogFormatProxyModel * m_proxy;
- shared_qobject_ptr <LogModel> m_model;
+ LogFormatProxyModel * m_proxy;
+ shared_qobject_ptr <LogModel> m_model;
};
diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp
index 90155df3..d449f8bf 100644
--- a/application/pages/instance/ModFolderPage.cpp
+++ b/application/pages/instance/ModFolderPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,191 +20,324 @@
#include <QEvent>
#include <QKeyEvent>
#include <QAbstractItemModel>
+#include <QMenu>
#include "MultiMC.h"
#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ModEditDialogCommon.h"
#include <GuiUtil.h>
-#include "minecraft/ModList.h"
-#include "minecraft/Mod.h"
+#include "minecraft/mod/ModFolderModel.h"
+#include "minecraft/mod/Mod.h"
#include "minecraft/VersionFilterData.h"
#include "minecraft/ComponentList.h"
#include <DesktopServices.h>
-ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> 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 );
+#include <QSortFilterProxyModel>
+#include "Version.h"
+
+namespace {
+ // FIXME: wasteful
+ void RemoveThePrefix(QString & string) {
+ QRegularExpression regex(QStringLiteral("^(([Tt][Hh][eE])|([Tt][eE][Hh])) +"));
+ string.remove(regex);
+ string = string.trimmed();
+ }
+}
+
+class ModSortProxy : public QSortFilterProxyModel
+{
+public:
+ explicit ModSortProxy(QObject *parent = 0) : QSortFilterProxyModel(parent)
+ {
+ }
+
+protected:
+ bool lessThan(const QModelIndex & source_left, const QModelIndex & source_right) const override
+ {
+ ModFolderModel *model = qobject_cast<ModFolderModel *>(sourceModel());
+ if(
+ !model ||
+ !source_left.isValid() ||
+ !source_right.isValid() ||
+ source_left.column() != source_right.column()
+ ) {
+ return QSortFilterProxyModel::lessThan(source_left, source_right);
+ }
+
+ // we are now guaranteed to have two valid indexes in the same column... we love the provided invariants unconditionally and proceed.
+
+ auto column = (ModFolderModel::Columns) source_left.column();
+ bool invert = false;
+ switch(column) {
+ // GH-2550 - sort by enabled/disabled
+ case ModFolderModel::ActiveColumn: {
+ auto dataL = source_left.data(Qt::CheckStateRole).toBool();
+ auto dataR = source_right.data(Qt::CheckStateRole).toBool();
+ if(dataL != dataR) {
+ return dataL > dataR;
+ }
+ // fallthrough
+ invert = sortOrder() == Qt::DescendingOrder;
+ }
+ // GH-2722 - sort mod names in a way that discards "The" prefixes
+ case ModFolderModel::NameColumn: {
+ auto dataL = model->data(model->index(source_left.row(), ModFolderModel::NameColumn)).toString();
+ RemoveThePrefix(dataL);
+ auto dataR = model->data(model->index(source_right.row(), ModFolderModel::NameColumn)).toString();
+ RemoveThePrefix(dataR);
+
+ auto less = dataL.compare(dataR, sortCaseSensitivity());
+ if(less != 0) {
+ return invert ? (less > 0) : (less < 0);
+ }
+ // fallthrough
+ invert = sortOrder() == Qt::DescendingOrder;
+ }
+ // GH-2762 - sort versions by parsing them as versions
+ case ModFolderModel::VersionColumn: {
+ auto dataL = Version(model->data(model->index(source_left.row(), ModFolderModel::VersionColumn)).toString());
+ auto dataR = Version(model->data(model->index(source_right.row(), ModFolderModel::VersionColumn)).toString());
+ return invert ? (dataL > dataR) : (dataL < dataR);
+ }
+ default: {
+ return QSortFilterProxyModel::lessThan(source_left, source_right);
+ }
+ }
+ }
+};
+
+ModFolderPage::ModFolderPage(
+ BaseInstance *inst,
+ std::shared_ptr<ModFolderModel> mods,
+ QString id,
+ QString iconName,
+ QString displayName,
+ QString helpPage,
+ QWidget *parent
+) :
+ QMainWindow(parent),
+ ui(new Ui::ModFolderPage)
+{
+ ui->setupUi(this);
+ ui->actionsToolbar->insertSpacer(ui->actionView_configs);
+
+ m_inst = inst;
+ on_RunningState_changed(m_inst && m_inst->isRunning());
+ m_mods = mods;
+ m_id = id;
+ m_displayName = displayName;
+ m_iconName = iconName;
+ m_helpName = helpPage;
+ m_fileSelectionFilter = "%1 (*.zip *.jar)";
+ m_filterModel = new ModSortProxy(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);
+ ui->modTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(ui->modTreeView, &ModListView::customContextMenuRequested, this, &ModFolderPage::ShowContextMenu);
+ connect(ui->modTreeView, &ModListView::activated, this, &ModFolderPage::modItemActivated);
+
+ auto smodel = ui->modTreeView->selectionModel();
+ connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent);
+ connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged );
+ connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed);
+}
+
+void ModFolderPage::modItemActivated(const QModelIndex&)
+{
+ if(!m_controlsEnabled) {
+ return;
+ }
+ auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
+ m_mods->setModStatus(selection.indexes(), ModFolderModel::Toggle);
+}
+
+QMenu * ModFolderPage::createPopupMenu()
+{
+ QMenu* filteredMenu = QMainWindow::createPopupMenu();
+ filteredMenu->removeAction(ui->actionsToolbar->toggleViewAction() );
+ return filteredMenu;
+}
+
+void ModFolderPage::ShowContextMenu(const QPoint& pos)
+{
+ auto menu = ui->actionsToolbar->createContextMenu(this, tr("Context menu"));
+ menu->exec(ui->modTreeView->mapToGlobal(pos));
+ delete menu;
}
void ModFolderPage::openedImpl()
{
- m_mods->startWatching();
+ m_mods->startWatching();
}
void ModFolderPage::closedImpl()
{
- m_mods->stopWatching();
+ m_mods->stopWatching();
}
void ModFolderPage::on_filterTextChanged(const QString& newContents)
{
- m_viewFilter = newContents;
- m_filterModel->setFilterFixedString(m_viewFilter);
+ m_viewFilter = newContents;
+ m_filterModel->setFilterFixedString(m_viewFilter);
}
-CoreModFolderPage::CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods,
- QString id, QString iconName, QString displayName,
- QString helpPage, QWidget *parent)
- : ModFolderPage(inst, mods, id, iconName, displayName, helpPage, parent)
+CoreModFolderPage::CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModFolderModel> 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;
+ m_mods->stopWatching();
+ delete ui;
+}
+
+void ModFolderPage::on_RunningState_changed(bool running)
+{
+ if(m_controlsEnabled == !running) {
+ return;
+ }
+ m_controlsEnabled = !running;
+ ui->actionAdd->setEnabled(m_controlsEnabled);
+ ui->actionDisable->setEnabled(m_controlsEnabled);
+ ui->actionEnable->setEnabled(m_controlsEnabled);
+ ui->actionRemove->setEnabled(m_controlsEnabled);
}
bool ModFolderPage::shouldDisplay() const
{
- if (m_inst)
- return !m_inst->isRunning();
- return true;
+ return true;
}
bool CoreModFolderPage::shouldDisplay() const
{
- if (ModFolderPage::shouldDisplay())
- {
- auto inst = dynamic_cast<MinecraftInstance *>(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;
+ if (ModFolderPage::shouldDisplay())
+ {
+ auto inst = dynamic_cast<MinecraftInstance *>(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);
+ switch (keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ on_actionRemove_triggered();
+ return true;
+ case Qt::Key_Plus:
+ on_actionAdd_triggered();
+ 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<QKeyEvent *>(ev);
- if (obj == ui->modTreeView)
- return modListFilter(keyEvent);
- return QWidget::eventFilter(obj, ev);
+ if (ev->type() != QEvent::KeyPress)
+ {
+ return QWidget::eventFilter(obj, ev);
+ }
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
+ if (obj == ui->modTreeView)
+ return modListFilter(keyEvent);
+ return QWidget::eventFilter(obj, ev);
}
-void ModFolderPage::on_addModBtn_clicked()
+void ModFolderPage::on_actionAdd_triggered()
{
- 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);
- }
- }
+ if(!m_controlsEnabled) {
+ return;
+ }
+ 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()
+void ModFolderPage::on_actionEnable_triggered()
{
- auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
- m_mods->enableMods(selection.indexes(), true);
+ if(!m_controlsEnabled) {
+ return;
+ }
+ auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
+ m_mods->setModStatus(selection.indexes(), ModFolderModel::Enable);
}
-void ModFolderPage::on_disableModBtn_clicked()
+void ModFolderPage::on_actionDisable_triggered()
{
- auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
- m_mods->enableMods(selection.indexes(), false);
+ if(!m_controlsEnabled) {
+ return;
+ }
+ auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
+ m_mods->setModStatus(selection.indexes(), ModFolderModel::Disable);
}
-void ModFolderPage::on_rmModBtn_clicked()
+void ModFolderPage::on_actionRemove_triggered()
{
- auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
- m_mods->deleteMods(selection.indexes());
+ if(!m_controlsEnabled) {
+ return;
+ }
+ auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
+ m_mods->deleteMods(selection.indexes());
}
-void ModFolderPage::on_configFolderBtn_clicked()
+void ModFolderPage::on_actionView_configs_triggered()
{
- DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true);
+ DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true);
}
-void ModFolderPage::on_viewModBtn_clicked()
+void ModFolderPage::on_actionView_Folder_triggered()
{
- DesktopServices::openDirectory(m_mods->dir().absolutePath(), true);
+ DesktopServices::openDirectory(m_mods->dir().absolutePath(), true);
}
void ModFolderPage::modCurrent(const QModelIndex &current, 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);
+ 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
index 15e728cb..d49d25c3 100644
--- a/application/pages/instance/ModFolderPage.h
+++ b/application/pages/instance/ModFolderPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,94 +15,105 @@
#pragma once
-#include <QWidget>
+#include <QMainWindow>
#include "minecraft/MinecraftInstance.h"
#include "pages/BasePage.h"
#include <MultiMC.h>
-class ModList;
+class ModFolderModel;
namespace Ui
{
class ModFolderPage;
}
-class ModFolderPage : public QWidget, public BasePage
+class ModFolderPage : public QMainWindow, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id,
- QString iconName, QString displayName, QString helpPage = "",
- QWidget *parent = 0);
- virtual ~ModFolderPage();
+ explicit ModFolderPage(
+ BaseInstance *inst,
+ std::shared_ptr<ModFolderModel> mods,
+ QString id,
+ QString iconName,
+ QString displayName,
+ QString helpPage = "",
+ QWidget *parent = 0
+ );
+ virtual ~ModFolderPage();
- void setFilter(const QString & filter)
- {
- m_fileSelectionFilter = filter;
- }
+ 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 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;
+ virtual void openedImpl() override;
+ virtual void closedImpl() override;
protected:
- bool eventFilter(QObject *obj, QEvent *ev) override;
- bool modListFilter(QKeyEvent *ev);
+ bool eventFilter(QObject *obj, QEvent *ev) override;
+ bool modListFilter(QKeyEvent *ev);
+ QMenu * createPopupMenu() override;
protected:
- BaseInstance *m_inst;
+ BaseInstance *m_inst = nullptr;
protected:
- Ui::ModFolderPage *ui;
- std::shared_ptr<ModList> m_mods;
- QSortFilterProxyModel *m_filterModel;
- QString m_iconName;
- QString m_id;
- QString m_displayName;
- QString m_helpName;
- QString m_fileSelectionFilter;
- QString m_viewFilter;
+ Ui::ModFolderPage *ui = nullptr;
+ std::shared_ptr<ModFolderModel> m_mods;
+ QSortFilterProxyModel *m_filterModel = nullptr;
+ QString m_iconName;
+ QString m_id;
+ QString m_displayName;
+ QString m_helpName;
+ QString m_fileSelectionFilter;
+ QString m_viewFilter;
+ bool m_controlsEnabled = true;
public
slots:
- void modCurrent(const QModelIndex &current, const QModelIndex &previous);
+ void modCurrent(const QModelIndex &current, 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();
+ void modItemActivated(const QModelIndex &index);
+ void on_filterTextChanged(const QString & newContents);
+ void on_RunningState_changed(bool running);
+ void on_actionAdd_triggered();
+ void on_actionRemove_triggered();
+ void on_actionEnable_triggered();
+ void on_actionDisable_triggered();
+ void on_actionView_Folder_triggered();
+ void on_actionView_configs_triggered();
+ void ShowContextMenu(const QPoint &pos);
};
class CoreModFolderPage : public ModFolderPage
{
public:
- explicit CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id,
- QString iconName, QString displayName, QString helpPage = "",
- QWidget *parent = 0);
- virtual ~CoreModFolderPage()
- {
- }
- virtual bool shouldDisplay() const;
+ explicit CoreModFolderPage(BaseInstance *inst, std::shared_ptr<ModFolderModel> 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
index b5597bdc..052df602 100644
--- a/application/pages/instance/ModFolderPage.ui
+++ b/application/pages/instance/ModFolderPage.ui
@@ -1,155 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ModFolderPage</class>
- <widget class="QWidget" name="ModFolderPage">
+ <widget class="QMainWindow" name="ModFolderPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>723</width>
- <height>532</height>
+ <width>1042</width>
+ <height>501</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
- </property>
- <widget class="QWidget" name="tab">
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QGridLayout" name="gridLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item row="4" column="1" colspan="3">
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="filterEdit">
+ <property name="clearButtonEnabled">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="filterLabel">
+ <property name="text">
+ <string>Filter:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="1" colspan="3">
+ <widget class="MCModInfoFrame" name="frame">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="3">
+ <widget class="ModListView" name="modTreeView">
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <attribute name="title">
- <string notr="true">Tab 1</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0">
- <item row="0" column="2">
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QPushButton" name="addModBtn">
- <property name="text">
- <string>&amp;Add</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="rmModBtn">
- <property name="text">
- <string>&amp;Remove</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="enableModBtn">
- <property name="text">
- <string>Enable</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="disableModBtn">
- <property name="text">
- <string>Disable</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="configFolderBtn">
- <property name="toolTip">
- <string>Open the 'config' folder in the system file manager.</string>
- </property>
- <property name="text">
- <string>View configs</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="viewModBtn">
- <property name="text">
- <string>&amp;View Folder</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="1" column="0" colspan="3">
- <widget class="MCModInfoFrame" name="frame">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item row="0" column="0" colspan="2">
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="1" column="1">
- <widget class="QLineEdit" name="filterEdit">
- <property name="clearButtonEnabled">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="filterLabel">
- <property name="text">
- <string>Filter:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0" colspan="3">
- <widget class="ModListView" name="modTreeView">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="acceptDrops">
- <bool>true</bool>
- </property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::DropOnly</enum>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DropOnly</enum>
+ </property>
</widget>
- </widget>
- </item>
- </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="WideBar" name="actionsToolbar">
+ <property name="windowTitle">
+ <string>Actions</string>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextOnly</enum>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>RightToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionAdd"/>
+ <addaction name="separator"/>
+ <addaction name="actionRemove"/>
+ <addaction name="actionEnable"/>
+ <addaction name="actionDisable"/>
+ <addaction name="actionView_configs"/>
+ <addaction name="actionView_Folder"/>
+ </widget>
+ <action name="actionAdd">
+ <property name="text">
+ <string>&amp;Add</string>
+ </property>
+ <property name="toolTip">
+ <string>Add mods</string>
+ </property>
+ </action>
+ <action name="actionRemove">
+ <property name="text">
+ <string>&amp;Remove</string>
+ </property>
+ <property name="toolTip">
+ <string>Remove selected mods</string>
+ </property>
+ </action>
+ <action name="actionEnable">
+ <property name="text">
+ <string>&amp;Enable</string>
+ </property>
+ <property name="toolTip">
+ <string>Enable selected mods</string>
+ </property>
+ </action>
+ <action name="actionDisable">
+ <property name="text">
+ <string>&amp;Disable</string>
+ </property>
+ <property name="toolTip">
+ <string>Disable selected mods</string>
+ </property>
+ </action>
+ <action name="actionView_configs">
+ <property name="text">
+ <string>View &amp;Configs</string>
+ </property>
+ <property name="toolTip">
+ <string>Open the 'config' folder in the system file manager.</string>
+ </property>
+ </action>
+ <action name="actionView_Folder">
+ <property name="text">
+ <string>View &amp;Folder</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
@@ -163,17 +152,15 @@
<header>widgets/MCModInfoFrame.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>WideBar</class>
+ <extends>QToolBar</extends>
+ <header>widgets/WideBar.h</header>
+ </customwidget>
</customwidgets>
<tabstops>
- <tabstop>tabWidget</tabstop>
<tabstop>modTreeView</tabstop>
<tabstop>filterEdit</tabstop>
- <tabstop>addModBtn</tabstop>
- <tabstop>rmModBtn</tabstop>
- <tabstop>enableModBtn</tabstop>
- <tabstop>disableModBtn</tabstop>
- <tabstop>configFolderBtn</tabstop>
- <tabstop>viewModBtn</tabstop>
</tabstops>
<resources/>
<connections/>
diff --git a/application/pages/instance/NotesPage.cpp b/application/pages/instance/NotesPage.cpp
index 3925fdfc..fa966c91 100644
--- a/application/pages/instance/NotesPage.cpp
+++ b/application/pages/instance/NotesPage.cpp
@@ -3,20 +3,19 @@
#include <QTabBar>
NotesPage::NotesPage(BaseInstance *inst, QWidget *parent)
- : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst)
+ : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
- ui->noteEditor->setText(m_inst->notes());
+ ui->setupUi(this);
+ ui->noteEditor->setText(m_inst->notes());
}
NotesPage::~NotesPage()
{
- delete ui;
+ delete ui;
}
bool NotesPage::apply()
{
- m_inst->setNotes(ui->noteEditor->toPlainText());
- return true;
+ m_inst->setNotes(ui->noteEditor->toPlainText());
+ return true;
}
diff --git a/application/pages/instance/NotesPage.h b/application/pages/instance/NotesPage.h
index 4a25f9b1..f96e5374 100644
--- a/application/pages/instance/NotesPage.h
+++ b/application/pages/instance/NotesPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,33 +28,33 @@ class NotesPage;
class NotesPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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";
- }
+ 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;
+ Ui::NotesPage *ui;
+ BaseInstance *m_inst;
};
diff --git a/application/pages/instance/NotesPage.ui b/application/pages/instance/NotesPage.ui
index 88cca92f..67cb261c 100644
--- a/application/pages/instance/NotesPage.ui
+++ b/application/pages/instance/NotesPage.ui
@@ -10,7 +10,7 @@
<height>538</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
+ <layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
@@ -24,34 +24,26 @@
<number>0</number>
</property>
<item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
+ <widget class="QTextEdit" name="noteEditor">
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
+ <property name="tabChangesFocus">
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
- <widget class="QWidget" name="tab">
- <attribute name="title">
- <string notr="true">Tab 1</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QTextEdit" name="noteEditor">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOn</enum>
- </property>
- <property name="acceptRichText">
- <bool>false</bool>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
</widget>
</item>
</layout>
</widget>
+ <tabstops>
+ <tabstop>noteEditor</tabstop>
+ </tabstops>
<resources/>
<connections/>
</ui>
diff --git a/application/pages/instance/OtherLogsPage.cpp b/application/pages/instance/OtherLogsPage.cpp
index 10cb1145..387db74f 100644
--- a/application/pages/instance/OtherLogsPage.cpp
+++ b/application/pages/instance/OtherLogsPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,289 +25,289 @@
#include <QShortcut>
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))
+ : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter),
+ m_watcher(new RecursiveFileSystemWatcher(this))
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
- m_watcher->setMatcher(fileFilter);
- m_watcher->setRootDir(QDir::current().absoluteFilePath(m_path));
+ m_watcher->setMatcher(fileFilter);
+ m_watcher->setRootDir(QDir::current().absoluteFilePath(m_path));
- connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this, &OtherLogsPage::populateSelectLogBox);
- populateSelectLogBox();
+ 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 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 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);
+ 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);
+ connect(ui->searchBar, &QLineEdit::returnPressed, this, &OtherLogsPage::on_findButton_clicked);
}
OtherLogsPage::~OtherLogsPage()
{
- delete ui;
+ delete ui;
}
void OtherLogsPage::openedImpl()
{
- m_watcher->enable();
+ m_watcher->enable();
}
void OtherLogsPage::closedImpl()
{
- m_watcher->disable();
+ 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);
- }
- }
+ 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);
- }
+ 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);
- }
+ 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);
- }
+ 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);
+ GuiUtil::uploadPaste(ui->text->toPlainText(), this);
}
void OtherLogsPage::on_btnCopy_clicked()
{
- GuiUtil::setClipboardText(ui->text->toPlainText());
+ 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()));
- }
+ 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);
+ 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();
- }
+ 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);
+ 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));
+ _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);
+ 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);
+ findNext(ui->text, ui->searchBar->text(), false);
}
void OtherLogsPage::findPreviousActivated()
{
- findNext(ui->text, ui->searchBar->text(), true);
+ 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();
- }
+ // 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
index ac01ef0a..226f3af3 100644
--- a/application/pages/instance/OtherLogsPage.h
+++ b/application/pages/instance/OtherLogsPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,52 +30,52 @@ class RecursiveFileSystemWatcher;
class OtherLogsPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent = 0);
- ~OtherLogsPage();
+ 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;
+ 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 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();
+ void on_findButton_clicked();
+ void findActivated();
+ void findNextActivated();
+ void findPreviousActivated();
private:
- void setControlsEnabled(const bool enabled);
+ void setControlsEnabled(const bool enabled);
private:
- Ui::OtherLogsPage *ui;
- QString m_path;
- QString m_currentFile;
- IPathMatcher::Ptr m_fileFilter;
- RecursiveFileSystemWatcher *m_watcher;
+ Ui::OtherLogsPage *ui;
+ QString m_path;
+ QString m_currentFile;
+ IPathMatcher::Ptr m_fileFilter;
+ RecursiveFileSystemWatcher *m_watcher;
};
diff --git a/application/pages/instance/ResourcePackPage.h b/application/pages/instance/ResourcePackPage.h
index 19dc78da..e11c78a3 100644
--- a/application/pages/instance/ResourcePackPage.h
+++ b/application/pages/instance/ResourcePackPage.h
@@ -4,18 +4,19 @@
class ResourcePackPage : public ModFolderPage
{
+ Q_OBJECT
public:
- explicit ResourcePackPage(MinecraftInstance *instance, QWidget *parent = 0)
- : ModFolderPage(instance, instance->resourcePackList(), "resourcepacks",
- "resourcepacks", tr("Resource packs"), "Resource-packs", parent)
- {
- ui->configFolderBtn->setHidden(true);
- }
+ explicit ResourcePackPage(MinecraftInstance *instance, QWidget *parent = 0)
+ : ModFolderPage(instance, instance->resourcePackList(), "resourcepacks",
+ "resourcepacks", tr("Resource packs"), "Resource-packs", parent)
+ {
+ ui->actionView_configs->setVisible(false);
+ }
- virtual ~ResourcePackPage() {}
- virtual bool shouldDisplay() const override
- {
- return !m_inst->traits().contains("no-texturepacks") &&
- !m_inst->traits().contains("texturepacks");
- }
+ 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
index 71458386..efa0f9f2 100644
--- a/application/pages/instance/ScreenshotsPage.cpp
+++ b/application/pages/instance/ScreenshotsPage.cpp
@@ -13,6 +13,7 @@
#include <QPainter>
#include <QClipboard>
#include <QKeyEvent>
+#include <QMenu>
#include <MultiMC.h>
@@ -32,341 +33,390 @@ typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr;
class ThumbnailingResult : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public slots:
- inline void emitResultsReady(const QString &path) { emit resultsReady(path); }
- inline void emitResultsFailed(const QString &path) { emit resultsFailed(path); }
+ 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);
+ 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;
+ 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
+ Q_OBJECT
public:
- explicit FilterModel(QObject *parent = 0) : QIdentityProxyModel(parent)
- {
- m_thumbnailingPool.setMaxThreadCount(4);
- m_thumbnailCache = std::make_shared<SharedIconCache>();
- 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<QString> &)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);
- }
+ explicit FilterModel(QObject *parent = 0) : QIdentityProxyModel(parent)
+ {
+ m_thumbnailingPool.setMaxThreadCount(4);
+ m_thumbnailCache = std::make_shared<SharedIconCache>();
+ 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<QString> &)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);
- }
+ 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);
- }
+ 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<QString> m_failed;
- QSet<QString> watched;
- QFileSystemWatcher watcher;
+ SharedIconCachePtr m_thumbnailCache;
+ QThreadPool m_thumbnailingPool;
+ QSet<QString> m_failed;
+ QSet<QString> 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<QLineEdit *>(widget);
- if (foo)
- {
- foo->setAlignment(Qt::AlignHCenter);
- foo->setFrame(true);
- foo->setMaximumWidth(192);
- }
- return widget;
- }
+ 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<QLineEdit *>(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)
+ : QMainWindow(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)));
+ 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->toolBar->insertSpacer(ui->actionView_Folder);
+
+ 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));
+ ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(ui->listView, &QListView::customContextMenuRequested, this, &ScreenshotsPage::ShowContextMenu);
+ 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<QKeyEvent *>(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);
+ if (obj != ui->listView)
+ return QWidget::eventFilter(obj, evt);
+ if (evt->type() != QEvent::KeyPress)
+ {
+ return QWidget::eventFilter(obj, evt);
+ }
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt);
+ switch (keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ on_actionDelete_triggered();
+ return true;
+ case Qt::Key_F2:
+ on_actionRename_triggered();
+ return true;
+ default:
+ break;
+ }
+ return QWidget::eventFilter(obj, evt);
}
ScreenshotsPage::~ScreenshotsPage()
{
- delete ui;
+ delete ui;
+}
+
+void ScreenshotsPage::ShowContextMenu(const QPoint& pos)
+{
+ auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
+ menu->exec(ui->listView->mapToGlobal(pos));
+ delete menu;
+}
+
+QMenu * ScreenshotsPage::createPopupMenu()
+{
+ QMenu* filteredMenu = QMainWindow::createPopupMenu();
+ filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
+ return filteredMenu;
}
void ScreenshotsPage::onItemActivated(QModelIndex index)
{
- if (!index.isValid())
- return;
- auto info = m_model->fileInfo(index);
- QString fileName = info.absoluteFilePath();
- DesktopServices::openFile(info.absoluteFilePath());
+ if (!index.isValid())
+ return;
+ auto info = m_model->fileInfo(index);
+ QString fileName = info.absoluteFilePath();
+ DesktopServices::openFile(info.absoluteFilePath());
}
-void ScreenshotsPage::on_viewFolderBtn_clicked()
+void ScreenshotsPage::on_actionView_Folder_triggered()
{
- DesktopServices::openDirectory(m_folder, true);
+ DesktopServices::openDirectory(m_folder, true);
}
-void ScreenshotsPage::on_uploadBtn_clicked()
+void ScreenshotsPage::on_actionUpload_triggered()
{
- auto selection = ui->listView->selectionModel()->selectedRows();
- if (selection.isEmpty())
- return;
-
- QList<ScreenshotPtr> uploaded;
- auto job = NetJobPtr(new NetJob("Screenshot Upload"));
- for (auto item : selection)
- {
- auto info = m_model->fileInfo(item);
- auto screenshot = std::make_shared<ScreenShot>(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 <a href=\"%1\">link to the uploaded album</a> has been placed in your clipboard.") .arg(link),
- QMessageBox::Information
- )->exec();
- }
- m_uploadActive = false;
+ auto selection = ui->listView->selectionModel()->selectedRows();
+ if (selection.isEmpty())
+ return;
+
+ QList<ScreenshotPtr> uploaded;
+ auto job = NetJobPtr(new NetJob("Screenshot Upload"));
+ if(selection.size() < 2)
+ {
+ auto item = selection.at(0);
+ auto info = m_model->fileInfo(item);
+ auto screenshot = std::make_shared<ScreenShot>(info);
+ job->addNetAction(ImgurUpload::make(screenshot));
+
+ m_uploadActive = true;
+ ProgressDialog dialog(this);
+ if(dialog.execWithTask(job.get()) != QDialog::Accepted)
+ {
+ CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
+ tr("Unknown error"), QMessageBox::Warning)->exec();
+ }
+ else
+ {
+ auto link = screenshot->m_url;
+ QClipboard *clipboard = QApplication::clipboard();
+ clipboard->setText(link);
+ CustomMessageBox::selectable(
+ this,
+ tr("Upload finished"),
+ tr("The <a href=\"%1\">link to the uploaded screenshot</a> has been placed in your clipboard.")
+ .arg(link),
+ QMessageBox::Information
+ )->exec();
+ }
+
+ m_uploadActive = false;
+ return;
+ }
+
+ for (auto item : selection)
+ {
+ auto info = m_model->fileInfo(item);
+ auto screenshot = std::make_shared<ScreenShot>(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 <a href=\"%1\">link to the uploaded album</a> has been placed in your clipboard.") .arg(link),
+ QMessageBox::Information
+ )->exec();
+ }
+ m_uploadActive = false;
}
-void ScreenshotsPage::on_deleteBtn_clicked()
+void ScreenshotsPage::on_actionDelete_triggered()
{
- 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<QMessageBox> box(mbox);
-
- if (box->exec() != QMessageBox::Yes)
- return;
-
- auto selected = ui->listView->selectionModel()->selectedIndexes();
- for (auto item : selected)
- {
- m_model->remove(item);
- }
+ 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<QMessageBox> 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()
+void ScreenshotsPage::on_actionRename_triggered()
{
- auto selection = ui->listView->selectionModel()->selectedIndexes();
- if (selection.isEmpty())
- return;
- ui->listView->edit(selection[0]);
- // TODO: mass renaming
+ 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);
- }
- }
+ 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
index e31fb8b4..9adf79af 100644
--- a/application/pages/instance/ScreenshotsPage.h
+++ b/application/pages/instance/ScreenshotsPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
#pragma once
-#include <QWidget>
+#include <QMainWindow>
#include "pages/BasePage.h"
#include <MultiMC.h>
@@ -31,54 +31,59 @@ struct ScreenShot;
class ScreenshotList;
class ImgurAlbumCreation;
-class ScreenshotsPage : public QWidget, public BasePage
+class ScreenshotsPage : public QMainWindow, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit ScreenshotsPage(QString path, QWidget *parent = 0);
- virtual ~ScreenshotsPage();
+ explicit ScreenshotsPage(QString path, QWidget *parent = 0);
+ virtual ~ScreenshotsPage();
- virtual void openedImpl() override;
+ virtual void openedImpl() override;
- enum
- {
- NothingDone = 0x42
- };
+ 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;
+ }
+
+protected:
+ QMenu * createPopupMenu() override;
- 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);
+ void on_actionUpload_triggered();
+ void on_actionDelete_triggered();
+ void on_actionRename_triggered();
+ void on_actionView_Folder_triggered();
+ void onItemActivated(QModelIndex);
+ void ShowContextMenu(const QPoint &pos);
private:
- Ui::ScreenshotsPage *ui;
- std::shared_ptr<QFileSystemModel> m_model;
- std::shared_ptr<QIdentityProxyModel> m_filterModel;
- QString m_folder;
- bool m_valid = false;
- bool m_uploadActive = false;
+ Ui::ScreenshotsPage *ui;
+ std::shared_ptr<QFileSystemModel> m_model;
+ std::shared_ptr<QIdentityProxyModel> 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
index d05c4384..42d4db64 100644
--- a/application/pages/instance/ScreenshotsPage.ui
+++ b/application/pages/instance/ScreenshotsPage.ui
@@ -1,106 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScreenshotsPage</class>
- <widget class="QWidget" name="ScreenshotsPage">
+ <widget class="QMainWindow" name="ScreenshotsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>723</width>
- <height>532</height>
+ <width>800</width>
+ <height>600</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
- <number>0</number>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QListView" name="listView">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="WideBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
</property>
- <property name="topMargin">
- <number>0</number>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextOnly</enum>
</property>
- <property name="rightMargin">
- <number>0</number>
+ <attribute name="toolBarArea">
+ <enum>RightToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionUpload"/>
+ <addaction name="actionDelete"/>
+ <addaction name="actionRename"/>
+ <addaction name="actionView_Folder"/>
+ </widget>
+ <action name="actionUpload">
+ <property name="text">
+ <string>Upload</string>
</property>
- <property name="bottomMargin">
- <number>0</number>
+ </action>
+ <action name="actionDelete">
+ <property name="text">
+ <string>Delete</string>
</property>
- <item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
- </property>
- <widget class="QWidget" name="tab">
- <attribute name="title">
- <string notr="true">Tab 1</string>
- </attribute>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QListView" name="listView">
- <property name="selectionMode">
- <enum>QAbstractItemView::ExtendedSelection</enum>
- </property>
- <property name="selectionBehavior">
- <enum>QAbstractItemView::SelectRows</enum>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QPushButton" name="uploadBtn">
- <property name="text">
- <string>&amp;Upload</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="deleteBtn">
- <property name="text">
- <string>&amp;Delete</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="renameBtn">
- <property name="text">
- <string>&amp;Rename</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="viewFolderBtn">
- <property name="text">
- <string>&amp;View Folder</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
+ </action>
+ <action name="actionRename">
+ <property name="text">
+ <string>Rename</string>
+ </property>
+ </action>
+ <action name="actionView_Folder">
+ <property name="text">
+ <string>View Folder</string>
+ </property>
+ </action>
</widget>
- <tabstops>
- <tabstop>listView</tabstop>
- <tabstop>uploadBtn</tabstop>
- <tabstop>deleteBtn</tabstop>
- <tabstop>renameBtn</tabstop>
- <tabstop>viewFolderBtn</tabstop>
- </tabstops>
+ <customwidgets>
+ <customwidget>
+ <class>WideBar</class>
+ <extends>QToolBar</extends>
+ <header>widgets/WideBar.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>
diff --git a/application/pages/instance/ServersPage.cpp b/application/pages/instance/ServersPage.cpp
new file mode 100644
index 00000000..c33eef1f
--- /dev/null
+++ b/application/pages/instance/ServersPage.cpp
@@ -0,0 +1,760 @@
+#include "ServersPage.h"
+#include "ui_ServersPage.h"
+
+#include <FileSystem.h>
+#include <sstream>
+#include <io/stream_reader.h>
+#include <tag_string.h>
+#include <tag_primitive.h>
+#include <tag_list.h>
+#include <tag_compound.h>
+#include <minecraft/MinecraftInstance.h>
+
+#include <QFileSystemWatcher>
+#include <QMenu>
+
+static const int COLUMN_COUNT = 2; // 3 , TBD: latency and other nice things.
+
+struct Server
+{
+ // Types
+ enum class AcceptsTextures : int
+ {
+ ASK = 0,
+ ALWAYS = 1,
+ NEVER = 2
+ };
+
+ // Methods
+ Server()
+ {
+ m_name = QObject::tr("Minecraft Server");
+ }
+ Server(const QString & name, const QString & address)
+ {
+ m_name = name;
+ m_address = address;
+ }
+ Server(nbt::tag_compound& server)
+ {
+ std::string addressStr(server["ip"]);
+ m_address = QString::fromUtf8(addressStr.c_str());
+
+ std::string nameStr(server["name"]);
+ m_name = QString::fromUtf8(nameStr.c_str());
+
+ if(server["icon"])
+ {
+ std::string base64str(server["icon"]);
+ m_icon = QByteArray::fromBase64(base64str.c_str());
+ }
+
+ if(server.has_key("acceptTextures", nbt::tag_type::Byte))
+ {
+ bool value = server["acceptTextures"].as<nbt::tag_byte>().get();
+ if(value)
+ {
+ m_acceptsTextures = AcceptsTextures::ALWAYS;
+ }
+ else
+ {
+ m_acceptsTextures = AcceptsTextures::NEVER;
+ }
+ }
+ }
+
+ void serialize(nbt::tag_compound& server)
+ {
+ server.insert("name", m_name.trimmed().toUtf8().toStdString());
+ server.insert("ip", m_address.trimmed().toUtf8().toStdString());
+ if(m_icon.size())
+ {
+ server.insert("icon", m_icon.toBase64().toStdString());
+ }
+ if(m_acceptsTextures != AcceptsTextures::ASK)
+ {
+ server.insert("acceptTextures", nbt::tag_byte(m_acceptsTextures == AcceptsTextures::ALWAYS));
+ }
+ }
+
+ // Data - persistent and user changeable
+ QString m_name;
+ QString m_address;
+ AcceptsTextures m_acceptsTextures = AcceptsTextures::ASK;
+
+ // Data - persistent and automatically updated
+ QByteArray m_icon;
+
+ // Data - temporary
+ bool m_checked = false;
+ bool m_up = false;
+ QString m_motd; // https://mctools.org/motd-creator
+ int m_ping = 0;
+ int m_currentPlayers = 0;
+ int m_maxPlayers = 0;
+};
+
+static std::unique_ptr <nbt::tag_compound> parseServersDat(const QString& filename)
+{
+ try
+ {
+ QByteArray input = FS::read(filename);
+ std::istringstream foo(std::string(input.constData(), input.size()));
+ auto pair = nbt::io::read_compound(foo);
+
+ if(pair.first != "")
+ return nullptr;
+
+ if(pair.second == nullptr)
+ return nullptr;
+
+ return std::move(pair.second);
+ }
+ catch (...)
+ {
+ return nullptr;
+ }
+}
+
+static bool serializeServerDat(const QString& filename, nbt::tag_compound * levelInfo)
+{
+ try
+ {
+ if(!FS::ensureFilePathExists(filename))
+ {
+ return false;
+ }
+ std::ostringstream s;
+ nbt::io::write_tag("", *levelInfo, s);
+ QByteArray val(s.str().data(), (int) s.str().size() );
+ FS::write(filename, val);
+ return true;
+ }
+ catch (...)
+ {
+ return false;
+ }
+}
+
+class ServersModel: public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum Roles
+ {
+ ServerPtrRole = Qt::UserRole,
+ };
+ explicit ServersModel(const QString &path, QObject *parent = 0)
+ : QAbstractListModel(parent)
+ {
+ m_path = path;
+ m_watcher = new QFileSystemWatcher(this);
+ connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &ServersModel::fileChanged);
+ connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &ServersModel::dirChanged);
+ m_saveTimer.setSingleShot(true);
+ m_saveTimer.setInterval(5000);
+ connect(&m_saveTimer, &QTimer::timeout, this, &ServersModel::save_internal);
+ }
+ virtual ~ServersModel() {};
+
+ void observe()
+ {
+ if(m_observed)
+ {
+ return;
+ }
+ m_observed = true;
+
+ if(!m_loaded)
+ {
+ load();
+ }
+
+ updateFSObserver();
+ }
+
+ void unobserve()
+ {
+ if(!m_observed)
+ {
+ return;
+ }
+ m_observed = false;
+
+ updateFSObserver();
+ }
+
+ void lock()
+ {
+ if(m_locked)
+ {
+ return;
+ }
+ saveNow();
+
+ m_locked = true;
+ updateFSObserver();
+ }
+
+ void unlock()
+ {
+ if(!m_locked)
+ {
+ return;
+ }
+ m_locked = false;
+
+ updateFSObserver();
+ }
+
+ int addEmptyRow(int position)
+ {
+ if(m_locked)
+ {
+ return -1;
+ }
+ if(position < 0 || position >= rowCount())
+ {
+ position = rowCount();
+ }
+ beginInsertRows(QModelIndex(), position, position);
+ m_servers.insert(position, Server());
+ endInsertRows();
+ scheduleSave();
+ return position;
+ }
+
+ bool removeRow(int row)
+ {
+ if(m_locked)
+ {
+ return false;
+ }
+ if(row < 0 || row >= rowCount())
+ {
+ return false;
+ }
+ beginRemoveRows(QModelIndex(), row, row);
+ m_servers.removeAt(row);
+ endRemoveRows(); // does absolutely nothing, the selected server stays as the next line...
+ scheduleSave();
+ return true;
+ }
+
+ bool moveUp(int row)
+ {
+ if(m_locked)
+ {
+ return false;
+ }
+ if(row <= 0)
+ {
+ return false;
+ }
+ beginMoveRows(QModelIndex(), row, row, QModelIndex(), row - 1);
+ m_servers.swap(row-1, row);
+ endMoveRows();
+ scheduleSave();
+ return true;
+ }
+
+ bool moveDown(int row)
+ {
+ if(m_locked)
+ {
+ return false;
+ }
+ int count = rowCount();
+ if(row + 1 >= count)
+ {
+ return false;
+ }
+ beginMoveRows(QModelIndex(), row, row, QModelIndex(), row + 2);
+ m_servers.swap(row+1, row);
+ endMoveRows();
+ scheduleSave();
+ return true;
+ }
+
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const override
+ {
+ if (section < 0 || section >= COLUMN_COUNT)
+ return QVariant();
+
+ if(role == Qt::DisplayRole)
+ {
+ switch(section)
+ {
+ case 0:
+ return tr("Name");
+ case 1:
+ return tr("Address");
+ case 2:
+ return tr("Latency");
+ }
+ }
+
+ return QAbstractListModel::headerData(section, orientation, role);
+ }
+
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
+ {
+ if (!index.isValid())
+ return QVariant();
+
+ int row = index.row();
+ int column = index.column();
+ if(column < 0 || column >= COLUMN_COUNT)
+ return QVariant();
+
+ if (row < 0 || row >= m_servers.size())
+ return QVariant();
+
+ switch(column)
+ {
+ case 0:
+ switch (role)
+ {
+ case Qt::DecorationRole:
+ {
+ auto & bytes = m_servers[row].m_icon;
+ if(bytes.size())
+ {
+ QPixmap px;
+ if(px.loadFromData(bytes))
+ return QIcon(px);
+ }
+ return MMC->getThemedIcon("unknown_server");
+ }
+ case Qt::DisplayRole:
+ return m_servers[row].m_name;
+ case ServerPtrRole:
+ return QVariant::fromValue<void *>((void *)&m_servers[row]);
+ default:
+ return QVariant();
+ }
+ case 1:
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ return m_servers[row].m_address;
+ default:
+ return QVariant();
+ }
+ case 2:
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ return m_servers[row].m_ping;
+ default:
+ return QVariant();
+ }
+ default:
+ return QVariant();
+ }
+ }
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override
+ {
+ return m_servers.size();
+ }
+ int columnCount(const QModelIndex & parent) const override
+ {
+ return COLUMN_COUNT;
+ }
+
+ Server * at(int index)
+ {
+ if(index < 0 || index >= rowCount())
+ {
+ return nullptr;
+ }
+ return &m_servers[index];
+ }
+
+ void setName(int row, const QString & name)
+ {
+ if(m_locked)
+ {
+ return;
+ }
+ auto server = at(row);
+ if(!server || server->m_name == name)
+ {
+ return;
+ }
+ server->m_name = name;
+ emit dataChanged(index(row, 0), index(row, COLUMN_COUNT - 1));
+ scheduleSave();
+ }
+
+ void setAddress(int row, const QString & address)
+ {
+ if(m_locked)
+ {
+ return;
+ }
+ auto server = at(row);
+ if(!server || server->m_address == address)
+ {
+ return;
+ }
+ server->m_address = address;
+ emit dataChanged(index(row, 0), index(row, COLUMN_COUNT - 1));
+ scheduleSave();
+ }
+
+ void setAcceptsTextures(int row, Server::AcceptsTextures textures)
+ {
+ if(m_locked)
+ {
+ return;
+ }
+ auto server = at(row);
+ if(!server || server->m_acceptsTextures == textures)
+ {
+ return;
+ }
+ server->m_acceptsTextures = textures;
+ emit dataChanged(index(row, 0), index(row, COLUMN_COUNT - 1));
+ scheduleSave();
+ }
+
+ void load()
+ {
+ cancelSave();
+ beginResetModel();
+ QList<Server> servers;
+ auto serversDat = parseServersDat(serversPath());
+ if(serversDat)
+ {
+ auto &serversList = serversDat->at("servers").as<nbt::tag_list>();
+ for(auto iter = serversList.begin(); iter != serversList.end(); iter++)
+ {
+ auto & serverTag = (*iter).as<nbt::tag_compound>();
+ Server s(serverTag);
+ servers.append(s);
+ }
+ }
+ m_servers.swap(servers);
+ m_loaded = true;
+ endResetModel();
+ }
+
+ void saveNow()
+ {
+ if(saveIsScheduled())
+ {
+ save_internal();
+ }
+ }
+
+
+public slots:
+ void dirChanged(const QString& path)
+ {
+ qDebug() << "Changed:" << path;
+ load();
+ }
+ void fileChanged(const QString& path)
+ {
+ qDebug() << "Changed:" << path;
+ }
+
+private slots:
+ void save_internal()
+ {
+ cancelSave();
+ QString path = serversPath();
+ qDebug() << "Server list about to be saved to" << path;
+
+ nbt::tag_compound out;
+ nbt::tag_list list;
+ for(auto & server: m_servers)
+ {
+ nbt::tag_compound serverNbt;
+ server.serialize(serverNbt);
+ list.push_back(std::move(serverNbt));
+ }
+ out.insert("servers", nbt::value(std::move(list)));
+
+ if(!serializeServerDat(path, &out))
+ {
+ qDebug() << "Failed to save server list:" << path << "Will try again.";
+ scheduleSave();
+ }
+ }
+
+private:
+ void scheduleSave()
+ {
+ if(!m_loaded)
+ {
+ qDebug() << "Server list should never save if it didn't successfully load, path:" << m_path;
+ return;
+ }
+ if(!m_dirty)
+ {
+ m_dirty = true;
+ qDebug() << "Server list save is scheduled for" << m_path;
+ }
+ m_saveTimer.start();
+ }
+
+ void cancelSave()
+ {
+ m_dirty = false;
+ m_saveTimer.stop();
+ }
+
+ bool saveIsScheduled() const
+ {
+ return m_dirty;
+ }
+
+ void updateFSObserver()
+ {
+ bool observingFS = m_watcher->directories().contains(m_path);
+ if(m_observed && m_locked)
+ {
+ if(!observingFS)
+ {
+ qWarning() << "Will watch" << m_path;
+ if(!m_watcher->addPath(m_path))
+ {
+ qWarning() << "Failed to start watching" << m_path;
+ }
+ }
+ }
+ else
+ {
+ if(observingFS)
+ {
+ qWarning() << "Will stop watching" << m_path;
+ if(!m_watcher->removePath(m_path))
+ {
+ qWarning() << "Failed to stop watching" << m_path;
+ }
+ }
+ }
+ }
+
+ QString serversPath()
+ {
+ QFileInfo foo(FS::PathCombine(m_path, "servers.dat"));
+ return foo.filePath();
+ }
+
+private:
+ bool m_loaded = false;
+ bool m_locked = false;
+ bool m_observed = false;
+ bool m_dirty = false;
+ QString m_path;
+ QList<Server> m_servers;
+ QFileSystemWatcher *m_watcher = nullptr;
+ QTimer m_saveTimer;
+};
+
+ServersPage::ServersPage(MinecraftInstance * inst, QWidget* parent)
+ : QMainWindow(parent), ui(new Ui::ServersPage)
+{
+ ui->setupUi(this);
+ m_inst = inst;
+ m_model = new ServersModel(inst->gameRoot(), this);
+ ui->serversView->setIconSize(QSize(64,64));
+ ui->serversView->setModel(m_model);
+ ui->serversView->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(ui->serversView, &QTreeView::customContextMenuRequested, this, &ServersPage::ShowContextMenu);
+
+ auto head = ui->serversView->header();
+ if(head->count())
+ {
+ head->setSectionResizeMode(0, QHeaderView::Stretch);
+ for(int i = 1; i < head->count(); i++)
+ {
+ head->setSectionResizeMode(i, QHeaderView::ResizeToContents);
+ }
+ }
+
+ auto selectionModel = ui->serversView->selectionModel();
+ connect(selectionModel, &QItemSelectionModel::currentChanged, this, &ServersPage::currentChanged);
+ connect(m_inst, &MinecraftInstance::runningStatusChanged, this, &ServersPage::on_RunningState_changed);
+ connect(ui->nameLine, &QLineEdit::textEdited, this, &ServersPage::nameEdited);
+ connect(ui->addressLine, &QLineEdit::textEdited, this, &ServersPage::addressEdited);
+ connect(ui->resourceComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(resourceIndexChanged(int)));
+ connect(m_model, &QAbstractItemModel::rowsRemoved, this, &ServersPage::rowsRemoved);
+
+ m_locked = m_inst->isRunning();
+ if(m_locked)
+ {
+ m_model->lock();
+ }
+
+ updateState();
+}
+
+ServersPage::~ServersPage()
+{
+ m_model->saveNow();
+}
+
+void ServersPage::ShowContextMenu(const QPoint& pos)
+{
+ auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
+ menu->exec(ui->serversView->mapToGlobal(pos));
+ delete menu;
+}
+
+QMenu * ServersPage::createPopupMenu()
+{
+ QMenu* filteredMenu = QMainWindow::createPopupMenu();
+ filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
+ return filteredMenu;
+}
+
+void ServersPage::on_RunningState_changed(bool running)
+{
+ if(m_locked == running)
+ {
+ return;
+ }
+ m_locked = running;
+ if(m_locked)
+ {
+ m_model->lock();
+ }
+ else
+ {
+ m_model->unlock();
+ }
+ updateState();
+}
+
+void ServersPage::currentChanged(const QModelIndex &current, const QModelIndex &previous)
+{
+ int nextServer = -1;
+ if (!current.isValid())
+ {
+ nextServer = -1;
+ }
+ else
+ {
+ nextServer = current.row();
+ }
+ currentServer = nextServer;
+ updateState();
+}
+
+// WARNING: this is here because currentChanged is not accurate when removing rows. the current item needs to be fixed up after removal.
+void ServersPage::rowsRemoved(const QModelIndex& parent, int first, int last)
+{
+ if(currentServer < first)
+ {
+ // current was before the removal
+ return;
+ }
+ else if(currentServer >= first && currentServer <= last)
+ {
+ // current got removed...
+ return;
+ }
+ else
+ {
+ // current was past the removal
+ int count = last - first + 1;
+ currentServer -= count;
+ }
+}
+
+void ServersPage::nameEdited(const QString& name)
+{
+ m_model->setName(currentServer, name);
+}
+
+void ServersPage::addressEdited(const QString& address)
+{
+ m_model->setAddress(currentServer, address);
+}
+
+void ServersPage::resourceIndexChanged(int index)
+{
+ auto acceptsTextures = Server::AcceptsTextures(index);
+ m_model->setAcceptsTextures(currentServer, acceptsTextures);
+}
+
+void ServersPage::updateState()
+{
+ auto server = m_model->at(currentServer);
+
+ bool serverEditEnabled = server && !m_locked;
+ ui->addressLine->setEnabled(serverEditEnabled);
+ ui->nameLine->setEnabled(serverEditEnabled);
+ ui->resourceComboBox->setEnabled(serverEditEnabled);
+ ui->actionMove_Down->setEnabled(serverEditEnabled);
+ ui->actionMove_Up->setEnabled(serverEditEnabled);
+ ui->actionRemove->setEnabled(serverEditEnabled);
+
+ if(server)
+ {
+ ui->addressLine->setText(server->m_address);
+ ui->nameLine->setText(server->m_name);
+ ui->resourceComboBox->setCurrentIndex(int(server->m_acceptsTextures));
+ }
+ else
+ {
+ ui->addressLine->setText(QString());
+ ui->nameLine->setText(QString());
+ ui->resourceComboBox->setCurrentIndex(0);
+ }
+
+ ui->actionAdd->setDisabled(m_locked);
+}
+
+void ServersPage::openedImpl()
+{
+ m_model->observe();
+}
+
+void ServersPage::closedImpl()
+{
+ m_model->unobserve();
+}
+
+void ServersPage::on_actionAdd_triggered()
+{
+ int position = m_model->addEmptyRow(currentServer + 1);
+ if(position < 0)
+ {
+ return;
+ }
+ // select the new row
+ ui->serversView->selectionModel()->setCurrentIndex(
+ m_model->index(position),
+ QItemSelectionModel::SelectCurrent | QItemSelectionModel::Clear | QItemSelectionModel::Rows
+ );
+ currentServer = position;
+}
+
+void ServersPage::on_actionRemove_triggered()
+{
+ m_model->removeRow(currentServer);
+}
+
+void ServersPage::on_actionMove_Up_triggered()
+{
+ if(m_model->moveUp(currentServer))
+ {
+ currentServer --;
+ }
+}
+
+void ServersPage::on_actionMove_Down_triggered()
+{
+ if(m_model->moveDown(currentServer))
+ {
+ currentServer ++;
+ }
+}
+
+#include "ServersPage.moc"
diff --git a/application/pages/instance/ServersPage.h b/application/pages/instance/ServersPage.h
new file mode 100644
index 00000000..c81f47be
--- /dev/null
+++ b/application/pages/instance/ServersPage.h
@@ -0,0 +1,93 @@
+/* Copyright 2013-2019 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 <QMainWindow>
+#include <QString>
+
+#include "pages/BasePage.h"
+#include <MultiMC.h>
+
+namespace Ui
+{
+class ServersPage;
+}
+
+struct Server;
+class ServersModel;
+class MinecraftInstance;
+
+class ServersPage : public QMainWindow, public BasePage
+{
+ Q_OBJECT
+
+public:
+ explicit ServersPage(MinecraftInstance *inst, QWidget *parent = 0);
+ virtual ~ServersPage();
+
+ void openedImpl() override;
+ void closedImpl() override;
+
+ virtual QString displayName() const override
+ {
+ return tr("Servers");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("unknown_server");
+ }
+ virtual QString id() const override
+ {
+ return "servers";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Servers-management";
+ }
+
+protected:
+ QMenu * createPopupMenu() override;
+
+private:
+ void updateState();
+ void scheduleSave();
+ bool saveIsScheduled() const;
+
+private slots:
+ void currentChanged(const QModelIndex &current, const QModelIndex &previous);
+ void rowsRemoved(const QModelIndex &parent, int first, int last);
+
+ void on_actionAdd_triggered();
+ void on_actionRemove_triggered();
+ void on_actionMove_Up_triggered();
+ void on_actionMove_Down_triggered();
+
+ void on_RunningState_changed(bool running);
+
+ void nameEdited(const QString & name);
+ void addressEdited(const QString & address);
+ void resourceIndexChanged(int index);\
+
+ void ShowContextMenu(const QPoint &pos);
+
+private: // data
+ int currentServer = -1;
+ bool m_locked = true;
+ Ui::ServersPage *ui = nullptr;
+ ServersModel * m_model = nullptr;
+ MinecraftInstance * m_inst = nullptr;
+};
+
diff --git a/application/pages/instance/ServersPage.ui b/application/pages/instance/ServersPage.ui
new file mode 100644
index 00000000..9c31abe3
--- /dev/null
+++ b/application/pages/instance/ServersPage.ui
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ServersPage</class>
+ <widget class="QMainWindow" name="ServersPage">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1318</width>
+ <height>879</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTreeView" name="serversView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>64</width>
+ <height>64</height>
+ </size>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <property name="leftMargin">
+ <number>6</number>
+ </property>
+ <property name="rightMargin">
+ <number>6</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="nameLabel">
+ <property name="text">
+ <string>&amp;Name</string>
+ </property>
+ <property name="buddy">
+ <cstring>nameLine</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="nameLine"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="addressLabel">
+ <property name="text">
+ <string>Address</string>
+ </property>
+ <property name="buddy">
+ <cstring>addressLine</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="addressLine"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="resourcesLabel">
+ <property name="text">
+ <string>Reso&amp;urces</string>
+ </property>
+ <property name="buddy">
+ <cstring>resourceComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="resourceComboBox">
+ <item>
+ <property name="text">
+ <string>Ask to download</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Always download</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Never download</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="WideBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
+ </property>
+ <property name="allowedAreas">
+ <set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextOnly</enum>
+ </property>
+ <property name="floatable">
+ <bool>false</bool>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>RightToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionAdd"/>
+ <addaction name="actionRemove"/>
+ <addaction name="actionMove_Up"/>
+ <addaction name="actionMove_Down"/>
+ </widget>
+ <action name="actionAdd">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </action>
+ <action name="actionRemove">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </action>
+ <action name="actionMove_Up">
+ <property name="text">
+ <string>Move Up</string>
+ </property>
+ </action>
+ <action name="actionMove_Down">
+ <property name="text">
+ <string>Move Down</string>
+ </property>
+ </action>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>WideBar</class>
+ <extends>QToolBar</extends>
+ <header>widgets/WideBar.h</header>
+ </customwidget>
+ </customwidgets>
+ <tabstops>
+ <tabstop>serversView</tabstop>
+ <tabstop>nameLine</tabstop>
+ <tabstop>addressLine</tabstop>
+ <tabstop>resourceComboBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/application/pages/instance/TexturePackPage.h b/application/pages/instance/TexturePackPage.h
index b03614f0..a792ba07 100644
--- a/application/pages/instance/TexturePackPage.h
+++ b/application/pages/instance/TexturePackPage.h
@@ -4,16 +4,17 @@
class TexturePackPage : public ModFolderPage
{
+ Q_OBJECT
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");
- }
+ explicit TexturePackPage(MinecraftInstance *instance, QWidget *parent = 0)
+ : ModFolderPage(instance, instance->texturePackList(), "texturepacks", "resourcepacks",
+ tr("Texture packs"), "Texture-packs", parent)
+ {
+ ui->actionView_configs->setVisible(false);
+ }
+ 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
index 00ae0a7e..2acc13c2 100644
--- a/application/pages/instance/VersionPage.cpp
+++ b/application/pages/instance/VersionPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,10 @@
#include "MultiMC.h"
#include <QMessageBox>
+#include <QLabel>
#include <QEvent>
#include <QKeyEvent>
+#include <QMenu>
#include "VersionPage.h"
#include "ui_VersionPage.h"
@@ -25,7 +27,6 @@
#include "dialogs/CustomMessageBox.h"
#include "dialogs/VersionSelectDialog.h"
#include "dialogs/NewComponentDialog.h"
-#include "dialogs/ModEditDialogCommon.h"
#include "dialogs/ProgressDialog.h"
#include <GuiUtil.h>
@@ -38,532 +39,574 @@
#include "minecraft/ComponentList.h"
#include "minecraft/auth/MojangAccountList.h"
-#include "minecraft/Mod.h"
+#include "minecraft/mod/Mod.h"
#include "icons/IconList.h"
#include "Exception.h"
-
-#include "MultiMC.h"
+#include "Version.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
class IconProxy : public QIdentityProxyModel
{
- Q_OBJECT
+ 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;
- }
+ 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;
- }
+ void widgetGone()
+ {
+ m_parentWidget = nullptr;
+ }
private:
- QWidget *m_parentWidget = nullptr;
+ QWidget *m_parentWidget = nullptr;
};
QIcon VersionPage::icon() const
{
- return MMC->icons()->getIcon(m_inst->iconKey());
+ return MMC->icons()->getIcon(m_inst->iconKey());
}
bool VersionPage::shouldDisplay() const
{
- return !m_inst->isRunning();
+ return true;
+}
+
+QMenu * VersionPage::createPopupMenu()
+{
+ QMenu* filteredMenu = QMainWindow::createPopupMenu();
+ filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
+ return filteredMenu;
}
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);
+ : QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst)
+{
+ ui->setupUi(this);
+
+ ui->toolBar->insertSpacer(ui->actionReload);
+
+ m_profile = m_inst->getComponentList();
+
+ reloadComponentList();
+
+ auto proxy = new IconProxy(ui->packageView);
+ proxy->setSourceModel(m_profile.get());
+ ui->packageView->setModel(proxy);
+ ui->packageView->installEventFilter(this);
+ ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
+ ui->packageView->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
+ auto smodel = ui->packageView->selectionModel();
+ connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
+
+ connect(m_profile.get(), &ComponentList::minecraftChanged, this, &VersionPage::updateVersionControls);
+ controlsEnabled = !m_inst->isRunning();
+ updateVersionControls();
+ preselect(0);
+ connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus);
+ connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::ShowContextMenu);
}
VersionPage::~VersionPage()
{
- delete ui;
+ delete ui;
+}
+
+void VersionPage::ShowContextMenu(const QPoint& pos)
+{
+ auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
+ menu->exec(ui->packageView->mapToGlobal(pos));
+ delete menu;
}
void VersionPage::packageCurrent(const QModelIndex &current, 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);
+ 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::updateRunningStatus(bool running)
+{
+ if(controlsEnabled == running) {
+ controlsEnabled = !running;
+ updateVersionControls();
+ }
+}
void VersionPage::updateVersionControls()
{
- ui->forgeBtn->setEnabled(true);
- ui->liteloaderBtn->setEnabled(true);
- updateButtons();
+ // FIXME: this is a dirty hack
+ auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
+ bool newCraft = controlsEnabled && (minecraftVersion >= Version("1.14"));
+ bool oldCraft = controlsEnabled && (minecraftVersion <= Version("1.12.2"));
+ ui->actionInstall_Fabric->setEnabled(newCraft);
+ ui->actionInstall_Forge->setEnabled(oldCraft);
+ ui->actionInstall_LiteLoader->setEnabled(oldCraft);
+ ui->actionReload->setEnabled(true);
+ updateButtons();
}
-void VersionPage::disableVersionControls()
+void VersionPage::updateButtons(int row)
{
- ui->forgeBtn->setEnabled(false);
- ui->liteloaderBtn->setEnabled(false);
- ui->reloadBtn->setEnabled(false);
- updateButtons();
+ if(row == -1)
+ row = currentRow();
+ auto patch = m_profile->getComponent(row);
+ ui->actionRemove->setEnabled(controlsEnabled && patch && patch->isRemovable());
+ ui->actionMove_down->setEnabled(controlsEnabled && patch && patch->isMoveable());
+ ui->actionMove_up->setEnabled(controlsEnabled && patch && patch->isMoveable());
+ ui->actionChange_version->setEnabled(controlsEnabled && patch && patch->isVersionChangeable());
+ ui->actionEdit->setEnabled(controlsEnabled && patch && patch->isCustom());
+ ui->actionCustomize->setEnabled(controlsEnabled && patch && patch->isCustomizable());
+ ui->actionRevert->setEnabled(controlsEnabled && patch && patch->isRevertible());
+ ui->actionDownload_All->setEnabled(controlsEnabled);
+ ui->actionAdd_Empty->setEnabled(controlsEnabled);
+ ui->actionReload->setEnabled(controlsEnabled);
+ ui->actionInstall_mods->setEnabled(controlsEnabled);
+ ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled);
+ ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled);
}
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();
- }
+ try
+ {
+ m_profile->reload(Net::Mode::Online);
+ return true;
+ }
+ catch (const 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::versionCurrent(const QModelIndex &current, const QModelIndex &previous)
+void VersionPage::on_actionReload_triggered()
{
- currentIdx = current.row();
- updateButtons(currentIdx);
+ reloadComponentList();
+ m_container->refreshContainer();
}
-void VersionPage::preselect(int row)
+void VersionPage::on_actionRemove_triggered()
{
- 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);
+ 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::updateButtons(int row)
+void VersionPage::on_actionInstall_mods_triggered()
+{
+ if(m_container)
+ {
+ m_container->selectPage("mods");
+ }
+}
+
+void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()
+{
+ 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_actionReplace_Minecraft_jar_triggered()
+{
+ 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_actionMove_up_triggered()
+{
+ try
+ {
+ m_profile->move(currentRow(), ComponentList::MoveUp);
+ }
+ catch (const Exception &e)
+ {
+ QMessageBox::critical(this, tr("Error"), e.cause());
+ }
+ updateButtons();
+}
+
+void VersionPage::on_actionMove_down_triggered()
+{
+ try
+ {
+ m_profile->move(currentRow(), ComponentList::MoveDown);
+ }
+ catch (const Exception &e)
+ {
+ QMessageBox::critical(this, tr("Error"), e.cause());
+ }
+ updateButtons();
+}
+
+void VersionPage::on_actionChange_version_triggered()
+{
+ 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_actionInstall_Forge_triggered();
+ return;
+ }
+ else if (uid == "com.mumfrey.liteloader")
+ {
+ on_actionInstall_LiteLoader_triggered();
+ return;
+ }
+ VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
+ if (uid == "net.fabricmc.intermediary")
+ {
+ vselect.setEmptyString(tr("No Fabric Loader versions are currently available."));
+ vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!"));
+ vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
+ }
+ 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_actionDownload_triggered()
+{
+ 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_actionInstall_Forge_triggered()
+{
+ 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_actionInstall_Fabric_triggered()
+{
+ auto vlist = ENV.metadataIndex()->get("net.fabricmc.fabric-loader");
+ if(!vlist)
+ {
+ return;
+ }
+ VersionSelectDialog vselect(vlist.get(), tr("Select Fabric Loader version"), this);
+ vselect.setEmptyString(tr("No Fabric Loader versions are currently available."));
+ vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!"));
+
+ auto currentVersion = m_profile->getComponentVersion("net.fabricmc.fabric-loader");
+ if(!currentVersion.isEmpty())
+ {
+ vselect.setCurrentVersion(currentVersion);
+ }
+
+ if (vselect.exec() && vselect.selectedVersion())
+ {
+ auto vsn = vselect.selectedVersion();
+ m_profile->setComponentVersion("net.fabricmc.fabric-loader", vsn->descriptor());
+ m_profile->resolve(Net::Mode::Online);
+ preselect(m_profile->rowCount(QModelIndex())-1);
+ m_container->refreshContainer();
+ }
+}
+
+void VersionPage::on_actionAdd_Empty_triggered()
+{
+ 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_actionInstall_LiteLoader_triggered()
{
- 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());
- }
+ 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 &current, 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::onGameUpdateError(QString error)
{
- CustomMessageBox::selectable(this, tr("Error updating instance"), error,
- QMessageBox::Warning)->show();
+ 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);
+ 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();
+ if (ui->packageView->selectionModel()->selectedRows().isEmpty())
+ {
+ return -1;
+ }
+ return ui->packageView->selectionModel()->selectedRows().first().row();
+}
+
+void VersionPage::on_actionCustomize_triggered()
+{
+ 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_actionEdit_triggered()
+{
+ 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_actionRevert_triggered()
+{
+ 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
index 85304ea5..31344eb9 100644
--- a/application/pages/instance/VersionPage.h
+++ b/application/pages/instance/VersionPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
#pragma once
-#include <QWidget>
+#include <QMainWindow>
#include "minecraft/MinecraftInstance.h"
#include "minecraft/ComponentList.h"
@@ -26,70 +26,74 @@ namespace Ui
class VersionPage;
}
-class VersionPage : public QWidget, public BasePage
+class VersionPage : public QMainWindow, public BasePage
{
- Q_OBJECT
+ 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;
+ 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 on_actionChange_version_triggered();
+ void on_actionInstall_Forge_triggered();
+ void on_actionInstall_Fabric_triggered();
+ void on_actionAdd_Empty_triggered();
+ void on_actionInstall_LiteLoader_triggered();
+ void on_actionReload_triggered();
+ void on_actionRemove_triggered();
+ void on_actionMove_up_triggered();
+ void on_actionMove_down_triggered();
+ void on_actionAdd_to_Minecraft_jar_triggered();
+ void on_actionReplace_Minecraft_jar_triggered();
+ void on_actionRevert_triggered();
+ void on_actionEdit_triggered();
+ void on_actionInstall_mods_triggered();
+ void on_actionCustomize_triggered();
+ void on_actionDownload_triggered();
- void updateVersionControls();
- void disableVersionControls();
- void on_changeVersionBtn_clicked();
+ void updateVersionControls();
private:
- Component * current();
- int currentRow();
- void updateButtons(int row = -1);
- void preselect(int row = 0);
- int doUpdate();
+ 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();
+ QMenu * createPopupMenu() override;
+
+ /// FIXME: this shouldn't be necessary!
+ bool reloadComponentList();
private:
- Ui::VersionPage *ui;
- std::shared_ptr<ComponentList> m_profile;
- MinecraftInstance *m_inst;
- int currentIdx = 0;
+ Ui::VersionPage *ui;
+ std::shared_ptr<ComponentList> m_profile;
+ MinecraftInstance *m_inst;
+ int currentIdx = 0;
+ bool controlsEnabled = false;
public slots:
- void versionCurrent(const QModelIndex &current, const QModelIndex &previous);
+ void versionCurrent(const QModelIndex &current, const QModelIndex &previous);
private slots:
- void onGameUpdateError(QString error);
- void packageCurrent(const QModelIndex &current, const QModelIndex &previous);
-
+ void updateRunningStatus(bool running);
+ void onGameUpdateError(QString error);
+ void packageCurrent(const QModelIndex &current, const QModelIndex &previous);
+ void ShowContextMenu(const QPoint &pos);
};
diff --git a/application/pages/instance/VersionPage.ui b/application/pages/instance/VersionPage.ui
index d54dd840..e16f18bc 100644
--- a/application/pages/instance/VersionPage.ui
+++ b/application/pages/instance/VersionPage.ui
@@ -1,279 +1,231 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VersionPage</class>
- <widget class="QWidget" name="VersionPage">
+ <widget class="QMainWindow" name="VersionPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>870</width>
- <height>1008</height>
+ <width>961</width>
+ <height>1091</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
- </property>
- <widget class="QWidget" name="tab">
- <attribute name="title">
- <string notr="true">Tab 1</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="ModListView" name="packageView">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOn</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="headerHidden">
- <bool>false</bool>
- </property>
- <attribute name="headerVisible">
- <bool>true</bool>
- </attribute>
- </widget>
- </item>
- <item row="0" column="1">
- <layout class="QVBoxLayout" name="verticalLayout_4">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Selection</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="changeVersionBtn">
- <property name="toolTip">
- <string>Change version of the selected package.</string>
- </property>
- <property name="text">
- <string>Change version</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="moveUpBtn">
- <property name="toolTip">
- <string>Make the selected package apply sooner.</string>
- </property>
- <property name="text">
- <string>Move up</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="moveDownBtn">
- <property name="toolTip">
- <string>Make the selected package apply later.</string>
- </property>
- <property name="text">
- <string>Move down</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="removeBtn">
- <property name="toolTip">
- <string>Remove selected package from the instance.</string>
- </property>
- <property name="text">
- <string>Remove</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="LineSeparator" name="separator_4" native="true"/>
- </item>
- <item>
- <widget class="QLabel" name="label_10">
- <property name="text">
- <string>Edit</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="customizeBtn">
- <property name="toolTip">
- <string>Customize selected package.</string>
- </property>
- <property name="text">
- <string>Customize</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="editBtn">
- <property name="toolTip">
- <string>Edit selected package.</string>
- </property>
- <property name="text">
- <string>Edit</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="revertBtn">
- <property name="toolTip">
- <string>Revert the selected package to default.</string>
- </property>
- <property name="text">
- <string>Revert</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="LineSeparator" name="separator" native="true"/>
- </item>
- <item>
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Install</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="forgeBtn">
- <property name="toolTip">
- <string>Install the Minecraft Forge package.</string>
- </property>
- <property name="text">
- <string>Install Forge</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="liteloaderBtn">
- <property name="toolTip">
- <string>Install the LiteLoader package.</string>
- </property>
- <property name="text">
- <string>Install LiteLoader</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="modBtn">
- <property name="toolTip">
- <string>Install normal mods.</string>
- </property>
- <property name="text">
- <string>Install mods</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="LineSeparator" name="widget" native="true"/>
- </item>
- <item>
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Advanced</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="jarmodBtn">
- <property name="toolTip">
- <string>Add a mod into the Minecraft jar file.</string>
- </property>
- <property name="text">
- <string>Add to Minecraft.jar</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="jarBtn">
- <property name="text">
- <string>Replace Minecraft.jar</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="addEmptyBtn">
- <property name="text">
- <string>Add Empty</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="reloadBtn">
- <property name="toolTip">
- <string>Reload all packages.</string>
- </property>
- <property name="text">
- <string>Reload</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="downloadBtn">
- <property name="toolTip">
- <string>Download the files needed to launch the instance now.</string>
- </property>
- <property name="text">
- <string>Download All</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer_7">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>111</width>
- <height>13</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item row="1" column="0" colspan="2">
- <widget class="MCModInfoFrame" name="frame">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="ModListView" name="packageView">
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="sortingEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="headerHidden">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerVisible">
+ <bool>true</bool>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="MCModInfoFrame" name="frame">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="WideBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
+ </property>
+ <property name="allowedAreas">
+ <set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextOnly</enum>
+ </property>
+ <property name="floatable">
+ <bool>false</bool>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>RightToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionChange_version"/>
+ <addaction name="actionMove_up"/>
+ <addaction name="actionMove_down"/>
+ <addaction name="actionRemove"/>
+ <addaction name="separator"/>
+ <addaction name="actionCustomize"/>
+ <addaction name="actionEdit"/>
+ <addaction name="actionRevert"/>
+ <addaction name="separator"/>
+ <addaction name="actionInstall_Forge"/>
+ <addaction name="actionInstall_Fabric"/>
+ <addaction name="actionInstall_LiteLoader"/>
+ <addaction name="actionInstall_mods"/>
+ <addaction name="separator"/>
+ <addaction name="actionAdd_to_Minecraft_jar"/>
+ <addaction name="actionReplace_Minecraft_jar"/>
+ <addaction name="actionAdd_Empty"/>
+ <addaction name="actionReload"/>
+ <addaction name="actionDownload_All"/>
+ </widget>
+ <action name="actionChange_version">
+ <property name="text">
+ <string>Change version</string>
+ </property>
+ <property name="toolTip">
+ <string>Change version of the selected package.</string>
+ </property>
+ </action>
+ <action name="actionMove_up">
+ <property name="text">
+ <string>Move up</string>
+ </property>
+ <property name="toolTip">
+ <string>Make the selected package apply sooner.</string>
+ </property>
+ </action>
+ <action name="actionMove_down">
+ <property name="text">
+ <string>Move down</string>
+ </property>
+ <property name="toolTip">
+ <string>Make the selected package apply later.</string>
+ </property>
+ </action>
+ <action name="actionRemove">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ <property name="toolTip">
+ <string>Remove selected package from the instance.</string>
+ </property>
+ </action>
+ <action name="actionCustomize">
+ <property name="text">
+ <string>Customize</string>
+ </property>
+ <property name="toolTip">
+ <string>Customize selected package.</string>
+ </property>
+ </action>
+ <action name="actionEdit">
+ <property name="text">
+ <string>Edit</string>
+ </property>
+ <property name="toolTip">
+ <string>Edit selected package.</string>
+ </property>
+ </action>
+ <action name="actionRevert">
+ <property name="text">
+ <string>Revert</string>
+ </property>
+ <property name="toolTip">
+ <string>Revert the selected package to default.</string>
+ </property>
+ </action>
+ <action name="actionInstall_Forge">
+ <property name="text">
+ <string>Install Forge</string>
+ </property>
+ <property name="toolTip">
+ <string>Install the Minecraft Forge package.</string>
+ </property>
+ </action>
+ <action name="actionInstall_Fabric">
+ <property name="text">
+ <string>Install Fabric</string>
+ </property>
+ <property name="toolTip">
+ <string>Install the Fabric Loader package.</string>
+ </property>
+ </action>
+ <action name="actionInstall_LiteLoader">
+ <property name="text">
+ <string>Install LiteLoader</string>
+ </property>
+ <property name="toolTip">
+ <string>Install the LiteLoader package.</string>
+ </property>
+ </action>
+ <action name="actionInstall_mods">
+ <property name="text">
+ <string>Install mods</string>
+ </property>
+ <property name="toolTip">
+ <string>Install normal mods.</string>
+ </property>
+ </action>
+ <action name="actionAdd_to_Minecraft_jar">
+ <property name="text">
+ <string>Add to Minecraft.jar</string>
+ </property>
+ <property name="toolTip">
+ <string>Add a mod into the Minecraft jar file.</string>
+ </property>
+ </action>
+ <action name="actionReplace_Minecraft_jar">
+ <property name="text">
+ <string>Replace Minecraft.jar</string>
+ </property>
+ </action>
+ <action name="actionAdd_Empty">
+ <property name="text">
+ <string>Add Empty</string>
+ </property>
+ <property name="toolTip">
+ <string>Add an empty custom package.</string>
+ </property>
+ </action>
+ <action name="actionReload">
+ <property name="text">
+ <string>Reload</string>
+ </property>
+ <property name="toolTip">
+ <string>Reload all packages.</string>
+ </property>
+ </action>
+ <action name="actionDownload_All">
+ <property name="text">
+ <string>Download All</string>
+ </property>
+ <property name="toolTip">
+ <string>Download the files needed to launch the instance now.</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
@@ -282,37 +234,17 @@
<header>widgets/ModListView.h</header>
</customwidget>
<customwidget>
- <class>LineSeparator</class>
- <extends>QWidget</extends>
- <header>widgets/LineSeparator.h</header>
- <container>1</container>
- </customwidget>
- <customwidget>
<class>MCModInfoFrame</class>
<extends>QFrame</extends>
<header>widgets/MCModInfoFrame.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>WideBar</class>
+ <extends>QToolBar</extends>
+ <header>widgets/WideBar.h</header>
+ </customwidget>
</customwidgets>
- <tabstops>
- <tabstop>packageView</tabstop>
- <tabstop>changeVersionBtn</tabstop>
- <tabstop>moveUpBtn</tabstop>
- <tabstop>moveDownBtn</tabstop>
- <tabstop>removeBtn</tabstop>
- <tabstop>customizeBtn</tabstop>
- <tabstop>editBtn</tabstop>
- <tabstop>revertBtn</tabstop>
- <tabstop>forgeBtn</tabstop>
- <tabstop>liteloaderBtn</tabstop>
- <tabstop>modBtn</tabstop>
- <tabstop>jarmodBtn</tabstop>
- <tabstop>jarBtn</tabstop>
- <tabstop>addEmptyBtn</tabstop>
- <tabstop>reloadBtn</tabstop>
- <tabstop>downloadBtn</tabstop>
- <tabstop>tabWidget</tabstop>
- </tabstops>
<resources/>
<connections/>
</ui>
diff --git a/application/pages/instance/WorldListPage.cpp b/application/pages/instance/WorldListPage.cpp
index 539d26a0..8358a0f1 100644
--- a/application/pages/instance/WorldListPage.cpp
+++ b/application/pages/instance/WorldListPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2015-2018 MultiMC Contributors
+/* Copyright 2015-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,8 @@
#include "ui_WorldListPage.h"
#include "minecraft/WorldList.h"
#include <DesktopServices.h>
-#include "dialogs/ModEditDialogCommon.h"
#include <QEvent>
+#include <QMenu>
#include <QKeyEvent>
#include <QClipboard>
#include <QMessageBox>
@@ -31,300 +31,314 @@
#include <QProcess>
#include <FileSystem.h>
-WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> 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)
+WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QWidget *parent)
+ : QMainWindow(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds)
{
- 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());
+ ui->setupUi(this);
+
+ ui->toolBar->insertSpacer(ui->actionRefresh);
+
+ 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);
+ ui->worldTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(ui->worldTreeView, &QTreeView::customContextMenuRequested, this, &WorldListPage::ShowContextMenu);
+
+ auto head = ui->worldTreeView->header();
+ head->setSectionResizeMode(0, QHeaderView::Stretch);
+ head->setSectionResizeMode(1, QHeaderView::ResizeToContents);
+
+ connect(ui->worldTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WorldListPage::worldChanged);
+ worldChanged(QModelIndex(), QModelIndex());
}
void WorldListPage::openedImpl()
{
- m_worlds->startWatching();
+ m_worlds->startWatching();
}
void WorldListPage::closedImpl()
{
- m_worlds->stopWatching();
+ m_worlds->stopWatching();
}
WorldListPage::~WorldListPage()
{
- m_worlds->stopWatching();
- delete ui;
+ m_worlds->stopWatching();
+ delete ui;
+}
+
+void WorldListPage::ShowContextMenu(const QPoint& pos)
+{
+ auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
+ menu->exec(ui->worldTreeView->mapToGlobal(pos));
+ delete menu;
+}
+
+QMenu * WorldListPage::createPopupMenu()
+{
+ QMenu* filteredMenu = QMainWindow::createPopupMenu();
+ filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
+ return filteredMenu;
}
bool WorldListPage::shouldDisplay() const
{
- return true;
+ 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);
+ switch (keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ on_actionRemove_triggered();
+ 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<QKeyEvent *>(ev);
- if (obj == ui->worldTreeView)
- return worldListFilter(keyEvent);
- return QWidget::eventFilter(obj, ev);
+ if (ev->type() != QEvent::KeyPress)
+ {
+ return QWidget::eventFilter(obj, ev);
+ }
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
+ if (obj == ui->worldTreeView)
+ return worldListFilter(keyEvent);
+ return QWidget::eventFilter(obj, ev);
}
-void WorldListPage::on_rmWorldBtn_clicked()
+void WorldListPage::on_actionRemove_triggered()
{
- 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();
+ 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()
+void WorldListPage::on_actionView_Folder_triggered()
{
- DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true);
+ DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true);
}
QModelIndex WorldListPage::getSelectedWorld()
{
- auto index = ui->worldTreeView->selectionModel()->currentIndex();
+ auto index = ui->worldTreeView->selectionModel()->currentIndex();
- auto proxy = (QSortFilterProxyModel *) ui->worldTreeView->model();
- return proxy->mapToSource(index);
+ auto proxy = (QSortFilterProxyModel *) ui->worldTreeView->model();
+ return proxy->mapToSource(index);
}
-void WorldListPage::on_copySeedBtn_clicked()
+void WorldListPage::on_actionCopy_Seed_triggered()
{
- QModelIndex index = getSelectedWorld();
-
- if (!index.isValid())
- {
- return;
- }
- int64_t seed = m_worlds->data(index, WorldList::SeedRole).toLongLong();
- MMC->clipboard()->setText(QString::number(seed));
+ 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()
+void WorldListPage::on_actionMCEdit_triggered()
{
- if(m_mceditStarting)
- return;
+ if(m_mceditStarting)
+ return;
- auto mcedit = MMC->mcedit();
+ auto mcedit = MMC->mcedit();
- const QString mceditPath = mcedit->path();
+ const QString mceditPath = mcedit->path();
- QModelIndex index = getSelectedWorld();
+ QModelIndex index = getSelectedWorld();
- if (!index.isValid())
- {
- return;
- }
+ if (!index.isValid())
+ {
+ return;
+ }
- if(!worldSafetyNagQuestion())
- return;
+ if(!worldSafetyNagQuestion())
+ return;
- auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString();
+ auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString();
- auto program = mcedit->getProgramPath();
- if(program.size())
- {
+ auto program = mcedit->getProgramPath();
+ if(program.size())
+ {
#ifdef Q_OS_WIN32
- if(!QProcess::startDetached(program, {fullPath}, mceditPath))
- {
- mceditError();
- }
+ 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;
+ 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.")
- );
- }
+ }
+ 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.")
- );
+ 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();
- }
+ 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 &current, 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);
+ QModelIndex index = getSelectedWorld();
+ bool enable = index.isValid();
+ ui->actionCopy_Seed->setEnabled(enable);
+ ui->actionMCEdit->setEnabled(enable);
+ ui->actionRemove->setEnabled(enable);
+ ui->actionCopy->setEnabled(enable);
+ ui->actionRename->setEnabled(enable);
}
-void WorldListPage::on_addBtn_clicked()
+void WorldListPage::on_actionAdd_triggered()
{
- 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();
- }
+ auto list = GuiUtil::BrowseForFiles(
+ displayName(),
+ 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();
+ 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;
+ 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()
+void WorldListPage::on_actionCopy_triggered()
{
- QModelIndex index = getSelectedWorld();
- if (!index.isValid())
- {
- return;
- }
-
- if(!worldSafetyNagQuestion())
- return;
-
- auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
- auto world = (World *) worldVariant.value<void *>();
- 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);
- }
+ QModelIndex index = getSelectedWorld();
+ if (!index.isValid())
+ {
+ return;
+ }
+
+ if(!worldSafetyNagQuestion())
+ return;
+
+ auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
+ auto world = (World *) worldVariant.value<void *>();
+ 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()
+void WorldListPage::on_actionRename_triggered()
{
- QModelIndex index = getSelectedWorld();
- if (!index.isValid())
- {
- return;
- }
+ QModelIndex index = getSelectedWorld();
+ if (!index.isValid())
+ {
+ return;
+ }
- if(!worldSafetyNagQuestion())
- return;
+ if(!worldSafetyNagQuestion())
+ return;
- auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
- auto world = (World *) worldVariant.value<void *>();
+ auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
+ auto world = (World *) worldVariant.value<void *>();
- bool ok = false;
- QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new world name."), QLineEdit::Normal, world->name(), &ok);
+ 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);
- }
+ if (ok && name.length() > 0)
+ {
+ world->rename(name);
+ }
}
-void WorldListPage::on_refreshBtn_clicked()
+void WorldListPage::on_actionRefresh_triggered()
{
- m_worlds->update();
+ m_worlds->update();
}
diff --git a/application/pages/instance/WorldListPage.h b/application/pages/instance/WorldListPage.h
index 71b87bda..c39420da 100644
--- a/application/pages/instance/WorldListPage.h
+++ b/application/pages/instance/WorldListPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2015-2018 MultiMC Contributors
+/* Copyright 2015-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
#pragma once
-#include <QWidget>
+#include <QMainWindow>
#include "minecraft/MinecraftInstance.h"
#include "pages/BasePage.h"
@@ -28,69 +28,70 @@ namespace Ui
class WorldListPage;
}
-class WorldListPage : public QWidget, public BasePage
+class WorldListPage : public QMainWindow, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
- QString iconName, QString displayName, QString helpPage = "",
- QWidget *parent = 0);
- virtual ~WorldListPage();
+ explicit WorldListPage(
+ BaseInstance *inst,
+ std::shared_ptr<WorldList> worlds,
+ 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 QString displayName() const override
+ {
+ return tr("Worlds");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("worlds");
+ }
+ virtual QString id() const override
+ {
+ return "worlds";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Worlds";
+ }
+ virtual bool shouldDisplay() const override;
- virtual void openedImpl() override;
- virtual void closedImpl() override;
+ virtual void openedImpl() override;
+ virtual void closedImpl() override;
protected:
- bool eventFilter(QObject *obj, QEvent *ev) override;
- bool worldListFilter(QKeyEvent *ev);
+ bool eventFilter(QObject *obj, QEvent *ev) override;
+ bool worldListFilter(QKeyEvent *ev);
+ QMenu * createPopupMenu() override;
protected:
- BaseInstance *m_inst;
+ BaseInstance *m_inst;
private:
- QModelIndex getSelectedWorld();
- bool isWorldSafe(QModelIndex index);
- bool worldSafetyNagQuestion();
- void mceditError();
+ QModelIndex getSelectedWorld();
+ bool isWorldSafe(QModelIndex index);
+ bool worldSafetyNagQuestion();
+ void mceditError();
private:
- Ui::WorldListPage *ui;
- std::shared_ptr<WorldList> m_worlds;
- unique_qobject_ptr<LoggedProcess> m_mceditProcess;
- bool m_mceditStarting = false;
- QString m_iconName;
- QString m_id;
- QString m_displayName;
- QString m_helpName;
+ Ui::WorldListPage *ui;
+ std::shared_ptr<WorldList> m_worlds;
+ unique_qobject_ptr<LoggedProcess> m_mceditProcess;
+ bool m_mceditStarting = false;
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 &current, const QModelIndex &previous);
- void mceditState(LoggedProcess::State state);
+ void on_actionCopy_Seed_triggered();
+ void on_actionMCEdit_triggered();
+ void on_actionRemove_triggered();
+ void on_actionAdd_triggered();
+ void on_actionCopy_triggered();
+ void on_actionRename_triggered();
+ void on_actionRefresh_triggered();
+ void on_actionView_Folder_triggered();
+ void worldChanged(const QModelIndex &current, const QModelIndex &previous);
+ void mceditState(LoggedProcess::State state);
+
+ void ShowContextMenu(const QPoint &pos);
};
diff --git a/application/pages/instance/WorldListPage.ui b/application/pages/instance/WorldListPage.ui
index 0018ddf3..b7a9e57a 100644
--- a/application/pages/instance/WorldListPage.ui
+++ b/application/pages/instance/WorldListPage.ui
@@ -1,168 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WorldListPage</class>
- <widget class="QWidget" name="WorldListPage">
+ <widget class="QMainWindow" name="WorldListPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>723</width>
- <height>532</height>
+ <width>800</width>
+ <height>600</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
- <number>0</number>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTreeView" name="worldTreeView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DragDrop</enum>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="sortingEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <attribute name="headerStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="WideBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
</property>
- <property name="topMargin">
- <number>0</number>
+ <property name="allowedAreas">
+ <set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set>
</property>
- <property name="rightMargin">
- <number>0</number>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextOnly</enum>
</property>
- <property name="bottomMargin">
- <number>0</number>
+ <property name="floatable">
+ <bool>false</bool>
</property>
- <item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
- </property>
- <widget class="QWidget" name="tab">
- <attribute name="title">
- <string notr="true">Tab 1</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="2">
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QPushButton" name="addBtn">
- <property name="text">
- <string>Add</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="LineSeparator" name="separator" native="true"/>
- </item>
- <item>
- <widget class="QPushButton" name="renameBtn">
- <property name="text">
- <string>Rename</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="copyBtn">
- <property name="text">
- <string>Copy</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="rmWorldBtn">
- <property name="text">
- <string>&amp;Remove</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="mcEditBtn">
- <property name="text">
- <string notr="true">MCEdit</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="LineSeparator" name="separator_2" native="true"/>
- </item>
- <item>
- <widget class="QPushButton" name="copySeedBtn">
- <property name="text">
- <string>Copy Seed</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="refreshBtn">
- <property name="text">
- <string>Refresh</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="viewFolderBtn">
- <property name="text">
- <string>&amp;View Folder</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="0" column="1">
- <widget class="QTreeView" name="worldTreeView">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="acceptDrops">
- <bool>true</bool>
- </property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::DragDrop</enum>
- </property>
- <property name="sortingEnabled">
- <bool>true</bool>
- </property>
- <property name="allColumnsShowFocus">
- <bool>true</bool>
- </property>
- <attribute name="headerStretchLastSection">
- <bool>false</bool>
- </attribute>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
+ <attribute name="toolBarArea">
+ <enum>RightToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionAdd"/>
+ <addaction name="separator"/>
+ <addaction name="actionRename"/>
+ <addaction name="actionCopy"/>
+ <addaction name="actionRemove"/>
+ <addaction name="actionMCEdit"/>
+ <addaction name="separator"/>
+ <addaction name="actionCopy_Seed"/>
+ <addaction name="actionRefresh"/>
+ <addaction name="actionView_Folder"/>
+ </widget>
+ <action name="actionAdd">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </action>
+ <action name="actionRename">
+ <property name="text">
+ <string>Rename</string>
+ </property>
+ </action>
+ <action name="actionCopy">
+ <property name="text">
+ <string>Copy</string>
+ </property>
+ </action>
+ <action name="actionRemove">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </action>
+ <action name="actionMCEdit">
+ <property name="text">
+ <string>MCEdit</string>
+ </property>
+ </action>
+ <action name="actionCopy_Seed">
+ <property name="text">
+ <string>Copy Seed</string>
+ </property>
+ </action>
+ <action name="actionRefresh">
+ <property name="text">
+ <string>Refresh</string>
+ </property>
+ </action>
+ <action name="actionView_Folder">
+ <property name="text">
+ <string>View Folder</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
- <class>LineSeparator</class>
- <extends>QWidget</extends>
- <header>widgets/LineSeparator.h</header>
- <container>1</container>
+ <class>WideBar</class>
+ <extends>QToolBar</extends>
+ <header>widgets/WideBar.h</header>
</customwidget>
</customwidgets>
- <tabstops>
- <tabstop>tabWidget</tabstop>
- <tabstop>worldTreeView</tabstop>
- <tabstop>addBtn</tabstop>
- <tabstop>renameBtn</tabstop>
- <tabstop>copyBtn</tabstop>
- <tabstop>rmWorldBtn</tabstop>
- <tabstop>mcEditBtn</tabstop>
- <tabstop>copySeedBtn</tabstop>
- <tabstop>refreshBtn</tabstop>
- <tabstop>viewFolderBtn</tabstop>
- </tabstops>
<resources/>
<connections/>
</ui>
diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp
index f438fce7..dca86efd 100644
--- a/application/pages/modplatform/FTBPage.cpp
+++ b/application/pages/modplatform/FTBPage.cpp
@@ -1,222 +1,364 @@
#include "FTBPage.h"
#include "ui_FTBPage.h"
+#include <QInputDialog>
+
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/NewInstanceDialog.h"
#include "modplatform/ftb/FtbPackFetchTask.h"
#include "modplatform/ftb/FtbPackInstallTask.h"
+#include "modplatform/ftb/FtbPrivatePackManager.h"
#include "FtbListModel.h"
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
- : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
+ : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
{
- ftbFetchTask = new FtbPackFetchTask();
+ ftbFetchTask.reset(new FtbPackFetchTask());
+ ftbPrivatePacks.reset(new FtbPrivatePackManager());
+
+ ui->setupUi(this);
+
+ {
+ publicFilterModel = new FtbFilterModel(this);
+ publicListModel = new FtbListModel(this);
+ publicFilterModel->setSourceModel(publicListModel);
+
+ ui->publicPackList->setModel(publicFilterModel);
+ ui->publicPackList->setSortingEnabled(true);
+ ui->publicPackList->header()->hide();
+ ui->publicPackList->setIndentation(0);
+ ui->publicPackList->setIconSize(QSize(42, 42));
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+ for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
+ {
+ ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
+ }
- {
- publicFilterModel = new FtbFilterModel(this);
- publicListModel = new FtbListModel(this);
- publicFilterModel->setSourceModel(publicListModel);
+ ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
+ }
- ui->publicPackList->setModel(publicFilterModel);
- ui->publicPackList->setSortingEnabled(true);
- ui->publicPackList->header()->hide();
- ui->publicPackList->setIndentation(0);
- ui->publicPackList->setIconSize(QSize(42, 42));
+ {
+ thirdPartyFilterModel = new FtbFilterModel(this);
+ thirdPartyModel = new FtbListModel(this);
+ thirdPartyFilterModel->setSourceModel(thirdPartyModel);
- for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
- {
- ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
- }
+ ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
+ ui->thirdPartyPackList->setSortingEnabled(true);
+ ui->thirdPartyPackList->header()->hide();
+ ui->thirdPartyPackList->setIndentation(0);
+ ui->thirdPartyPackList->setIconSize(QSize(42, 42));
- ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
- }
+ thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
+ }
- {
- thirdPartyFilterModel = new FtbFilterModel(this);
- thirdPartyModel = new FtbListModel(this);
- thirdPartyFilterModel->setSourceModel(thirdPartyModel);
+ {
+ privateFilterModel = new FtbFilterModel(this);
+ privateListModel = new FtbListModel(this);
+ privateFilterModel->setSourceModel(privateListModel);
- ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
- ui->thirdPartyPackList->setSortingEnabled(true);
- ui->thirdPartyPackList->header()->hide();
- ui->thirdPartyPackList->setIndentation(0);
- ui->thirdPartyPackList->setIconSize(QSize(42, 42));
+ ui->privatePackList->setModel(privateFilterModel);
+ ui->privatePackList->setSortingEnabled(true);
+ ui->privatePackList->header()->hide();
+ ui->privatePackList->setIndentation(0);
+ ui->privatePackList->setIconSize(QSize(42, 42));
- thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
- }
+ privateFilterModel->setSorting(publicFilterModel->getCurrentSorting());
+ }
- ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
+ ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
- connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
- connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
+ connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
+ connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
- connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
- connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
+ connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
+ connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
+ connect(ui->privatePackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPrivatePackSelectionChanged);
- connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
+ connect(ui->addPackBtn, &QPushButton::pressed, this, &FTBPage::onAddPackClicked);
+ connect(ui->removePackBtn, &QPushButton::pressed, this, &FTBPage::onRemovePackClicked);
- ui->modpackInfo->setOpenExternalLinks(true);
+ connect(ui->tabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
- ui->publicPackList->selectionModel()->reset();
- ui->thirdPartyPackList->selectionModel()->reset();
+ // ui->modpackInfo->setOpenExternalLinks(true);
+
+ ui->publicPackList->selectionModel()->reset();
+ ui->thirdPartyPackList->selectionModel()->reset();
+ ui->privatePackList->selectionModel()->reset();
+
+ onTabChanged(ui->tabWidget->currentIndex());
}
FTBPage::~FTBPage()
{
- delete ui;
- if(ftbFetchTask) {
- ftbFetchTask->deleteLater();
- }
+ delete ui;
}
bool FTBPage::shouldDisplay() const
{
- return true;
+ return true;
}
void FTBPage::openedImpl()
{
- if(!initialized)
- {
- connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
- connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
- ftbFetchTask->fetch();
- initialized = true;
- }
- suggestCurrent();
+ if(!initialized)
+ {
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
+
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::privateFileDownloadFinished, this, &FTBPage::ftbPrivatePackDataDownloadSuccessfully);
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::privateFileDownloadFailed, this, &FTBPage::ftbPrivatePackDataDownloadFailed);
+
+ ftbFetchTask->fetch();
+ ftbPrivatePacks->load();
+ ftbFetchTask->fetchPrivate(ftbPrivatePacks->getCurrentPackCodes().toList());
+ initialized = true;
+ }
+ suggestCurrent();
}
void FTBPage::suggestCurrent()
{
- if(isOpened)
- {
- if(!selected.broken)
- {
- dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
- if(selected.type == FtbPackType::Public) {
- publicListModel->getLogo(selected.logo, [this](QString logo){
- dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
- });
- } else if (selected.type == FtbPackType::ThirdParty) {
- thirdPartyModel->getLogo(selected.logo, [this](QString logo){
- dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
- });
- }
- }
- else
- {
- dialog->setSuggestedPack();
- }
- }
+ if(isOpened)
+ {
+ if(!selected.broken)
+ {
+ dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
+ QString editedLogoName;
+ if(selected.logo.toLower().startsWith("ftb"))
+ {
+ editedLogoName = selected.logo;
+ }
+ else
+ {
+ editedLogoName = "ftb_" + selected.logo;
+ }
+
+ editedLogoName = editedLogoName.left(editedLogoName.lastIndexOf(".png"));
+
+ if(selected.type == FtbPackType::Public)
+ {
+ publicListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+ }
+ else if (selected.type == FtbPackType::ThirdParty)
+ {
+ thirdPartyModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+ }
+ else if (selected.type == FtbPackType::Private)
+ {
+ privateListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+ }
+ }
+ else
+ {
+ dialog->setSuggestedPack();
+ }
+ }
}
void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks)
{
- publicListModel->fill(publicPacks);
- thirdPartyModel->fill(thirdPartyPacks);
+ publicListModel->fill(publicPacks);
+ thirdPartyModel->fill(thirdPartyPacks);
}
void FTBPage::ftbPackDataDownloadFailed(QString reason)
{
- //TODO: Display the error
+ //TODO: Display the error
+}
+
+void FTBPage::ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack)
+{
+ privateListModel->addPack(pack);
+}
+
+void FTBPage::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
+{
+ auto reply = QMessageBox::question(
+ this,
+ tr("FTB private packs"),
+ tr("Failed to download pack information for code %1.\nShould it be removed now?").arg(packCode)
+ );
+ if(reply == QMessageBox::Yes)
+ {
+ ftbPrivatePacks->remove(packCode);
+ }
}
void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
- if(!now.isValid())
- {
- onPackSelectionChanged();
- return;
- }
- FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
- onPackSelectionChanged(&selectedPack);
+ if(!now.isValid())
+ {
+ onPackSelectionChanged();
+ return;
+ }
+ FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&selectedPack);
}
void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
- if(!now.isValid())
- {
- onPackSelectionChanged();
- return;
- }
- FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
- onPackSelectionChanged(&selectedPack);
+ if(!now.isValid())
+ {
+ onPackSelectionChanged();
+ return;
+ }
+ FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&selectedPack);
+}
+
+void FTBPage::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
+{
+ if(!now.isValid())
+ {
+ onPackSelectionChanged();
+ return;
+ }
+ FtbModpack selectedPack = privateFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&selectedPack);
}
void FTBPage::onPackSelectionChanged(FtbModpack* pack)
{
- ui->packVersionSelection->clear();
- if(pack)
- {
- ui->modpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>"
- "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
- bool currentAdded = false;
-
- for(int i = 0; i < pack->oldVersions.size(); i++)
- {
- if(pack->currentVersion == pack->oldVersions.at(i))
- {
- currentAdded = true;
- }
- ui->packVersionSelection->addItem(pack->oldVersions.at(i));
- }
-
- if(!currentAdded)
- {
- ui->packVersionSelection->addItem(pack->currentVersion);
- }
- selected = *pack;
- }
- suggestCurrent();
+ ui->versionSelectionBox->clear();
+ if(pack)
+ {
+ currentModpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" +
+ "<br>Minecraft " + pack->mcVersion + "<br>" + "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>")
+ + "</li></ul>");
+ bool currentAdded = false;
+
+ for(int i = 0; i < pack->oldVersions.size(); i++)
+ {
+ if(pack->currentVersion == pack->oldVersions.at(i))
+ {
+ currentAdded = true;
+ }
+ ui->versionSelectionBox->addItem(pack->oldVersions.at(i));
+ }
+
+ if(!currentAdded)
+ {
+ ui->versionSelectionBox->addItem(pack->currentVersion);
+ }
+ selected = *pack;
+ }
+ else
+ {
+ currentModpackInfo->setHtml("");
+ ui->versionSelectionBox->clear();
+ if(isOpened)
+ {
+ dialog->setSuggestedPack();
+ }
+ return;
+ }
+ suggestCurrent();
}
void FTBPage::onVersionSelectionItemChanged(QString data)
{
- if(data.isNull() || data.isEmpty())
- {
- selectedVersion = "";
- return;
- }
+ if(data.isNull() || data.isEmpty())
+ {
+ selectedVersion = "";
+ return;
+ }
- selectedVersion = data;
- suggestCurrent();
+ selectedVersion = data;
+ suggestCurrent();
}
void FTBPage::onSortingSelectionChanged(QString data)
{
- FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
- publicFilterModel->setSorting(toSet);
- thirdPartyFilterModel->setSorting(toSet);
+ FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
+ publicFilterModel->setSorting(toSet);
+ thirdPartyFilterModel->setSorting(toSet);
+ privateFilterModel->setSorting(toSet);
}
void FTBPage::onTabChanged(int tab)
{
- FtbFilterModel* currentModel = nullptr;
- QTreeView* currentList = nullptr;
- if (tab == 0)
- {
- currentModel = publicFilterModel;
- currentList = ui->publicPackList;
- }
- else
- {
- currentModel = thirdPartyFilterModel;
- currentList = ui->thirdPartyPackList;
- }
- QModelIndex idx = currentList->currentIndex();
- if(idx.isValid())
- {
- auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
- onPackSelectionChanged(&pack);
- }
- else
- {
- onPackSelectionChanged();
- }
+ if(tab == 1)
+ {
+ currentModel = thirdPartyFilterModel;
+ currentList = ui->thirdPartyPackList;
+ currentModpackInfo = ui->thirdPartyPackDescription;
+ }
+ else if(tab == 2)
+ {
+ currentModel = privateFilterModel;
+ currentList = ui->privatePackList;
+ currentModpackInfo = ui->privatePackDescription;
+ }
+ else
+ {
+ currentModel = publicFilterModel;
+ currentList = ui->publicPackList;
+ currentModpackInfo = ui->publicPackDescription;
+ }
+
+ currentList->selectionModel()->reset();
+ QModelIndex idx = currentList->currentIndex();
+ if(idx.isValid())
+ {
+ auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&pack);
+ }
+ else
+ {
+ onPackSelectionChanged();
+ }
+}
+
+void FTBPage::onAddPackClicked()
+{
+ bool ok;
+ QString text = QInputDialog::getText(
+ this,
+ tr("Add FTB pack"),
+ tr("Enter pack code:"),
+ QLineEdit::Normal,
+ QString(),
+ &ok
+ );
+ if(ok && !text.isEmpty())
+ {
+ ftbPrivatePacks->add(text);
+ ftbFetchTask->fetchPrivate({text});
+ }
+}
+
+void FTBPage::onRemovePackClicked()
+{
+ auto index = ui->privatePackList->currentIndex();
+ if(!index.isValid())
+ {
+ return;
+ }
+ auto row = index.row();
+ FtbModpack pack = privateListModel->at(row);
+ auto answer = QMessageBox::question(
+ this,
+ tr("Remove pack"),
+ tr("Are you sure you want to remove pack %1?").arg(pack.name),
+ QMessageBox::Yes | QMessageBox::No
+ );
+ if(answer != QMessageBox::Yes)
+ {
+ return;
+ }
+
+ ftbPrivatePacks->remove(pack.packCode);
+ privateListModel->remove(row);
+ onPackSelectionChanged();
}
diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h
index 00c5e9c5..215252ee 100644
--- a/application/pages/modplatform/FTBPage.h
+++ b/application/pages/modplatform/FTBPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,15 @@
#pragma once
#include <QWidget>
+#include <QTreeView>
+#include <QTextBrowser>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
#include "modplatform/ftb/PackHelpers.h"
#include "modplatform/ftb/FtbPackFetchTask.h"
+#include "QObjectPtr.h"
namespace Ui
{
@@ -31,62 +34,81 @@ class FTBPage;
class FtbListModel;
class FtbFilterModel;
class NewInstanceDialog;
+class FtbPrivatePackListModel;
+class FtbPrivatePackFilterModel;
+class FtbPrivatePackManager;
class FTBPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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;
private:
- void suggestCurrent();
- void onPackSelectionChanged(FtbModpack *pack = nullptr);
+ void suggestCurrent();
+ void onPackSelectionChanged(FtbModpack *pack = nullptr);
private slots:
- void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
- void ftbPackDataDownloadFailed(QString reason);
+ void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
+ void ftbPackDataDownloadFailed(QString reason);
- void onSortingSelectionChanged(QString data);
- void onVersionSelectionItemChanged(QString data);
+ void ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack);
+ void ftbPrivatePackDataDownloadFailed(QString reason, QString packCode);
- void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
- void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void onSortingSelectionChanged(QString data);
+ void onVersionSelectionItemChanged(QString data);
- void onTabChanged(int tab);
+ void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void onPrivatePackSelectionChanged(QModelIndex first, QModelIndex second);
+
+ void onTabChanged(int tab);
+
+ void onAddPackClicked();
+ void onRemovePackClicked();
private:
- bool initialized = false;
- FtbModpack selected;
- QString selectedVersion;
+ FtbFilterModel* currentModel = nullptr;
+ QTreeView* currentList = nullptr;
+ QTextBrowser* currentModpackInfo = nullptr;
+
+ bool initialized = false;
+ FtbModpack selected;
+ QString selectedVersion;
+
+ FtbListModel* publicListModel = nullptr;
+ FtbFilterModel* publicFilterModel = nullptr;
+
+ FtbListModel *thirdPartyModel = nullptr;
+ FtbFilterModel *thirdPartyFilterModel = nullptr;
- FtbListModel* publicListModel = nullptr;
- FtbFilterModel* publicFilterModel = nullptr;
+ FtbListModel *privateListModel = nullptr;
+ FtbFilterModel *privateFilterModel = nullptr;
- FtbListModel *thirdPartyModel = nullptr;
- FtbFilterModel *thirdPartyFilterModel = nullptr;
+ unique_qobject_ptr<FtbPackFetchTask> ftbFetchTask;
+ std::unique_ptr<FtbPrivatePackManager> ftbPrivatePacks;
- FtbPackFetchTask *ftbFetchTask = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ NewInstanceDialog* dialog = nullptr;
- Ui::FTBPage *ui = nullptr;
+ Ui::FTBPage *ui = nullptr;
};
diff --git a/application/pages/modplatform/FTBPage.ui b/application/pages/modplatform/FTBPage.ui
index cb085af2..e5ed78cb 100644
--- a/application/pages/modplatform/FTBPage.ui
+++ b/application/pages/modplatform/FTBPage.ui
@@ -11,18 +11,6 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
@@ -30,86 +18,107 @@
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
- <string notr="true"/>
+ <string>Public</string>
</attribute>
- <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
- <item row="1" column="2" colspan="2">
- <widget class="QTextBrowser" name="modpackInfo">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAsNeeded</enum>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QTreeView" name="publicPackList">
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
</property>
</widget>
</item>
- <item row="2" column="2">
- <widget class="QLabel" name="selectedVersionLabel">
- <property name="text">
- <string>Version selected:</string>
+ <item row="0" column="1">
+ <widget class="QTextBrowser" name="publicPackDescription"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>3rd Party</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="1">
+ <widget class="QTextBrowser" name="thirdPartyPackDescription"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QTreeView" name="thirdPartyPackList">
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
</property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_3">
+ <attribute name="title">
+ <string>Private</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QTreeView" name="privatePackList">
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
</property>
</widget>
</item>
- <item row="2" column="3">
- <widget class="QComboBox" name="packVersionSelection"/>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="addPackBtn">
+ <property name="text">
+ <string>Add pack</string>
+ </property>
+ </widget>
</item>
<item row="2" column="0">
- <widget class="QComboBox" name="sortByBox"/>
- </item>
- <item row="0" column="0" rowspan="2">
- <widget class="QTabWidget" name="ftbTabWidget">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="tabShape">
- <enum>QTabWidget::Rounded</enum>
- </property>
- <property name="currentIndex">
- <number>0</number>
+ <widget class="QPushButton" name="removePackBtn">
+ <property name="text">
+ <string>Remove selected pack</string>
</property>
- <widget class="QWidget" name="tab_2">
- <attribute name="title">
- <string>Public Packs</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QTreeView" name="publicPackList">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAsNeeded</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QWidget" name="tab_3">
- <attribute name="title">
- <string>3rd Party Packs</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QTreeView" name="thirdPartyPackList">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAsNeeded</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
</widget>
</item>
+ <item row="0" column="1" rowspan="3">
+ <widget class="QTextBrowser" name="privatePackDescription"/>
+ </item>
</layout>
</widget>
</widget>
</item>
+ <item>
+ <layout class="QGridLayout" name="gridLayout_4">
+ <item row="0" column="1">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Version selected:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QComboBox" name="versionSelectionBox"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QComboBox" name="sortByBox">
+ <property name="minimumSize">
+ <size>
+ <width>265</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/application/pages/modplatform/FtbListModel.cpp b/application/pages/modplatform/FtbListModel.cpp
index c14907c6..51aec890 100644
--- a/application/pages/modplatform/FtbListModel.cpp
+++ b/application/pages/modplatform/FtbListModel.cpp
@@ -10,56 +10,58 @@
#include <RWStorage.h>
#include <Env.h>
+#include "net/URLConstants.h"
+
FtbFilterModel::FtbFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
{
- currentSorting = Sorting::ByGameVersion;
- sortings.insert(tr("Sort by name"), Sorting::ByName);
- sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
+ currentSorting = Sorting::ByGameVersion;
+ sortings.insert(tr("Sort by name"), Sorting::ByName);
+ sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
}
bool FtbFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
- FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
- FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
+ FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
+ FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
- if(currentSorting == Sorting::ByGameVersion) {
- Version lv(leftPack.mcVersion);
- Version rv(rightPack.mcVersion);
- return lv < rv;
+ if(currentSorting == Sorting::ByGameVersion) {
+ Version lv(leftPack.mcVersion);
+ Version rv(rightPack.mcVersion);
+ return lv < rv;
- } else if(currentSorting == Sorting::ByName) {
- return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
- }
+ } else if(currentSorting == Sorting::ByName) {
+ return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
+ }
- //UHM, some inavlid value set?!
- qWarning() << "Invalid sorting set!";
- return true;
+ //UHM, some inavlid value set?!
+ qWarning() << "Invalid sorting set!";
+ return true;
}
bool FtbFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
- return true;
+ return true;
}
const QMap<QString, FtbFilterModel::Sorting> FtbFilterModel::getAvailableSortings()
{
- return sortings;
+ return sortings;
}
QString FtbFilterModel::translateCurrentSorting()
{
- return sortings.key(currentSorting);
+ return sortings.key(currentSorting);
}
void FtbFilterModel::setSorting(Sorting s)
{
- currentSorting = s;
- invalidate();
+ currentSorting = s;
+ invalidate();
}
FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting()
{
- return currentSorting;
+ return currentSorting;
}
FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent)
@@ -72,128 +74,183 @@ FtbListModel::~FtbListModel()
QString FtbListModel::translatePackType(FtbPackType type) const
{
- if(type == FtbPackType::Public) {
- return tr("Public Modpack");
- } else if(type == FtbPackType::ThirdParty) {
- return tr("Third Party Modpack");
- } else if(type == FtbPackType::Private) {
- return tr("Private Modpack");
- } else {
- return tr("Unknown Type");
- }
+ switch(type)
+ {
+ case FtbPackType::Public:
+ return tr("Public Modpack");
+ case FtbPackType::ThirdParty:
+ return tr("Third Party Modpack");
+ case FtbPackType::Private:
+ return tr("Private Modpack");
+ }
+ qWarning() << "Unknown FTB modpack type:" << int(type);
+ return QString();
}
int FtbListModel::rowCount(const QModelIndex &parent) const
{
- return modpacks.size();
+ return modpacks.size();
}
int FtbListModel::columnCount(const QModelIndex &parent) const
{
- return 1;
+ return 1;
}
QVariant FtbListModel::data(const QModelIndex &index, int role) const
{
- int pos = index.row();
- if(pos >= modpacks.size() || pos < 0 || !index.isValid()) {
- return QString("INVALID INDEX %1").arg(pos);
- }
-
- FtbModpack pack = modpacks.at(pos);
- if(role == Qt::DisplayRole) {
- return pack.name + "\n" + translatePackType(pack.type);
- } else if (role == Qt::ToolTipRole) {
- if(pack.description.length() > 100) {
- //some magic to prevent to long tooltips and replace html linebreaks
- QString edit = pack.description.left(97);
- edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
- return edit;
-
- }
- return pack.description;
- } else if(role == Qt::DecorationRole) {
- if(m_logoMap.contains(pack.logo)) {
- return (m_logoMap.value(pack.logo));
- }
- QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
- ((FtbListModel *)this)->requestLogo(pack.logo);
- return icon;
- } else if(role == Qt::TextColorRole) {
- if(pack.broken) {
- //FIXME: Hardcoded color
- return QColor(255, 0, 50);
- } else if(pack.bugged) {
- //FIXME: Hardcoded color
- //bugged pack, currently only indicates bugged xml
- return QColor(244, 229, 66);
- }
- } else if(role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
- }
-
- return QVariant();
+ int pos = index.row();
+ if(pos >= modpacks.size() || pos < 0 || !index.isValid())
+ {
+ return QString("INVALID INDEX %1").arg(pos);
+ }
+
+ FtbModpack pack = modpacks.at(pos);
+ if(role == Qt::DisplayRole)
+ {
+ return pack.name + "\n" + translatePackType(pack.type);
+ }
+ else if (role == Qt::ToolTipRole)
+ {
+ if(pack.description.length() > 100)
+ {
+ //some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+
+ }
+ return pack.description;
+ }
+ else if(role == Qt::DecorationRole)
+ {
+ if(m_logoMap.contains(pack.logo))
+ {
+ return (m_logoMap.value(pack.logo));
+ }
+ QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
+ ((FtbListModel *)this)->requestLogo(pack.logo);
+ return icon;
+ }
+ else if(role == Qt::TextColorRole)
+ {
+ if(pack.broken)
+ {
+ //FIXME: Hardcoded color
+ return QColor(255, 0, 50);
+ }
+ else if(pack.bugged)
+ {
+ //FIXME: Hardcoded color
+ //bugged pack, currently only indicates bugged xml
+ return QColor(244, 229, 66);
+ }
+ }
+ else if(role == Qt::UserRole)
+ {
+ QVariant v;
+ v.setValue(pack);
+ return v;
+ }
+
+ return QVariant();
}
void FtbListModel::fill(FtbModpackList modpacks)
{
- beginResetModel();
- this->modpacks = modpacks;
- endResetModel();
+ beginResetModel();
+ this->modpacks = modpacks;
+ endResetModel();
+}
+
+void FtbListModel::addPack(FtbModpack modpack)
+{
+ beginResetModel();
+ this->modpacks.append(modpack);
+ endResetModel();
+}
+
+void FtbListModel::clear()
+{
+ beginResetModel();
+ modpacks.clear();
+ endResetModel();
}
FtbModpack FtbListModel::at(int row)
{
- return modpacks.at(row);
+ return modpacks.at(row);
+}
+
+void FtbListModel::remove(int row)
+{
+ if(row < 0 || row >= modpacks.size())
+ {
+ qWarning() << "Attempt to remove FTB modpacks with invalid row" << row;
+ return;
+ }
+ beginRemoveRows(QModelIndex(), row, row);
+ modpacks.removeAt(row);
+ endRemoveRows();
}
void FtbListModel::logoLoaded(QString logo, QIcon out)
{
- m_loadingLogos.removeAll(logo);
- m_logoMap.insert(logo, out);
- emit dataChanged(createIndex(0, 0), createIndex(1, 0));
+ m_loadingLogos.removeAll(logo);
+ m_logoMap.insert(logo, out);
+ emit dataChanged(createIndex(0, 0), createIndex(1, 0));
}
void FtbListModel::logoFailed(QString logo)
{
- m_failedLogos.append(logo);
- m_loadingLogos.removeAll(logo);
+ m_failedLogos.append(logo);
+ m_loadingLogos.removeAll(logo);
}
void FtbListModel::requestLogo(QString file)
{
- if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) {
- return;
- }
-
- MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
- NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file));
- job->addNetAction(Net::Download::makeCached(QUrl(QString("https://ftb.cursecdn.com/FTB2/static/%1").arg(file)), entry));
-
- auto fullPath = entry->getFullPath();
- QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
- emit logoLoaded(file, QIcon(fullPath));
- if(waitingCallbacks.contains(file)) {
- waitingCallbacks.value(file)(fullPath);
- }
- });
-
- QObject::connect(job, &NetJob::failed, this, [this, file]{
- emit logoFailed(file);
- });
-
- job->start();
-
- m_loadingLogos.append(file);
+ if(m_loadingLogos.contains(file) || m_failedLogos.contains(file))
+ {
+ return;
+ }
+
+ MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
+ NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file));
+ job->addNetAction(Net::Download::makeCached(QUrl(QString(URLConstants::FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
+
+ auto fullPath = entry->getFullPath();
+ QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]
+ {
+ emit logoLoaded(file, QIcon(fullPath));
+ if(waitingCallbacks.contains(file))
+ {
+ waitingCallbacks.value(file)(fullPath);
+ }
+ });
+
+ QObject::connect(job, &NetJob::failed, this, [this, file]
+ {
+ emit logoFailed(file);
+ });
+
+ job->start();
+
+ m_loadingLogos.append(file);
}
void FtbListModel::getLogo(const QString &logo, LogoCallback callback)
{
- if(m_logoMap.contains(logo)) {
- callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
- } else {
- requestLogo(logo);
- }
+ if(m_logoMap.contains(logo))
+ {
+ callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ }
+ else
+ {
+ requestLogo(logo);
+ }
+}
+
+Qt::ItemFlags FtbListModel::flags(const QModelIndex &index) const
+{
+ return QAbstractListModel::flags(index);
}
diff --git a/application/pages/modplatform/FtbListModel.h b/application/pages/modplatform/FtbListModel.h
index d3a82b73..34749b24 100644
--- a/application/pages/modplatform/FtbListModel.h
+++ b/application/pages/modplatform/FtbListModel.h
@@ -7,6 +7,7 @@
#include <QSortFilterProxyModel>
#include <QThreadPool>
#include <QIcon>
+#include <QStyledItemDelegate>
#include <functional>
@@ -15,54 +16,59 @@ typedef std::function<void(QString)> LogoCallback;
class FtbFilterModel : public QSortFilterProxyModel
{
+ Q_OBJECT
public:
- FtbFilterModel(QObject* parent = Q_NULLPTR);
- enum Sorting {
- ByName,
- ByGameVersion
- };
- const QMap<QString, Sorting> getAvailableSortings();
- QString translateCurrentSorting();
- void setSorting(Sorting sorting);
- Sorting getCurrentSorting();
+ FtbFilterModel(QObject* parent = Q_NULLPTR);
+ enum Sorting {
+ ByName,
+ ByGameVersion
+ };
+ const QMap<QString, Sorting> getAvailableSortings();
+ QString translateCurrentSorting();
+ void setSorting(Sorting sorting);
+ Sorting getCurrentSorting();
protected:
- bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
- bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private:
- QMap<QString, Sorting> sortings;
- Sorting currentSorting;
+ QMap<QString, Sorting> sortings;
+ Sorting currentSorting;
};
class FtbListModel : public QAbstractListModel
{
- Q_OBJECT
+ Q_OBJECT
private:
- FtbModpackList modpacks;
- QStringList m_failedLogos;
- QStringList m_loadingLogos;
- FtbLogoMap m_logoMap;
- QMap<QString, LogoCallback> waitingCallbacks;
+ FtbModpackList modpacks;
+ QStringList m_failedLogos;
+ QStringList m_loadingLogos;
+ FtbLogoMap m_logoMap;
+ QMap<QString, LogoCallback> waitingCallbacks;
- void requestLogo(QString file);
- QString translatePackType(FtbPackType type) const;
+ void requestLogo(QString file);
+ QString translatePackType(FtbPackType type) const;
private slots:
- void logoFailed(QString logo);
- void logoLoaded(QString logo, QIcon out);
+ void logoFailed(QString logo);
+ void logoLoaded(QString logo, QIcon out);
public:
- FtbListModel(QObject *parent);
- ~FtbListModel();
- int rowCount(const QModelIndex &parent) const override;
- int columnCount(const QModelIndex &parent) const override;
- QVariant data(const QModelIndex &index, int role) const override;
+ FtbListModel(QObject *parent);
+ ~FtbListModel();
+ int rowCount(const QModelIndex &parent) const override;
+ int columnCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
- void fill(FtbModpackList modpacks);
+ void fill(FtbModpackList modpacks);
+ void addPack(FtbModpack modpack);
+ void clear();
+ void remove(int row);
- FtbModpack at(int row);
- void getLogo(const QString &logo, LogoCallback callback);
+ FtbModpack at(int row);
+ void getLogo(const QString &logo, LogoCallback callback);
};
diff --git a/application/pages/modplatform/ImportPage.cpp b/application/pages/modplatform/ImportPage.cpp
index 75a51245..af243511 100644
--- a/application/pages/modplatform/ImportPage.cpp
+++ b/application/pages/modplatform/ImportPage.cpp
@@ -2,11 +2,9 @@
#include "ui_ImportPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
#include <QFileDialog>
+#include <QValidator>
#include <InstanceImportTask.h>
#include <QTabBar>
#include <QValidator>
@@ -14,114 +12,119 @@
class UrlValidator : public QValidator
{
public:
- using QValidator::QValidator;
+ 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;
- }
- }
+ 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)
+ : 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);
+ ui->setupUi(this);
+ ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
+ connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState);
}
ImportPage::~ImportPage()
{
- delete ui;
+ delete ui;
}
bool ImportPage::shouldDisplay() const
{
- return true;
+ return true;
}
void ImportPage::openedImpl()
{
- updateState();
+ 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();
- }
+ 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
+ {
+ if(input.endsWith("?client=y")) {
+ input.chop(9);
+ input.append("/file");
+ url = QUrl::fromUserInput(input);
+ }
+ // 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();
+ 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());
- }
- }
+ 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());
- }
+ 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
index 8f62e6b1..3afb0045 100644
--- a/application/pages/modplatform/ImportPage.h
+++ b/application/pages/modplatform/ImportPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,41 +30,41 @@ class NewInstanceDialog;
class ImportPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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;
+ void setUrl(const QString & url);
+ void openedImpl() override;
private slots:
- void on_modpackBtn_clicked();
- void updateState();
+ void on_modpackBtn_clicked();
+ void updateState();
private:
- QUrl modpackUrl() const;
+ QUrl modpackUrl() const;
private:
- Ui::ImportPage *ui = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ Ui::ImportPage *ui = nullptr;
+ NewInstanceDialog* dialog = nullptr;
};
diff --git a/application/pages/modplatform/TechnicPage.cpp b/application/pages/modplatform/TechnicPage.cpp
index c0f4faa5..2f95bec8 100644
--- a/application/pages/modplatform/TechnicPage.cpp
+++ b/application/pages/modplatform/TechnicPage.cpp
@@ -2,28 +2,25 @@
#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)
+ : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
}
TechnicPage::~TechnicPage()
{
- delete ui;
+ delete ui;
}
bool TechnicPage::shouldDisplay() const
{
- return true;
+ return true;
}
void TechnicPage::openedImpl()
{
- dialog->setSuggestedPack();
+ dialog->setSuggestedPack();
}
diff --git a/application/pages/modplatform/TechnicPage.h b/application/pages/modplatform/TechnicPage.h
index 5b0f16a6..cc82ddf3 100644
--- a/application/pages/modplatform/TechnicPage.h
+++ b/application/pages/modplatform/TechnicPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,32 +30,32 @@ class NewInstanceDialog;
class TechnicPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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;
+ Ui::TechnicPage *ui = nullptr;
+ NewInstanceDialog* dialog = nullptr;
};
diff --git a/application/pages/modplatform/TwitchPage.cpp b/application/pages/modplatform/TwitchPage.cpp
index 42aa46be..ea0f9267 100644
--- a/application/pages/modplatform/TwitchPage.cpp
+++ b/application/pages/modplatform/TwitchPage.cpp
@@ -2,28 +2,59 @@
#include "ui_TwitchPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
+#include <InstanceImportTask.h>
TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
- : QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
+ : QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
+ connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck);
}
TwitchPage::~TwitchPage()
{
- delete ui;
+ delete ui;
}
bool TwitchPage::shouldDisplay() const
{
- return false;
+ return true;
}
void TwitchPage::openedImpl()
{
- dialog->setSuggestedPack();
+ dialog->setSuggestedPack();
+}
+
+void TwitchPage::triggerCheck(bool)
+{
+ if(m_modIdResolver) {
+ return;
+ }
+ auto task = new Flame::UrlResolvingTask(ui->lineEdit->text());
+ connect(task, &Task::finished, this, &TwitchPage::checkDone);
+ m_modIdResolver.reset(task);
+ task->start();
+}
+
+void TwitchPage::setUrl(const QString& url)
+{
+ ui->lineEdit->setText(url);
+ triggerCheck(true);
+}
+
+void TwitchPage::checkDone()
+{
+ auto result = m_modIdResolver->getResults();
+ auto formatted = QString("Project %1, File %2").arg(result.projectId).arg(result.fileId);
+ if(result.resolved && result.type == Flame::File::Type::Modpack) {
+ ui->twitchLabel->setText(formatted);
+ QFileInfo fi(result.fileName);
+ dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(result.url));
+ } else {
+ ui->twitchLabel->setPixmap(QPixmap(QString::fromUtf8(":/assets/deadglitch")));
+ dialog->setSuggestedPack();
+ }
+ m_modIdResolver.reset();
}
diff --git a/application/pages/modplatform/TwitchPage.h b/application/pages/modplatform/TwitchPage.h
index 8e072917..600913cd 100644
--- a/application/pages/modplatform/TwitchPage.h
+++ b/application/pages/modplatform/TwitchPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
+#include "modplatform/flame/UrlResolvingTask.h"
namespace Ui
{
@@ -30,32 +31,39 @@ class NewInstanceDialog;
class TwitchPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0);
+ virtual ~TwitchPage();
+ virtual QString displayName() const override
+ {
+ return tr("Twitch URL");
+ }
+ 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;
+
+ void setUrl(const QString & url);
+
+private slots:
+ void triggerCheck(bool checked);
+ void checkDone();
private:
- Ui::TwitchPage *ui = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ Ui::TwitchPage *ui = nullptr;
+ NewInstanceDialog* dialog = nullptr;
+ shared_qobject_ptr<Flame::UrlResolvingTask> m_modIdResolver;
};
diff --git a/application/pages/modplatform/TwitchPage.ui b/application/pages/modplatform/TwitchPage.ui
index 0930f541..0db2484d 100644
--- a/application/pages/modplatform/TwitchPage.ui
+++ b/application/pages/modplatform/TwitchPage.ui
@@ -10,9 +10,25 @@
<height>405</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="label_3">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Twitch URL:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="3">
+ <widget class="QLabel" name="twitchLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="font">
<font>
<pointsize>40</pointsize>
@@ -26,8 +42,19 @@
</property>
</widget>
</item>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="checkButton">
+ <property name="text">
+ <string>Check</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
+ <tabstops>
+ <tabstop>lineEdit</tabstop>
+ <tabstop>checkButton</tabstop>
+ </tabstops>
<resources>
<include location="../../resources/assets/assets.qrc"/>
</resources>
diff --git a/application/pages/modplatform/VanillaPage.cpp b/application/pages/modplatform/VanillaPage.cpp
index c355fccb..17535f1e 100644
--- a/application/pages/modplatform/VanillaPage.cpp
+++ b/application/pages/modplatform/VanillaPage.cpp
@@ -2,9 +2,6 @@
#include "ui_VanillaPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
@@ -15,81 +12,84 @@
#include <QTabBar>
VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent)
- : QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage)
+ : 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);
- connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh);
+ 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);
+ connect(ui->experimentsFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh);
}
void VanillaPage::openedImpl()
{
- if(!initialized)
- {
- auto vlist = ENV.metadataIndex()->get("net.minecraft");
- ui->versionList->initialize(vlist.get());
- initialized = true;
- }
- else
- {
- suggestCurrent();
- }
+ if(!initialized)
+ {
+ auto vlist = ENV.metadataIndex()->get("net.minecraft");
+ ui->versionList->initialize(vlist.get());
+ initialized = true;
+ }
+ else
+ {
+ suggestCurrent();
+ }
}
void VanillaPage::refresh()
{
- ui->versionList->loadList();
+ ui->versionList->loadList();
}
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));
+ 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)";
+ if(ui->experimentsFilter->isChecked())
+ out << "(experiment)";
+ auto regexp = out.join('|');
+ ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
}
VanillaPage::~VanillaPage()
{
- delete ui;
+ delete ui;
}
bool VanillaPage::shouldDisplay() const
{
- return true;
+ return true;
}
BaseVersionPtr VanillaPage::selectedVersion() const
{
- return m_selectedVersion;
+ return m_selectedVersion;
}
void VanillaPage::suggestCurrent()
{
- if(m_selectedVersion && isOpened)
- {
- dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
- }
+ if(m_selectedVersion && isOpened)
+ {
+ dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
+ }
}
void VanillaPage::setSelectedVersion(BaseVersionPtr version)
{
- m_selectedVersion = version;
- suggestCurrent();
+ m_selectedVersion = version;
+ suggestCurrent();
}
diff --git a/application/pages/modplatform/VanillaPage.h b/application/pages/modplatform/VanillaPage.h
index 91c65edf..cc77733c 100644
--- a/application/pages/modplatform/VanillaPage.h
+++ b/application/pages/modplatform/VanillaPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,46 +30,46 @@ class NewInstanceDialog;
class VanillaPage : public QWidget, public BasePage
{
- Q_OBJECT
+ 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;
+ 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;
+ BaseVersionPtr selectedVersion() const;
public slots:
- void setSelectedVersion(BaseVersionPtr version);
+ void setSelectedVersion(BaseVersionPtr version);
private slots:
- void filterChanged();
+ void filterChanged();
private:
- void refresh();
- void suggestCurrent();
+ void refresh();
+ void suggestCurrent();
private:
- bool initialized = false;
- NewInstanceDialog *dialog = nullptr;
- Ui::VanillaPage *ui = nullptr;
- bool m_versionSetByUser = false;
- BaseVersionPtr m_selectedVersion;
+ 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
index ae9cab47..47effc86 100644
--- a/application/pages/modplatform/VanillaPage.ui
+++ b/application/pages/modplatform/VanillaPage.ui
@@ -99,6 +99,16 @@
</widget>
</item>
<item>
+ <widget class="QCheckBox" name="experimentsFilter">
+ <property name="text">
+ <string>Experiments</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -144,6 +154,16 @@
<container>1</container>
</customwidget>
</customwidgets>
+ <tabstops>
+ <tabstop>tabWidget</tabstop>
+ <tabstop>releaseFilter</tabstop>
+ <tabstop>snapshotFilter</tabstop>
+ <tabstop>oldSnapshotFilter</tabstop>
+ <tabstop>betaFilter</tabstop>
+ <tabstop>alphaFilter</tabstop>
+ <tabstop>experimentsFilter</tabstop>
+ <tabstop>refreshBtn</tabstop>
+ </tabstops>
<resources/>
<connections/>
</ui>