Add item to system tray to toggle notifications display

Signed-off-by: Kirill Gerasimenko <kirill.gerasimenko@outlook.com> (github: kirill-gerasimenko)
This commit is contained in:
Signed-off-by: Kirill Gerasimenko 2015-02-04 08:14:20 +02:00 committed by Kirill Gerasimenko
parent 001864baab
commit 8fc9aa6fdb
5 changed files with 40 additions and 5 deletions

View File

@ -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";

View File

@ -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();
}

View File

@ -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();

View File

@ -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();

View File

@ -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();