Skip to content

Commit

Permalink
Add native platform method to show file/folder properties, implement
Browse files Browse the repository at this point in the history
for linux
  • Loading branch information
nyalldawson committed Oct 26, 2018
1 parent d34fe6b commit aa42b86
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
25 changes: 23 additions & 2 deletions src/gui/qgsbrowserdockwidget.cpp
Expand Up @@ -35,6 +35,7 @@
#include "qgsbrowserproxymodel.h"
#include "qgsgui.h"
#include "qgswindowmanagerinterface.h"
#include "qgsnative.h"

// browser layer properties dialog
#include "qgsapplication.h"
Expand Down Expand Up @@ -221,12 +222,24 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
menu->addAction( tr( "Remove Favorite" ), this, SLOT( removeFavorite() ) );
menu->addSeparator();
}
menu->addAction( tr( "Properties…" ), this, SLOT( showProperties() ) );
menu->addAction( tr( "Hide from Browser" ), this, SLOT( hideItem() ) );
QAction *action = menu->addAction( tr( "Fast Scan this Directory" ), this, SLOT( toggleFastScan() ) );
action->setCheckable( true );
action->setChecked( settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ),
QStringList() ).toStringList().contains( item->path() ) );

menu->addAction( tr( "Properties…" ), this, SLOT( showProperties() ) );
if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeFilePropertiesDialog )
{
if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item ) )
{
QAction *action = menu->addAction( tr( "Directory Properties…" ) );
connect( action, &QAction::triggered, dirItem, [ dirItem ]
{
QgsGui::nativePlatformInterface()->showFileProperties( dirItem->dirPath() );
} );
}
}
}
else if ( item->type() == QgsDataItem::Layer )
{
Expand Down Expand Up @@ -270,7 +283,15 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
}

menu->addAction( tr( "Add Selected Layer(s) to Canvas" ), this, SLOT( addSelectedLayers() ) );
menu->addAction( tr( "Properties…" ), this, SLOT( showProperties() ) );
menu->addAction( tr( "Layer Properties…" ), this, SLOT( showProperties() ) );
if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeFilePropertiesDialog )
{
QAction *action = menu->addAction( tr( "File Properties…" ) );
connect( action, &QAction::triggered, this, [ = ]
{
QgsGui::nativePlatformInterface()->showFileProperties( item->path() );
} );
}
}
else if ( item->type() == QgsDataItem::Favorites )
{
Expand Down
22 changes: 21 additions & 1 deletion src/native/linux/qgslinuxnative.cpp
Expand Up @@ -26,7 +26,7 @@

QgsNative::Capabilities QgsLinuxNative::capabilities() const
{
return NativeDesktopNotifications;
return NativeDesktopNotifications | NativeFilePropertiesDialog;
}

void QgsLinuxNative::initializeMainWindow( QWindow *,
Expand Down Expand Up @@ -58,6 +58,26 @@ void QgsLinuxNative::openFileExplorerAndSelectFile( const QString &path )
}
}

void QgsLinuxNative::showFileProperties( const QString &path )
{
if ( !QDBusConnection::sessionBus().isConnected() )
{
QgsNative::showFileProperties( path );
return;
}

QDBusInterface iface( QStringLiteral( "org.freedesktop.FileManager1" ),
QStringLiteral( "/org/freedesktop/FileManager1" ),
QStringLiteral( "org.freedesktop.FileManager1" ),
QDBusConnection::sessionBus() );

iface.call( QDBus::NoBlock, QStringLiteral( "ShowItemProperties" ), QStringList( QUrl::fromLocalFile( path ).toString() ), QStringLiteral( "QGIS" ) );
if ( iface.lastError().type() != QDBusError::NoError )
{
QgsNative::showFileProperties( path );
}
}

void QgsLinuxNative::showUndefinedApplicationProgress()
{
const QVariantMap properties
Expand Down
1 change: 1 addition & 0 deletions src/native/linux/qgslinuxnative.h
Expand Up @@ -39,6 +39,7 @@ class NATIVE_EXPORT QgsLinuxNative : public QgsNative
const QString &organizationName,
const QString &version ) override;
void openFileExplorerAndSelectFile( const QString &path ) override;
void showFileProperties( const QString &path ) override;
void showUndefinedApplicationProgress() override;
void setApplicationProgress( double progress ) override;
void hideApplicationProgress() override;
Expand Down
5 changes: 5 additions & 0 deletions src/native/qgsnative.cpp
Expand Up @@ -48,6 +48,11 @@ void QgsNative::openFileExplorerAndSelectFile( const QString &path )
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
}

void QgsNative::showFileProperties( const QString & )
{

}

void QgsNative::showUndefinedApplicationProgress()
{

Expand Down
11 changes: 11 additions & 0 deletions src/native/qgsnative.h
Expand Up @@ -44,6 +44,7 @@ class NATIVE_EXPORT QgsNative : public QObject
enum Capability
{
NativeDesktopNotifications = 1 << 1, //!< Native desktop notifications are supported. See showDesktopNotification().
NativeFilePropertiesDialog = 1 << 2, //!< Platform can show a native "file" (or folder) properties dialog.
};
Q_DECLARE_FLAGS( Capabilities, Capability )

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

/**
* Opens the desktop explorer file (or folder) properties dialog, for the given \a path.
*
* The default implementation does nothing. Platforms which implement this interface should
* return the QgsNative::NativeFilePropertiesDialog capability.
*
* \since QGIS 3.6
*/
virtual void showFileProperties( const QString &path );

/**
* Shows the application progress report, using an "undefined" total
* type progress (i.e. the platform's way of showing that a task
Expand Down

0 comments on commit aa42b86

Please sign in to comment.