mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-19 05:31:22 +00:00
Better show in folder in Windows / Linux.
Inspired by https://github.com/qbittorrent/qBittorrent.
This commit is contained in:
parent
291a6b73ab
commit
a7e695d914
@ -61,10 +61,32 @@ QByteArray EscapeShell(const QByteArray &content) {
|
|||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
void UnsafeShowInFolder(const QString &filepath) {
|
void UnsafeShowInFolder(const QString &filepath) {
|
||||||
Ui::hideLayer(true);
|
Ui::hideLayer(true); // Hide mediaview to make other apps visible.
|
||||||
auto result = system(("xdg-open " + internal::EscapeShell(QFile::encodeName(QFileInfo(filepath).absoluteDir().absolutePath()))).constData());
|
|
||||||
if (result) {
|
auto absolutePath = QFileInfo(filepath).absoluteFilePath();
|
||||||
LOG(("Failed to launch xdg-open"));
|
QProcess process;
|
||||||
|
process.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
||||||
|
process.waitForFinished();
|
||||||
|
auto output = QString::fromLatin1(process.readLine().simplified());
|
||||||
|
auto command = qsl("xdg-open");
|
||||||
|
auto arguments = QStringList();
|
||||||
|
if (output == qstr("dolphin.desktop") || output == qstr("org.kde.dolphin.desktop")) {
|
||||||
|
command = qsl("dolphin");
|
||||||
|
arguments << "--select" << absolutePath;
|
||||||
|
} else if (output == qstr("nautilus.desktop") || output == qstr("org.gnome.Nautilus.desktop") || output == qstr("nautilus-folder-handler.desktop")) {
|
||||||
|
command = qsl("nautilus");
|
||||||
|
arguments << "--no-desktop" << absolutePath;
|
||||||
|
} else if (output == qstr("nemo.desktop")) {
|
||||||
|
command = qsl("nemo");
|
||||||
|
arguments << "--no-desktop" << absolutePath;
|
||||||
|
} else if (output == qstr("konqueror.desktop") || output == qstr("kfmclient_dir.desktop")) {
|
||||||
|
command = qsl("konqueror");
|
||||||
|
arguments << "--select" << absolutePath;
|
||||||
|
} else {
|
||||||
|
arguments << QFileInfo(filepath).absoluteDir().absolutePath();
|
||||||
|
}
|
||||||
|
if (!process.startDetached(command, arguments)) {
|
||||||
|
LOG(("Failed to launch '%1 %2'").arg(command).arg(arguments.join(' ')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,9 +266,16 @@ void UnsafeLaunch(const QString &filepath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeShowInFolder(const QString &filepath) {
|
void UnsafeShowInFolder(const QString &filepath) {
|
||||||
auto pathEscaped = QDir::toNativeSeparators(filepath).replace('"', qsl("\"\""));
|
auto nativePath = QDir::toNativeSeparators(filepath);
|
||||||
|
auto wstringPath = nativePath.toStdWString();
|
||||||
|
if (auto pidl = ILCreateFromPathW(wstringPath.c_str())) {
|
||||||
|
SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
|
||||||
|
ILFree(pidl);
|
||||||
|
} else {
|
||||||
|
auto pathEscaped = nativePath.replace('"', qsl("\"\""));
|
||||||
auto wstringParam = (qstr("/select,") + pathEscaped).toStdWString();
|
auto wstringParam = (qstr("/select,") + pathEscaped).toStdWString();
|
||||||
ShellExecute(0, 0, L"explorer", wstringParam.c_str(), 0, SW_SHOWNORMAL);
|
ShellExecute(0, 0, L"explorer", wstringParam.c_str(), 0, SW_SHOWNORMAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostprocessDownloaded(const QString &filepath) {
|
void PostprocessDownloaded(const QString &filepath) {
|
||||||
|
Loading…
Reference in New Issue
Block a user