mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 22:18:05 -06:00
Avoid spawning another temporary event loop
And redirect stderr messages to console. PR #23344.
This commit is contained in:
@@ -175,44 +175,61 @@ void Utils::Gui::openFolderSelect(const Path &path)
|
|||||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||||
const int lineMaxLength = 64;
|
const int lineMaxLength = 64;
|
||||||
|
|
||||||
QProcess proc;
|
auto lookupProc = new QProcess();
|
||||||
proc.setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
lookupProc->setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||||
proc.start(u"xdg-mime"_s, {u"query"_s, u"default"_s, u"inode/directory"_s});
|
lookupProc->setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
proc.waitForFinished();
|
QObject::connect(lookupProc, &QProcess::finished, lookupProc
|
||||||
const auto output = QString::fromLocal8Bit(proc.readLine(lineMaxLength).simplified());
|
, [path, lookupProc]([[maybe_unused]] const int exitCode, [[maybe_unused]] const QProcess::ExitStatus exitStatus)
|
||||||
|
{
|
||||||
|
lookupProc->deleteLater();
|
||||||
|
|
||||||
|
const auto output = QString::fromLocal8Bit(lookupProc->readLine(lineMaxLength).simplified());
|
||||||
if ((output == u"dolphin.desktop") || (output == u"org.kde.dolphin.desktop"))
|
if ((output == u"dolphin.desktop") || (output == u"org.kde.dolphin.desktop"))
|
||||||
{
|
{
|
||||||
proc.startDetached(u"dolphin"_s, {u"--select"_s, path.toString()});
|
QProcess::startDetached(u"dolphin"_s, {u"--select"_s, path.toString()});
|
||||||
}
|
}
|
||||||
else if ((output == u"nautilus.desktop") || (output == u"org.gnome.Nautilus.desktop")
|
else if ((output == u"nautilus.desktop") || (output == u"org.gnome.Nautilus.desktop")
|
||||||
|| (output == u"nautilus-folder-handler.desktop"))
|
|| (output == u"nautilus-folder-handler.desktop"))
|
||||||
{
|
{
|
||||||
proc.start(u"nautilus"_s, {u"--version"_s});
|
auto deProcess = new QProcess();
|
||||||
proc.waitForFinished();
|
deProcess->setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||||
const auto nautilusVerStr = QString::fromLocal8Bit(proc.readLine(lineMaxLength)).remove(QRegularExpression(u"[^0-9.]"_s));
|
deProcess->setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
QObject::connect(deProcess, &QProcess::finished, deProcess
|
||||||
|
, [deProcess, path]([[maybe_unused]] const int exitCode, [[maybe_unused]] const QProcess::ExitStatus exitStatus)
|
||||||
|
{
|
||||||
|
deProcess->deleteLater();
|
||||||
|
|
||||||
|
const auto nautilusVerStr = QString::fromLocal8Bit(deProcess->readLine(lineMaxLength))
|
||||||
|
.remove(QRegularExpression(u"[^0-9.]"_s));
|
||||||
using NautilusVersion = Utils::Version<3>;
|
using NautilusVersion = Utils::Version<3>;
|
||||||
|
const QString pathParam = (Fs::isDir(path) ? path.parentPath() : path).toString();
|
||||||
|
|
||||||
if (NautilusVersion::fromString(nautilusVerStr, {1, 0, 0}) > NautilusVersion(3, 28, 0))
|
if (NautilusVersion::fromString(nautilusVerStr, {1, 0, 0}) > NautilusVersion(3, 28, 0))
|
||||||
proc.startDetached(u"nautilus"_s, {(Fs::isDir(path) ? path.parentPath() : path).toString()});
|
QProcess::startDetached(u"nautilus"_s, {pathParam});
|
||||||
else
|
else
|
||||||
proc.startDetached(u"nautilus"_s, {u"--no-desktop"_s, (Fs::isDir(path) ? path.parentPath() : path).toString()});
|
QProcess::startDetached(u"nautilus"_s, {u"--no-desktop"_s, pathParam});
|
||||||
|
});
|
||||||
|
deProcess->start(u"nautilus"_s, {u"--version"_s});
|
||||||
}
|
}
|
||||||
else if (output == u"nemo.desktop")
|
else if (output == u"nemo.desktop")
|
||||||
{
|
{
|
||||||
proc.startDetached(u"nemo"_s, {u"--no-desktop"_s, (Fs::isDir(path) ? path.parentPath() : path).toString()});
|
QProcess::startDetached(u"nemo"_s, {u"--no-desktop"_s, (Fs::isDir(path) ? path.parentPath() : path).toString()});
|
||||||
}
|
}
|
||||||
else if ((output == u"konqueror.desktop") || (output == u"kfmclient_dir.desktop"))
|
else if ((output == u"konqueror.desktop") || (output == u"kfmclient_dir.desktop"))
|
||||||
{
|
{
|
||||||
proc.startDetached(u"konqueror"_s, {u"--select"_s, path.toString()});
|
QProcess::startDetached(u"konqueror"_s, {u"--select"_s, path.toString()});
|
||||||
}
|
}
|
||||||
else if (output == u"thunar.desktop")
|
else if (output == u"thunar.desktop")
|
||||||
{
|
{
|
||||||
proc.startDetached(u"thunar"_s, {path.toString()});
|
QProcess::startDetached(u"thunar"_s, {path.toString()});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003
|
// "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003
|
||||||
openPath(path.parentPath());
|
openPath(path.parentPath());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
lookupProc->start(u"xdg-mime"_s, {u"query"_s, u"default"_s, u"inode/directory"_s});
|
||||||
#else
|
#else
|
||||||
openPath(path.parentPath());
|
openPath(path.parentPath());
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user