From 1fc6aabdcd15e4f5db4da8590968ec6c8fd689f8 Mon Sep 17 00:00:00 2001 From: nirvn Date: Fri, 3 Aug 2018 11:48:00 +0700 Subject: [PATCH] Implement openFileExplorerAndSelectFile for Linux --- src/app/qgsmapsavedialog.cpp | 4 ++-- src/native/CMakeLists.txt | 4 ++++ src/native/linux/qgslinuxnative.cpp | 25 +++++++++++++++++++++++++ src/native/linux/qgslinuxnative.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/app/qgsmapsavedialog.cpp b/src/app/qgsmapsavedialog.cpp index eb156c6d9b3..d14a6ed0757 100644 --- a/src/app/qgsmapsavedialog.cpp +++ b/src/app/qgsmapsavedialog.cpp @@ -405,7 +405,7 @@ void QgsMapSaveDialog::onAccepted() connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, [ = ] { QgisApp::instance()->messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved map to %2" ) - .arg( QUrl::fromLocalFile( QFileInfo( fileNameAndFilter.first ).path() ).toString(), QDir::toNativeSeparators( fileNameAndFilter.first ) ) ); + .arg( QUrl::fromLocalFile( fileNameAndFilter.first ).toString(), QDir::toNativeSeparators( fileNameAndFilter.first ) ) ); } ); connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, [ = ]( int error ) { @@ -456,7 +456,7 @@ void QgsMapSaveDialog::onAccepted() connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, [ = ] { QgisApp::instance()->messageBar()->pushSuccess( tr( "Save as PDF" ), tr( "Successfully saved map to %2" ) - .arg( QUrl::fromLocalFile( QFileInfo( fileName ).path() ).toString(), QDir::toNativeSeparators( fileName ) ) ); + .arg( QUrl::fromLocalFile( fileName ).toString(), QDir::toNativeSeparators( fileName ) ) ); } ); connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, [ = ]( int ) { diff --git a/src/native/CMakeLists.txt b/src/native/CMakeLists.txt index a621d063907..3e8f889bebf 100644 --- a/src/native/CMakeLists.txt +++ b/src/native/CMakeLists.txt @@ -137,6 +137,10 @@ TARGET_LINK_LIBRARIES(qgis_native "${NATIVE_LINK_LIBS}" ) +IF (UNIX) + TARGET_LINK_LIBRARIES(qgis_native Qt5DBus) +ENDIF (UNIX) + IF (WIN32) TARGET_LINK_LIBRARIES(qgis_native shell32) ENDIF (WIN32) diff --git a/src/native/linux/qgslinuxnative.cpp b/src/native/linux/qgslinuxnative.cpp index 621b521c8e2..ee70ce7ba4f 100644 --- a/src/native/linux/qgslinuxnative.cpp +++ b/src/native/linux/qgslinuxnative.cpp @@ -16,3 +16,28 @@ ***************************************************************************/ #include "qgslinuxnative.h" + +#include +#include +#include +#include + +void QgsLinuxNative::openFileExplorerAndSelectFile( const QString &path ) +{ + if ( !QDBusConnection::sessionBus().isConnected() ) + { + QgsNative::openFileExplorerAndSelectFile( path ); + return; + } + + QDBusInterface iface( QStringLiteral( "org.freedesktop.FileManager1" ), + QStringLiteral( "/org/freedesktop/FileManager1" ), + QStringLiteral( "org.freedesktop.FileManager1" ), + QDBusConnection::sessionBus() ); + + iface.call( QDBus::NoBlock, QStringLiteral( "ShowItems" ), QStringList( QUrl::fromLocalFile( path ).toString() ), QStringLiteral( "QGIS" ) ); + if ( iface.lastError().type() != QDBusError::NoError ) + { + QgsNative::openFileExplorerAndSelectFile( path ); + } +} diff --git a/src/native/linux/qgslinuxnative.h b/src/native/linux/qgslinuxnative.h index 519e44ee32b..a1fc8f796d6 100644 --- a/src/native/linux/qgslinuxnative.h +++ b/src/native/linux/qgslinuxnative.h @@ -23,6 +23,7 @@ class NATIVE_EXPORT QgsLinuxNative : public QgsNative { public: + void openFileExplorerAndSelectFile( const QString &path ) override; }; #endif // QGSLINUXNATIVE_H