summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-01-05 07:32:52 +0100
committerPetr Mrázek <peterix@gmail.com>2016-01-05 07:32:52 +0100
commit4d0caf6254fdb18f4626a3c7937e64422b40d40c (patch)
tree76b037c8f6b6c73f8438b85e8e05a2f59da89c17
parentd1e344f28f643c9fb0318feea0259be8ac72c8f7 (diff)
downloadMultiMC-4d0caf6254fdb18f4626a3c7937e64422b40d40c.tar
MultiMC-4d0caf6254fdb18f4626a3c7937e64422b40d40c.tar.gz
MultiMC-4d0caf6254fdb18f4626a3c7937e64422b40d40c.tar.lz
MultiMC-4d0caf6254fdb18f4626a3c7937e64422b40d40c.tar.xz
MultiMC-4d0caf6254fdb18f4626a3c7937e64422b40d40c.zip
GH-1389 wrap QDesktopServices and QProcess::startDetached
Essentially do not pass some environment variables to subprocesses: * LD_PRELOAD * LD_LIBRARY_PATH * LD_DEBUG * QT_PLUGIN_PATH * QT_FONTPATH
-rw-r--r--application/GuiUtil.cpp4
-rw-r--r--application/MainWindow.cpp32
-rw-r--r--application/MainWindow.h3
-rw-r--r--application/MultiMC.cpp8
-rw-r--r--application/dialogs/EditAccountDialog.cpp4
-rw-r--r--application/dialogs/ModEditDialogCommon.cpp2
-rw-r--r--application/dialogs/ModEditDialogCommon.h2
-rw-r--r--application/pages/LegacyJarModPage.cpp4
-rw-r--r--application/pages/ModFolderPage.cpp5
-rw-r--r--application/pages/ScreenshotsPage.cpp8
-rw-r--r--application/pages/WorldListPage.cpp7
-rw-r--r--application/widgets/PageContainer.cpp4
-rw-r--r--application/widgets/ServerStatus.cpp4
-rw-r--r--logic/CMakeLists.txt4
-rw-r--r--logic/DesktopServices.cpp149
-rw-r--r--logic/DesktopServices.h37
-rw-r--r--logic/FileSystem.cpp20
-rw-r--r--logic/FileSystem.h6
-rw-r--r--logic/tools/MCEditTool.cpp4
19 files changed, 235 insertions, 72 deletions
diff --git a/application/GuiUtil.cpp b/application/GuiUtil.cpp
index cc06d711..f10095c1 100644
--- a/application/GuiUtil.cpp
+++ b/application/GuiUtil.cpp
@@ -1,7 +1,6 @@
#include "GuiUtil.h"
#include <QClipboard>
-#include <QDesktopServices>
#include <QApplication>
#include <QFileDialog>
@@ -11,6 +10,7 @@
#include "MultiMC.h"
#include <settings/SettingsObject.h>
+#include <DesktopServices.h>
#include <BuildConfig.h>
void GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget)
@@ -42,7 +42,7 @@ void GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget)
{
const QString link = paste->pasteLink();
setClipboardText(link);
- QDesktopServices::openUrl(link);
+ DesktopServices::openUrl(link);
CustomMessageBox::selectable(
parentWidget, QObject::tr("Upload finished"),
QObject::tr("The <a href=\"%1\">link to the uploaded log</a> has been opened in "
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index fa756678..c977715b 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -26,7 +26,6 @@
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
-#include <QtGui/QDesktopServices>
#include <QtGui/QKeyEvent>
#include <QtWidgets/QAction>
@@ -69,6 +68,7 @@
#include <tools/BaseProfiler.h>
#include <updater/DownloadTask.h>
#include <updater/UpdateChecker.h>
+#include <DesktopServices.h>
#include "InstancePageProvider.h"
#include "InstanceProxyModel.h"
@@ -1197,7 +1197,7 @@ void MainWindow::on_actionAddInstance_triggered()
void MainWindow::on_actionREDDIT_triggered()
{
- openWebPage(QUrl("https://www.reddit.com/r/MultiMC/"));
+ DesktopServices::openUrl(QUrl("https://www.reddit.com/r/MultiMC/"));
}
void MainWindow::on_actionCopyInstance_triggered()
@@ -1312,7 +1312,7 @@ void MainWindow::on_actionChangeInstGroup_triggered()
void MainWindow::on_actionViewInstanceFolder_triggered()
{
QString str = MMC->settings()->get("InstanceDir").toString();
- FS::openDirInDefaultProgram(str);
+ DesktopServices::openDirectory(str);
}
void MainWindow::on_actionRefresh_triggered()
@@ -1322,7 +1322,7 @@ void MainWindow::on_actionRefresh_triggered()
void MainWindow::on_actionViewCentralModsFolder_triggered()
{
- FS::openDirInDefaultProgram(MMC->settings()->get("CentralModsDir").toString(), true);
+ DesktopServices::openDirectory(MMC->settings()->get("CentralModsDir").toString(), true);
}
void MainWindow::on_actionConfig_Folder_triggered()
@@ -1330,7 +1330,7 @@ void MainWindow::on_actionConfig_Folder_triggered()
if (m_selectedInstance)
{
QString str = m_selectedInstance->instanceConfigFolder();
- FS::openDirInDefaultProgram(QDir(str).absolutePath());
+ DesktopServices::openDirectory(QDir(str).absolutePath());
}
}
@@ -1384,26 +1384,30 @@ void MainWindow::on_actionManageAccounts_triggered()
void MainWindow::on_actionReportBug_triggered()
{
- openWebPage(QUrl("https://github.com/MultiMC/MultiMC5/issues"));
+ DesktopServices::openUrl(QUrl("https://github.com/MultiMC/MultiMC5/issues"));
}
void MainWindow::on_actionPatreon_triggered()
{
- openWebPage(QUrl("http://www.patreon.com/multimc"));
+ DesktopServices::openUrl(QUrl("http://www.patreon.com/multimc"));
}
void MainWindow::on_actionMoreNews_triggered()
{
- openWebPage(QUrl("http://multimc.org/posts.html"));
+ DesktopServices::openUrl(QUrl("http://multimc.org/posts.html"));
}
void MainWindow::newsButtonClicked()
{
QList<NewsEntryPtr> entries = m_newsChecker->getNewsEntries();
if (entries.count() > 0)
- openWebPage(QUrl(entries[0]->link));
+ {
+ DesktopServices::openUrl(QUrl(entries[0]->link));
+ }
else
- openWebPage(QUrl("http://multimc.org/posts.html"));
+ {
+ DesktopServices::openUrl(QUrl("http://multimc.org/posts.html"));
+ }
}
void MainWindow::on_actionAbout_triggered()
@@ -1469,7 +1473,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
if (m_selectedInstance)
{
QString str = m_selectedInstance->instanceRoot();
- FS::openDirInDefaultProgram(QDir(str).absolutePath());
+ DesktopServices::openDirectory(QDir(str).absolutePath());
}
}
@@ -1538,12 +1542,6 @@ void MainWindow::startTask(Task *task)
task->start();
}
-// BrowserDialog
-void MainWindow::openWebPage(QUrl url)
-{
- QDesktopServices::openUrl(url);
-}
-
void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (!current.isValid())
diff --git a/application/MainWindow.h b/application/MainWindow.h
index 0685c9f8..0a6167bc 100644
--- a/application/MainWindow.h
+++ b/application/MainWindow.h
@@ -166,9 +166,6 @@ private:
void finalizeInstance(InstancePtr inst);
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
- /// open a web page in the default browser
- void openWebPage(QUrl url);
-
private:
std::unique_ptr<Ui> ui;
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index a2a14506..fb82510d 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -17,7 +17,6 @@
#include <QLibraryInfo>
#include <QMessageBox>
#include <QStringList>
-#include <QDesktopServices>
#include <QDebug>
#include "InstanceList.h"
@@ -54,6 +53,7 @@
#include <Commandline.h>
#include <FileSystem.h>
+#include <DesktopServices.h>
using namespace Commandline;
@@ -932,12 +932,12 @@ bool MultiMC::openJsonEditor(const QString &filename)
const QString file = QDir::current().absoluteFilePath(filename);
if (m_settings->get("JsonEditor").toString().isEmpty())
{
- return QDesktopServices::openUrl(QUrl::fromLocalFile(file));
+ return DesktopServices::openUrl(QUrl::fromLocalFile(file));
}
else
{
- return QProcess::startDetached(m_settings->get("JsonEditor").toString(), QStringList()
- << file);
+ //return DesktopServices::openFile(m_settings->get("JsonEditor").toString(), file);
+ return DesktopServices::run(m_settings->get("JsonEditor").toString(), {});
}
}
diff --git a/application/dialogs/EditAccountDialog.cpp b/application/dialogs/EditAccountDialog.cpp
index 7c2ff981..f7e25f6f 100644
--- a/application/dialogs/EditAccountDialog.cpp
+++ b/application/dialogs/EditAccountDialog.cpp
@@ -15,7 +15,7 @@
#include "EditAccountDialog.h"
#include "ui_EditAccountDialog.h"
-#include <QDesktopServices>
+#include <DesktopServices.h>
#include <QUrl>
EditAccountDialog::EditAccountDialog(const QString &text, QWidget *parent, int flags)
@@ -37,7 +37,7 @@ EditAccountDialog::~EditAccountDialog()
void EditAccountDialog::on_label_linkActivated(const QString &link)
{
- QDesktopServices::openUrl(QUrl(link));
+ DesktopServices::openUrl(QUrl(link));
}
void EditAccountDialog::setUsername(const QString & user) const
diff --git a/application/dialogs/ModEditDialogCommon.cpp b/application/dialogs/ModEditDialogCommon.cpp
index 4a2115d8..4201bdad 100644
--- a/application/dialogs/ModEditDialogCommon.cpp
+++ b/application/dialogs/ModEditDialogCommon.cpp
@@ -28,7 +28,7 @@ void showWebsiteForMod(QWidget *parentDlg, Mod &m)
{
url = "http://" + url;
}
- QDesktopServices::openUrl(url);
+ DesktopServices::openUrl(url);
}
else
{
diff --git a/application/dialogs/ModEditDialogCommon.h b/application/dialogs/ModEditDialogCommon.h
index e2afb98a..fc5e3c2b 100644
--- a/application/dialogs/ModEditDialogCommon.h
+++ b/application/dialogs/ModEditDialogCommon.h
@@ -1,6 +1,6 @@
#pragma once
#include <QModelIndex>
-#include <QDesktopServices>
+#include <DesktopServices.h>
#include <QWidget>
#include <minecraft/Mod.h>
diff --git a/application/pages/LegacyJarModPage.cpp b/application/pages/LegacyJarModPage.cpp
index 2ff6b6de..b329ba70 100644
--- a/application/pages/LegacyJarModPage.cpp
+++ b/application/pages/LegacyJarModPage.cpp
@@ -25,7 +25,7 @@
#include "minecraft/ModList.h"
#include "minecraft/LegacyInstance.h"
#include "Env.h"
-#include <FileSystem.h>
+#include <DesktopServices.h>
#include "MultiMC.h"
#include <GuiUtil.h>
@@ -146,7 +146,7 @@ void LegacyJarModPage::on_rmJarBtn_clicked()
void LegacyJarModPage::on_viewJarBtn_clicked()
{
- FS::openDirInDefaultProgram(m_inst->jarModsDir(), true);
+ DesktopServices::openDirectory(m_inst->jarModsDir(), true);
}
void LegacyJarModPage::jarCurrent(QModelIndex current, QModelIndex previous)
diff --git a/application/pages/ModFolderPage.cpp b/application/pages/ModFolderPage.cpp
index 6791a59e..3c68b23f 100644
--- a/application/pages/ModFolderPage.cpp
+++ b/application/pages/ModFolderPage.cpp
@@ -19,7 +19,6 @@
#include <QMessageBox>
#include <QEvent>
#include <QKeyEvent>
-#include <QDesktopServices>
#include <QAbstractItemModel>
#include "MultiMC.h"
@@ -29,7 +28,7 @@
#include "minecraft/ModList.h"
#include "minecraft/Mod.h"
#include "minecraft/VersionFilterData.h"
-#include <FileSystem.h>
+#include <DesktopServices.h>
ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id,
QString iconName, QString displayName, QString helpPage,
@@ -162,7 +161,7 @@ void ModFolderPage::on_rmModBtn_clicked()
void ModFolderPage::on_viewModBtn_clicked()
{
- FS::openDirInDefaultProgram(m_mods->dir().absolutePath(), true);
+ DesktopServices::openDirectory(m_mods->dir().absolutePath(), true);
}
void ModFolderPage::modCurrent(const QModelIndex &current, const QModelIndex &previous)
diff --git a/application/pages/ScreenshotsPage.cpp b/application/pages/ScreenshotsPage.cpp
index 2b2fe31f..5b406f3d 100644
--- a/application/pages/ScreenshotsPage.cpp
+++ b/application/pages/ScreenshotsPage.cpp
@@ -12,7 +12,6 @@
#include <QEvent>
#include <QPainter>
#include <QClipboard>
-#include <QDesktopServices>
#include <QKeyEvent>
#include <MultiMC.h>
@@ -26,6 +25,7 @@
#include "RWStorage.h"
#include <FileSystem.h>
+#include <DesktopServices.h>
typedef RWStorage<QString, QIcon> SharedIconCache;
typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr;
@@ -271,12 +271,12 @@ void ScreenshotsPage::onItemActivated(QModelIndex index)
return;
auto info = m_model->fileInfo(index);
QString fileName = info.absoluteFilePath();
- FS::openFileInDefaultProgram(info.absoluteFilePath());
+ DesktopServices::openFile(info.absoluteFilePath());
}
void ScreenshotsPage::on_viewFolderBtn_clicked()
{
- FS::openDirInDefaultProgram(m_folder, true);
+ DesktopServices::openDirectory(m_folder, true);
}
void ScreenshotsPage::on_uploadBtn_clicked()
@@ -312,7 +312,7 @@ void ScreenshotsPage::on_uploadBtn_clicked()
auto link = QString("https://imgur.com/a/%1").arg(imgurAlbum->id());
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(link);
- QDesktopServices::openUrl(link);
+ DesktopServices::openUrl(link);
CustomMessageBox::selectable(
this, tr("Upload finished"),
tr("The <a href=\"%1\">link to the uploaded album</a> has been opened in the "
diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp
index 4e7eeedc..befb6b5e 100644
--- a/application/pages/WorldListPage.cpp
+++ b/application/pages/WorldListPage.cpp
@@ -16,7 +16,7 @@
#include "WorldListPage.h"
#include "ui_WorldListPage.h"
#include "minecraft/WorldList.h"
-#include <FileSystem.h>
+#include <DesktopServices.h>
#include "dialogs/ModEditDialogCommon.h"
#include <QEvent>
#include <QKeyEvent>
@@ -123,7 +123,7 @@ void WorldListPage::on_rmWorldBtn_clicked()
void WorldListPage::on_viewFolderBtn_clicked()
{
- FS::openDirInDefaultProgram(m_worlds->dir().absolutePath(), true);
+ DesktopServices::openDirectory(m_worlds->dir().absolutePath(), true);
}
QModelIndex WorldListPage::getSelectedWorld()
@@ -193,7 +193,8 @@ void WorldListPage::on_mcEditBtn_clicked()
if(program.size())
{
qint64 pid = 0;
- QProcess::startDetached(program, QStringList() << fullPath, mceditPath, &pid);
+
+ DesktopServices::openFile(program, fullPath, mceditPath, &pid);
if(pid == 0)
{
QMessageBox::warning(this->parentWidget(), tr("MCEdit failed to start!"), tr("MCEdit failed to start.\nIt may be necessary to reinstall it."));
diff --git a/application/widgets/PageContainer.cpp b/application/widgets/PageContainer.cpp
index 66d94e6c..90aad26e 100644
--- a/application/widgets/PageContainer.cpp
+++ b/application/widgets/PageContainer.cpp
@@ -25,13 +25,13 @@
#include <QLabel>
#include <QDialogButtonBox>
#include <QGridLayout>
-#include <QDesktopServices>
#include "MultiMC.h"
#include "settings/SettingsObject.h"
#include "widgets/IconLabel.h"
#include "PageContainer_p.h"
#include <MultiMC.h>
+#include <DesktopServices.h>
class PageEntryFilterModel : public QSortFilterProxyModel
{
@@ -195,7 +195,7 @@ void PageContainer::help()
QString pageId = m_currentPage->helpPage();
if (pageId.isEmpty())
return;
- QDesktopServices::openUrl(QUrl("https://github.com/MultiMC/MultiMC5/wiki/" + pageId));
+ DesktopServices::openUrl(QUrl("https://github.com/MultiMC/MultiMC5/wiki/" + pageId));
}
}
diff --git a/application/widgets/ServerStatus.cpp b/application/widgets/ServerStatus.cpp
index f0a7f97a..4602dde5 100644
--- a/application/widgets/ServerStatus.cpp
+++ b/application/widgets/ServerStatus.cpp
@@ -2,6 +2,7 @@
#include "LineSeparator.h"
#include "IconLabel.h"
#include "status/StatusChecker.h"
+#include <DesktopServices.h>
#include "MultiMC.h"
@@ -11,7 +12,6 @@
#include <QMap>
#include <QToolButton>
#include <QAction>
-#include <QDesktopServices>
class ClickableLabel : public QLabel
{
@@ -127,7 +127,7 @@ void ServerStatus::addStatus(QString key, QString name)
void ServerStatus::clicked()
{
- QDesktopServices::openUrl(QUrl("https://help.mojang.com/"));
+ DesktopServices::openUrl(QUrl("https://help.mojang.com/"));
}
void ServerStatus::setStatus(QString key, int value)
diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt
index 0398cffe..9a87dcab 100644
--- a/logic/CMakeLists.txt
+++ b/logic/CMakeLists.txt
@@ -32,8 +32,12 @@ set(LOGIC_SOURCES
# JSON parsing helpers
Json.h
Json.cpp
+
FileSystem.h
FileSystem.cpp
+ DesktopServices.h
+ DesktopServices.cpp
+
Exception.h
# RW lock protected map
diff --git a/logic/DesktopServices.cpp b/logic/DesktopServices.cpp
new file mode 100644
index 00000000..3154ea01
--- /dev/null
+++ b/logic/DesktopServices.cpp
@@ -0,0 +1,149 @@
+#include "DesktopServices.h"
+#include <QDir>
+#include <QDesktopServices>
+#include <QProcess>
+#include <QDebug>
+
+/**
+ * This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing.
+ */
+#if defined(Q_OS_LINUX)
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+template <typename T>
+bool IndirectOpen(T callable, qint64 *pid_forked = nullptr)
+{
+ auto pid = fork();
+ if(pid_forked)
+ {
+ if(pid > 0)
+ *pid_forked = pid;
+ else
+ *pid_forked = 0;
+ }
+ if(pid == -1)
+ {
+ qWarning() << "IndirectOpen failed to fork: " << errno;
+ return false;
+ }
+ // child - do the stuff
+ if(pid == 0)
+ {
+ // unset all this garbage so it doesn't get passed to the child process
+ qunsetenv("LD_PRELOAD");
+ qunsetenv("LD_LIBRARY_PATH");
+ qunsetenv("LD_DEBUG");
+ qunsetenv("QT_PLUGIN_PATH");
+ qunsetenv("QT_FONTPATH");
+
+ // open the URL
+ auto status = callable();
+
+ // detach from the parent process group.
+ setsid();
+
+ // die. now. do not clean up anything, it would just hang forever.
+ _exit(status ? 0 : 1);
+ }
+ else
+ {
+ //parent - assume it worked.
+ int status;
+ while (waitpid(pid, &status, 0))
+ {
+ if(WIFEXITED(status))
+ {
+ return WEXITSTATUS(status) == 0;
+ }
+ if(WIFSIGNALED(status))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+#endif
+
+namespace DesktopServices {
+bool openDirectory(const QString &path, bool ensureExists)
+{
+ qDebug() << "Opening directory" << path;
+ QDir parentPath;
+ QDir dir(path);
+ if (!dir.exists())
+ {
+ parentPath.mkpath(dir.absolutePath());
+ }
+ auto f = [&]()
+ {
+ return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
+ };
+#if defined(Q_OS_LINUX)
+ return IndirectOpen(f);
+#else
+ return f();
+#endif
+}
+
+bool openFile(const QString &path)
+{
+ qDebug() << "Opening file" << path;
+ auto f = [&]()
+ {
+ return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
+ };
+#if defined(Q_OS_LINUX)
+ return IndirectOpen(f);
+#else
+ return f();
+#endif
+}
+
+bool openFile(const QString &application, const QString &path, const QString &workingDirectory, qint64 *pid)
+{
+ qDebug() << "Opening file" << path << "using" << application;
+#if defined(Q_OS_LINUX)
+ // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
+ return IndirectOpen([&]()
+ {
+ return QProcess::startDetached(application, QStringList() << path, workingDirectory);
+ }, pid);
+#else
+ return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
+#endif
+}
+
+bool run(const QString &application, const QStringList &args, const QString &workingDirectory, qint64 *pid)
+{
+ qDebug() << "Running" << application << "with args" << args.join(' ');
+#if defined(Q_OS_LINUX)
+ // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
+ return IndirectOpen([&]()
+ {
+ return QProcess::startDetached(application, args, workingDirectory);
+ }, pid);
+#else
+ return QProcess::startDetached(application, args, workingDirectory, pid);
+#endif
+}
+
+bool openUrl(const QUrl &url)
+{
+ qDebug() << "Opening URL" << url.toString();
+ auto f = [&]()
+ {
+ return QDesktopServices::openUrl(url);
+ };
+#if defined(Q_OS_LINUX)
+ return IndirectOpen(f);
+#else
+ return f();
+#endif
+}
+
+}
diff --git a/logic/DesktopServices.h b/logic/DesktopServices.h
new file mode 100644
index 00000000..1e67e4cb
--- /dev/null
+++ b/logic/DesktopServices.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <QUrl>
+#include <QString>
+#include "multimc_logic_export.h"
+
+/**
+ * This wraps around QDesktopServices and adds workarounds where needed
+ * Use this instead of QDesktopServices!
+ */
+namespace DesktopServices
+{
+ /**
+ * Open a file in whatever application is applicable
+ */
+ MULTIMC_LOGIC_EXPORT bool openFile(const QString &path);
+
+ /**
+ * Open a file in the specified application
+ */
+ MULTIMC_LOGIC_EXPORT bool openFile(const QString &application, const QString &path, const QString & workingDirectory = QString(), qint64 *pid = 0);
+
+ /**
+ * Run an application
+ */
+ MULTIMC_LOGIC_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0);
+
+ /**
+ * Open a directory
+ */
+ MULTIMC_LOGIC_EXPORT bool openDirectory(const QString &path, bool ensureExists = false);
+
+ /**
+ * Open the URL, most likely in a browser. Maybe.
+ */
+ MULTIMC_LOGIC_EXPORT bool openUrl(const QUrl &url);
+};
diff --git a/logic/FileSystem.cpp b/logic/FileSystem.cpp
index 006356b3..049f1e38 100644
--- a/logic/FileSystem.cpp
+++ b/logic/FileSystem.cpp
@@ -6,8 +6,8 @@
#include <QSaveFile>
#include <QFileInfo>
#include <QDebug>
-#include <QDesktopServices>
#include <QUrl>
+#include <QStandardPaths>
namespace FS {
@@ -304,22 +304,6 @@ QString DirNameFromString(QString string, QString inDir)
return dirName;
}
-void openDirInDefaultProgram(QString path, bool ensureExists)
-{
- QDir parentPath;
- QDir dir(path);
- if (!dir.exists())
- {
- parentPath.mkpath(dir.absolutePath());
- }
- QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
-}
-
-void openFileInDefaultProgram(QString filename)
-{
- QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
-}
-
// Does the directory path contain any '!'? If yes, return true, otherwise false.
// (This is a problem for Java)
bool checkProblemticPathJava(QDir folder)
@@ -449,4 +433,4 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na
return false;
#endif
}
-} \ No newline at end of file
+}
diff --git a/logic/FileSystem.h b/logic/FileSystem.h
index 5e21375b..80637f90 100644
--- a/logic/FileSystem.h
+++ b/logic/FileSystem.h
@@ -110,12 +110,6 @@ MULTIMC_LOGIC_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar re
MULTIMC_LOGIC_EXPORT QString DirNameFromString(QString string, QString inDir = ".");
-/// Opens the given file in the default application.
-MULTIMC_LOGIC_EXPORT void openFileInDefaultProgram(QString filename);
-
-/// Opens the given directory in the default application.
-MULTIMC_LOGIC_EXPORT void openDirInDefaultProgram(QString dirpath, bool ensureExists = false);
-
/// Checks if the a given Path contains "!"
MULTIMC_LOGIC_EXPORT bool checkProblemticPathJava(QDir folder);
diff --git a/logic/tools/MCEditTool.cpp b/logic/tools/MCEditTool.cpp
index db45797f..f0f715c3 100644
--- a/logic/tools/MCEditTool.cpp
+++ b/logic/tools/MCEditTool.cpp
@@ -2,7 +2,6 @@
#include <QDir>
#include <QProcess>
-#include <QDesktopServices>
#include <QUrl>
// FIXME: mixing logic and UI!!!!
#include <QInputDialog>
@@ -11,6 +10,7 @@
#include "settings/SettingsObject.h"
#include "BaseInstance.h"
#include "minecraft/MinecraftInstance.h"
+#include <DesktopServices.h>
MCEditTool::MCEditTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent)
: BaseDetachedTool(settings, instance, parent)
@@ -84,7 +84,7 @@ void MCEditTool::runImpl()
#endif
if(program.size())
{
- QProcess::startDetached(program, QStringList() << save, mceditPath);
+ DesktopServices::openFile(program, save, mceditPath);
}
#endif
}