From bb7e8985f6d189de0acac6a1c3033cb16378c1fb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 4 Nov 2013 02:53:05 +0100 Subject: Reformat and (slightly) decruft all the things. --- gui/ConsoleWindow.cpp | 135 +++++ gui/ConsoleWindow.h | 79 +++ gui/ConsoleWindow.ui | 85 ++++ gui/CopyInstanceDialog.cpp | 84 ---- gui/CopyInstanceDialog.h | 50 -- gui/CopyInstanceDialog.ui | 134 ----- gui/CustomMessageBox.cpp | 19 - gui/CustomMessageBox.h | 11 - gui/EditNotesDialog.cpp | 29 -- gui/EditNotesDialog.h | 20 - gui/EditNotesDialog.ui | 77 --- gui/IconPickerDialog.cpp | 147 ------ gui/IconPickerDialog.h | 29 -- gui/IconPickerDialog.ui | 67 --- gui/LabeledToolButton.cpp | 72 --- gui/LabeledToolButton.h | 22 - gui/LegacyModEditDialog.cpp | 393 --------------- gui/LegacyModEditDialog.h | 78 --- gui/LegacyModEditDialog.ui | 321 ------------ gui/MCModInfoFrame.cpp | 109 ---- gui/MCModInfoFrame.h | 46 -- gui/MCModInfoFrame.ui | 68 --- gui/MainWindow.cpp | 976 ++++++++++++++++++++++++++++++++++++ gui/MainWindow.h | 167 ++++++ gui/MainWindow.ui | 474 +++++++++++++++++ gui/ModEditDialogCommon.cpp | 41 -- gui/ModEditDialogCommon.h | 7 - gui/ModListView.cpp | 36 -- gui/ModListView.h | 13 - gui/OneSixModEditDialog.cpp | 317 ------------ gui/OneSixModEditDialog.h | 67 --- gui/OneSixModEditDialog.ui | 319 ------------ gui/Platform.h | 32 ++ gui/Platform_Other.cpp | 27 + gui/Platform_X11.cpp | 62 +++ gui/ProgressDialog.cpp | 110 ---- gui/ProgressDialog.h | 62 --- gui/ProgressDialog.ui | 53 -- gui/aboutdialog.cpp | 24 - gui/aboutdialog.h | 22 - gui/aboutdialog.ui | 315 ------------ gui/consolewindow.cpp | 120 ----- gui/consolewindow.h | 63 --- gui/consolewindow.ui | 85 ---- gui/dialogs/AboutDialog.cpp | 37 ++ gui/dialogs/AboutDialog.h | 35 ++ gui/dialogs/AboutDialog.ui | 316 ++++++++++++ gui/dialogs/CopyInstanceDialog.cpp | 84 ++++ gui/dialogs/CopyInstanceDialog.h | 50 ++ gui/dialogs/CopyInstanceDialog.ui | 134 +++++ gui/dialogs/CustomMessageBox.cpp | 34 ++ gui/dialogs/CustomMessageBox.h | 26 + gui/dialogs/EditNotesDialog.cpp | 42 ++ gui/dialogs/EditNotesDialog.h | 38 ++ gui/dialogs/EditNotesDialog.ui | 77 +++ gui/dialogs/IconPickerDialog.cpp | 156 ++++++ gui/dialogs/IconPickerDialog.h | 48 ++ gui/dialogs/IconPickerDialog.ui | 67 +++ gui/dialogs/InstanceSettings.cpp | 180 +++++++ gui/dialogs/InstanceSettings.h | 50 ++ gui/dialogs/InstanceSettings.ui | 422 ++++++++++++++++ gui/dialogs/LegacyModEditDialog.cpp | 393 +++++++++++++++ gui/dialogs/LegacyModEditDialog.h | 78 +++ gui/dialogs/LegacyModEditDialog.ui | 321 ++++++++++++ gui/dialogs/LoginDialog.cpp | 252 ++++++++++ gui/dialogs/LoginDialog.h | 61 +++ gui/dialogs/LoginDialog.ui | 186 +++++++ gui/dialogs/LwjglSelectDialog.cpp | 72 +++ gui/dialogs/LwjglSelectDialog.h | 44 ++ gui/dialogs/LwjglSelectDialog.ui | 85 ++++ gui/dialogs/ModEditDialogCommon.cpp | 57 +++ gui/dialogs/ModEditDialogCommon.h | 22 + gui/dialogs/NewInstanceDialog.cpp | 125 +++++ gui/dialogs/NewInstanceDialog.h | 55 ++ gui/dialogs/NewInstanceDialog.ui | 179 +++++++ gui/dialogs/OneSixModEditDialog.cpp | 322 ++++++++++++ gui/dialogs/OneSixModEditDialog.h | 67 +++ gui/dialogs/OneSixModEditDialog.ui | 319 ++++++++++++ gui/dialogs/ProgressDialog.cpp | 107 ++++ gui/dialogs/ProgressDialog.h | 60 +++ gui/dialogs/ProgressDialog.ui | 53 ++ gui/dialogs/SettingsDialog.cpp | 260 ++++++++++ gui/dialogs/SettingsDialog.h | 63 +++ gui/dialogs/SettingsDialog.ui | 569 +++++++++++++++++++++ gui/dialogs/VersionSelectDialog.cpp | 111 ++++ gui/dialogs/VersionSelectDialog.h | 61 +++ gui/dialogs/VersionSelectDialog.ui | 103 ++++ gui/instancedelegate.cpp | 231 --------- gui/instancedelegate.h | 12 - gui/instancesettings.cpp | 189 ------- gui/instancesettings.h | 35 -- gui/instancesettings.ui | 422 ---------------- gui/logindialog.cpp | 248 --------- gui/logindialog.h | 57 --- gui/logindialog.ui | 185 ------- gui/lwjglselectdialog.cpp | 72 --- gui/lwjglselectdialog.h | 46 -- gui/lwjglselectdialog.ui | 85 ---- gui/mainwindow.cpp | 974 ----------------------------------- gui/mainwindow.h | 170 ------- gui/mainwindow.ui | 474 ----------------- gui/newinstancedialog.cpp | 125 ----- gui/newinstancedialog.h | 55 -- gui/newinstancedialog.ui | 179 ------- gui/newmodeditwindow.ui | 159 ------ gui/platform.h | 35 -- gui/platform_other.cpp | 27 - gui/platform_x11.cpp | 62 --- gui/settingsdialog.cpp | 256 ---------- gui/settingsdialog.h | 64 --- gui/settingsdialog.ui | 569 --------------------- gui/versionselectdialog.cpp | 110 ---- gui/versionselectdialog.h | 61 --- gui/versionselectdialog.ui | 103 ---- gui/widgets/InstanceDelegate.cpp | 246 +++++++++ gui/widgets/InstanceDelegate.h | 27 + gui/widgets/LabeledToolButton.cpp | 86 ++++ gui/widgets/LabeledToolButton.h | 37 ++ gui/widgets/MCModInfoFrame.cpp | 111 ++++ gui/widgets/MCModInfoFrame.h | 46 ++ gui/widgets/MCModInfoFrame.ui | 68 +++ gui/widgets/ModListView.cpp | 51 ++ gui/widgets/ModListView.h | 27 + 123 files changed, 8557 insertions(+), 8435 deletions(-) create mode 100644 gui/ConsoleWindow.cpp create mode 100644 gui/ConsoleWindow.h create mode 100644 gui/ConsoleWindow.ui delete mode 100644 gui/CopyInstanceDialog.cpp delete mode 100644 gui/CopyInstanceDialog.h delete mode 100644 gui/CopyInstanceDialog.ui delete mode 100644 gui/CustomMessageBox.cpp delete mode 100644 gui/CustomMessageBox.h delete mode 100644 gui/EditNotesDialog.cpp delete mode 100644 gui/EditNotesDialog.h delete mode 100644 gui/EditNotesDialog.ui delete mode 100644 gui/IconPickerDialog.cpp delete mode 100644 gui/IconPickerDialog.h delete mode 100644 gui/IconPickerDialog.ui delete mode 100644 gui/LabeledToolButton.cpp delete mode 100644 gui/LabeledToolButton.h delete mode 100644 gui/LegacyModEditDialog.cpp delete mode 100644 gui/LegacyModEditDialog.h delete mode 100644 gui/LegacyModEditDialog.ui delete mode 100644 gui/MCModInfoFrame.cpp delete mode 100644 gui/MCModInfoFrame.h delete mode 100644 gui/MCModInfoFrame.ui create mode 100644 gui/MainWindow.cpp create mode 100644 gui/MainWindow.h create mode 100644 gui/MainWindow.ui delete mode 100644 gui/ModEditDialogCommon.cpp delete mode 100644 gui/ModEditDialogCommon.h delete mode 100644 gui/ModListView.cpp delete mode 100644 gui/ModListView.h delete mode 100644 gui/OneSixModEditDialog.cpp delete mode 100644 gui/OneSixModEditDialog.h delete mode 100644 gui/OneSixModEditDialog.ui create mode 100644 gui/Platform.h create mode 100644 gui/Platform_Other.cpp create mode 100644 gui/Platform_X11.cpp delete mode 100644 gui/ProgressDialog.cpp delete mode 100644 gui/ProgressDialog.h delete mode 100644 gui/ProgressDialog.ui delete mode 100644 gui/aboutdialog.cpp delete mode 100644 gui/aboutdialog.h delete mode 100644 gui/aboutdialog.ui delete mode 100644 gui/consolewindow.cpp delete mode 100644 gui/consolewindow.h delete mode 100644 gui/consolewindow.ui create mode 100644 gui/dialogs/AboutDialog.cpp create mode 100644 gui/dialogs/AboutDialog.h create mode 100644 gui/dialogs/AboutDialog.ui create mode 100644 gui/dialogs/CopyInstanceDialog.cpp create mode 100644 gui/dialogs/CopyInstanceDialog.h create mode 100644 gui/dialogs/CopyInstanceDialog.ui create mode 100644 gui/dialogs/CustomMessageBox.cpp create mode 100644 gui/dialogs/CustomMessageBox.h create mode 100644 gui/dialogs/EditNotesDialog.cpp create mode 100644 gui/dialogs/EditNotesDialog.h create mode 100644 gui/dialogs/EditNotesDialog.ui create mode 100644 gui/dialogs/IconPickerDialog.cpp create mode 100644 gui/dialogs/IconPickerDialog.h create mode 100644 gui/dialogs/IconPickerDialog.ui create mode 100644 gui/dialogs/InstanceSettings.cpp create mode 100644 gui/dialogs/InstanceSettings.h create mode 100644 gui/dialogs/InstanceSettings.ui create mode 100644 gui/dialogs/LegacyModEditDialog.cpp create mode 100644 gui/dialogs/LegacyModEditDialog.h create mode 100644 gui/dialogs/LegacyModEditDialog.ui create mode 100644 gui/dialogs/LoginDialog.cpp create mode 100644 gui/dialogs/LoginDialog.h create mode 100644 gui/dialogs/LoginDialog.ui create mode 100644 gui/dialogs/LwjglSelectDialog.cpp create mode 100644 gui/dialogs/LwjglSelectDialog.h create mode 100644 gui/dialogs/LwjglSelectDialog.ui create mode 100644 gui/dialogs/ModEditDialogCommon.cpp create mode 100644 gui/dialogs/ModEditDialogCommon.h create mode 100644 gui/dialogs/NewInstanceDialog.cpp create mode 100644 gui/dialogs/NewInstanceDialog.h create mode 100644 gui/dialogs/NewInstanceDialog.ui create mode 100644 gui/dialogs/OneSixModEditDialog.cpp create mode 100644 gui/dialogs/OneSixModEditDialog.h create mode 100644 gui/dialogs/OneSixModEditDialog.ui create mode 100644 gui/dialogs/ProgressDialog.cpp create mode 100644 gui/dialogs/ProgressDialog.h create mode 100644 gui/dialogs/ProgressDialog.ui create mode 100644 gui/dialogs/SettingsDialog.cpp create mode 100644 gui/dialogs/SettingsDialog.h create mode 100644 gui/dialogs/SettingsDialog.ui create mode 100644 gui/dialogs/VersionSelectDialog.cpp create mode 100644 gui/dialogs/VersionSelectDialog.h create mode 100644 gui/dialogs/VersionSelectDialog.ui delete mode 100644 gui/instancedelegate.cpp delete mode 100644 gui/instancedelegate.h delete mode 100644 gui/instancesettings.cpp delete mode 100644 gui/instancesettings.h delete mode 100644 gui/instancesettings.ui delete mode 100644 gui/logindialog.cpp delete mode 100644 gui/logindialog.h delete mode 100644 gui/logindialog.ui delete mode 100644 gui/lwjglselectdialog.cpp delete mode 100644 gui/lwjglselectdialog.h delete mode 100644 gui/lwjglselectdialog.ui delete mode 100644 gui/mainwindow.cpp delete mode 100644 gui/mainwindow.h delete mode 100644 gui/mainwindow.ui delete mode 100644 gui/newinstancedialog.cpp delete mode 100644 gui/newinstancedialog.h delete mode 100644 gui/newinstancedialog.ui delete mode 100644 gui/newmodeditwindow.ui delete mode 100644 gui/platform.h delete mode 100644 gui/platform_other.cpp delete mode 100644 gui/platform_x11.cpp delete mode 100644 gui/settingsdialog.cpp delete mode 100644 gui/settingsdialog.h delete mode 100644 gui/settingsdialog.ui delete mode 100644 gui/versionselectdialog.cpp delete mode 100644 gui/versionselectdialog.h delete mode 100644 gui/versionselectdialog.ui create mode 100644 gui/widgets/InstanceDelegate.cpp create mode 100644 gui/widgets/InstanceDelegate.h create mode 100644 gui/widgets/LabeledToolButton.cpp create mode 100644 gui/widgets/LabeledToolButton.h create mode 100644 gui/widgets/MCModInfoFrame.cpp create mode 100644 gui/widgets/MCModInfoFrame.h create mode 100644 gui/widgets/MCModInfoFrame.ui create mode 100644 gui/widgets/ModListView.cpp create mode 100644 gui/widgets/ModListView.h (limited to 'gui') diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp new file mode 100644 index 00000000..ec25b9cf --- /dev/null +++ b/gui/ConsoleWindow.cpp @@ -0,0 +1,135 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ConsoleWindow.h" +#include "ui_ConsoleWindow.h" + +#include +#include + +#include +#include + +ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : + QDialog(parent), + ui(new Ui::ConsoleWindow), + m_mayclose(true), + proc(mcproc) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + this->setWindowFlags(Qt::Window); + connect(mcproc, SIGNAL(ended(BaseInstance*)), this, SLOT(onEnded(BaseInstance*))); +} + +ConsoleWindow::~ConsoleWindow() +{ + delete ui; +} + +void ConsoleWindow::writeColor(QString text, const char *color) +{ + // append a paragraph + if (color != nullptr) + ui->text->appendHtml(QString("%2").arg(color).arg(text)); + else + ui->text->appendPlainText(text); + // scroll down + QScrollBar *bar = ui->text->verticalScrollBar(); + bar->setValue(bar->maximum()); +} + +void ConsoleWindow::write(QString data, MessageLevel::Enum mode) +{ + if (data.endsWith('\n')) + data = data.left(data.length()-1); + QStringList paragraphs = data.split('\n'); + for(QString ¶graph : paragraphs) + { + paragraph = paragraph.trimmed(); + } + + QListIterator iter(paragraphs); + if (mode == MessageLevel::MultiMC) + while(iter.hasNext()) + writeColor(iter.next(), "blue"); + else if (mode == MessageLevel::Error) + while(iter.hasNext()) + writeColor(iter.next(), "red"); + else if (mode == MessageLevel::Warning) + while(iter.hasNext()) + writeColor(iter.next(), "orange"); + else if (mode == MessageLevel::Fatal) + while(iter.hasNext()) + writeColor(iter.next(), "pink"); + else if (mode == MessageLevel::Debug) + while(iter.hasNext()) + writeColor(iter.next(), "green"); + // TODO: implement other MessageLevels + else + while(iter.hasNext()) + writeColor(iter.next()); +} + +void ConsoleWindow::clear() +{ + ui->text->clear(); +} + +void ConsoleWindow::on_closeButton_clicked() +{ + close(); +} + +void ConsoleWindow::setMayClose(bool mayclose) +{ + m_mayclose = mayclose; + if (mayclose) + ui->closeButton->setEnabled(true); + else + ui->closeButton->setEnabled(false); +} + +void ConsoleWindow::closeEvent(QCloseEvent * event) +{ + if(!m_mayclose) + event->ignore(); + else + QDialog::closeEvent(event); +} + +void ConsoleWindow::on_btnKillMinecraft_clicked() +{ + ui->btnKillMinecraft->setEnabled(false); + auto response = CustomMessageBox::selectable(this, tr("Kill Minecraft?"), + tr("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason"), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)->exec(); + if (response == QMessageBox::Yes) + proc->killMinecraft(); + else + ui->btnKillMinecraft->setEnabled(true); +} + +void ConsoleWindow::onEnded(BaseInstance *instance) +{ + ui->btnKillMinecraft->setEnabled(false); + + // TODO: Might need an option to forcefully close, even on an error + if(instance->settings().get("AutoCloseConsole").toBool()) + { + // TODO: Check why this doesn't work + if (!proc->exitCode()) this->close(); + } +} diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h new file mode 100644 index 00000000..0ed35554 --- /dev/null +++ b/gui/ConsoleWindow.h @@ -0,0 +1,79 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "logic/MinecraftProcess.h" + +namespace Ui +{ +class ConsoleWindow; +} + +class ConsoleWindow : public QDialog +{ + Q_OBJECT + +public: + explicit ConsoleWindow(MinecraftProcess *proc, QWidget *parent = 0); + ~ConsoleWindow(); + + /** + * @brief specify if the window is allowed to close + * @param mayclose + * used to keep it alive while MC runs + */ + void setMayClose(bool mayclose); + +public +slots: + /** + * @brief write a string + * @param data the string + * @param mode the WriteMode + * lines have to be put through this as a whole! + */ + void write(QString data, MessageLevel::Enum level = MessageLevel::MultiMC); + + /** + * @brief write a colored paragraph + * @param data the string + * @param color the css color name + * this will only insert a single paragraph. + * \n are ignored. a real \n is always appended. + */ + void writeColor(QString data, const char *color = nullptr); + + /** + * @brief clear the text widget + */ + void clear(); + +private +slots: + void on_closeButton_clicked(); + void on_btnKillMinecraft_clicked(); + void onEnded(BaseInstance *instance); + +protected: + void closeEvent(QCloseEvent *); + +private: + Ui::ConsoleWindow *ui; + MinecraftProcess *proc; + bool m_mayclose; +}; + diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui new file mode 100644 index 00000000..8dc80015 --- /dev/null +++ b/gui/ConsoleWindow.ui @@ -0,0 +1,85 @@ + + + ConsoleWindow + + + + 0 + 0 + 600 + 400 + + + + MultiMC Console + + + + 0 + + + 0 + + + 0 + + + + + + 10 + + + + false + + + true + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + false + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Kill Minecraft + + + + + + + Close + + + + + + + + + + diff --git a/gui/CopyInstanceDialog.cpp b/gui/CopyInstanceDialog.cpp deleted file mode 100644 index 1e0b9e6c..00000000 --- a/gui/CopyInstanceDialog.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "CopyInstanceDialog.h" -#include "ui_CopyInstanceDialog.h" - -#include "logic/InstanceFactory.h" -#include "logic/BaseVersion.h" -#include "logic/lists/IconList.h" -#include "logic/lists/MinecraftVersionList.h" -#include "logic/tasks/Task.h" -#include - -#include "gui/platform.h" -#include "versionselectdialog.h" -#include "ProgressDialog.h" -#include "IconPickerDialog.h" - -#include -#include - -CopyInstanceDialog::CopyInstanceDialog(BaseInstance *original, QWidget *parent) - : m_original(original), QDialog(parent), ui(new Ui::CopyInstanceDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - resize(minimumSizeHint()); - layout()->setSizeConstraint(QLayout::SetFixedSize); - - InstIconKey = original->iconKey(); - ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); - ui->instNameTextBox->setText(original->name()); - ui->instNameTextBox->setFocus(); -} - -CopyInstanceDialog::~CopyInstanceDialog() -{ - delete ui; -} - -void CopyInstanceDialog::updateDialogState() -{ - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty()); -} - -QString CopyInstanceDialog::instName() const -{ - return ui->instNameTextBox->text(); -} - -QString CopyInstanceDialog::iconKey() const -{ - return InstIconKey; -} - -void CopyInstanceDialog::on_iconButton_clicked() -{ - IconPickerDialog dlg(this); - dlg.exec(InstIconKey); - - if (dlg.result() == QDialog::Accepted) - { - InstIconKey = dlg.selectedIconKey; - ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); - } -} - -void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) -{ - updateDialogState(); -} diff --git a/gui/CopyInstanceDialog.h b/gui/CopyInstanceDialog.h deleted file mode 100644 index 7ab366e2..00000000 --- a/gui/CopyInstanceDialog.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "logic/BaseVersion.h" - -class BaseInstance; - -namespace Ui -{ -class CopyInstanceDialog; -} - -class CopyInstanceDialog : public QDialog -{ - Q_OBJECT - -public: - explicit CopyInstanceDialog(BaseInstance *original, QWidget *parent = 0); - ~CopyInstanceDialog(); - - void updateDialogState(); - - QString instName() const; - QString iconKey() const; - -private -slots: - void on_iconButton_clicked(); - void on_instNameTextBox_textChanged(const QString &arg1); - -private: - Ui::CopyInstanceDialog *ui; - QString InstIconKey; - BaseInstance *m_original; -}; diff --git a/gui/CopyInstanceDialog.ui b/gui/CopyInstanceDialog.ui deleted file mode 100644 index 1327ce0b..00000000 --- a/gui/CopyInstanceDialog.ui +++ /dev/null @@ -1,134 +0,0 @@ - - - CopyInstanceDialog - - - Qt::ApplicationModal - - - - 0 - 0 - 345 - 205 - - - - Copy Instance - - - - :/icons/toolbar/copy:/icons/toolbar/copy - - - true - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - :/icons/instances/infinity:/icons/instances/infinity - - - - 80 - 80 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Name - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - buttonBox - accepted() - CopyInstanceDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - CopyInstanceDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/CustomMessageBox.cpp b/gui/CustomMessageBox.cpp deleted file mode 100644 index e55ebbbb..00000000 --- a/gui/CustomMessageBox.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "CustomMessageBox.h" - -namespace CustomMessageBox -{ - QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text, - QMessageBox::Icon icon, QMessageBox::StandardButtons buttons, - QMessageBox::StandardButton defaultButton) - { - QMessageBox *messageBox = new QMessageBox(parent); - messageBox->setWindowTitle(title); - messageBox->setText(text); - messageBox->setStandardButtons(buttons); - messageBox->setDefaultButton(defaultButton); - messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); - messageBox->setIcon(icon); - - return messageBox; - } -} diff --git a/gui/CustomMessageBox.h b/gui/CustomMessageBox.h deleted file mode 100644 index 145651ec..00000000 --- a/gui/CustomMessageBox.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -namespace CustomMessageBox -{ - QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text, - QMessageBox::Icon icon = QMessageBox::NoIcon, - QMessageBox::StandardButtons buttons = QMessageBox::Ok, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); -} diff --git a/gui/EditNotesDialog.cpp b/gui/EditNotesDialog.cpp deleted file mode 100644 index 535ca804..00000000 --- a/gui/EditNotesDialog.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "EditNotesDialog.h" -#include "ui_EditNotesDialog.h" -#include "gui/platform.h" - -#include -#include - -EditNotesDialog::EditNotesDialog( QString notes, QString name, QWidget* parent ) : - m_instance_notes(notes), - m_instance_name(name), - QDialog(parent), - ui(new Ui::EditNotesDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - ui->noteEditor->setText(notes); - setWindowTitle(tr("Edit notes of %1").arg(m_instance_name)); - //connect(ui->closeButton, SIGNAL(clicked()), SLOT(close())); -} - -EditNotesDialog::~EditNotesDialog() -{ - delete ui; -} - -QString EditNotesDialog::getText() -{ - return ui->noteEditor->toPlainText(); -} diff --git a/gui/EditNotesDialog.h b/gui/EditNotesDialog.h deleted file mode 100644 index 582e019f..00000000 --- a/gui/EditNotesDialog.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include - -namespace Ui { -class EditNotesDialog; -} - -class EditNotesDialog : public QDialog -{ - Q_OBJECT - -public: - explicit EditNotesDialog(QString notes, QString name, QWidget *parent = 0); - ~EditNotesDialog(); - QString getText(); -private: - Ui::EditNotesDialog *ui; - QString m_instance_name; - QString m_instance_notes; -}; diff --git a/gui/EditNotesDialog.ui b/gui/EditNotesDialog.ui deleted file mode 100644 index 487dfb84..00000000 --- a/gui/EditNotesDialog.ui +++ /dev/null @@ -1,77 +0,0 @@ - - - EditNotesDialog - - - - 0 - 0 - 459 - 399 - - - - Edit Notes - - - - - - Qt::ScrollBarAlwaysOn - - - false - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - EditNotesDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - EditNotesDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/IconPickerDialog.cpp b/gui/IconPickerDialog.cpp deleted file mode 100644 index ebacf87c..00000000 --- a/gui/IconPickerDialog.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include "IconPickerDialog.h" -#include "instancedelegate.h" -#include "ui_IconPickerDialog.h" -#include "logic/lists/IconList.h" -#include "gui/platform.h" -#include -#include -#include - -IconPickerDialog::IconPickerDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::IconPickerDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - setWindowModality(Qt::WindowModal); - - auto contentsWidget = ui->iconView; - contentsWidget->setViewMode(QListView::IconMode); - contentsWidget->setFlow(QListView::LeftToRight); - contentsWidget->setIconSize(QSize(48, 48)); - contentsWidget->setMovement(QListView::Static); - contentsWidget->setResizeMode(QListView::Adjust); - contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection); - contentsWidget->setSpacing(5); - contentsWidget->setWordWrap(false); - contentsWidget->setWrapping(true); - contentsWidget->setUniformItemSizes(true); - contentsWidget->setTextElideMode(Qt::ElideRight); - contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); - contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - contentsWidget->setItemDelegate(new ListViewDelegate()); - - //contentsWidget->setAcceptDrops(true); - contentsWidget->setDropIndicatorShown(true); - contentsWidget->viewport()->setAcceptDrops(true); - contentsWidget->setDragDropMode(QAbstractItemView::DropOnly); - contentsWidget->setDefaultDropAction(Qt::CopyAction); - - contentsWidget->installEventFilter(this); - - contentsWidget->setModel(MMC->icons().get()); - - auto buttonAdd = ui->buttonBox->addButton(tr("Add Icon"),QDialogButtonBox::ResetRole); - auto buttonRemove = ui->buttonBox->addButton(tr("Remove Icon"),QDialogButtonBox::ResetRole); - - - connect(buttonAdd,SIGNAL(clicked(bool)),SLOT(addNewIcon())); - connect(buttonRemove,SIGNAL(clicked(bool)),SLOT(removeSelectedIcon())); - - connect - ( - contentsWidget, - SIGNAL(doubleClicked(QModelIndex)), - SLOT(activated(QModelIndex)) - ); - - connect - ( - contentsWidget->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(selectionChanged(QItemSelection,QItemSelection)) - ); -} -bool IconPickerDialog::eventFilter ( QObject* obj, QEvent* evt) -{ - if(obj != ui->iconView) - return QDialog::eventFilter(obj ,evt); - if (evt->type() != QEvent::KeyPress) - { - return QDialog::eventFilter(obj ,evt); - } - QKeyEvent *keyEvent = static_cast(evt); - switch(keyEvent->key()) - { - case Qt::Key_Delete: - removeSelectedIcon(); - return true; - case Qt::Key_Plus: - addNewIcon(); - return true; - default: - break; - } - return QDialog::eventFilter(obj ,evt); -} - -void IconPickerDialog::addNewIcon() -{ - //: The title of the select icons open file dialog - QString selectIcons = tr("Select Icons"); - //: The type of icon files - QStringList fileNames = QFileDialog::getOpenFileNames(this, selectIcons, QString(), tr("Icons") + "(*.png *.jpg *.jpeg)"); - MMC->icons()->installIcons(fileNames); -} - -void IconPickerDialog::removeSelectedIcon() -{ - MMC->icons()->deleteIcon(selectedIconKey); -} - - -void IconPickerDialog::activated ( QModelIndex index ) -{ - selectedIconKey = index.data(Qt::UserRole).toString(); - accept(); -} - - -void IconPickerDialog::selectionChanged ( QItemSelection selected, QItemSelection deselected ) -{ - if(selected.empty()) - return; - - QString key = selected.first().indexes().first().data(Qt::UserRole).toString(); - if(!key.isEmpty()) - selectedIconKey = key; -} - -int IconPickerDialog::exec ( QString selection ) -{ - auto list = MMC->icons(); - auto contentsWidget = ui->iconView; - selectedIconKey = selection; - - - int index_nr = list->getIconIndex(selection); - auto model_index = list->index(index_nr); - contentsWidget->selectionModel()->select(model_index, QItemSelectionModel::Current | QItemSelectionModel::Select); - - QMetaObject::invokeMethod(this, "delayed_scroll", Qt::QueuedConnection, Q_ARG(QModelIndex,model_index)); - return QDialog::exec(); -} - -void IconPickerDialog::delayed_scroll ( QModelIndex model_index ) -{ - auto contentsWidget = ui->iconView; - contentsWidget->scrollTo(model_index); -} - - -IconPickerDialog::~IconPickerDialog() -{ - delete ui; -} diff --git a/gui/IconPickerDialog.h b/gui/IconPickerDialog.h deleted file mode 100644 index 96fc61ff..00000000 --- a/gui/IconPickerDialog.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include - -namespace Ui { -class IconPickerDialog; -} - -class IconPickerDialog : public QDialog -{ - Q_OBJECT - -public: - explicit IconPickerDialog(QWidget *parent = 0); - ~IconPickerDialog(); - int exec(QString selection); - QString selectedIconKey; -protected: - virtual bool eventFilter ( QObject* , QEvent* ); -private: - Ui::IconPickerDialog *ui; - -private slots: - void selectionChanged ( QItemSelection,QItemSelection ); - void activated ( QModelIndex ); - void delayed_scroll ( QModelIndex ); - void addNewIcon(); - void removeSelectedIcon(); -}; diff --git a/gui/IconPickerDialog.ui b/gui/IconPickerDialog.ui deleted file mode 100644 index c548edfb..00000000 --- a/gui/IconPickerDialog.ui +++ /dev/null @@ -1,67 +0,0 @@ - - - IconPickerDialog - - - - 0 - 0 - 676 - 555 - - - - Pick icon - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - IconPickerDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - IconPickerDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/LabeledToolButton.cpp b/gui/LabeledToolButton.cpp deleted file mode 100644 index be84d1b7..00000000 --- a/gui/LabeledToolButton.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include "LabeledToolButton.h" -#include - - -/* - * - * Tool Button with a label on it, instead of the normal text rendering - * - */ - -LabeledToolButton::LabeledToolButton(QWidget * parent) - : QToolButton(parent) - , m_label(new QLabel(this)) -{ - //QToolButton::setText(" "); - m_label->setWordWrap(true); - m_label->setMouseTracking(false); - m_label->setAlignment(Qt::AlignCenter); - m_label->setTextInteractionFlags(Qt::NoTextInteraction); - // somehow, this makes word wrap work in the QLabel. yay. - m_label->setMinimumWidth(100); -} - -QString LabeledToolButton::text() const -{ - return m_label->text(); -} - -void LabeledToolButton::setText(const QString & text) -{ - m_label->setText(text); -} - -/*! - \reimp -*/ -QSize LabeledToolButton::sizeHint() const -{ - /* - Q_D(const QToolButton); - if (d->sizeHint.isValid()) - return d->sizeHint; - */ - ensurePolished(); - - int w = 0, h = 0; - QStyleOptionToolButton opt; - initStyleOption(&opt); - QSize sz =m_label->sizeHint(); - w = sz.width(); - h = sz.height(); - - opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height - if (popupMode() == MenuButtonPopup) - w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); - - QSize rawSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this); - QSize sizeHint = rawSize.expandedTo(QApplication::globalStrut()); - return sizeHint; -} - - - -void LabeledToolButton::resizeEvent(QResizeEvent * event) -{ - m_label->setGeometry(QRect(4, 4, width()-8, height()-8)); - QWidget::resizeEvent(event); -} diff --git a/gui/LabeledToolButton.h b/gui/LabeledToolButton.h deleted file mode 100644 index 24ef798a..00000000 --- a/gui/LabeledToolButton.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include - -class QLabel; - -class LabeledToolButton : public QToolButton -{ - Q_OBJECT - - QLabel * m_label; - -public: - LabeledToolButton(QWidget * parent = 0); - - QString text() const; - void setText(const QString & text); - virtual QSize sizeHint() const; -protected: - void resizeEvent(QResizeEvent * event); -}; diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp deleted file mode 100644 index a7021bf9..00000000 --- a/gui/LegacyModEditDialog.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MultiMC.h" -#include "LegacyModEditDialog.h" -#include "ModEditDialogCommon.h" -#include "versionselectdialog.h" -#include "ProgressDialog.h" -#include "ui_LegacyModEditDialog.h" -#include "logic/ModList.h" -#include "logic/lists/ForgeVersionList.h" -#include "gui/platform.h" - -#include -#include -//#include -#include -#include -#include - -LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) - : m_inst(inst), QDialog(parent), ui(new Ui::LegacyModEditDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - - // Jar mods - { - ensureFolderPathExists(m_inst->jarModsDir()); - m_jarmods = m_inst->jarModList(); - ui->jarModsTreeView->setModel(m_jarmods.get()); -#ifndef Q_OS_LINUX - // FIXME: internal DnD causes segfaults later - ui->jarModsTreeView->setDragDropMode(QAbstractItemView::DragDrop); - // FIXME: DnD is glitched with contiguous (we move only first item in selection) - ui->jarModsTreeView->setSelectionMode(QAbstractItemView::SingleSelection); -#endif - ui->jarModsTreeView->installEventFilter(this); - m_jarmods->startWatching(); - auto smodel = ui->jarModsTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(jarCurrent(QModelIndex, QModelIndex))); - } - // Core mods - { - ensureFolderPathExists(m_inst->coreModsDir()); - m_coremods = m_inst->coreModList(); - ui->coreModsTreeView->setModel(m_coremods.get()); - ui->coreModsTreeView->installEventFilter(this); - m_coremods->startWatching(); - auto smodel = ui->coreModsTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(coreCurrent(QModelIndex, QModelIndex))); - } - // Loader mods - { - ensureFolderPathExists(m_inst->loaderModsDir()); - m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.get()); - ui->loaderModTreeView->installEventFilter(this); - m_mods->startWatching(); - auto smodel = ui->loaderModTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(loaderCurrent(QModelIndex, QModelIndex))); - } - // texture packs - { - ensureFolderPathExists(m_inst->texturePacksDir()); - m_texturepacks = m_inst->texturePackList(); - ui->texPackTreeView->setModel(m_texturepacks.get()); - ui->texPackTreeView->installEventFilter(this); - m_texturepacks->startWatching(); - } -} - -LegacyModEditDialog::~LegacyModEditDialog() -{ - m_mods->stopWatching(); - m_coremods->stopWatching(); - m_jarmods->stopWatching(); - m_texturepacks->stopWatching(); - delete ui; -} - -bool LegacyModEditDialog::coreListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmCoreBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addCoreBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); -} - -bool LegacyModEditDialog::jarListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Up: - { - if (keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarUpBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Down: - { - if (keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarDownBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Delete: - on_rmJarBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addJarBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->jarModsTreeView, keyEvent); -} - -bool LegacyModEditDialog::loaderListFilter(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 QDialog::eventFilter(ui->loaderModTreeView, keyEvent); -} - -bool LegacyModEditDialog::texturePackListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmTexPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addTexPackBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->texPackTreeView, keyEvent); -} - -bool LegacyModEditDialog::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QDialog::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->jarModsTreeView) - return jarListFilter(keyEvent); - if (obj == ui->coreModsTreeView) - return coreListFilter(keyEvent); - if (obj == ui->loaderModTreeView) - return loaderListFilter(keyEvent); - if (obj == ui->texPackTreeView) - return texturePackListFilter(keyEvent); - return QDialog::eventFilter(obj, ev); -} - -void LegacyModEditDialog::on_addCoreBtn_clicked() -{ - //: Title of core mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); - for (auto filename : fileNames) - { - m_coremods->stopWatching(); - m_coremods->installMod(QFileInfo(filename)); - m_coremods->startWatching(); - } -} -void LegacyModEditDialog::on_addForgeBtn_clicked() -{ - VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); - vselect.setFilter(1, m_inst->intendedVersionId()); - if (vselect.exec() && vselect.selectedVersion()) - { - ForgeVersionPtr forge = - std::dynamic_pointer_cast(vselect.selectedVersion()); - if (!forge) - return; - auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); - if (entry->stale) - { - NetJob *fjob = new NetJob("Forge download"); - fjob->addNetAction(CacheDownload::make(forge->universal_url, entry)); - ProgressDialog dlg(this); - dlg.exec(fjob); - if (dlg.result() == QDialog::Accepted) - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(entry->getFullPath())); - m_jarmods->startWatching(); - } - else - { - // failed to download forge :/ - } - } - else - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(entry->getFullPath())); - m_jarmods->startWatching(); - } - } -} -void LegacyModEditDialog::on_addJarBtn_clicked() -{ - //: Title of jar mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Jar Mods")); - for (auto filename : fileNames) - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(filename)); - m_jarmods->startWatching(); - } -} -void LegacyModEditDialog::on_addModBtn_clicked() -{ - //: Title of regular mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Loader Mods")); - for (auto filename : fileNames) - { - m_mods->stopWatching(); - m_mods->installMod(QFileInfo(filename)); - m_mods->startWatching(); - } -} -void LegacyModEditDialog::on_addTexPackBtn_clicked() -{ - //: Title of texture pack selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Texture Packs")); - for (auto filename : fileNames) - { - m_texturepacks->stopWatching(); - m_texturepacks->installMod(QFileInfo(filename)); - m_texturepacks->startWatching(); - } -} - -void LegacyModEditDialog::on_moveJarDownBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - - m_jarmods->moveModsDown(first, last); -} -void LegacyModEditDialog::on_moveJarUpBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_jarmods->moveModsUp(first, last); -} -void LegacyModEditDialog::on_rmCoreBtn_clicked() -{ - int first, last; - auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_coremods->stopWatching(); - m_coremods->deleteMods(first, last); - m_coremods->startWatching(); -} -void LegacyModEditDialog::on_rmJarBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_jarmods->stopWatching(); - m_jarmods->deleteMods(first, last); - m_jarmods->startWatching(); -} -void LegacyModEditDialog::on_rmModBtn_clicked() -{ - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_mods->stopWatching(); - m_mods->deleteMods(first, last); - m_mods->startWatching(); -} -void LegacyModEditDialog::on_rmTexPackBtn_clicked() -{ - int first, last; - auto list = ui->texPackTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_texturepacks->stopWatching(); - m_texturepacks->deleteMods(first, last); - m_texturepacks->startWatching(); -} -void LegacyModEditDialog::on_viewCoreBtn_clicked() -{ - openDirInDefaultProgram(m_inst->coreModsDir(), true); -} -void LegacyModEditDialog::on_viewModBtn_clicked() -{ - openDirInDefaultProgram(m_inst->loaderModsDir(), true); -} -void LegacyModEditDialog::on_viewTexPackBtn_clicked() -{ - openDirInDefaultProgram(m_inst->texturePacksDir(), true); -} - -void LegacyModEditDialog::on_buttonBox_rejected() -{ - close(); -} - -void LegacyModEditDialog::jarCurrent(QModelIndex current, QModelIndex previous) -{ - if(!current.isValid()) - { - ui->jarMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_jarmods->operator[](row); - ui->jarMIFrame->updateWithMod(m); -} - -void LegacyModEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) -{ - if(!current.isValid()) - { - ui->coreMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_coremods->operator[](row); - ui->coreMIFrame->updateWithMod(m); -} - -void LegacyModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) -{ - if(!current.isValid()) - { - ui->loaderMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_mods->operator[](row); - ui->loaderMIFrame->updateWithMod(m); -} diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h deleted file mode 100644 index d5582aef..00000000 --- a/gui/LegacyModEditDialog.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "logic/LegacyInstance.h" -#include - -namespace Ui -{ -class LegacyModEditDialog; -} - -class LegacyModEditDialog : public QDialog -{ - Q_OBJECT - -public: - explicit LegacyModEditDialog(LegacyInstance *inst, QWidget *parent = 0); - ~LegacyModEditDialog(); - -private -slots: - - void on_addJarBtn_clicked(); - void on_rmJarBtn_clicked(); - void on_addForgeBtn_clicked(); - void on_moveJarUpBtn_clicked(); - void on_moveJarDownBtn_clicked(); - - void on_addCoreBtn_clicked(); - void on_rmCoreBtn_clicked(); - void on_viewCoreBtn_clicked(); - - void on_addModBtn_clicked(); - void on_rmModBtn_clicked(); - void on_viewModBtn_clicked(); - - void on_addTexPackBtn_clicked(); - void on_rmTexPackBtn_clicked(); - void on_viewTexPackBtn_clicked(); - - // Questionable: SettingsDialog doesn't need this for some reason? - void on_buttonBox_rejected(); - - void jarCurrent(QModelIndex current, QModelIndex previous); - void coreCurrent(QModelIndex current, QModelIndex previous); - void loaderCurrent(QModelIndex current, QModelIndex previous); - -protected: - bool eventFilter(QObject *obj, QEvent *ev); - bool jarListFilter(QKeyEvent *ev); - bool coreListFilter(QKeyEvent *ev); - bool loaderListFilter(QKeyEvent *ev); - bool texturePackListFilter(QKeyEvent *ev); - -private: - Ui::LegacyModEditDialog *ui; - std::shared_ptr m_mods; - std::shared_ptr m_coremods; - std::shared_ptr m_jarmods; - std::shared_ptr m_texturepacks; - LegacyInstance *m_inst; - NetJobPtr forgeJob; -}; diff --git a/gui/LegacyModEditDialog.ui b/gui/LegacyModEditDialog.ui deleted file mode 100644 index bb0d9ef2..00000000 --- a/gui/LegacyModEditDialog.ui +++ /dev/null @@ -1,321 +0,0 @@ - - - LegacyModEditDialog - - - - 0 - 0 - 540 - 420 - - - - Dialog - - - - - - 0 - - - - Jar Mods - - - - - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - MCForge - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Move &Up - - - - - - - Move &Down - - - - - - - - - - - QFrame::Plain - - - - - - - - Core Mods - - - - - - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - Loader Mods - - - - - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - false - - - Texture Packs - - - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - - QDialogButtonBox::Close - - - - - - - - ModListView - QTreeView -
gui/ModListView.h
-
- - MCModInfoFrame - QFrame -
gui/MCModInfoFrame.h
- 1 -
-
- - -
diff --git a/gui/MCModInfoFrame.cpp b/gui/MCModInfoFrame.cpp deleted file mode 100644 index 55ef13f1..00000000 --- a/gui/MCModInfoFrame.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MCModInfoFrame.h" -#include "ui_MCModInfoFrame.h" -#include "CustomMessageBox.h" -#include -#include -void MCModInfoFrame::updateWithMod(Mod &m) -{ - if(m.type() == m.MOD_FOLDER) - { - clear(); - return; - } - - QString text = ""; - QString name = ""; - if(m.name().isEmpty()) name = m.id(); - else name = m.name(); - - if(m.homeurl().isEmpty()) text = name; - else text = "" + name + ""; - if(!m.authors().isEmpty()) text += " by " + m.authors(); - - setModText(text); - - if(m.description().isEmpty()) - { - setModDescription(tr("No description provided in mcmod.info")); - } - else - { - setModDescription(m.description()); - } -} - -void MCModInfoFrame::clear() -{ - setModText(tr("Select a mod to view title and authors...")); - setModDescription(tr("Select a mod to view description...")); -} - -MCModInfoFrame::MCModInfoFrame(QWidget *parent) : - QFrame(parent), - ui(new Ui::MCModInfoFrame) -{ - ui->setupUi(this); -} - -MCModInfoFrame::~MCModInfoFrame() -{ - delete ui; -} - -void MCModInfoFrame::setModText(QString text) -{ - ui->label_ModText->setText(text); -} - -void MCModInfoFrame::setModDescription(QString text) -{ - ui->label_ModDescription->setToolTip(""); - QString intermediatetext = text.trimmed(); - bool prev(false); - QChar rem('\n'); - QString finaltext; - finaltext.reserve(intermediatetext.size()); - foreach(const QChar& c, intermediatetext) - { - if(c == rem && prev){ - continue; - } - prev = c == rem; - finaltext += c; - } - QString labeltext; - labeltext.reserve(300); - if(finaltext.length() > 290) - { - ui->label_ModDescription->setOpenExternalLinks(false); - ui->label_ModDescription->setTextFormat(Qt::TextFormat::RichText); - desc = text; - labeltext.append("" + finaltext.left(287) + "..."); - QObject::connect(ui->label_ModDescription, &QLabel::linkActivated, this, &MCModInfoFrame::modDescEllipsisHandler); - } - else - { - ui->label_ModDescription->setTextFormat(Qt::TextFormat::PlainText); - labeltext.append(finaltext); - } - ui->label_ModDescription->setText(labeltext); -} -void MCModInfoFrame::modDescEllipsisHandler(const QString &link) -{ - CustomMessageBox::selectable(this, tr(""), desc)->show(); -} diff --git a/gui/MCModInfoFrame.h b/gui/MCModInfoFrame.h deleted file mode 100644 index 54c5d674..00000000 --- a/gui/MCModInfoFrame.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "logic/Mod.h" - -namespace Ui -{ -class MCModInfoFrame; -} - -class MCModInfoFrame : public QFrame -{ - Q_OBJECT - -public: - explicit MCModInfoFrame(QWidget *parent = 0); - ~MCModInfoFrame(); - - void setModText(QString text); - void setModDescription(QString text); - - void updateWithMod(Mod &m); - void clear(); - -public slots: - void modDescEllipsisHandler(const QString& link ); - -private: - Ui::MCModInfoFrame *ui; - QString desc; -}; diff --git a/gui/MCModInfoFrame.ui b/gui/MCModInfoFrame.ui deleted file mode 100644 index 60e0a65c..00000000 --- a/gui/MCModInfoFrame.ui +++ /dev/null @@ -1,68 +0,0 @@ - - - MCModInfoFrame - - - - 0 - 0 - 527 - 113 - - - - - 0 - 0 - - - - - 16777215 - 120 - - - - Frame - - - - - - Select a mod to view title and authors... - - - Qt::RichText - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - true - - - - - - - Select a mod to view description... - - - Qt::PlainText - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp new file mode 100644 index 00000000..39e6dff2 --- /dev/null +++ b/gui/MainWindow.cpp @@ -0,0 +1,976 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Andrew Okin + * Peterix + * Orochimarufan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "MultiMC.h" + +#include "MainWindow.h" +#include "ui_MainWindow.h" +#include "keyring.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "osutils.h" +#include "userutils.h" +#include "pathutils.h" + +#include "categorizedview.h" +#include "categorydrawer.h" + +#include "gui/Platform.h" + +#include "gui/widgets/InstanceDelegate.h" +#include "gui/widgets/LabeledToolButton.h" + +#include "gui/dialogs/SettingsDialog.h" +#include "gui/dialogs/NewInstanceDialog.h" +#include "gui/dialogs/LoginDialog.h" +#include "gui/dialogs/ProgressDialog.h" +#include "gui/dialogs/AboutDialog.h" +#include "gui/dialogs/VersionSelectDialog.h" +#include "gui/dialogs/CustomMessageBox.h" +#include "gui/dialogs/LwjglSelectDialog.h" +#include "gui/dialogs/InstanceSettings.h" +#include "gui/dialogs/IconPickerDialog.h" +#include "gui/dialogs/EditNotesDialog.h" +#include "gui/dialogs/CopyInstanceDialog.h" + +#include "gui/ConsoleWindow.h" + +#include "logic/lists/InstanceList.h" +#include "logic/lists/MinecraftVersionList.h" +#include "logic/lists/LwjglVersionList.h" +#include "logic/lists/IconList.h" +#include "logic/lists/JavaVersionList.h" + +#include "logic/net/LoginTask.h" + +#include "logic/BaseInstance.h" +#include "logic/InstanceFactory.h" +#include "logic/MinecraftProcess.h" +#include "logic/OneSixAssets.h" +#include "logic/OneSixUpdate.h" +#include "logic/JavaUtils.h" +#include "logic/NagUtils.h" + +#include "logic/LegacyInstance.h" + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + setWindowTitle(QString("MultiMC %1").arg(MMC->version().toString())); + + // Set the selected instance to null + m_selectedInstance = nullptr; + // Set active instance to null. + m_activeInst = nullptr; + + // OSX magic. + setUnifiedTitleAndToolBarOnMac(true); + + // The instance action toolbar customizations + { + // disabled until we have an instance selected + ui->instanceToolBar->setEnabled(false); + + // the rename label is inside the rename tool button + renameButton = new LabeledToolButton(); + renameButton->setText("Instance Name"); + renameButton->setToolTip(ui->actionRenameInstance->toolTip()); + connect(renameButton, SIGNAL(clicked(bool)), SLOT(on_actionRenameInstance_triggered())); + ui->instanceToolBar->insertWidget(ui->actionLaunchInstance, renameButton); + ui->instanceToolBar->insertSeparator(ui->actionLaunchInstance); + renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + } + + // Create the instance list widget + { + view = new KCategorizedView(ui->centralWidget); + drawer = new KCategoryDrawer(view); + + view->setSelectionMode(QAbstractItemView::SingleSelection); + view->setCategoryDrawer(drawer); + view->setCollapsibleBlocks(true); + view->setViewMode(QListView::IconMode); + view->setFlow(QListView::LeftToRight); + view->setWordWrap(true); + view->setMouseTracking(true); + view->viewport()->setAttribute(Qt::WA_Hover); + auto delegate = new ListViewDelegate(); + view->setItemDelegate(delegate); + view->setSpacing(10); + view->setUniformItemWidths(true); + + // do not show ugly blue border on the mac + view->setAttribute(Qt::WA_MacShowFocusRect, false); + + view->installEventFilter(this); + + proxymodel = new InstanceProxyModel(this); +// proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole); + //proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole); + // proxymodel->setDynamicSortFilter ( true ); + + // FIXME: instList should be global-ish, or at least not tied to the main window... + // maybe the application itself? + proxymodel->setSourceModel(MMC->instances().get()); + proxymodel->sort(0); + view->setFrameShape(QFrame::NoFrame); + view->setModel(proxymodel); + + ui->horizontalLayout->addWidget(view); + } + // The cat background + { + bool cat_enable = MMC->settings()->get("TheCat").toBool(); + ui->actionCAT->setChecked(cat_enable); + connect(ui->actionCAT, SIGNAL(toggled(bool)), SLOT(onCatToggled(bool))); + setCatBackground(cat_enable); + } + // start instance when double-clicked + connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, + SLOT(instanceActivated(const QModelIndex &))); + // track the selection -- update the instance toolbar + connect(view->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, + SLOT(instanceChanged(const QModelIndex &, const QModelIndex &))); + // model reset -> selection is invalid. All the instance pointers are wrong. + // FIXME: stop using POINTERS everywhere + connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad())); + + m_statusLeft = new QLabel(tr("Instance type"), this); + m_statusRight = new QLabel(tr("Assets information"), this); + m_statusRight->setAlignment(Qt::AlignRight); + statusBar()->addPermanentWidget(m_statusLeft, 1); + statusBar()->addPermanentWidget(m_statusRight, 0); + + // run the things that load and download other things... FIXME: this is NOT the place + // FIXME: invisible actions in the background = NOPE. + { + if (!MMC->minecraftlist()->isLoaded()) + { + m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); + startTask(m_versionLoadTask); + } + if (!MMC->lwjgllist()->isLoaded()) + { + MMC->lwjgllist()->loadList(); + } + assets_downloader = new OneSixAssets(); + connect(assets_downloader, SIGNAL(indexStarted()), SLOT(assetsIndexStarted())); + connect(assets_downloader, SIGNAL(filesStarted()), SLOT(assetsFilesStarted())); + connect(assets_downloader, SIGNAL(filesProgress(int, int, int)), + SLOT(assetsFilesProgress(int, int, int))); + connect(assets_downloader, SIGNAL(failed()), SLOT(assetsFailed())); + connect(assets_downloader, SIGNAL(finished()), SLOT(assetsFinished())); + assets_downloader->start(); + } +} + +MainWindow::~MainWindow() +{ + delete ui; + delete proxymodel; + delete drawer; + delete assets_downloader; +} + +bool MainWindow::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == view) + { + if (ev->type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast(ev); + switch (keyEvent->key()) + { + case Qt::Key_Enter: + case Qt::Key_Return: + on_actionLaunchInstance_triggered(); + return true; + case Qt::Key_Delete: + on_actionDeleteInstance_triggered(); + return true; + case Qt::Key_F5: + on_actionRefresh_triggered(); + return true; + case Qt::Key_F2: + on_actionRenameInstance_triggered(); + return true; + default: + break; + } + } + } + return QMainWindow::eventFilter(obj, ev); +} + +void MainWindow::onCatToggled(bool state) +{ + setCatBackground(state); + MMC->settings()->set("TheCat", state); +} + +void MainWindow::setCatBackground(bool enabled) +{ + if (enabled) + { + view->setStyleSheet("QListView" + "{" + "background-image: url(:/backgrounds/kitteh);" + "background-attachment: fixed;" + "background-clip: padding;" + "background-position: top right;" + "background-repeat: none;" + "background-color:palette(base);" + "}"); + } + else + { + view->setStyleSheet(QString()); + } +} + +void MainWindow::on_actionAddInstance_triggered() +{ + if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && + m_versionLoadTask->isRunning()) + { + QEventLoop waitLoop; + waitLoop.connect(m_versionLoadTask, SIGNAL(failed(QString)), SLOT(quit())); + waitLoop.connect(m_versionLoadTask, SIGNAL(succeeded()), SLOT(quit())); + waitLoop.exec(); + } + + NewInstanceDialog newInstDlg(this); + if (!newInstDlg.exec()) + return; + + BaseInstance *newInstance = NULL; + + QString instancesDir = MMC->settings()->get("InstanceDir").toString(); + QString instDirName = DirNameFromString(newInstDlg.instName(), instancesDir); + QString instDir = PathCombine(instancesDir, instDirName); + + auto &loader = InstanceFactory::get(); + + auto error = loader.createInstance(newInstance, newInstDlg.selectedVersion(), instDir); + QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); + switch (error) + { + case InstanceFactory::NoCreateError: + newInstance->setName(newInstDlg.instName()); + newInstance->setIconKey(newInstDlg.iconKey()); + MMC->instances()->add(InstancePtr(newInstance)); + return; + + case InstanceFactory::InstExists: + { + errorMsg += "An instance with the given directory name already exists."; + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); + break; + } + + case InstanceFactory::CantCreateDir: + { + errorMsg += "Failed to create the instance directory."; + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); + break; + } + + default: + { + errorMsg += QString("Unknown instance loader error %1").arg(error); + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); + break; + } + } +} + +void MainWindow::on_actionCopyInstance_triggered() +{ + if (!m_selectedInstance) + return; + + CopyInstanceDialog copyInstDlg(m_selectedInstance, this); + if (!copyInstDlg.exec()) + return; + + QString instancesDir = MMC->settings()->get("InstanceDir").toString(); + QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir); + QString instDir = PathCombine(instancesDir, instDirName); + + auto &loader = InstanceFactory::get(); + + BaseInstance *newInstance = NULL; + auto error = loader.copyInstance(newInstance, m_selectedInstance, instDir); + + QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); + switch (error) + { + case InstanceFactory::NoCreateError: + newInstance->setName(copyInstDlg.instName()); + newInstance->setIconKey(copyInstDlg.iconKey()); + MMC->instances()->add(InstancePtr(newInstance)); + return; + + case InstanceFactory::InstExists: + { + errorMsg += "An instance with the given directory name already exists."; + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); + break; + } + + case InstanceFactory::CantCreateDir: + { + errorMsg += "Failed to create the instance directory."; + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); + break; + } + + default: + { + errorMsg += QString("Unknown instance loader error %1").arg(error); + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); + break; + } + } +} + +void MainWindow::on_actionChangeInstIcon_triggered() +{ + if (!m_selectedInstance) + return; + + IconPickerDialog dlg(this); + dlg.exec(m_selectedInstance->iconKey()); + if (dlg.result() == QDialog::Accepted) + { + m_selectedInstance->setIconKey(dlg.selectedIconKey); + auto ico = MMC->icons()->getIcon(dlg.selectedIconKey); + ui->actionChangeInstIcon->setIcon(ico); + } +} + +void MainWindow::on_actionChangeInstGroup_triggered() +{ + if (!m_selectedInstance) + return; + + bool ok = false; + QString name(m_selectedInstance->group()); + name = QInputDialog::getText(this, tr("Group name"), tr("Enter a new group name."), + QLineEdit::Normal, name, &ok); + if (ok) + m_selectedInstance->setGroupPost(name); +} + +void MainWindow::on_actionViewInstanceFolder_triggered() +{ + QString str = MMC->settings()->get("InstanceDir").toString(); + openDirInDefaultProgram(str); +} + +void MainWindow::on_actionRefresh_triggered() +{ + MMC->instances()->loadList(); +} + +void MainWindow::on_actionViewCentralModsFolder_triggered() +{ + openDirInDefaultProgram(MMC->settings()->get("CentralModsDir").toString(), true); +} + +void MainWindow::on_actionConfig_Folder_triggered() +{ + if (m_selectedInstance) + { + QString str = m_selectedInstance->instanceConfigFolder(); + openDirInDefaultProgram(QDir(str).absolutePath()); + } +} + +void MainWindow::on_actionCheckUpdate_triggered() +{ +} + +void MainWindow::on_actionSettings_triggered() +{ + SettingsDialog dialog(this); + dialog.exec(); + //FIXME: quick HACK to make this work. improve, optimize. + proxymodel->invalidate(); + proxymodel->sort(0); +} + +void MainWindow::on_actionReportBug_triggered() +{ + openWebPage(QUrl("http://multimc.myjetbrains.com/youtrack/dashboard#newissue=yes")); +} + +void MainWindow::on_actionNews_triggered() +{ + openWebPage(QUrl("http://multimc.org/posts.html")); +} + +void MainWindow::on_actionAbout_triggered() +{ + AboutDialog dialog(this); + dialog.exec(); +} + +void MainWindow::on_mainToolBar_visibilityChanged(bool) +{ + // Don't allow hiding the main toolbar. + // This is the only way I could find to prevent it... :/ + ui->mainToolBar->setVisible(true); +} + +void MainWindow::on_actionDeleteInstance_triggered() +{ + if (m_selectedInstance) + { + auto response = CustomMessageBox::selectable( + this, tr("CAREFUL"), tr("This is permanent! Are you sure?\nAbout to delete: ") + + m_selectedInstance->name(), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); + if (response == QMessageBox::Yes) + { + m_selectedInstance->nuke(); + } + } +} + +void MainWindow::on_actionRenameInstance_triggered() +{ + if (m_selectedInstance) + { + bool ok = false; + QString name(m_selectedInstance->name()); + name = + QInputDialog::getText(this, tr("Instance name"), tr("Enter a new instance name."), + QLineEdit::Normal, name, &ok); + + if (name.length() > 0) + { + if (ok && name.length()) + { + m_selectedInstance->setName(name); + renameButton->setText(name); + } + } + } +} + +void MainWindow::on_actionViewSelectedInstFolder_triggered() +{ + if (m_selectedInstance) + { + QString str = m_selectedInstance->instanceRoot(); + openDirInDefaultProgram(QDir(str).absolutePath()); + } +} + +void MainWindow::on_actionEditInstMods_triggered() +{ + if (m_selectedInstance) + { + auto dialog = m_selectedInstance->createModEditDialog(this); + if (dialog) + dialog->exec(); + dialog->deleteLater(); + } +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + // Save the window state and geometry. + + MMC->settings()->set("MainWindowState", saveState().toBase64()); + MMC->settings()->set("MainWindowGeometry", saveGeometry().toBase64()); + + QMainWindow::closeEvent(event); + QApplication::exit(); +} +/* +void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) +{ + QMenu *instContextMenu = new QMenu("Instance", this); + + // Add the actions from the toolbar to the context menu. + instContextMenu->addActions(ui->instanceToolBar->actions()); + + instContextMenu->exec(view->mapToGlobal(pos)); +} +*/ +void MainWindow::instanceActivated(QModelIndex index) +{ + if (!index.isValid()) + return; + + BaseInstance *inst = + (BaseInstance *)index.data(InstanceList::InstancePointerRole).value(); + + NagUtils::checkJVMArgs(MMC->settings()->get("JvmArgs").toString(), this); + + bool autoLogin = MMC->settings()->get("AutoLogin").toBool(); + if (autoLogin) + doAutoLogin(); + else + doLogin(); +} + +void MainWindow::on_actionLaunchInstance_triggered() +{ + if (m_selectedInstance) + { + NagUtils::checkJVMArgs(MMC->settings()->get("JvmArgs").toString(), this); + doLogin(); + } +} + +void MainWindow::doAutoLogin() +{ + if (!m_selectedInstance) + return; + + Keyring *k = Keyring::instance(); + QStringList accounts = k->getStoredAccounts("minecraft"); + + if (!accounts.isEmpty()) + { + QString username = accounts[0]; + QString password = k->getPassword("minecraft", username); + + if (!password.isEmpty()) + { + QLOG_INFO() << "Automatically logging in with stored account: " << username; + m_activeInst = m_selectedInstance; + doLogin(username, password); + } + else + { + QLOG_ERROR() << "Auto login set for account, but no password was found: " + << username; + doLogin(tr("Auto login attempted, but no password is stored.")); + } + } + else + { + QLOG_ERROR() << "Auto login set but no accounts were stored."; + doLogin(tr("Auto login attempted, but no accounts are stored.")); + } +} + +void MainWindow::doLogin(QString username, QString password) +{ + UserInfo uInfo{username, password}; + + ProgressDialog *tDialog = new ProgressDialog(this); + LoginTask *loginTask = new LoginTask(uInfo, tDialog); + connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection); + connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); + + tDialog->exec(loginTask); +} + +void MainWindow::doLogin(const QString &errorMsg) +{ + if (!m_selectedInstance) + return; + + LoginDialog *loginDlg = new LoginDialog(this, errorMsg); + if (!m_selectedInstance->lastLaunch()) + loginDlg->forceOnline(); + + loginDlg->exec(); + if (loginDlg->result() == QDialog::Accepted) + { + if (loginDlg->isOnline()) + { + m_activeInst = m_selectedInstance; + doLogin(loginDlg->getUsername(), loginDlg->getPassword()); + } + else + { + QString user = loginDlg->getUsername(); + if (user.length() == 0) + user = QString("Player"); + m_activeLogin = {user, QString("Offline"), user, QString()}; + m_activeInst = m_selectedInstance; + launchInstance(m_activeInst, m_activeLogin); + } + } +} + +void MainWindow::onLoginComplete() +{ + if (!m_activeInst) + return; + LoginTask *task = (LoginTask *)QObject::sender(); + m_activeLogin = task->getResult(); + + BaseUpdate *updateTask = m_activeInst->doUpdate(); + if (!updateTask) + { + launchInstance(m_activeInst, m_activeLogin); + } + else + { + ProgressDialog tDialog(this); + connect(updateTask, SIGNAL(succeeded()), SLOT(onGameUpdateComplete())); + connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); + tDialog.exec(updateTask); + delete updateTask; + } + + auto job = new NetJob("Player skin: " + m_activeLogin.player_name); + + auto meta = MMC->metacache()->resolveEntry("skins", m_activeLogin.player_name + ".png"); + auto action = CacheDownload::make( + QUrl("http://skins.minecraft.net/MinecraftSkins/" + m_activeLogin.player_name + ".png"), + meta); + job->addNetAction(action); + meta->stale = true; + + job->start(); + auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); + QFile listFile(filename); + + // Add skin mapping + QByteArray data; + { + if (!listFile.open(QIODevice::ReadWrite)) + { + QLOG_ERROR() << "Failed to open/make skins list JSON"; + return; + } + + data = listFile.readAll(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + QJsonObject root = jsonDoc.object(); + QJsonObject mappings = root.value("mappings").toObject(); + QJsonArray usernames = mappings.value(m_activeLogin.username).toArray(); + + if (!usernames.contains(m_activeLogin.player_name)) + { + usernames.prepend(m_activeLogin.player_name); + mappings[m_activeLogin.username] = usernames; + root["mappings"] = mappings; + jsonDoc.setObject(root); + + // QJson hack - shouldn't have to clear the file every time a save happens + listFile.resize(0); + listFile.write(jsonDoc.toJson()); + } +} + +void MainWindow::onGameUpdateComplete() +{ + launchInstance(m_activeInst, m_activeLogin); +} + +void MainWindow::onGameUpdateError(QString error) +{ + CustomMessageBox::selectable(this, tr("Error updating instance"), error, + QMessageBox::Warning)->show(); +} + +void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) +{ + Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); + + proc = instance->prepareForLaunch(response); + if (!proc) + return; + + // Prepare GUI: If it shall stay open disable the required parts + if (MMC->settings()->get("NoHide").toBool()) + { + ui->actionLaunchInstance->setEnabled(false); + } + else + { + this->hide(); + } + + console = new ConsoleWindow(proc); + + connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, + SLOT(write(QString, MessageLevel::Enum))); + connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); + + if (instance->settings().get("ShowConsole").toBool()) + { + console->show(); + } + + proc->setLogin(response.username, response.session_id); + proc->launch(); +} + +void MainWindow::taskStart() +{ + // Nothing to do here yet. +} + +void MainWindow::taskEnd() +{ + QObject *sender = QObject::sender(); + if (sender == m_versionLoadTask) + m_versionLoadTask = NULL; + + sender->deleteLater(); +} + +void MainWindow::startTask(Task *task) +{ + connect(task, SIGNAL(started()), SLOT(taskStart())); + connect(task, SIGNAL(succeeded()), SLOT(taskEnd())); + connect(task, SIGNAL(failed(QString)), SLOT(taskEnd())); + task->start(); +} + +// Create A Desktop Shortcut +void MainWindow::on_actionMakeDesktopShortcut_triggered() +{ + QString name("Test"); + name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."), + QLineEdit::Normal, name); + + Util::createShortCut(Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), + QStringList() << "-dl" << QDir::currentPath() << "test", name, + "application-x-octet-stream"); + + CustomMessageBox::selectable( + this, tr("Not useful"), + tr("A Dummy Shortcut was created. it will not do anything productive"), + QMessageBox::Warning)->show(); +} + +// BrowserDialog +void MainWindow::openWebPage(QUrl url) +{ + QDesktopServices::openUrl(url); +} + +void MainWindow::on_actionChangeInstMCVersion_triggered() +{ + if (view->selectionModel()->selectedIndexes().count() < 1) + return; + + VersionSelectDialog vselect(m_selectedInstance->versionList().get(), + tr("Change Minecraft version"), this); + vselect.setFilter(1, "OneSix"); + if (vselect.exec() && vselect.selectedVersion()) + { + if (m_selectedInstance->versionIsCustom()) + { + auto result = CustomMessageBox::selectable( + this, tr("Are you sure?"), + tr("This will remove any library/version customization you did previously. " + "This includes things like Forge install and similar."), + QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Abort)->exec(); + + if (result != QMessageBox::Ok) + return; + } + m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); + } +} + +void MainWindow::on_actionChangeInstLWJGLVersion_triggered() +{ + if (!m_selectedInstance) + return; + + LWJGLSelectDialog lselect(this); + lselect.exec(); + if (lselect.result() == QDialog::Accepted) + { + LegacyInstance *linst = (LegacyInstance *)m_selectedInstance; + linst->setLWJGLVersion(lselect.selectedVersion()); + } +} + +void MainWindow::on_actionInstanceSettings_triggered() +{ + if (view->selectionModel()->selectedIndexes().count() < 1) + return; + + InstanceSettings settings(&m_selectedInstance->settings(), this); + settings.setWindowTitle(QString("Instance settings")); + settings.exec(); +} + +void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + if (current.isValid() && + nullptr != (m_selectedInstance = + (BaseInstance *)current.data(InstanceList::InstancePointerRole) + .value())) + { + ui->instanceToolBar->setEnabled(true); + QString iconKey = m_selectedInstance->iconKey(); + renameButton->setText(m_selectedInstance->name()); + ui->actionChangeInstLWJGLVersion->setEnabled( + m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); + ui->actionEditInstMods->setEnabled( + m_selectedInstance->menuActionEnabled("actionEditInstMods")); + ui->actionChangeInstMCVersion->setEnabled( + m_selectedInstance->menuActionEnabled("actionChangeInstMCVersion")); + m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); + auto ico = MMC->icons()->getIcon(iconKey); + ui->actionChangeInstIcon->setIcon(ico); + } + else + { + selectionBad(); + } +} + +void MainWindow::selectionBad() +{ + m_selectedInstance = nullptr; + QString iconKey = "infinity"; + statusBar()->clearMessage(); + ui->instanceToolBar->setEnabled(false); + renameButton->setText(tr("Rename Instance")); + auto ico = MMC->icons()->getIcon(iconKey); + ui->actionChangeInstIcon->setIcon(ico); +} + +void MainWindow::on_actionEditInstNotes_triggered() +{ + if (!m_selectedInstance) + return; + LegacyInstance *linst = (LegacyInstance *)m_selectedInstance; + + EditNotesDialog noteedit(linst->notes(), linst->name(), this); + noteedit.exec(); + if (noteedit.result() == QDialog::Accepted) + { + + linst->setNotes(noteedit.getText()); + } +} + +void MainWindow::instanceEnded(BaseInstance *instance) +{ + this->show(); + ui->actionLaunchInstance->setEnabled(m_selectedInstance); + + if (instance->settings().get("AutoCloseConsole").toBool()) + { + console->close(); + } +} + +void MainWindow::checkSetDefaultJava() +{ + bool askForJava = false; + { + QString currentHostName = QHostInfo::localHostName(); + QString oldHostName = MMC->settings()->get("LastHostname").toString(); + if (currentHostName != oldHostName) + { + MMC->settings()->set("LastHostname", currentHostName); + askForJava = true; + } + } + + { + QString currentJavaPath = MMC->settings()->get("JavaPath").toString(); + if (currentJavaPath.isEmpty()) + { + askForJava = true; + } + } + + if (askForJava) + { + QLOG_DEBUG() << "Java path needs resetting, showing Java selection dialog..."; + + JavaVersionPtr java; + + VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, + false); + vselect.setResizeOn(2); + vselect.exec(); + + if (vselect.selectedVersion()) + java = std::dynamic_pointer_cast(vselect.selectedVersion()); + else + { + CustomMessageBox::selectable( + this, tr("Invalid version selected"), + tr("You didn't select a valid Java version, so MultiMC will " + "select the default. " + "You can change this in the settings dialog."), + QMessageBox::Warning)->show(); + + JavaUtils ju; + java = ju.GetDefaultJava(); + } + if (java) + MMC->settings()->set("JavaPath", java->path); + else + MMC->settings()->set("JavaPath", QString("java")); + } +} + +void MainWindow::assetsIndexStarted() +{ + m_statusRight->setText(tr("Checking assets...")); +} + +void MainWindow::assetsFilesStarted() +{ + m_statusRight->setText(tr("Downloading assets...")); +} + +void MainWindow::assetsFilesProgress(int succeeded, int failed, int total) +{ + QString status = tr("Downloading assets: %1 / %2").arg(succeeded + failed).arg(total); + if (failed > 0) + status += tr(" (%1 failed)").arg(failed); + status += tr("..."); + m_statusRight->setText(status); +} + +void MainWindow::assetsFailed() +{ + m_statusRight->setText(tr("Failed to update assets.")); +} + +void MainWindow::assetsFinished() +{ + m_statusRight->setText(tr("Assets up to date.")); +} diff --git a/gui/MainWindow.h b/gui/MainWindow.h new file mode 100644 index 00000000..97aa0d9f --- /dev/null +++ b/gui/MainWindow.h @@ -0,0 +1,167 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include "logic/lists/InstanceList.h" +#include "logic/net/LoginTask.h" +#include "logic/BaseInstance.h" + +class QToolButton; +class LabeledToolButton; +class QLabel; +class InstanceProxyModel; +class KCategorizedView; +class KCategoryDrawer; +class MinecraftProcess; +class ConsoleWindow; +class OneSixAssets; + +namespace Ui +{ +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void closeEvent(QCloseEvent *event); + + // Browser Dialog + void openWebPage(QUrl url); + + void checkSetDefaultJava(); + +private +slots: + void onCatToggled(bool); + + void on_actionAbout_triggered(); + + void on_actionAddInstance_triggered(); + + void on_actionCopyInstance_triggered(); + + void on_actionChangeInstGroup_triggered(); + + void on_actionChangeInstIcon_triggered(); + + void on_actionViewInstanceFolder_triggered(); + + void on_actionConfig_Folder_triggered(); + + void on_actionViewSelectedInstFolder_triggered(); + + void on_actionRefresh_triggered(); + + void on_actionViewCentralModsFolder_triggered(); + + void on_actionCheckUpdate_triggered(); + + void on_actionSettings_triggered(); + + void on_actionReportBug_triggered(); + + void on_actionNews_triggered(); + + void on_mainToolBar_visibilityChanged(bool); + + // void on_instanceView_customContextMenuRequested(const QPoint &pos); + + void on_actionLaunchInstance_triggered(); + + void on_actionDeleteInstance_triggered(); + + void on_actionRenameInstance_triggered(); + + void on_actionMakeDesktopShortcut_triggered(); + + void on_actionChangeInstMCVersion_triggered(); + + void on_actionEditInstMods_triggered(); + + void on_actionEditInstNotes_triggered(); + + void doLogin(const QString &errorMsg = ""); + void doLogin(QString username, QString password); + void doAutoLogin(); + + void onLoginComplete(); + + void onGameUpdateComplete(); + void onGameUpdateError(QString error); + + void taskStart(); + void taskEnd(); + + void on_actionChangeInstLWJGLVersion_triggered(); + + void instanceEnded(BaseInstance *instance); + + void on_actionInstanceSettings_triggered(); + + void assetsIndexStarted(); + void assetsFilesStarted(); + void assetsFilesProgress(int, int, int); + void assetsFailed(); + void assetsFinished(); + +public +slots: + void instanceActivated(QModelIndex); + + void instanceChanged(const QModelIndex ¤t, const QModelIndex &previous); + + void selectionBad(); + + void startTask(Task *task); + + void launchInstance(BaseInstance *inst, LoginResponse response); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + void setCatBackground(bool enabled); + +private: + Ui::MainWindow *ui; + KCategoryDrawer *drawer; + KCategorizedView *view; + InstanceProxyModel *proxymodel; + MinecraftProcess *proc; + ConsoleWindow *console; + OneSixAssets *assets_downloader; + LabeledToolButton *renameButton; + QToolButton *changeIconButton; + + BaseInstance *m_selectedInstance; + + // A pointer to the instance we are actively doing stuff with. + // This is set when the user launches an instance and is used to refer to that + // instance throughout the launching process. + BaseInstance *m_activeInst; + LoginResponse m_activeLogin; + + Task *m_versionLoadTask; + + QLabel *m_statusLeft; + QLabel *m_statusRight; +}; diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui new file mode 100644 index 00000000..6f70fc98 --- /dev/null +++ b/gui/MainWindow.ui @@ -0,0 +1,474 @@ + + + MainWindow + + + + 0 + 0 + 688 + 650 + + + + MultiMC 5 + + + + :/icons/multimc/scalable/apps/multimc.svg:/icons/multimc/scalable/apps/multimc.svg + + + + + 0 + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Main Toolbar + + + false + + + Qt::TopToolBarArea + + + Qt::ToolButtonIconOnly + + + false + + + TopToolBarArea + + + false + + + + + + + + + + + + + + + + + + + + + true + + + Instance Toolbar + + + Qt::LeftToolBarArea|Qt::RightToolBarArea + + + + 80 + 80 + + + + Qt::ToolButtonIconOnly + + + false + + + RightToolBarArea + + + false + + + + + + + + + + + + + + + + + + + + :/icons/toolbar/new:/icons/toolbar/new + + + Add Instance + + + Add a new instance. + + + Add a new instance. + + + + + + :/icons/toolbar/viewfolder:/icons/toolbar/viewfolder + + + View Instance Folder + + + Open the instance folder in a file browser. + + + Open the instance folder in a file browser. + + + + + + :/icons/toolbar/refresh:/icons/toolbar/refresh + + + Refresh + + + Reload the instance list. + + + Reload the instance list. + + + + + + :/icons/toolbar/centralmods:/icons/toolbar/centralmods + + + View Central Mods Folder + + + Open the central mods folder in a file browser. + + + Open the central mods folder in a file browser. + + + + + + :/icons/toolbar/checkupdate:/icons/toolbar/checkupdate + + + Check for Updates + + + Check for new updates for MultiMC + + + Check for new updates for MultiMC + + + + + + :/icons/toolbar/settings:/icons/toolbar/settings + + + Settings + + + Change settings. + + + Change settings. + + + QAction::PreferencesRole + + + + + + :/icons/toolbar/bug:/icons/toolbar/bug + + + Report a Bug + + + Open the bug tracker to report a bug with MultiMC. + + + Open the bug tracker to report a bug with MultiMC. + + + + + + :/icons/toolbar/news:/icons/toolbar/news + + + News + + + Open the MultiMC dev blog to read news about MultiMC. + + + Open the MultiMC dev blog to read news about MultiMC. + + + + + + :/icons/toolbar/about:/icons/toolbar/about + + + About MultiMC + + + View information about MultiMC. + + + About MultiMC + + + QAction::AboutRole + + + + + Play + + + Launch the selected instance. + + + Launch the selected instance. + + + + + Instance Name + + + Rename the selected instance. + + + Rename the selected instance. + + + + + Change Group + + + Change the selected instance's group. + + + Change the selected instance's group. + + + + + true + + + + :/icons/instances/infinity:/icons/instances/infinity + + + Change Icon + + + Change the selected instance's icon. + + + Change the selected instance's icon. + + + true + + + + + Edit Notes + + + Edit the notes for the selected instance. + + + Edit the notes for the selected instance. + + + + + true + + + Settings + + + Change settings for the selected instance. + + + Change settings for the selected instance. + + + + + false + + + Make Shortcut + + + Make a shortcut on the desktop for the selected instance. + + + Make a shortcut on the desktop for the selected instance. + + + + + false + + + Manage Saves + + + Manage saves for the selected instance. + + + Manage saves for the selected instance. + + + + + Edit Mods + + + Edit the mods for the selected instance. + + + Edit the mods for the selected instance. + + + + + Change Version + + + Change the selected instance's Minecraft version. + + + Change the selected instance's Minecraft version. + + + + + false + + + Change LWJGL + + + Change the version of LWJGL for the selected instance to use. + + + Change the version of LWJGL for the selected instance to use. + + + + + Instance Folder + + + Open the selected instance's root folder in a file browser. + + + Open the selected instance's root folder in a file browser. + + + + + Delete + + + Delete the selected instance. + + + Delete the selected instance. + + + + + Config Folder + + + Open the instance's config folder + + + + + true + + + + :/icons/toolbar/cat:/icons/toolbar/cat + + + Meow + + + <html><head/><body><p align="center"><span style=" font-weight:600; color:#ff0004;">Catnarok!</span></p><p align="center">Or just a cat with a ball of yarn?</p><p align="center"><span style=" font-style:italic;">WHO KNOWS?!</span></p><p align="center"><img src=":/icons/instances/tnt"/></p></body></html> + + + + + + :/icons/toolbar/copy:/icons/toolbar/copy + + + Copy Instance + + + Copy the selected instance. + + + Add a new instance. + + + + + + + + + diff --git a/gui/ModEditDialogCommon.cpp b/gui/ModEditDialogCommon.cpp deleted file mode 100644 index 873cd8ea..00000000 --- a/gui/ModEditDialogCommon.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "ModEditDialogCommon.h" -#include "CustomMessageBox.h" -#include -#include -#include -#include -bool lastfirst(QModelIndexList &list, int &first, int &last) -{ - if (!list.size()) - return false; - first = last = list[0].row(); - for (auto item : list) - { - int row = item.row(); - if (row < first) - first = row; - if (row > last) - last = row; - } - return true; -} - -void showWebsiteForMod(QWidget *parentDlg, Mod &m) -{ - QString url = m.homeurl(); - if (url.size()) - { - // catch the cases where the protocol is missing - if(!url.startsWith("http")) - { - url = "http://" + url; - } - QDesktopServices::openUrl(url); - } - else - { - CustomMessageBox::selectable(parentDlg, parentDlg->tr("How sad!"), - parentDlg->tr("The mod author didn't provide a website link for this mod."), - QMessageBox::Warning); - } -} diff --git a/gui/ModEditDialogCommon.h b/gui/ModEditDialogCommon.h deleted file mode 100644 index bc8e223f..00000000 --- a/gui/ModEditDialogCommon.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include -#include - -bool lastfirst (QModelIndexList & list, int & first, int & last); - -void showWebsiteForMod(QWidget * parentDlg, Mod& m); \ No newline at end of file diff --git a/gui/ModListView.cpp b/gui/ModListView.cpp deleted file mode 100644 index 1d0e834c..00000000 --- a/gui/ModListView.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "ModListView.h" -#include -#include -#include -#include -#include - -ModListView::ModListView ( QWidget* parent ) - :QTreeView ( parent ) -{ - setAllColumnsShowFocus ( true ); - setExpandsOnDoubleClick ( false ); - setRootIsDecorated ( false ); - setSortingEnabled ( false ); - setAlternatingRowColors ( true ); - setSelectionMode ( QAbstractItemView::ContiguousSelection ); - setHeaderHidden ( false ); - setSelectionBehavior(QAbstractItemView::SelectRows); - setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn ); - setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded ); - setDropIndicatorShown(true); - setDragEnabled(true); - setDragDropMode(QAbstractItemView::DropOnly); - viewport()->setAcceptDrops(true); -} - -void ModListView::setModel ( QAbstractItemModel* model ) -{ - QTreeView::setModel ( model ); - auto head = header(); - head->setStretchLastSection(false); - head->setSectionResizeMode(0, QHeaderView::Stretch); - for(int i = 1; i < head->count(); i++) - head->setSectionResizeMode(i, QHeaderView::ResizeToContents); - dropIndicatorPosition(); -} diff --git a/gui/ModListView.h b/gui/ModListView.h deleted file mode 100644 index 69a26755..00000000 --- a/gui/ModListView.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include - -class Mod; - -class ModListView: public QTreeView -{ - Q_OBJECT -public: - explicit ModListView ( QWidget* parent = 0 ); - virtual void setModel ( QAbstractItemModel* model ); - -}; diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp deleted file mode 100644 index 42bcfeb0..00000000 --- a/gui/OneSixModEditDialog.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "MultiMC.h" -#include "OneSixModEditDialog.h" -#include "ModEditDialogCommon.h" -#include "ui_OneSixModEditDialog.h" -#include "logic/ModList.h" -#include "logic/OneSixVersion.h" -#include "logic/EnabledItemFilter.h" -#include "logic/lists/ForgeVersionList.h" -#include "logic/ForgeInstaller.h" -#include "gui/versionselectdialog.h" -#include "gui/platform.h" -#include "gui/CustomMessageBox.h" -#include "ProgressDialog.h" - -#include -#include -#include -#include -#include -#include -#include - -OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) - : m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - // libraries! - - m_version = m_inst->getFullVersion(); - if (m_version) - { - main_model = new EnabledItemFilter(this); - main_model->setActive(true); - main_model->setSourceModel(m_version.get()); - ui->libraryTreeView->setModel(main_model); - ui->libraryTreeView->installEventFilter(this); - ui->mainClassEdit->setText(m_version->mainClass); - updateVersionControls(); - } - else - { - disableVersionControls(); - } - // Loader mods - { - ensureFolderPathExists(m_inst->loaderModsDir()); - m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.get()); - ui->loaderModTreeView->installEventFilter(this); - m_mods->startWatching(); - auto smodel = ui->loaderModTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(loaderCurrent(QModelIndex,QModelIndex))); - } - // resource packs - { - ensureFolderPathExists(m_inst->resourcePacksDir()); - m_resourcepacks = m_inst->resourcePackList(); - ui->resPackTreeView->setModel(m_resourcepacks.get()); - ui->resPackTreeView->installEventFilter(this); - m_resourcepacks->startWatching(); - } -} - -OneSixModEditDialog::~OneSixModEditDialog() -{ - m_mods->stopWatching(); - m_resourcepacks->stopWatching(); - delete ui; -} - -void OneSixModEditDialog::updateVersionControls() -{ - bool customVersion = m_inst->versionIsCustom(); - ui->customizeBtn->setEnabled(!customVersion); - ui->revertBtn->setEnabled(customVersion); - ui->forgeBtn->setEnabled(true); -} - -void OneSixModEditDialog::disableVersionControls() -{ - ui->customizeBtn->setEnabled(false); - ui->revertBtn->setEnabled(false); - ui->forgeBtn->setEnabled(false); -} - -void OneSixModEditDialog::on_customizeBtn_clicked() -{ - if (m_inst->customizeVersion()) - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } -} - -void OneSixModEditDialog::on_revertBtn_clicked() -{ - auto response = CustomMessageBox::selectable(this, tr("Revert?"), - tr("Do you want to revert the " - "version of this instance to its original configuration?"), - QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); - if (response == QMessageBox::Yes) - { - if (m_inst->revertCustomVersion()) - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - } -} - -void OneSixModEditDialog::on_forgeBtn_clicked() -{ - VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); - vselect.setFilter(1, m_inst->currentVersionId()); - if (vselect.exec() && vselect.selectedVersion()) - { - if (m_inst->versionIsCustom()) - { - auto reply = QMessageBox::question( - this, tr("Revert?"), - tr("This will revert any " - "changes you did to the version up to this point. Is that " - "OK?"), - QMessageBox::Yes | QMessageBox::No); - if (reply == QMessageBox::Yes) - { - m_inst->revertCustomVersion(); - m_inst->customizeVersion(); - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - } - else - return; - } - else - { - m_inst->customizeVersion(); - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - ForgeVersionPtr forgeVersion = - std::dynamic_pointer_cast(vselect.selectedVersion()); - if (!forgeVersion) - return; - auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); - if (entry->stale) - { - NetJob *fjob = new NetJob("Forge download"); - fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry)); - ProgressDialog dlg(this); - dlg.exec(fjob); - if (dlg.result() == QDialog::Accepted) - { - // install - QString forgePath = entry->getFullPath(); - ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!forge.apply(m_version)) - { - // failure notice - } - } - else - { - // failed to download forge :/ - } - } - else - { - // install - QString forgePath = entry->getFullPath(); - ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!forge.apply(m_version)) - { - // failure notice - } - } - } -} - -bool OneSixModEditDialog::loaderListFilter(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 QDialog::eventFilter(ui->loaderModTreeView, keyEvent); -} - -bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmResPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addResPackBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->resPackTreeView, keyEvent); -} - -bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QDialog::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->loaderModTreeView) - return loaderListFilter(keyEvent); - if (obj == ui->resPackTreeView) - return resourcePackListFilter(keyEvent); - return QDialog::eventFilter(obj, ev); -} - -void OneSixModEditDialog::on_buttonBox_rejected() -{ - close(); -} - -void OneSixModEditDialog::on_addModBtn_clicked() -{ - QStringList fileNames = QFileDialog::getOpenFileNames( - this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); - for (auto filename : fileNames) - { - m_mods->stopWatching(); - m_mods->installMod(QFileInfo(filename)); - m_mods->startWatching(); - } -} -void OneSixModEditDialog::on_rmModBtn_clicked() -{ - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_mods->stopWatching(); - m_mods->deleteMods(first, last); - m_mods->startWatching(); -} -void OneSixModEditDialog::on_viewModBtn_clicked() -{ - openDirInDefaultProgram(m_inst->loaderModsDir(), true); -} - -void OneSixModEditDialog::on_addResPackBtn_clicked() -{ - QStringList fileNames = QFileDialog::getOpenFileNames( - this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); - for (auto filename : fileNames) - { - m_resourcepacks->stopWatching(); - m_resourcepacks->installMod(QFileInfo(filename)); - m_resourcepacks->startWatching(); - } -} -void OneSixModEditDialog::on_rmResPackBtn_clicked() -{ - int first, last; - auto list = ui->resPackTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_resourcepacks->stopWatching(); - m_resourcepacks->deleteMods(first, last); - m_resourcepacks->startWatching(); -} -void OneSixModEditDialog::on_viewResPackBtn_clicked() -{ - openDirInDefaultProgram(m_inst->resourcePacksDir(), true); -} - -void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) -{ - if(!current.isValid()) - { - ui->frame->clear(); - return; - } - int row = current.row(); - Mod &m = m_mods->operator[](row); - ui->frame->updateWithMod(m); -} diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h deleted file mode 100644 index 5376e526..00000000 --- a/gui/OneSixModEditDialog.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include - -#include - -class EnabledItemFilter; -namespace Ui -{ -class OneSixModEditDialog; -} - -class OneSixModEditDialog : public QDialog -{ - Q_OBJECT - -public: - explicit OneSixModEditDialog(OneSixInstance *inst, QWidget *parent = 0); - virtual ~OneSixModEditDialog(); - -private -slots: - void on_addModBtn_clicked(); - void on_rmModBtn_clicked(); - void on_viewModBtn_clicked(); - - void on_addResPackBtn_clicked(); - void on_rmResPackBtn_clicked(); - void on_viewResPackBtn_clicked(); - // Questionable: SettingsDialog doesn't need this for some reason? - void on_buttonBox_rejected(); - void on_forgeBtn_clicked(); - void on_customizeBtn_clicked(); - void on_revertBtn_clicked(); - void updateVersionControls(); - void disableVersionControls(); - -protected: - bool eventFilter(QObject *obj, QEvent *ev); - bool loaderListFilter(QKeyEvent *ev); - bool resourcePackListFilter(QKeyEvent *ev); - -private: - Ui::OneSixModEditDialog *ui; - std::shared_ptr m_version; - std::shared_ptr m_mods; - std::shared_ptr m_resourcepacks; - EnabledItemFilter *main_model; - OneSixInstance *m_inst; -public -slots: - void loaderCurrent(QModelIndex current, QModelIndex previous); -}; diff --git a/gui/OneSixModEditDialog.ui b/gui/OneSixModEditDialog.ui deleted file mode 100644 index 6d70200a..00000000 --- a/gui/OneSixModEditDialog.ui +++ /dev/null @@ -1,319 +0,0 @@ - - - OneSixModEditDialog - - - - 0 - 0 - 555 - 463 - - - - Dialog - - - - - - true - - - - 0 - 0 - - - - 1 - - - - Version - - - - - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - - - - - - - Main Class: - - - - - - - false - - - - - - - - - - - - - Replace any current custom version with Minecraft Forge - - - Install Forge - - - - - - - Create an customized copy of the base version - - - Customize - - - - - - - false - - - Revert to original base version - - - Revert - - - - - - - QFrame::Sunken - - - Qt::Horizontal - - - - - - - false - - - Add new libraries - - - &Add - - - - - - - false - - - Remove selected libraries - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Loader Mods - - - - - - - - - - - 0 - 0 - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - 0 - 0 - - - - - - - - - Resource Packs - - - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - - false - - - QDialogButtonBox::Close - - - - - - - - ModListView - QTreeView -
gui/ModListView.h
-
- - MCModInfoFrame - QFrame -
gui/MCModInfoFrame.h
- 1 -
-
- - -
diff --git a/gui/Platform.h b/gui/Platform.h new file mode 100644 index 00000000..5cde9505 --- /dev/null +++ b/gui/Platform.h @@ -0,0 +1,32 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Orochimarufan + * + * 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 + +/** + * @file Platform.h + * This file contains platform-specific functions, tweaks and fixes. + */ + +#include + +class MultiMCPlatform +{ +public: + // X11 WM_CLASS + static void fixWM_CLASS(QWidget *widget); +}; diff --git a/gui/Platform_Other.cpp b/gui/Platform_Other.cpp new file mode 100644 index 00000000..e02bd921 --- /dev/null +++ b/gui/Platform_Other.cpp @@ -0,0 +1,27 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Orochimarufan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +/** + * Stub for non-X11 platforms + * @brief MultiMCPlatform::fixWM_CLASS + * @param widget + */ +void MultiMCPlatform::fixWM_CLASS(QWidget *widget) +{ + Q_UNUSED(widget); +} diff --git a/gui/Platform_X11.cpp b/gui/Platform_X11.cpp new file mode 100644 index 00000000..bcd26f53 --- /dev/null +++ b/gui/Platform_X11.cpp @@ -0,0 +1,62 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Orochimarufan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +static QByteArray WM_CLASS = "MultiMC5\0MultiMC5"; + +template +static inline unsigned int XcbCallVoid(xcb_void_cookie_t (*func)(xcb_connection_t *, ArgTypes...), ArgTypes2... args...) +{ + return func(QX11Info::connection(), args...).sequence; +} + +static void getAtoms(size_t n, xcb_atom_t *atoms, const char *const names[], bool create) +{ + xcb_connection_t *conn = QX11Info::connection(); + xcb_intern_atom_cookie_t *cookies = (xcb_intern_atom_cookie_t *)malloc(sizeof(xcb_intern_atom_cookie_t) * 2); + for (size_t i = 0; i < n; ++i) + cookies[i] = xcb_intern_atom(conn, create, strlen(names[i]), names[i]); + memset(atoms, 0, sizeof(xcb_atom_t) * n); + for (size_t i = 0; i < n; ++i) + { + xcb_intern_atom_reply_t *r = xcb_intern_atom_reply(conn, cookies[i], 0); + if (r) + { + atoms[i] = r->atom; + free(r); + } + } + free(cookies); +} + +static inline xcb_atom_t getAtom(const char *name, bool create=false) +{ + xcb_atom_t atom; + getAtoms(1, &atom, &name, create); + return atom; +} + +void MultiMCPlatform::fixWM_CLASS(QWidget *widget) +{ + static const xcb_atom_t atom = getAtom("WM_CLASS"); + XcbCallVoid(xcb_change_property, XCB_PROP_MODE_REPLACE, + widget->winId(), atom, XCB_ATOM_STRING, 8, WM_CLASS.count(), + WM_CLASS.constData()); +} diff --git a/gui/ProgressDialog.cpp b/gui/ProgressDialog.cpp deleted file mode 100644 index 2e5251a0..00000000 --- a/gui/ProgressDialog.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ProgressDialog.h" -#include "ui_ProgressDialog.h" - -#include - -#include "logic/tasks/Task.h" -#include "gui/platform.h" - -ProgressDialog::ProgressDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::ProgressDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - updateSize(); - - changeProgress(0,100); -} - -ProgressDialog::~ProgressDialog() -{ - delete ui; -} - -void ProgressDialog::updateSize() -{ - resize(QSize(480, minimumSizeHint().height())); -} - -int ProgressDialog::exec(ProgressProvider *task) -{ - this->task = task; - - // Connect signals. - connect(task, SIGNAL(started()), SLOT(onTaskStarted())); - connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString))); - connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded())); - connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString&))); - connect(task, SIGNAL(progress(qint64,qint64)), SLOT(changeProgress(qint64,qint64))); - - // this makes sure that the task is started after the dialog is created - QMetaObject::invokeMethod(task, "start", Qt::QueuedConnection); - return QDialog::exec(); -} - -ProgressProvider* ProgressDialog::getTask() -{ - return task; -} - -void ProgressDialog::onTaskStarted() -{ - -} - -void ProgressDialog::onTaskFailed(QString failure) -{ - reject(); -} - -void ProgressDialog::onTaskSucceeded() -{ - accept(); -} - -void ProgressDialog::changeStatus(const QString &status) -{ - ui->statusLabel->setText(status); - updateSize(); -} - -void ProgressDialog::changeProgress(qint64 current, qint64 total) -{ - ui->taskProgressBar->setMaximum(total); - ui->taskProgressBar->setValue(current); -} - -void ProgressDialog::keyPressEvent(QKeyEvent* e) -{ - if (e->key() == Qt::Key_Escape) - return; - QDialog::keyPressEvent(e); -} - -void ProgressDialog::closeEvent(QCloseEvent* e) -{ - if (task && task->isRunning()) - { - e->ignore(); - } - else - { - QDialog::closeEvent(e); - } -} diff --git a/gui/ProgressDialog.h b/gui/ProgressDialog.h deleted file mode 100644 index ac6bb412..00000000 --- a/gui/ProgressDialog.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef TASKDIALOG_H -#define TASKDIALOG_H - -#include - -class ProgressProvider; - -namespace Ui { -class ProgressDialog; -} - -class ProgressDialog : public QDialog -{ - Q_OBJECT - -public: - explicit ProgressDialog(QWidget *parent = 0); - ~ProgressDialog(); - - void updateSize(); - - int exec(ProgressProvider* task); - - ProgressProvider* getTask(); - -public slots: - void onTaskStarted(); - void onTaskFailed(QString failure); - void onTaskSucceeded(); - - void changeStatus(const QString& status); - void changeProgress(qint64 current, qint64 total); - -signals: - - -protected: - virtual void keyPressEvent(QKeyEvent* e); - virtual void closeEvent(QCloseEvent* e); - -private: - Ui::ProgressDialog *ui; - - ProgressProvider* task; -}; - -#endif // TASKDIALOG_H diff --git a/gui/ProgressDialog.ui b/gui/ProgressDialog.ui deleted file mode 100644 index a56d2a92..00000000 --- a/gui/ProgressDialog.ui +++ /dev/null @@ -1,53 +0,0 @@ - - - ProgressDialog - - - - 0 - 0 - 400 - 68 - - - - - 400 - 0 - - - - - 600 - 16777215 - - - - Please wait... - - - - - - Task Status... - - - true - - - - - - - 24 - - - false - - - - - - - - diff --git a/gui/aboutdialog.cpp b/gui/aboutdialog.cpp deleted file mode 100644 index 7105446c..00000000 --- a/gui/aboutdialog.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "aboutdialog.h" -#include "ui_aboutdialog.h" -#include -#include -#include "gui/platform.h" - -AboutDialog::AboutDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::AboutDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - - ui->icon->setPixmap(QIcon(":/icons/multimc/scalable/apps/multimc.svg").pixmap(64)); - ui->title->setText("MultiMC " + MMC->version().toString()); - connect(ui->closeButton, SIGNAL(clicked()), SLOT(close())); - - MMC->connect(ui->aboutQt, SIGNAL(clicked()), SLOT(aboutQt())); -} - -AboutDialog::~AboutDialog() -{ - delete ui; -} diff --git a/gui/aboutdialog.h b/gui/aboutdialog.h deleted file mode 100644 index d462de28..00000000 --- a/gui/aboutdialog.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ABOUTDIALOG_H -#define ABOUTDIALOG_H - -#include - -namespace Ui { -class AboutDialog; -} - -class AboutDialog : public QDialog -{ - Q_OBJECT - -public: - explicit AboutDialog(QWidget *parent = 0); - ~AboutDialog(); - -private: - Ui::AboutDialog *ui; -}; - -#endif // ABOUTDIALOG_H diff --git a/gui/aboutdialog.ui b/gui/aboutdialog.ui deleted file mode 100644 index c075f895..00000000 --- a/gui/aboutdialog.ui +++ /dev/null @@ -1,315 +0,0 @@ - - - AboutDialog - - - - 0 - 0 - 450 - 429 - - - - - 450 - 400 - - - - Dialog - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 64 - 64 - - - - - 64 - 64 - - - - - - - :/icons/multimc/scalable/apps/multimc.svg - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 15 - - - - MultiMC - - - Qt::AlignCenter - - - - - - - - - 0 - 0 - 432 - 197 - - - - About - - - - - - <html><head/><body><p>MultiMC is a custom launcher that makes managing Minecraft easier by allowing you to have multiple instances of Minecraft at once.</p></body></html> - - - Qt::AlignCenter - - - true - - - - - - - - 8 - true - - - - © 2013 MultiMC Contributors - - - Qt::AlignCenter - - - - - - - - 10 - - - - <html><head/><body><p><a href="http://github.com/Forkk/MultiMC5"><span style=" text-decoration: underline; color:#0000ff;">http://github.com/MultiMC/MultiMC5</span></a></p></body></html> - - - Qt::AlignCenter - - - - - - - - - 0 - 0 - 432 - 197 - - - - Credits - - - - - - true - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Andrew Okin &lt;</span><a href="mailto:forkk@forkk.net"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">forkk@forkk.net</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Petr Mrázek &lt;</span><a href="mailto:peterix@gmail.com"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">peterix@gmail.com</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Orochimarufan &lt;</span><a href="mailto:orochimarufan.x3@gmail.com"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">orochimarufan.x3@gmail.com</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">TakSuyu &lt;</span><a href="mailto:taksuyu@gmail.com"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">taksuyu@gmail.com</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Sky (Drayshak) &lt;</span><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">multimc@bunnies.cc</span><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Kilobyte &lt;</span><a href="mailto:stiepen22@gmx.de"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">stiepen22@gmx.de</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p></body></html> - - - - - - - No Language file loaded. - - - true - - - - - - - - - 0 - 0 - 432 - 197 - - - - License - - - - - - - 0 - 0 - - - - true - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Copyright 2012 MultiMC Contributors</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">you may not use this file except in compliance with the License.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">You may obtain a copy of the License at</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> http://www.apache.org/licenses/LICENSE-2.0</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Unless required by applicable law or agreed to in writing, software</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">See the License for the specific language governing permissions and</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">limitations under the License.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">MultiMC uses QSLog, </span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Copyright (c) 2010, Razvan Petru</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">All rights reserved.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Redistribution and use in source and binary forms, with or without modification,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">are permitted provided that the following conditions are met:</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* Redistributions of source code must retain the above copyright notice, this</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> list of conditions and the following disclaimer.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* Redistributions in binary form must reproduce the above copyright notice, this</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> list of conditions and the following disclaimer in the documentation and/or other</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> materials provided with the distribution.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* The name of the contributors may not be used to endorse or promote products</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> derived from this software without specific prior written permission.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">OF THE POSSIBILITY OF SUCH DAMAGE.</span></p></body></html> - - - - - - - - - - - - - false - - - About Qt - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Close - - - - - - - - - - - - diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp deleted file mode 100644 index 49e12339..00000000 --- a/gui/consolewindow.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "consolewindow.h" -#include "ui_consolewindow.h" - -#include -#include - -#include -#include - -ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : - QDialog(parent), - ui(new Ui::ConsoleWindow), - m_mayclose(true), - proc(mcproc) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - this->setWindowFlags(Qt::Window); - connect(mcproc, SIGNAL(ended(BaseInstance*)), this, SLOT(onEnded(BaseInstance*))); -} - -ConsoleWindow::~ConsoleWindow() -{ - delete ui; -} - -void ConsoleWindow::writeColor(QString text, const char *color) -{ - // append a paragraph - if (color != nullptr) - ui->text->appendHtml(QString("%2").arg(color).arg(text)); - else - ui->text->appendPlainText(text); - // scroll down - QScrollBar *bar = ui->text->verticalScrollBar(); - bar->setValue(bar->maximum()); -} - -void ConsoleWindow::write(QString data, MessageLevel::Enum mode) -{ - if (data.endsWith('\n')) - data = data.left(data.length()-1); - QStringList paragraphs = data.split('\n'); - for(QString ¶graph : paragraphs) - { - paragraph = paragraph.trimmed(); - } - - QListIterator iter(paragraphs); - if (mode == MessageLevel::MultiMC) - while(iter.hasNext()) - writeColor(iter.next(), "blue"); - else if (mode == MessageLevel::Error) - while(iter.hasNext()) - writeColor(iter.next(), "red"); - else if (mode == MessageLevel::Warning) - while(iter.hasNext()) - writeColor(iter.next(), "orange"); - else if (mode == MessageLevel::Fatal) - while(iter.hasNext()) - writeColor(iter.next(), "pink"); - else if (mode == MessageLevel::Debug) - while(iter.hasNext()) - writeColor(iter.next(), "green"); - // TODO: implement other MessageLevels - else - while(iter.hasNext()) - writeColor(iter.next()); -} - -void ConsoleWindow::clear() -{ - ui->text->clear(); -} - -void ConsoleWindow::on_closeButton_clicked() -{ - close(); -} - -void ConsoleWindow::setMayClose(bool mayclose) -{ - m_mayclose = mayclose; - if (mayclose) - ui->closeButton->setEnabled(true); - else - ui->closeButton->setEnabled(false); -} - -void ConsoleWindow::closeEvent(QCloseEvent * event) -{ - if(!m_mayclose) - event->ignore(); - else - QDialog::closeEvent(event); -} - -void ConsoleWindow::on_btnKillMinecraft_clicked() -{ - ui->btnKillMinecraft->setEnabled(false); - auto response = CustomMessageBox::selectable(this, tr("Kill Minecraft?"), - tr("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason"), - QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)->exec(); - if (response == QMessageBox::Yes) - proc->killMinecraft(); - else - ui->btnKillMinecraft->setEnabled(true); -} - -void ConsoleWindow::onEnded(BaseInstance *instance) -{ - ui->btnKillMinecraft->setEnabled(false); - - // TODO: Might need an option to forcefully close, even on an error - if(instance->settings().get("AutoCloseConsole").toBool()) - { - // TODO: Check why this doesn't work - if (!proc->exitCode()) this->close(); - } -} diff --git a/gui/consolewindow.h b/gui/consolewindow.h deleted file mode 100644 index e8790c92..00000000 --- a/gui/consolewindow.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef CONSOLEWINDOW_H -#define CONSOLEWINDOW_H - -#include -#include "logic/MinecraftProcess.h" - -namespace Ui { -class ConsoleWindow; -} - -class ConsoleWindow : public QDialog -{ - Q_OBJECT - -public: - explicit ConsoleWindow(MinecraftProcess *proc, QWidget *parent = 0); - ~ConsoleWindow(); - - /** - * @brief specify if the window is allowed to close - * @param mayclose - * used to keep it alive while MC runs - */ - void setMayClose(bool mayclose); - -public slots: - /** - * @brief write a string - * @param data the string - * @param mode the WriteMode - * lines have to be put through this as a whole! - */ - void write(QString data, MessageLevel::Enum level=MessageLevel::MultiMC); - - /** - * @brief write a colored paragraph - * @param data the string - * @param color the css color name - * this will only insert a single paragraph. - * \n are ignored. a real \n is always appended. - */ - void writeColor(QString data, const char *color=nullptr); - - /** - * @brief clear the text widget - */ - void clear(); - -private slots: - void on_closeButton_clicked(); - void on_btnKillMinecraft_clicked(); - void onEnded(BaseInstance *instance); - -protected: - void closeEvent(QCloseEvent *); - -private: - Ui::ConsoleWindow *ui; - MinecraftProcess *proc; - bool m_mayclose; -}; - -#endif // CONSOLEWINDOW_H diff --git a/gui/consolewindow.ui b/gui/consolewindow.ui deleted file mode 100644 index 8dc80015..00000000 --- a/gui/consolewindow.ui +++ /dev/null @@ -1,85 +0,0 @@ - - - ConsoleWindow - - - - 0 - 0 - 600 - 400 - - - - MultiMC Console - - - - 0 - - - 0 - - - 0 - - - - - - 10 - - - - false - - - true - - - - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - false - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Kill Minecraft - - - - - - - Close - - - - - - - - - - diff --git a/gui/dialogs/AboutDialog.cpp b/gui/dialogs/AboutDialog.cpp new file mode 100644 index 00000000..58d61dd0 --- /dev/null +++ b/gui/dialogs/AboutDialog.cpp @@ -0,0 +1,37 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AboutDialog.h" +#include "ui_AboutDialog.h" +#include +#include "MultiMC.h" +#include "gui/Platform.h" + +AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + + ui->icon->setPixmap(QIcon(":/icons/multimc/scalable/apps/multimc.svg").pixmap(64)); + ui->title->setText("MultiMC " + MMC->version().toString()); + connect(ui->closeButton, SIGNAL(clicked()), SLOT(close())); + + MMC->connect(ui->aboutQt, SIGNAL(clicked()), SLOT(aboutQt())); +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} diff --git a/gui/dialogs/AboutDialog.h b/gui/dialogs/AboutDialog.h new file mode 100644 index 00000000..9d747bac --- /dev/null +++ b/gui/dialogs/AboutDialog.h @@ -0,0 +1,35 @@ +/* Copyright 2013 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 + +namespace Ui +{ +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = 0); + ~AboutDialog(); + +private: + Ui::AboutDialog *ui; +}; diff --git a/gui/dialogs/AboutDialog.ui b/gui/dialogs/AboutDialog.ui new file mode 100644 index 00000000..0a189d9c --- /dev/null +++ b/gui/dialogs/AboutDialog.ui @@ -0,0 +1,316 @@ + + + AboutDialog + + + + 0 + 0 + 450 + 429 + + + + + 450 + 400 + + + + Dialog + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 64 + 64 + + + + + 64 + 64 + + + + + + + :/icons/multimc/scalable/apps/multimc.svg + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 15 + + + + MultiMC + + + Qt::AlignCenter + + + + + + + + + 0 + 0 + 432 + 179 + + + + About + + + + + + <html><head/><body><p>MultiMC is a custom launcher that makes managing Minecraft easier by allowing you to have multiple instances of Minecraft at once.</p></body></html> + + + Qt::AlignCenter + + + true + + + + + + + + 8 + true + + + + © 2013 MultiMC Contributors + + + Qt::AlignCenter + + + + + + + + 10 + + + + <html><head/><body><p><a href="http://github.com/Forkk/MultiMC5"><span style=" text-decoration: underline; color:#0000ff;">http://github.com/MultiMC/MultiMC5</span></a></p></body></html> + + + Qt::AlignCenter + + + + + + + + + 0 + 0 + 98 + 120 + + + + Credits + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Andrew Okin &lt;</span><a href="mailto:forkk@forkk.net"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">forkk@forkk.net</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Petr Mrázek &lt;</span><a href="mailto:peterix@gmail.com"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">peterix@gmail.com</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Orochimarufan &lt;</span><a href="mailto:orochimarufan.x3@gmail.com"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">orochimarufan.x3@gmail.com</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">TakSuyu &lt;</span><a href="mailto:taksuyu@gmail.com"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">taksuyu@gmail.com</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Sky (Drayshak) &lt;</span><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">multimc@bunnies.cc</span><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Kilobyte &lt;</span><a href="mailto:stiepen22@gmx.de"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">stiepen22@gmx.de</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p></body></html> + + + + + + + No Language file loaded. + + + true + + + + + + + + + 0 + 0 + 98 + 88 + + + + License + + + + + + + 0 + 0 + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Copyright 2012 MultiMC Contributors</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">you may not use this file except in compliance with the License.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">You may obtain a copy of the License at</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> http://www.apache.org/licenses/LICENSE-2.0</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Unless required by applicable law or agreed to in writing, software</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">See the License for the specific language governing permissions and</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">limitations under the License.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">MultiMC uses QSLog, </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Copyright (c) 2010, Razvan Petru</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">All rights reserved.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Redistribution and use in source and binary forms, with or without modification,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">are permitted provided that the following conditions are met:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* Redistributions of source code must retain the above copyright notice, this</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> list of conditions and the following disclaimer.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* Redistributions in binary form must reproduce the above copyright notice, this</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> list of conditions and the following disclaimer in the documentation and/or other</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> materials provided with the distribution.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* The name of the contributors may not be used to endorse or promote products</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> derived from this software without specific prior written permission.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">OF THE POSSIBILITY OF SUCH DAMAGE.</span></p></body></html> + + + + + + + + + + + + + false + + + About Qt + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + + + + + diff --git a/gui/dialogs/CopyInstanceDialog.cpp b/gui/dialogs/CopyInstanceDialog.cpp new file mode 100644 index 00000000..4d588a1e --- /dev/null +++ b/gui/dialogs/CopyInstanceDialog.cpp @@ -0,0 +1,84 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "MultiMC.h" +#include "CopyInstanceDialog.h" +#include "ui_CopyInstanceDialog.h" + +#include "gui/Platform.h" +#include "gui/dialogs/VersionSelectDialog.h" +#include "gui/dialogs/ProgressDialog.h" +#include "gui/dialogs/IconPickerDialog.h" + +#include "logic/InstanceFactory.h" +#include "logic/BaseVersion.h" +#include "logic/lists/IconList.h" +#include "logic/lists/MinecraftVersionList.h" +#include "logic/tasks/Task.h" +#include "logic/BaseInstance.h" + +CopyInstanceDialog::CopyInstanceDialog(BaseInstance *original, QWidget *parent) + : m_original(original), QDialog(parent), ui(new Ui::CopyInstanceDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + resize(minimumSizeHint()); + layout()->setSizeConstraint(QLayout::SetFixedSize); + + InstIconKey = original->iconKey(); + ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); + ui->instNameTextBox->setText(original->name()); + ui->instNameTextBox->setFocus(); +} + +CopyInstanceDialog::~CopyInstanceDialog() +{ + delete ui; +} + +void CopyInstanceDialog::updateDialogState() +{ + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty()); +} + +QString CopyInstanceDialog::instName() const +{ + return ui->instNameTextBox->text(); +} + +QString CopyInstanceDialog::iconKey() const +{ + return InstIconKey; +} + +void CopyInstanceDialog::on_iconButton_clicked() +{ + IconPickerDialog dlg(this); + dlg.exec(InstIconKey); + + if (dlg.result() == QDialog::Accepted) + { + InstIconKey = dlg.selectedIconKey; + ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); + } +} + +void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) +{ + updateDialogState(); +} diff --git a/gui/dialogs/CopyInstanceDialog.h b/gui/dialogs/CopyInstanceDialog.h new file mode 100644 index 00000000..7ab366e2 --- /dev/null +++ b/gui/dialogs/CopyInstanceDialog.h @@ -0,0 +1,50 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "logic/BaseVersion.h" + +class BaseInstance; + +namespace Ui +{ +class CopyInstanceDialog; +} + +class CopyInstanceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CopyInstanceDialog(BaseInstance *original, QWidget *parent = 0); + ~CopyInstanceDialog(); + + void updateDialogState(); + + QString instName() const; + QString iconKey() const; + +private +slots: + void on_iconButton_clicked(); + void on_instNameTextBox_textChanged(const QString &arg1); + +private: + Ui::CopyInstanceDialog *ui; + QString InstIconKey; + BaseInstance *m_original; +}; diff --git a/gui/dialogs/CopyInstanceDialog.ui b/gui/dialogs/CopyInstanceDialog.ui new file mode 100644 index 00000000..dd7ce641 --- /dev/null +++ b/gui/dialogs/CopyInstanceDialog.ui @@ -0,0 +1,134 @@ + + + CopyInstanceDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 345 + 205 + + + + Copy Instance + + + + :/icons/toolbar/copy:/icons/toolbar/copy + + + true + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + :/icons/instances/infinity:/icons/instances/infinity + + + + 80 + 80 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Name + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + CopyInstanceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CopyInstanceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/CustomMessageBox.cpp b/gui/dialogs/CustomMessageBox.cpp new file mode 100644 index 00000000..1d2ab58a --- /dev/null +++ b/gui/dialogs/CustomMessageBox.cpp @@ -0,0 +1,34 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CustomMessageBox.h" + +namespace CustomMessageBox +{ +QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text, + QMessageBox::Icon icon, QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) +{ + QMessageBox *messageBox = new QMessageBox(parent); + messageBox->setWindowTitle(title); + messageBox->setText(text); + messageBox->setStandardButtons(buttons); + messageBox->setDefaultButton(defaultButton); + messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); + messageBox->setIcon(icon); + + return messageBox; +} +} diff --git a/gui/dialogs/CustomMessageBox.h b/gui/dialogs/CustomMessageBox.h new file mode 100644 index 00000000..b08b9f57 --- /dev/null +++ b/gui/dialogs/CustomMessageBox.h @@ -0,0 +1,26 @@ +/* Copyright 2013 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 + +namespace CustomMessageBox +{ +QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text, + QMessageBox::Icon icon = QMessageBox::NoIcon, + QMessageBox::StandardButtons buttons = QMessageBox::Ok, + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); +} diff --git a/gui/dialogs/EditNotesDialog.cpp b/gui/dialogs/EditNotesDialog.cpp new file mode 100644 index 00000000..cd52e694 --- /dev/null +++ b/gui/dialogs/EditNotesDialog.cpp @@ -0,0 +1,42 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "EditNotesDialog.h" +#include "ui_EditNotesDialog.h" +#include "gui/Platform.h" + +#include +#include + +EditNotesDialog::EditNotesDialog(QString notes, QString name, QWidget *parent) + : m_instance_notes(notes), m_instance_name(name), QDialog(parent), + ui(new Ui::EditNotesDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + ui->noteEditor->setText(notes); + setWindowTitle(tr("Edit notes of %1").arg(m_instance_name)); + // connect(ui->closeButton, SIGNAL(clicked()), SLOT(close())); +} + +EditNotesDialog::~EditNotesDialog() +{ + delete ui; +} + +QString EditNotesDialog::getText() +{ + return ui->noteEditor->toPlainText(); +} diff --git a/gui/dialogs/EditNotesDialog.h b/gui/dialogs/EditNotesDialog.h new file mode 100644 index 00000000..b74558c4 --- /dev/null +++ b/gui/dialogs/EditNotesDialog.h @@ -0,0 +1,38 @@ +/* Copyright 2013 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 + +namespace Ui +{ +class EditNotesDialog; +} + +class EditNotesDialog : public QDialog +{ + Q_OBJECT + +public: + explicit EditNotesDialog(QString notes, QString name, QWidget *parent = 0); + ~EditNotesDialog(); + QString getText(); + +private: + Ui::EditNotesDialog *ui; + QString m_instance_name; + QString m_instance_notes; +}; diff --git a/gui/dialogs/EditNotesDialog.ui b/gui/dialogs/EditNotesDialog.ui new file mode 100644 index 00000000..487dfb84 --- /dev/null +++ b/gui/dialogs/EditNotesDialog.ui @@ -0,0 +1,77 @@ + + + EditNotesDialog + + + + 0 + 0 + 459 + 399 + + + + Edit Notes + + + + + + Qt::ScrollBarAlwaysOn + + + false + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + EditNotesDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EditNotesDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/IconPickerDialog.cpp b/gui/dialogs/IconPickerDialog.cpp new file mode 100644 index 00000000..99d6dc9a --- /dev/null +++ b/gui/dialogs/IconPickerDialog.cpp @@ -0,0 +1,156 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "MultiMC.h" + +#include "IconPickerDialog.h" +#include "ui_IconPickerDialog.h" + +#include "gui/Platform.h" +#include "gui/widgets/InstanceDelegate.h" + +#include "logic/lists/IconList.h" + +IconPickerDialog::IconPickerDialog(QWidget *parent) + : QDialog(parent), ui(new Ui::IconPickerDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + setWindowModality(Qt::WindowModal); + + auto contentsWidget = ui->iconView; + contentsWidget->setViewMode(QListView::IconMode); + contentsWidget->setFlow(QListView::LeftToRight); + contentsWidget->setIconSize(QSize(48, 48)); + contentsWidget->setMovement(QListView::Static); + contentsWidget->setResizeMode(QListView::Adjust); + contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection); + contentsWidget->setSpacing(5); + contentsWidget->setWordWrap(false); + contentsWidget->setWrapping(true); + contentsWidget->setUniformItemSizes(true); + contentsWidget->setTextElideMode(Qt::ElideRight); + contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + contentsWidget->setItemDelegate(new ListViewDelegate()); + + // contentsWidget->setAcceptDrops(true); + contentsWidget->setDropIndicatorShown(true); + contentsWidget->viewport()->setAcceptDrops(true); + contentsWidget->setDragDropMode(QAbstractItemView::DropOnly); + contentsWidget->setDefaultDropAction(Qt::CopyAction); + + contentsWidget->installEventFilter(this); + + contentsWidget->setModel(MMC->icons().get()); + + auto buttonAdd = ui->buttonBox->addButton(tr("Add Icon"), QDialogButtonBox::ResetRole); + auto buttonRemove = + ui->buttonBox->addButton(tr("Remove Icon"), QDialogButtonBox::ResetRole); + + connect(buttonAdd, SIGNAL(clicked(bool)), SLOT(addNewIcon())); + connect(buttonRemove, SIGNAL(clicked(bool)), SLOT(removeSelectedIcon())); + + connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex))); + + connect(contentsWidget->selectionModel(), + SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + SLOT(selectionChanged(QItemSelection, QItemSelection))); +} +bool IconPickerDialog::eventFilter(QObject *obj, QEvent *evt) +{ + if (obj != ui->iconView) + return QDialog::eventFilter(obj, evt); + if (evt->type() != QEvent::KeyPress) + { + return QDialog::eventFilter(obj, evt); + } + QKeyEvent *keyEvent = static_cast(evt); + switch (keyEvent->key()) + { + case Qt::Key_Delete: + removeSelectedIcon(); + return true; + case Qt::Key_Plus: + addNewIcon(); + return true; + default: + break; + } + return QDialog::eventFilter(obj, evt); +} + +void IconPickerDialog::addNewIcon() +{ + //: The title of the select icons open file dialog + QString selectIcons = tr("Select Icons"); + //: The type of icon files + QStringList fileNames = QFileDialog::getOpenFileNames(this, selectIcons, QString(), + tr("Icons") + "(*.png *.jpg *.jpeg)"); + MMC->icons()->installIcons(fileNames); +} + +void IconPickerDialog::removeSelectedIcon() +{ + MMC->icons()->deleteIcon(selectedIconKey); +} + +void IconPickerDialog::activated(QModelIndex index) +{ + selectedIconKey = index.data(Qt::UserRole).toString(); + accept(); +} + +void IconPickerDialog::selectionChanged(QItemSelection selected, QItemSelection deselected) +{ + if (selected.empty()) + return; + + QString key = selected.first().indexes().first().data(Qt::UserRole).toString(); + if (!key.isEmpty()) + selectedIconKey = key; +} + +int IconPickerDialog::exec(QString selection) +{ + auto list = MMC->icons(); + auto contentsWidget = ui->iconView; + selectedIconKey = selection; + + int index_nr = list->getIconIndex(selection); + auto model_index = list->index(index_nr); + contentsWidget->selectionModel()->select( + model_index, QItemSelectionModel::Current | QItemSelectionModel::Select); + + QMetaObject::invokeMethod(this, "delayed_scroll", Qt::QueuedConnection, + Q_ARG(QModelIndex, model_index)); + return QDialog::exec(); +} + +void IconPickerDialog::delayed_scroll(QModelIndex model_index) +{ + auto contentsWidget = ui->iconView; + contentsWidget->scrollTo(model_index); +} + +IconPickerDialog::~IconPickerDialog() +{ + delete ui; +} diff --git a/gui/dialogs/IconPickerDialog.h b/gui/dialogs/IconPickerDialog.h new file mode 100644 index 00000000..f00c2388 --- /dev/null +++ b/gui/dialogs/IconPickerDialog.h @@ -0,0 +1,48 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include + +namespace Ui +{ +class IconPickerDialog; +} + +class IconPickerDialog : public QDialog +{ + Q_OBJECT + +public: + explicit IconPickerDialog(QWidget *parent = 0); + ~IconPickerDialog(); + int exec(QString selection); + QString selectedIconKey; + +protected: + virtual bool eventFilter(QObject *, QEvent *); + +private: + Ui::IconPickerDialog *ui; + +private +slots: + void selectionChanged(QItemSelection, QItemSelection); + void activated(QModelIndex); + void delayed_scroll(QModelIndex); + void addNewIcon(); + void removeSelectedIcon(); +}; diff --git a/gui/dialogs/IconPickerDialog.ui b/gui/dialogs/IconPickerDialog.ui new file mode 100644 index 00000000..c548edfb --- /dev/null +++ b/gui/dialogs/IconPickerDialog.ui @@ -0,0 +1,67 @@ + + + IconPickerDialog + + + + 0 + 0 + 676 + 555 + + + + Pick icon + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + IconPickerDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + IconPickerDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/InstanceSettings.cpp b/gui/dialogs/InstanceSettings.cpp new file mode 100644 index 00000000..57dd6a81 --- /dev/null +++ b/gui/dialogs/InstanceSettings.cpp @@ -0,0 +1,180 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Andrew Okin + * Peterix + * Orochimarufan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "InstanceSettings.h" +#include "ui_InstanceSettings.h" +#include "gui/Platform.h" + +InstanceSettings::InstanceSettings(SettingsObject *obj, QWidget *parent) + : m_obj(obj), QDialog(parent), ui(new Ui::InstanceSettings) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + loadSettings(); +} + +InstanceSettings::~InstanceSettings() +{ + delete ui; +} + +void InstanceSettings::showEvent(QShowEvent *ev) +{ + QDialog::showEvent(ev); + adjustSize(); +} + +void InstanceSettings::on_customCommandsGroupBox_toggled(bool state) +{ + ui->labelCustomCmdsDescription->setEnabled(state); +} + +void InstanceSettings::on_buttonBox_accepted() +{ + applySettings(); + accept(); +} + +void InstanceSettings::on_buttonBox_rejected() +{ + reject(); +} + +void InstanceSettings::applySettings() +{ + // Console + bool console = ui->consoleSettingsBox->isChecked(); + m_obj->set("OverrideConsole", console); + if (console) + { + m_obj->set("ShowConsole", ui->showConsoleCheck->isChecked()); + m_obj->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); + } + else + { + m_obj->reset("ShowConsole"); + m_obj->reset("AutoCloseConsole"); + } + + // Window Size + bool window = ui->windowSizeGroupBox->isChecked(); + m_obj->set("OverrideWindow", window); + if (window) + { + m_obj->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); + m_obj->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); + m_obj->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); + } + else + { + m_obj->reset("LaunchMaximized"); + m_obj->reset("MinecraftWinWidth"); + m_obj->reset("MinecraftWinHeight"); + } + + // Auto Login + bool login = ui->accountSettingsGroupBox->isChecked(); + m_obj->set("OverrideLogin", login); + if (login) + { + m_obj->set("AutoLogin", ui->autoLoginChecBox->isChecked()); + } + else + { + m_obj->reset("AutoLogin"); + } + + // Memory + bool memory = ui->memoryGroupBox->isChecked(); + m_obj->set("OverrideMemory", memory); + if (memory) + { + m_obj->set("MinMemAlloc", ui->minMemSpinBox->value()); + m_obj->set("MaxMemAlloc", ui->maxMemSpinBox->value()); + m_obj->set("PermGen", ui->permGenSpinBox->value()); + } + else + { + m_obj->reset("MinMemAlloc"); + m_obj->reset("MaxMemAlloc"); + m_obj->reset("PermGen"); + } + + // Java Settings + bool java = ui->javaSettingsGroupBox->isChecked(); + m_obj->set("OverrideJava", java); + if (java) + { + m_obj->set("JavaPath", ui->javaPathTextBox->text()); + m_obj->set("JvmArgs", ui->jvmArgsTextBox->text()); + } + else + { + m_obj->reset("JavaPath"); + m_obj->reset("JvmArgs"); + } + + // Custom Commands + bool custcmd = ui->customCommandsGroupBox->isChecked(); + m_obj->set("OverrideCommands", custcmd); + if (custcmd) + { + m_obj->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); + m_obj->set("PostExitCommand", ui->postExitCmdTextBox->text()); + } + else + { + m_obj->reset("PreLaunchCommand"); + m_obj->reset("PostExitCommand"); + } +} + +void InstanceSettings::loadSettings() +{ + // Console + ui->consoleSettingsBox->setChecked(m_obj->get("OverrideConsole").toBool()); + ui->showConsoleCheck->setChecked(m_obj->get("ShowConsole").toBool()); + ui->autoCloseConsoleCheck->setChecked(m_obj->get("AutoCloseConsole").toBool()); + + // Window Size + ui->windowSizeGroupBox->setChecked(m_obj->get("OverrideWindow").toBool()); + ui->maximizedCheckBox->setChecked(m_obj->get("LaunchMaximized").toBool()); + ui->windowWidthSpinBox->setValue(m_obj->get("MinecraftWinWidth").toInt()); + ui->windowHeightSpinBox->setValue(m_obj->get("MinecraftWinHeight").toInt()); + + // Auto Login + ui->accountSettingsGroupBox->setChecked(m_obj->get("OverrideLogin").toBool()); + ui->autoLoginChecBox->setChecked(m_obj->get("AutoLogin").toBool()); + + // Memory + ui->memoryGroupBox->setChecked(m_obj->get("OverrideMemory").toBool()); + ui->minMemSpinBox->setValue(m_obj->get("MinMemAlloc").toInt()); + ui->maxMemSpinBox->setValue(m_obj->get("MaxMemAlloc").toInt()); + ui->permGenSpinBox->setValue(m_obj->get("PermGen").toInt()); + + // Java Settings + ui->javaSettingsGroupBox->setChecked(m_obj->get("OverrideJava").toBool()); + ui->javaPathTextBox->setText(m_obj->get("JavaPath").toString()); + ui->jvmArgsTextBox->setText(m_obj->get("JvmArgs").toString()); + + // Custom Commands + ui->customCommandsGroupBox->setChecked(m_obj->get("OverrideCommands").toBool()); + ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString()); + ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString()); +} diff --git a/gui/dialogs/InstanceSettings.h b/gui/dialogs/InstanceSettings.h new file mode 100644 index 00000000..452e7a58 --- /dev/null +++ b/gui/dialogs/InstanceSettings.h @@ -0,0 +1,50 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "settingsobject.h" + +namespace Ui +{ +class InstanceSettings; +} + +class InstanceSettings : public QDialog +{ + Q_OBJECT + +public: + explicit InstanceSettings(SettingsObject *s, QWidget *parent = 0); + ~InstanceSettings(); + + void updateCheckboxStuff(); + + void applySettings(); + void loadSettings(); + +protected: + virtual void showEvent(QShowEvent *); +private +slots: + void on_customCommandsGroupBox_toggled(bool arg1); + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); + +private: + Ui::InstanceSettings *ui; + SettingsObject *m_obj; +}; diff --git a/gui/dialogs/InstanceSettings.ui b/gui/dialogs/InstanceSettings.ui new file mode 100644 index 00000000..b536e9ff --- /dev/null +++ b/gui/dialogs/InstanceSettings.ui @@ -0,0 +1,422 @@ + + + InstanceSettings + + + + 0 + 0 + 526 + 590 + + + + + + + + + + QTabWidget::Rounded + + + 0 + + + + Minecraft + + + + + + true + + + Window Size + + + true + + + false + + + + + + Start Minecraft maximized? + + + + + + + + + Window height: + + + + + + + Window width: + + + + + + + 854 + + + 65536 + + + 1 + + + 854 + + + + + + + 480 + + + 65536 + + + 480 + + + + + + + + + + + + true + + + Console Settings + + + true + + + false + + + + + + Show console while the game is running? + + + + + + + Automatically close console when the game quits? + + + + + + + + + + true + + + Account Settings + + + true + + + false + + + + + + false + + + Login automatically when an instance icon is double clicked? + + + false + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Java + + + + + + true + + + Memory + + + true + + + false + + + + + + 512 + + + 65536 + + + 128 + + + 1024 + + + + + + + Minimum memory allocation: + + + + + + + Maximum memory allocation: + + + + + + + 256 + + + 65536 + + + 128 + + + 256 + + + + + + + 64 + + + 999999999 + + + 8 + + + 64 + + + + + + + PermGen: + + + + + + + + + + true + + + Java Settings + + + true + + + false + + + + + + Java path: + + + + + + + + + + JVM arguments: + + + + + + + Auto-detect + + + + + + + + + + + + + true + + + Custom Commands + + + true + + + false + + + + + + + + + Post-exit command: + + + + + + + Pre-launch command: + + + + + + + + + + + + + false + + + + 0 + 0 + + + + Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + settingsTabs + buttonBox + windowSizeGroupBox + maximizedCheckBox + windowWidthSpinBox + windowHeightSpinBox + consoleSettingsBox + showConsoleCheck + autoCloseConsoleCheck + accountSettingsGroupBox + autoLoginChecBox + memoryGroupBox + minMemSpinBox + maxMemSpinBox + permGenSpinBox + javaSettingsGroupBox + javaPathTextBox + pushButton + jvmArgsTextBox + customCommandsGroupBox + preLaunchCmdTextBox + postExitCmdTextBox + + + + diff --git a/gui/dialogs/LegacyModEditDialog.cpp b/gui/dialogs/LegacyModEditDialog.cpp new file mode 100644 index 00000000..25a1c616 --- /dev/null +++ b/gui/dialogs/LegacyModEditDialog.cpp @@ -0,0 +1,393 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiMC.h" +#include "LegacyModEditDialog.h" +#include "ModEditDialogCommon.h" +#include "VersionSelectDialog.h" +#include "ProgressDialog.h" +#include "ui_LegacyModEditDialog.h" +#include "logic/ModList.h" +#include "logic/lists/ForgeVersionList.h" +#include "gui/Platform.h" + +#include +#include +//#include +#include +#include +#include + +LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) + : m_inst(inst), QDialog(parent), ui(new Ui::LegacyModEditDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + + // Jar mods + { + ensureFolderPathExists(m_inst->jarModsDir()); + m_jarmods = m_inst->jarModList(); + ui->jarModsTreeView->setModel(m_jarmods.get()); +#ifndef Q_OS_LINUX + // FIXME: internal DnD causes segfaults later + ui->jarModsTreeView->setDragDropMode(QAbstractItemView::DragDrop); + // FIXME: DnD is glitched with contiguous (we move only first item in selection) + ui->jarModsTreeView->setSelectionMode(QAbstractItemView::SingleSelection); +#endif + ui->jarModsTreeView->installEventFilter(this); + m_jarmods->startWatching(); + auto smodel = ui->jarModsTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(jarCurrent(QModelIndex, QModelIndex))); + } + // Core mods + { + ensureFolderPathExists(m_inst->coreModsDir()); + m_coremods = m_inst->coreModList(); + ui->coreModsTreeView->setModel(m_coremods.get()); + ui->coreModsTreeView->installEventFilter(this); + m_coremods->startWatching(); + auto smodel = ui->coreModsTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(coreCurrent(QModelIndex, QModelIndex))); + } + // Loader mods + { + ensureFolderPathExists(m_inst->loaderModsDir()); + m_mods = m_inst->loaderModList(); + ui->loaderModTreeView->setModel(m_mods.get()); + ui->loaderModTreeView->installEventFilter(this); + m_mods->startWatching(); + auto smodel = ui->loaderModTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(loaderCurrent(QModelIndex, QModelIndex))); + } + // texture packs + { + ensureFolderPathExists(m_inst->texturePacksDir()); + m_texturepacks = m_inst->texturePackList(); + ui->texPackTreeView->setModel(m_texturepacks.get()); + ui->texPackTreeView->installEventFilter(this); + m_texturepacks->startWatching(); + } +} + +LegacyModEditDialog::~LegacyModEditDialog() +{ + m_mods->stopWatching(); + m_coremods->stopWatching(); + m_jarmods->stopWatching(); + m_texturepacks->stopWatching(); + delete ui; +} + +bool LegacyModEditDialog::coreListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmCoreBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addCoreBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); +} + +bool LegacyModEditDialog::jarListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Up: + { + if (keyEvent->modifiers() & Qt::ControlModifier) + { + on_moveJarUpBtn_clicked(); + return true; + } + break; + } + case Qt::Key_Down: + { + if (keyEvent->modifiers() & Qt::ControlModifier) + { + on_moveJarDownBtn_clicked(); + return true; + } + break; + } + case Qt::Key_Delete: + on_rmJarBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addJarBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->jarModsTreeView, keyEvent); +} + +bool LegacyModEditDialog::loaderListFilter(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 QDialog::eventFilter(ui->loaderModTreeView, keyEvent); +} + +bool LegacyModEditDialog::texturePackListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmTexPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addTexPackBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->texPackTreeView, keyEvent); +} + +bool LegacyModEditDialog::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QDialog::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->jarModsTreeView) + return jarListFilter(keyEvent); + if (obj == ui->coreModsTreeView) + return coreListFilter(keyEvent); + if (obj == ui->loaderModTreeView) + return loaderListFilter(keyEvent); + if (obj == ui->texPackTreeView) + return texturePackListFilter(keyEvent); + return QDialog::eventFilter(obj, ev); +} + +void LegacyModEditDialog::on_addCoreBtn_clicked() +{ + //: Title of core mod selection dialog + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); + for (auto filename : fileNames) + { + m_coremods->stopWatching(); + m_coremods->installMod(QFileInfo(filename)); + m_coremods->startWatching(); + } +} +void LegacyModEditDialog::on_addForgeBtn_clicked() +{ + VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); + vselect.setFilter(1, m_inst->intendedVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ForgeVersionPtr forge = + std::dynamic_pointer_cast(vselect.selectedVersion()); + if (!forge) + return; + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); + if (entry->stale) + { + NetJob *fjob = new NetJob("Forge download"); + fjob->addNetAction(CacheDownload::make(forge->universal_url, entry)); + ProgressDialog dlg(this); + dlg.exec(fjob); + if (dlg.result() == QDialog::Accepted) + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + else + { + // failed to download forge :/ + } + } + else + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + } +} +void LegacyModEditDialog::on_addJarBtn_clicked() +{ + //: Title of jar mod selection dialog + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Jar Mods")); + for (auto filename : fileNames) + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(filename)); + m_jarmods->startWatching(); + } +} +void LegacyModEditDialog::on_addModBtn_clicked() +{ + //: Title of regular mod selection dialog + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Loader Mods")); + for (auto filename : fileNames) + { + m_mods->stopWatching(); + m_mods->installMod(QFileInfo(filename)); + m_mods->startWatching(); + } +} +void LegacyModEditDialog::on_addTexPackBtn_clicked() +{ + //: Title of texture pack selection dialog + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Texture Packs")); + for (auto filename : fileNames) + { + m_texturepacks->stopWatching(); + m_texturepacks->installMod(QFileInfo(filename)); + m_texturepacks->startWatching(); + } +} + +void LegacyModEditDialog::on_moveJarDownBtn_clicked() +{ + int first, last; + auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + + m_jarmods->moveModsDown(first, last); +} +void LegacyModEditDialog::on_moveJarUpBtn_clicked() +{ + int first, last; + auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_jarmods->moveModsUp(first, last); +} +void LegacyModEditDialog::on_rmCoreBtn_clicked() +{ + int first, last; + auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_coremods->stopWatching(); + m_coremods->deleteMods(first, last); + m_coremods->startWatching(); +} +void LegacyModEditDialog::on_rmJarBtn_clicked() +{ + int first, last; + auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_jarmods->stopWatching(); + m_jarmods->deleteMods(first, last); + m_jarmods->startWatching(); +} +void LegacyModEditDialog::on_rmModBtn_clicked() +{ + int first, last; + auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_mods->stopWatching(); + m_mods->deleteMods(first, last); + m_mods->startWatching(); +} +void LegacyModEditDialog::on_rmTexPackBtn_clicked() +{ + int first, last; + auto list = ui->texPackTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_texturepacks->stopWatching(); + m_texturepacks->deleteMods(first, last); + m_texturepacks->startWatching(); +} +void LegacyModEditDialog::on_viewCoreBtn_clicked() +{ + openDirInDefaultProgram(m_inst->coreModsDir(), true); +} +void LegacyModEditDialog::on_viewModBtn_clicked() +{ + openDirInDefaultProgram(m_inst->loaderModsDir(), true); +} +void LegacyModEditDialog::on_viewTexPackBtn_clicked() +{ + openDirInDefaultProgram(m_inst->texturePacksDir(), true); +} + +void LegacyModEditDialog::on_buttonBox_rejected() +{ + close(); +} + +void LegacyModEditDialog::jarCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->jarMIFrame->clear(); + return; + } + int row = current.row(); + Mod &m = m_jarmods->operator[](row); + ui->jarMIFrame->updateWithMod(m); +} + +void LegacyModEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->coreMIFrame->clear(); + return; + } + int row = current.row(); + Mod &m = m_coremods->operator[](row); + ui->coreMIFrame->updateWithMod(m); +} + +void LegacyModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->loaderMIFrame->clear(); + return; + } + int row = current.row(); + Mod &m = m_mods->operator[](row); + ui->loaderMIFrame->updateWithMod(m); +} diff --git a/gui/dialogs/LegacyModEditDialog.h b/gui/dialogs/LegacyModEditDialog.h new file mode 100644 index 00000000..d5582aef --- /dev/null +++ b/gui/dialogs/LegacyModEditDialog.h @@ -0,0 +1,78 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "logic/LegacyInstance.h" +#include + +namespace Ui +{ +class LegacyModEditDialog; +} + +class LegacyModEditDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LegacyModEditDialog(LegacyInstance *inst, QWidget *parent = 0); + ~LegacyModEditDialog(); + +private +slots: + + void on_addJarBtn_clicked(); + void on_rmJarBtn_clicked(); + void on_addForgeBtn_clicked(); + void on_moveJarUpBtn_clicked(); + void on_moveJarDownBtn_clicked(); + + void on_addCoreBtn_clicked(); + void on_rmCoreBtn_clicked(); + void on_viewCoreBtn_clicked(); + + void on_addModBtn_clicked(); + void on_rmModBtn_clicked(); + void on_viewModBtn_clicked(); + + void on_addTexPackBtn_clicked(); + void on_rmTexPackBtn_clicked(); + void on_viewTexPackBtn_clicked(); + + // Questionable: SettingsDialog doesn't need this for some reason? + void on_buttonBox_rejected(); + + void jarCurrent(QModelIndex current, QModelIndex previous); + void coreCurrent(QModelIndex current, QModelIndex previous); + void loaderCurrent(QModelIndex current, QModelIndex previous); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + bool jarListFilter(QKeyEvent *ev); + bool coreListFilter(QKeyEvent *ev); + bool loaderListFilter(QKeyEvent *ev); + bool texturePackListFilter(QKeyEvent *ev); + +private: + Ui::LegacyModEditDialog *ui; + std::shared_ptr m_mods; + std::shared_ptr m_coremods; + std::shared_ptr m_jarmods; + std::shared_ptr m_texturepacks; + LegacyInstance *m_inst; + NetJobPtr forgeJob; +}; diff --git a/gui/dialogs/LegacyModEditDialog.ui b/gui/dialogs/LegacyModEditDialog.ui new file mode 100644 index 00000000..47db0079 --- /dev/null +++ b/gui/dialogs/LegacyModEditDialog.ui @@ -0,0 +1,321 @@ + + + LegacyModEditDialog + + + + 0 + 0 + 540 + 420 + + + + Dialog + + + + + + 0 + + + + Jar Mods + + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + MCForge + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Move &Up + + + + + + + Move &Down + + + + + + + + + + + QFrame::Plain + + + + + + + + Core Mods + + + + + + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + Loader Mods + + + + + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + false + + + Texture Packs + + + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + + QDialogButtonBox::Close + + + + + + + + ModListView + QTreeView +
gui/widgets/ModListView.h
+
+ + MCModInfoFrame + QFrame +
gui/widgets/MCModInfoFrame.h
+ 1 +
+
+ + +
diff --git a/gui/dialogs/LoginDialog.cpp b/gui/dialogs/LoginDialog.cpp new file mode 100644 index 00000000..19c6437d --- /dev/null +++ b/gui/dialogs/LoginDialog.cpp @@ -0,0 +1,252 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LoginDialog.h" +#include "ui_LoginDialog.h" +#include "keyring.h" +#include "gui/Platform.h" +#include "MultiMC.h" + +#include +#include +#include +#include +#include "logic/net/HttpMetaCache.h" +#include "logger/QsLog.h" + +LoginDialog::LoginDialog(QWidget *parent, const QString &loginErrMsg) + : QDialog(parent), ui(new Ui::LoginDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + + //: Use offline mode one time + offlineButton = new QPushButton(tr("Offline Once")); + + ui->loginButtonBox->addButton(offlineButton, QDialogButtonBox::ActionRole); + + blockToggles = false; + isOnline_ = true; + onlineForced = false; + + //: The username during login (placeholder) + ui->usernameTextBox->lineEdit()->setPlaceholderText(tr("Name")); + + connect(ui->usernameTextBox, SIGNAL(currentTextChanged(QString)), this, + SLOT(userTextChanged(QString))); + connect(ui->forgetButton, SIGNAL(clicked(bool)), this, SLOT(forgetCurrentUser())); + connect(offlineButton, SIGNAL(clicked(bool)), this, SLOT(launchOffline())); + + if (loginErrMsg.isEmpty()) + ui->loginErrorLabel->setVisible(false); + else + { + ui->loginErrorLabel->setVisible(true); + ui->loginErrorLabel->setText( + QString("%1").arg(loginErrMsg)); + } + + ui->lblFace->setVisible(false); + + resize(minimumSizeHint()); + layout()->setSizeConstraint(QLayout::SetFixedSize); + Keyring *k = Keyring::instance(); + QStringList accounts = k->getStoredAccounts("minecraft"); + ui->usernameTextBox->addItems(accounts); + + // TODO: restore last selected account here, if applicable + + int index = ui->usernameTextBox->currentIndex(); + if (index != -1) + { + ui->passwordTextBox->setFocus(Qt::OtherFocusReason); + } + + connect(ui->rememberUsernameCheckbox, SIGNAL(toggled(bool)), SLOT(usernameToggled(bool))); + connect(ui->rememberPasswordCheckbox, SIGNAL(toggled(bool)), SLOT(passwordToggled(bool))); +} + +LoginDialog::~LoginDialog() +{ + delete offlineButton; + delete ui; +} + +QString LoginDialog::getUsername() const +{ + return ui->usernameTextBox->currentText(); +} + +QString LoginDialog::getPassword() const +{ + return ui->passwordTextBox->text(); +} + +void LoginDialog::forgetCurrentUser() +{ + Keyring *k = Keyring::instance(); + QString acct = ui->usernameTextBox->currentText(); + k->removeStoredAccount("minecraft", acct); + ui->passwordTextBox->clear(); + int index = ui->usernameTextBox->findText(acct); + if (index != -1) + ui->usernameTextBox->removeItem(index); + if (!ui->usernameTextBox->count()) + { + blockToggles = true; + ui->rememberUsernameCheckbox->setChecked(false); + ui->rememberPasswordCheckbox->setChecked(false); + blockToggles = false; + } +} + +void LoginDialog::passwordToggled(bool state) +{ + // if toggled off + if (blockToggles) + return; + blockToggles = true; + if (!state) + { + QLOG_DEBUG() << "password disabled"; + } + else + { + if (!ui->rememberUsernameCheckbox->isChecked()) + { + ui->rememberUsernameCheckbox->setChecked(true); + } + QLOG_DEBUG() << "password enabled"; + } + blockToggles = false; +} + +void LoginDialog::usernameToggled(bool state) +{ + // if toggled off + if (blockToggles) + return; + blockToggles = true; + if (!state) + { + if (ui->rememberPasswordCheckbox->isChecked()) + { + ui->rememberPasswordCheckbox->setChecked(false); + } + QLOG_DEBUG() << "username disabled"; + } + else + { + QLOG_DEBUG() << "username enabled"; + } + blockToggles = false; +} + +void LoginDialog::userTextChanged(const QString &user) +{ + blockToggles = true; + Keyring *k = Keyring::instance(); + QStringList sl = k->getStoredAccounts("minecraft"); + bool gotFace = false; + + if (sl.contains(user)) + { + ui->rememberUsernameCheckbox->setChecked(true); + QString passwd = k->getPassword("minecraft", user); + ui->rememberPasswordCheckbox->setChecked(!passwd.isEmpty()); + ui->passwordTextBox->setText(passwd); + + QByteArray data; + { + auto filename = + MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); + QFile listFile(filename); + if (!listFile.open(QIODevice::ReadOnly)) + return; + data = listFile.readAll(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + QJsonObject root = jsonDoc.object(); + QJsonObject mappings = root.value("mappings").toObject(); + + if (!mappings[user].isUndefined()) + { + QJsonArray usernames = mappings.value(user).toArray(); + if (!usernames.isEmpty()) + { + QString mapped_username = usernames[0].toString(); + + if (!mapped_username.isEmpty()) + { + QFile fskin(MMC->metacache() + ->resolveEntry("skins", mapped_username + ".png") + ->getFullPath()); + if (fskin.exists()) + { + QPixmap skin(MMC->metacache() + ->resolveEntry("skins", mapped_username + ".png") + ->getFullPath()); + QPixmap face = + skin.copy(8, 8, 8, 8).scaled(48, 48, Qt::KeepAspectRatio); + + ui->lblFace->setPixmap(face); + gotFace = true; + } + } + } + } + } + + ui->lblFace->setVisible(gotFace); + blockToggles = false; +} + +void LoginDialog::accept() +{ + bool saveName = ui->rememberUsernameCheckbox->isChecked(); + bool savePass = ui->rememberPasswordCheckbox->isChecked(); + Keyring *k = Keyring::instance(); + if (saveName) + { + if (savePass) + { + k->storePassword("minecraft", getUsername(), getPassword()); + } + else + { + k->storePassword("minecraft", getUsername(), QString()); + } + } + else + { + QString acct = ui->usernameTextBox->currentText(); + k->removeStoredAccount("minecraft", acct); + } + QDialog::accept(); +} + +void LoginDialog::launchOffline() +{ + isOnline_ = false; + QDialog::accept(); +} + +void LoginDialog::forceOnline() +{ + onlineForced = true; + offlineButton->setEnabled(false); +} diff --git a/gui/dialogs/LoginDialog.h b/gui/dialogs/LoginDialog.h new file mode 100644 index 00000000..73a92aab --- /dev/null +++ b/gui/dialogs/LoginDialog.h @@ -0,0 +1,61 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +namespace Ui +{ +class LoginDialog; +} + +class LoginDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LoginDialog(QWidget *parent = 0, const QString &loginErrMsg = ""); + ~LoginDialog(); + + QString getUsername() const; + QString getPassword() const; + + inline bool isOnline() + { + return isOnline_; + } + + void forceOnline(); + +public +slots: + virtual void accept(); + virtual void userTextChanged(const QString &user); + virtual void forgetCurrentUser(); +private +slots: + void usernameToggled(bool); + void passwordToggled(bool); + void launchOffline(); + +private: + Ui::LoginDialog *ui; + bool blockToggles; + QPushButton *offlineButton; + bool isOnline_; + bool onlineForced; +}; diff --git a/gui/dialogs/LoginDialog.ui b/gui/dialogs/LoginDialog.ui new file mode 100644 index 00000000..d15679dd --- /dev/null +++ b/gui/dialogs/LoginDialog.ui @@ -0,0 +1,186 @@ + + + LoginDialog + + + + 0 + 0 + 496 + 168 + + + + Login + + + + + + <span style=" color:#ff0000;">Error</span> + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + + + 48 + 48 + + + + + 48 + 48 + + + + + 1 + 1 + + + + + + + :/icons/instances/steve + + + true + + + + + + + true + + + + + + + Username: + + + + + + + Password: + + + + + + + QLineEdit::Password + + + Password + + + + + + + + + + + + 1 + 0 + + + + &Remember Username? + + + + + + + + 1 + 0 + + + + R&emember Password? + + + + + + + + 0 + 0 + + + + Forget + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + + loginButtonBox + accepted() + LoginDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + loginButtonBox + rejected() + LoginDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/LwjglSelectDialog.cpp b/gui/dialogs/LwjglSelectDialog.cpp new file mode 100644 index 00000000..046a4e2e --- /dev/null +++ b/gui/dialogs/LwjglSelectDialog.cpp @@ -0,0 +1,72 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiMC.h" +#include "LwjglSelectDialog.h" +#include "ui_LwjglSelectDialog.h" +#include "gui/Platform.h" + +#include "logic/lists/LwjglVersionList.h" + +LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) + : QDialog(parent), ui(new Ui::LWJGLSelectDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + ui->labelStatus->setVisible(false); + auto lwjgllist = MMC->lwjgllist(); + ui->lwjglListView->setModel(lwjgllist.get()); + + connect(lwjgllist.get(), SIGNAL(loadingStateUpdated(bool)), + SLOT(loadingStateUpdated(bool))); + connect(lwjgllist.get(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); + loadingStateUpdated(lwjgllist->isLoading()); +} + +LWJGLSelectDialog::~LWJGLSelectDialog() +{ + delete ui; +} + +QString LWJGLSelectDialog::selectedVersion() const +{ + return MMC->lwjgllist() + ->data(ui->lwjglListView->selectionModel()->currentIndex(), Qt::DisplayRole) + .toString(); +} + +void LWJGLSelectDialog::on_refreshButton_clicked() +{ + if (!MMC->lwjgllist()->isLoading()) + MMC->lwjgllist()->loadList(); +} + +void LWJGLSelectDialog::loadingStateUpdated(bool loading) +{ + setEnabled(!loading); + if (loading) + { + ui->labelStatus->setText(tr("Loading LWJGL version list...")); + ui->labelStatus->setStyleSheet("QLabel { color: black; }"); + } + ui->labelStatus->setVisible(loading); +} + +void LWJGLSelectDialog::loadingFailed(QString error) +{ + ui->labelStatus->setText(error); + ui->labelStatus->setStyleSheet("QLabel { color: red; }"); + ui->labelStatus->setVisible(true); +} diff --git a/gui/dialogs/LwjglSelectDialog.h b/gui/dialogs/LwjglSelectDialog.h new file mode 100644 index 00000000..2724cbe8 --- /dev/null +++ b/gui/dialogs/LwjglSelectDialog.h @@ -0,0 +1,44 @@ +/* Copyright 2013 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 + +namespace Ui +{ +class LWJGLSelectDialog; +} + +class LWJGLSelectDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LWJGLSelectDialog(QWidget *parent = 0); + ~LWJGLSelectDialog(); + + QString selectedVersion() const; + +private +slots: + void on_refreshButton_clicked(); + + void loadingStateUpdated(bool loading); + void loadingFailed(QString error); + +private: + Ui::LWJGLSelectDialog *ui; +}; diff --git a/gui/dialogs/LwjglSelectDialog.ui b/gui/dialogs/LwjglSelectDialog.ui new file mode 100644 index 00000000..c715cc07 --- /dev/null +++ b/gui/dialogs/LwjglSelectDialog.ui @@ -0,0 +1,85 @@ + + + LWJGLSelectDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Status label... + + + + + + + + + + + + &Refresh + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + LWJGLSelectDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LWJGLSelectDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/ModEditDialogCommon.cpp b/gui/dialogs/ModEditDialogCommon.cpp new file mode 100644 index 00000000..9a15d92d --- /dev/null +++ b/gui/dialogs/ModEditDialogCommon.cpp @@ -0,0 +1,57 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ModEditDialogCommon.h" +#include "CustomMessageBox.h" +#include +#include +#include +#include +bool lastfirst(QModelIndexList &list, int &first, int &last) +{ + if (!list.size()) + return false; + first = last = list[0].row(); + for (auto item : list) + { + int row = item.row(); + if (row < first) + first = row; + if (row > last) + last = row; + } + return true; +} + +void showWebsiteForMod(QWidget *parentDlg, Mod &m) +{ + QString url = m.homeurl(); + if (url.size()) + { + // catch the cases where the protocol is missing + if (!url.startsWith("http")) + { + url = "http://" + url; + } + QDesktopServices::openUrl(url); + } + else + { + CustomMessageBox::selectable( + parentDlg, parentDlg->tr("How sad!"), + parentDlg->tr("The mod author didn't provide a website link for this mod."), + QMessageBox::Warning); + } +} diff --git a/gui/dialogs/ModEditDialogCommon.h b/gui/dialogs/ModEditDialogCommon.h new file mode 100644 index 00000000..a226d5a9 --- /dev/null +++ b/gui/dialogs/ModEditDialogCommon.h @@ -0,0 +1,22 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include + +bool lastfirst(QModelIndexList &list, int &first, int &last); + +void showWebsiteForMod(QWidget *parentDlg, Mod &m); \ No newline at end of file diff --git a/gui/dialogs/NewInstanceDialog.cpp b/gui/dialogs/NewInstanceDialog.cpp new file mode 100644 index 00000000..5b2cd086 --- /dev/null +++ b/gui/dialogs/NewInstanceDialog.cpp @@ -0,0 +1,125 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiMC.h" +#include "NewInstanceDialog.h" +#include "ui_NewInstanceDialog.h" + +#include "logic/InstanceFactory.h" +#include "logic/BaseVersion.h" +#include "logic/lists/IconList.h" +#include "logic/lists/MinecraftVersionList.h" +#include "logic/tasks/Task.h" + +#include "gui/Platform.h" +#include "VersionSelectDialog.h" +#include "ProgressDialog.h" +#include "IconPickerDialog.h" + +#include +#include + +NewInstanceDialog::NewInstanceDialog(QWidget *parent) + : QDialog(parent), ui(new Ui::NewInstanceDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + resize(minimumSizeHint()); + layout()->setSizeConstraint(QLayout::SetFixedSize); + /* + if (!MinecraftVersionList::getMainList().isLoaded()) + { + TaskDialog *taskDlg = new TaskDialog(this); + Task *loadTask = MinecraftVersionList::getMainList().getLoadTask(); + loadTask->setParent(taskDlg); + taskDlg->exec(loadTask); + } + */ + setSelectedVersion(MMC->minecraftlist()->getLatestStable()); + InstIconKey = "infinity"; + ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); +} + +NewInstanceDialog::~NewInstanceDialog() +{ + delete ui; +} + +void NewInstanceDialog::updateDialogState() +{ + ui->buttonBox->button(QDialogButtonBox::Ok) + ->setEnabled(!instName().isEmpty() && m_selectedVersion); +} + +void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version) +{ + m_selectedVersion = version; + + if (m_selectedVersion) + { + ui->versionTextBox->setText(version->name()); + } + else + { + ui->versionTextBox->setText(""); + } + + updateDialogState(); +} + +QString NewInstanceDialog::instName() const +{ + return ui->instNameTextBox->text(); +} + +QString NewInstanceDialog::iconKey() const +{ + return InstIconKey; +} + +BaseVersionPtr NewInstanceDialog::selectedVersion() const +{ + return m_selectedVersion; +} + +void NewInstanceDialog::on_btnChangeVersion_clicked() +{ + VersionSelectDialog vselect(MMC->minecraftlist().get(), tr("Change Minecraft version"), + this); + vselect.exec(); + if (vselect.result() == QDialog::Accepted) + { + BaseVersionPtr version = vselect.selectedVersion(); + if (version) + setSelectedVersion(version); + } +} + +void NewInstanceDialog::on_iconButton_clicked() +{ + IconPickerDialog dlg(this); + dlg.exec(InstIconKey); + + if (dlg.result() == QDialog::Accepted) + { + InstIconKey = dlg.selectedIconKey; + ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); + } +} + +void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) +{ + updateDialogState(); +} diff --git a/gui/dialogs/NewInstanceDialog.h b/gui/dialogs/NewInstanceDialog.h new file mode 100644 index 00000000..4357c28d --- /dev/null +++ b/gui/dialogs/NewInstanceDialog.h @@ -0,0 +1,55 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "logic/BaseVersion.h" + +namespace Ui +{ +class NewInstanceDialog; +} + +class NewInstanceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit NewInstanceDialog(QWidget *parent = 0); + ~NewInstanceDialog(); + + void updateDialogState(); + + void setSelectedVersion(BaseVersionPtr version); + + void loadVersionList(); + + QString instName() const; + QString iconKey() const; + BaseVersionPtr selectedVersion() const; + +private +slots: + void on_btnChangeVersion_clicked(); + void on_iconButton_clicked(); + void on_instNameTextBox_textChanged(const QString &arg1); + +private: + Ui::NewInstanceDialog *ui; + + BaseVersionPtr m_selectedVersion; + QString InstIconKey; +}; diff --git a/gui/dialogs/NewInstanceDialog.ui b/gui/dialogs/NewInstanceDialog.ui new file mode 100644 index 00000000..b4b8723e --- /dev/null +++ b/gui/dialogs/NewInstanceDialog.ui @@ -0,0 +1,179 @@ + + + NewInstanceDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 220 + 234 + + + + New Instance + + + + :/icons/toolbar/new:/icons/toolbar/new + + + true + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + :/icons/instances/infinity:/icons/instances/infinity + + + + 80 + 80 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Name + + + + + + + Qt::Horizontal + + + + + + + + + Version: + + + + + + + true + + + + + + + ... + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + NewInstanceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewInstanceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp new file mode 100644 index 00000000..dea1b86b --- /dev/null +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -0,0 +1,322 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiMC.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "OneSixModEditDialog.h" +#include "ModEditDialogCommon.h" +#include "ui_OneSixModEditDialog.h" + +#include "gui/Platform.h" +#include "gui/dialogs/CustomMessageBox.h" +#include "gui/dialogs/VersionSelectDialog.h" + +#include "gui/dialogs/ProgressDialog.h" + +#include "logic/ModList.h" +#include "logic/OneSixVersion.h" +#include "logic/EnabledItemFilter.h" +#include "logic/lists/ForgeVersionList.h" +#include "logic/ForgeInstaller.h" + +OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) + : m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + // libraries! + + m_version = m_inst->getFullVersion(); + if (m_version) + { + main_model = new EnabledItemFilter(this); + main_model->setActive(true); + main_model->setSourceModel(m_version.get()); + ui->libraryTreeView->setModel(main_model); + ui->libraryTreeView->installEventFilter(this); + ui->mainClassEdit->setText(m_version->mainClass); + updateVersionControls(); + } + else + { + disableVersionControls(); + } + // Loader mods + { + ensureFolderPathExists(m_inst->loaderModsDir()); + m_mods = m_inst->loaderModList(); + ui->loaderModTreeView->setModel(m_mods.get()); + ui->loaderModTreeView->installEventFilter(this); + m_mods->startWatching(); + auto smodel = ui->loaderModTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(loaderCurrent(QModelIndex, QModelIndex))); + } + // resource packs + { + ensureFolderPathExists(m_inst->resourcePacksDir()); + m_resourcepacks = m_inst->resourcePackList(); + ui->resPackTreeView->setModel(m_resourcepacks.get()); + ui->resPackTreeView->installEventFilter(this); + m_resourcepacks->startWatching(); + } +} + +OneSixModEditDialog::~OneSixModEditDialog() +{ + m_mods->stopWatching(); + m_resourcepacks->stopWatching(); + delete ui; +} + +void OneSixModEditDialog::updateVersionControls() +{ + bool customVersion = m_inst->versionIsCustom(); + ui->customizeBtn->setEnabled(!customVersion); + ui->revertBtn->setEnabled(customVersion); + ui->forgeBtn->setEnabled(true); +} + +void OneSixModEditDialog::disableVersionControls() +{ + ui->customizeBtn->setEnabled(false); + ui->revertBtn->setEnabled(false); + ui->forgeBtn->setEnabled(false); +} + +void OneSixModEditDialog::on_customizeBtn_clicked() +{ + if (m_inst->customizeVersion()) + { + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.get()); + updateVersionControls(); + } +} + +void OneSixModEditDialog::on_revertBtn_clicked() +{ + auto response = CustomMessageBox::selectable( + this, tr("Revert?"), tr("Do you want to revert the " + "version of this instance to its original configuration?"), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); + if (response == QMessageBox::Yes) + { + if (m_inst->revertCustomVersion()) + { + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.get()); + updateVersionControls(); + } + } +} + +void OneSixModEditDialog::on_forgeBtn_clicked() +{ + VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); + vselect.setFilter(1, m_inst->currentVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + if (m_inst->versionIsCustom()) + { + auto reply = QMessageBox::question( + this, tr("Revert?"), + tr("This will revert any " + "changes you did to the version up to this point. Is that " + "OK?"), + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) + { + m_inst->revertCustomVersion(); + m_inst->customizeVersion(); + { + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.get()); + updateVersionControls(); + } + } + else + return; + } + else + { + m_inst->customizeVersion(); + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.get()); + updateVersionControls(); + } + ForgeVersionPtr forgeVersion = + std::dynamic_pointer_cast(vselect.selectedVersion()); + if (!forgeVersion) + return; + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); + if (entry->stale) + { + NetJob *fjob = new NetJob("Forge download"); + fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry)); + ProgressDialog dlg(this); + dlg.exec(fjob); + if (dlg.result() == QDialog::Accepted) + { + // install + QString forgePath = entry->getFullPath(); + ForgeInstaller forge(forgePath, forgeVersion->universal_url); + if (!forge.apply(m_version)) + { + // failure notice + } + } + else + { + // failed to download forge :/ + } + } + else + { + // install + QString forgePath = entry->getFullPath(); + ForgeInstaller forge(forgePath, forgeVersion->universal_url); + if (!forge.apply(m_version)) + { + // failure notice + } + } + } +} + +bool OneSixModEditDialog::loaderListFilter(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 QDialog::eventFilter(ui->loaderModTreeView, keyEvent); +} + +bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmResPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addResPackBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->resPackTreeView, keyEvent); +} + +bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QDialog::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->loaderModTreeView) + return loaderListFilter(keyEvent); + if (obj == ui->resPackTreeView) + return resourcePackListFilter(keyEvent); + return QDialog::eventFilter(obj, ev); +} + +void OneSixModEditDialog::on_buttonBox_rejected() +{ + close(); +} + +void OneSixModEditDialog::on_addModBtn_clicked() +{ + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); + for (auto filename : fileNames) + { + m_mods->stopWatching(); + m_mods->installMod(QFileInfo(filename)); + m_mods->startWatching(); + } +} +void OneSixModEditDialog::on_rmModBtn_clicked() +{ + int first, last; + auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_mods->stopWatching(); + m_mods->deleteMods(first, last); + m_mods->startWatching(); +} +void OneSixModEditDialog::on_viewModBtn_clicked() +{ + openDirInDefaultProgram(m_inst->loaderModsDir(), true); +} + +void OneSixModEditDialog::on_addResPackBtn_clicked() +{ + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); + for (auto filename : fileNames) + { + m_resourcepacks->stopWatching(); + m_resourcepacks->installMod(QFileInfo(filename)); + m_resourcepacks->startWatching(); + } +} +void OneSixModEditDialog::on_rmResPackBtn_clicked() +{ + int first, last; + auto list = ui->resPackTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_resourcepacks->stopWatching(); + m_resourcepacks->deleteMods(first, last); + m_resourcepacks->startWatching(); +} +void OneSixModEditDialog::on_viewResPackBtn_clicked() +{ + openDirInDefaultProgram(m_inst->resourcePacksDir(), true); +} + +void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->frame->clear(); + return; + } + int row = current.row(); + Mod &m = m_mods->operator[](row); + ui->frame->updateWithMod(m); +} diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h new file mode 100644 index 00000000..5376e526 --- /dev/null +++ b/gui/dialogs/OneSixModEditDialog.h @@ -0,0 +1,67 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +#include + +class EnabledItemFilter; +namespace Ui +{ +class OneSixModEditDialog; +} + +class OneSixModEditDialog : public QDialog +{ + Q_OBJECT + +public: + explicit OneSixModEditDialog(OneSixInstance *inst, QWidget *parent = 0); + virtual ~OneSixModEditDialog(); + +private +slots: + void on_addModBtn_clicked(); + void on_rmModBtn_clicked(); + void on_viewModBtn_clicked(); + + void on_addResPackBtn_clicked(); + void on_rmResPackBtn_clicked(); + void on_viewResPackBtn_clicked(); + // Questionable: SettingsDialog doesn't need this for some reason? + void on_buttonBox_rejected(); + void on_forgeBtn_clicked(); + void on_customizeBtn_clicked(); + void on_revertBtn_clicked(); + void updateVersionControls(); + void disableVersionControls(); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + bool loaderListFilter(QKeyEvent *ev); + bool resourcePackListFilter(QKeyEvent *ev); + +private: + Ui::OneSixModEditDialog *ui; + std::shared_ptr m_version; + std::shared_ptr m_mods; + std::shared_ptr m_resourcepacks; + EnabledItemFilter *main_model; + OneSixInstance *m_inst; +public +slots: + void loaderCurrent(QModelIndex current, QModelIndex previous); +}; diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui new file mode 100644 index 00000000..8f301438 --- /dev/null +++ b/gui/dialogs/OneSixModEditDialog.ui @@ -0,0 +1,319 @@ + + + OneSixModEditDialog + + + + 0 + 0 + 555 + 463 + + + + Dialog + + + + + + true + + + + 0 + 0 + + + + 1 + + + + Version + + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + + + + + + + Main Class: + + + + + + + false + + + + + + + + + + + + + Replace any current custom version with Minecraft Forge + + + Install Forge + + + + + + + Create an customized copy of the base version + + + Customize + + + + + + + false + + + Revert to original base version + + + Revert + + + + + + + QFrame::Sunken + + + Qt::Horizontal + + + + + + + false + + + Add new libraries + + + &Add + + + + + + + false + + + Remove selected libraries + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Loader Mods + + + + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + 0 + 0 + + + + + + + + + Resource Packs + + + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + + false + + + QDialogButtonBox::Close + + + + + + + + ModListView + QTreeView +
gui/widgets/ModListView.h
+
+ + MCModInfoFrame + QFrame +
gui/widgets/MCModInfoFrame.h
+ 1 +
+
+ + +
diff --git a/gui/dialogs/ProgressDialog.cpp b/gui/dialogs/ProgressDialog.cpp new file mode 100644 index 00000000..ca433dab --- /dev/null +++ b/gui/dialogs/ProgressDialog.cpp @@ -0,0 +1,107 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ProgressDialog.h" +#include "ui_ProgressDialog.h" + +#include + +#include "logic/tasks/Task.h" +#include "gui/Platform.h" + +ProgressDialog::ProgressDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ProgressDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + updateSize(); + + changeProgress(0, 100); +} + +ProgressDialog::~ProgressDialog() +{ + delete ui; +} + +void ProgressDialog::updateSize() +{ + resize(QSize(480, minimumSizeHint().height())); +} + +int ProgressDialog::exec(ProgressProvider *task) +{ + this->task = task; + + // Connect signals. + connect(task, SIGNAL(started()), SLOT(onTaskStarted())); + connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString))); + connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded())); + connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString &))); + connect(task, SIGNAL(progress(qint64, qint64)), SLOT(changeProgress(qint64, qint64))); + + // this makes sure that the task is started after the dialog is created + QMetaObject::invokeMethod(task, "start", Qt::QueuedConnection); + return QDialog::exec(); +} + +ProgressProvider *ProgressDialog::getTask() +{ + return task; +} + +void ProgressDialog::onTaskStarted() +{ +} + +void ProgressDialog::onTaskFailed(QString failure) +{ + reject(); +} + +void ProgressDialog::onTaskSucceeded() +{ + accept(); +} + +void ProgressDialog::changeStatus(const QString &status) +{ + ui->statusLabel->setText(status); + updateSize(); +} + +void ProgressDialog::changeProgress(qint64 current, qint64 total) +{ + ui->taskProgressBar->setMaximum(total); + ui->taskProgressBar->setValue(current); +} + +void ProgressDialog::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(e); +} + +void ProgressDialog::closeEvent(QCloseEvent *e) +{ + if (task && task->isRunning()) + { + e->ignore(); + } + else + { + QDialog::closeEvent(e); + } +} diff --git a/gui/dialogs/ProgressDialog.h b/gui/dialogs/ProgressDialog.h new file mode 100644 index 00000000..0029d3ec --- /dev/null +++ b/gui/dialogs/ProgressDialog.h @@ -0,0 +1,60 @@ +/* Copyright 2013 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 + +class ProgressProvider; + +namespace Ui +{ +class ProgressDialog; +} + +class ProgressDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProgressDialog(QWidget *parent = 0); + ~ProgressDialog(); + + void updateSize(); + + int exec(ProgressProvider *task); + + ProgressProvider *getTask(); + +public +slots: + void onTaskStarted(); + void onTaskFailed(QString failure); + void onTaskSucceeded(); + + void changeStatus(const QString &status); + void changeProgress(qint64 current, qint64 total); + +signals: + +protected: + virtual void keyPressEvent(QKeyEvent *e); + virtual void closeEvent(QCloseEvent *e); + +private: + Ui::ProgressDialog *ui; + + ProgressProvider *task; +}; diff --git a/gui/dialogs/ProgressDialog.ui b/gui/dialogs/ProgressDialog.ui new file mode 100644 index 00000000..a56d2a92 --- /dev/null +++ b/gui/dialogs/ProgressDialog.ui @@ -0,0 +1,53 @@ + + + ProgressDialog + + + + 0 + 0 + 400 + 68 + + + + + 400 + 0 + + + + + 600 + 16777215 + + + + Please wait... + + + + + + Task Status... + + + true + + + + + + + 24 + + + false + + + + + + + + diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp new file mode 100644 index 00000000..e4f22d83 --- /dev/null +++ b/gui/dialogs/SettingsDialog.cpp @@ -0,0 +1,260 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiMC.h" + +#include "gui/dialogs/SettingsDialog.h" +#include "ui_SettingsDialog.h" + +#include "gui/Platform.h" +#include "gui/dialogs/VersionSelectDialog.h" +#include "gui/dialogs/CustomMessageBox.h" + +#include "logic/JavaUtils.h" +#include "logic/NagUtils.h" +#include "logic/lists/JavaVersionList.h" + +#include +#include +#include +#include +#include + +SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name); + ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch); + + loadSettings(MMC->settings().get()); + updateCheckboxStuff(); +} + +SettingsDialog::~SettingsDialog() +{ + delete ui; +} +void SettingsDialog::showEvent(QShowEvent *ev) +{ + QDialog::showEvent(ev); + adjustSize(); +} + +void SettingsDialog::updateCheckboxStuff() +{ + ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); + ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); +} + +void SettingsDialog::on_instDirBrowseBtn_clicked() +{ + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"), + ui->instDirTextBox->text()); + QString cooked_dir = NormalizePath(raw_dir); + + // do not allow current dir - it's dirty. Do not allow dirs that don't exist + if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + { + ui->instDirTextBox->setText(cooked_dir); + } +} + +void SettingsDialog::on_modsDirBrowseBtn_clicked() +{ + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"), + ui->modsDirTextBox->text()); + QString cooked_dir = NormalizePath(raw_dir); + + // do not allow current dir - it's dirty. Do not allow dirs that don't exist + if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + { + ui->modsDirTextBox->setText(cooked_dir); + } +} + +void SettingsDialog::on_lwjglDirBrowseBtn_clicked() +{ + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"), + ui->lwjglDirTextBox->text()); + QString cooked_dir = NormalizePath(raw_dir); + + // do not allow current dir - it's dirty. Do not allow dirs that don't exist + if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + { + ui->lwjglDirTextBox->setText(cooked_dir); + } +} + +void SettingsDialog::on_compatModeCheckBox_clicked(bool checked) +{ + Q_UNUSED(checked); + updateCheckboxStuff(); +} + +void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) +{ + Q_UNUSED(checked); + updateCheckboxStuff(); +} + +void SettingsDialog::on_buttonBox_accepted() +{ + applySettings(MMC->settings().get()); +} + +void SettingsDialog::applySettings(SettingsObject *s) +{ + // Special cases + + // Warn about dev builds. + if (!ui->devBuildsCheckBox->isChecked()) + { + s->set("UseDevBuilds", false); + } + else if (!s->get("UseDevBuilds").toBool()) + { + auto response = CustomMessageBox::selectable( + this, tr("Development builds"), + tr("Development builds contain experimental features " + "and may be unstable. Are you sure you want to enable them?"), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); + if (response == QMessageBox::Yes) + { + s->set("UseDevBuilds", true); + } + } + + // Updates + s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked()); + + // Folders + // TODO: Offer to move instances to new instance folder. + s->set("InstanceDir", ui->instDirTextBox->text()); + s->set("CentralModsDir", ui->modsDirTextBox->text()); + s->set("LWJGLDir", ui->lwjglDirTextBox->text()); + + // Console + s->set("ShowConsole", ui->showConsoleCheck->isChecked()); + s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); + + // Window Size + s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); + s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); + s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); + + // Auto Login + s->set("AutoLogin", ui->autoLoginCheckBox->isChecked()); + + // Memory + s->set("MinMemAlloc", ui->minMemSpinBox->value()); + s->set("MaxMemAlloc", ui->maxMemSpinBox->value()); + s->set("PermGen", ui->permGenSpinBox->value()); + + // Java Settings + s->set("JavaPath", ui->javaPathTextBox->text()); + s->set("JvmArgs", ui->jvmArgsTextBox->text()); + NagUtils::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget()); + + // Custom Commands + s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); + s->set("PostExitCommand", ui->postExitCmdTextBox->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; + } + + s->set("PostExitCommand", ui->postExitCmdTextBox->text()); +} + +void SettingsDialog::loadSettings(SettingsObject *s) +{ + // Updates + ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool()); + ui->devBuildsCheckBox->setChecked(s->get("UseDevBuilds").toBool()); + + // Folders + ui->instDirTextBox->setText(s->get("InstanceDir").toString()); + ui->modsDirTextBox->setText(s->get("CentralModsDir").toString()); + ui->lwjglDirTextBox->setText(s->get("LWJGLDir").toString()); + + // Console + ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool()); + ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool()); + + // Window Size + ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool()); + ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt()); + ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt()); + + // Auto Login + ui->autoLoginCheckBox->setChecked(s->get("AutoLogin").toBool()); + + // Memory + ui->minMemSpinBox->setValue(s->get("MinMemAlloc").toInt()); + ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt()); + ui->permGenSpinBox->setValue(s->get("PermGen").toInt()); + + QString sortMode = s->get("InstSortMode").toString(); + + if (sortMode == "LastLaunch") + { + ui->sortLastLaunchedBtn->setChecked(true); + } + else + { + ui->sortByNameBtn->setChecked(true); + } + + // Java Settings + ui->javaPathTextBox->setText(s->get("JavaPath").toString()); + ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); + + // Custom Commands + ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); + ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); +} + +void SettingsDialog::on_pushButton_clicked() +{ + JavaVersionPtr java; + + VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true); + vselect.setResizeOn(2); + vselect.exec(); + + if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) + { + java = std::dynamic_pointer_cast(vselect.selectedVersion()); + ui->javaPathTextBox->setText(java->path); + } +} + +void SettingsDialog::on_btnBrowse_clicked() +{ + QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable")); + if (!dir.isNull()) + { + ui->javaPathTextBox->setText(dir); + } +} diff --git a/gui/dialogs/SettingsDialog.h b/gui/dialogs/SettingsDialog.h new file mode 100644 index 00000000..e24047c3 --- /dev/null +++ b/gui/dialogs/SettingsDialog.h @@ -0,0 +1,63 @@ +/* Copyright 2013 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 + +class SettingsObject; + +namespace Ui +{ +class SettingsDialog; +} + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsDialog(QWidget *parent = 0); + ~SettingsDialog(); + + void updateCheckboxStuff(); + + void applySettings(SettingsObject *s); + void loadSettings(SettingsObject *s); + +protected: + virtual void showEvent(QShowEvent *); + +private +slots: + void on_instDirBrowseBtn_clicked(); + + void on_modsDirBrowseBtn_clicked(); + + void on_lwjglDirBrowseBtn_clicked(); + + void on_compatModeCheckBox_clicked(bool checked); + + void on_maximizedCheckBox_clicked(bool checked); + + void on_buttonBox_accepted(); + + void on_pushButton_clicked(); + + void on_btnBrowse_clicked(); + +private: + Ui::SettingsDialog *ui; +}; diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui new file mode 100644 index 00000000..6da9420e --- /dev/null +++ b/gui/dialogs/SettingsDialog.ui @@ -0,0 +1,569 @@ + + + SettingsDialog + + + + 0 + 0 + 502 + 599 + + + + + 0 + 0 + + + + Settings + + + + :/icons/toolbar/settings:/icons/toolbar/settings + + + true + + + + + + QTabWidget::Rounded + + + 0 + + + + General + + + + + + true + + + Sorting Mode + + + + + + By last launched + + + sortingModeGroup + + + + + + + By name + + + sortingModeGroup + + + + + + + + + + Update Settings + + + + + + Use development builds? + + + + + + + Check for updates when MultiMC starts? + + + + + + + + + + Folders + + + + + + Instances: + + + + + + + + + + ... + + + + + + + Mods: + + + + + + + + + + ... + + + + + + + LWJGL: + + + + + + + + + + ... + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Minecraft + + + + + + Window Size + + + + + + Start Minecraft maximized? + + + + + + + + + Window height: + + + + + + + Window width: + + + + + + + 854 + + + 65536 + + + 1 + + + 854 + + + + + + + 480 + + + 65536 + + + 480 + + + + + + + + + + + + Console Settings + + + + + + Show console while the game is running? + + + + + + + Automatically close console when the game quits? + + + + + + + + + + Login automatically when an instance icon is double clicked? + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Java + + + + + + Memory + + + + + + 512 + + + 65536 + + + 128 + + + 1024 + + + + + + + Minimum memory allocation: + + + + + + + Maximum memory allocation: + + + + + + + 256 + + + 65536 + + + 128 + + + 256 + + + + + + + PermGen: + + + + + + + 64 + + + 999999999 + + + 8 + + + 64 + + + + + + + + + + Java Settings + + + + + + + 0 + 0 + + + + Java path: + + + + + + + + 0 + 0 + + + + JVM arguments: + + + + + + + + 0 + 0 + + + + Browse... + + + + + + + + + + + 0 + 0 + + + + Auto-detect... + + + + + + + + + + + + + Custom Commands + + + + + + Post-exit command: + + + + + + + Pre-launch command: + + + + + + + + + + + + + + + + + 0 + 0 + + + + Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + settingsTabs + buttonBox + sortLastLaunchedBtn + sortByNameBtn + devBuildsCheckBox + autoUpdateCheckBox + instDirTextBox + modsDirTextBox + lwjglDirTextBox + instDirBrowseBtn + modsDirBrowseBtn + lwjglDirBrowseBtn + maximizedCheckBox + windowWidthSpinBox + windowHeightSpinBox + showConsoleCheck + autoCloseConsoleCheck + autoLoginCheckBox + minMemSpinBox + maxMemSpinBox + permGenSpinBox + javaPathTextBox + pushButton + btnBrowse + jvmArgsTextBox + preLaunchCmdTextBox + postExitCmdTextBox + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 257 + 410 + + + 157 + 274 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 325 + 410 + + + 286 + 274 + + + + + + + + diff --git a/gui/dialogs/VersionSelectDialog.cpp b/gui/dialogs/VersionSelectDialog.cpp new file mode 100644 index 00000000..d6efe3c0 --- /dev/null +++ b/gui/dialogs/VersionSelectDialog.cpp @@ -0,0 +1,111 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "VersionSelectDialog.h" +#include "ui_VersionSelectDialog.h" + +#include + +#include + +#include +#include "gui/Platform.h" + +#include +#include +#include + +VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, + bool cancelable) + : QDialog(parent), ui(new Ui::VersionSelectDialog) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + setWindowModality(Qt::WindowModal); + setWindowTitle(title); + + m_vlist = vlist; + + m_proxyModel = new QSortFilterProxyModel(this); + m_proxyModel->setSourceModel(vlist); + + ui->listView->setModel(m_proxyModel); + ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); + + if (!cancelable) + { + ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); + } +} + +VersionSelectDialog::~VersionSelectDialog() +{ + delete ui; +} + +void VersionSelectDialog::setResizeOn(int column) +{ + ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents); + resizeOnColumn = column; + ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); +} + +int VersionSelectDialog::exec() +{ + QDialog::open(); + if (!m_vlist->isLoaded()) + loadList(); + return QDialog::exec(); +} + +void VersionSelectDialog::loadList() +{ + ProgressDialog *taskDlg = new ProgressDialog(this); + Task *loadTask = m_vlist->getLoadTask(); + loadTask->setParent(taskDlg); + taskDlg->exec(loadTask); +} + +BaseVersionPtr VersionSelectDialog::selectedVersion() const +{ + auto currentIndex = ui->listView->selectionModel()->currentIndex(); + auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole); + return variant.value(); +} + +void VersionSelectDialog::on_refreshButton_clicked() +{ + loadList(); +} + +void VersionSelectDialog::setFilter(int column, QString filter) +{ + m_proxyModel->setFilterKeyColumn(column); + m_proxyModel->setFilterFixedString(filter); + /* + QStringList filteredTypes; + if (!ui->filterSnapshotsCheckbox->isChecked()) + filteredTypes += "Snapshot"; + if (!ui->filterMCNostalgiaCheckbox->isChecked()) + filteredTypes += "Nostalgia"; + + QString regexStr = "^.*$"; + if (filteredTypes.length() > 0) + regexStr = QString("^((?!%1).)*$").arg(filteredTypes.join('|')); + + QLOG_DEBUG() << "Filter:" << regexStr; + */ +} diff --git a/gui/dialogs/VersionSelectDialog.h b/gui/dialogs/VersionSelectDialog.h new file mode 100644 index 00000000..e36341db --- /dev/null +++ b/gui/dialogs/VersionSelectDialog.h @@ -0,0 +1,61 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "logic/BaseVersion.h" + +class BaseVersionList; + +namespace Ui +{ +class VersionSelectDialog; +} + +class VersionSelectDialog : public QDialog +{ + Q_OBJECT + +public: + explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0, + bool cancelable = true); + ~VersionSelectDialog(); + + virtual int exec(); + + //! Starts a task that loads the list. + void loadList(); + + BaseVersionPtr selectedVersion() const; + + void setFilter(int column, QString filter); + void setResizeOn(int column); + +private +slots: + void on_refreshButton_clicked(); + +private: + Ui::VersionSelectDialog *ui; + + BaseVersionList *m_vlist; + + QSortFilterProxyModel *m_proxyModel; + + int resizeOnColumn = 0; +}; diff --git a/gui/dialogs/VersionSelectDialog.ui b/gui/dialogs/VersionSelectDialog.ui new file mode 100644 index 00000000..222f29cf --- /dev/null +++ b/gui/dialogs/VersionSelectDialog.ui @@ -0,0 +1,103 @@ + + + VersionSelectDialog + + + + 0 + 0 + 400 + 347 + + + + Dialog + + + + + + Qt::ScrollBarAlwaysOff + + + true + + + false + + + false + + + true + + + true + + + false + + + + + + + + + Reloads the version list. + + + &Refresh + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + VersionSelectDialog + accept() + + + 257 + 290 + + + 157 + 274 + + + + + buttonBox + rejected() + VersionSelectDialog + reject() + + + 325 + 290 + + + 286 + 274 + + + + + diff --git a/gui/instancedelegate.cpp b/gui/instancedelegate.cpp deleted file mode 100644 index 4c7a3a3a..00000000 --- a/gui/instancedelegate.cpp +++ /dev/null @@ -1,231 +0,0 @@ -#include "instancedelegate.h" -#include -#include -#include -#include -#include - -// Origin: Qt -static void viewItemTextLayout ( QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed ) -{ - height = 0; - widthUsed = 0; - textLayout.beginLayout(); - QString str = textLayout.text(); - while ( true ) - { - QTextLine line = textLayout.createLine(); - if ( !line.isValid() ) - break; - if(line.textLength() == 0) - break; - line.setLineWidth ( lineWidth ); - line.setPosition ( QPointF ( 0, height ) ); - height += line.height(); - widthUsed = qMax ( widthUsed, line.naturalTextWidth() ); - } - textLayout.endLayout(); -} - -#define QFIXED_MAX (INT_MAX/256) - -ListViewDelegate::ListViewDelegate ( QObject* parent ) : QStyledItemDelegate ( parent ) -{ - -} - -void drawSelectionRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) -{ - if ((option.state & QStyle::State_Selected)) - painter->fillRect ( rect, option.palette.brush ( QPalette::Highlight ) ); - else - { - QColor backgroundColor = option.palette.color(QPalette::Background); - backgroundColor.setAlpha(160); - painter->fillRect ( rect, QBrush(backgroundColor) ); - } - -} - -void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) -{ - if (!(option.state & QStyle::State_HasFocus)) - return; - QStyleOptionFocusRect opt; - opt.direction = option.direction; - opt.fontMetrics = option.fontMetrics; - opt.palette = option.palette; - opt.rect = rect; - //opt.state = option.state | QStyle::State_KeyboardFocusChange | QStyle::State_Item; - auto col = option.state & QStyle::State_Selected ? QPalette::Highlight : QPalette::Base; - opt.backgroundColor = option.palette.color(col); - // Apparently some widget styles expect this hint to not be set - painter->setRenderHint(QPainter::Antialiasing, false); - - QStyle *style = option.widget ? option.widget->style() : QApplication::style(); - - style->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, painter, option.widget); - - painter->setRenderHint(QPainter::Antialiasing); -} - -static QSize viewItemTextSize ( const QStyleOptionViewItemV4 *option ) -{ - QStyle *style = option->widget ? option->widget->style() : QApplication::style(); - QTextOption textOption; - textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); - QTextLayout textLayout; - textLayout.setTextOption ( textOption ); - textLayout.setFont ( option->font ); - textLayout.setText ( option->text ); - const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, option, option->widget ) + 1; - QRect bounds ( 0,0,100 - 2*textMargin,600 ); - qreal height = 0, widthUsed = 0; - viewItemTextLayout ( textLayout, bounds.width(), height, widthUsed ); - const QSize size ( qCeil ( widthUsed ), qCeil ( height ) ); - return QSize ( size.width() + 2 * textMargin, size.height() ); -} - -void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - QStyleOptionViewItemV4 opt = option; - initStyleOption ( &opt, index ); - painter->save(); - painter->setClipRect ( opt.rect ); - - opt.features |= QStyleOptionViewItem::WrapText; - opt.text = index.data().toString(); - opt.textElideMode = Qt::ElideRight; - opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; - - QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - - //const int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize); - const int iconSize = 48; - QRect iconbox = opt.rect; - const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, 0, opt.widget ) + 1; - QRect textRect = opt.rect; - QRect textHighlightRect = textRect; - // clip the decoration on top, remove width padding - textRect.adjust ( textMargin,iconSize + textMargin + 5,-textMargin,0 ); - - textHighlightRect.adjust ( 0,iconSize + 5,0,0 ); - - // draw background - { - QSize textSize = viewItemTextSize ( &opt ); - QPalette::ColorGroup cg; - QStyleOptionViewItemV4 opt2(opt); - - if((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled)) - { - if(! ( opt.state & QStyle::State_Active )) - cg = QPalette::Inactive; - else - cg = QPalette::Normal; - } - else - { - cg = QPalette::Disabled; - } - opt2.palette.setCurrentColorGroup(cg); - - // fill in background, if any - if ( opt.backgroundBrush.style() != Qt::NoBrush ) - { - QPointF oldBO = painter->brushOrigin(); - painter->setBrushOrigin ( opt.rect.topLeft() ); - painter->fillRect ( opt.rect, opt.backgroundBrush ); - painter->setBrushOrigin ( oldBO ); - } - - if ( opt.showDecorationSelected ) - { - drawSelectionRect(painter,opt2, opt.rect); - drawFocusRect(painter,opt2, opt.rect); - //painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) ); - } - else - { - - //if ( opt.state & QStyle::State_Selected ) - { - //QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText, opt, opt.widget ); - //painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, QPalette::Highlight ) ); - drawSelectionRect(painter,opt2, textHighlightRect); - drawFocusRect(painter,opt2, textHighlightRect); - } - } - } - - // draw the icon - { - QIcon::Mode mode = QIcon::Normal; - if ( ! ( opt.state & QStyle::State_Enabled ) ) - mode = QIcon::Disabled; - else if ( opt.state & QStyle::State_Selected ) - mode = QIcon::Selected; - QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; - - iconbox.setHeight ( iconSize ); - opt.icon.paint ( painter, iconbox, Qt::AlignCenter, mode, state ); - } - // set the text colors - QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - if ( cg == QPalette::Normal && ! ( opt.state & QStyle::State_Active ) ) - cg = QPalette::Inactive; - if ( opt.state & QStyle::State_Selected ) - { - painter->setPen ( opt.palette.color ( cg, QPalette::HighlightedText ) ); - } - else - { - painter->setPen ( opt.palette.color ( cg, QPalette::Text ) ); - } - - // draw the text - QTextOption textOption; - textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); - textOption.setTextDirection ( opt.direction ); - textOption.setAlignment ( QStyle::visualAlignment ( opt.direction, opt.displayAlignment ) ); - QTextLayout textLayout; - textLayout.setTextOption ( textOption ); - textLayout.setFont ( opt.font ); - textLayout.setText ( opt.text ); - - qreal width, height; - viewItemTextLayout ( textLayout, textRect.width(), height, width ); - - const int lineCount = textLayout.lineCount(); - - const QRect layoutRect = QStyle::alignedRect ( opt.direction, opt.displayAlignment, QSize ( textRect.width(), int ( height ) ), textRect ); - const QPointF position = layoutRect.topLeft(); - for ( int i = 0; i < lineCount; ++i ) - { - const QTextLine line = textLayout.lineAt ( i ); - line.draw ( painter, position ); - } - - painter->restore(); -} - - -QSize ListViewDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - QStyleOptionViewItemV4 opt = option; - initStyleOption ( &opt, index ); - opt.features |= QStyleOptionViewItem::WrapText; - opt.text = index.data().toString(); - opt.textElideMode = Qt::ElideRight; - opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; - - QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, &option, opt.widget ) + 1; - int height = 48 + textMargin * 2 + 5; // TODO: turn constants into variables - QSize szz = viewItemTextSize ( &opt ); - height += szz.height(); - // FIXME: maybe the icon items could scale and keep proportions? - QSize sz ( 100,height ); - return sz; -} - diff --git a/gui/instancedelegate.h b/gui/instancedelegate.h deleted file mode 100644 index 56bc34ba..00000000 --- a/gui/instancedelegate.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class ListViewDelegate : public QStyledItemDelegate -{ -public: - explicit ListViewDelegate ( QObject* parent = 0 ); -protected: - void paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; -}; diff --git a/gui/instancesettings.cpp b/gui/instancesettings.cpp deleted file mode 100644 index 73eb6627..00000000 --- a/gui/instancesettings.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Andrew Okin - * Peterix - * Orochimarufan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "instancesettings.h" -#include "ui_instancesettings.h" -#include "gui/platform.h" - -InstanceSettings::InstanceSettings( SettingsObject * obj, QWidget *parent) : - m_obj(obj), - QDialog(parent), - ui(new Ui::InstanceSettings) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - loadSettings(); -} - -InstanceSettings::~InstanceSettings() -{ - delete ui; -} - -void InstanceSettings::showEvent ( QShowEvent* ev ) -{ - QDialog::showEvent(ev); - adjustSize(); -} - -void InstanceSettings::on_customCommandsGroupBox_toggled(bool state) -{ - ui->labelCustomCmdsDescription->setEnabled(state); -} - -void InstanceSettings::on_buttonBox_accepted() -{ - applySettings(); - accept(); -} - -void InstanceSettings::on_buttonBox_rejected() -{ - reject(); -} - - -void InstanceSettings::applySettings() -{ - // Console - bool console = ui->consoleSettingsBox->isChecked(); - m_obj->set("OverrideConsole", console); - if(console) - { - m_obj->set("ShowConsole", ui->showConsoleCheck->isChecked()); - m_obj->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); - } - else - { - m_obj->reset("ShowConsole"); - m_obj->reset("AutoCloseConsole"); - } - - // Window Size - bool window = ui->windowSizeGroupBox->isChecked(); - m_obj->set("OverrideWindow", window); - if(window) - { - m_obj->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); - m_obj->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); - m_obj->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); - } - else - { - m_obj->reset("LaunchMaximized"); - m_obj->reset("MinecraftWinWidth"); - m_obj->reset("MinecraftWinHeight"); - } - - - // Auto Login - bool login = ui->accountSettingsGroupBox->isChecked(); - m_obj->set("OverrideLogin", login); - if(login) - { - m_obj->set("AutoLogin", ui->autoLoginChecBox->isChecked()); - } - else - { - m_obj->reset("AutoLogin"); - } - - - // Memory - bool memory = ui->memoryGroupBox->isChecked(); - m_obj->set("OverrideMemory", memory); - if(memory) - { - m_obj->set("MinMemAlloc", ui->minMemSpinBox->value()); - m_obj->set("MaxMemAlloc", ui->maxMemSpinBox->value()); - m_obj->set("PermGen", ui->permGenSpinBox->value()); - } - else - { - m_obj->reset("MinMemAlloc"); - m_obj->reset("MaxMemAlloc"); - m_obj->reset("PermGen"); - } - - - // Java Settings - bool java = ui->javaSettingsGroupBox->isChecked(); - m_obj->set("OverrideJava", java); - if(java) - { - m_obj->set("JavaPath", ui->javaPathTextBox->text()); - m_obj->set("JvmArgs", ui->jvmArgsTextBox->text()); - } - else - { - m_obj->reset("JavaPath"); - m_obj->reset("JvmArgs"); - } - - - // Custom Commands - bool custcmd = ui->customCommandsGroupBox->isChecked(); - m_obj->set("OverrideCommands", custcmd); - if(custcmd) - { - m_obj->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); - m_obj->set("PostExitCommand", ui->postExitCmdTextBox->text()); - } - else - { - m_obj->reset("PreLaunchCommand"); - m_obj->reset("PostExitCommand"); - } - -} - -void InstanceSettings::loadSettings() -{ - // Console - ui->consoleSettingsBox->setChecked(m_obj->get("OverrideConsole").toBool()); - ui->showConsoleCheck->setChecked(m_obj->get("ShowConsole").toBool()); - ui->autoCloseConsoleCheck->setChecked(m_obj->get("AutoCloseConsole").toBool()); - - // Window Size - ui->windowSizeGroupBox->setChecked(m_obj->get("OverrideWindow").toBool()); - ui->maximizedCheckBox->setChecked(m_obj->get("LaunchMaximized").toBool()); - ui->windowWidthSpinBox->setValue(m_obj->get("MinecraftWinWidth").toInt()); - ui->windowHeightSpinBox->setValue(m_obj->get("MinecraftWinHeight").toInt()); - - - // Auto Login - ui->accountSettingsGroupBox->setChecked(m_obj->get("OverrideLogin").toBool()); - ui->autoLoginChecBox->setChecked(m_obj->get("AutoLogin").toBool()); - - // Memory - ui->memoryGroupBox->setChecked(m_obj->get("OverrideMemory").toBool()); - ui->minMemSpinBox->setValue(m_obj->get("MinMemAlloc").toInt()); - ui->maxMemSpinBox->setValue(m_obj->get("MaxMemAlloc").toInt()); - ui->permGenSpinBox->setValue(m_obj->get("PermGen").toInt()); - - // Java Settings - ui->javaSettingsGroupBox->setChecked(m_obj->get("OverrideJava").toBool()); - ui->javaPathTextBox->setText(m_obj->get("JavaPath").toString()); - ui->jvmArgsTextBox->setText(m_obj->get("JvmArgs").toString()); - - // Custom Commands - ui->customCommandsGroupBox->setChecked(m_obj->get("OverrideCommands").toBool()); - ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString()); - ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString()); -} diff --git a/gui/instancesettings.h b/gui/instancesettings.h deleted file mode 100644 index b6cdb92c..00000000 --- a/gui/instancesettings.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef INSTANCESETTINGS_H -#define INSTANCESETTINGS_H - -#include -#include "settingsobject.h" - -namespace Ui { -class InstanceSettings; -} - -class InstanceSettings : public QDialog -{ - Q_OBJECT - -public: - explicit InstanceSettings(SettingsObject *s, QWidget *parent = 0); - ~InstanceSettings(); - - void updateCheckboxStuff(); - - void applySettings(); - void loadSettings(); -protected: - virtual void showEvent ( QShowEvent* ); -private slots: - void on_customCommandsGroupBox_toggled(bool arg1); - void on_buttonBox_accepted(); - void on_buttonBox_rejected(); - -private: - Ui::InstanceSettings *ui; - SettingsObject * m_obj; -}; - -#endif // INSTANCESETTINGS_H diff --git a/gui/instancesettings.ui b/gui/instancesettings.ui deleted file mode 100644 index b536e9ff..00000000 --- a/gui/instancesettings.ui +++ /dev/null @@ -1,422 +0,0 @@ - - - InstanceSettings - - - - 0 - 0 - 526 - 590 - - - - - - - - - - QTabWidget::Rounded - - - 0 - - - - Minecraft - - - - - - true - - - Window Size - - - true - - - false - - - - - - Start Minecraft maximized? - - - - - - - - - Window height: - - - - - - - Window width: - - - - - - - 854 - - - 65536 - - - 1 - - - 854 - - - - - - - 480 - - - 65536 - - - 480 - - - - - - - - - - - - true - - - Console Settings - - - true - - - false - - - - - - Show console while the game is running? - - - - - - - Automatically close console when the game quits? - - - - - - - - - - true - - - Account Settings - - - true - - - false - - - - - - false - - - Login automatically when an instance icon is double clicked? - - - false - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - Java - - - - - - true - - - Memory - - - true - - - false - - - - - - 512 - - - 65536 - - - 128 - - - 1024 - - - - - - - Minimum memory allocation: - - - - - - - Maximum memory allocation: - - - - - - - 256 - - - 65536 - - - 128 - - - 256 - - - - - - - 64 - - - 999999999 - - - 8 - - - 64 - - - - - - - PermGen: - - - - - - - - - - true - - - Java Settings - - - true - - - false - - - - - - Java path: - - - - - - - - - - JVM arguments: - - - - - - - Auto-detect - - - - - - - - - - - - - true - - - Custom Commands - - - true - - - false - - - - - - - - - Post-exit command: - - - - - - - Pre-launch command: - - - - - - - - - - - - - false - - - - 0 - 0 - - - - Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables. - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - settingsTabs - buttonBox - windowSizeGroupBox - maximizedCheckBox - windowWidthSpinBox - windowHeightSpinBox - consoleSettingsBox - showConsoleCheck - autoCloseConsoleCheck - accountSettingsGroupBox - autoLoginChecBox - memoryGroupBox - minMemSpinBox - maxMemSpinBox - permGenSpinBox - javaSettingsGroupBox - javaPathTextBox - pushButton - jvmArgsTextBox - customCommandsGroupBox - preLaunchCmdTextBox - postExitCmdTextBox - - - - diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp deleted file mode 100644 index aeaaaa9e..00000000 --- a/gui/logindialog.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "logindialog.h" -#include "ui_logindialog.h" -#include "keyring.h" -#include "gui/platform.h" -#include "MultiMC.h" - -#include -#include -#include -#include -#include "logic/net/HttpMetaCache.h" -#include - -LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : - QDialog(parent), - ui(new Ui::LoginDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - - //: Use offline mode one time - offlineButton = new QPushButton(tr("Offline Once")); - - ui->loginButtonBox->addButton(offlineButton, QDialogButtonBox::ActionRole); - - blockToggles = false; - isOnline_ = true; - onlineForced = false; - - //: The username during login (placeholder) - ui->usernameTextBox->lineEdit()->setPlaceholderText(tr("Name")); - - connect(ui->usernameTextBox, SIGNAL(currentTextChanged(QString)), this, SLOT(userTextChanged(QString))); - connect(ui->forgetButton, SIGNAL(clicked(bool)), this, SLOT(forgetCurrentUser())); - connect(offlineButton, SIGNAL(clicked(bool)), this, SLOT(launchOffline())); - - if (loginErrMsg.isEmpty()) - ui->loginErrorLabel->setVisible(false); - else - { - ui->loginErrorLabel->setVisible(true); - ui->loginErrorLabel->setText(QString("%1"). - arg(loginErrMsg)); - } - - ui->lblFace->setVisible(false); - - resize(minimumSizeHint()); - layout()->setSizeConstraint(QLayout::SetFixedSize); - Keyring * k = Keyring::instance(); - QStringList accounts = k->getStoredAccounts("minecraft"); - ui->usernameTextBox->addItems(accounts); - - // TODO: restore last selected account here, if applicable - - int index = ui->usernameTextBox->currentIndex(); - if(index != -1) - { - ui->passwordTextBox->setFocus(Qt::OtherFocusReason); - } - - connect(ui->rememberUsernameCheckbox,SIGNAL(toggled(bool)), SLOT(usernameToggled(bool))); - connect(ui->rememberPasswordCheckbox,SIGNAL(toggled(bool)), SLOT(passwordToggled(bool))); -} - -LoginDialog::~LoginDialog() -{ - delete offlineButton; - delete ui; -} - -QString LoginDialog::getUsername() const -{ - return ui->usernameTextBox->currentText(); -} - -QString LoginDialog::getPassword() const -{ - return ui->passwordTextBox->text(); -} - -void LoginDialog::forgetCurrentUser() -{ - Keyring * k = Keyring::instance(); - QString acct = ui->usernameTextBox->currentText(); - k->removeStoredAccount("minecraft", acct); - ui->passwordTextBox->clear(); - int index = ui->usernameTextBox->findText(acct); - if(index != -1) - ui->usernameTextBox->removeItem(index); - if(!ui->usernameTextBox->count()) - { - blockToggles = true; - ui->rememberUsernameCheckbox->setChecked(false); - ui->rememberPasswordCheckbox->setChecked(false); - blockToggles = false; - } -} - -void LoginDialog::passwordToggled ( bool state ) -{ - // if toggled off - if(blockToggles) - return; - blockToggles = true; - if(!state) - { - QLOG_DEBUG() << "password disabled"; - } - else - { - if(!ui->rememberUsernameCheckbox->isChecked()) - { - ui->rememberUsernameCheckbox->setChecked(true); - } - QLOG_DEBUG() << "password enabled"; - } - blockToggles = false; -} - -void LoginDialog::usernameToggled ( bool state ) -{ - // if toggled off - if(blockToggles) - return; - blockToggles = true; - if(!state) - { - if(ui->rememberPasswordCheckbox->isChecked()) - { - ui->rememberPasswordCheckbox->setChecked(false); - } - QLOG_DEBUG() << "username disabled"; - } - else - { - QLOG_DEBUG() << "username enabled"; - } - blockToggles = false; -} - - -void LoginDialog::userTextChanged ( const QString& user ) -{ - blockToggles = true; - Keyring * k = Keyring::instance(); - QStringList sl = k->getStoredAccounts("minecraft"); - bool gotFace = false; - - if(sl.contains(user)) - { - ui->rememberUsernameCheckbox->setChecked(true); - QString passwd = k->getPassword("minecraft",user); - ui->rememberPasswordCheckbox->setChecked(!passwd.isEmpty()); - ui->passwordTextBox->setText(passwd); - - QByteArray data; - { - auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); - QFile listFile(filename); - if(!listFile.open(QIODevice::ReadOnly)) - return; - data = listFile.readAll(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - QJsonObject root = jsonDoc.object(); - QJsonObject mappings = root.value("mappings").toObject(); - - if(!mappings[user].isUndefined()) - { - QJsonArray usernames = mappings.value(user).toArray(); - if(!usernames.isEmpty()) - { - QString mapped_username = usernames[0].toString(); - - if(!mapped_username.isEmpty()) - { - QFile fskin(MMC->metacache()->resolveEntry("skins", mapped_username + ".png")->getFullPath()); - if(fskin.exists()) - { - QPixmap skin(MMC->metacache()->resolveEntry("skins", mapped_username + ".png")->getFullPath()); - QPixmap face = skin.copy(8, 8, 8, 8).scaled(48, 48, Qt::KeepAspectRatio); - - ui->lblFace->setPixmap(face); - gotFace = true; - } - } - } - } - } - - ui->lblFace->setVisible(gotFace); - blockToggles = false; -} - - -void LoginDialog::accept() -{ - bool saveName = ui->rememberUsernameCheckbox->isChecked(); - bool savePass = ui->rememberPasswordCheckbox->isChecked(); - Keyring * k = Keyring::instance(); - if(saveName) - { - if(savePass) - { - k->storePassword("minecraft",getUsername(),getPassword()); - } - else - { - k->storePassword("minecraft",getUsername(),QString()); - } - } - else - { - QString acct = ui->usernameTextBox->currentText(); - k->removeStoredAccount("minecraft", acct); - } - QDialog::accept(); -} - -void LoginDialog::launchOffline() -{ - isOnline_ = false; - QDialog::accept(); -} - -void LoginDialog::forceOnline() -{ - onlineForced = true; - offlineButton->setEnabled(false); -} diff --git a/gui/logindialog.h b/gui/logindialog.h deleted file mode 100644 index f7c0e930..00000000 --- a/gui/logindialog.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef LOGINDIALOG_H -#define LOGINDIALOG_H - -#include -#include - -namespace Ui { -class LoginDialog; -} - -class LoginDialog : public QDialog -{ - Q_OBJECT - -public: - explicit LoginDialog(QWidget *parent = 0, const QString& loginErrMsg = ""); - ~LoginDialog(); - - QString getUsername() const; - QString getPassword() const; - - inline bool isOnline() { return isOnline_; } - - void forceOnline(); - -public slots: - virtual void accept(); - virtual void userTextChanged(const QString& user); - virtual void forgetCurrentUser(); -private slots: - void usernameToggled ( bool ); - void passwordToggled ( bool ); - void launchOffline(); -private: - Ui::LoginDialog *ui; - bool blockToggles; - QPushButton *offlineButton; - bool isOnline_; - bool onlineForced; -}; - -#endif // LOGINDIALOG_H diff --git a/gui/logindialog.ui b/gui/logindialog.ui deleted file mode 100644 index 94900d72..00000000 --- a/gui/logindialog.ui +++ /dev/null @@ -1,185 +0,0 @@ - - - LoginDialog - - - - 0 - 0 - 476 - 168 - - - - Login - - - - - - <span style=" color:#ff0000;">Error</span> - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - - - - - 48 - 48 - - - - - 48 - 48 - - - - - 1 - 1 - - - - - - - :/icons/instances/steve - - - true - - - - - - - true - - - - - - - Username: - - - - - - - Password: - - - - - - - QLineEdit::Password - - - Password - - - - - - - - - - - - 1 - 0 - - - - &Remember Username? - - - - - - - - 1 - 0 - - - - R&emember Password? - - - - - - - - 0 - 0 - - - - Forget - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - loginButtonBox - accepted() - LoginDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - loginButtonBox - rejected() - LoginDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/lwjglselectdialog.cpp b/gui/lwjglselectdialog.cpp deleted file mode 100644 index 09963ce0..00000000 --- a/gui/lwjglselectdialog.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MultiMC.h" -#include "lwjglselectdialog.h" -#include "ui_lwjglselectdialog.h" -#include "gui/platform.h" - -#include "logic/lists/LwjglVersionList.h" - -LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::LWJGLSelectDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - ui->labelStatus->setVisible(false); - auto lwjgllist = MMC->lwjgllist(); - ui->lwjglListView->setModel(lwjgllist.get()); - - connect(lwjgllist.get(), SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); - connect(lwjgllist.get(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); - loadingStateUpdated(lwjgllist->isLoading()); -} - -LWJGLSelectDialog::~LWJGLSelectDialog() -{ - delete ui; -} - -QString LWJGLSelectDialog::selectedVersion() const -{ - return MMC->lwjgllist()->data( - ui->lwjglListView->selectionModel()->currentIndex(), - Qt::DisplayRole).toString(); -} - -void LWJGLSelectDialog::on_refreshButton_clicked() -{ - if (!MMC->lwjgllist()->isLoading()) - MMC->lwjgllist()->loadList(); -} - -void LWJGLSelectDialog::loadingStateUpdated(bool loading) -{ - setEnabled(!loading); - if (loading) - { - ui->labelStatus->setText(tr("Loading LWJGL version list...")); - ui->labelStatus->setStyleSheet("QLabel { color: black; }"); - } - ui->labelStatus->setVisible(loading); -} - -void LWJGLSelectDialog::loadingFailed(QString error) -{ - ui->labelStatus->setText(error); - ui->labelStatus->setStyleSheet("QLabel { color: red; }"); - ui->labelStatus->setVisible(true); -} diff --git a/gui/lwjglselectdialog.h b/gui/lwjglselectdialog.h deleted file mode 100644 index 1772904a..00000000 --- a/gui/lwjglselectdialog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef LWJGLSELECTDIALOG_H -#define LWJGLSELECTDIALOG_H - -#include - -namespace Ui -{ -class LWJGLSelectDialog; -} - -class LWJGLSelectDialog : public QDialog -{ - Q_OBJECT - -public: - explicit LWJGLSelectDialog(QWidget *parent = 0); - ~LWJGLSelectDialog(); - - QString selectedVersion() const; - -private slots: - void on_refreshButton_clicked(); - - void loadingStateUpdated(bool loading); - void loadingFailed(QString error); - -private: - Ui::LWJGLSelectDialog *ui; -}; - -#endif // LWJGLSELECTDIALOG_H diff --git a/gui/lwjglselectdialog.ui b/gui/lwjglselectdialog.ui deleted file mode 100644 index c715cc07..00000000 --- a/gui/lwjglselectdialog.ui +++ /dev/null @@ -1,85 +0,0 @@ - - - LWJGLSelectDialog - - - - 0 - 0 - 400 - 300 - - - - Dialog - - - - - - Status label... - - - - - - - - - - - - &Refresh - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - buttonBox - accepted() - LWJGLSelectDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - LWJGLSelectDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp deleted file mode 100644 index 20a2b84b..00000000 --- a/gui/mainwindow.cpp +++ /dev/null @@ -1,974 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Andrew Okin - * Peterix - * Orochimarufan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "keyring.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "osutils.h" -#include "userutils.h" -#include "pathutils.h" - -#include "categorizedview.h" -#include "categorydrawer.h" - -#include "gui/settingsdialog.h" -#include "gui/newinstancedialog.h" -#include "gui/logindialog.h" -#include "gui/ProgressDialog.h" -#include "gui/aboutdialog.h" -#include "gui/versionselectdialog.h" -#include "gui/lwjglselectdialog.h" -#include "gui/consolewindow.h" -#include "gui/instancesettings.h" -#include "gui/platform.h" -#include "gui/CustomMessageBox.h" - -#include "logic/lists/InstanceList.h" -#include "logic/lists/MinecraftVersionList.h" -#include "logic/lists/LwjglVersionList.h" -#include "logic/lists/IconList.h" -#include "logic/lists/JavaVersionList.h" - -#include "logic/net/LoginTask.h" - -#include "logic/BaseInstance.h" -#include "logic/InstanceFactory.h" -#include "logic/MinecraftProcess.h" -#include "logic/OneSixAssets.h" -#include "logic/OneSixUpdate.h" -#include "logic/JavaUtils.h" -#include "logic/NagUtils.h" - -#include "logic/LegacyInstance.h" - -#include "instancedelegate.h" -#include "IconPickerDialog.h" -#include "LabeledToolButton.h" -#include "EditNotesDialog.h" -#include "CopyInstanceDialog.h" - -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - setWindowTitle(QString("MultiMC %1").arg(MMC->version().toString())); - - // Set the selected instance to null - m_selectedInstance = nullptr; - // Set active instance to null. - m_activeInst = nullptr; - - // OSX magic. - setUnifiedTitleAndToolBarOnMac(true); - - // The instance action toolbar customizations - { - // disabled until we have an instance selected - ui->instanceToolBar->setEnabled(false); - - // the rename label is inside the rename tool button - renameButton = new LabeledToolButton(); - renameButton->setText("Instance Name"); - renameButton->setToolTip(ui->actionRenameInstance->toolTip()); - connect(renameButton, SIGNAL(clicked(bool)), SLOT(on_actionRenameInstance_triggered())); - ui->instanceToolBar->insertWidget(ui->actionLaunchInstance, renameButton); - ui->instanceToolBar->insertSeparator(ui->actionLaunchInstance); - renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - } - - // Create the instance list widget - { - view = new KCategorizedView(ui->centralWidget); - drawer = new KCategoryDrawer(view); - - view->setSelectionMode(QAbstractItemView::SingleSelection); - view->setCategoryDrawer(drawer); - view->setCollapsibleBlocks(true); - view->setViewMode(QListView::IconMode); - view->setFlow(QListView::LeftToRight); - view->setWordWrap(true); - view->setMouseTracking(true); - view->viewport()->setAttribute(Qt::WA_Hover); - auto delegate = new ListViewDelegate(); - view->setItemDelegate(delegate); - view->setSpacing(10); - view->setUniformItemWidths(true); - - // do not show ugly blue border on the mac - view->setAttribute(Qt::WA_MacShowFocusRect, false); - - view->installEventFilter(this); - - proxymodel = new InstanceProxyModel(this); -// proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole); - //proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole); - // proxymodel->setDynamicSortFilter ( true ); - - // FIXME: instList should be global-ish, or at least not tied to the main window... - // maybe the application itself? - proxymodel->setSourceModel(MMC->instances().get()); - proxymodel->sort(0); - view->setFrameShape(QFrame::NoFrame); - view->setModel(proxymodel); - - ui->horizontalLayout->addWidget(view); - } - // The cat background - { - bool cat_enable = MMC->settings()->get("TheCat").toBool(); - ui->actionCAT->setChecked(cat_enable); - connect(ui->actionCAT, SIGNAL(toggled(bool)), SLOT(onCatToggled(bool))); - setCatBackground(cat_enable); - } - // start instance when double-clicked - connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, - SLOT(instanceActivated(const QModelIndex &))); - // track the selection -- update the instance toolbar - connect(view->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, - SLOT(instanceChanged(const QModelIndex &, const QModelIndex &))); - // model reset -> selection is invalid. All the instance pointers are wrong. - // FIXME: stop using POINTERS everywhere - connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad())); - - m_statusLeft = new QLabel(tr("Instance type"), this); - m_statusRight = new QLabel(tr("Assets information"), this); - m_statusRight->setAlignment(Qt::AlignRight); - statusBar()->addPermanentWidget(m_statusLeft, 1); - statusBar()->addPermanentWidget(m_statusRight, 0); - - // run the things that load and download other things... FIXME: this is NOT the place - // FIXME: invisible actions in the background = NOPE. - { - if (!MMC->minecraftlist()->isLoaded()) - { - m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); - startTask(m_versionLoadTask); - } - if (!MMC->lwjgllist()->isLoaded()) - { - MMC->lwjgllist()->loadList(); - } - assets_downloader = new OneSixAssets(); - connect(assets_downloader, SIGNAL(indexStarted()), SLOT(assetsIndexStarted())); - connect(assets_downloader, SIGNAL(filesStarted()), SLOT(assetsFilesStarted())); - connect(assets_downloader, SIGNAL(filesProgress(int, int, int)), - SLOT(assetsFilesProgress(int, int, int))); - connect(assets_downloader, SIGNAL(failed()), SLOT(assetsFailed())); - connect(assets_downloader, SIGNAL(finished()), SLOT(assetsFinished())); - assets_downloader->start(); - } -} - -MainWindow::~MainWindow() -{ - delete ui; - delete proxymodel; - delete drawer; - delete assets_downloader; -} - -bool MainWindow::eventFilter(QObject *obj, QEvent *ev) -{ - if (obj == view) - { - if (ev->type() == QEvent::KeyPress) - { - QKeyEvent *keyEvent = static_cast(ev); - switch (keyEvent->key()) - { - case Qt::Key_Enter: - case Qt::Key_Return: - on_actionLaunchInstance_triggered(); - return true; - case Qt::Key_Delete: - on_actionDeleteInstance_triggered(); - return true; - case Qt::Key_F5: - on_actionRefresh_triggered(); - return true; - case Qt::Key_F2: - on_actionRenameInstance_triggered(); - return true; - default: - break; - } - } - } - return QMainWindow::eventFilter(obj, ev); -} - -void MainWindow::onCatToggled(bool state) -{ - setCatBackground(state); - MMC->settings()->set("TheCat", state); -} - -void MainWindow::setCatBackground(bool enabled) -{ - if (enabled) - { - view->setStyleSheet("QListView" - "{" - "background-image: url(:/backgrounds/kitteh);" - "background-attachment: fixed;" - "background-clip: padding;" - "background-position: top right;" - "background-repeat: none;" - "background-color:palette(base);" - "}"); - } - else - { - view->setStyleSheet(QString()); - } -} - -void MainWindow::on_actionAddInstance_triggered() -{ - if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && - m_versionLoadTask->isRunning()) - { - QEventLoop waitLoop; - waitLoop.connect(m_versionLoadTask, SIGNAL(failed(QString)), SLOT(quit())); - waitLoop.connect(m_versionLoadTask, SIGNAL(succeeded()), SLOT(quit())); - waitLoop.exec(); - } - - NewInstanceDialog newInstDlg(this); - if (!newInstDlg.exec()) - return; - - BaseInstance *newInstance = NULL; - - QString instancesDir = MMC->settings()->get("InstanceDir").toString(); - QString instDirName = DirNameFromString(newInstDlg.instName(), instancesDir); - QString instDir = PathCombine(instancesDir, instDirName); - - auto &loader = InstanceFactory::get(); - - auto error = loader.createInstance(newInstance, newInstDlg.selectedVersion(), instDir); - QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); - switch (error) - { - case InstanceFactory::NoCreateError: - newInstance->setName(newInstDlg.instName()); - newInstance->setIconKey(newInstDlg.iconKey()); - MMC->instances()->add(InstancePtr(newInstance)); - return; - - case InstanceFactory::InstExists: - { - errorMsg += "An instance with the given directory name already exists."; - CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); - break; - } - - case InstanceFactory::CantCreateDir: - { - errorMsg += "Failed to create the instance directory."; - CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); - break; - } - - default: - { - errorMsg += QString("Unknown instance loader error %1").arg(error); - CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); - break; - } - } -} - -void MainWindow::on_actionCopyInstance_triggered() -{ - if (!m_selectedInstance) - return; - - CopyInstanceDialog copyInstDlg(m_selectedInstance, this); - if (!copyInstDlg.exec()) - return; - - QString instancesDir = MMC->settings()->get("InstanceDir").toString(); - QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir); - QString instDir = PathCombine(instancesDir, instDirName); - - auto &loader = InstanceFactory::get(); - - BaseInstance *newInstance = NULL; - auto error = loader.copyInstance(newInstance, m_selectedInstance, instDir); - - QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); - switch (error) - { - case InstanceFactory::NoCreateError: - newInstance->setName(copyInstDlg.instName()); - newInstance->setIconKey(copyInstDlg.iconKey()); - MMC->instances()->add(InstancePtr(newInstance)); - return; - - case InstanceFactory::InstExists: - { - errorMsg += "An instance with the given directory name already exists."; - CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); - break; - } - - case InstanceFactory::CantCreateDir: - { - errorMsg += "Failed to create the instance directory."; - CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); - break; - } - - default: - { - errorMsg += QString("Unknown instance loader error %1").arg(error); - CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); - break; - } - } -} - -void MainWindow::on_actionChangeInstIcon_triggered() -{ - if (!m_selectedInstance) - return; - - IconPickerDialog dlg(this); - dlg.exec(m_selectedInstance->iconKey()); - if (dlg.result() == QDialog::Accepted) - { - m_selectedInstance->setIconKey(dlg.selectedIconKey); - auto ico = MMC->icons()->getIcon(dlg.selectedIconKey); - ui->actionChangeInstIcon->setIcon(ico); - } -} - -void MainWindow::on_actionChangeInstGroup_triggered() -{ - if (!m_selectedInstance) - return; - - bool ok = false; - QString name(m_selectedInstance->group()); - name = QInputDialog::getText(this, tr("Group name"), tr("Enter a new group name."), - QLineEdit::Normal, name, &ok); - if (ok) - m_selectedInstance->setGroupPost(name); -} - -void MainWindow::on_actionViewInstanceFolder_triggered() -{ - QString str = MMC->settings()->get("InstanceDir").toString(); - openDirInDefaultProgram(str); -} - -void MainWindow::on_actionRefresh_triggered() -{ - MMC->instances()->loadList(); -} - -void MainWindow::on_actionViewCentralModsFolder_triggered() -{ - openDirInDefaultProgram(MMC->settings()->get("CentralModsDir").toString(), true); -} - -void MainWindow::on_actionConfig_Folder_triggered() -{ - if (m_selectedInstance) - { - QString str = m_selectedInstance->instanceConfigFolder(); - openDirInDefaultProgram(QDir(str).absolutePath()); - } -} - -void MainWindow::on_actionCheckUpdate_triggered() -{ -} - -void MainWindow::on_actionSettings_triggered() -{ - SettingsDialog dialog(this); - dialog.exec(); - //FIXME: quick HACK to make this work. improve, optimize. - proxymodel->invalidate(); - proxymodel->sort(0); -} - -void MainWindow::on_actionReportBug_triggered() -{ - openWebPage(QUrl("http://multimc.myjetbrains.com/youtrack/dashboard#newissue=yes")); -} - -void MainWindow::on_actionNews_triggered() -{ - openWebPage(QUrl("http://multimc.org/posts.html")); -} - -void MainWindow::on_actionAbout_triggered() -{ - AboutDialog dialog(this); - dialog.exec(); -} - -void MainWindow::on_mainToolBar_visibilityChanged(bool) -{ - // Don't allow hiding the main toolbar. - // This is the only way I could find to prevent it... :/ - ui->mainToolBar->setVisible(true); -} - -void MainWindow::on_actionDeleteInstance_triggered() -{ - if (m_selectedInstance) - { - auto response = CustomMessageBox::selectable( - this, tr("CAREFUL"), tr("This is permanent! Are you sure?\nAbout to delete: ") + - m_selectedInstance->name(), - QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); - if (response == QMessageBox::Yes) - { - m_selectedInstance->nuke(); - } - } -} - -void MainWindow::on_actionRenameInstance_triggered() -{ - if (m_selectedInstance) - { - bool ok = false; - QString name(m_selectedInstance->name()); - name = - QInputDialog::getText(this, tr("Instance name"), tr("Enter a new instance name."), - QLineEdit::Normal, name, &ok); - - if (name.length() > 0) - { - if (ok && name.length()) - { - m_selectedInstance->setName(name); - renameButton->setText(name); - } - } - } -} - -void MainWindow::on_actionViewSelectedInstFolder_triggered() -{ - if (m_selectedInstance) - { - QString str = m_selectedInstance->instanceRoot(); - openDirInDefaultProgram(QDir(str).absolutePath()); - } -} - -void MainWindow::on_actionEditInstMods_triggered() -{ - if (m_selectedInstance) - { - auto dialog = m_selectedInstance->createModEditDialog(this); - if (dialog) - dialog->exec(); - dialog->deleteLater(); - } -} - -void MainWindow::closeEvent(QCloseEvent *event) -{ - // Save the window state and geometry. - - MMC->settings()->set("MainWindowState", saveState().toBase64()); - MMC->settings()->set("MainWindowGeometry", saveGeometry().toBase64()); - - QMainWindow::closeEvent(event); - QApplication::exit(); -} -/* -void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) -{ - QMenu *instContextMenu = new QMenu("Instance", this); - - // Add the actions from the toolbar to the context menu. - instContextMenu->addActions(ui->instanceToolBar->actions()); - - instContextMenu->exec(view->mapToGlobal(pos)); -} -*/ -void MainWindow::instanceActivated(QModelIndex index) -{ - if (!index.isValid()) - return; - - BaseInstance *inst = - (BaseInstance *)index.data(InstanceList::InstancePointerRole).value(); - - NagUtils::checkJVMArgs(MMC->settings()->get("JvmArgs").toString(), this); - - bool autoLogin = MMC->settings()->get("AutoLogin").toBool(); - if (autoLogin) - doAutoLogin(); - else - doLogin(); -} - -void MainWindow::on_actionLaunchInstance_triggered() -{ - if (m_selectedInstance) - { - NagUtils::checkJVMArgs(MMC->settings()->get("JvmArgs").toString(), this); - doLogin(); - } -} - -void MainWindow::doAutoLogin() -{ - if (!m_selectedInstance) - return; - - Keyring *k = Keyring::instance(); - QStringList accounts = k->getStoredAccounts("minecraft"); - - if (!accounts.isEmpty()) - { - QString username = accounts[0]; - QString password = k->getPassword("minecraft", username); - - if (!password.isEmpty()) - { - QLOG_INFO() << "Automatically logging in with stored account: " << username; - m_activeInst = m_selectedInstance; - doLogin(username, password); - } - else - { - QLOG_ERROR() << "Auto login set for account, but no password was found: " - << username; - doLogin(tr("Auto login attempted, but no password is stored.")); - } - } - else - { - QLOG_ERROR() << "Auto login set but no accounts were stored."; - doLogin(tr("Auto login attempted, but no accounts are stored.")); - } -} - -void MainWindow::doLogin(QString username, QString password) -{ - UserInfo uInfo{username, password}; - - ProgressDialog *tDialog = new ProgressDialog(this); - LoginTask *loginTask = new LoginTask(uInfo, tDialog); - connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection); - connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); - - tDialog->exec(loginTask); -} - -void MainWindow::doLogin(const QString &errorMsg) -{ - if (!m_selectedInstance) - return; - - LoginDialog *loginDlg = new LoginDialog(this, errorMsg); - if (!m_selectedInstance->lastLaunch()) - loginDlg->forceOnline(); - - loginDlg->exec(); - if (loginDlg->result() == QDialog::Accepted) - { - if (loginDlg->isOnline()) - { - m_activeInst = m_selectedInstance; - doLogin(loginDlg->getUsername(), loginDlg->getPassword()); - } - else - { - QString user = loginDlg->getUsername(); - if (user.length() == 0) - user = QString("Player"); - m_activeLogin = {user, QString("Offline"), user, QString()}; - m_activeInst = m_selectedInstance; - launchInstance(m_activeInst, m_activeLogin); - } - } -} - -void MainWindow::onLoginComplete() -{ - if (!m_activeInst) - return; - LoginTask *task = (LoginTask *)QObject::sender(); - m_activeLogin = task->getResult(); - - BaseUpdate *updateTask = m_activeInst->doUpdate(); - if (!updateTask) - { - launchInstance(m_activeInst, m_activeLogin); - } - else - { - ProgressDialog tDialog(this); - connect(updateTask, SIGNAL(succeeded()), SLOT(onGameUpdateComplete())); - connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); - tDialog.exec(updateTask); - delete updateTask; - } - - auto job = new NetJob("Player skin: " + m_activeLogin.player_name); - - auto meta = MMC->metacache()->resolveEntry("skins", m_activeLogin.player_name + ".png"); - auto action = CacheDownload::make( - QUrl("http://skins.minecraft.net/MinecraftSkins/" + m_activeLogin.player_name + ".png"), - meta); - job->addNetAction(action); - meta->stale = true; - - job->start(); - auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath(); - QFile listFile(filename); - - // Add skin mapping - QByteArray data; - { - if (!listFile.open(QIODevice::ReadWrite)) - { - QLOG_ERROR() << "Failed to open/make skins list JSON"; - return; - } - - data = listFile.readAll(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - QJsonObject root = jsonDoc.object(); - QJsonObject mappings = root.value("mappings").toObject(); - QJsonArray usernames = mappings.value(m_activeLogin.username).toArray(); - - if (!usernames.contains(m_activeLogin.player_name)) - { - usernames.prepend(m_activeLogin.player_name); - mappings[m_activeLogin.username] = usernames; - root["mappings"] = mappings; - jsonDoc.setObject(root); - - // QJson hack - shouldn't have to clear the file every time a save happens - listFile.resize(0); - listFile.write(jsonDoc.toJson()); - } -} - -void MainWindow::onGameUpdateComplete() -{ - launchInstance(m_activeInst, m_activeLogin); -} - -void MainWindow::onGameUpdateError(QString error) -{ - CustomMessageBox::selectable(this, tr("Error updating instance"), error, - QMessageBox::Warning)->show(); -} - -void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) -{ - Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); - - proc = instance->prepareForLaunch(response); - if (!proc) - return; - - // Prepare GUI: If it shall stay open disable the required parts - if (MMC->settings()->get("NoHide").toBool()) - { - ui->actionLaunchInstance->setEnabled(false); - } - else - { - this->hide(); - } - - console = new ConsoleWindow(proc); - - connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, - SLOT(write(QString, MessageLevel::Enum))); - connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); - - if (instance->settings().get("ShowConsole").toBool()) - { - console->show(); - } - - proc->setLogin(response.username, response.session_id); - proc->launch(); -} - -void MainWindow::taskStart() -{ - // Nothing to do here yet. -} - -void MainWindow::taskEnd() -{ - QObject *sender = QObject::sender(); - if (sender == m_versionLoadTask) - m_versionLoadTask = NULL; - - sender->deleteLater(); -} - -void MainWindow::startTask(Task *task) -{ - connect(task, SIGNAL(started()), SLOT(taskStart())); - connect(task, SIGNAL(succeeded()), SLOT(taskEnd())); - connect(task, SIGNAL(failed(QString)), SLOT(taskEnd())); - task->start(); -} - -// Create A Desktop Shortcut -void MainWindow::on_actionMakeDesktopShortcut_triggered() -{ - QString name("Test"); - name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."), - QLineEdit::Normal, name); - - Util::createShortCut(Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), - QStringList() << "-dl" << QDir::currentPath() << "test", name, - "application-x-octet-stream"); - - CustomMessageBox::selectable( - this, tr("Not useful"), - tr("A Dummy Shortcut was created. it will not do anything productive"), - QMessageBox::Warning)->show(); -} - -// BrowserDialog -void MainWindow::openWebPage(QUrl url) -{ - QDesktopServices::openUrl(url); -} - -void MainWindow::on_actionChangeInstMCVersion_triggered() -{ - if (view->selectionModel()->selectedIndexes().count() < 1) - return; - - VersionSelectDialog vselect(m_selectedInstance->versionList().get(), - tr("Change Minecraft version"), this); - vselect.setFilter(1, "OneSix"); - if (vselect.exec() && vselect.selectedVersion()) - { - if (m_selectedInstance->versionIsCustom()) - { - auto result = CustomMessageBox::selectable( - this, tr("Are you sure?"), - tr("This will remove any library/version customization you did previously. " - "This includes things like Forge install and similar."), - QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Abort)->exec(); - - if (result != QMessageBox::Ok) - return; - } - m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); - } -} - -void MainWindow::on_actionChangeInstLWJGLVersion_triggered() -{ - if (!m_selectedInstance) - return; - - LWJGLSelectDialog lselect(this); - lselect.exec(); - if (lselect.result() == QDialog::Accepted) - { - LegacyInstance *linst = (LegacyInstance *)m_selectedInstance; - linst->setLWJGLVersion(lselect.selectedVersion()); - } -} - -void MainWindow::on_actionInstanceSettings_triggered() -{ - if (view->selectionModel()->selectedIndexes().count() < 1) - return; - - InstanceSettings settings(&m_selectedInstance->settings(), this); - settings.setWindowTitle(QString("Instance settings")); - settings.exec(); -} - -void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &previous) -{ - if (current.isValid() && - nullptr != (m_selectedInstance = - (BaseInstance *)current.data(InstanceList::InstancePointerRole) - .value())) - { - ui->instanceToolBar->setEnabled(true); - QString iconKey = m_selectedInstance->iconKey(); - renameButton->setText(m_selectedInstance->name()); - ui->actionChangeInstLWJGLVersion->setEnabled( - m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); - ui->actionEditInstMods->setEnabled( - m_selectedInstance->menuActionEnabled("actionEditInstMods")); - ui->actionChangeInstMCVersion->setEnabled( - m_selectedInstance->menuActionEnabled("actionChangeInstMCVersion")); - m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); - auto ico = MMC->icons()->getIcon(iconKey); - ui->actionChangeInstIcon->setIcon(ico); - } - else - { - selectionBad(); - } -} - -void MainWindow::selectionBad() -{ - m_selectedInstance = nullptr; - QString iconKey = "infinity"; - statusBar()->clearMessage(); - ui->instanceToolBar->setEnabled(false); - renameButton->setText(tr("Rename Instance")); - auto ico = MMC->icons()->getIcon(iconKey); - ui->actionChangeInstIcon->setIcon(ico); -} - -void MainWindow::on_actionEditInstNotes_triggered() -{ - if (!m_selectedInstance) - return; - LegacyInstance *linst = (LegacyInstance *)m_selectedInstance; - - EditNotesDialog noteedit(linst->notes(), linst->name(), this); - noteedit.exec(); - if (noteedit.result() == QDialog::Accepted) - { - - linst->setNotes(noteedit.getText()); - } -} - -void MainWindow::instanceEnded(BaseInstance *instance) -{ - this->show(); - ui->actionLaunchInstance->setEnabled(m_selectedInstance); - - if (instance->settings().get("AutoCloseConsole").toBool()) - { - console->close(); - } -} - -void MainWindow::checkSetDefaultJava() -{ - bool askForJava = false; - { - QString currentHostName = QHostInfo::localHostName(); - QString oldHostName = MMC->settings()->get("LastHostname").toString(); - if (currentHostName != oldHostName) - { - MMC->settings()->set("LastHostname", currentHostName); - askForJava = true; - } - } - - { - QString currentJavaPath = MMC->settings()->get("JavaPath").toString(); - if (currentJavaPath.isEmpty()) - { - askForJava = true; - } - } - - if (askForJava) - { - QLOG_DEBUG() << "Java path needs resetting, showing Java selection dialog..."; - - JavaVersionPtr java; - - VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, - false); - vselect.setResizeOn(2); - vselect.exec(); - - if (vselect.selectedVersion()) - java = std::dynamic_pointer_cast(vselect.selectedVersion()); - else - { - CustomMessageBox::selectable( - this, tr("Invalid version selected"), - tr("You didn't select a valid Java version, so MultiMC will " - "select the default. " - "You can change this in the settings dialog."), - QMessageBox::Warning)->show(); - - JavaUtils ju; - java = ju.GetDefaultJava(); - } - if (java) - MMC->settings()->set("JavaPath", java->path); - else - MMC->settings()->set("JavaPath", QString("java")); - } -} - -void MainWindow::assetsIndexStarted() -{ - m_statusRight->setText(tr("Checking assets...")); -} - -void MainWindow::assetsFilesStarted() -{ - m_statusRight->setText(tr("Downloading assets...")); -} - -void MainWindow::assetsFilesProgress(int succeeded, int failed, int total) -{ - QString status = tr("Downloading assets: %1 / %2").arg(succeeded + failed).arg(total); - if (failed > 0) - status += tr(" (%1 failed)").arg(failed); - status += tr("..."); - m_statusRight->setText(status); -} - -void MainWindow::assetsFailed() -{ - m_statusRight->setText(tr("Failed to update assets.")); -} - -void MainWindow::assetsFinished() -{ - m_statusRight->setText(tr("Assets up to date.")); -} diff --git a/gui/mainwindow.h b/gui/mainwindow.h deleted file mode 100644 index 36562563..00000000 --- a/gui/mainwindow.h +++ /dev/null @@ -1,170 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -#include "logic/lists/InstanceList.h" -#include "logic/net/LoginTask.h" -#include "logic/BaseInstance.h" - -class QToolButton; -class LabeledToolButton; -class QLabel; -class InstanceProxyModel; -class KCategorizedView; -class KCategoryDrawer; -class MinecraftProcess; -class ConsoleWindow; -class OneSixAssets; - -namespace Ui -{ -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - - void closeEvent(QCloseEvent *event); - - // Browser Dialog - void openWebPage(QUrl url); - - void checkSetDefaultJava(); - -private -slots: - void onCatToggled(bool); - - void on_actionAbout_triggered(); - - void on_actionAddInstance_triggered(); - - void on_actionCopyInstance_triggered(); - - void on_actionChangeInstGroup_triggered(); - - void on_actionChangeInstIcon_triggered(); - - void on_actionViewInstanceFolder_triggered(); - - void on_actionConfig_Folder_triggered(); - - void on_actionViewSelectedInstFolder_triggered(); - - void on_actionRefresh_triggered(); - - void on_actionViewCentralModsFolder_triggered(); - - void on_actionCheckUpdate_triggered(); - - void on_actionSettings_triggered(); - - void on_actionReportBug_triggered(); - - void on_actionNews_triggered(); - - void on_mainToolBar_visibilityChanged(bool); - - // void on_instanceView_customContextMenuRequested(const QPoint &pos); - - void on_actionLaunchInstance_triggered(); - - void on_actionDeleteInstance_triggered(); - - void on_actionRenameInstance_triggered(); - - void on_actionMakeDesktopShortcut_triggered(); - - void on_actionChangeInstMCVersion_triggered(); - - void on_actionEditInstMods_triggered(); - - void on_actionEditInstNotes_triggered(); - - void doLogin(const QString &errorMsg = ""); - void doLogin(QString username, QString password); - void doAutoLogin(); - - void onLoginComplete(); - - void onGameUpdateComplete(); - void onGameUpdateError(QString error); - - void taskStart(); - void taskEnd(); - - void on_actionChangeInstLWJGLVersion_triggered(); - - void instanceEnded(BaseInstance *instance); - - void on_actionInstanceSettings_triggered(); - - void assetsIndexStarted(); - void assetsFilesStarted(); - void assetsFilesProgress(int, int, int); - void assetsFailed(); - void assetsFinished(); - -public -slots: - void instanceActivated(QModelIndex); - - void instanceChanged(const QModelIndex ¤t, const QModelIndex &previous); - - void selectionBad(); - - void startTask(Task *task); - - void launchInstance(BaseInstance *inst, LoginResponse response); - -protected: - bool eventFilter(QObject *obj, QEvent *ev); - void setCatBackground(bool enabled); - -private: - Ui::MainWindow *ui; - KCategoryDrawer *drawer; - KCategorizedView *view; - InstanceProxyModel *proxymodel; - MinecraftProcess *proc; - ConsoleWindow *console; - OneSixAssets *assets_downloader; - LabeledToolButton *renameButton; - QToolButton *changeIconButton; - - BaseInstance *m_selectedInstance; - - // A pointer to the instance we are actively doing stuff with. - // This is set when the user launches an instance and is used to refer to that - // instance throughout the launching process. - BaseInstance *m_activeInst; - LoginResponse m_activeLogin; - - Task *m_versionLoadTask; - - QLabel *m_statusLeft; - QLabel *m_statusRight; -}; - -#endif // MAINWINDOW_H diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui deleted file mode 100644 index 6f70fc98..00000000 --- a/gui/mainwindow.ui +++ /dev/null @@ -1,474 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 688 - 650 - - - - MultiMC 5 - - - - :/icons/multimc/scalable/apps/multimc.svg:/icons/multimc/scalable/apps/multimc.svg - - - - - 0 - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - Main Toolbar - - - false - - - Qt::TopToolBarArea - - - Qt::ToolButtonIconOnly - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - - - - - - - - - - - true - - - Instance Toolbar - - - Qt::LeftToolBarArea|Qt::RightToolBarArea - - - - 80 - 80 - - - - Qt::ToolButtonIconOnly - - - false - - - RightToolBarArea - - - false - - - - - - - - - - - - - - - - - - - - :/icons/toolbar/new:/icons/toolbar/new - - - Add Instance - - - Add a new instance. - - - Add a new instance. - - - - - - :/icons/toolbar/viewfolder:/icons/toolbar/viewfolder - - - View Instance Folder - - - Open the instance folder in a file browser. - - - Open the instance folder in a file browser. - - - - - - :/icons/toolbar/refresh:/icons/toolbar/refresh - - - Refresh - - - Reload the instance list. - - - Reload the instance list. - - - - - - :/icons/toolbar/centralmods:/icons/toolbar/centralmods - - - View Central Mods Folder - - - Open the central mods folder in a file browser. - - - Open the central mods folder in a file browser. - - - - - - :/icons/toolbar/checkupdate:/icons/toolbar/checkupdate - - - Check for Updates - - - Check for new updates for MultiMC - - - Check for new updates for MultiMC - - - - - - :/icons/toolbar/settings:/icons/toolbar/settings - - - Settings - - - Change settings. - - - Change settings. - - - QAction::PreferencesRole - - - - - - :/icons/toolbar/bug:/icons/toolbar/bug - - - Report a Bug - - - Open the bug tracker to report a bug with MultiMC. - - - Open the bug tracker to report a bug with MultiMC. - - - - - - :/icons/toolbar/news:/icons/toolbar/news - - - News - - - Open the MultiMC dev blog to read news about MultiMC. - - - Open the MultiMC dev blog to read news about MultiMC. - - - - - - :/icons/toolbar/about:/icons/toolbar/about - - - About MultiMC - - - View information about MultiMC. - - - About MultiMC - - - QAction::AboutRole - - - - - Play - - - Launch the selected instance. - - - Launch the selected instance. - - - - - Instance Name - - - Rename the selected instance. - - - Rename the selected instance. - - - - - Change Group - - - Change the selected instance's group. - - - Change the selected instance's group. - - - - - true - - - - :/icons/instances/infinity:/icons/instances/infinity - - - Change Icon - - - Change the selected instance's icon. - - - Change the selected instance's icon. - - - true - - - - - Edit Notes - - - Edit the notes for the selected instance. - - - Edit the notes for the selected instance. - - - - - true - - - Settings - - - Change settings for the selected instance. - - - Change settings for the selected instance. - - - - - false - - - Make Shortcut - - - Make a shortcut on the desktop for the selected instance. - - - Make a shortcut on the desktop for the selected instance. - - - - - false - - - Manage Saves - - - Manage saves for the selected instance. - - - Manage saves for the selected instance. - - - - - Edit Mods - - - Edit the mods for the selected instance. - - - Edit the mods for the selected instance. - - - - - Change Version - - - Change the selected instance's Minecraft version. - - - Change the selected instance's Minecraft version. - - - - - false - - - Change LWJGL - - - Change the version of LWJGL for the selected instance to use. - - - Change the version of LWJGL for the selected instance to use. - - - - - Instance Folder - - - Open the selected instance's root folder in a file browser. - - - Open the selected instance's root folder in a file browser. - - - - - Delete - - - Delete the selected instance. - - - Delete the selected instance. - - - - - Config Folder - - - Open the instance's config folder - - - - - true - - - - :/icons/toolbar/cat:/icons/toolbar/cat - - - Meow - - - <html><head/><body><p align="center"><span style=" font-weight:600; color:#ff0004;">Catnarok!</span></p><p align="center">Or just a cat with a ball of yarn?</p><p align="center"><span style=" font-style:italic;">WHO KNOWS?!</span></p><p align="center"><img src=":/icons/instances/tnt"/></p></body></html> - - - - - - :/icons/toolbar/copy:/icons/toolbar/copy - - - Copy Instance - - - Copy the selected instance. - - - Add a new instance. - - - - - - - - - diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp deleted file mode 100644 index c37db2ac..00000000 --- a/gui/newinstancedialog.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "newinstancedialog.h" -#include "ui_newinstancedialog.h" - -#include "logic/InstanceFactory.h" -#include "logic/BaseVersion.h" -#include "logic/lists/IconList.h" -#include "logic/lists/MinecraftVersionList.h" -#include "logic/tasks/Task.h" - -#include "gui/platform.h" -#include "versionselectdialog.h" -#include "ProgressDialog.h" -#include "IconPickerDialog.h" - -#include -#include - -NewInstanceDialog::NewInstanceDialog(QWidget *parent) - : QDialog(parent), ui(new Ui::NewInstanceDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - resize(minimumSizeHint()); - layout()->setSizeConstraint(QLayout::SetFixedSize); - /* - if (!MinecraftVersionList::getMainList().isLoaded()) - { - TaskDialog *taskDlg = new TaskDialog(this); - Task *loadTask = MinecraftVersionList::getMainList().getLoadTask(); - loadTask->setParent(taskDlg); - taskDlg->exec(loadTask); - } - */ - setSelectedVersion(MMC->minecraftlist()->getLatestStable()); - InstIconKey = "infinity"; - ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); -} - -NewInstanceDialog::~NewInstanceDialog() -{ - delete ui; -} - -void NewInstanceDialog::updateDialogState() -{ - ui->buttonBox->button(QDialogButtonBox::Ok) - ->setEnabled(!instName().isEmpty() && m_selectedVersion); -} - -void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version) -{ - m_selectedVersion = version; - - if (m_selectedVersion) - { - ui->versionTextBox->setText(version->name()); - } - else - { - ui->versionTextBox->setText(""); - } - - updateDialogState(); -} - -QString NewInstanceDialog::instName() const -{ - return ui->instNameTextBox->text(); -} - -QString NewInstanceDialog::iconKey() const -{ - return InstIconKey; -} - -BaseVersionPtr NewInstanceDialog::selectedVersion() const -{ - return m_selectedVersion; -} - -void NewInstanceDialog::on_btnChangeVersion_clicked() -{ - VersionSelectDialog vselect(MMC->minecraftlist().get(), tr("Change Minecraft version"), - this); - vselect.exec(); - if (vselect.result() == QDialog::Accepted) - { - BaseVersionPtr version = vselect.selectedVersion(); - if (version) - setSelectedVersion(version); - } -} - -void NewInstanceDialog::on_iconButton_clicked() -{ - IconPickerDialog dlg(this); - dlg.exec(InstIconKey); - - if (dlg.result() == QDialog::Accepted) - { - InstIconKey = dlg.selectedIconKey; - ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); - } -} - -void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) -{ - updateDialogState(); -} diff --git a/gui/newinstancedialog.h b/gui/newinstancedialog.h deleted file mode 100644 index 4357c28d..00000000 --- a/gui/newinstancedialog.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "logic/BaseVersion.h" - -namespace Ui -{ -class NewInstanceDialog; -} - -class NewInstanceDialog : public QDialog -{ - Q_OBJECT - -public: - explicit NewInstanceDialog(QWidget *parent = 0); - ~NewInstanceDialog(); - - void updateDialogState(); - - void setSelectedVersion(BaseVersionPtr version); - - void loadVersionList(); - - QString instName() const; - QString iconKey() const; - BaseVersionPtr selectedVersion() const; - -private -slots: - void on_btnChangeVersion_clicked(); - void on_iconButton_clicked(); - void on_instNameTextBox_textChanged(const QString &arg1); - -private: - Ui::NewInstanceDialog *ui; - - BaseVersionPtr m_selectedVersion; - QString InstIconKey; -}; diff --git a/gui/newinstancedialog.ui b/gui/newinstancedialog.ui deleted file mode 100644 index 540176d5..00000000 --- a/gui/newinstancedialog.ui +++ /dev/null @@ -1,179 +0,0 @@ - - - NewInstanceDialog - - - Qt::ApplicationModal - - - - 0 - 0 - 220 - 234 - - - - New Instance - - - - :/icons/toolbar/new:/icons/toolbar/new - - - true - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - :/icons/instances/infinity:/icons/instances/infinity - - - - 80 - 80 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Name - - - - - - - Qt::Horizontal - - - - - - - - - Version: - - - - - - - true - - - - - - - ... - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - buttonBox - accepted() - NewInstanceDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - NewInstanceDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/gui/newmodeditwindow.ui b/gui/newmodeditwindow.ui deleted file mode 100644 index a7587d11..00000000 --- a/gui/newmodeditwindow.ui +++ /dev/null @@ -1,159 +0,0 @@ - - - Dialog - - - - 0 - 0 - 569 - 420 - - - - Dialog - - - - - - true - - - - 0 - 0 - - - - 2 - - - Qt::ElideNone - - - false - - - - Library - - - - - - - - - - Mods - - - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - Resource Pack - - - - - - - - - - - PushButton - - - - - - - PushButton - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - PushButton - - - - - - - - - - - - - false - - - QDialogButtonBox::Close - - - - - - - - diff --git a/gui/platform.h b/gui/platform.h deleted file mode 100644 index 5cf9ed80..00000000 --- a/gui/platform.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Orochimarufan - * - * 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. - */ - -#ifndef PLATFORM_H -#define PLATFORM_H - -/** - * @file platform.h - * This file contains platform-specific functions, tweaks and fixes. - */ - -#include - -class MultiMCPlatform -{ -public: - // X11 WM_CLASS - static void fixWM_CLASS(QWidget *widget); -}; - -#endif // PLATFORM_H diff --git a/gui/platform_other.cpp b/gui/platform_other.cpp deleted file mode 100644 index a41abe36..00000000 --- a/gui/platform_other.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Orochimarufan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -/** - * Stub for non-X11 platforms - * @brief MultiMCPlatform::fixWM_CLASS - * @param widget - */ -void MultiMCPlatform::fixWM_CLASS(QWidget *widget) -{ - Q_UNUSED(widget); -} diff --git a/gui/platform_x11.cpp b/gui/platform_x11.cpp deleted file mode 100644 index 0401e8bf..00000000 --- a/gui/platform_x11.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Orochimarufan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -static QByteArray WM_CLASS = "MultiMC5\0MultiMC5"; - -template -static inline unsigned int XcbCallVoid(xcb_void_cookie_t (*func)(xcb_connection_t *, ArgTypes...), ArgTypes2... args...) -{ - return func(QX11Info::connection(), args...).sequence; -} - -static void getAtoms(size_t n, xcb_atom_t *atoms, const char *const names[], bool create) -{ - xcb_connection_t *conn = QX11Info::connection(); - xcb_intern_atom_cookie_t *cookies = (xcb_intern_atom_cookie_t *)malloc(sizeof(xcb_intern_atom_cookie_t) * 2); - for (size_t i = 0; i < n; ++i) - cookies[i] = xcb_intern_atom(conn, create, strlen(names[i]), names[i]); - memset(atoms, 0, sizeof(xcb_atom_t) * n); - for (size_t i = 0; i < n; ++i) - { - xcb_intern_atom_reply_t *r = xcb_intern_atom_reply(conn, cookies[i], 0); - if (r) - { - atoms[i] = r->atom; - free(r); - } - } - free(cookies); -} - -static inline xcb_atom_t getAtom(const char *name, bool create=false) -{ - xcb_atom_t atom; - getAtoms(1, &atom, &name, create); - return atom; -} - -void MultiMCPlatform::fixWM_CLASS(QWidget *widget) -{ - static const xcb_atom_t atom = getAtom("WM_CLASS"); - XcbCallVoid(xcb_change_property, XCB_PROP_MODE_REPLACE, - widget->winId(), atom, XCB_ATOM_STRING, 8, WM_CLASS.count(), - WM_CLASS.constData()); -} diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp deleted file mode 100644 index bf331fc0..00000000 --- a/gui/settingsdialog.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "settingsdialog.h" -#include "ui_settingsdialog.h" -#include "logic/JavaUtils.h" -#include "logic/NagUtils.h" -#include "gui/versionselectdialog.h" -#include "gui/platform.h" -#include "gui/CustomMessageBox.h" -#include "logic/lists/JavaVersionList.h" - -#include -#include -#include -#include -#include - -SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name); - ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch); - - loadSettings(MMC->settings().get()); - updateCheckboxStuff(); -} - -SettingsDialog::~SettingsDialog() -{ - delete ui; -} -void SettingsDialog::showEvent(QShowEvent *ev) -{ - QDialog::showEvent(ev); - adjustSize(); -} - -void SettingsDialog::updateCheckboxStuff() -{ - ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); - ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); -} - -void SettingsDialog::on_instDirBrowseBtn_clicked() -{ - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"), - ui->instDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); - - // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) - { - ui->instDirTextBox->setText(cooked_dir); - } -} - -void SettingsDialog::on_modsDirBrowseBtn_clicked() -{ - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"), - ui->modsDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); - - // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) - { - ui->modsDirTextBox->setText(cooked_dir); - } -} - -void SettingsDialog::on_lwjglDirBrowseBtn_clicked() -{ - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"), - ui->lwjglDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); - - // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) - { - ui->lwjglDirTextBox->setText(cooked_dir); - } -} - -void SettingsDialog::on_compatModeCheckBox_clicked(bool checked) -{ - Q_UNUSED(checked); - updateCheckboxStuff(); -} - -void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) -{ - Q_UNUSED(checked); - updateCheckboxStuff(); -} - -void SettingsDialog::on_buttonBox_accepted() -{ - applySettings(MMC->settings().get()); -} - -void SettingsDialog::applySettings(SettingsObject *s) -{ - // Special cases - - // Warn about dev builds. - if (!ui->devBuildsCheckBox->isChecked()) - { - s->set("UseDevBuilds", false); - } - else if (!s->get("UseDevBuilds").toBool()) - { - auto response = CustomMessageBox::selectable(this, tr("Development builds"), - tr("Development builds contain experimental features " - "and may be unstable. Are you sure you want to enable them?"), - QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); - if (response == QMessageBox::Yes) - { - s->set("UseDevBuilds", true); - } - } - - // Updates - s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked()); - - // Folders - // TODO: Offer to move instances to new instance folder. - s->set("InstanceDir", ui->instDirTextBox->text()); - s->set("CentralModsDir", ui->modsDirTextBox->text()); - s->set("LWJGLDir", ui->lwjglDirTextBox->text()); - - // Console - s->set("ShowConsole", ui->showConsoleCheck->isChecked()); - s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); - - // Window Size - s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); - s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); - s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); - - // Auto Login - s->set("AutoLogin", ui->autoLoginCheckBox->isChecked()); - - // Memory - s->set("MinMemAlloc", ui->minMemSpinBox->value()); - s->set("MaxMemAlloc", ui->maxMemSpinBox->value()); - s->set("PermGen", ui->permGenSpinBox->value()); - - // Java Settings - s->set("JavaPath", ui->javaPathTextBox->text()); - s->set("JvmArgs", ui->jvmArgsTextBox->text()); - NagUtils::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget()); - - // Custom Commands - s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); - s->set("PostExitCommand", ui->postExitCmdTextBox->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; - } - - s->set("PostExitCommand", ui->postExitCmdTextBox->text()); -} - -void SettingsDialog::loadSettings(SettingsObject *s) -{ - // Updates - ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool()); - ui->devBuildsCheckBox->setChecked(s->get("UseDevBuilds").toBool()); - - // Folders - ui->instDirTextBox->setText(s->get("InstanceDir").toString()); - ui->modsDirTextBox->setText(s->get("CentralModsDir").toString()); - ui->lwjglDirTextBox->setText(s->get("LWJGLDir").toString()); - - // Console - ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool()); - ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool()); - - // Window Size - ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool()); - ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt()); - ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt()); - - // Auto Login - ui->autoLoginCheckBox->setChecked(s->get("AutoLogin").toBool()); - - // Memory - ui->minMemSpinBox->setValue(s->get("MinMemAlloc").toInt()); - ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt()); - ui->permGenSpinBox->setValue(s->get("PermGen").toInt()); - - QString sortMode = s->get("InstSortMode").toString(); - - if(sortMode == "LastLaunch") - { - ui->sortLastLaunchedBtn->setChecked(true); - } - else - { - ui->sortByNameBtn->setChecked(true); - } - - // Java Settings - ui->javaPathTextBox->setText(s->get("JavaPath").toString()); - ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); - - // Custom Commands - ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); - ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); -} - -void SettingsDialog::on_pushButton_clicked() -{ - JavaVersionPtr java; - - VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true); - vselect.setResizeOn(2); - vselect.exec(); - - if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) - { - java = std::dynamic_pointer_cast(vselect.selectedVersion()); - ui->javaPathTextBox->setText(java->path); - } -} - -void SettingsDialog::on_btnBrowse_clicked() -{ - QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - if (!dir.isNull()) - { - ui->javaPathTextBox->setText(dir); - } -} diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h deleted file mode 100644 index a8dfb1c6..00000000 --- a/gui/settingsdialog.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef SETTINGSDIALOG_H -#define SETTINGSDIALOG_H - -#include - -class SettingsObject; - -namespace Ui { -class SettingsDialog; -} - -class SettingsDialog : public QDialog -{ - Q_OBJECT - -public: - explicit SettingsDialog(QWidget *parent = 0); - ~SettingsDialog(); - - void updateCheckboxStuff(); - - void applySettings(SettingsObject *s); - void loadSettings(SettingsObject* s); - -protected: - virtual void showEvent ( QShowEvent* ); - -private slots: - void on_instDirBrowseBtn_clicked(); - - void on_modsDirBrowseBtn_clicked(); - - void on_lwjglDirBrowseBtn_clicked(); - - void on_compatModeCheckBox_clicked(bool checked); - - void on_maximizedCheckBox_clicked(bool checked); - - void on_buttonBox_accepted(); - - void on_pushButton_clicked(); - - void on_btnBrowse_clicked(); - -private: - Ui::SettingsDialog *ui; -}; - -#endif // SETTINGSDIALOG_H diff --git a/gui/settingsdialog.ui b/gui/settingsdialog.ui deleted file mode 100644 index bf173b1b..00000000 --- a/gui/settingsdialog.ui +++ /dev/null @@ -1,569 +0,0 @@ - - - SettingsDialog - - - - 0 - 0 - 502 - 599 - - - - - 0 - 0 - - - - Settings - - - - :/icons/toolbar/settings:/icons/toolbar/settings - - - true - - - - - - QTabWidget::Rounded - - - 0 - - - - General - - - - - - true - - - Sorting Mode - - - - - - By last launched - - - sortingModeGroup - - - - - - - By name - - - sortingModeGroup - - - - - - - - - - Update Settings - - - - - - Use development builds? - - - - - - - Check for updates when MultiMC starts? - - - - - - - - - - Folders - - - - - - Instances: - - - - - - - - - - ... - - - - - - - Mods: - - - - - - - - - - ... - - - - - - - LWJGL: - - - - - - - - - - ... - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - Minecraft - - - - - - Window Size - - - - - - Start Minecraft maximized? - - - - - - - - - Window height: - - - - - - - Window width: - - - - - - - 854 - - - 65536 - - - 1 - - - 854 - - - - - - - 480 - - - 65536 - - - 480 - - - - - - - - - - - - Console Settings - - - - - - Show console while the game is running? - - - - - - - Automatically close console when the game quits? - - - - - - - - - - Login automatically when an instance icon is double clicked? - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - Java - - - - - - Memory - - - - - - 512 - - - 65536 - - - 128 - - - 1024 - - - - - - - Minimum memory allocation: - - - - - - - Maximum memory allocation: - - - - - - - 256 - - - 65536 - - - 128 - - - 256 - - - - - - - PermGen: - - - - - - - 64 - - - 999999999 - - - 8 - - - 64 - - - - - - - - - - Java Settings - - - - - - - 0 - 0 - - - - Java path: - - - - - - - - 0 - 0 - - - - JVM arguments: - - - - - - - - 0 - 0 - - - - Browse... - - - - - - - - - - - 0 - 0 - - - - Auto-detect... - - - - - - - - - - - - - Custom Commands - - - - - - Post-exit command: - - - - - - - Pre-launch command: - - - - - - - - - - - - - - - - - 0 - 0 - - - - Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables. - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - settingsTabs - buttonBox - sortLastLaunchedBtn - sortByNameBtn - devBuildsCheckBox - autoUpdateCheckBox - instDirTextBox - modsDirTextBox - lwjglDirTextBox - instDirBrowseBtn - modsDirBrowseBtn - lwjglDirBrowseBtn - maximizedCheckBox - windowWidthSpinBox - windowHeightSpinBox - showConsoleCheck - autoCloseConsoleCheck - autoLoginCheckBox - minMemSpinBox - maxMemSpinBox - permGenSpinBox - javaPathTextBox - pushButton - btnBrowse - jvmArgsTextBox - preLaunchCmdTextBox - postExitCmdTextBox - - - - - - - buttonBox - accepted() - SettingsDialog - accept() - - - 257 - 410 - - - 157 - 274 - - - - - buttonBox - rejected() - SettingsDialog - reject() - - - 325 - 410 - - - 286 - 274 - - - - - - - - diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp deleted file mode 100644 index 8fa62f75..00000000 --- a/gui/versionselectdialog.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "versionselectdialog.h" -#include "ui_versionselectdialog.h" - -#include - -#include - -#include -#include "gui/platform.h" - -#include -#include -#include - -VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, bool cancelable) - : QDialog(parent), ui(new Ui::VersionSelectDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - setWindowModality(Qt::WindowModal); - setWindowTitle(title); - - m_vlist = vlist; - - m_proxyModel = new QSortFilterProxyModel(this); - m_proxyModel->setSourceModel(vlist); - - ui->listView->setModel(m_proxyModel); - ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); - - if(!cancelable) - { - ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); - } -} - -VersionSelectDialog::~VersionSelectDialog() -{ - delete ui; -} - -void VersionSelectDialog::setResizeOn(int column) -{ - ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents); - resizeOnColumn = column; - ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); -} - -int VersionSelectDialog::exec() -{ - QDialog::open(); - if (!m_vlist->isLoaded()) - loadList(); - return QDialog::exec(); -} - -void VersionSelectDialog::loadList() -{ - ProgressDialog *taskDlg = new ProgressDialog(this); - Task *loadTask = m_vlist->getLoadTask(); - loadTask->setParent(taskDlg); - taskDlg->exec(loadTask); -} - -BaseVersionPtr VersionSelectDialog::selectedVersion() const -{ - auto currentIndex = ui->listView->selectionModel()->currentIndex(); - auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole); - return variant.value(); -} - -void VersionSelectDialog::on_refreshButton_clicked() -{ - loadList(); -} - -void VersionSelectDialog::setFilter(int column, QString filter) -{ - m_proxyModel->setFilterKeyColumn(column); - m_proxyModel->setFilterFixedString(filter); - /* - QStringList filteredTypes; - if (!ui->filterSnapshotsCheckbox->isChecked()) - filteredTypes += "Snapshot"; - if (!ui->filterMCNostalgiaCheckbox->isChecked()) - filteredTypes += "Nostalgia"; - - QString regexStr = "^.*$"; - if (filteredTypes.length() > 0) - regexStr = QString("^((?!%1).)*$").arg(filteredTypes.join('|')); - - QLOG_DEBUG() << "Filter:" << regexStr; - */ -} diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h deleted file mode 100644 index 319caeca..00000000 --- a/gui/versionselectdialog.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2013 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. - */ - -#ifndef VERSIONSELECTDIALOG_H -#define VERSIONSELECTDIALOG_H - -#include - -#include -#include "logic/BaseVersion.h" - -class BaseVersionList; - -namespace Ui -{ -class VersionSelectDialog; -} - -class VersionSelectDialog : public QDialog -{ - Q_OBJECT - -public: - explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0, bool cancelable = true); - ~VersionSelectDialog(); - - virtual int exec(); - - //! Starts a task that loads the list. - void loadList(); - - BaseVersionPtr selectedVersion() const; - - void setFilter(int column, QString filter); - void setResizeOn(int column); - -private slots: - void on_refreshButton_clicked(); -private: - Ui::VersionSelectDialog *ui; - - BaseVersionList *m_vlist; - - QSortFilterProxyModel *m_proxyModel; - - int resizeOnColumn = 0; -}; - -#endif // VERSIONSELECTDIALOG_H diff --git a/gui/versionselectdialog.ui b/gui/versionselectdialog.ui deleted file mode 100644 index 222f29cf..00000000 --- a/gui/versionselectdialog.ui +++ /dev/null @@ -1,103 +0,0 @@ - - - VersionSelectDialog - - - - 0 - 0 - 400 - 347 - - - - Dialog - - - - - - Qt::ScrollBarAlwaysOff - - - true - - - false - - - false - - - true - - - true - - - false - - - - - - - - - Reloads the version list. - - - &Refresh - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - buttonBox - accepted() - VersionSelectDialog - accept() - - - 257 - 290 - - - 157 - 274 - - - - - buttonBox - rejected() - VersionSelectDialog - reject() - - - 325 - 290 - - - 286 - 274 - - - - - diff --git a/gui/widgets/InstanceDelegate.cpp b/gui/widgets/InstanceDelegate.cpp new file mode 100644 index 00000000..487fed61 --- /dev/null +++ b/gui/widgets/InstanceDelegate.cpp @@ -0,0 +1,246 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "InstanceDelegate.h" +#include +#include +#include +#include +#include + +// Origin: Qt +static void viewItemTextLayout ( QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed ) +{ + height = 0; + widthUsed = 0; + textLayout.beginLayout(); + QString str = textLayout.text(); + while ( true ) + { + QTextLine line = textLayout.createLine(); + if ( !line.isValid() ) + break; + if(line.textLength() == 0) + break; + line.setLineWidth ( lineWidth ); + line.setPosition ( QPointF ( 0, height ) ); + height += line.height(); + widthUsed = qMax ( widthUsed, line.naturalTextWidth() ); + } + textLayout.endLayout(); +} + +#define QFIXED_MAX (INT_MAX/256) + +ListViewDelegate::ListViewDelegate ( QObject* parent ) : QStyledItemDelegate ( parent ) +{ + +} + +void drawSelectionRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) +{ + if ((option.state & QStyle::State_Selected)) + painter->fillRect ( rect, option.palette.brush ( QPalette::Highlight ) ); + else + { + QColor backgroundColor = option.palette.color(QPalette::Background); + backgroundColor.setAlpha(160); + painter->fillRect ( rect, QBrush(backgroundColor) ); + } + +} + +void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) +{ + if (!(option.state & QStyle::State_HasFocus)) + return; + QStyleOptionFocusRect opt; + opt.direction = option.direction; + opt.fontMetrics = option.fontMetrics; + opt.palette = option.palette; + opt.rect = rect; + //opt.state = option.state | QStyle::State_KeyboardFocusChange | QStyle::State_Item; + auto col = option.state & QStyle::State_Selected ? QPalette::Highlight : QPalette::Base; + opt.backgroundColor = option.palette.color(col); + // Apparently some widget styles expect this hint to not be set + painter->setRenderHint(QPainter::Antialiasing, false); + + QStyle *style = option.widget ? option.widget->style() : QApplication::style(); + + style->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, painter, option.widget); + + painter->setRenderHint(QPainter::Antialiasing); +} + +static QSize viewItemTextSize ( const QStyleOptionViewItemV4 *option ) +{ + QStyle *style = option->widget ? option->widget->style() : QApplication::style(); + QTextOption textOption; + textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); + QTextLayout textLayout; + textLayout.setTextOption ( textOption ); + textLayout.setFont ( option->font ); + textLayout.setText ( option->text ); + const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, option, option->widget ) + 1; + QRect bounds ( 0,0,100 - 2*textMargin,600 ); + qreal height = 0, widthUsed = 0; + viewItemTextLayout ( textLayout, bounds.width(), height, widthUsed ); + const QSize size ( qCeil ( widthUsed ), qCeil ( height ) ); + return QSize ( size.width() + 2 * textMargin, size.height() ); +} + +void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + QStyleOptionViewItemV4 opt = option; + initStyleOption ( &opt, index ); + painter->save(); + painter->setClipRect ( opt.rect ); + + opt.features |= QStyleOptionViewItem::WrapText; + opt.text = index.data().toString(); + opt.textElideMode = Qt::ElideRight; + opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; + + QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); + + //const int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize); + const int iconSize = 48; + QRect iconbox = opt.rect; + const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, 0, opt.widget ) + 1; + QRect textRect = opt.rect; + QRect textHighlightRect = textRect; + // clip the decoration on top, remove width padding + textRect.adjust ( textMargin,iconSize + textMargin + 5,-textMargin,0 ); + + textHighlightRect.adjust ( 0,iconSize + 5,0,0 ); + + // draw background + { + QSize textSize = viewItemTextSize ( &opt ); + QPalette::ColorGroup cg; + QStyleOptionViewItemV4 opt2(opt); + + if((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled)) + { + if(! ( opt.state & QStyle::State_Active )) + cg = QPalette::Inactive; + else + cg = QPalette::Normal; + } + else + { + cg = QPalette::Disabled; + } + opt2.palette.setCurrentColorGroup(cg); + + // fill in background, if any + if ( opt.backgroundBrush.style() != Qt::NoBrush ) + { + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin ( opt.rect.topLeft() ); + painter->fillRect ( opt.rect, opt.backgroundBrush ); + painter->setBrushOrigin ( oldBO ); + } + + if ( opt.showDecorationSelected ) + { + drawSelectionRect(painter,opt2, opt.rect); + drawFocusRect(painter,opt2, opt.rect); + //painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) ); + } + else + { + + //if ( opt.state & QStyle::State_Selected ) + { + //QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText, opt, opt.widget ); + //painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, QPalette::Highlight ) ); + drawSelectionRect(painter,opt2, textHighlightRect); + drawFocusRect(painter,opt2, textHighlightRect); + } + } + } + + // draw the icon + { + QIcon::Mode mode = QIcon::Normal; + if ( ! ( opt.state & QStyle::State_Enabled ) ) + mode = QIcon::Disabled; + else if ( opt.state & QStyle::State_Selected ) + mode = QIcon::Selected; + QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; + + iconbox.setHeight ( iconSize ); + opt.icon.paint ( painter, iconbox, Qt::AlignCenter, mode, state ); + } + // set the text colors + QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; + if ( cg == QPalette::Normal && ! ( opt.state & QStyle::State_Active ) ) + cg = QPalette::Inactive; + if ( opt.state & QStyle::State_Selected ) + { + painter->setPen ( opt.palette.color ( cg, QPalette::HighlightedText ) ); + } + else + { + painter->setPen ( opt.palette.color ( cg, QPalette::Text ) ); + } + + // draw the text + QTextOption textOption; + textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); + textOption.setTextDirection ( opt.direction ); + textOption.setAlignment ( QStyle::visualAlignment ( opt.direction, opt.displayAlignment ) ); + QTextLayout textLayout; + textLayout.setTextOption ( textOption ); + textLayout.setFont ( opt.font ); + textLayout.setText ( opt.text ); + + qreal width, height; + viewItemTextLayout ( textLayout, textRect.width(), height, width ); + + const int lineCount = textLayout.lineCount(); + + const QRect layoutRect = QStyle::alignedRect ( opt.direction, opt.displayAlignment, QSize ( textRect.width(), int ( height ) ), textRect ); + const QPointF position = layoutRect.topLeft(); + for ( int i = 0; i < lineCount; ++i ) + { + const QTextLine line = textLayout.lineAt ( i ); + line.draw ( painter, position ); + } + + painter->restore(); +} + + +QSize ListViewDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const +{ + QStyleOptionViewItemV4 opt = option; + initStyleOption ( &opt, index ); + opt.features |= QStyleOptionViewItem::WrapText; + opt.text = index.data().toString(); + opt.textElideMode = Qt::ElideRight; + opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; + + QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); + const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, &option, opt.widget ) + 1; + int height = 48 + textMargin * 2 + 5; // TODO: turn constants into variables + QSize szz = viewItemTextSize ( &opt ); + height += szz.height(); + // FIXME: maybe the icon items could scale and keep proportions? + QSize sz ( 100,height ); + return sz; +} + diff --git a/gui/widgets/InstanceDelegate.h b/gui/widgets/InstanceDelegate.h new file mode 100644 index 00000000..6f924405 --- /dev/null +++ b/gui/widgets/InstanceDelegate.h @@ -0,0 +1,27 @@ +/* Copyright 2013 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 + +class ListViewDelegate : public QStyledItemDelegate +{ +public: + explicit ListViewDelegate ( QObject* parent = 0 ); +protected: + void paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; + QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; +}; diff --git a/gui/widgets/LabeledToolButton.cpp b/gui/widgets/LabeledToolButton.cpp new file mode 100644 index 00000000..fe3cac45 --- /dev/null +++ b/gui/widgets/LabeledToolButton.cpp @@ -0,0 +1,86 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "LabeledToolButton.h" +#include + +/* + * + * Tool Button with a label on it, instead of the normal text rendering + * + */ + +LabeledToolButton::LabeledToolButton(QWidget * parent) + : QToolButton(parent) + , m_label(new QLabel(this)) +{ + //QToolButton::setText(" "); + m_label->setWordWrap(true); + m_label->setMouseTracking(false); + m_label->setAlignment(Qt::AlignCenter); + m_label->setTextInteractionFlags(Qt::NoTextInteraction); + // somehow, this makes word wrap work in the QLabel. yay. + m_label->setMinimumWidth(100); +} + +QString LabeledToolButton::text() const +{ + return m_label->text(); +} + +void LabeledToolButton::setText(const QString & text) +{ + m_label->setText(text); +} + +/*! + \reimp +*/ +QSize LabeledToolButton::sizeHint() const +{ + /* + Q_D(const QToolButton); + if (d->sizeHint.isValid()) + return d->sizeHint; + */ + ensurePolished(); + + int w = 0, h = 0; + QStyleOptionToolButton opt; + initStyleOption(&opt); + QSize sz =m_label->sizeHint(); + w = sz.width(); + h = sz.height(); + + opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height + if (popupMode() == MenuButtonPopup) + w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); + + QSize rawSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this); + QSize sizeHint = rawSize.expandedTo(QApplication::globalStrut()); + return sizeHint; +} + + + +void LabeledToolButton::resizeEvent(QResizeEvent * event) +{ + m_label->setGeometry(QRect(4, 4, width()-8, height()-8)); + QWidget::resizeEvent(event); +} diff --git a/gui/widgets/LabeledToolButton.h b/gui/widgets/LabeledToolButton.h new file mode 100644 index 00000000..b417f814 --- /dev/null +++ b/gui/widgets/LabeledToolButton.h @@ -0,0 +1,37 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +class QLabel; + +class LabeledToolButton : public QToolButton +{ + Q_OBJECT + + QLabel * m_label; + +public: + LabeledToolButton(QWidget * parent = 0); + + QString text() const; + void setText(const QString & text); + virtual QSize sizeHint() const; +protected: + void resizeEvent(QResizeEvent * event); +}; diff --git a/gui/widgets/MCModInfoFrame.cpp b/gui/widgets/MCModInfoFrame.cpp new file mode 100644 index 00000000..ad167bc9 --- /dev/null +++ b/gui/widgets/MCModInfoFrame.cpp @@ -0,0 +1,111 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "MCModInfoFrame.h" +#include "ui_MCModInfoFrame.h" +#include "gui/dialogs/CustomMessageBox.h" + +void MCModInfoFrame::updateWithMod(Mod &m) +{ + if(m.type() == m.MOD_FOLDER) + { + clear(); + return; + } + + QString text = ""; + QString name = ""; + if(m.name().isEmpty()) name = m.id(); + else name = m.name(); + + if(m.homeurl().isEmpty()) text = name; + else text = "" + name + ""; + if(!m.authors().isEmpty()) text += " by " + m.authors(); + + setModText(text); + + if(m.description().isEmpty()) + { + setModDescription(tr("No description provided in mcmod.info")); + } + else + { + setModDescription(m.description()); + } +} + +void MCModInfoFrame::clear() +{ + setModText(tr("Select a mod to view title and authors...")); + setModDescription(tr("Select a mod to view description...")); +} + +MCModInfoFrame::MCModInfoFrame(QWidget *parent) : + QFrame(parent), + ui(new Ui::MCModInfoFrame) +{ + ui->setupUi(this); +} + +MCModInfoFrame::~MCModInfoFrame() +{ + delete ui; +} + +void MCModInfoFrame::setModText(QString text) +{ + ui->label_ModText->setText(text); +} + +void MCModInfoFrame::setModDescription(QString text) +{ + ui->label_ModDescription->setToolTip(""); + QString intermediatetext = text.trimmed(); + bool prev(false); + QChar rem('\n'); + QString finaltext; + finaltext.reserve(intermediatetext.size()); + foreach(const QChar& c, intermediatetext) + { + if(c == rem && prev){ + continue; + } + prev = c == rem; + finaltext += c; + } + QString labeltext; + labeltext.reserve(300); + if(finaltext.length() > 290) + { + ui->label_ModDescription->setOpenExternalLinks(false); + ui->label_ModDescription->setTextFormat(Qt::TextFormat::RichText); + desc = text; + labeltext.append("" + finaltext.left(287) + "..."); + QObject::connect(ui->label_ModDescription, &QLabel::linkActivated, this, &MCModInfoFrame::modDescEllipsisHandler); + } + else + { + ui->label_ModDescription->setTextFormat(Qt::TextFormat::PlainText); + labeltext.append(finaltext); + } + ui->label_ModDescription->setText(labeltext); +} +void MCModInfoFrame::modDescEllipsisHandler(const QString &link) +{ + CustomMessageBox::selectable(this, tr(""), desc)->show(); +} diff --git a/gui/widgets/MCModInfoFrame.h b/gui/widgets/MCModInfoFrame.h new file mode 100644 index 00000000..54c5d674 --- /dev/null +++ b/gui/widgets/MCModInfoFrame.h @@ -0,0 +1,46 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "logic/Mod.h" + +namespace Ui +{ +class MCModInfoFrame; +} + +class MCModInfoFrame : public QFrame +{ + Q_OBJECT + +public: + explicit MCModInfoFrame(QWidget *parent = 0); + ~MCModInfoFrame(); + + void setModText(QString text); + void setModDescription(QString text); + + void updateWithMod(Mod &m); + void clear(); + +public slots: + void modDescEllipsisHandler(const QString& link ); + +private: + Ui::MCModInfoFrame *ui; + QString desc; +}; diff --git a/gui/widgets/MCModInfoFrame.ui b/gui/widgets/MCModInfoFrame.ui new file mode 100644 index 00000000..60e0a65c --- /dev/null +++ b/gui/widgets/MCModInfoFrame.ui @@ -0,0 +1,68 @@ + + + MCModInfoFrame + + + + 0 + 0 + 527 + 113 + + + + + 0 + 0 + + + + + 16777215 + 120 + + + + Frame + + + + + + Select a mod to view title and authors... + + + Qt::RichText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + true + + + + + + + Select a mod to view description... + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + diff --git a/gui/widgets/ModListView.cpp b/gui/widgets/ModListView.cpp new file mode 100644 index 00000000..838af75e --- /dev/null +++ b/gui/widgets/ModListView.cpp @@ -0,0 +1,51 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ModListView.h" +#include +#include +#include +#include +#include + +ModListView::ModListView ( QWidget* parent ) + :QTreeView ( parent ) +{ + setAllColumnsShowFocus ( true ); + setExpandsOnDoubleClick ( false ); + setRootIsDecorated ( false ); + setSortingEnabled ( false ); + setAlternatingRowColors ( true ); + setSelectionMode ( QAbstractItemView::ContiguousSelection ); + setHeaderHidden ( false ); + setSelectionBehavior(QAbstractItemView::SelectRows); + setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn ); + setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded ); + setDropIndicatorShown(true); + setDragEnabled(true); + setDragDropMode(QAbstractItemView::DropOnly); + viewport()->setAcceptDrops(true); +} + +void ModListView::setModel ( QAbstractItemModel* model ) +{ + QTreeView::setModel ( model ); + auto head = header(); + head->setStretchLastSection(false); + head->setSectionResizeMode(0, QHeaderView::Stretch); + for(int i = 1; i < head->count(); i++) + head->setSectionResizeMode(i, QHeaderView::ResizeToContents); + dropIndicatorPosition(); +} diff --git a/gui/widgets/ModListView.h b/gui/widgets/ModListView.h new file mode 100644 index 00000000..b26fa26b --- /dev/null +++ b/gui/widgets/ModListView.h @@ -0,0 +1,27 @@ +/* Copyright 2013 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 + +class Mod; + +class ModListView: public QTreeView +{ + Q_OBJECT +public: + explicit ModListView ( QWidget* parent = 0 ); + virtual void setModel ( QAbstractItemModel* model ); +}; -- cgit