feat: open folder will also select file on linux

This commit is contained in:
Gary Wang 2022-10-29 23:35:30 +08:00
parent a24c246fc7
commit b83de962cb
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
3 changed files with 785 additions and 755 deletions

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
- name: Get build dept. - name: Get build dept.
run: | run: |
sudo apt update sudo apt update
@ -24,7 +24,7 @@ jobs:
run: | run: |
cd build cd build
sudo apt install ./*.deb sudo apt install ./*.deb
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
with: with:
name: ubuntu-20.04-deb-package name: ubuntu-20.04-deb-package
path: build/*.deb path: build/*.deb

View File

@ -17,7 +17,10 @@ set (QT_MINIMUM_VERSION "5.10")
option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON) option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON)
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets Svg LinguistTools) find_package(Qt5 ${QT_MINIMUM_VERSION} REQUIRED
COMPONENTS Widgets Svg LinguistTools
OPTIONAL_COMPONENTS DBus
)
if (EXIV2_METADATA_SUPPORT) if (EXIV2_METADATA_SUPPORT)
find_package(LibExiv2) find_package(LibExiv2)
@ -113,6 +116,15 @@ if (LibExiv2_FOUND)
) )
endif () endif ()
if (Qt5DBus_FOUND)
target_link_libraries (${EXE_NAME}
Qt5::DBus
)
target_compile_definitions(${EXE_NAME} PRIVATE
HAVE_QTDBUS
)
endif()
# Extra build settings # Extra build settings
if (WIN32) if (WIN32)
set_property ( set_property (

View File

@ -36,6 +36,10 @@
#include <QProcess> #include <QProcess>
#include <QDesktopServices> #include <QDesktopServices>
#ifdef HAVE_QTDBUS
#include <QDBusInterface>
#endif // HAVE_QTDBUS
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: FramelessWindow(parent) : FramelessWindow(parent)
, m_am(new ActionManager) , m_am(new ActionManager)
@ -738,11 +742,25 @@ void MainWindow::on_actionLocateInFileManager_triggered()
QFileInfo fileInfo(currentFileUrl.toLocalFile()); QFileInfo fileInfo(currentFileUrl.toLocalFile());
if (!fileInfo.exists()) return; if (!fileInfo.exists()) return;
QUrl && folderUrl = QUrl::fromLocalFile(fileInfo.absolutePath());
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
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)
// Use https://www.freedesktop.org/wiki/Specifications/file-manager-interface/ if possible
QDBusInterface fm1Iface(QStringLiteral("org.freedesktop.FileManager1"),
QStringLiteral("/org/freedesktop/FileManager1"),
QStringLiteral("org.freedesktop.FileManager1"));
if (!fm1Iface.isValid()) {
QDesktopServices::openUrl(folderUrl);
return;
}
fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", {
QStringList{currentFileUrl.toString()},
QString()
});
#else #else
// maybe use https://www.freedesktop.org/wiki/Specifications/file-manager-interface/ for linux? QDesktopServices::openUrl(folderUrl);
QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.absolutePath()));
#endif // Q_OS_WIN #endif // Q_OS_WIN
} }