mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Refactor
This commit is contained in:
parent
8742d7aa45
commit
bb956b8453
@ -572,65 +572,58 @@ void Utils::Misc::openPath(const QString &absolutePath)
|
|||||||
void Utils::Misc::openFolderSelect(const QString &absolutePath)
|
void Utils::Misc::openFolderSelect(const QString &absolutePath)
|
||||||
{
|
{
|
||||||
const QString path = Utils::Fs::fromNativePath(absolutePath);
|
const QString path = Utils::Fs::fromNativePath(absolutePath);
|
||||||
#ifdef Q_OS_WIN
|
// If the item to select doesn't exist, try to open its parent
|
||||||
if (QFileInfo(path).exists()) {
|
if (!QFileInfo(path).exists()) {
|
||||||
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
|
|
||||||
// Dir separators MUST be win-style slashes
|
|
||||||
|
|
||||||
// QProcess::startDetached() has an obscure bug. If the path has
|
|
||||||
// no spaces and a comma(and maybe other special characters) it doesn't
|
|
||||||
// get wrapped in quotes. So explorer.exe can't find the correct path and
|
|
||||||
// displays the default one. If we wrap the path in quotes and pass it to
|
|
||||||
// QProcess::startDetached() explorer.exe still shows the default path. In
|
|
||||||
// this case QProcess::startDetached() probably puts its own quotes around ours.
|
|
||||||
|
|
||||||
STARTUPINFO startupInfo;
|
|
||||||
::ZeroMemory(&startupInfo, sizeof(startupInfo));
|
|
||||||
startupInfo.cb = sizeof(startupInfo);
|
|
||||||
|
|
||||||
PROCESS_INFORMATION processInfo;
|
|
||||||
::ZeroMemory(&processInfo, sizeof(processInfo));
|
|
||||||
|
|
||||||
QString cmd = QString("explorer.exe /select,\"%1\"").arg(Utils::Fs::toNativePath(absolutePath));
|
|
||||||
LPWSTR lpCmd = new WCHAR[cmd.size() + 1];
|
|
||||||
cmd.toWCharArray(lpCmd);
|
|
||||||
lpCmd[cmd.size()] = 0;
|
|
||||||
|
|
||||||
bool ret = ::CreateProcessW(NULL, lpCmd, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo);
|
|
||||||
delete [] lpCmd;
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
::CloseHandle(processInfo.hProcess);
|
|
||||||
::CloseHandle(processInfo.hThread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// If the item to select doesn't exist, try to open its parent
|
|
||||||
openPath(path.left(path.lastIndexOf("/")));
|
openPath(path.left(path.lastIndexOf("/")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
|
||||||
|
// Dir separators MUST be win-style slashes
|
||||||
|
|
||||||
|
// QProcess::startDetached() has an obscure bug. If the path has
|
||||||
|
// no spaces and a comma(and maybe other special characters) it doesn't
|
||||||
|
// get wrapped in quotes. So explorer.exe can't find the correct path and
|
||||||
|
// displays the default one. If we wrap the path in quotes and pass it to
|
||||||
|
// QProcess::startDetached() explorer.exe still shows the default path. In
|
||||||
|
// this case QProcess::startDetached() probably puts its own quotes around ours.
|
||||||
|
|
||||||
|
STARTUPINFO startupInfo;
|
||||||
|
::ZeroMemory(&startupInfo, sizeof(startupInfo));
|
||||||
|
startupInfo.cb = sizeof(startupInfo);
|
||||||
|
|
||||||
|
PROCESS_INFORMATION processInfo;
|
||||||
|
::ZeroMemory(&processInfo, sizeof(processInfo));
|
||||||
|
|
||||||
|
QString cmd = QString("explorer.exe /select,\"%1\"").arg(Utils::Fs::toNativePath(absolutePath));
|
||||||
|
LPWSTR lpCmd = new WCHAR[cmd.size() + 1];
|
||||||
|
cmd.toWCharArray(lpCmd);
|
||||||
|
lpCmd[cmd.size()] = 0;
|
||||||
|
|
||||||
|
bool ret = ::CreateProcessW(NULL, lpCmd, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo);
|
||||||
|
delete [] lpCmd;
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
::CloseHandle(processInfo.hProcess);
|
||||||
|
::CloseHandle(processInfo.hThread);
|
||||||
}
|
}
|
||||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||||
if (QFileInfo(path).exists()) {
|
QProcess proc;
|
||||||
QProcess proc;
|
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
||||||
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
proc.waitForFinished();
|
||||||
proc.waitForFinished();
|
QString output = proc.readLine().simplified();
|
||||||
QString output = proc.readLine().simplified();
|
if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop"))
|
||||||
if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop"))
|
proc.startDetached("dolphin", QStringList() << "--select" << Utils::Fs::toNativePath(path));
|
||||||
proc.startDetached("dolphin", QStringList() << "--select" << Utils::Fs::toNativePath(path));
|
else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop")
|
||||||
else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop")
|
|| (output == "nautilus-folder-handler.desktop"))
|
||||||
|| (output == "nautilus-folder-handler.desktop"))
|
proc.startDetached("nautilus", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path));
|
||||||
proc.startDetached("nautilus", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path));
|
else if (output == "nemo.desktop")
|
||||||
else if (output == "nemo.desktop")
|
proc.startDetached("nemo", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path));
|
||||||
proc.startDetached("nemo", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path));
|
else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop"))
|
||||||
else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop"))
|
proc.startDetached("konqueror", QStringList() << "--select" << Utils::Fs::toNativePath(path));
|
||||||
proc.startDetached("konqueror", QStringList() << "--select" << Utils::Fs::toNativePath(path));
|
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.left(path.lastIndexOf("/")));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// If the item to select doesn't exist, try to open its parent
|
|
||||||
openPath(path.left(path.lastIndexOf("/")));
|
openPath(path.left(path.lastIndexOf("/")));
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
openPath(path.left(path.lastIndexOf("/")));
|
openPath(path.left(path.lastIndexOf("/")));
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user