diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index 308aa32269..bba20363f8 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -28,6 +28,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org "lng_menu_restart" = "Restart"; "lng_menu_back" = "Back"; +"lng_disable_notifications_from_tray" = "Disable notifications"; +"lng_enable_notifications_from_tray" = "Enable notifications"; "lng_open_from_tray" = "Open Telegram"; "lng_minimize_to_tray" = "Minimize to tray"; "lng_quit_from_tray" = "Quit Telegram"; diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index e3a9269920..59781258cf 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -857,6 +857,7 @@ void SettingsInner::updateSize(int32 newWidth) { } } + void SettingsInner::updateOnlineDisplay() { } @@ -1479,6 +1480,11 @@ void SettingsInner::onDesktopNotify() { } } +void SettingsInner::enableDisplayNotify(bool enable) +{ + _desktopNotify.setChecked(enable); +} + void SettingsInner::onSenderName() { _messagePreview.setDisabled(!_senderName.checked()); if (!_senderName.checked() && _messagePreview.checked()) { @@ -1863,6 +1869,11 @@ void SettingsWidget::updateWideMode() { } } +void SettingsWidget::updateDisplayNotify() +{ + _inner.enableDisplayNotify(cDesktopNotify()); +} + void SettingsWidget::updateOnlineDisplay() { _inner.updateOnlineDisplay(); } diff --git a/Telegram/SourceFiles/settingswidget.h b/Telegram/SourceFiles/settingswidget.h index a651250839..e0fc5dbb97 100644 --- a/Telegram/SourceFiles/settingswidget.h +++ b/Telegram/SourceFiles/settingswidget.h @@ -85,6 +85,7 @@ public: void updateChatBackground(); void needBackgroundUpdate(bool tile); + void enableDisplayNotify(bool enable); public slots: @@ -318,6 +319,8 @@ public: void updateOnlineDisplay(); void updateConnectionType(); + void updateDisplayNotify(); + void rpcInvalidate(); void usernameChanged(); diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index e76739576c..cb565642ba 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -449,10 +449,15 @@ void Window::firstShow() { trayIconMenu = new QMenu(this); trayIconMenu->setFont(QFont("Tahoma")); #endif + QString notificationItem = lang(cDesktopNotify() + ? lng_disable_notifications_from_tray : lng_enable_notifications_from_tray); + if (cPlatform() == dbipWindows || cPlatform() == dbipMac) { + trayIconMenu->addAction(notificationItem, this, SLOT(toggleDisplayNotifyFromTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true); } else { + trayIconMenu->addAction(notificationItem, this, SLOT(toggleDisplayNotifyFromTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_open_from_tray), this, SLOT(showFromTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true); @@ -1025,13 +1030,19 @@ void Window::updateTrayMenu(bool force) { bool active = isActive(false); if (cPlatform() == dbipWindows || cPlatform() == dbipMac) { + QString notificationItem = lang(cDesktopNotify() + ? lng_disable_notifications_from_tray : lng_enable_notifications_from_tray); + QAction *first = trayIconMenu->actions().at(0); - first->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray)); - disconnect(first, SIGNAL(triggered(bool)), 0, 0); - connect(first, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray())); - } else { + first->setText(notificationItem); + QAction *second = trayIconMenu->actions().at(1); - second->setDisabled(!isVisible()); + second->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray)); + disconnect(second, SIGNAL(triggered(bool)), 0, 0); + connect(second, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray())); + } else { + QAction *third = trayIconMenu->actions().at(2); + third->setDisabled(!isVisible()); } #ifndef Q_OS_WIN if (trayIcon) { @@ -1167,6 +1178,13 @@ void Window::toggleTray(QSystemTrayIcon::ActivationReason reason) { } } +void Window::toggleDisplayNotifyFromTray() { + cSetDesktopNotify(!cDesktopNotify()); + if (settings) { + settings->updateDisplayNotify(); + } +} + void Window::closeEvent(QCloseEvent *e) { if (MTP::authedId() && minimizeToTray()) { e->ignore(); diff --git a/Telegram/SourceFiles/window.h b/Telegram/SourceFiles/window.h index 0d91959478..204df3f986 100644 --- a/Telegram/SourceFiles/window.h +++ b/Telegram/SourceFiles/window.h @@ -264,6 +264,7 @@ public slots: void showFromTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); bool minimizeToTray(); void toggleTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); + void toggleDisplayNotifyFromTray(); void onInactiveTimer();