Skip to content

Commit

Permalink
[needs-docs] Implement native file properties support for Windows
Browse files Browse the repository at this point in the history
Allows opening the native file explorer file/directory properties
dialog for browser items
  • Loading branch information
nyalldawson committed Nov 12, 2018
1 parent 9f1d00d commit c79a9a1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
51 changes: 44 additions & 7 deletions src/native/win/qgswinnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -40,6 +54,7 @@ void QgsWinNative::initializeMainWindow( QWindow *window,
const QString &organizationName,
const QString &version )
{
mWindow = window;
if ( mTaskButton )
return; // already initialized!

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion src/native/win/qgswinnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit c79a9a1

Please sign in to comment.