Skip to content

Commit

Permalink
Merge pull request telegramdesktop#471 from kirill-gerasimenko/notifi…
Browse files Browse the repository at this point in the history
…cation_tray

Add item to system tray to toggle notifications display
  • Loading branch information
john-preston committed Oct 12, 2015
2 parents 001864b + 8fc9aa6 commit 580e6cd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Telegram/Resources/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
11 changes: 11 additions & 0 deletions Telegram/SourceFiles/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ void SettingsInner::updateSize(int32 newWidth) {
}
}


void SettingsInner::updateOnlineDisplay() {
}

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -1863,6 +1869,11 @@ void SettingsWidget::updateWideMode() {
}
}

void SettingsWidget::updateDisplayNotify()
{
_inner.enableDisplayNotify(cDesktopNotify());
}

void SettingsWidget::updateOnlineDisplay() {
_inner.updateOnlineDisplay();
}
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/settingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class SettingsInner : public QWidget, public RPCSender, public Animated {

void updateChatBackground();
void needBackgroundUpdate(bool tile);
void enableDisplayNotify(bool enable);

public slots:

Expand Down Expand Up @@ -318,6 +319,8 @@ class SettingsWidget : public QWidget, public Animated {
void updateOnlineDisplay();
void updateConnectionType();

void updateDisplayNotify();

void rpcInvalidate();
void usernameChanged();

Expand Down
28 changes: 23 additions & 5 deletions Telegram/SourceFiles/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 580e6cd

Please sign in to comment.