From 5856e428baf9ae02254bf49dacc16819fd7cfb90 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Sun, 24 Nov 2013 21:36:26 +0000 Subject: [PATCH 1/2] Minor: Renamed method for readability. This method isn't about disabling/enabling the "new icon", it's only about the count. For the "new icon" we need another enabler/disabler. --- kmkernel.cpp | 4 ++-- kmsystemtray.cpp | 10 +++++----- kmsystemtray.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kmkernel.cpp b/kmkernel.cpp index 37efdcdff..47a76d125 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -540,7 +540,7 @@ void KMKernel::checkMail () //might create a new reader but won't show!! void KMKernel::setSystrayUnreadCountEnabled(bool enabled) { GlobalSettings::self()->systemTrayShowUnreadItem()->setValue(enabled); - mSystemTray->setShowUnread(enabled); + mSystemTray->setShowUnreadCount(enabled); GlobalSettings::self()->writeConfig(); } @@ -2096,7 +2096,7 @@ void KMKernel::toggleSystemTray() // Set mode of systemtray. If mode has changed, tray will handle this. if ( mSystemTray ) { mSystemTray->setMode( GlobalSettings::self()->systemTrayPolicy() ); - mSystemTray->setShowUnread( GlobalSettings::self()->systemTrayShowUnread() ); + mSystemTray->setShowUnreadCount( GlobalSettings::self()->systemTrayShowUnread() ); } } diff --git a/kmsystemtray.cpp b/kmsystemtray.cpp index fb6959288..5a51f7f12 100644 --- a/kmsystemtray.cpp +++ b/kmsystemtray.cpp @@ -62,7 +62,7 @@ KMSystemTray::KMSystemTray(QObject *parent) mDesktopOfMainWin( 0 ), mMode( GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ), mCount( 0 ), - mShowUnreadMail( true ), + mShowUnreadMailCount( true ), mNewMessagesPopup( 0 ), mSendQueued( 0 ) { @@ -142,11 +142,11 @@ KMSystemTray::~KMSystemTray() { } -void KMSystemTray::setShowUnread(bool showUnread) +void KMSystemTray::setShowUnreadCount(bool showUnreadCount) { - if (mShowUnreadMail == showUnread) + if (mShowUnreadMailCount == showUnreadCount) return; - mShowUnreadMail = showUnread; + mShowUnreadMailCount = showUnreadCount; updateSystemTray(); } @@ -186,7 +186,7 @@ void KMSystemTray::updateCount() setIconByName( "kmail" ); return; } - if (mShowUnreadMail) { + if (mShowUnreadMailCount) { const int overlaySize = KIconLoader::SizeSmallMedium; const QString countString = QString::number( mCount ); diff --git a/kmsystemtray.h b/kmsystemtray.h index 6373d981d..4dd390b60 100644 --- a/kmsystemtray.h +++ b/kmsystemtray.h @@ -47,7 +47,7 @@ public: /** destructor */ ~KMSystemTray(); - void setShowUnread(bool showUnread); + void setShowUnreadCount(bool showUnreadCount); void setMode(int mode); int mode() const; @@ -80,7 +80,7 @@ private: int mMode; int mCount; - bool mShowUnreadMail; + bool mShowUnreadMailCount; QMenu *mNewMessagesPopup; QAction *mSendQueued; }; From f954915795adfc839715d4fb2a278dfb4f10b195 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Sun, 24 Nov 2013 22:48:22 +0000 Subject: [PATCH 2/2] Improve my last commit re disabling systray icon changes via dbus. Disabling unread count wasn't enough, the icon still changed when new mail arrived. --- kmkernel.cpp | 6 ++---- kmkernel.h | 6 +++++- kmsystemtray.cpp | 10 +++++++++- kmsystemtray.h | 10 ++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/kmkernel.cpp b/kmkernel.cpp index 47a76d125..4ac25046e 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -537,11 +537,9 @@ void KMKernel::checkMail () //might create a new reader but won't show!! } } -void KMKernel::setSystrayUnreadCountEnabled(bool enabled) +void KMKernel::setSystrayIconNotificationsEnabled( bool enabled ) { - GlobalSettings::self()->systemTrayShowUnreadItem()->setValue(enabled); - mSystemTray->setShowUnreadCount(enabled); - GlobalSettings::self()->writeConfig(); + mSystemTray->setSystrayIconNotificationsEnabled( enabled ); } QStringList KMKernel::accounts() diff --git a/kmkernel.h b/kmkernel.h index 6425c7759..1056ef537 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -120,7 +120,11 @@ public Q_SLOTS: Q_SCRIPTABLE void checkMail(); Q_SCRIPTABLE void openReader() { openReader( false ); } - Q_SCRIPTABLE void setSystrayUnreadCountEnabled(bool enabled); + /** + * Enables/disables systray icon changing when mail arrives. + * With this disabled the systray icon will always be the same. + */ + Q_SCRIPTABLE void setSystrayIconNotificationsEnabled( bool enabled ); /** * Pauses all background jobs and does not diff --git a/kmsystemtray.cpp b/kmsystemtray.cpp index 5a51f7f12..43af5b214 100644 --- a/kmsystemtray.cpp +++ b/kmsystemtray.cpp @@ -63,6 +63,7 @@ KMSystemTray::KMSystemTray(QObject *parent) mMode( GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ), mCount( 0 ), mShowUnreadMailCount( true ), + mIconNotificationsEnabled( true ), mNewMessagesPopup( 0 ), mSendQueued( 0 ) { @@ -182,7 +183,7 @@ int KMSystemTray::mode() const */ void KMSystemTray::updateCount() { - if (mCount == 0) { + if (mCount == 0 || !mIconNotificationsEnabled) { setIconByName( "kmail" ); return; } @@ -229,6 +230,13 @@ void KMSystemTray::updateCount() } } +void KMSystemTray::setSystrayIconNotificationsEnabled( bool enabled ) +{ + if ( enabled != mIconNotificationsEnabled ) { + mIconNotificationsEnabled = enabled; + updateSystemTray(); + } +} /** * On left mouse click, switch focus to the first KMMainWidget. On right diff --git a/kmsystemtray.h b/kmsystemtray.h index 4dd390b60..3258a572b 100644 --- a/kmsystemtray.h +++ b/kmsystemtray.h @@ -48,6 +48,14 @@ public: ~KMSystemTray(); void setShowUnreadCount(bool showUnreadCount); + + /** + * Use this method to disable any systray icon changing. + * By default this is enabled and you'll see the "new e-mail" icon whenever there's + * new e-mail. + */ + void setSystrayIconNotificationsEnabled(bool enable); + void setMode(int mode); int mode() const; @@ -81,6 +89,8 @@ private: int mCount; bool mShowUnreadMailCount; + bool mIconNotificationsEnabled; + QMenu *mNewMessagesPopup; QAction *mSendQueued; };