From 5f18bf3d3974d910420e4a205dbfb004a00cb8fb Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sat, 9 May 2020 13:30:55 +0200 Subject: [PATCH] Add count type preference --- app/SysTray-X/preferences.cpp | 26 ++ app/SysTray-X/preferences.h | 32 ++ app/SysTray-X/preferences.ui | 536 +++++++++++++++------------- app/SysTray-X/preferencesdialog.cpp | 25 ++ app/SysTray-X/preferencesdialog.h | 12 + app/SysTray-X/systrayx.cpp | 2 + app/SysTray-X/systrayxlink.cpp | 24 ++ app/SysTray-X/systrayxlink.h | 5 + 8 files changed, 420 insertions(+), 242 deletions(-) diff --git a/app/SysTray-X/preferences.cpp b/app/SysTray-X/preferences.cpp index b9cfb06..ae1c5ba 100644 --- a/app/SysTray-X/preferences.cpp +++ b/app/SysTray-X/preferences.cpp @@ -40,6 +40,7 @@ Preferences::Preferences( QObject *parent ) : QObject( parent ) m_show_number = true; m_number_color = "#000000"; + m_count_type = PREF_COUNT_UNREAD; m_minimize_type = PREF_DEFAULT_MINIMIZE; m_start_minimized = false; @@ -266,6 +267,31 @@ void Preferences::setNumberColor( QString color ) } +/* + * Get the count type. + */ +Preferences::CountType Preferences::getCountType() const +{ + return m_count_type; +} + + +/* + * Set the count type. + */ +void Preferences::setCountType( CountType count_type ) +{ + if( m_count_type != count_type) + { + m_count_type = count_type; + + /* + * Tell the world the new preference + */ + emit signalCountTypeChange(); + } +} + /* * Get the icon type. */ diff --git a/app/SysTray-X/preferences.h b/app/SysTray-X/preferences.h index 9c8cd35..688306f 100644 --- a/app/SysTray-X/preferences.h +++ b/app/SysTray-X/preferences.h @@ -39,6 +39,14 @@ class Preferences : public QObject PREF_CUSTOM_ICON }; + /* + * Count types + */ + enum CountType { + PREF_COUNT_UNREAD = 0, + PREF_COUNT_NEW + }; + /* * Window states */ @@ -197,6 +205,20 @@ class Preferences : public QObject */ void setNumberColor( QString color ); + /** + * @brief getCountType. Get the count type. + * + * @return The count type. + */ + CountType getCountType() const; + + /** + * @brief setCountType. Set the count type. + * + * @param The count type. + */ + void setCountType( CountType count_type ); + /** * @brief getMinimizeType. Get the minimize type. * @@ -324,6 +346,11 @@ class Preferences : public QObject */ void signalNumberColorChange(); + /** + * @brief signalCountTypeChange. Signal a count type change. + */ + void signalCountTypeChange(); + /** * @brief signalMinimizeTypeChange. Signal a minimize type change. */ @@ -396,6 +423,11 @@ class Preferences : public QObject */ QString m_number_color; + /** + * @brief m_count_type. Selected count type. + */ + CountType m_count_type; + /** * @brief m_minimize_type. Selected minimize type. */ diff --git a/app/SysTray-X/preferences.ui b/app/SysTray-X/preferences.ui index 7746ce8..7a3f31e 100644 --- a/app/SysTray-X/preferences.ui +++ b/app/SysTray-X/preferences.ui @@ -6,8 +6,8 @@ 0 0 - 583 - 261 + 676 + 313 @@ -17,16 +17,257 @@ :/files/icons/SysTray-X.png:/files/icons/SysTray-X.png - - - - - - - Number properties - - - + + + + + Windows + + + + + + + + Minimize + + + + + + Default minimize + + + false + + + minimizeTypeGroup + + + + + + + Minimize to tray, method 1 + + + true + + + minimizeTypeGroup + + + + + + + Minimize to tray, method 2 + + + minimizeTypeGroup + + + + + + + + + + Start application minimized + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Mail notification icon + + + + + + + + QLayout::SetFixedSize + + + + + Blank icon + + + true + + + iconTypeGroup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QLayout::SetFixedSize + + + + + New mail icon + + + iconTypeGroup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QLayout::SetMaximumSize + + + + + Custom icon + + + iconTypeGroup + + + + + + + + + + + + + + Choose + + + false + + + + + + + + + + + + + + Mail actions + + + + + + + + Poll startup delay + + + + + + + 1 + + + 999 + + + 60 + + + + + + + Poll interval + + + + + + + 1 + + + 999 + + + 60 + + + + + + + + + + + + Number properties + + + + + @@ -45,8 +286,8 @@ - 40 - 20 + 30 + 37 @@ -75,268 +316,78 @@ - 40 - 20 + 31 + 37 - - - - - - - Mail actions - - - - - - - - Poll startup delay - - - - - - - 1 - - - 999 - - - 60 - - - - - - - Poll interval - - - - - - - 1 - - - 999 - - - 60 - - - - - - - - - - - - Windows - - - + - - - Minimize + + + Message count type: - - - - - Default minimize - - - false - - - minimizeTypeGroup - - - - - - - Minimize to tray, method 1 - - - true - - - minimizeTypeGroup - - - - - - - Minimize to tray, method 2 - - - minimizeTypeGroup - - - - - - - Start application minimized - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Mail notification icon - - - - - - - - QLayout::SetFixedSize - + - + - Blank icon + Unread true - iconTypeGroup + countTypeGroup - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - QLayout::SetFixedSize - - - + - New mail icon + New - iconTypeGroup + countTypeGroup - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - QLayout::SetMaximumSize - - - - - Custom icon - - - iconTypeGroup - - - - - - - - - - - - - - Choose - - - false - - - - - - - - - Display debug window - - - - + + + - + + + + Display debug window + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + Qt::Horizontal @@ -370,7 +421,8 @@ - + + diff --git a/app/SysTray-X/preferencesdialog.cpp b/app/SysTray-X/preferencesdialog.cpp index 9f5fab0..1b92b66 100644 --- a/app/SysTray-X/preferencesdialog.cpp +++ b/app/SysTray-X/preferencesdialog.cpp @@ -51,6 +51,12 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi m_ui->iconTypeGroup->setId( m_ui->newMailButton, Preferences::PREF_NEWMAIL_ICON ); m_ui->iconTypeGroup->setId( m_ui->customRadioButton, Preferences::PREF_CUSTOM_ICON ); + /* + * Set count type button Ids + */ + m_ui->countTypeGroup->setId( m_ui->unreadRadioButton, Preferences::PREF_COUNT_UNREAD ); + m_ui->countTypeGroup->setId( m_ui->newRadioButton, Preferences::PREF_COUNT_NEW ); + /* * Set defaults */ @@ -184,6 +190,15 @@ void PreferencesDialog::setNumberColor( QString color ) } +/* + * Set the count type + */ +void PreferencesDialog::setCountType( Preferences::CountType count_type ) +{ + ( m_ui->countTypeGroup->button( count_type ) )->setChecked( true ); +} + + /* * Handle the accept signal */ @@ -209,6 +224,7 @@ void PreferencesDialog::slotAccept() m_pref->setShowNumber( m_ui->showNumberCheckBox->isChecked() ); m_pref->setNumberColor( m_number_color ); + m_pref->setCountType( static_cast< Preferences::CountType >( m_ui->countTypeGroup->checkedId() ) ); m_pref->setDebug( m_ui->debugWindowCheckBox->isChecked() ); @@ -363,3 +379,12 @@ void PreferencesDialog::slotNumberColorChange() { setNumberColor( m_pref->getNumberColor() ); } + + +/* + * Handle the count type change signal + */ +void PreferencesDialog::slotCountTypeChange() +{ + setCountType( m_pref->getCountType() ); +} diff --git a/app/SysTray-X/preferencesdialog.h b/app/SysTray-X/preferencesdialog.h index acf6d72..68b4731 100644 --- a/app/SysTray-X/preferencesdialog.h +++ b/app/SysTray-X/preferencesdialog.h @@ -110,6 +110,13 @@ class PreferencesDialog : public QDialog */ void setNumberColor( QString color ); + /** + * @brief setCountType. Set the count type. + * + * @param count_type The count type. + */ + void setCountType( Preferences::CountType count_type ); + signals: /** @@ -171,6 +178,11 @@ class PreferencesDialog : public QDialog */ void slotNumberColorChange(); + /** + * @brief slotCountTypeChange. Slot for handling count type change. + */ + void slotCountTypeChange(); + private slots: /** diff --git a/app/SysTray-X/systrayx.cpp b/app/SysTray-X/systrayx.cpp index 08ce593..a697d96 100644 --- a/app/SysTray-X/systrayx.cpp +++ b/app/SysTray-X/systrayx.cpp @@ -92,6 +92,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_preferences, &Preferences::signalIconDataChange, m_pref_dialog, &PreferencesDialog::slotIconDataChange ); connect( m_preferences, &Preferences::signalShowNumberChange, m_pref_dialog, &PreferencesDialog::slotShowNumberChange ); connect( m_preferences, &Preferences::signalNumberColorChange, m_pref_dialog, &PreferencesDialog::slotNumberColorChange ); + connect( m_preferences, &Preferences::signalCountTypeChange, m_pref_dialog, &PreferencesDialog::slotCountTypeChange ); connect( m_preferences, &Preferences::signalMinimizeTypeChange, m_pref_dialog, &PreferencesDialog::slotMinimizeTypeChange ); connect( m_preferences, &Preferences::signalStartMinimizedChange, m_pref_dialog, &PreferencesDialog::slotStartMinimizedChange ); connect( m_preferences, &Preferences::signalPollStartupDelayChange, m_pref_dialog, &PreferencesDialog::slotPollStartupDelayChange ); @@ -102,6 +103,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_preferences, &Preferences::signalIconDataChange, m_link, &SysTrayXLink::slotIconDataChange ); connect( m_preferences, &Preferences::signalShowNumberChange, m_link, &SysTrayXLink::slotShowNumberChange ); connect( m_preferences, &Preferences::signalNumberColorChange, m_link, &SysTrayXLink::slotNumberColorChange ); + connect( m_preferences, &Preferences::signalCountTypeChange, m_link, &SysTrayXLink::slotCountTypeChange ); connect( m_preferences, &Preferences::signalMinimizeTypeChange, m_link, &SysTrayXLink::slotMinimizeTypeChange ); connect( m_preferences, &Preferences::signalStartMinimizedChange, m_link, &SysTrayXLink::slotStartMinimizedChange ); connect( m_preferences, &Preferences::signalPollStartupDelayChange, m_link, &SysTrayXLink::slotPollStartupDelayChange ); diff --git a/app/SysTray-X/systrayxlink.cpp b/app/SysTray-X/systrayxlink.cpp index c7a3bd2..ce5b2d2 100644 --- a/app/SysTray-X/systrayxlink.cpp +++ b/app/SysTray-X/systrayxlink.cpp @@ -473,6 +473,17 @@ void SysTrayXLink::DecodePreferences( const QJsonObject& pref ) m_pref->setNumberColor( number_color ); } + if( pref.contains( "countType" ) && pref[ "countType" ].isString() ) + { + Preferences::CountType count_type = static_cast< Preferences::CountType >( pref[ "countType" ].toString().toInt() ); + + /* + * Store the new icon type + */ + m_pref->setCountType( count_type ); + } + + if( pref.contains( "minimizeType" ) && pref[ "minimizeType" ].isString() ) { Preferences::MinimizeType minimize_type = static_cast< Preferences::MinimizeType >( pref[ "minimizeType" ].toString().toInt() ); @@ -544,6 +555,7 @@ void SysTrayXLink::EncodePreferences( const Preferences& pref ) prefObject.insert("icon", QJsonValue::fromVariant( QString( pref.getIconData().toBase64() ) ) ); prefObject.insert("showNumber", QJsonValue::fromVariant( QString( pref.getShowNumber() ? "true" : "false" ) ) ); prefObject.insert("numberColor", QJsonValue::fromVariant( QString( pref.getNumberColor() ) ) ); + prefObject.insert("countType", QJsonValue::fromVariant( QString::number( pref.getCountType() ) ) ); QJsonObject preferencesObject; preferencesObject.insert("preferences", prefObject ); @@ -682,3 +694,15 @@ void SysTrayXLink::slotNumberColorChange() sendPreferences(); } } + + +/* + * Handle the count type change signal + */ +void SysTrayXLink::slotCountTypeChange() +{ + if( m_pref->getAppPrefChanged() ) + { + sendPreferences(); + } +} diff --git a/app/SysTray-X/systrayxlink.h b/app/SysTray-X/systrayxlink.h index 6a03388..abdc4a2 100644 --- a/app/SysTray-X/systrayxlink.h +++ b/app/SysTray-X/systrayxlink.h @@ -230,6 +230,11 @@ class SysTrayXLink : public QObject */ void slotNumberColorChange(); + /** + * @brief slotCountTypeChange. Slot for handling count type change signals. + */ + void slotCountTypeChange(); + private slots: /**