Skip to content

Commit

Permalink
Implement openFileExplorerAndSelectFile for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Aug 3, 2018
1 parent 65ae32a commit 1fc6aab
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsmapsavedialog.cpp
Expand Up @@ -405,7 +405,7 @@ void QgsMapSaveDialog::onAccepted()
connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, [ = ]
{
QgisApp::instance()->messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved map to <a href=\"%1\">%2</a>" )
.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 )
{
Expand Down Expand Up @@ -456,7 +456,7 @@ void QgsMapSaveDialog::onAccepted()
connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, [ = ]
{
QgisApp::instance()->messageBar()->pushSuccess( tr( "Save as PDF" ), tr( "Successfully saved map to <a href=\"%1\">%2</a>" )
.arg( QUrl::fromLocalFile( QFileInfo( fileName ).path() ).toString(), QDir::toNativeSeparators( fileName ) ) );
.arg( QUrl::fromLocalFile( fileName ).toString(), QDir::toNativeSeparators( fileName ) ) );
} );
connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, [ = ]( int )
{
Expand Down
4 changes: 4 additions & 0 deletions src/native/CMakeLists.txt
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions src/native/linux/qgslinuxnative.cpp
Expand Up @@ -16,3 +16,28 @@
***************************************************************************/

#include "qgslinuxnative.h"

#include <QUrl>
#include <QString>
#include <QtDBus/QtDBus>
#include <QtDebug>

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 );
}
}
1 change: 1 addition & 0 deletions src/native/linux/qgslinuxnative.h
Expand Up @@ -23,6 +23,7 @@
class NATIVE_EXPORT QgsLinuxNative : public QgsNative
{
public:
void openFileExplorerAndSelectFile( const QString &path ) override;
};

#endif // QGSLINUXNATIVE_H

0 comments on commit 1fc6aab

Please sign in to comment.