From 6116188e8b1725d69e1f41d7cdd3d0d4b164e0ce Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 23 Feb 2020 02:41:19 +0300 Subject: [PATCH] Notification sound tray menu option --- Telegram/Resources/langs/lang.strings | 3 +++ Telegram/Resources/langs/rewrites/ru.json | 4 ++- Telegram/SourceFiles/mainwindow.cpp | 27 +++++++++++++++++++ Telegram/SourceFiles/mainwindow.h | 1 + Telegram/SourceFiles/storage/localstorage.cpp | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f20737722..aafc22ea1 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2391,4 +2391,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_adaptive_bubbles" = "Adaptive bubbles"; +"ktg_settings_disable_sound_from_tray" = "Disable sound"; +"ktg_settings_enable_sound_from_tray" = "Enable sound"; + // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index dad3d5342..471f0d2da 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -88,5 +88,7 @@ "ktg_settings_call_confirm": "Подтверждение перед звонком", "ktg_call_sure": "Вы уверены, что хотите позвонить этому пользователю?", "ktg_call_button": "Позвонить", - "ktg_settings_adaptive_bubbles": "Адаптивные пузырьки сообщений" + "ktg_settings_adaptive_bubbles": "Адаптивные пузырьки сообщений", + "ktg_settings_disable_sound_from_tray": "Отключить звук", + "ktg_settings_enable_sound_from_tray": "Включить звук" } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 213a2e68a..2e29a566f 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -142,11 +142,16 @@ void MainWindow::createTrayIconMenu() { ? tr::lng_disable_notifications_from_tray(tr::now) : tr::lng_enable_notifications_from_tray(tr::now); + auto soundActionText = Global::SoundNotify() + ? tr::ktg_settings_disable_sound_from_tray(tr::now) + : tr::ktg_settings_enable_sound_from_tray(tr::now); + if (Platform::IsLinux()) { trayIconMenu->addAction(tr::ktg_open_from_tray(tr::now), this, SLOT(showFromTray())); } trayIconMenu->addAction(tr::lng_minimize_to_tray(tr::now), this, SLOT(minimizeToTray())); trayIconMenu->addAction(notificationActionText, this, SLOT(toggleDisplayNotifyFromTray())); + trayIconMenu->addAction(soundActionText, this, SLOT(toggleSoundNotifyFromTray())); trayIconMenu->addAction(tr::ktg_quit_from_tray(tr::now), this, SLOT(quitFromTray())); initTrayMenuHook(); @@ -613,6 +618,12 @@ void MainWindow::updateTrayMenu(bool force) { : tr::lng_enable_notifications_from_tray(tr::now); notificationAction->setText(notificationActionText); + auto soundAction = actions.at(Platform::IsLinux() ? 3 : 2); + auto soundActionText = Global::SoundNotify() + ? tr::ktg_settings_disable_sound_from_tray(tr::now) + : tr::ktg_settings_enable_sound_from_tray(tr::now); + soundAction->setText(soundActionText); + psTrayMenuUpdated(); } @@ -782,6 +793,22 @@ void MainWindow::toggleDisplayNotifyFromTray() { } } +void MainWindow::toggleSoundNotifyFromTray() { + if (Core::App().locked()) { + if (!isActive()) showFromTray(); + Ui::show(Box(tr::lng_passcode_need_unblock(tr::now))); + return; + } + if (!account().sessionExists()) { + return; + } + + Global::SetSoundNotify(!Global::SoundNotify()); + Local::writeUserSettings(); + account().session().notifications().settingsChanged().notify( + Window::Notifications::ChangeType::SoundEnabled); +} + void MainWindow::closeEvent(QCloseEvent *e) { if (Core::Sandbox::Instance().isSavingSession()) { e->accept(); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index d9b6fae0c..2e923dfc8 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -135,6 +135,7 @@ public slots: void quitFromTray(); void showFromTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); void toggleDisplayNotifyFromTray(); + void toggleSoundNotifyFromTray(); void onClearFinished(int task, void *manager); void onClearFailed(int task, void *manager); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index f42220469..2a3039f90 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -1113,6 +1113,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting if (!_checkStreamStatus(stream)) return false; Global::SetSoundNotify(v == 1); + if (App::wnd()) App::wnd()->updateTrayMenu(); } break; case dbiAutoDownloadOld: {