Skip to content
Permalink
Browse files

[needs-docs] Implement native file properties support for Windows

Allows opening the native file explorer file/directory properties
dialog for browser items
  • Loading branch information
nyalldawson committed Nov 11, 2018
1 parent 9f1d00d commit c79a9a1954759a7725e95ead91cccdf7b25b3c47
Showing with 47 additions and 8 deletions.
  1. +44 −7 src/native/win/qgswinnative.cpp
  2. +3 −1 src/native/win/qgswinnative.h
@@ -29,6 +29,20 @@
#include <QtWinExtras/QWinJumpListCategory>
#include "wintoastlib.h"
#include <Dbt.h>
#include <memory>


struct ITEMIDLISTDeleter
{
void operator()( ITEMIDLIST *pidl )
{
ILFree( pidl );
}
};

using ITEMIDLIST_unique_ptr = std::unique_ptr< ITEMIDLIST, ITEMIDLISTDeleter>;



QgsNative::Capabilities QgsWinNative::capabilities() const
{
@@ -40,6 +54,7 @@ void QgsWinNative::initializeMainWindow( QWindow *window,
const QString &organizationName,
const QString &version )
{
mWindow = window;
if ( mTaskButton )
return; // already initialized!

@@ -69,24 +84,46 @@ void QgsWinNative::cleanup()
{
if ( mWinToastInitialized )
WinToastLib::WinToast::instance()->clear();
mWindow = nullptr;
}

void QgsWinNative::openFileExplorerAndSelectFile( const QString &path )
std::unique_ptr< wchar_t[] > pathToWChar( const QString &path )
{
const QString nativePath = QDir::toNativeSeparators( path );

wchar_t *pathArray = new wchar_t[static_cast< uint>( nativePath.length() + 1 )];
nativePath.toWCharArray( pathArray );
std::unique_ptr< wchar_t[] > pathArray( new wchar_t[static_cast< uint>( nativePath.length() + 1 )] );
nativePath.toWCharArray( pathArray.get() );
pathArray[nativePath.length()] = 0;
return pathArray;
}

ITEMIDLIST *pidl = ILCreateFromPathW( pathArray );
void QgsWinNative::openFileExplorerAndSelectFile( const QString &path )
{
std::unique_ptr< wchar_t[] > pathArray = pathToWChar( path );
ITEMIDLIST_unique_ptr pidl( ILCreateFromPathW( pathArray.get() ) );
if ( pidl )
{
SHOpenFolderAndSelectItems( pidl, 0, nullptr, 0 );
ILFree( pidl );
SHOpenFolderAndSelectItems( pidl.get(), 0, nullptr, 0 );
pidl.reset();
}
}

delete[] pathArray;
void QgsWinNative::showFileProperties( const QString &path )
{
std::unique_ptr< wchar_t[] > pathArray = pathToWChar( path );
ITEMIDLIST_unique_ptr pidl( ILCreateFromPathW( pathArray.get() ) );
if ( pidl )
{
SHELLEXECUTEINFO info{ sizeof( info ) };
if ( mWindow )
info.hwnd = reinterpret_cast<HWND>( mWindow->winId() );
info.nShow = SW_SHOWNORMAL;
info.fMask = SEE_MASK_INVOKEIDLIST;
info.lpIDList = pidl.get();
info.lpVerb = "properties";

ShellExecuteEx( &info );
}
}

void QgsWinNative::showUndefinedApplicationProgress()
@@ -57,6 +57,7 @@ class NATIVE_EXPORT QgsWinNative : public QgsNative
const QString &version ) override;
void cleanup() override;
void openFileExplorerAndSelectFile( const QString &path ) override;
void showFileProperties( const QString &path ) override;
void showUndefinedApplicationProgress() override;
void setApplicationProgress( double progress ) override;
void hideApplicationProgress() override;
@@ -65,7 +66,8 @@ class NATIVE_EXPORT QgsWinNative : public QgsNative

private:

Capabilities mCapabilities = nullptr;
QWindow *mWindow = nullptr;
Capabilities mCapabilities = NativeFilePropertiesDialog;
bool mWinToastInitialized = false;
QWinTaskbarButton *mTaskButton = nullptr;
QWinTaskbarProgress *mTaskProgress = nullptr;

0 comments on commit c79a9a1

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