Skip to content

Commit aa42b86

Browse files
committedOct 26, 2018
Add native platform method to show file/folder properties, implement
for linux
1 parent d34fe6b commit aa42b86

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed
 

‎src/gui/qgsbrowserdockwidget.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "qgsbrowserproxymodel.h"
3636
#include "qgsgui.h"
3737
#include "qgswindowmanagerinterface.h"
38+
#include "qgsnative.h"
3839

3940
// browser layer properties dialog
4041
#include "qgsapplication.h"
@@ -221,12 +222,24 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
221222
menu->addAction( tr( "Remove Favorite" ), this, SLOT( removeFavorite() ) );
222223
menu->addSeparator();
223224
}
224-
menu->addAction( tr( "Properties…" ), this, SLOT( showProperties() ) );
225225
menu->addAction( tr( "Hide from Browser" ), this, SLOT( hideItem() ) );
226226
QAction *action = menu->addAction( tr( "Fast Scan this Directory" ), this, SLOT( toggleFastScan() ) );
227227
action->setCheckable( true );
228228
action->setChecked( settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
229229
QStringList() ).toStringList().contains( item->path() ) );
230+
231+
menu->addAction( tr( "Properties…" ), this, SLOT( showProperties() ) );
232+
if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeFilePropertiesDialog )
233+
{
234+
if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item ) )
235+
{
236+
QAction *action = menu->addAction( tr( "Directory Properties…" ) );
237+
connect( action, &QAction::triggered, dirItem, [ dirItem ]
238+
{
239+
QgsGui::nativePlatformInterface()->showFileProperties( dirItem->dirPath() );
240+
} );
241+
}
242+
}
230243
}
231244
else if ( item->type() == QgsDataItem::Layer )
232245
{
@@ -270,7 +283,15 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
270283
}
271284

272285
menu->addAction( tr( "Add Selected Layer(s) to Canvas" ), this, SLOT( addSelectedLayers() ) );
273-
menu->addAction( tr( "Properties…" ), this, SLOT( showProperties() ) );
286+
menu->addAction( tr( "Layer Properties…" ), this, SLOT( showProperties() ) );
287+
if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeFilePropertiesDialog )
288+
{
289+
QAction *action = menu->addAction( tr( "File Properties…" ) );
290+
connect( action, &QAction::triggered, this, [ = ]
291+
{
292+
QgsGui::nativePlatformInterface()->showFileProperties( item->path() );
293+
} );
294+
}
274295
}
275296
else if ( item->type() == QgsDataItem::Favorites )
276297
{

‎src/native/linux/qgslinuxnative.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
QgsNative::Capabilities QgsLinuxNative::capabilities() const
2828
{
29-
return NativeDesktopNotifications;
29+
return NativeDesktopNotifications | NativeFilePropertiesDialog;
3030
}
3131

3232
void QgsLinuxNative::initializeMainWindow( QWindow *,
@@ -58,6 +58,26 @@ void QgsLinuxNative::openFileExplorerAndSelectFile( const QString &path )
5858
}
5959
}
6060

61+
void QgsLinuxNative::showFileProperties( const QString &path )
62+
{
63+
if ( !QDBusConnection::sessionBus().isConnected() )
64+
{
65+
QgsNative::showFileProperties( path );
66+
return;
67+
}
68+
69+
QDBusInterface iface( QStringLiteral( "org.freedesktop.FileManager1" ),
70+
QStringLiteral( "/org/freedesktop/FileManager1" ),
71+
QStringLiteral( "org.freedesktop.FileManager1" ),
72+
QDBusConnection::sessionBus() );
73+
74+
iface.call( QDBus::NoBlock, QStringLiteral( "ShowItemProperties" ), QStringList( QUrl::fromLocalFile( path ).toString() ), QStringLiteral( "QGIS" ) );
75+
if ( iface.lastError().type() != QDBusError::NoError )
76+
{
77+
QgsNative::showFileProperties( path );
78+
}
79+
}
80+
6181
void QgsLinuxNative::showUndefinedApplicationProgress()
6282
{
6383
const QVariantMap properties

‎src/native/linux/qgslinuxnative.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class NATIVE_EXPORT QgsLinuxNative : public QgsNative
3939
const QString &organizationName,
4040
const QString &version ) override;
4141
void openFileExplorerAndSelectFile( const QString &path ) override;
42+
void showFileProperties( const QString &path ) override;
4243
void showUndefinedApplicationProgress() override;
4344
void setApplicationProgress( double progress ) override;
4445
void hideApplicationProgress() override;

‎src/native/qgsnative.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ void QgsNative::openFileExplorerAndSelectFile( const QString &path )
4848
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
4949
}
5050

51+
void QgsNative::showFileProperties( const QString & )
52+
{
53+
54+
}
55+
5156
void QgsNative::showUndefinedApplicationProgress()
5257
{
5358

‎src/native/qgsnative.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class NATIVE_EXPORT QgsNative : public QObject
4444
enum Capability
4545
{
4646
NativeDesktopNotifications = 1 << 1, //!< Native desktop notifications are supported. See showDesktopNotification().
47+
NativeFilePropertiesDialog = 1 << 2, //!< Platform can show a native "file" (or folder) properties dialog.
4748
};
4849
Q_DECLARE_FLAGS( Capabilities, Capability )
4950

@@ -91,6 +92,16 @@ class NATIVE_EXPORT QgsNative : public QObject
9192
*/
9293
virtual void openFileExplorerAndSelectFile( const QString &path );
9394

95+
/**
96+
* Opens the desktop explorer file (or folder) properties dialog, for the given \a path.
97+
*
98+
* The default implementation does nothing. Platforms which implement this interface should
99+
* return the QgsNative::NativeFilePropertiesDialog capability.
100+
*
101+
* \since QGIS 3.6
102+
*/
103+
virtual void showFileProperties( const QString &path );
104+
94105
/**
95106
* Shows the application progress report, using an "undefined" total
96107
* type progress (i.e. the platform's way of showing that a task

0 commit comments

Comments
 (0)
Please sign in to comment.