From efa8e26a3f3f7ba5e536cd10e86303b4fe1baba0 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 15 Feb 2014 14:19:35 +0100 Subject: Profiler support. Currently JProfiler and JVisualVM are implemented. --- gui/MainWindow.cpp | 56 ++++++++++++++++++--- gui/MainWindow.h | 8 +-- gui/MainWindow.ui | 12 ++++- gui/dialogs/SettingsDialog.cpp | 85 +++++++++++++++++++++++++++++++ gui/dialogs/SettingsDialog.h | 5 ++ gui/dialogs/SettingsDialog.ui | 112 ++++++++++++++++++++++++++++++++++++++++- 6 files changed, 264 insertions(+), 14 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 29f7c8e8..ddeb9947 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "osutils.h" #include "userutils.h" @@ -97,6 +98,9 @@ #include #include +#include "logic/profiler/BaseProfiler.h" +#include "logic/OneSixInstance.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MultiMCPlatform::fixWM_CLASS(this); @@ -1078,7 +1082,7 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered() } } -void MainWindow::doLaunch(bool online) +void MainWindow::doLaunch(bool online, bool profile) { if (!m_selectedInstance) return; @@ -1194,11 +1198,11 @@ void MainWindow::doLaunch(bool online) // update first if the server actually responded if (session->auth_server_online) { - updateInstance(m_selectedInstance, session); + updateInstance(m_selectedInstance, session, profile); } else { - launchInstance(m_selectedInstance, session); + launchInstance(m_selectedInstance, session, profile); } tryagain = false; } @@ -1206,22 +1210,22 @@ void MainWindow::doLaunch(bool online) } } -void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session) +void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session, bool profile) { auto updateTask = instance->doUpdate(); if (!updateTask) { - launchInstance(instance, session); + launchInstance(instance, session, profile); return; } ProgressDialog tDialog(this); - connect(updateTask.get(), &Task::succeeded, [this, instance, session] - { launchInstance(instance, session); }); + connect(updateTask.get(), &Task::succeeded, [this, instance, session, profile] + { launchInstance(instance, session, profile); }); connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); tDialog.exec(updateTask.get()); } -void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session) +void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, bool profile) { Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL"); @@ -1237,6 +1241,33 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session) proc->setLogin(session); proc->launch(); + + if (profile && qobject_cast(instance)) + { + BaseProfiler *profiler = MMC->currentProfiler()->createProfiler( + qobject_cast(instance), this); + QProgressDialog dialog; + dialog.setMinimum(0); + dialog.setMaximum(0); + dialog.setValue(0); + dialog.setLabelText(tr("Waiting for profiler...")); + dialog.show(); + connect(profiler, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) + { + dialog.accept(); + QMessageBox msg; + msg.setText(tr("The launch of Minecraft itself is delayed until you press the " + "button. This is the right time to setup the profiler, as the " + "profiler server is running now.\n\n%1").arg(message)); + msg.setWindowTitle(tr("Waiting")); + msg.setIcon(QMessageBox::Information); + msg.addButton(tr("Launch"), QMessageBox::AcceptRole); + msg.exec(); + proc->write("launch onesix\n"); + }); + profiler->beginProfiling(proc); + dialog.exec(); + } } void MainWindow::onGameUpdateError(QString error) @@ -1416,6 +1447,15 @@ void MainWindow::on_actionEditInstNotes_triggered() } } +void MainWindow::on_actionProfileInstance_triggered() +{ + if (m_selectedInstance) + { + NagUtils::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this); + doLaunch(true, true); + } +} + void MainWindow::instanceEnded() { this->show(); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 4d9e165d..66d98bc5 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -107,22 +107,24 @@ slots: void on_actionEditInstNotes_triggered(); + void on_actionProfileInstance_triggered(); + /*! * Launches the currently selected instance with the default account. * If no default account is selected, prompts the user to pick an account. */ - void doLaunch(bool online = true); + void doLaunch(bool online = true, bool profile = false); /*! * Launches the given instance with the given account. * This function assumes that the given account has a valid, usable access token. */ - void launchInstance(BaseInstance *instance, AuthSessionPtr session); + void launchInstance(BaseInstance *instance, AuthSessionPtr session, bool profile = false); /*! * Prepares the given instance for launch with the given account. */ - void updateInstance(BaseInstance *instance, AuthSessionPtr account); + void updateInstance(BaseInstance *instance, AuthSessionPtr account, bool profile = false); void onGameUpdateError(QString error); diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 8cf26d18..81f66136 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -108,6 +108,7 @@ + @@ -528,12 +529,19 @@ Launch the selected instance. + + + Profile + + + Starts a profiling session with the current instance + + - - + diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index ef363f02..3039acc1 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -29,6 +29,8 @@ #include "logic/updater/UpdateChecker.h" +#include "logic/profiler/BaseProfiler.h" + #include #include #include @@ -368,6 +370,22 @@ void SettingsDialog::applySettings(SettingsObject *s) } s->set("PostExitCommand", ui->postExitCmdTextBox->text()); + + // Profilers + s->set("JProfilerPath", ui->jprofilerPathEdit->text()); + s->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); + if (ui->profilerNoneBtn->isChecked()) + { + s->set("CurrentProfiler", QString()); + } + else if (ui->jprofilerBtn->isChecked()) + { + s->set("CurrentProfiler", "jprofiler"); + } + else if (ui->jvisualvmBtn->isChecked()) + { + s->set("CurrentProfiler", "jvisualvm"); + } } void SettingsDialog::loadSettings(SettingsObject *s) @@ -447,6 +465,23 @@ void SettingsDialog::loadSettings(SettingsObject *s) // Custom Commands ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); + + // Profilers + ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString()); + ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString()); + const QString currentProfiler = s->get("CurrentProfiler").toString(); + if (currentProfiler.isEmpty()) + { + ui->profilerNoneBtn->setChecked(true); + } + else if (currentProfiler == "jprofiler") + { + ui->jprofilerBtn->setChecked(true); + } + else if (currentProfiler == "jvisualvm") + { + ui->jvisualvmBtn->setChecked(true); + } } void SettingsDialog::on_javaDetectBtn_clicked() @@ -503,3 +538,53 @@ void SettingsDialog::checkFinished(JavaCheckResult result) "or set the path to the java executable.")); } } + +void SettingsDialog::on_jprofilerPathBtn_clicked() +{ + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Directory"), + ui->jprofilerPathEdit->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->jprofilerPathEdit->setText(cooked_dir); + } +} +void SettingsDialog::on_jprofilerCheckBtn_clicked() +{ + if (!ui->jprofilerPathEdit->text().isEmpty()) + { + QString error; + if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JProfiler install:\n%1").arg(error)); + } + } +} + +void SettingsDialog::on_jvisualvmPathBtn_clicked() +{ + QString raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), + ui->jvisualvmPathEdit->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->jvisualvmPathEdit->setText(cooked_dir); + } +} +void SettingsDialog::on_jvisualvmCheckBtn_clicked() +{ + if (!ui->jvisualvmPathEdit->text().isEmpty()) + { + QString error; + if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JVisualVM install:\n%1").arg(error)); + } + } +} diff --git a/gui/dialogs/SettingsDialog.h b/gui/dialogs/SettingsDialog.h index d7bbbeb3..60d569f9 100644 --- a/gui/dialogs/SettingsDialog.h +++ b/gui/dialogs/SettingsDialog.h @@ -75,6 +75,11 @@ slots: void checkFinished(JavaCheckResult result); + void on_jprofilerPathBtn_clicked(); + void on_jprofilerCheckBtn_clicked(); + void on_jvisualvmPathBtn_clicked(); + void on_jvisualvmCheckBtn_clicked(); + /*! * Updates the list of update channels in the combo box. */ diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 54e7db7a..29cbbcba 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -863,6 +863,116 @@ + + + Profiling + + + + + + Active profiler + + + + + + None + + + + + + + JProfiler + + + + + + + JVisualVM + + + + + + + + + + JProfiler + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + + + + JVisualVM + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + @@ -938,7 +1048,7 @@ - + -- cgit v1.2.3 From 8219dbf612f4e6f603d304348fc388e364602f98 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 15 Feb 2014 22:26:44 +0100 Subject: Underp. Don't depend on OneSix. Nicer "menu" style choosing. --- gui/MainWindow.cpp | 62 ++++++++++++++++++++++++++---------------- gui/MainWindow.h | 9 +++--- gui/MainWindow.ui | 9 ------ gui/dialogs/SettingsDialog.cpp | 25 ----------------- gui/dialogs/SettingsDialog.ui | 38 ++------------------------ 5 files changed, 45 insertions(+), 98 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index ddeb9947..b4811579 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -99,7 +99,6 @@ #include #include "logic/profiler/BaseProfiler.h" -#include "logic/OneSixInstance.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -1082,7 +1081,7 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered() } } -void MainWindow::doLaunch(bool online, bool profile) +void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler) { if (!m_selectedInstance) return; @@ -1198,11 +1197,11 @@ void MainWindow::doLaunch(bool online, bool profile) // update first if the server actually responded if (session->auth_server_online) { - updateInstance(m_selectedInstance, session, profile); + updateInstance(m_selectedInstance, session, profiler); } else { - launchInstance(m_selectedInstance, session, profile); + launchInstance(m_selectedInstance, session, profiler); } tryagain = false; } @@ -1210,22 +1209,22 @@ void MainWindow::doLaunch(bool online, bool profile) } } -void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session, bool profile) +void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler) { auto updateTask = instance->doUpdate(); if (!updateTask) { - launchInstance(instance, session, profile); + launchInstance(instance, session, profiler); return; } ProgressDialog tDialog(this); - connect(updateTask.get(), &Task::succeeded, [this, instance, session, profile] - { launchInstance(instance, session, profile); }); + connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler] + { launchInstance(instance, session, profiler); }); connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); tDialog.exec(updateTask.get()); } -void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, bool profile) +void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler) { Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL"); @@ -1242,17 +1241,22 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, proc->setLogin(session); proc->launch(); - if (profile && qobject_cast(instance)) + if (profiler) { - BaseProfiler *profiler = MMC->currentProfiler()->createProfiler( - qobject_cast(instance), this); + QString error; + if (!profiler->check(&error)) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); + return; + } + BaseProfiler *profilerInstance = profiler->createProfiler(instance, this); QProgressDialog dialog; dialog.setMinimum(0); dialog.setMaximum(0); dialog.setValue(0); dialog.setLabelText(tr("Waiting for profiler...")); dialog.show(); - connect(profiler, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) + connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) { dialog.accept(); QMessageBox msg; @@ -1263,11 +1267,15 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, msg.setIcon(QMessageBox::Information); msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.exec(); - proc->write("launch onesix\n"); + proc->write("launch\n"); }); - profiler->beginProfiling(proc); + profilerInstance->beginProfiling(proc); dialog.exec(); } + else + { + proc->write("launch\n"); + } } void MainWindow::onGameUpdateError(QString error) @@ -1408,6 +1416,21 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); updateInstanceToolIcon(m_selectedInstance->iconKey()); + if (ui->actionLaunchInstance->menu()) + { + ui->actionLaunchInstance->menu()->deleteLater(); + } + QMenu *launchMenu = new QMenu; + QAction *normalLaunch = launchMenu->addAction(tr("Launch")); + connect(normalLaunch, &QAction::triggered, [this](){doLaunch();}); + launchMenu->addSeparator()->setText(tr("Profilers")); + for (auto profiler : MMC->profilers().values()) + { + QAction *profilerAction = launchMenu->addAction(profiler->name()); + connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());}); + } + ui->actionLaunchInstance->setMenu(launchMenu); + MMC->settings()->set("SelectedInstance", m_selectedInstance->id()); } else @@ -1447,15 +1470,6 @@ void MainWindow::on_actionEditInstNotes_triggered() } } -void MainWindow::on_actionProfileInstance_triggered() -{ - if (m_selectedInstance) - { - NagUtils::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this); - doLaunch(true, true); - } -} - void MainWindow::instanceEnded() { this->show(); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 66d98bc5..682c711d 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -29,6 +29,7 @@ class LabeledToolButton; class QLabel; class MinecraftProcess; class ConsoleWindow; +class BaseProfilerFactory; namespace Ui { @@ -107,24 +108,22 @@ slots: void on_actionEditInstNotes_triggered(); - void on_actionProfileInstance_triggered(); - /*! * Launches the currently selected instance with the default account. * If no default account is selected, prompts the user to pick an account. */ - void doLaunch(bool online = true, bool profile = false); + void doLaunch(bool online = true, BaseProfilerFactory *profiler = 0); /*! * Launches the given instance with the given account. * This function assumes that the given account has a valid, usable access token. */ - void launchInstance(BaseInstance *instance, AuthSessionPtr session, bool profile = false); + void launchInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler = 0); /*! * Prepares the given instance for launch with the given account. */ - void updateInstance(BaseInstance *instance, AuthSessionPtr account, bool profile = false); + void updateInstance(BaseInstance *instance, AuthSessionPtr account, BaseProfilerFactory *profiler = 0); void onGameUpdateError(QString error); diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 81f66136..90c86075 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -108,7 +108,6 @@ - @@ -529,14 +528,6 @@ Launch the selected instance. - - - Profile - - - Starts a profiling session with the current instance - - diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 3039acc1..ba2052c6 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -374,18 +374,6 @@ void SettingsDialog::applySettings(SettingsObject *s) // Profilers s->set("JProfilerPath", ui->jprofilerPathEdit->text()); s->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); - if (ui->profilerNoneBtn->isChecked()) - { - s->set("CurrentProfiler", QString()); - } - else if (ui->jprofilerBtn->isChecked()) - { - s->set("CurrentProfiler", "jprofiler"); - } - else if (ui->jvisualvmBtn->isChecked()) - { - s->set("CurrentProfiler", "jvisualvm"); - } } void SettingsDialog::loadSettings(SettingsObject *s) @@ -469,19 +457,6 @@ void SettingsDialog::loadSettings(SettingsObject *s) // Profilers ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString()); ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString()); - const QString currentProfiler = s->get("CurrentProfiler").toString(); - if (currentProfiler.isEmpty()) - { - ui->profilerNoneBtn->setChecked(true); - } - else if (currentProfiler == "jprofiler") - { - ui->jprofilerBtn->setChecked(true); - } - else if (currentProfiler == "jvisualvm") - { - ui->jvisualvmBtn->setChecked(true); - } } void SettingsDialog::on_javaDetectBtn_clicked() diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 29cbbcba..8d9a7f87 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -20,7 +20,7 @@ Settings - + :/icons/toolbar/settings:/icons/toolbar/settings @@ -33,7 +33,7 @@ QTabWidget::Rounded - 0 + 5 @@ -868,36 +868,6 @@ Profiling - - - - Active profiler - - - - - - None - - - - - - - JProfiler - - - - - - - JVisualVM - - - - - - @@ -1010,9 +980,7 @@ postExitCmdTextBox settingsTabs - - - + buttonBox -- cgit v1.2.3 From 7ceb2cacb129d5924087f616cfc0b949689ed4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 16 Feb 2014 00:10:45 +0100 Subject: Fix a few bugs in profilers. * Legacy was launching before the profiler. * Some clarity changes. * Report problem with empty strings as profiler paths. --- gui/MainWindow.cpp | 7 ++++--- gui/dialogs/SettingsDialog.cpp | 30 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index b4811579..7c61ca9d 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1239,7 +1239,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded())); proc->setLogin(session); - proc->launch(); + proc->arm(); if (profiler) { @@ -1247,6 +1247,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, if (!profiler->check(&error)) { QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); + proc->abort(); return; } BaseProfiler *profilerInstance = profiler->createProfiler(instance, this); @@ -1267,14 +1268,14 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, msg.setIcon(QMessageBox::Information); msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.exec(); - proc->write("launch\n"); + proc->launch(); }); profilerInstance->beginProfiling(proc); dialog.exec(); } else { - proc->write("launch\n"); + proc->launch(); } } diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index ba2052c6..7afb6565 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -528,14 +528,15 @@ void SettingsDialog::on_jprofilerPathBtn_clicked() } void SettingsDialog::on_jprofilerCheckBtn_clicked() { - if (!ui->jprofilerPathEdit->text().isEmpty()) + QString error; + if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) { - QString error; - if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); - } + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JProfiler install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("JProfiler setup seems to be OK")); } } @@ -553,13 +554,14 @@ void SettingsDialog::on_jvisualvmPathBtn_clicked() } void SettingsDialog::on_jvisualvmCheckBtn_clicked() { - if (!ui->jvisualvmPathEdit->text().isEmpty()) + QString error; + if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) { - QString error; - if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) - { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); - } + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JVisualVM install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("JVisualVM setup seems to be OK")); } } -- cgit v1.2.3 From 82b35b5445d88d67c89c6547b24053d31dc35b9c Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 08:54:52 +0100 Subject: Fix stuff. Make sure different ways of aborting profiling work. --- gui/MainWindow.cpp | 12 ++++++++++++ gui/dialogs/SettingsDialog.ui | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 7c61ca9d..b28e753f 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1256,6 +1256,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, dialog.setMaximum(0); dialog.setValue(0); dialog.setLabelText(tr("Waiting for profiler...")); + connect(&dialog, &QDialog::rejected, profilerInstance, &BaseProfiler::abortProfiling); dialog.show(); connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) { @@ -1270,6 +1271,17 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, msg.exec(); proc->launch(); }); + connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this](const QString &message) + { + dialog.accept(); + QMessageBox msg; + msg.setText(tr("Couldn't start the profiler: %1").arg(message)); + msg.setWindowTitle(tr("Error")); + msg.setIcon(QMessageBox::Critical); + msg.addButton(QMessageBox::Ok); + msg.exec(); + proc->abort(); + }); profilerInstance->beginProfiling(proc); dialog.exec(); } diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 8d9a7f87..acf360a3 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -20,7 +20,7 @@ Settings - + :/icons/toolbar/settings:/icons/toolbar/settings @@ -33,7 +33,7 @@ QTabWidget::Rounded - 5 + 0 @@ -980,7 +980,9 @@ postExitCmdTextBox settingsTabs - + + + buttonBox -- cgit v1.2.3 From 994972bf5da5584186e6e82c36287afeb6c1e23a Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 09:30:38 +0100 Subject: More fixes. --- gui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index b28e753f..b05c58f7 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1256,7 +1256,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, dialog.setMaximum(0); dialog.setValue(0); dialog.setLabelText(tr("Waiting for profiler...")); - connect(&dialog, &QDialog::rejected, profilerInstance, &BaseProfiler::abortProfiling); + connect(&dialog, &QProgressDialog::canceled, profilerInstance, &BaseProfiler::abortProfiling); dialog.show(); connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) { -- cgit v1.2.3 From 616c37269053bc4f111792dbb9374cc119a58339 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 10:46:14 +0100 Subject: Fix more stuff. Detached tools, only MCEdit for now. --- gui/MainWindow.cpp | 29 ++++++++++++++++++++++++++++- gui/dialogs/SettingsDialog.cpp | 28 ++++++++++++++++++++++++++++ gui/dialogs/SettingsDialog.h | 2 ++ gui/dialogs/SettingsDialog.ui | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 3 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index b05c58f7..3f469061 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1440,7 +1440,34 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & for (auto profiler : MMC->profilers().values()) { QAction *profilerAction = launchMenu->addAction(profiler->name()); - connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());}); + QString error; + if (!profiler->check(&error)) + { + profilerAction->setDisabled(true); + profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\".")); + } + else + { + connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());}); + } + } + launchMenu->addSeparator()->setText(tr("Tools")); + for (auto tool : MMC->tools().values()) + { + QAction *toolAction = launchMenu->addAction(tool->name()); + QString error; + if (!tool->check(&error)) + { + toolAction->setDisabled(true); + toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\".")); + } + else + { + connect(toolAction, &QAction::triggered, [this, tool]() + { + tool->createDetachedTool(m_selectedInstance, this)->run(); + }); + } } ui->actionLaunchInstance->setMenu(launchMenu); diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 7afb6565..9423d7eb 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -374,6 +374,7 @@ void SettingsDialog::applySettings(SettingsObject *s) // Profilers s->set("JProfilerPath", ui->jprofilerPathEdit->text()); s->set("JVisualVMPath", ui->jvisualvmPathEdit->text()); + s->set("MCEditPath", ui->mceditPathEdit->text()); } void SettingsDialog::loadSettings(SettingsObject *s) @@ -457,6 +458,7 @@ void SettingsDialog::loadSettings(SettingsObject *s) // Profilers ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString()); ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString()); + ui->mceditPathEdit->setText(s->get("MCEditPath").toString()); } void SettingsDialog::on_javaDetectBtn_clicked() @@ -565,3 +567,29 @@ void SettingsDialog::on_jvisualvmCheckBtn_clicked() QMessageBox::information(this, tr("OK"), tr("JVisualVM setup seems to be OK")); } } + +void SettingsDialog::on_mceditPathBtn_clicked() +{ + QString raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Path"), + ui->jvisualvmPathEdit->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->mceditPathEdit->setText(cooked_dir); + } +} +void SettingsDialog::on_mceditCheckBtn_clicked() +{ + QString error; + if (!MMC->tools()["mcedit"]->check(ui->mceditPathEdit->text(), &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking MCEdit install:\n%1").arg(error)); + } + else + { + QMessageBox::information(this, tr("OK"), tr("MCEdit setup seems to be OK")); + } +} diff --git a/gui/dialogs/SettingsDialog.h b/gui/dialogs/SettingsDialog.h index 60d569f9..d8495fdd 100644 --- a/gui/dialogs/SettingsDialog.h +++ b/gui/dialogs/SettingsDialog.h @@ -79,6 +79,8 @@ slots: void on_jprofilerCheckBtn_clicked(); void on_jvisualvmPathBtn_clicked(); void on_jvisualvmCheckBtn_clicked(); + void on_mceditPathBtn_clicked(); + void on_mceditCheckBtn_clicked(); /*! * Updates the list of update channels in the combo box. diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index acf360a3..fbfa7aed 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -863,9 +863,9 @@ - + - Profiling + External Tools @@ -928,6 +928,36 @@ + + + + MCEdit + + + + + + + + + + + ... + + + + + + + + + Check + + + + + + -- cgit v1.2.3 From c88c639b8efdcdfe87c2ce44fa270889826b38ef Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 11:49:55 +0100 Subject: Fix for windows and update tool menu after closing settings dialog --- gui/MainWindow.cpp | 88 +++++++++++++++++++++++++++++------------------------- gui/MainWindow.h | 2 ++ 2 files changed, 49 insertions(+), 41 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 3f469061..16c88201 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -360,6 +360,51 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos) myMenu.exec(view->mapToGlobal(pos)); } +void MainWindow::updateToolsMenu() +{ + if (ui->actionLaunchInstance->menu()) + { + ui->actionLaunchInstance->menu()->deleteLater(); + } + QMenu *launchMenu = new QMenu(this); + QAction *normalLaunch = launchMenu->addAction(tr("Launch")); + connect(normalLaunch, &QAction::triggered, [this](){doLaunch();}); + launchMenu->addSeparator()->setText(tr("Profilers")); + for (auto profiler : MMC->profilers().values()) + { + QAction *profilerAction = launchMenu->addAction(profiler->name()); + QString error; + if (!profiler->check(&error)) + { + profilerAction->setDisabled(true); + profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\".")); + } + else + { + connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());}); + } + } + launchMenu->addSeparator()->setText(tr("Tools")); + for (auto tool : MMC->tools().values()) + { + QAction *toolAction = launchMenu->addAction(tool->name()); + QString error; + if (!tool->check(&error)) + { + toolAction->setDisabled(true); + toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\".")); + } + else + { + connect(toolAction, &QAction::triggered, [this, tool]() + { + tool->createDetachedTool(m_selectedInstance, this)->run(); + }); + } + } + ui->actionLaunchInstance->setMenu(launchMenu); +} + void MainWindow::repopulateAccountsMenu() { accountMenu->clear(); @@ -933,6 +978,7 @@ void MainWindow::on_actionSettings_triggered() // FIXME: quick HACK to make this work. improve, optimize. proxymodel->invalidate(); proxymodel->sort(0); + updateToolsMenu(); } void MainWindow::on_actionManageAccounts_triggered() @@ -1429,47 +1475,7 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); updateInstanceToolIcon(m_selectedInstance->iconKey()); - if (ui->actionLaunchInstance->menu()) - { - ui->actionLaunchInstance->menu()->deleteLater(); - } - QMenu *launchMenu = new QMenu; - QAction *normalLaunch = launchMenu->addAction(tr("Launch")); - connect(normalLaunch, &QAction::triggered, [this](){doLaunch();}); - launchMenu->addSeparator()->setText(tr("Profilers")); - for (auto profiler : MMC->profilers().values()) - { - QAction *profilerAction = launchMenu->addAction(profiler->name()); - QString error; - if (!profiler->check(&error)) - { - profilerAction->setDisabled(true); - profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\".")); - } - else - { - connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());}); - } - } - launchMenu->addSeparator()->setText(tr("Tools")); - for (auto tool : MMC->tools().values()) - { - QAction *toolAction = launchMenu->addAction(tool->name()); - QString error; - if (!tool->check(&error)) - { - toolAction->setDisabled(true); - toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\".")); - } - else - { - connect(toolAction, &QAction::triggered, [this, tool]() - { - tool->createDetachedTool(m_selectedInstance, this)->run(); - }); - } - } - ui->actionLaunchInstance->setMenu(launchMenu); + updateToolsMenu(); MMC->settings()->set("SelectedInstance", m_selectedInstance->id()); } diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 682c711d..7a29977d 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -141,6 +141,8 @@ slots: void showInstanceContextMenu(const QPoint&); + void updateToolsMenu(); + public slots: void instanceActivated(QModelIndex); -- cgit v1.2.3 From 1dc34269bde4611d1a1c76f01df6dacd85f79c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 16 Feb 2014 12:04:26 +0100 Subject: Fix path selections for tools (settings dialog) --- gui/dialogs/SettingsDialog.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'gui') diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 9423d7eb..d20c0aa7 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -527,6 +527,10 @@ void SettingsDialog::on_jprofilerPathBtn_clicked() { ui->jprofilerPathEdit->setText(cooked_dir); } + else + { + // FIXME: see below... + } } void SettingsDialog::on_jprofilerCheckBtn_clicked() { @@ -546,12 +550,18 @@ void SettingsDialog::on_jvisualvmPathBtn_clicked() { QString raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), ui->jvisualvmPathEdit->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_path = NormalizePath(raw_dir); + QFileInfo finfo(cooked_path); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + if (!cooked_path.isEmpty() && finfo.isExecutable() && finfo.isFile()) { - ui->jvisualvmPathEdit->setText(cooked_dir); + ui->jvisualvmPathEdit->setText(cooked_path); + } + else + { + // FIXME: report error here, or run the checker instead of that condition above. + // ideally unify all the sanity checks and put them into the relevant classes } } void SettingsDialog::on_jvisualvmCheckBtn_clicked() @@ -570,8 +580,8 @@ void SettingsDialog::on_jvisualvmCheckBtn_clicked() void SettingsDialog::on_mceditPathBtn_clicked() { - QString raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Path"), - ui->jvisualvmPathEdit->text()); + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Path"), + ui->mceditPathEdit->text()); QString cooked_dir = NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist @@ -579,6 +589,9 @@ void SettingsDialog::on_mceditPathBtn_clicked() { ui->mceditPathEdit->setText(cooked_dir); } + { + // FIXME: as above. + } } void SettingsDialog::on_mceditCheckBtn_clicked() { -- cgit v1.2.3 From 9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 12:52:35 +0100 Subject: Restructure --- gui/MainWindow.cpp | 2 +- gui/dialogs/SettingsDialog.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 16c88201..ebbace52 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -98,7 +98,7 @@ #include #include -#include "logic/profiler/BaseProfiler.h" +#include "logic/tools/BaseProfiler.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index d20c0aa7..cd5aba74 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -29,7 +29,7 @@ #include "logic/updater/UpdateChecker.h" -#include "logic/profiler/BaseProfiler.h" +#include "logic/tools/BaseProfiler.h" #include #include -- cgit v1.2.3 From e4ecc31e07d6b16983cc038fee906417f58482d7 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 13:02:59 +0100 Subject: Links to the tools --- gui/dialogs/SettingsDialog.ui | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'gui') diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index fbfa7aed..7d94446e 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -895,6 +895,13 @@ + + + + <html><head/><body><p><a href="http://www.ej-technologies.com/products/jprofiler/overview.html"><span style=" text-decoration: underline; color:#0000ff;">http://www.ej-technologies.com/products/jprofiler/overview.html</span></a></p></body></html> + + + @@ -925,6 +932,13 @@ + + + + <html><head/><body><p><a href="http://visualvm.java.net/"><span style=" text-decoration: underline; color:#0000ff;">http://visualvm.java.net/</span></a></p></body></html> + + + @@ -955,6 +969,13 @@ + + + + <html><head/><body><p><a href="http://www.mcedit.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.mcedit.net/</span></a></p></body></html> + + + -- cgit v1.2.3 From dd2d8f48face27a0f43502206fc5ed8fc0dd6a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 16 Feb 2014 14:42:44 +0100 Subject: Nicer way of selecting tool folders and executables --- gui/dialogs/SettingsDialog.cpp | 202 +++++++++++++++++++++++++---------------- gui/dialogs/SettingsDialog.ui | 6 +- 2 files changed, 129 insertions(+), 79 deletions(-) (limited to 'gui') diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index cd5aba74..4b0b117d 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -48,12 +48,14 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se ui->jsonEditorTextBox->setClearButtonEnabled(true); #endif - restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("SettingsGeometry").toByteArray())); + restoreGeometry( + QByteArray::fromBase64(MMC->settings()->get("SettingsGeometry").toByteArray())); loadSettings(MMC->settings().get()); updateCheckboxStuff(); - QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this, &SettingsDialog::refreshUpdateChannelList); + QObject::connect(MMC->updateChecker().get(), &UpdateChecker::channelListLoaded, this, + &SettingsDialog::refreshUpdateChannelList); if (MMC->updateChecker()->hasChannels()) { @@ -64,6 +66,9 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se MMC->updateChecker()->updateChanList(); } connect(ui->proxyGroup, SIGNAL(buttonClicked(int)), SLOT(proxyChanged(int))); + ui->mceditLink->setOpenExternalLinks(true); + ui->jvisualvmLink->setOpenExternalLinks(true); + ui->jprofilerLink->setOpenExternalLinks(true); } SettingsDialog::~SettingsDialog() @@ -86,8 +91,10 @@ void SettingsDialog::updateCheckboxStuff() { ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); - ui->proxyAddrBox->setEnabled(!ui->proxyNoneBtn->isChecked() && !ui->proxyDefaultBtn->isChecked()); - ui->proxyAuthBox->setEnabled(!ui->proxyNoneBtn->isChecked() && !ui->proxyDefaultBtn->isChecked()); + ui->proxyAddrBox->setEnabled(!ui->proxyNoneBtn->isChecked() && + !ui->proxyDefaultBtn->isChecked()); + ui->proxyAuthBox->setEnabled(!ui->proxyNoneBtn->isChecked() && + !ui->proxyDefaultBtn->isChecked()); } void SettingsDialog::on_ftbLauncherBrowseBtn_clicked() @@ -105,8 +112,8 @@ void SettingsDialog::on_ftbLauncherBrowseBtn_clicked() void SettingsDialog::on_ftbBrowseBtn_clicked() { - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Directory"), - ui->ftbBox->text()); + QString raw_dir = + QFileDialog::getExistingDirectory(this, tr("FTB Directory"), ui->ftbBox->text()); QString cooked_dir = NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist @@ -172,11 +179,11 @@ void SettingsDialog::on_jsonEditorBrowseBtn_clicked() QString raw_file = QFileDialog::getOpenFileName( this, tr("JSON Editor"), ui->jsonEditorTextBox->text().isEmpty() - #if defined(Q_OS_LINUX) +#if defined(Q_OS_LINUX) ? QString("/usr/bin") - #else +#else ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() - #endif +#endif : ui->jsonEditorTextBox->text()); QString cooked_file = NormalizePath(raw_file); @@ -186,14 +193,14 @@ void SettingsDialog::on_jsonEditorBrowseBtn_clicked() } // it has to exist and be an executable - if (QFileInfo(cooked_file).exists() && - QFileInfo(cooked_file).isExecutable()) + if (QFileInfo(cooked_file).exists() && QFileInfo(cooked_file).isExecutable()) { ui->jsonEditorTextBox->setText(cooked_file); } else { - QMessageBox::warning(this, tr("Invalid"), tr("The file chosen does not seem to be an executable")); + QMessageBox::warning(this, tr("Invalid"), + tr("The file chosen does not seem to be an executable")); } } @@ -225,9 +232,11 @@ void SettingsDialog::proxyChanged(int) void SettingsDialog::refreshUpdateChannelList() { - // Stop listening for selection changes. It's going to change a lot while we update it and we don't need to update the + // Stop listening for selection changes. It's going to change a lot while we update it and + // we don't need to update the // description label constantly. - QObject::disconnect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChannelSelectionChanged(int))); + QObject::disconnect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this, + SLOT(updateChannelSelectionChanged(int))); QList channelList = MMC->updateChecker()->getChannelList(); ui->updateChannelComboBox->clear(); @@ -235,29 +244,34 @@ void SettingsDialog::refreshUpdateChannelList() for (int i = 0; i < channelList.count(); i++) { UpdateChecker::ChannelListEntry entry = channelList.at(i); - - // When it comes to selection, we'll rely on the indexes of a channel entry being the same in the + + // When it comes to selection, we'll rely on the indexes of a channel entry being the + // same in the // combo box as it is in the update checker's channel list. - // This probably isn't very safe, but the channel list doesn't change often enough (or at all) for + // This probably isn't very safe, but the channel list doesn't change often enough (or + // at all) for // this to be a big deal. Hope it doesn't break... ui->updateChannelComboBox->addItem(entry.name); - // If the update channel we just added was the selected one, set the current index in the combo box to it. + // If the update channel we just added was the selected one, set the current index in + // the combo box to it. if (entry.id == m_currentUpdateChannel) { QLOG_DEBUG() << "Selected index" << i << "channel id" << m_currentUpdateChannel; selection = i; } } - + ui->updateChannelComboBox->setCurrentIndex(selection); // Start listening for selection changes again and update the description label. - QObject::connect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChannelSelectionChanged(int))); + QObject::connect(ui->updateChannelComboBox, SIGNAL(currentIndexChanged(int)), this, + SLOT(updateChannelSelectionChanged(int))); refreshUpdateChannelDesc(); // Now that we've updated the channel list, we can enable the combo box. - // It starts off disabled so that if the channel list hasn't been loaded, it will be disabled. + // It starts off disabled so that if the channel list hasn't been loaded, it will be + // disabled. ui->updateChannelComboBox->setEnabled(true); } @@ -271,7 +285,7 @@ void SettingsDialog::refreshUpdateChannelDesc() // Get the channel list. QList channelList = MMC->updateChecker()->getChannelList(); int selectedIndex = ui->updateChannelComboBox->currentIndex(); - if(selectedIndex < 0) + if (selectedIndex < 0) { return; } @@ -291,7 +305,8 @@ void SettingsDialog::refreshUpdateChannelDesc() void SettingsDialog::applySettings(SettingsObject *s) { // Language - s->set("Language", ui->languageBox->itemData(ui->languageBox->currentIndex()).toLocale().bcp47Name()); + s->set("Language", + ui->languageBox->itemData(ui->languageBox->currentIndex()).toLocale().bcp47Name()); // Updates s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked()); @@ -311,7 +326,8 @@ void SettingsDialog::applySettings(SettingsObject *s) // Editors QString jsonEditor = ui->jsonEditorTextBox->text(); - if (!jsonEditor.isEmpty() && (!QFileInfo(jsonEditor).exists() || !QFileInfo(jsonEditor).isExecutable())) + if (!jsonEditor.isEmpty() && + (!QFileInfo(jsonEditor).exists() || !QFileInfo(jsonEditor).isExecutable())) { QString found = QStandardPaths::findExecutable(jsonEditor); if (!found.isEmpty()) @@ -332,10 +348,14 @@ void SettingsDialog::applySettings(SettingsObject *s) // Proxy QString proxyType = "None"; - if (ui->proxyDefaultBtn->isChecked()) proxyType = "Default"; - else if (ui->proxyNoneBtn->isChecked()) proxyType = "None"; - else if (ui->proxySOCKS5Btn->isChecked()) proxyType = "SOCKS5"; - else if (ui->proxyHTTPBtn->isChecked()) proxyType = "HTTP"; + if (ui->proxyDefaultBtn->isChecked()) + proxyType = "Default"; + else if (ui->proxyNoneBtn->isChecked()) + proxyType = "None"; + else if (ui->proxySOCKS5Btn->isChecked()) + proxyType = "SOCKS5"; + else if (ui->proxyHTTPBtn->isChecked()) + proxyType = "HTTP"; s->set("ProxyType", proxyType); s->set("ProxyAddr", ui->proxyAddrEdit->text()); @@ -386,11 +406,10 @@ void SettingsDialog::loadSettings(SettingsObject *s) QDir(MMC->root() + "/translations").entryList(QStringList() << "*.qm", QDir::Files)) { QLocale locale(lang.section(QRegExp("[_\.]"), 1)); - ui->languageBox->addItem( - QLocale::languageToString(locale.language()), - locale); + ui->languageBox->addItem(QLocale::languageToString(locale.language()), locale); } - ui->languageBox->setCurrentIndex(ui->languageBox->findData(QLocale(s->get("Language").toString()))); + ui->languageBox->setCurrentIndex( + ui->languageBox->findData(QLocale(s->get("Language").toString()))); // Updates ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool()); @@ -437,10 +456,14 @@ void SettingsDialog::loadSettings(SettingsObject *s) // Proxy QString proxyType = s->get("ProxyType").toString(); - if (proxyType == "Default") ui->proxyDefaultBtn->setChecked(true); - else if (proxyType == "None") ui->proxyNoneBtn->setChecked(true); - else if (proxyType == "SOCKS5") ui->proxySOCKS5Btn->setChecked(true); - else if (proxyType == "HTTP") ui->proxyHTTPBtn->setChecked(true); + if (proxyType == "Default") + ui->proxyDefaultBtn->setChecked(true); + else if (proxyType == "None") + ui->proxyNoneBtn->setChecked(true); + else if (proxyType == "SOCKS5") + ui->proxySOCKS5Btn->setChecked(true); + else if (proxyType == "HTTP") + ui->proxyHTTPBtn->setChecked(true); ui->proxyAddrEdit->setText(s->get("ProxyAddr").toString()); ui->proxyPortEdit->setValue(s->get("ProxyPort").value()); @@ -518,19 +541,28 @@ void SettingsDialog::checkFinished(JavaCheckResult result) void SettingsDialog::on_jprofilerPathBtn_clicked() { - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Directory"), - ui->jprofilerPathEdit->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->jprofilerPathEdit->setText(cooked_dir); - } - else + QString raw_dir = ui->jprofilerPathEdit->text(); + QString error; + do { - // FIXME: see below... - } + raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Directory"), raw_dir); + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = NormalizePath(raw_dir); + if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking JProfiler install:\n%1").arg(error)); + continue; + } + else + { + ui->jprofilerPathEdit->setText(cooked_dir); + break; + } + } while (1); } void SettingsDialog::on_jprofilerCheckBtn_clicked() { @@ -538,7 +570,7 @@ void SettingsDialog::on_jprofilerCheckBtn_clicked() if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) { QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); + tr("Error while checking JProfiler install:\n%1").arg(error)); } else { @@ -548,21 +580,28 @@ void SettingsDialog::on_jprofilerCheckBtn_clicked() void SettingsDialog::on_jvisualvmPathBtn_clicked() { - QString raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), - ui->jvisualvmPathEdit->text()); - QString cooked_path = NormalizePath(raw_dir); - QFileInfo finfo(cooked_path); - - // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_path.isEmpty() && finfo.isExecutable() && finfo.isFile()) - { - ui->jvisualvmPathEdit->setText(cooked_path); - } - else + QString raw_dir = ui->jvisualvmPathEdit->text(); + QString error; + do { - // FIXME: report error here, or run the checker instead of that condition above. - // ideally unify all the sanity checks and put them into the relevant classes - } + raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), raw_dir); + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = NormalizePath(raw_dir); + if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking MCEdit install:\n%1").arg(error)); + continue; + } + else + { + ui->jvisualvmPathEdit->setText(cooked_dir); + break; + } + } while (1); } void SettingsDialog::on_jvisualvmCheckBtn_clicked() { @@ -570,7 +609,7 @@ void SettingsDialog::on_jvisualvmCheckBtn_clicked() if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) { QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); + tr("Error while checking JVisualVM install:\n%1").arg(error)); } else { @@ -580,26 +619,37 @@ void SettingsDialog::on_jvisualvmCheckBtn_clicked() void SettingsDialog::on_mceditPathBtn_clicked() { - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Path"), - ui->mceditPathEdit->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->mceditPathEdit->setText(cooked_dir); - } + QString raw_dir = ui->mceditPathEdit->text(); + QString error; + do { - // FIXME: as above. - } + raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Path"), raw_dir); + if (raw_dir.isEmpty()) + { + break; + } + QString cooked_dir = NormalizePath(raw_dir); + if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) + { + QMessageBox::critical(this, tr("Error"), + tr("Error while checking MCEdit install:\n%1").arg(error)); + continue; + } + else + { + ui->mceditPathEdit->setText(cooked_dir); + break; + } + } while (1); } + void SettingsDialog::on_mceditCheckBtn_clicked() { QString error; if (!MMC->tools()["mcedit"]->check(ui->mceditPathEdit->text(), &error)) { QMessageBox::critical(this, tr("Error"), - tr("Error while checking MCEdit install:\n%1").arg(error)); + tr("Error while checking MCEdit install:\n%1").arg(error)); } else { diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 7d94446e..e8da8582 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -896,7 +896,7 @@ - + <html><head/><body><p><a href="http://www.ej-technologies.com/products/jprofiler/overview.html"><span style=" text-decoration: underline; color:#0000ff;">http://www.ej-technologies.com/products/jprofiler/overview.html</span></a></p></body></html> @@ -933,7 +933,7 @@ - + <html><head/><body><p><a href="http://visualvm.java.net/"><span style=" text-decoration: underline; color:#0000ff;">http://visualvm.java.net/</span></a></p></body></html> @@ -970,7 +970,7 @@ - + <html><head/><body><p><a href="http://www.mcedit.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.mcedit.net/</span></a></p></body></html> -- cgit v1.2.3 From 16d378687c24f9572b70c96ffd81e4b7f710777b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 16 Feb 2014 14:53:03 +0100 Subject: Fix some external tool related string sin the settings dialog. --- gui/dialogs/SettingsDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui') diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 4b0b117d..fd67b22f 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -593,7 +593,7 @@ void SettingsDialog::on_jvisualvmPathBtn_clicked() if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) { QMessageBox::critical(this, tr("Error"), - tr("Error while checking MCEdit install:\n%1").arg(error)); + tr("Error while checking JVisualVM install:\n%1").arg(error)); continue; } else @@ -623,7 +623,7 @@ void SettingsDialog::on_mceditPathBtn_clicked() QString error; do { - raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Path"), raw_dir); + raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Directory"), raw_dir); if (raw_dir.isEmpty()) { break; -- cgit v1.2.3 From a354e8bfae812b23b85b65c4a5b7e860cb18080c Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 21 Feb 2014 20:13:12 +0100 Subject: Fix MCEdit on OSX --- gui/dialogs/SettingsDialog.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gui') diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index fd67b22f..d79bb558 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -623,7 +623,12 @@ void SettingsDialog::on_mceditPathBtn_clicked() QString error; do { +#ifdef Q_OS_OSX +#warning stuff + raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir); +#else raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Directory"), raw_dir); +#endif if (raw_dir.isEmpty()) { break; -- cgit v1.2.3