2021-01-18 12:58:54 +05:30
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
2014-07-16 03:43:40 +05:30
|
|
|
*
|
|
|
|
* 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 "ExternalToolsPage.h"
|
|
|
|
#include "ui_ExternalToolsPage.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFileDialog>
|
2014-07-21 03:17:46 +05:30
|
|
|
#include <QStandardPaths>
|
2018-06-01 19:50:33 +05:30
|
|
|
#include <QTabBar>
|
2014-07-16 03:43:40 +05:30
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "settings/SettingsObject.h"
|
|
|
|
#include "tools/BaseProfiler.h"
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2021-11-20 20:52:22 +05:30
|
|
|
#include "Application.h"
|
2016-11-02 07:03:55 +05:30
|
|
|
#include <tools/MCEditTool.h>
|
2014-07-16 03:43:40 +05:30
|
|
|
|
|
|
|
ExternalToolsPage::ExternalToolsPage(QWidget *parent) :
|
2018-07-15 18:21:05 +05:30
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::ExternalToolsPage)
|
2014-07-16 03:43:40 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->setupUi(this);
|
|
|
|
ui->tabWidget->tabBar()->hide();
|
2014-07-21 03:17:46 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
ui->jsonEditorTextBox->setClearButtonEnabled(true);
|
|
|
|
#endif
|
2014-07-16 03:43:40 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->mceditLink->setOpenExternalLinks(true);
|
|
|
|
ui->jvisualvmLink->setOpenExternalLinks(true);
|
|
|
|
ui->jprofilerLink->setOpenExternalLinks(true);
|
|
|
|
loadSettings();
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
ExternalToolsPage::~ExternalToolsPage()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
delete ui;
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
|
2014-07-21 03:17:46 +05:30
|
|
|
void ExternalToolsPage::loadSettings()
|
2014-07-16 03:43:40 +05:30
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
auto s = APPLICATION->settings();
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->jprofilerPathEdit->setText(s->get("JProfilerPath").toString());
|
|
|
|
ui->jvisualvmPathEdit->setText(s->get("JVisualVMPath").toString());
|
|
|
|
ui->mceditPathEdit->setText(s->get("MCEditPath").toString());
|
2014-07-21 03:17:46 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// Editors
|
|
|
|
ui->jsonEditorTextBox->setText(s->get("JsonEditor").toString());
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
2014-07-21 03:17:46 +05:30
|
|
|
void ExternalToolsPage::applySettings()
|
2014-07-16 03:43:40 +05:30
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
auto s = APPLICATION->settings();
|
2018-07-15 18:21:05 +05:30
|
|
|
|
|
|
|
s->set("JProfilerPath", ui->jprofilerPathEdit->text());
|
|
|
|
s->set("JVisualVMPath", ui->jvisualvmPathEdit->text());
|
|
|
|
s->set("MCEditPath", ui->mceditPathEdit->text());
|
|
|
|
|
|
|
|
// Editors
|
|
|
|
QString jsonEditor = ui->jsonEditorTextBox->text();
|
|
|
|
if (!jsonEditor.isEmpty() &&
|
|
|
|
(!QFileInfo(jsonEditor).exists() || !QFileInfo(jsonEditor).isExecutable()))
|
|
|
|
{
|
|
|
|
QString found = QStandardPaths::findExecutable(jsonEditor);
|
|
|
|
if (!found.isEmpty())
|
|
|
|
{
|
|
|
|
jsonEditor = found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->set("JsonEditor", jsonEditor);
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalToolsPage::on_jprofilerPathBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString raw_dir = ui->jprofilerPathEdit->text();
|
|
|
|
QString error;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
raw_dir = QFileDialog::getExistingDirectory(this, tr("JProfiler Folder"), raw_dir);
|
|
|
|
if (raw_dir.isEmpty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QString cooked_dir = FS::NormalizePath(raw_dir);
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->profilers()["jprofiler"]->check(cooked_dir, &error))
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
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);
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
void ExternalToolsPage::on_jprofilerCheckBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString error;
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error))
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
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"));
|
|
|
|
}
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalToolsPage::on_jvisualvmPathBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString raw_dir = ui->jvisualvmPathEdit->text();
|
|
|
|
QString error;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
raw_dir = QFileDialog::getOpenFileName(this, tr("JVisualVM Executable"), raw_dir);
|
|
|
|
if (raw_dir.isEmpty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QString cooked_dir = FS::NormalizePath(raw_dir);
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->profilers()["jvisualvm"]->check(cooked_dir, &error))
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Error while checking JVisualVM install:\n%1").arg(error));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->jvisualvmPathEdit->setText(cooked_dir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
void ExternalToolsPage::on_jvisualvmCheckBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString error;
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error))
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
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"));
|
|
|
|
}
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalToolsPage::on_mceditPathBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString raw_dir = ui->mceditPathEdit->text();
|
|
|
|
QString error;
|
|
|
|
do
|
|
|
|
{
|
2014-07-16 03:43:40 +05:30
|
|
|
#ifdef Q_OS_OSX
|
2018-07-15 18:21:05 +05:30
|
|
|
raw_dir = QFileDialog::getOpenFileName(this, tr("MCEdit Application"), raw_dir);
|
2014-07-16 03:43:40 +05:30
|
|
|
#else
|
2018-07-15 18:21:05 +05:30
|
|
|
raw_dir = QFileDialog::getExistingDirectory(this, tr("MCEdit Folder"), raw_dir);
|
2014-07-16 03:43:40 +05:30
|
|
|
#endif
|
2018-07-15 18:21:05 +05:30
|
|
|
if (raw_dir.isEmpty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QString cooked_dir = FS::NormalizePath(raw_dir);
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->mcedit()->check(cooked_dir, error))
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
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);
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
|
|
|
void ExternalToolsPage::on_mceditCheckBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString error;
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->mcedit()->check(ui->mceditPathEdit->text(), error))
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
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"));
|
|
|
|
}
|
2014-07-16 03:43:40 +05:30
|
|
|
}
|
2014-07-21 03:17:46 +05:30
|
|
|
|
|
|
|
void ExternalToolsPage::on_jsonEditorBrowseBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString raw_file = QFileDialog::getOpenFileName(
|
|
|
|
this, tr("JSON Editor"),
|
|
|
|
ui->jsonEditorTextBox->text().isEmpty()
|
2014-07-21 03:17:46 +05:30
|
|
|
#if defined(Q_OS_LINUX)
|
2018-07-15 18:21:05 +05:30
|
|
|
? QString("/usr/bin")
|
2014-07-21 03:17:46 +05:30
|
|
|
#else
|
2018-07-15 18:21:05 +05:30
|
|
|
? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first()
|
2014-07-21 03:17:46 +05:30
|
|
|
#endif
|
2018-07-15 18:21:05 +05:30
|
|
|
: ui->jsonEditorTextBox->text());
|
|
|
|
|
|
|
|
if (raw_file.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString cooked_file = FS::NormalizePath(raw_file);
|
|
|
|
|
|
|
|
// it has to exist and be an executable
|
|
|
|
if (QFileInfo(cooked_file).exists() && QFileInfo(cooked_file).isExecutable())
|
|
|
|
{
|
|
|
|
ui->jsonEditorTextBox->setText(cooked_file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Invalid"),
|
|
|
|
tr("The file chosen does not seem to be an executable"));
|
|
|
|
}
|
2014-07-21 03:17:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool ExternalToolsPage::apply()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applySettings();
|
|
|
|
return true;
|
2014-07-21 03:17:46 +05:30
|
|
|
}
|