From 7e7b8e75e6719ed432ee06e854077a98559c98d5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Nov 2022 06:54:34 +0530 Subject: [PATCH] Windows: Fix a regression in calibre 6 causing Open With to not extract icons from EXE files. Fixes #1998165 [Enhancement Request: Changing icon of Open With application: Icons from executable](https://bugs.launchpad.net/calibre/+bug/1998165) More pyqt6 goodness. QImage::fromHICON is not wrapped in PyQt6, so we wrap it ourselves rather than waiting for PyQt6 to be fixed. --- .../gui2/progress_indicator/QProgressIndicator.cpp | 10 ++++++++++ .../gui2/progress_indicator/QProgressIndicator.h | 1 + .../gui2/progress_indicator/QProgressIndicator.sip | 1 + src/calibre/utils/open_with/windows.py | 6 +++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp index e71942b026..4066f807fb 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp @@ -133,3 +133,13 @@ int get_image_allocation_limit() { return QImageReader::allocationLimit(); } + +QImage +image_from_hicon(void* hicon) { +#ifdef Q_OS_WIN + return QImage::fromHICON((HICON)hicon); +#else + (void)hicon; + return QImage(); +#endif +} diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.h b/src/calibre/gui2/progress_indicator/QProgressIndicator.h index 82df47aea7..9817d4242a 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.h +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.h @@ -162,3 +162,4 @@ void set_menu_on_action(QAction* ac, QMenu* menu); QMenu* menu_for_action(const QAction *ac); void set_image_allocation_limit(int megabytes); int get_image_allocation_limit(); +QImage image_from_hicon(void* hicon); diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip index 5ba46a0aff..209a038009 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip @@ -89,3 +89,4 @@ void set_menu_on_action(QAction* ac, QMenu* menu); QMenu* menu_for_action(const QAction *ac); void set_image_allocation_limit(int megabytes); int get_image_allocation_limit(); +QImage image_from_hicon(void*); diff --git a/src/calibre/utils/open_with/windows.py b/src/calibre/utils/open_with/windows.py index df3375c24e..b5de257c64 100644 --- a/src/calibre/utils/open_with/windows.py +++ b/src/calibre/utils/open_with/windows.py @@ -6,17 +6,17 @@ __copyright__ = '2015, Kovid Goyal ' import re import sys -from qt.core import QBuffer, QByteArray, QImage, QIODevice, QPixmap, Qt +from qt.core import QBuffer, QByteArray, QIODevice, QPixmap, Qt from calibre.gui2 import must_use_qt from calibre.utils.winreg.default_programs import split_commandline -from calibre_extensions import winutil +from calibre_extensions import winutil, progress_indicator ICON_SIZE = 256 def hicon_to_pixmap(hicon): - QPixmap.fromImage(QImage.fromHICON(int(hicon))) + return progress_indicator.image_from_hicon(int(hicon)) def pixmap_to_data(pixmap):