From 7989435e87ec80351096f5b8b54315c71b8deed5 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Thu, 2 Nov 2023 17:11:08 +0100 Subject: [PATCH] Add new option --- app/SysTray-X/SysTray-X-app/preferences.cpp | 26 ++++++++++++ app/SysTray-X/SysTray-X-app/preferences.h | 24 +++++++++++ .../SysTray-X-app/preferencesdialog.cpp | 27 ++++++++++++ .../SysTray-X-app/preferencesdialog.h | 11 +++++ app/SysTray-X/SysTray-X-app/systrayx.cpp | 2 + app/SysTray-X/SysTray-X-app/systrayxlink.cpp | 22 ++++++++++ app/SysTray-X/SysTray-X-app/systrayxlink.h | 5 +++ webext/_locales/de/messages.json | 5 +++ webext/_locales/el/messages.json | 5 +++ webext/_locales/en-US/messages.json | 5 +++ webext/_locales/it/messages.json | 5 +++ webext/_locales/nl/messages.json | 5 +++ webext/_locales/pt-BR/messages.json | 5 +++ webext/_locales/ru/messages.json | 5 +++ webext/options.html | 9 ++++ webext/options.js | 41 +++++++++++++++++++ 16 files changed, 202 insertions(+) diff --git a/app/SysTray-X/SysTray-X-app/preferences.cpp b/app/SysTray-X/SysTray-X-app/preferences.cpp index e5a4a7a..f58db68 100644 --- a/app/SysTray-X/SysTray-X-app/preferences.cpp +++ b/app/SysTray-X/SysTray-X-app/preferences.cpp @@ -913,6 +913,32 @@ void Preferences::setCloseAppArgs( QString args ) } +/* + * Get the API count method state. + */ +bool Preferences::getApiCountMethod() const +{ + return m_api_count_method; +} + + +/* + * Set the API count method state. + */ +void Preferences::setApiCountMethod( bool state ) +{ + if( m_api_count_method != state ) + { + m_api_count_method = state; + + /* + * Tell the world the new preference + */ + emit signalApiCountMethodChange(); + } +} + + /* * Get the debug state. */ diff --git a/app/SysTray-X/SysTray-X-app/preferences.h b/app/SysTray-X/SysTray-X-app/preferences.h index b4b6964..642019d 100644 --- a/app/SysTray-X/SysTray-X-app/preferences.h +++ b/app/SysTray-X/SysTray-X-app/preferences.h @@ -564,6 +564,20 @@ class Preferences : public QObject */ void setCloseAppArgs( QString args ); + /** + * @brief getApiCountMethod. Get the API count method state. + * + * @return The state. + */ + bool getApiCountMethod() const; + + /** + * @brief setApiCountMethod. Set the API count method state. + * + * @param state The state. + */ + void setApiCountMethod( bool state ); + /** * @brief getDebug. Get the debug windows state. * @@ -745,6 +759,11 @@ class Preferences : public QObject */ void signalCloseAppArgsChange(); + /** + * @brief signalApiCountMethodChange + */ + void signalApiCountMethodChange(); + private: /** @@ -931,6 +950,11 @@ class Preferences : public QObject */ QString m_close_app_args; + /** + * @brief m_api_count_method. The API count method state. + */ + bool m_api_count_method; + /** * @brief m_debug. Display debug window. */ diff --git a/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp b/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp index 04bae40..144261f 100644 --- a/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp +++ b/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp @@ -115,6 +115,15 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi m_ui->newIndicatorTypeGroup->setId( m_ui->newIconStarRadioButton, Preferences::PREF_NEW_INDICATOR_STAR ); m_ui->newIndicatorTypeGroup->setId( m_ui->newShadeRadioButton, Preferences::PREF_NEW_INDICATOR_SHADE); + if( m_pref->getBrowserVersion().split(".")[0].toInt() < 115 ) + { + m_ui->specialOptionsGroupBox->setVisible( false ); + } + else + { + setApiCountMethod( m_pref->getApiCountMethod() ); + } + /* * Signals and slots */ @@ -519,6 +528,15 @@ void PreferencesDialog::setCloseAppArgs( QString args ) } +/* + * Set the API count method state + */ +void PreferencesDialog::setApiCountMethod( bool state ) +{ + m_ui->apiCountMethod->setChecked( state ); +} + + /* * Handle show dialog signal */ @@ -994,3 +1012,12 @@ void PreferencesDialog::slotCloseAppArgsChange() { setCloseAppArgs( m_pref->getCloseAppArgs() ); } + + +/* + * Handle the API count method change signal + */ +void PreferencesDialog::slotApiCountMethodChange() +{ + setApiCountMethod( m_pref->getApiCountMethod() ); +} diff --git a/app/SysTray-X/SysTray-X-app/preferencesdialog.h b/app/SysTray-X/SysTray-X-app/preferencesdialog.h index 91f73b2..546a44b 100644 --- a/app/SysTray-X/SysTray-X-app/preferencesdialog.h +++ b/app/SysTray-X/SysTray-X-app/preferencesdialog.h @@ -258,6 +258,12 @@ class PreferencesDialog : public QDialog */ void setCloseAppArgs( QString args ); + /** + * @brief setApiCountMethod. Set the API count method state. + * + * @param state The state. + */ + void setApiCountMethod( bool state ); signals: @@ -410,6 +416,11 @@ class PreferencesDialog : public QDialog */ void slotCloseAppArgsChange(); + /** + * @brief slotApiCountMethodChange. Slot for handling the API count methid change. + */ + void slotApiCountMethodChange(); + private slots: /** diff --git a/app/SysTray-X/SysTray-X-app/systrayx.cpp b/app/SysTray-X/SysTray-X-app/systrayx.cpp index 8450d5a..9a5e204 100644 --- a/app/SysTray-X/SysTray-X-app/systrayx.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayx.cpp @@ -140,6 +140,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_preferences, &Preferences::signalStartAppArgsChange, m_pref_dialog, &PreferencesDialog::slotStartAppArgsChange ); connect( m_preferences, &Preferences::signalCloseAppChange, m_pref_dialog, &PreferencesDialog::slotCloseAppChange ); connect( m_preferences, &Preferences::signalCloseAppArgsChange, m_pref_dialog, &PreferencesDialog::slotCloseAppArgsChange ); + connect( m_preferences, &Preferences::signalApiCountMethodChange, m_pref_dialog, &PreferencesDialog::slotApiCountMethodChange ); connect( m_preferences, &Preferences::signalDebugChange, m_pref_dialog, &PreferencesDialog::slotDebugChange ); connect( m_preferences, &Preferences::signalDefaultIconTypeChange, m_link, &SysTrayXLink::slotDefaultIconTypeChange ); @@ -167,6 +168,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_preferences, &Preferences::signalStartAppArgsChange, m_link, &SysTrayXLink::slotStartAppArgsChange ); connect( m_preferences, &Preferences::signalCloseAppChange, m_link, &SysTrayXLink::slotCloseAppChange ); connect( m_preferences, &Preferences::signalCloseAppArgsChange, m_link, &SysTrayXLink::slotCloseAppArgsChange ); + connect( m_preferences, &Preferences::signalApiCountMethodChange, m_link, &SysTrayXLink::slotApiCountMethodChange ); connect( m_preferences, &Preferences::signalDebugChange, m_link, &SysTrayXLink::slotDebugChange ); connect( m_preferences, &Preferences::signalHideDefaultIconChange, this, &SysTrayX::slotSelectIconObjectPref ); diff --git a/app/SysTray-X/SysTray-X-app/systrayxlink.cpp b/app/SysTray-X/SysTray-X-app/systrayxlink.cpp index a8e140f..c50b28f 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxlink.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayxlink.cpp @@ -857,6 +857,16 @@ void SysTrayXLink::DecodePreferences( const QJsonObject& pref ) m_pref->setCloseAppArgs( args ); } + if( pref.contains( "apiCountMethod" ) && pref[ "apiCountMethod" ].isString() ) + { + bool api_count_method = pref[ "apiCountMethod" ].toString() == "true"; + + /* + * Store the new API cont method state + */ + m_pref->setApiCountMethod( api_count_method ); + } + if( pref.contains( "debug" ) && pref[ "debug" ].isString() ) { bool debug = pref[ "debug" ].toString() == "true"; @@ -937,6 +947,7 @@ void SysTrayXLink::EncodePreferences( const Preferences& pref ) prefObject.insert("numberMargins", marginsObject ); prefObject.insert("countType", QJsonValue::fromVariant( QString::number( pref.getCountType() ) ) ); prefObject.insert("startupDelay", QJsonValue::fromVariant( QString::number( pref.getStartupDelay() ) ) ); + prefObject.insert("apiCountMethod", QJsonValue::fromVariant( QString( pref.getApiCountMethod() ? "true" : "false" ) ) ); prefObject.insert("startApp", QJsonValue::fromVariant( pref.getStartApp() ) ); prefObject.insert("startAppArgs", QJsonValue::fromVariant( pref.getStartAppArgs() ) ); @@ -1283,6 +1294,17 @@ void SysTrayXLink::slotCloseAppArgsChange() } +/* + * Handle a API count method change signal + */ +void SysTrayXLink::slotApiCountMethodChange() +{ + if( m_pref->getAppPrefChanged() ) + { + sendPreferences(); + } +} + /* * Handle a debug state change signal */ diff --git a/app/SysTray-X/SysTray-X-app/systrayxlink.h b/app/SysTray-X/SysTray-X-app/systrayxlink.h index 7c49fdb..238b03c 100644 --- a/app/SysTray-X/SysTray-X-app/systrayxlink.h +++ b/app/SysTray-X/SysTray-X-app/systrayxlink.h @@ -389,6 +389,11 @@ class SysTrayXLink : public QObject */ void slotCloseAppArgsChange(); + /** + * @brief slotApiCountMethodChange. Slot for handling the API count method change signals. + */ + void slotApiCountMethodChange(); + private slots: /** diff --git a/webext/_locales/de/messages.json b/webext/_locales/de/messages.json index 1f6311f..372fea4 100644 --- a/webext/_locales/de/messages.json +++ b/webext/_locales/de/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "API-Zählmethode", + "description": "API count method" + }, + "count_number_options": { "message": "Nummereigenschaften", "description": "Caption for Number options" diff --git a/webext/_locales/el/messages.json b/webext/_locales/el/messages.json index c96980a..c833f8e 100644 --- a/webext/_locales/el/messages.json +++ b/webext/_locales/el/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "Μέθοδος καταμέτρησης API", + "description": "API count method" + }, + "count_number_options": { "message": "Αριθμός", "description": "Caption for Number options" diff --git a/webext/_locales/en-US/messages.json b/webext/_locales/en-US/messages.json index f9c7be4..56b1eca 100644 --- a/webext/_locales/en-US/messages.json +++ b/webext/_locales/en-US/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "API count method", + "description": "API count method" + }, + "count_number_options": { "message": "Number", "description": "Caption for Number options" diff --git a/webext/_locales/it/messages.json b/webext/_locales/it/messages.json index 6791184..8d8f244 100644 --- a/webext/_locales/it/messages.json +++ b/webext/_locales/it/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "Metodo di conteggio API", + "description": "API count method" + }, + "count_number_options": { "message": "Proprietà numero", "description": "Caption for Number options" diff --git a/webext/_locales/nl/messages.json b/webext/_locales/nl/messages.json index 06269c3..681f35f 100644 --- a/webext/_locales/nl/messages.json +++ b/webext/_locales/nl/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "API tel methode", + "description": "API count method" + }, + "count_number_options": { "message": "Nummer opties", "description": "Caption for Number options" diff --git a/webext/_locales/pt-BR/messages.json b/webext/_locales/pt-BR/messages.json index a1f79d5..813df5b 100644 --- a/webext/_locales/pt-BR/messages.json +++ b/webext/_locales/pt-BR/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "Método de contagem de API", + "description": "API count method" + }, + "count_number_options": { "message": "Número", "description": "Caption for Number options" diff --git a/webext/_locales/ru/messages.json b/webext/_locales/ru/messages.json index 3befdc5..4820685 100644 --- a/webext/_locales/ru/messages.json +++ b/webext/_locales/ru/messages.json @@ -244,6 +244,11 @@ "description": "Count new mails" }, + "count_api_count_method": { + "message": "Метод подсчета API", + "description": "API count method" + }, + "count_number_options": { "message": "Настройки индикатора кол-ва", "description": "Caption for Number options" diff --git a/webext/options.html b/webext/options.html index 39ef51b..03eb0cd 100644 --- a/webext/options.html +++ b/webext/options.html @@ -419,6 +419,15 @@ +
+
+ + +
+
+
__MSG_count_number_options__ diff --git a/webext/options.js b/webext/options.js index 459ca19..f251cc1 100644 --- a/webext/options.js +++ b/webext/options.js @@ -222,6 +222,14 @@ SysTrayX.SaveOptions = { startupDelay: startupDelay, }); + // + // Save API count method state + // + const apiCountMethod = document.querySelector('input[name="apiCountMethod"]').checked; + await storage().set({ + apiCountMethod: `${apiCountMethod}`, + }); + // // Save number color // @@ -496,6 +504,16 @@ SysTrayX.RestoreOptions = { SysTrayX.RestoreOptions.ontartupDelayError ); + // + // Restore API count method state + // + await storage() + .get("apiCountMethod") + .then( + SysTrayX.RestoreOptions.setApiCountMethod, + SysTrayX.RestoreOptions.onApiCountMethodError + ); + // // Restore number color // @@ -924,6 +942,20 @@ SysTrayX.RestoreOptions = { console.log(`StartupDelay Error: ${error}`); }, + // + // Restore API count method state callbacks + // + setApiCountMethod: function (result) { + const apiCountMethod = result.apiCountMethod || "false"; + + const checkbox = document.querySelector(`input[name="apiCountMethod"]`); + checkbox.checked = apiCountMethod === "true"; + }, + + onApiCountMethodError: function (error) { + console.log(`ApiCountMethod Error: ${error}`); + }, + // // Restore number color // @@ -1278,6 +1310,11 @@ SysTrayX.StorageChanged = { startupDelay: changes[item].newValue, }); } + if (item === "apiCountMethod") { + SysTrayX.RestoreOptions.setApiCountMethod({ + apiCountMethod: changes[item].newValue, + }); + } if (item === "numberColor") { SysTrayX.RestoreOptions.setNumberColor({ numberColor: changes[item].newValue, @@ -1401,6 +1438,10 @@ async function start() { document.getElementById("kdeintegration").style.display = "none"; } + if (SysTrayX.Info.browserInfo.majorVersion < 115) { + document.getElementById("apicountmethod").style.display = "none"; + } + // Setup account tree const accountsInitPromise = () => new Promise((res) => res(SysTrayX.Accounts.init()));