Skip to content

Commit 1fc6aab

Browse files
committedAug 3, 2018
Implement openFileExplorerAndSelectFile for Linux
1 parent 65ae32a commit 1fc6aab

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed
 

‎src/app/qgsmapsavedialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void QgsMapSaveDialog::onAccepted()
405405
connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, [ = ]
406406
{
407407
QgisApp::instance()->messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved map to <a href=\"%1\">%2</a>" )
408-
.arg( QUrl::fromLocalFile( QFileInfo( fileNameAndFilter.first ).path() ).toString(), QDir::toNativeSeparators( fileNameAndFilter.first ) ) );
408+
.arg( QUrl::fromLocalFile( fileNameAndFilter.first ).toString(), QDir::toNativeSeparators( fileNameAndFilter.first ) ) );
409409
} );
410410
connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, [ = ]( int error )
411411
{
@@ -456,7 +456,7 @@ void QgsMapSaveDialog::onAccepted()
456456
connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, [ = ]
457457
{
458458
QgisApp::instance()->messageBar()->pushSuccess( tr( "Save as PDF" ), tr( "Successfully saved map to <a href=\"%1\">%2</a>" )
459-
.arg( QUrl::fromLocalFile( QFileInfo( fileName ).path() ).toString(), QDir::toNativeSeparators( fileName ) ) );
459+
.arg( QUrl::fromLocalFile( fileName ).toString(), QDir::toNativeSeparators( fileName ) ) );
460460
} );
461461
connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, [ = ]( int )
462462
{

‎src/native/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ TARGET_LINK_LIBRARIES(qgis_native
137137
"${NATIVE_LINK_LIBS}"
138138
)
139139

140+
IF (UNIX)
141+
TARGET_LINK_LIBRARIES(qgis_native Qt5DBus)
142+
ENDIF (UNIX)
143+
140144
IF (WIN32)
141145
TARGET_LINK_LIBRARIES(qgis_native shell32)
142146
ENDIF (WIN32)

‎src/native/linux/qgslinuxnative.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,28 @@
1616
***************************************************************************/
1717

1818
#include "qgslinuxnative.h"
19+
20+
#include <QUrl>
21+
#include <QString>
22+
#include <QtDBus/QtDBus>
23+
#include <QtDebug>
24+
25+
void QgsLinuxNative::openFileExplorerAndSelectFile( const QString &path )
26+
{
27+
if ( !QDBusConnection::sessionBus().isConnected() )
28+
{
29+
QgsNative::openFileExplorerAndSelectFile( path );
30+
return;
31+
}
32+
33+
QDBusInterface iface( QStringLiteral( "org.freedesktop.FileManager1" ),
34+
QStringLiteral( "/org/freedesktop/FileManager1" ),
35+
QStringLiteral( "org.freedesktop.FileManager1" ),
36+
QDBusConnection::sessionBus() );
37+
38+
iface.call( QDBus::NoBlock, QStringLiteral( "ShowItems" ), QStringList( QUrl::fromLocalFile( path ).toString() ), QStringLiteral( "QGIS" ) );
39+
if ( iface.lastError().type() != QDBusError::NoError )
40+
{
41+
QgsNative::openFileExplorerAndSelectFile( path );
42+
}
43+
}

‎src/native/linux/qgslinuxnative.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class NATIVE_EXPORT QgsLinuxNative : public QgsNative
2424
{
2525
public:
26+
void openFileExplorerAndSelectFile( const QString &path ) override;
2627
};
2728

2829
#endif // QGSLINUXNATIVE_H

0 commit comments

Comments
 (0)
Please sign in to comment.