From 8ae37bf704aa5df5911c1494083535bb286904b9 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Fri, 25 Aug 2023 15:48:27 +0200 Subject: [PATCH] New unified mail count message --- app/SysTray-X/SysTray-X-app/debugwidget.cpp | 11 +- app/SysTray-X/SysTray-X-app/debugwidget.h | 14 +- app/SysTray-X/SysTray-X-app/debugwidget.ui | 60 +++++--- app/SysTray-X/SysTray-X-app/systrayx.cpp | 40 ++--- app/SysTray-X/SysTray-X-app/systrayx.h | 23 ++- app/SysTray-X/SysTray-X-app/systrayxicon.cpp | 20 ++- app/SysTray-X/SysTray-X-app/systrayxicon.h | 21 ++- app/SysTray-X/SysTray-X-app/systrayxlink.cpp | 32 +++- app/SysTray-X/SysTray-X-app/systrayxlink.h | 11 +- .../SysTray-X-app/systrayxstatusnotifier.cpp | 23 +-- .../SysTray-X-app/systrayxstatusnotifier.h | 21 ++- webext/background.js | 138 ++++++------------ webext/js/defaults.js | 27 +--- 13 files changed, 229 insertions(+), 212 deletions(-) diff --git a/app/SysTray-X/SysTray-X-app/debugwidget.cpp b/app/SysTray-X/SysTray-X-app/debugwidget.cpp index dcb4c56..188c842 100644 --- a/app/SysTray-X/SysTray-X-app/debugwidget.cpp +++ b/app/SysTray-X/SysTray-X-app/debugwidget.cpp @@ -52,11 +52,12 @@ void DebugWidget::changeEvent( QEvent* event ) /* - * Set the number of unread mail + * Set the number of unread/new mails */ -void DebugWidget::setUnreadMail( int unread ) +void DebugWidget::setMailCount( int unread_mail, int new_mail ) { - m_ui->unreadMailLabel->setText( QString::number( unread ) ); + m_ui->unreadMailLabel->setText( QString::number( unread_mail ) ); + m_ui->newMailLabel->setText( QString::number( new_mail ) ); } @@ -72,9 +73,9 @@ void DebugWidget::slotDebugChange() /* * Handle unread mail signal */ -void DebugWidget::slotUnreadMail( int unread_mail ) +void DebugWidget::slotMailCount( int unread_mail, int new_mail ) { - setUnreadMail( unread_mail ); + setMailCount( unread_mail, new_mail ); } diff --git a/app/SysTray-X/SysTray-X-app/debugwidget.h b/app/SysTray-X/SysTray-X-app/debugwidget.h index 975cb4b..07f3648 100644 --- a/app/SysTray-X/SysTray-X-app/debugwidget.h +++ b/app/SysTray-X/SysTray-X-app/debugwidget.h @@ -46,11 +46,12 @@ class DebugWidget : public QWidget void changeEvent( QEvent *event ); /** - * @brief setUnreadMail. Set the number of unread mails. + * @brief setMailCount. Set the number of unread/new mails. * - * @param unread The number of unread mails. + * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void setUnreadMail( int unread ); + void setMailCount( int unread_mail, int new_mail ); signals: @@ -82,11 +83,12 @@ class DebugWidget : public QWidget void slotDebugChange(); /** - * @brief slotSetUnreadMail. Slot for handling unread mail signals. + * @brief slotMailCount. Slot for handling unread/new mail signals. * - * @param unread_mail The number of unread mails. + * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void slotUnreadMail( int unread_mail ); + void slotMailCount( int unread_mail, int new_mail ); /** * @brief slotHandleTest1Button. Handle a click on the test 1 button. diff --git a/app/SysTray-X/SysTray-X-app/debugwidget.ui b/app/SysTray-X/SysTray-X-app/debugwidget.ui index b4bdaf0..3648677 100644 --- a/app/SysTray-X/SysTray-X-app/debugwidget.ui +++ b/app/SysTray-X/SysTray-X-app/debugwidget.ui @@ -6,8 +6,8 @@ 0 0 - 368 - 280 + 358 + 290 @@ -19,18 +19,44 @@ - - - Unread mail: - - - - - - - 0 - - + + + + + + + Unread mail: + + + + + + + 0 + + + + + + + + + + + New mail: + + + + + + + 0 + + + + + + @@ -45,7 +71,7 @@ - + Qt::Horizontal @@ -58,10 +84,10 @@ - + - + diff --git a/app/SysTray-X/SysTray-X-app/systrayx.cpp b/app/SysTray-X/SysTray-X-app/systrayx.cpp index 914ec41..122cdce 100644 --- a/app/SysTray-X/SysTray-X-app/systrayx.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayx.cpp @@ -39,6 +39,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) m_tray_icon_menu = nullptr; m_unread_mail = 0; + m_new_mail = 0; m_locale = QString(); /* @@ -84,7 +85,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) /* * Connect debug link signals */ - connect( m_link, &SysTrayXLink::signalUnreadMail, m_debug, &DebugWidget::slotUnreadMail ); + connect( m_link, &SysTrayXLink::signalMailCount, m_debug, &DebugWidget::slotMailCount ); connect( this, &SysTrayX::signalConsole, m_debug, &DebugWidget::slotConsole ); connect( m_preferences, &Preferences::signalConsole, m_debug, &DebugWidget::slotConsole ); @@ -163,7 +164,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_link, &SysTrayXLink::signalAddOnShutdown, this, &SysTrayX::slotAddOnShutdown ); connect( m_link, &SysTrayXLink::signalErrorAddOnShutdown, this, &SysTrayX::slotErrorAddOnShutdown ); connect( m_link, &SysTrayXLink::signalWindowState, m_win_ctrl, &WindowCtrl::slotWindowState ); - connect( m_link, &SysTrayXLink::signalUnreadMail, this, &SysTrayX::slotSetUnreadMail ); + connect( m_link, &SysTrayXLink::signalMailCount, this, &SysTrayX::slotMailCount ); connect( m_link, &SysTrayXLink::signalVersion, this, &SysTrayX::slotVersion ); connect( m_link, &SysTrayXLink::signalKdeIntegration, this, &SysTrayX::slotSelectIconObject ); connect( m_link, &SysTrayXLink::signalLocale, this, &SysTrayX::slotLoadLanguage ); @@ -194,7 +195,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) //slotLoadLanguage( "ru" ); slotSelectIconObject( false ); - slotSetUnreadMail( 10 ); + slotMailCount( 10, 1 ); */ } @@ -308,16 +309,16 @@ void SysTrayX::showTrayIcon() connect( m_preferences, &Preferences::signalNumberMarginsChange, m_tray_icon, &SysTrayXIcon::slotNumberMarginsChange ); connect( m_preferences, &Preferences::signalThemeChange, m_tray_icon, &SysTrayXIcon::slotThemeChange ); - connect( m_link, &SysTrayXLink::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail ); + connect( m_link, &SysTrayXLink::signalMailCount, m_tray_icon, &SysTrayXIcon::slotMailCount ); - connect( this, &SysTrayX::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail ); + connect( this, &SysTrayX::signalMailCount, m_tray_icon, &SysTrayXIcon::slotMailCount ); /* * Show it */ m_tray_icon->show(); - QTimer::singleShot(500, this, &SysTrayX::resendUnreadMail); + QTimer::singleShot(500, this, &SysTrayX::resendMailCount); } } @@ -345,9 +346,9 @@ void SysTrayX::hideTrayIcon() disconnect( m_preferences, &Preferences::signalNumberMarginsChange, m_tray_icon, &SysTrayXIcon::slotNumberMarginsChange ); disconnect( m_preferences, &Preferences::signalThemeChange, m_tray_icon, &SysTrayXIcon::slotThemeChange ); - disconnect( m_link, &SysTrayXLink::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail ); + disconnect( m_link, &SysTrayXLink::signalMailCount, m_tray_icon, &SysTrayXIcon::slotMailCount ); - disconnect( this, &SysTrayX::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail ); + disconnect( this, &SysTrayX::signalMailCount, m_tray_icon, &SysTrayXIcon::slotMailCount ); /* * Hide the icon first to prevent "ghosts" @@ -420,14 +421,14 @@ void SysTrayX::showKdeTrayIcon() connect( m_preferences, &Preferences::signalNumberMarginsChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotNumberMarginsChange ); connect( m_preferences, &Preferences::signalThemeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotThemeChange ); - connect( m_link, &SysTrayXLink::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail ); + connect( m_link, &SysTrayXLink::signalMailCount, m_kde_tray_icon, &SysTrayXStatusNotifier::slotMailCount ); - connect( this, &SysTrayX::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail ); + connect( this, &SysTrayX::signalMailCount, m_kde_tray_icon, &SysTrayXStatusNotifier::slotMailCount ); /* * Show */ - QTimer::singleShot(500, this, &SysTrayX::resendUnreadMail); + QTimer::singleShot(500, this, &SysTrayX::resendMailCount); } } @@ -456,9 +457,9 @@ void SysTrayX::hideKdeTrayIcon() disconnect( m_preferences, &Preferences::signalNumberMarginsChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotNumberMarginsChange ); disconnect( m_preferences, &Preferences::signalThemeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotThemeChange ); - disconnect( m_link, &SysTrayXLink::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail ); + disconnect( m_link, &SysTrayXLink::signalMailCount, m_kde_tray_icon, &SysTrayXStatusNotifier::slotMailCount ); - disconnect( this, &SysTrayX::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail ); + disconnect( this, &SysTrayX::signalMailCount, m_kde_tray_icon, &SysTrayXStatusNotifier::slotMailCount ); /* * Remove the notifier icon @@ -526,11 +527,11 @@ void SysTrayX::slotSelectIconObject( bool state ) /* - * Resend unread mail + * Resend unread/new mail */ -void SysTrayX::resendUnreadMail() +void SysTrayX::resendMailCount() { - emit signalUnreadMail( m_unread_mail ); + emit signalMailCount( m_unread_mail, m_new_mail ); } @@ -674,11 +675,12 @@ void SysTrayX::slotVersion( QString version ) /* - * Handle unread mail signal + * Handle mail count signal */ -void SysTrayX::slotSetUnreadMail( int unread ) +void SysTrayX::slotMailCount( int unread_mail, int new_mail ) { - m_unread_mail = unread; + m_unread_mail = unread_mail; + m_new_mail = new_mail; } diff --git a/app/SysTray-X/SysTray-X-app/systrayx.h b/app/SysTray-X/SysTray-X-app/systrayx.h index 209007f..889f71e 100644 --- a/app/SysTray-X/SysTray-X-app/systrayx.h +++ b/app/SysTray-X/SysTray-X-app/systrayx.h @@ -90,18 +90,19 @@ class SysTrayX : public QObject #endif /** - * @brief resendUnreadMail. Send another unread mail signal to the icon. + * @brief resendMailCount. Send another unread/new mail signal to the icon. */ - void resendUnreadMail(); + void resendMailCount(); signals: /** - * @brief signalUnreadMail. Signal numder of unread mails. + * @brief signalMailCount. Signal numder of unread/new mails. * - * @param unreadMail The number of unread mails. + * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void signalUnreadMail( int unread_mail ); + void signalMailCount( int unread_mail, int new_mail ); /** * @brief signalWriteMessage @@ -125,11 +126,12 @@ class SysTrayX : public QObject public slots: /** - * @brief slotSetUnreadMail. Handle the unred mail signal. + * @brief slotMailCount. Handle the mail count signal. * - * @param unread Number of unread mail. + * @param unread_mail Number of unread mail. + * @param new_mail Number of new mail. */ - void slotSetUnreadMail( int unread ); + void slotMailCount( int unread_mail, int new_mail ); /** * @brief slotLoadLanguage. Handle locale change signal. @@ -228,6 +230,11 @@ class SysTrayX : public QObject */ int m_unread_mail; + /** + * @brief m_new_mail. Number of new mails + */ + int m_new_mail; + /** * @brief m_translator. The translator object. */ diff --git a/app/SysTray-X/SysTray-X-app/systrayxicon.cpp b/app/SysTray-X/SysTray-X-app/systrayxicon.cpp index 4d0d337..25e21fe 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxicon.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayxicon.cpp @@ -29,6 +29,7 @@ SysTrayXIcon::SysTrayXIcon( SysTrayXLink* link, Preferences* pref, QObject* pare m_pref = pref; m_unread_mail = 0; + m_new_mail = 0; m_show_number = m_pref->getShowNumber(); m_number_color = m_pref->getNumberColor(); @@ -276,16 +277,17 @@ void SysTrayXIcon::setNumberMargins( QMargins margins ) /* - * Set the number of unread mails + * Set the number of unread/new mails */ -void SysTrayXIcon::setUnreadMail( int unread_mail ) +void SysTrayXIcon::setMailCount( int unread_mail, int new_mail ) { - if( m_unread_mail != unread_mail ) + if( m_unread_mail != unread_mail || m_new_mail != new_mail ) { /* * Store the new value */ m_unread_mail = unread_mail; + m_new_mail = new_mail; /* * Render and set a new icon in the tray @@ -302,7 +304,7 @@ void SysTrayXIcon::renderIcon() { QPixmap pixmap; - if( m_unread_mail > 0 ) + if( m_unread_mail > 0 || m_new_mail > 0 ) { switch( m_icon_type ) { @@ -392,7 +394,7 @@ void SysTrayXIcon::renderIcon() } } - if( m_show_number && ( m_unread_mail > 0 ) ) + if( m_show_number && ( m_unread_mail > 0 || m_new_mail > 0 ) ) { /* * Paint the number @@ -415,6 +417,8 @@ void SysTrayXIcon::renderIcon() QRect bounding = pixmap.rect().adjusted( m_number_margins.left(), m_number_margins.top(), -m_number_margins.right(), -m_number_margins.bottom()); + +// TODO: check pref for type painter.drawText( bounding, m_number_alignment, QString::number( m_unread_mail ) ); } @@ -426,11 +430,11 @@ void SysTrayXIcon::renderIcon() /* - * Handle unread mail signal + * Handle mail count signal */ -void SysTrayXIcon::slotSetUnreadMail( int unread_mail ) +void SysTrayXIcon::slotMailCount( int unread_mail, int new_mail ) { - setUnreadMail( unread_mail ); + setMailCount( unread_mail, new_mail ); } diff --git a/app/SysTray-X/SysTray-X-app/systrayxicon.h b/app/SysTray-X/SysTray-X-app/systrayxicon.h index 87e3477..d9924e9 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxicon.h +++ b/app/SysTray-X/SysTray-X-app/systrayxicon.h @@ -111,11 +111,12 @@ class SysTrayXIcon : public QSystemTrayIcon void setNumberMargins( QMargins margins ); /** - * @brief setUnreadMail. Set the number of unread mails. + * @brief setMailCount. Set the number of unread/new mails. * * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void setUnreadMail( int unread_mail ); + void setMailCount( int unread_mail, int new_mail ); private: @@ -134,11 +135,12 @@ class SysTrayXIcon : public QSystemTrayIcon public slots: /** - * @brief slotSetUnreadMail. Slot for handling unread mail signals. + * @brief slotMailCount. Slot for handling unread/new mail signals. * * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void slotSetUnreadMail( int unread_mail ); + void slotMailCount( int unread_mail, int new_mail ); /** * @brief slotDefaultIconTypeChange. Slot for handling default icon type change signals. @@ -242,17 +244,17 @@ class SysTrayXIcon : public QSystemTrayIcon QByteArray m_icon_data; /** - * @brief m_show_number. Show the unread mail count. + * @brief m_show_number. Show the unread/new mail count. */ bool m_show_number; /** - * @brief m_number_color. Color of the unread mail number. + * @brief m_number_color. Color of the unread/new mail number. */ QString m_number_color; /** - * @brief m_number_size. Size of the unread mail number. + * @brief m_number_size. Size of the unread/new mail number. */ int m_number_size; @@ -270,6 +272,11 @@ class SysTrayXIcon : public QSystemTrayIcon * @brief m_unread_mail. Storage for the number of unread mails. */ int m_unread_mail; + + /** + * @brief m_new_mail. Storage for the number of new mails. + */ + int m_new_mail; }; #endif // SYSTRAYXICON_H diff --git a/app/SysTray-X/SysTray-X-app/systrayxlink.cpp b/app/SysTray-X/SysTray-X-app/systrayxlink.cpp index dbfefa6..af1d06c 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxlink.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayxlink.cpp @@ -79,7 +79,7 @@ void SysTrayXLinkReader::startThread() /* * Start the work */ - m_doWork = true; + m_do_work = true; /* * Start the worker @@ -96,7 +96,7 @@ void SysTrayXLinkReader::stopThread() /* * Stop working */ - m_doWork = false; + m_do_work = false; } @@ -107,7 +107,7 @@ void SysTrayXLinkReader::slotWorker() { int error_count = 0; - while( m_doWork ) + while( m_do_work ) { qint32 data_len; std::cin.read( reinterpret_cast< char* >( &data_len ), sizeof( qint32 ) ); @@ -317,10 +317,30 @@ void SysTrayXLink::DecodeMessage( const QByteArray& message ) } */ - if( jsonObject.contains( "unreadMail" ) && jsonObject[ "unreadMail" ].isDouble() ) + if( jsonObject.contains( "mailCount" ) && jsonObject[ "mailCount" ].isObject() ) { - int unreadMail = jsonObject[ "unreadMail" ].toInt(); - emit signalUnreadMail( unreadMail ); + QJsonObject mailCount = jsonObject[ "mailCount" ].toObject(); + + /* + * Check the received object + */ + int unreadMail = 0; + int newMail = 0; + if( mailCount.contains( "unread" ) && mailCount[ "unread" ].isDouble() ) + { + unreadMail = mailCount[ "unread" ].toInt(); + + emit signalConsole( QString("Unread %1").arg( unreadMail ) ); + } + + if( mailCount.contains( "new" ) && mailCount[ "new" ].isDouble() ) + { + newMail = mailCount[ "new" ].toInt(); + + emit signalConsole( QString("New %1").arg( newMail ) ); + } + + emit signalMailCount( unreadMail, newMail ); } if( jsonObject.contains( "version" ) && jsonObject[ "version" ].isString() ) diff --git a/app/SysTray-X/SysTray-X-app/systrayxlink.h b/app/SysTray-X/SysTray-X-app/systrayxlink.h index 981ff87..670d1a7 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxlink.h +++ b/app/SysTray-X/SysTray-X-app/systrayxlink.h @@ -78,9 +78,9 @@ class SysTrayXLinkReader : public QObject QTimer* m_timer; /** - * @brief m_doWork. Status of the worker thread. + * @brief m_do_work. Status of the worker thread. */ - bool m_doWork; + bool m_do_work; }; @@ -228,11 +228,12 @@ class SysTrayXLink : public QObject void signalLocale( QString locale ); /** - * @brief signalUnreadMail. Signal numder of unread mails. + * @brief signalMailCount. Signal numder of unread/new mails. * - * @param unreadMail The number of unread mails. + * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void signalUnreadMail( int unread_mail ); + void signalMailCount( int unread_mail, int new_mail ); /** * @brief signalWindowPositions. Signal the startup positions. diff --git a/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.cpp b/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.cpp index 9582001..859baa4 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.cpp @@ -34,6 +34,7 @@ SysTrayXStatusNotifier::SysTrayXStatusNotifier( SysTrayXLink* link, Preferences* m_pref = pref; m_unread_mail = 0; + m_new_mail = 0; m_show_number = m_pref->getShowNumber(); m_number_color = m_pref->getNumberColor(); @@ -322,16 +323,17 @@ void SysTrayXStatusNotifier::setNumberMargins( QMargins margins ) /* - * Set the number of unread mails + * Set the number of unread/new mails */ -void SysTrayXStatusNotifier::setUnreadMail( int unread_mail ) +void SysTrayXStatusNotifier::setMailCount( int unread_mail, int new_mail ) { - if( m_unread_mail != unread_mail ) + if( m_unread_mail != unread_mail || m_new_mail != new_mail ) { /* * Store the new value */ m_unread_mail = unread_mail; + m_new_mail = new_mail; /* * Render and set a new icon in the tray @@ -348,7 +350,7 @@ void SysTrayXStatusNotifier::renderIcon() { QPixmap pixmap; - if( m_unread_mail > 0 ) + if( m_unread_mail > 0 || m_new_mail > 0 ) { switch( m_icon_type ) { @@ -437,7 +439,7 @@ void SysTrayXStatusNotifier::renderIcon() } } - if( m_show_number && ( m_unread_mail > 0 ) ) + if( m_show_number && ( m_unread_mail > 0 || m_new_mail > 0 ) ) { /* * Paint the number @@ -460,6 +462,7 @@ void SysTrayXStatusNotifier::renderIcon() QRect bounding = pixmap.rect().adjusted( m_number_margins.left(), m_number_margins.top(), -m_number_margins.right(), -m_number_margins.bottom()); +// TODO pref to get the type painter.drawText( bounding, m_number_alignment, QString::number( m_unread_mail ) ); } @@ -471,7 +474,7 @@ void SysTrayXStatusNotifier::renderIcon() /* * Hide the icon? */ - if( m_hide_default_icon && m_unread_mail == 0 ) + if( m_hide_default_icon && m_unread_mail == 0 && m_new_mail == 0 ) { setStatus( KStatusNotifierItem::ItemStatus::Passive ); } @@ -484,7 +487,7 @@ void SysTrayXStatusNotifier::renderIcon() void SysTrayXStatusNotifier::showIcon() { - if( !m_hide_default_icon || m_unread_mail > 0 ) + if( !m_hide_default_icon || m_unread_mail > 0 || m_new_mail > 0 ) { setStatus( KStatusNotifierItem::ItemStatus::Active ); } @@ -492,11 +495,11 @@ void SysTrayXStatusNotifier::showIcon() /* - * Handle unread mail signal + * Handle mail count signal */ -void SysTrayXStatusNotifier::slotSetUnreadMail( int unread_mail ) +void SysTrayXStatusNotifier::slotMailCount( int unread_mail, int new_mail ) { - setUnreadMail( unread_mail ); + setMailCount( unread_mail, new_mail ); } diff --git a/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.h b/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.h index bcadccd..df6f465 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.h +++ b/app/SysTray-X/SysTray-X-app/systrayxstatusnotifier.h @@ -122,11 +122,12 @@ class SysTrayXStatusNotifier : public KStatusNotifierItem void setNumberMargins( QMargins margins ); /** - * @brief setUnreadMail. Set the number of unread mails. + * @brief setMailCount. Set the number of unread/new mails. * * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void setUnreadMail( int unread_mail ); + void setMailCount( int unread_mail, int new_mail ); private: @@ -150,11 +151,12 @@ class SysTrayXStatusNotifier : public KStatusNotifierItem public slots: /** - * @brief slotSetUnreadMail. Slot for handling unread mail signals. + * @brief slotMailCount. Slot for handling unread/new mail signals. * * @param unread_mail The number of unread mails. + * @param new_mail The number of new mails. */ - void slotSetUnreadMail( int unread_mail ); + void slotMailCount( int unread_mail, int new_mail ); /** * @brief slotDefaultIconTypeChange. Slot for handling default icon type change signals. @@ -276,17 +278,17 @@ class SysTrayXStatusNotifier : public KStatusNotifierItem QByteArray m_icon_data; /** - * @brief m_show_number. Show the unread mail count. + * @brief m_show_number. Show the unread/new mail count. */ bool m_show_number; /** - * @brief m_number_color. Color of the unread mail number. + * @brief m_number_color. Color of the unread/new mail number. */ QString m_number_color; /** - * @brief m_number_size. Size of the unread mail number. + * @brief m_number_size. Size of the unread/new mail number. */ int m_number_size; @@ -304,6 +306,11 @@ class SysTrayXStatusNotifier : public KStatusNotifierItem * @brief m_unread_mail. Storage for the number of unread mails. */ int m_unread_mail; + + /** + * @brief m_new_mail. Storage for the number of new mails. + */ + int m_new_mail; }; #endif // SYSTRAYXSTATUSNOTIFIER_H diff --git a/webext/background.js b/webext/background.js index badfa69..f2ec9df 100644 --- a/webext/background.js +++ b/webext/background.js @@ -147,17 +147,10 @@ SysTrayX.Messaging = { SysTrayX.Messaging.listenerFolderDeleted ); - if (SysTrayX.Messaging.countType === "0") { - // Get the unread count - const getCountUnreadPromise = () => - new Promise((res) => res(SysTrayX.Messaging.countUnread())); - await getCountUnreadPromise(); - } else { - // Update new count - const getCountNewPromise = () => - new Promise((res) => res(SysTrayX.Messaging.countNew())); - await getCountNewPromise(); - } + // Get the mail count + const getCountPromise = () => + new Promise((res) => res(SysTrayX.Messaging.countMail())); + await getCountPromise(); // Set count listener browser.folders.onFolderInfoChanged.addListener( @@ -200,10 +193,7 @@ SysTrayX.Messaging = { // ); } - if (SysTrayX.Messaging.countType === "1") { - getNewMailCount(); - // console.debug("listenerNewMail: New count"); - } + getMailCount(); }, listenerFolderCreated: function (createdFolder) { @@ -248,38 +238,32 @@ SysTrayX.Messaging = { SysTrayX.Messaging.unread[folder.accountId][folder.path] = folderInfo.unreadMessageCount; - if (SysTrayX.Messaging.countType === "0") { - getUnreadMailCount(); - // console.debug("listenerFolderInfoChanged: Unread count"); - } else { - // Check if the new mails have been read, remove from new storage - const messages = SysTrayX.Messaging.new[folder.accountId][folder.path]; + // Check if the new mails have been read, remove from new storage + const messages = SysTrayX.Messaging.new[folder.accountId][folder.path]; - if (messages.length > 0) { - const newMessages = []; - for (let i = 0; i < messages.length; ++i) { - const message = messages[i]; + if (messages.length > 0) { + const newMessages = []; + for (let i = 0; i < messages.length; ++i) { + const message = messages[i]; - const getHeaderPromise = (messageId) => - new Promise((res) => res(messenger.messages.get(messageId))); - const header = await getHeaderPromise(message.id); + const getHeaderPromise = (messageId) => + new Promise((res) => res(messenger.messages.get(messageId))); + const header = await getHeaderPromise(message.id); - if (!header.read) { - newMessages.push(message); - } + if (!header.read) { + newMessages.push(message); } - SysTrayX.Messaging.new[folder.accountId][folder.path] = [ - ...newMessages, - ]; - - getNewMailCount(); - // console.debug("listenerFolderInfoChanged: New count"); } + SysTrayX.Messaging.new[folder.accountId][folder.path] = [ + ...newMessages, + ]; } + + getMailCount(); } }, - countUnread: async function () { + countMail: async function () { for (const filter of SysTrayX.Messaging.filters) { for (const path of filter.folders) { const folder = { @@ -300,40 +284,6 @@ SysTrayX.Messaging = { SysTrayX.Messaging.unread[folder.accountId] = {}; } - SysTrayX.Messaging.unread[folder.accountId][folder.path] = - mailFolderInfo.unreadMessageCount; - } - } - } - - let count = 0; - Object.keys(SysTrayX.Messaging.unread).forEach((key) => - Object.keys(SysTrayX.Messaging.unread[key]).forEach( - (path) => (count = count + SysTrayX.Messaging.unread[key][path]) - ) - ); - - //console.debug("countUnread: " + count); - SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); - }, - - countNew: async function () { - for (const filter of SysTrayX.Messaging.filters) { - for (const path of filter.folders) { - const folder = { - accountId: filter.accountId, - path: path, - }; - - let mailFolderInfo = {}; - try { - mailFolderInfo = await browser.folders.getFolderInfo(folder); - } catch (err) { - console.debug("Filter error: " + err); - console.debug("Filter error: " + JSON.stringify(folder)); - } - - if (mailFolderInfo.unreadMessageCount !== undefined) { if (SysTrayX.Messaging.new[folder.accountId] === undefined) { SysTrayX.Messaging.new[folder.accountId] = {}; } @@ -344,21 +294,29 @@ SysTrayX.Messaging = { SysTrayX.Messaging.new[folder.accountId][folder.path] = []; } - // SysTrayX.Messaging.unread[folder.accountId][folder.path] = - // mailFolderInfo.unreadMessageCount; + SysTrayX.Messaging.unread[folder.accountId][folder.path] = + mailFolderInfo.unreadMessageCount; + } } } - let count = 0; - Object.keys(SysTrayX.Messaging.new).forEach((key) => - Object.keys(SysTrayX.Messaging.new[key]).forEach( - (path) => (count = count + SysTrayX.Messaging.new[key][path].length) + let unreadCount = 0; + Object.keys(SysTrayX.Messaging.unread).forEach((key) => + Object.keys(SysTrayX.Messaging.unread[key]).forEach( + (path) => (unreadCount = unreadCount + SysTrayX.Messaging.unread[key][path]) ) ); - //console.debug("countNew: " + count); - SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); + let newCount = 0; + Object.keys(SysTrayX.Messaging.new).forEach((key) => + Object.keys(SysTrayX.Messaging.new[key]).forEach( + (path) => (newCount = newCount + SysTrayX.Messaging.new[key][path].length) + ) + ); + + //console.debug("countMail: " + unreadCount + ", " + newCount); + SysTrayX.Link.postSysTrayXMessage( { mailCount: { unread: unreadCount, new: newCount } } ); }, onCloseButton: function () { @@ -384,11 +342,7 @@ SysTrayX.Messaging = { if (SysTrayX.Info.browserInfo.majorVersion < 91) { browser.folderChange.setFilters(SysTrayX.Messaging.filters); } else { - if (SysTrayX.Messaging.countType === "0") { - getUnreadMailCount(); - } else { - getNewMailCount(); - } + getMailCount(); } } @@ -414,11 +368,7 @@ SysTrayX.Messaging = { if (SysTrayX.Info.browserInfo.majorVersion < 91) { browser.folderChange.setCountType(Number(SysTrayX.Messaging.countType)); } else { - if (SysTrayX.Messaging.countType === "0") { - getUnreadMailCount(); - } else { - getNewMailCount(); - } + getMailCount(); } } @@ -440,7 +390,7 @@ SysTrayX.Messaging = { // unreadCb: function (count) { //console.debug("unreadCb: " + count); - SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); + SysTrayX.Link.postSysTrayXMessage( { mailCount: { unread: count, new: 0 } } ); }, // @@ -707,7 +657,7 @@ SysTrayX.Link = { postSysTrayXMessage: function (object) { // Send object (will be stringified by postMessage) - //console.debug("postSysTrayXMessage: " + JSON.stringify(object)); + console.debug("postSysTrayXMessage: " + JSON.stringify(object)); SysTrayX.Link.portSysTrayX.postMessage(object); }, @@ -914,9 +864,7 @@ SysTrayX.Window = { ] = []; } - if (SysTrayX.Messaging.countType === "1") { - getNewMailCount(); - } + getMailCount(); } SysTrayX.Messaging.displayedFolder = displayedFolder; diff --git a/webext/js/defaults.js b/webext/js/defaults.js index 6bad602..b251c1f 100644 --- a/webext/js/defaults.js +++ b/webext/js/defaults.js @@ -371,33 +371,22 @@ async function addFolderToFilters(newFolder) { } } -// Count the unread mail -const getUnreadMailCount = () => { - let count = 0; +// Count the unread and new mails +const getMailCount = () => { + let unreadCount = 0; + let newCount = 0; SysTrayX.Messaging.filters.forEach((filter) => { const accountId = filter.accountId; filter.folders.forEach((path) => { if (SysTrayX.Messaging.unread[accountId] !== undefined) { if (SysTrayX.Messaging.unread[accountId][path] !== undefined) { - count = count + SysTrayX.Messaging.unread[accountId][path]; + unreadCount = unreadCount + SysTrayX.Messaging.unread[accountId][path]; } } - }); - }); - //console.debug("getUnreadMailCount: " + count); - SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); -}; - -// Count the new mail -const getNewMailCount = () => { - let count = 0; - SysTrayX.Messaging.filters.forEach((filter) => { - const accountId = filter.accountId; - filter.folders.forEach((path) => { if (SysTrayX.Messaging.new[accountId] !== undefined) { if (SysTrayX.Messaging.new[accountId][path] !== undefined) { - count = count + SysTrayX.Messaging.new[accountId][path].length; + newCount = newCount + SysTrayX.Messaging.new[accountId][path].length; } } }); @@ -406,6 +395,6 @@ const getNewMailCount = () => { //console.debug("Filters: " + JSON.stringify(SysTrayX.Messaging.filters)); //console.debug("New: " + JSON.stringify(SysTrayX.Messaging.new)); - //console.debug("getNewMailCount: " + count); - SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); + //console.debug("getMailCount: " + unreadCount + ", " + newCount); + SysTrayX.Link.postSysTrayXMessage( { mailCount: { unread: unreadCount, new: newCount } } ); };