From c7601d7a4398970c293e65a75a1760a77ee07a6d Mon Sep 17 00:00:00 2001 From: Evgeny Lensky Date: Wed, 16 May 2018 02:03:12 +0700 Subject: [PATCH] Fix open destination folder with Nautilus > 3.28 Closes #8923. --- src/base/utils/misc.cpp | 42 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 1d3ec29fb..a06a22b1d 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -65,6 +65,8 @@ #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #include #include +#include +#include "base/utils/version.h" #endif #endif @@ -269,12 +271,12 @@ QString Utils::Misc::pythonExecutable() * On Unix-Like Systems python2 and python3 should always exist * http://legacy.python.org/dev/peps/pep-0394/ */ - pythonProc.start("python3", QStringList() << "--version", QIODevice::ReadOnly); + pythonProc.start("python3", {"--version"}, QIODevice::ReadOnly); if (pythonProc.waitForFinished() && (pythonProc.exitCode() == 0)) { executable = "python3"; return executable; } - pythonProc.start("python2", QStringList() << "--version", QIODevice::ReadOnly); + pythonProc.start("python2", {"--version"}, QIODevice::ReadOnly); if (pythonProc.waitForFinished() && (pythonProc.exitCode() == 0)) { executable = "python2"; return executable; @@ -282,7 +284,7 @@ QString Utils::Misc::pythonExecutable() #endif // Look for "python" in Windows and in UNIX if "python2" and "python3" are // not detected. - pythonProc.start("python", QStringList() << "--version", QIODevice::ReadOnly); + pythonProc.start("python", {"--version"}, QIODevice::ReadOnly); if (pythonProc.waitForFinished() && (pythonProc.exitCode() == 0)) executable = "python"; else @@ -303,7 +305,7 @@ QString Utils::Misc::pythonVersionComplete() if (pythonExecutable().isEmpty()) return version; QProcess pythonProc; - pythonProc.start(pythonExecutable(), QStringList() << "--version", QIODevice::ReadOnly); + pythonProc.start(pythonExecutable(), {"--version"}, QIODevice::ReadOnly); if (pythonProc.waitForFinished() && (pythonProc.exitCode() == 0)) { QByteArray output = pythonProc.readAllStandardOutput(); if (output.isEmpty()) @@ -619,21 +621,33 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath) ::CoUninitialize(); #elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC) QProcess proc; - proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory"); + proc.start("xdg-mime", {"query", "default", "inode/directory"}); proc.waitForFinished(); QString output = proc.readLine().simplified(); - if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop")) - proc.startDetached("dolphin", QStringList() << "--select" << Utils::Fs::toNativePath(path)); + if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop")) { + proc.startDetached("dolphin", {"--select", Utils::Fs::toNativePath(path)}); + } else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop") - || (output == "nautilus-folder-handler.desktop")) - proc.startDetached("nautilus", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); - else if (output == "nemo.desktop") - proc.startDetached("nemo", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); - else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) - proc.startDetached("konqueror", QStringList() << "--select" << Utils::Fs::toNativePath(path)); - else + || (output == "nautilus-folder-handler.desktop")) { + proc.start("nautilus", {"--version"}); + proc.waitForFinished(); + const QString nautilusVerStr = QString(proc.readLine()).remove(QRegExp("[^0-9.]")); + using NautilusVersion = Utils::Version; + if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28}) + proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)}); + else + proc.startDetached("nautilus", {"--no-desktop", Utils::Fs::toNativePath(path)}); + } + else if (output == "nemo.desktop") { + proc.startDetached("nemo", {"--no-desktop", Utils::Fs::toNativePath(path)}); + } + else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) { + proc.startDetached("konqueror", {"--select", Utils::Fs::toNativePath(path)}); + } + else { // "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003 openPath(path.left(path.lastIndexOf("/"))); + } #else openPath(path.left(path.lastIndexOf("/"))); #endif