From a76a3e5db69ddd343bc8b63bc506e8fc452c59df Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Thu, 16 Jul 2020 11:22:24 +0200 Subject: [PATCH] Change method of opening directories to be the same for all oses, including linux (#4046) * add opening directory in file browser to linux this uses QDesktopServices to open the url "file://[location]" by default this is "file://$HOME/.local/share/Cockatrice/Cockatrice/pics/CUSTOM" any distro that has a file browser should have an accompanying mime type specifying the file handler for the file:// protocol using the inode/directory mime type see https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html if a user were to have removed their mime database this will not work and it will fail with nothing but a log message, this would be rare and not worth checking in my opinion * make opening directories the same for all oses * sort headers --- cockatrice/src/window_main.cpp | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 5b4f90f6..e08504af 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -752,10 +753,8 @@ void MainWindow::createMenus() dbMenu->addAction(aManageSets); dbMenu->addAction(aEditTokens); dbMenu->addSeparator(); -#if defined(Q_OS_WIN) || defined(Q_OS_MAC) dbMenu->addAction(aOpenCustomFolder); dbMenu->addAction(aOpenCustomsetsFolder); -#endif dbMenu->addAction(aAddCustomSet); helpMenu = menuBar()->addMenu(QString()); @@ -1194,38 +1193,13 @@ void MainWindow::notifyUserAboutUpdate() void MainWindow::actOpenCustomFolder() { QString dir = settingsCache->getCustomPicsPath(); -#if defined(Q_OS_MAC) - QStringList scriptArgs; - scriptArgs << QLatin1String("-e"); - scriptArgs << QString::fromLatin1(R"(tell application "Finder" to open POSIX file "%1")").arg(dir); - scriptArgs << QLatin1String("-e"); - scriptArgs << QLatin1String("tell application \"Finder\" to activate"); - - QProcess::execute("/usr/bin/osascript", scriptArgs); -#elif defined(Q_OS_WIN) - QStringList args; - args << QDir::toNativeSeparators(dir); - QProcess::startDetached("explorer", args); -#endif + QDesktopServices::openUrl(QUrl::fromLocalFile(dir)); } void MainWindow::actOpenCustomsetsFolder() { QString dir = settingsCache->getCustomCardDatabasePath(); - -#if defined(Q_OS_MAC) - QStringList scriptArgs; - scriptArgs << QLatin1String("-e"); - scriptArgs << QString::fromLatin1(R"(tell application "Finder" to open POSIX file "%1")").arg(dir); - scriptArgs << QLatin1String("-e"); - scriptArgs << QLatin1String("tell application \"Finder\" to activate"); - - QProcess::execute("/usr/bin/osascript", scriptArgs); -#elif defined(Q_OS_WIN) - QStringList args; - args << QDir::toNativeSeparators(dir); - QProcess::startDetached("explorer", args); -#endif + QDesktopServices::openUrl(QUrl::fromLocalFile(dir)); } void MainWindow::actAddCustomSet()