Skip to content

Commit 2810c92

Browse files
authored
[mac] display icon in notification (#7734)
there is 2 icons in notifications, one from the app itself and one set from the notification the icon application seems not to be set correctly on mac for now only the windon icon is set in main.cpp with myApp.setWindowIcon the icon defined in application plist does not seem to be correctly set ...so in this PR we set the notification icon to be the QGIS one, so it looks nicer
1 parent 5c7f13b commit 2810c92

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/gui/qgsgui.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ QgsGui::~QgsGui()
115115
QgsGui::QgsGui()
116116
{
117117
#ifdef Q_OS_MAC
118-
mNative = new QgsMacNative();
118+
QgsMacNative *macNative = new QgsMacNative();
119+
macNative->setIconPath( QgsApplication::iconsPath() + QStringLiteral( "qgis-icon-macos.png" ) );
120+
mNative = macNative;
119121
#elif defined (Q_OS_WIN)
120122
mNative = new QgsWinNative();
121123
#elif defined(Q_OS_LINUX)

src/native/mac/qgsmacnative.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class NATIVE_EXPORT QgsMacNative : public QgsNative
2929
explicit QgsMacNative();
3030
~QgsMacNative() override;
3131

32+
//! reset the application icon used in the notification
33+
void setIconPath( const QString &iconPath = QString() );
34+
3235
virtual const char *currentAppLocalizedName();
3336
void currentAppActivateIgnoringOtherApps() override;
3437
void openFileExplorerAndSelectFile( const QString &path ) override;

src/native/mac/qgsmacnative.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ - ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPres
4242
{
4343
public:
4444
QgsUserNotificationCenterDelegate *_qgsUserNotificationCenter;
45+
NSImage *_qgisIcon;
4546
};
4647

4748
QgsMacNative::QgsMacNative()
@@ -57,6 +58,11 @@ - ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPres
5758
delete mQgsUserNotificationCenter;
5859
}
5960

61+
void QgsMacNative::setIconPath( const QString &iconPath )
62+
{
63+
mQgsUserNotificationCenter->_qgisIcon = QtMac::toNSImage( QPixmap( iconPath ) );
64+
}
65+
6066
const char *QgsMacNative::currentAppLocalizedName()
6167
{
6268
return [[[NSRunningApplication currentApplication] localizedName] UTF8String];
@@ -92,7 +98,10 @@ - ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPres
9298
NSImage *image = nil;
9399
if ( settings.image.isNull() )
94100
{
95-
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
101+
// image application (qgis.icns) seems not to be set for now, although present in the plist
102+
// whenever fixed, try following line (and remove corresponding code in QgsMacNative::QgsUserNotificationCenter)
103+
// image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]
104+
image = mQgsUserNotificationCenter->_qgisIcon;
96105
}
97106
else
98107
{

0 commit comments

Comments
 (0)