Implement openFileExplorerAndSelectFile for Linux

This commit is contained in:
nirvn 2018-08-03 11:48:00 +07:00 committed by Mathieu Pellerin
parent 65ae32aadd
commit 1fc6aabdcd
4 changed files with 32 additions and 2 deletions

View File

@ -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 )
{
@ -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 )
{

View File

@ -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)

View File

@ -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 );
}
}

View File

@ -23,6 +23,7 @@
class NATIVE_EXPORT QgsLinuxNative : public QgsNative
{
public:
void openFileExplorerAndSelectFile( const QString &path ) override;
};
#endif // QGSLINUXNATIVE_H