From 85b64ad76705cd152fb2b0525de75fe4e832c31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 2 Nov 2016 02:33:55 +0100 Subject: NOISSUE MCEdit integration - remove old 'tool', replace with Worlds --- application/MainWindow.cpp | 29 ++++++-------- application/MainWindow.h | 2 + application/MultiMC.cpp | 12 +++--- application/MultiMC.h | 14 ++++--- application/pages/WorldListPage.cpp | 54 ++++++++------------------ application/pages/global/ExternalToolsPage.cpp | 23 +++++------ 6 files changed, 53 insertions(+), 81 deletions(-) (limited to 'application') diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 6d88a14e..bf9da0dc 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -110,6 +110,7 @@ public: QAction *actionChangeInstIcon; QAction *actionEditInstNotes; QAction *actionEditInstance; + QAction *actionWorlds; QAction *actionViewSelectedInstFolder; QAction *actionDeleteInstance; QAction *actionConfig_Folder; @@ -187,6 +188,8 @@ public: actionEditInstNotes->setObjectName(QStringLiteral("actionEditInstNotes")); actionEditInstance = new QAction(MainWindow); actionEditInstance->setObjectName(QStringLiteral("actionEditInstance")); + actionWorlds = new QAction(MainWindow); + actionWorlds->setObjectName(QStringLiteral("actionWorlds")); actionViewSelectedInstFolder = new QAction(MainWindow); actionViewSelectedInstFolder->setObjectName(QStringLiteral("actionViewSelectedInstFolder")); actionDeleteInstance = new QAction(MainWindow); @@ -280,6 +283,7 @@ public: instanceToolBar->addAction(actionEditInstance); instanceToolBar->addAction(actionInstanceSettings); instanceToolBar->addAction(actionEditInstNotes); + instanceToolBar->addAction(actionWorlds); instanceToolBar->addAction(actionScreenshots); instanceToolBar->addSeparator(); instanceToolBar->addAction(actionViewSelectedInstFolder); @@ -330,6 +334,8 @@ public: actionChangeInstIcon->setToolTip(tr("Change the selected instance's icon.")); actionEditInstNotes->setText(tr("Edit Notes")); actionEditInstNotes->setToolTip(tr("Edit the notes for the selected instance.")); + actionWorlds->setText(tr("View Worlds")); + actionWorlds->setToolTip(tr("View the worlds of this instance.")); actionEditInstance->setText(tr("Edit Instance")); actionEditInstance->setToolTip(tr("Change the instance settings, mods and versions.")); actionViewSelectedInstFolder->setText(tr("Instance Folder")); @@ -690,24 +696,6 @@ void MainWindow::updateToolsMenu() }); } } - 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); } @@ -1250,6 +1238,11 @@ void MainWindow::on_actionEditInstNotes_triggered() MMC->showInstanceWindow(m_selectedInstance, "notes"); } +void MainWindow::on_actionWorlds_triggered() +{ + MMC->showInstanceWindow(m_selectedInstance, "worlds"); +} + void MainWindow::on_actionEditInstance_triggered() { MMC->showInstanceWindow(m_selectedInstance); diff --git a/application/MainWindow.h b/application/MainWindow.h index e499f162..506f7ee3 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -115,6 +115,8 @@ private slots: void on_actionEditInstNotes_triggered(); + void on_actionWorlds_triggered(); + void on_actionScreenshots_triggered(); void taskEnd(); diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 6c284b35..b3615580 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -271,12 +271,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) profiler->registerSettings(m_settings); } - //FIXME: what to do with these? - m_tools.insert("mcedit", std::shared_ptr(new MCEditFactory())); - for (auto tool : m_tools.values()) - { - tool->registerSettings(m_settings); - } + initMCEdit(); connect(this, SIGNAL(aboutToQuit()), SLOT(onExit())); @@ -628,6 +623,11 @@ void MultiMC::initGlobalSettings() } } +void MultiMC::initMCEdit() +{ + m_mcedit.reset(new MCEditTool(m_settings)); +} + std::shared_ptr MultiMC::lwjgllist() { if (!m_lwjgllist) diff --git a/application/MultiMC.h b/application/MultiMC.h index e7f41f18..4deb95d1 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -33,6 +33,7 @@ class BaseProfilerFactory; class BaseDetachedToolFactory; class TranslationDownloader; class ITheme; +class MCEditTool; #if defined(MMC) #undef MMC @@ -105,6 +106,11 @@ public: return m_icons; } + MCEditTool *mcedit() const + { + return m_mcedit.get(); + } + std::shared_ptr accounts() const { return m_accounts; @@ -120,11 +126,6 @@ public: return m_profilers; } - const QMap> &tools() const - { - return m_tools; - } - /// this is the root of the 'installation'. Used for automatic updates const QString &root() { @@ -166,6 +167,7 @@ private: void initNetwork(); void initInstances(); void initAccounts(); + void initMCEdit(); private: QDateTime startTime; @@ -186,9 +188,9 @@ private: std::shared_ptr m_translationChecker; std::shared_ptr m_globalSettingsProvider; std::map> m_themes; + std::unique_ptr m_mcedit; QMap> m_profilers; - QMap> m_tools; QString m_rootPath; Status m_status = MultiMC::Failed; diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp index fcef716b..a4f17744 100644 --- a/application/pages/WorldListPage.cpp +++ b/application/pages/WorldListPage.cpp @@ -24,10 +24,11 @@ #include #include #include - +#include #include "MultiMC.h" #include +#include WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, QString iconName, QString displayName, QString helpPage, @@ -148,7 +149,8 @@ void WorldListPage::on_copySeedBtn_clicked() void WorldListPage::on_mcEditBtn_clicked() { - const QString mceditPath = MMC->settings()->get("MCEditPath").toString(); + auto mcedit = MMC->mcedit(); + const QString mceditPath = mcedit->path(); QModelIndex index = getSelectedWorld(); @@ -162,49 +164,27 @@ void WorldListPage::on_mcEditBtn_clicked() auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString(); -#ifdef Q_OS_OSX - QProcess *process = new QProcess(); - connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), process, SLOT(deleteLater())); - process->setProgram(mceditPath); - process->setArguments(QStringList() << fullPath); - process->start(); -#else - QDir mceditDir(mceditPath); - QString program; - #ifdef Q_OS_LINUX - if (mceditDir.exists("mcedit.sh")) - { - program = mceditDir.absoluteFilePath("mcedit.sh"); - } - else if (mceditDir.exists("mcedit.py")) - { - program = mceditDir.absoluteFilePath("mcedit.py"); - } - #elif defined(Q_OS_WIN32) - if (mceditDir.exists("mcedit.exe")) - { - program = mceditDir.absoluteFilePath("mcedit.exe"); - } - else if (mceditDir.exists("mcedit2.exe")) - { - program = mceditDir.absoluteFilePath("mcedit2.exe"); - } - #endif + auto program = mcedit->getProgramPath(); if(program.size()) { - qint64 pid = 0; - - DesktopServices::openFile(program, fullPath, mceditPath, &pid); - if(pid == 0) + qint64 pid; + if(!QProcess::startDetached(program, QStringList() << fullPath, mceditPath, &pid)) { - QMessageBox::warning(this->parentWidget(), tr("MCEdit failed to start!"), tr("MCEdit failed to start.\nIt may be necessary to reinstall it.")); + QMessageBox::warning( + this->parentWidget(), + tr("MCEdit failed to start!"), + tr("MCEdit failed to start.\nIt may be necessary to reinstall it.") + ); } } else { - QMessageBox::warning(this->parentWidget(), tr("No MCEdit found or set up!"), tr("You do not have MCEdit set up or it was moved.\nYou can set it up in the global settings.")); + QMessageBox::warning( + this->parentWidget(), + tr("No MCEdit found or set up!"), + tr("You do not have MCEdit set up or it was moved.\nYou can set it up in the global settings.") + ); } -#endif } void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &previous) diff --git a/application/pages/global/ExternalToolsPage.cpp b/application/pages/global/ExternalToolsPage.cpp index e8091dee..4c3375c8 100644 --- a/application/pages/global/ExternalToolsPage.cpp +++ b/application/pages/global/ExternalToolsPage.cpp @@ -24,6 +24,7 @@ #include "tools/BaseProfiler.h" #include #include "MultiMC.h" +#include ExternalToolsPage::ExternalToolsPage(QWidget *parent) : QWidget(parent), @@ -93,8 +94,7 @@ void ExternalToolsPage::on_jprofilerPathBtn_clicked() QString cooked_dir = FS::NormalizePath(raw_dir); if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); + QMessageBox::critical(this, tr("Error"), tr("Error while checking JProfiler install:\n%1").arg(error)); continue; } else @@ -109,8 +109,7 @@ void ExternalToolsPage::on_jprofilerCheckBtn_clicked() QString error; if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JProfiler install:\n%1").arg(error)); + QMessageBox::critical(this, tr("Error"), tr("Error while checking JProfiler install:\n%1").arg(error)); } else { @@ -132,8 +131,7 @@ void ExternalToolsPage::on_jvisualvmPathBtn_clicked() QString cooked_dir = FS::NormalizePath(raw_dir); if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); + QMessageBox::critical(this, tr("Error"), tr("Error while checking JVisualVM install:\n%1").arg(error)); continue; } else @@ -148,8 +146,7 @@ void ExternalToolsPage::on_jvisualvmCheckBtn_clicked() QString error; if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking JVisualVM install:\n%1").arg(error)); + QMessageBox::critical(this, tr("Error"), tr("Error while checking JVisualVM install:\n%1").arg(error)); } else { @@ -174,10 +171,9 @@ void ExternalToolsPage::on_mceditPathBtn_clicked() break; } QString cooked_dir = FS::NormalizePath(raw_dir); - if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) + if (!MMC->mcedit()->check(cooked_dir, error)) { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking MCEdit install:\n%1").arg(error)); + QMessageBox::critical(this, tr("Error"), tr("Error while checking MCEdit install:\n%1").arg(error)); continue; } else @@ -190,10 +186,9 @@ void ExternalToolsPage::on_mceditPathBtn_clicked() void ExternalToolsPage::on_mceditCheckBtn_clicked() { QString error; - if (!MMC->tools()["mcedit"]->check(ui->mceditPathEdit->text(), &error)) + if (!!MMC->mcedit()->check(ui->mceditPathEdit->text(), error)) { - QMessageBox::critical(this, tr("Error"), - tr("Error while checking MCEdit install:\n%1").arg(error)); + QMessageBox::critical(this, tr("Error"), tr("Error while checking MCEdit install:\n%1").arg(error)); } else { -- cgit v1.2.3