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
This commit is contained in:
ebbit1q 2020-07-16 11:22:24 +02:00 committed by GitHub
parent faecfd65fe
commit a76a3e5db6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,6 +50,7 @@
#include <QApplication> #include <QApplication>
#include <QCloseEvent> #include <QCloseEvent>
#include <QDateTime> #include <QDateTime>
#include <QDesktopServices>
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
@ -752,10 +753,8 @@ void MainWindow::createMenus()
dbMenu->addAction(aManageSets); dbMenu->addAction(aManageSets);
dbMenu->addAction(aEditTokens); dbMenu->addAction(aEditTokens);
dbMenu->addSeparator(); dbMenu->addSeparator();
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
dbMenu->addAction(aOpenCustomFolder); dbMenu->addAction(aOpenCustomFolder);
dbMenu->addAction(aOpenCustomsetsFolder); dbMenu->addAction(aOpenCustomsetsFolder);
#endif
dbMenu->addAction(aAddCustomSet); dbMenu->addAction(aAddCustomSet);
helpMenu = menuBar()->addMenu(QString()); helpMenu = menuBar()->addMenu(QString());
@ -1194,38 +1193,13 @@ void MainWindow::notifyUserAboutUpdate()
void MainWindow::actOpenCustomFolder() void MainWindow::actOpenCustomFolder()
{ {
QString dir = settingsCache->getCustomPicsPath(); QString dir = settingsCache->getCustomPicsPath();
#if defined(Q_OS_MAC) QDesktopServices::openUrl(QUrl::fromLocalFile(dir));
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
} }
void MainWindow::actOpenCustomsetsFolder() void MainWindow::actOpenCustomsetsFolder()
{ {
QString dir = settingsCache->getCustomCardDatabasePath(); QString dir = settingsCache->getCustomCardDatabasePath();
QDesktopServices::openUrl(QUrl::fromLocalFile(dir));
#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
} }
void MainWindow::actAddCustomSet() void MainWindow::actAddCustomSet()