fix: proper check for filemanager1 dbus

This commit is contained in:
Gary Wang 2022-11-01 20:58:48 +08:00
parent 51e49ab8a8
commit d1fbf64011
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760

View File

@ -38,6 +38,7 @@
#ifdef HAVE_QTDBUS #ifdef HAVE_QTDBUS
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusConnectionInterface>
#endif // HAVE_QTDBUS #endif // HAVE_QTDBUS
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
@ -748,13 +749,18 @@ void MainWindow::on_actionLocateInFileManager_triggered()
QProcess::startDetached("explorer", QStringList() << "/select," << QDir::toNativeSeparators(fileInfo.absoluteFilePath())); QProcess::startDetached("explorer", QStringList() << "/select," << QDir::toNativeSeparators(fileInfo.absoluteFilePath()));
#elif defined(Q_OS_LINUX) and defined(HAVE_QTDBUS) #elif defined(Q_OS_LINUX) and defined(HAVE_QTDBUS)
// Use https://www.freedesktop.org/wiki/Specifications/file-manager-interface/ if possible // Use https://www.freedesktop.org/wiki/Specifications/file-manager-interface/ if possible
const QDBusConnectionInterface * dbusIface = QDBusConnection::sessionBus().interface();
if (!dbusIface || !dbusIface->isServiceRegistered(QLatin1String("org.freedesktop.FileManager1"))) {
QDesktopServices::openUrl(folderUrl);
return;
}
QDBusInterface fm1Iface(QStringLiteral("org.freedesktop.FileManager1"), QDBusInterface fm1Iface(QStringLiteral("org.freedesktop.FileManager1"),
QStringLiteral("/org/freedesktop/FileManager1"), QStringLiteral("/org/freedesktop/FileManager1"),
QStringLiteral("org.freedesktop.FileManager1")); QStringLiteral("org.freedesktop.FileManager1"));
fm1Iface.setTimeout(500); fm1Iface.setTimeout(1000);
fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", { fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", {
QStringList{currentFileUrl.toString()}, QStringList{currentFileUrl.toString()},
QString::number(QDateTime::currentSecsSinceEpoch()) QString()
}); });
if (fm1Iface.lastError().isValid()) { if (fm1Iface.lastError().isValid()) {
QDesktopServices::openUrl(folderUrl); QDesktopServices::openUrl(folderUrl);