From a25bedd7706b14cdae91556e4a577e410745f29a Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 28 Jan 2013 15:35:09 -0600 Subject: Implemented settings dialog. --- gui/settingsdialog.cpp | 112 +++++++++++++++++++++++++++++++++++++++++++++++-- gui/settingsdialog.h | 7 ++++ gui/settingsdialog.ui | 107 +++++++++++----------------------------------- 3 files changed, 139 insertions(+), 87 deletions(-) (limited to 'gui') diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 46569340..ab4d18ee 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -16,13 +16,19 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" +#include "data/appsettings.h" + #include +#include SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) { ui->setupUi(this); + + loadSettings(settings); + updateCheckboxStuff(); } SettingsDialog::~SettingsDialog() @@ -32,10 +38,10 @@ SettingsDialog::~SettingsDialog() void SettingsDialog::updateCheckboxStuff() { - ui->minMemSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || - ui->maximizedCheckBox->isChecked())); - ui->maxMemSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || - ui->maximizedCheckBox->isChecked())); + ui->windowWidthSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || + ui->maximizedCheckBox->isChecked())); + ui->windowHeightSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || + ui->maximizedCheckBox->isChecked())); ui->maximizedCheckBox->setEnabled(!ui->compatModeCheckBox->isChecked()); } @@ -75,3 +81,101 @@ void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) Q_UNUSED(checked); updateCheckboxStuff(); } + +void SettingsDialog::on_buttonBox_accepted() +{ + applySettings(settings); +} + +void SettingsDialog::applySettings(SettingsBase *s) +{ + // Special cases + + // Warn about dev builds. + if (!ui->devBuildsCheckBox->isChecked()) + { + s->setUseDevBuilds(false); + } + else if (!s->getUseDevBuilds()) + { + int response = QMessageBox::question(this, "Development builds", + "Development builds contain experimental features " + "and may be unstable. Are you sure you want to enable them?"); + if (response == QMessageBox::Yes) + { + s->setUseDevBuilds(true); + } + } + + + // Updates + s->setAutoUpdate(ui->autoUpdateCheckBox->isChecked()); + + // Folders + // TODO: Offer to move instances to new instance folder. + s->setInstanceDir(ui->instDirTextBox->text()); + s->setCentralModsDir(ui->modsDirTextBox->text()); + s->setLWJGLDir(ui->lwjglDirTextBox->text()); + + // Console + s->setShowConsole(ui->showConsoleCheck->isChecked()); + s->setAutoCloseConsole(ui->autoCloseConsoleCheck->isChecked()); + + // Window Size + s->setLaunchCompatMode(ui->compatModeCheckBox->isChecked()); + s->setLaunchMaximized(ui->maximizedCheckBox->isChecked()); + s->setMinecraftWinWidth(ui->windowWidthSpinBox->value()); + s->setMinecraftWinHeight(ui->windowHeightSpinBox->value()); + + // Auto Login + s->setAutoLogin(ui->autoLoginCheckBox->isChecked()); + + // Memory + s->setMinMemAlloc(ui->minMemSpinBox->value()); + s->setMaxMemAlloc(ui->maxMemSpinBox->value()); + + // Java Settings + s->setJavaPath(ui->javaPathTextBox->text()); + s->setJvmArgs(ui->jvmArgsTextBox->text()); + + // Custom Commands + s->setPreLaunchCommand(ui->preLaunchCmdTextBox->text()); + s->setPostExitCommand(ui->postExitCmdTextBox->text()); +} + +void SettingsDialog::loadSettings(SettingsBase *s) +{ + // Updates + ui->autoUpdateCheckBox->setChecked(s->getAutoUpdate()); + ui->devBuildsCheckBox->setChecked(s->getUseDevBuilds()); + + // Folders + ui->instDirTextBox->setText(s->getInstanceDir()); + ui->modsDirTextBox->setText(s->getCentralModsDir()); + ui->lwjglDirTextBox->setText(s->getLWJGLDir()); + + // Console + ui->showConsoleCheck->setChecked(s->getShowConsole()); + ui->autoCloseConsoleCheck->setChecked(s->getAutoCloseConsole()); + + // Window Size + ui->compatModeCheckBox->setChecked(s->getLaunchCompatMode()); + ui->maximizedCheckBox->setChecked(s->getLaunchMaximized()); + ui->windowWidthSpinBox->setValue(s->getMinecraftWinWidth()); + ui->windowHeightSpinBox->setValue(s->getMinecraftWinHeight()); + + // Auto Login + ui->autoLoginCheckBox->setChecked(s->getAutoLogin()); + + // Memory + ui->minMemSpinBox->setValue(s->getMinMemAlloc()); + ui->maxMemSpinBox->setValue(s->getMaxMemAlloc()); + + // Java Settings + ui->javaPathTextBox->setText(s->getJavaPath()); + ui->jvmArgsTextBox->setText(s->getJvmArgs()); + + // Custom Commands + ui->preLaunchCmdTextBox->setText(s->getPreLaunchCommand()); + ui->postExitCmdTextBox->setText(s->getPostExitCommand()); +} diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 3e9d9e0f..e223237f 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -18,6 +18,8 @@ #include +class SettingsBase; + namespace Ui { class SettingsDialog; } @@ -32,6 +34,9 @@ public: void updateCheckboxStuff(); + void applySettings(SettingsBase* s); + void loadSettings(SettingsBase* s); + private slots: void on_instDirBrowseBtn_clicked(); @@ -43,6 +48,8 @@ private slots: void on_maximizedCheckBox_clicked(bool checked); + void on_buttonBox_accepted(); + private: Ui::SettingsDialog *ui; }; diff --git a/gui/settingsdialog.ui b/gui/settingsdialog.ui index 315686ca..d30f56bb 100644 --- a/gui/settingsdialog.ui +++ b/gui/settingsdialog.ui @@ -158,88 +158,6 @@ - - - Console - - - - - - Console Settings - - - - - - Show console while the game is running? - - - - - - - Automatically close console when the game quits? - - - - - - - - - - Instance Console Colors - - - - - - System message color: - - - - - - - - - - Output message color: - - - - - - - - - - Error message color: - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - Minecraft @@ -315,10 +233,33 @@ + + + + Console Settings + + + + + + Show console while the game is running? + + + + + + + Automatically close console when the game quits? + + + + + + - Login automatically when an instance launches? + Login automatically when an instance icon is double clicked? -- cgit v1.2.3 From 3a0367a79c53c59e670ee50927247885fe4807cb Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 28 Jan 2013 18:01:20 -0600 Subject: Resized main window and added version info. --- gui/mainwindow.cpp | 6 +++++- gui/mainwindow.ui | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 87a1dcc0..eedaddb8 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -19,13 +19,17 @@ #include #include -#include "../gui/settingsdialog.h" +#include "gui/settingsdialog.h" +#include "data/version.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + + setWindowTitle(QString("MultiMC %1").arg(Version::current.toString())); + instList.initialLoad("instances"); ui->instanceView->setModel(&instList); } diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index ccc7e777..6640657a 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 739 - 657 + 854 + 480 -- cgit v1.2.3 From 7ac25bf2dae0c4435732265d26924140893914ff Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 29 Jan 2013 00:26:24 -0600 Subject: Implemented the view folder buttons on the main window. --- gui/mainwindow.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index eedaddb8..e2a3abfb 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -19,7 +19,9 @@ #include #include +#include "util/osutils.h" #include "gui/settingsdialog.h" +#include "data/appsettings.h" #include "data/version.h" MainWindow::MainWindow(QWidget *parent) : @@ -46,7 +48,7 @@ void MainWindow::on_actionAddInstance_triggered() void MainWindow::on_actionViewInstanceFolder_triggered() { - + openInDefaultProgram(settings->getInstanceDir()); } void MainWindow::on_actionRefresh_triggered() @@ -56,7 +58,7 @@ void MainWindow::on_actionRefresh_triggered() void MainWindow::on_actionViewCentralModsFolder_triggered() { - + openInDefaultProgram(settings->getCentralModsDir()); } void MainWindow::on_actionCheckUpdate_triggered() -- cgit v1.2.3 From 90764f97d94a52517d735ed96d26bb52a2d75de1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 29 Jan 2013 23:52:37 -0600 Subject: Add instance toolbar. --- gui/mainwindow.cpp | 18 +++++++ gui/mainwindow.h | 4 ++ gui/mainwindow.ui | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 171 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e2a3abfb..e257f5ae 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -32,6 +32,9 @@ MainWindow::MainWindow(QWidget *parent) : setWindowTitle(QString("MultiMC %1").arg(Version::current.toString())); + restoreGeometry(settings->getConfig().value("MainWindowGeometry", saveGeometry()).toByteArray()); + restoreState(settings->getConfig().value("MainWindowState", saveState()).toByteArray()); + instList.initialLoad("instances"); ui->instanceView->setModel(&instList); } @@ -86,3 +89,18 @@ void MainWindow::on_actionAbout_triggered() { } + +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::closeEvent(QCloseEvent *event) +{ + // Save the window state and geometry. + settings->getConfig().setValue("MainWindowGeometry", saveGeometry()); + settings->getConfig().setValue("MainWindowState", saveState()); + QMainWindow::closeEvent(event); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 77245531..91efd497 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -33,6 +33,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + void closeEvent(QCloseEvent *event); + private slots: void on_actionAbout_triggered(); @@ -52,6 +54,8 @@ private slots: void on_actionNews_triggered(); + void on_mainToolBar_visibilityChanged(bool); + private: Ui::MainWindow *ui; diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 6640657a..3e832276 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 854 - 480 + 600 + 400 @@ -39,6 +39,9 @@ + + Main Toolbar + false @@ -64,6 +67,38 @@ + + + Instance Toolbar + + + false + + + RightToolBarArea + + + false + + + + + + + + + + + + + + + + + + + + @@ -178,6 +213,118 @@ QAction::AboutRole + + + Play + + + Launch the selected instance. + + + + + Rename + + + Rename the selected instance. + + + + + Change Group + + + Change the selected instance's group. + + + + + Change Icon + + + Change the selected instance's icon. + + + + + Edit Notes + + + Edit the notes for the selected instance. + + + + + Settings + + + Change settings for the selected instance. + + + + + Make Shortcut + + + Make a shortcut on the desktop for the selected instance. + + + + + Manage Saves + + + Manage saves for the selected instance. + + + + + Edit Mods + + + Edit the mods for the selected instance. + + + + + Change Version + + + Change the selected instance's Minecraft version. + + + + + Change LWJGL + + + Change the version of LWJGL for the selected instance to use. + + + + + Rebuild Jar + + + Re-installs the mods for the selected instance. + + + + + View Folder + + + Opens the selected instance's root folder in a file browser. + + + + + Delete + + + Deletes the selected instance. + + -- cgit v1.2.3 From de2632af0dcd7e6a1c3c763c9f7cf38c67ead441 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 31 Jan 2013 14:31:16 -0600 Subject: Added instance context menu and status tips. --- gui/mainwindow.cpp | 12 ++++++++ gui/mainwindow.h | 2 ++ gui/mainwindow.ui | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 4 deletions(-) (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e257f5ae..dc8f77fe 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -16,6 +16,8 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include + #include #include @@ -104,3 +106,13 @@ void MainWindow::closeEvent(QCloseEvent *event) settings->getConfig().setValue("MainWindowState", saveState()); QMainWindow::closeEvent(event); } + +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(ui->instanceView->mapToGlobal(pos)); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 91efd497..ce06a085 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -56,6 +56,8 @@ private slots: void on_mainToolBar_visibilityChanged(bool); + void on_instanceView_customContextMenuRequested(const QPoint &pos); + private: Ui::MainWindow *ui; diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 3e832276..bc58f7f8 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -34,7 +34,11 @@ 0 - + + + Qt::CustomContextMenu + + @@ -110,6 +114,9 @@ Add a new instance. + + Add a new instance. + @@ -122,6 +129,9 @@ Open the instance folder in a file browser. + + Open the instance folder in a file browser. + @@ -134,6 +144,9 @@ Reload the instance list. + + Reload the instance list. + @@ -146,6 +159,9 @@ Open the central mods folder in a file browser. + + Open the central mods folder in a file browser. + @@ -158,6 +174,9 @@ Check for new updates for MultiMC + + Check for new updates for MultiMC + @@ -170,6 +189,9 @@ Change settings. + + Change settings. + QAction::PreferencesRole @@ -185,6 +207,9 @@ Open the bug tracker to report a bug with MultiMC. + + Open the bug tracker to report a bug with MultiMC. + @@ -197,6 +222,9 @@ Open the MultiMC dev blog to read news about MultiMC. + + Open the MultiMC dev blog to read news about MultiMC. + @@ -209,6 +237,9 @@ View information about MultiMC. + + About MultiMC + QAction::AboutRole @@ -220,6 +251,9 @@ Launch the selected instance. + + Launch the selected instance. + @@ -228,6 +262,9 @@ Rename the selected instance. + + Rename the selected instance. + @@ -236,6 +273,9 @@ Change the selected instance's group. + + Change the selected instance's group. + @@ -244,6 +284,9 @@ Change the selected instance's icon. + + Change the selected instance's icon. + @@ -252,6 +295,9 @@ Edit the notes for the selected instance. + + Edit the notes for the selected instance. + @@ -260,6 +306,9 @@ Change settings for the selected instance. + + Change settings for the selected instance. + @@ -268,6 +317,9 @@ Make a shortcut on the desktop for the selected instance. + + Make a shortcut on the desktop for the selected instance. + @@ -276,6 +328,9 @@ Manage saves for the selected instance. + + Manage saves for the selected instance. + @@ -284,6 +339,9 @@ Edit the mods for the selected instance. + + Edit the mods for the selected instance. + @@ -292,6 +350,9 @@ Change the selected instance's Minecraft version. + + Change the selected instance's Minecraft version. + @@ -300,13 +361,19 @@ Change the version of LWJGL for the selected instance to use. + + Change the version of LWJGL for the selected instance to use. + Rebuild Jar - Re-installs the mods for the selected instance. + Reinstall the mods for the selected instance. + + + Reinstall the mods for the selected instance. @@ -314,7 +381,10 @@ View Folder - Opens the selected instance's root folder in a file browser. + Open the selected instance's root folder in a file browser. + + + Open the selected instance's root folder in a file browser. @@ -322,7 +392,10 @@ Delete - Deletes the selected instance. + Delete the selected instance. + + + Delete the selected instance. -- cgit v1.2.3 From a96e1853de4c2769a6c3092212bec4276630b719 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 1 Feb 2013 12:22:22 -0600 Subject: Implement news and report bug buttons. --- gui/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index dc8f77fe..3a5e3d86 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -79,12 +79,12 @@ void MainWindow::on_actionSettings_triggered() void MainWindow::on_actionReportBug_triggered() { - + QDesktopServices::openUrl(QUrl("http://bugs.forkk.net/")); } void MainWindow::on_actionNews_triggered() { - + QDesktopServices::openUrl(QUrl("http://news.forkk.net/")); } void MainWindow::on_actionAbout_triggered() -- cgit v1.2.3 From 3c8a12aded03e6e3f4a0c50cbb7a7ef4e57fab07 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 1 Feb 2013 13:07:36 -0600 Subject: Added new instance dialog. --- gui/mainwindow.cpp | 7 +- gui/newinstancedialog.cpp | 33 +++++++++ gui/newinstancedialog.h | 37 +++++++++++ gui/newinstancedialog.ui | 166 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 gui/newinstancedialog.cpp create mode 100644 gui/newinstancedialog.h create mode 100644 gui/newinstancedialog.ui (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3a5e3d86..1ff633b2 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -17,12 +17,16 @@ #include "ui_mainwindow.h" #include +#include #include #include #include "util/osutils.h" + #include "gui/settingsdialog.h" +#include "gui/newinstancedialog.h" + #include "data/appsettings.h" #include "data/version.h" @@ -48,7 +52,8 @@ MainWindow::~MainWindow() void MainWindow::on_actionAddInstance_triggered() { - + NewInstanceDialog *newInstDlg = new NewInstanceDialog(this); + newInstDlg->exec(); } void MainWindow::on_actionViewInstanceFolder_triggered() diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp new file mode 100644 index 00000000..400b42d8 --- /dev/null +++ b/gui/newinstancedialog.cpp @@ -0,0 +1,33 @@ +/* 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 "newinstancedialog.h" +#include "ui_newinstancedialog.h" + +#include + +NewInstanceDialog::NewInstanceDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewInstanceDialog) +{ + ui->setupUi(this); + resize(minimumSizeHint()); + layout()->setSizeConstraint(QLayout::SetFixedSize); +} + +NewInstanceDialog::~NewInstanceDialog() +{ + delete ui; +} diff --git a/gui/newinstancedialog.h b/gui/newinstancedialog.h new file mode 100644 index 00000000..263136f1 --- /dev/null +++ b/gui/newinstancedialog.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. + */ + +#ifndef NEWINSTANCEDIALOG_H +#define NEWINSTANCEDIALOG_H + +#include + +namespace Ui { +class NewInstanceDialog; +} + +class NewInstanceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit NewInstanceDialog(QWidget *parent = 0); + ~NewInstanceDialog(); + +private: + Ui::NewInstanceDialog *ui; +}; + +#endif // NEWINSTANCEDIALOG_H diff --git a/gui/newinstancedialog.ui b/gui/newinstancedialog.ui new file mode 100644 index 00000000..865f6301 --- /dev/null +++ b/gui/newinstancedialog.ui @@ -0,0 +1,166 @@ + + + NewInstanceDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 220 + 230 + + + + 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::Horizontal + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + NewInstanceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewInstanceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- cgit v1.2.3 From a416c58a93dd9d108f4c4fa968b9431e30834c5c Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 5 Feb 2013 16:34:20 -0600 Subject: Started working on task system and login system. --- gui/logindialog.cpp | 51 ++++++++++++++++++ gui/logindialog.h | 40 ++++++++++++++ gui/logindialog.ui | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gui/mainwindow.cpp | 32 ++++++++++++ gui/mainwindow.h | 11 +++- gui/taskdialog.cpp | 109 +++++++++++++++++++++++++++++++++++++++ gui/taskdialog.h | 63 +++++++++++++++++++++++ gui/taskdialog.ui | 53 +++++++++++++++++++ 8 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 gui/logindialog.cpp create mode 100644 gui/logindialog.h create mode 100644 gui/logindialog.ui create mode 100644 gui/taskdialog.cpp create mode 100644 gui/taskdialog.h create mode 100644 gui/taskdialog.ui (limited to 'gui') diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp new file mode 100644 index 00000000..426757a9 --- /dev/null +++ b/gui/logindialog.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 "logindialog.h" +#include "ui_logindialog.h" + +LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : + QDialog(parent), + ui(new Ui::LoginDialog) +{ + ui->setupUi(this); + + if (loginErrMsg.isEmpty()) + ui->loginErrorLabel->setVisible(false); + else + { + ui->loginErrorLabel->setVisible(true); + ui->loginErrorLabel->setText(QString("%1"). + arg(loginErrMsg)); + } + + resize(minimumSizeHint()); + layout()->setSizeConstraint(QLayout::SetFixedSize); +} + +LoginDialog::~LoginDialog() +{ + delete ui; +} + +QString LoginDialog::getUsername() const +{ + return ui->usernameTextBox->text(); +} + +QString LoginDialog::getPassword() const +{ + return ui->passwordTextBox->text(); +} diff --git a/gui/logindialog.h b/gui/logindialog.h new file mode 100644 index 00000000..1b70dcd5 --- /dev/null +++ b/gui/logindialog.h @@ -0,0 +1,40 @@ +/* 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 + +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; + +private: + Ui::LoginDialog *ui; +}; + +#endif // LOGINDIALOG_H diff --git a/gui/logindialog.ui b/gui/logindialog.ui new file mode 100644 index 00000000..ce41d2f5 --- /dev/null +++ b/gui/logindialog.ui @@ -0,0 +1,146 @@ + + + LoginDialog + + + + 0 + 0 + 365 + 145 + + + + Login + + + + + + <span style=" color:#ff0000;">Error</span> + + + + + + + + + Username: + + + + + + + Username + + + + + + + Password: + + + + + + + QLineEdit::Password + + + Password + + + + + + + + + + + &Force Update + + + true + + + + + + + + 1 + 0 + + + + &Remember Username? + + + + + + + + 1 + 0 + + + + R&emember Password? + + + + + + + + + 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/mainwindow.cpp b/gui/mainwindow.cpp index 1ff633b2..c2f0c390 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -26,10 +26,14 @@ #include "gui/settingsdialog.h" #include "gui/newinstancedialog.h" +#include "gui/logindialog.h" +#include "gui/taskdialog.h" #include "data/appsettings.h" #include "data/version.h" +#include "tasks/logintask.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -121,3 +125,31 @@ void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) instContextMenu->exec(ui->instanceView->mapToGlobal(pos)); } + + +void MainWindow::on_actionLaunchInstance_triggered() +{ + doLogin(); +} + +void MainWindow::doLogin(const QString &errorMsg) +{ + LoginDialog* loginDlg = new LoginDialog(this, errorMsg); + if (loginDlg->exec()) + { + UserInfo uInfo(loginDlg->getUsername(), loginDlg->getPassword()); + + TaskDialog* tDialog = new TaskDialog(this); + LoginTask* loginTask = new LoginTask(uInfo, tDialog); + connect(loginTask, SIGNAL(loginComplete(LoginResponse)), + SLOT(onLoginComplete(LoginResponse))); + connect(loginTask, SIGNAL(loginFailed(QString)), + SLOT(doLogin(QString))); + tDialog->exec(loginTask); + } +} + +void MainWindow::onLoginComplete(LoginResponse response) +{ + +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index ce06a085..28ca341a 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -18,7 +18,8 @@ #include -#include "../data/instancemodel.h" +#include "data/instancemodel.h" +#include "data/loginresponse.h" namespace Ui { @@ -58,6 +59,14 @@ private slots: void on_instanceView_customContextMenuRequested(const QPoint &pos); + void on_actionLaunchInstance_triggered(); + + + void doLogin(const QString& errorMsg = ""); + + + void onLoginComplete(LoginResponse response); + private: Ui::MainWindow *ui; diff --git a/gui/taskdialog.cpp b/gui/taskdialog.cpp new file mode 100644 index 00000000..a8738fe3 --- /dev/null +++ b/gui/taskdialog.cpp @@ -0,0 +1,109 @@ +/* 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 "taskdialog.h" +#include "ui_taskdialog.h" + +#include + +#include "tasks/task.h" + +TaskDialog::TaskDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::TaskDialog) +{ + ui->setupUi(this); + updateSize(); + + changeProgress(0); +} + +TaskDialog::~TaskDialog() +{ + delete ui; +} + +void TaskDialog::updateSize() +{ + resize(QSize(480, minimumSizeHint().height())); +} + +void TaskDialog::exec(Task *task) +{ + this->task = task; + + // Connect signals. + connect(task, SIGNAL(taskStarted(Task*)), + this, SLOT(onTaskStarted(Task*))); + connect(task, SIGNAL(taskEnded(Task*)), + this, SLOT(onTaskEnded(Task*))); + connect(task, SIGNAL(statusChanged(const QString&)), + this, SLOT(changeStatus(const QString&))); + connect(task, SIGNAL(progressChanged(int)), + this, SLOT(changeProgress(int))); + + task->startTask(); + QDialog::exec(); +} + +Task* TaskDialog::getTask() +{ + return task; +} + +void TaskDialog::onTaskStarted(Task*) +{ + +} + +void TaskDialog::onTaskEnded(Task*) +{ + close(); +} + +void TaskDialog::changeStatus(const QString &status) +{ + ui->statusLabel->setText(status); + updateSize(); +} + +void TaskDialog::changeProgress(int progress) +{ + if (progress < 0) + progress = 0; + else if (progress > 100) + progress = 100; + + ui->taskProgressBar->setValue(progress); +} + +void TaskDialog::keyPressEvent(QKeyEvent* e) +{ + if (e->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(e); +} + +void TaskDialog::closeEvent(QCloseEvent* e) +{ + if (task && task->isRunning()) + { + e->ignore(); + } + else + { + QDialog::closeEvent(e); + } +} diff --git a/gui/taskdialog.h b/gui/taskdialog.h new file mode 100644 index 00000000..faf3ed90 --- /dev/null +++ b/gui/taskdialog.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. + */ + +#ifndef TASKDIALOG_H +#define TASKDIALOG_H + +#include + +class Task; + +namespace Ui { +class TaskDialog; +} + +class TaskDialog : public QDialog +{ + Q_OBJECT + +public: + explicit TaskDialog(QWidget *parent = 0); + ~TaskDialog(); + + void updateSize(); + + void exec(Task* task); + + Task* getTask(); + +public slots: + void onTaskStarted(Task*); + void onTaskEnded(Task*); + + void changeStatus(const QString& status); + void changeProgress(int progress); + + void test() { qDebug("Lol"); } + +signals: + + +protected: + virtual void keyPressEvent(QKeyEvent* e); + virtual void closeEvent(QCloseEvent* e); + +private: + Ui::TaskDialog *ui; + + Task* task; +}; + +#endif // TASKDIALOG_H diff --git a/gui/taskdialog.ui b/gui/taskdialog.ui new file mode 100644 index 00000000..1cdf7978 --- /dev/null +++ b/gui/taskdialog.ui @@ -0,0 +1,53 @@ + + + TaskDialog + + + + 0 + 0 + 400 + 58 + + + + + 400 + 0 + + + + + 600 + 16777215 + + + + Please wait... + + + + + + Task Status... + + + true + + + + + + + 24 + + + false + + + + + + + + -- cgit v1.2.3 From e475f5d51251ae57da0480bbadc9cb32a8bc72b2 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 5 Feb 2013 19:22:19 -0600 Subject: Implemented login system. --- gui/mainwindow.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gui') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c2f0c390..bc0840a0 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -142,14 +142,16 @@ void MainWindow::doLogin(const QString &errorMsg) TaskDialog* tDialog = new TaskDialog(this); LoginTask* loginTask = new LoginTask(uInfo, tDialog); connect(loginTask, SIGNAL(loginComplete(LoginResponse)), - SLOT(onLoginComplete(LoginResponse))); + SLOT(onLoginComplete(LoginResponse)), Qt::QueuedConnection); connect(loginTask, SIGNAL(loginFailed(QString)), - SLOT(doLogin(QString))); + SLOT(doLogin(QString)), Qt::QueuedConnection); tDialog->exec(loginTask); } } void MainWindow::onLoginComplete(LoginResponse response) { - + QMessageBox::information(this, "Login Successful", + QString("Logged in as %1 with session ID %2."). + arg(response.getUsername(), response.getSessionID())); } -- cgit v1.2.3