mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:55:54 +00:00
UI: Add AppUtil.
This commit is contained in:
parent
1c5b87ef30
commit
12c9e3d3a5
@ -48,6 +48,7 @@ SOURCES += \
|
||||
translationmanager.cpp \
|
||||
util/app/appinfomanager.cpp \
|
||||
util/app/appinfoworker.cpp \
|
||||
util/app/apputil.cpp \
|
||||
util/conf/addressrange.cpp \
|
||||
util/conf/confutil.cpp \
|
||||
util/dateutil.cpp \
|
||||
@ -111,6 +112,7 @@ HEADERS += \
|
||||
translationmanager.h \
|
||||
util/app/appinfomanager.h \
|
||||
util/app/appinfoworker.h \
|
||||
util/app/apputil.h \
|
||||
util/conf/addressrange.h \
|
||||
util/conf/confutil.h \
|
||||
util/dateutil.h \
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QImage>
|
||||
|
||||
#include "appinfomanager.h"
|
||||
#include "apputil.h"
|
||||
|
||||
AppInfoWorker::AppInfoWorker(AppInfoManager *manager) :
|
||||
WorkerObject(manager)
|
||||
|
63
src/ui/util/app/apputil.cpp
Normal file
63
src/ui/util/app/apputil.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "apputil.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <comdef.h>
|
||||
#include <commctrl.h>
|
||||
#include <commoncontrols.h>
|
||||
#include <objbase.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
// Defined in qpixmap_win.cpp
|
||||
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon);
|
||||
|
||||
namespace {
|
||||
|
||||
static QPixmap pixmapFromImageList(int iImageList, const SHFILEINFO &info)
|
||||
{
|
||||
QPixmap result;
|
||||
|
||||
IImageList *imageList;
|
||||
HICON hIcon;
|
||||
|
||||
if (SUCCEEDED(SHGetImageList(iImageList, IID_IImageList, reinterpret_cast<void **>(&imageList)))
|
||||
&& SUCCEEDED(imageList->GetIcon(info.iIcon, ILD_TRANSPARENT, &hIcon))) {
|
||||
result = qt_pixmapFromWinHICON(hIcon);
|
||||
DestroyIcon(hIcon);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static QPixmap extractShellIcon(const QString &appPath)
|
||||
{
|
||||
const QString nativePath = QDir::toNativeSeparators(appPath);
|
||||
const wchar_t *nativePathW = reinterpret_cast<const wchar_t *>(nativePath.utf16());
|
||||
|
||||
const UINT flags = SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES;
|
||||
|
||||
QPixmap pixmap;
|
||||
|
||||
SHFILEINFOW info;
|
||||
ZeroMemory(&info, sizeof(SHFILEINFOW));
|
||||
|
||||
const HRESULT hr = SHGetFileInfoW(nativePathW, 0, &info,
|
||||
sizeof(SHFILEINFOW), flags);
|
||||
if (SUCCEEDED(hr)) {
|
||||
pixmap = pixmapFromImageList(SHIL_JUMBO, info);
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AppUtil::AppUtil(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap AppUtil::getIcon(const QString &appPath)
|
||||
{
|
||||
return extractShellIcon(appPath);
|
||||
}
|
17
src/ui/util/app/apputil.h
Normal file
17
src/ui/util/app/apputil.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef APPUTIL_H
|
||||
#define APPUTIL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
|
||||
class AppUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AppUtil(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE static QPixmap getIcon(const QString &appPath);
|
||||
};
|
||||
|
||||
#endif // APPUTIL_H
|
Loading…
Reference in New Issue
Block a user