29
29
#include < QtWinExtras/QWinJumpListCategory>
30
30
#include " wintoastlib.h"
31
31
#include < Dbt.h>
32
+ #include < memory>
33
+
34
+
35
+ struct ITEMIDLISTDeleter
36
+ {
37
+ void operator ()( ITEMIDLIST *pidl )
38
+ {
39
+ ILFree ( pidl );
40
+ }
41
+ };
42
+
43
+ using ITEMIDLIST_unique_ptr = std::unique_ptr< ITEMIDLIST, ITEMIDLISTDeleter>;
44
+
45
+
32
46
33
47
QgsNative::Capabilities QgsWinNative::capabilities () const
34
48
{
@@ -40,6 +54,7 @@ void QgsWinNative::initializeMainWindow( QWindow *window,
40
54
const QString &organizationName,
41
55
const QString &version )
42
56
{
57
+ mWindow = window;
43
58
if ( mTaskButton )
44
59
return ; // already initialized!
45
60
@@ -69,24 +84,46 @@ void QgsWinNative::cleanup()
69
84
{
70
85
if ( mWinToastInitialized )
71
86
WinToastLib::WinToast::instance ()->clear ();
87
+ mWindow = nullptr ;
72
88
}
73
89
74
- void QgsWinNative::openFileExplorerAndSelectFile ( const QString &path )
90
+ std::unique_ptr< wchar_t [] > pathToWChar ( const QString &path )
75
91
{
76
92
const QString nativePath = QDir::toNativeSeparators ( path );
77
93
78
- wchar_t * pathArray = new wchar_t [static_cast < uint>( nativePath.length () + 1 )];
79
- nativePath.toWCharArray ( pathArray );
94
+ std::unique_ptr< wchar_t [] > pathArray ( new wchar_t [static_cast < uint>( nativePath.length () + 1 )] ) ;
95
+ nativePath.toWCharArray ( pathArray. get () );
80
96
pathArray[nativePath.length ()] = 0 ;
97
+ return pathArray;
98
+ }
81
99
82
- ITEMIDLIST *pidl = ILCreateFromPathW ( pathArray );
100
+ void QgsWinNative::openFileExplorerAndSelectFile ( const QString &path )
101
+ {
102
+ std::unique_ptr< wchar_t [] > pathArray = pathToWChar ( path );
103
+ ITEMIDLIST_unique_ptr pidl ( ILCreateFromPathW ( pathArray.get () ) );
83
104
if ( pidl )
84
105
{
85
- SHOpenFolderAndSelectItems ( pidl, 0 , nullptr , 0 );
86
- ILFree ( pidl );
106
+ SHOpenFolderAndSelectItems ( pidl. get () , 0 , nullptr , 0 );
107
+ pidl. reset ( );
87
108
}
109
+ }
88
110
89
- delete[] pathArray;
111
+ void QgsWinNative::showFileProperties ( const QString &path )
112
+ {
113
+ std::unique_ptr< wchar_t [] > pathArray = pathToWChar ( path );
114
+ ITEMIDLIST_unique_ptr pidl ( ILCreateFromPathW ( pathArray.get () ) );
115
+ if ( pidl )
116
+ {
117
+ SHELLEXECUTEINFO info{ sizeof ( info ) };
118
+ if ( mWindow )
119
+ info.hwnd = reinterpret_cast <HWND>( mWindow ->winId () );
120
+ info.nShow = SW_SHOWNORMAL;
121
+ info.fMask = SEE_MASK_INVOKEIDLIST;
122
+ info.lpIDList = pidl.get ();
123
+ info.lpVerb = " properties" ;
124
+
125
+ ShellExecuteEx ( &info );
126
+ }
90
127
}
91
128
92
129
void QgsWinNative::showUndefinedApplicationProgress ()
0 commit comments