Skip to content
Permalink
Browse files

Add native platform method to show file/folder properties, implement

for linux
  • Loading branch information
nyalldawson committed Oct 10, 2018
1 parent d34fe6b commit aa42b8689caffa96854284b2317a408af89f822c
@@ -35,6 +35,7 @@
#include "qgsbrowserproxymodel.h"
#include "qgsgui.h"
#include "qgswindowmanagerinterface.h"
#include "qgsnative.h"

// browser layer properties dialog
#include "qgsapplication.h"
@@ -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 )
{
@@ -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 )
{
@@ -26,7 +26,7 @@

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

void QgsLinuxNative::initializeMainWindow( QWindow *,
@@ -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
@@ -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;
@@ -48,6 +48,11 @@ void QgsNative::openFileExplorerAndSelectFile( const QString &path )
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
}

void QgsNative::showFileProperties( const QString & )
{

}

void QgsNative::showUndefinedApplicationProgress()
{

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

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

0 comments on commit aa42b86

Please sign in to comment.
You can’t perform that action at this time.