Commit b0730981 authored by Saul Ibarra's avatar Saul Ibarra

Added basic system tray icon and associated functionality


Application is not closed when the main window's X button is clicked, it's hidden instead, it can be displayed
again by clicking in the system tray icon or choosing 'Show' from the context menu.

This functionality is only available if the system tray is available (as reported by Qt) and if
the desktop environment is not Unity, since the system tray replacement it ships with doesn't work.
parent 28edbac2
...@@ -108,6 +108,10 @@ class Blink(QApplication): ...@@ -108,6 +108,10 @@ class Blink(QApplication):
self.log_manager = LogManager() self.log_manager = LogManager()
self.presence_manager = PresenceManager() self.presence_manager = PresenceManager()
# Prevent application from exiting after last window is closed if system tray was initialized
if self.main_window.system_tray_icon:
self.setQuitOnLastWindowClosed(False)
self.update_manager = UpdateManager() self.update_manager = UpdateManager()
self.main_window.check_for_updates_action.triggered.connect(self.update_manager.check_for_updates) self.main_window.check_for_updates_action.triggered.connect(self.update_manager.check_for_updates)
self.main_window.check_for_updates_action.setVisible(self.update_manager != Null) self.main_window.check_for_updates_action.setVisible(self.update_manager != Null)
......
...@@ -10,8 +10,8 @@ from functools import partial ...@@ -10,8 +10,8 @@ from functools import partial
from PyQt4 import uic from PyQt4 import uic
from PyQt4.QtCore import Qt, QSettings, QUrl from PyQt4.QtCore import Qt, QSettings, QUrl
from PyQt4.QtGui import QAction, QActionGroup, QDesktopServices, QShortcut from PyQt4.QtGui import QAction, QActionGroup, QDesktopServices, QMenu, QShortcut
from PyQt4.QtGui import QFileDialog, QIcon, QStyle, QStyleOptionComboBox, QStyleOptionFrameV2 from PyQt4.QtGui import QFileDialog, QIcon, QStyle, QStyleOptionComboBox, QStyleOptionFrameV2, QSystemTrayIcon
from application.notification import IObserver, NotificationCenter from application.notification import IObserver, NotificationCenter
from application.python import Null, limit from application.python import Null, limit
...@@ -86,6 +86,18 @@ class MainWindow(base_class, ui_class): ...@@ -86,6 +86,18 @@ class MainWindow(base_class, ui_class):
self.contacts_view.setCurrentWidget(self.contact_list_panel) self.contacts_view.setCurrentWidget(self.contact_list_panel)
self.search_view.setCurrentWidget(self.search_list_panel) self.search_view.setCurrentWidget(self.search_list_panel)
# System tray
if QSystemTrayIcon.isSystemTrayAvailable() and not os.getenv('XDG_CURRENT_DESKTOP', '').lower().startswith('unity'):
self.system_tray_icon = QSystemTrayIcon(QIcon(Resources.get('icons/blink.png')), self)
self.system_tray_icon.activated.connect(self._SH_SystemTrayIconActivated)
menu = QMenu(self)
menu.addAction(QAction("Show", self, triggered=self._AH_SystemTrayShowWindow))
menu.addAction(QAction(QIcon(Resources.get('icons/application-exit.png')), "Quit", self, triggered=self._AH_QuitActionTriggered))
self.system_tray_icon.setContextMenu(menu)
self.system_tray_icon.show()
else:
self.system_tray_icon = None
# Accounts # Accounts
self.account_model = AccountModel(self) self.account_model = AccountModel(self)
self.enabled_account_model = ActiveAccountModel(self.account_model, self) self.enabled_account_model = ActiveAccountModel(self.account_model, self)
...@@ -160,7 +172,7 @@ class MainWindow(base_class, ui_class): ...@@ -160,7 +172,7 @@ class MainWindow(base_class, ui_class):
self.auto_accept_chat_action.triggered.connect(self._AH_AutoAcceptChatTriggered) self.auto_accept_chat_action.triggered.connect(self._AH_AutoAcceptChatTriggered)
self.auto_accept_files_action.triggered.connect(self._AH_AutoAcceptFilesTriggered) self.auto_accept_files_action.triggered.connect(self._AH_AutoAcceptFilesTriggered)
self.release_notes_action.triggered.connect(partial(QDesktopServices.openUrl, QUrl(u'http://icanblink.com/changelog-qt.phtml'))) self.release_notes_action.triggered.connect(partial(QDesktopServices.openUrl, QUrl(u'http://icanblink.com/changelog-qt.phtml')))
self.quit_action.triggered.connect(self.close) self.quit_action.triggered.connect(self._AH_QuitActionTriggered)
# Call menu actions # Call menu actions
self.redial_action.triggered.connect(self._AH_RedialActionTriggered) self.redial_action.triggered.connect(self._AH_RedialActionTriggered)
...@@ -367,6 +379,19 @@ class MainWindow(base_class, ui_class): ...@@ -367,6 +379,19 @@ class MainWindow(base_class, ui_class):
account = None account = None
session_manager.start_call(None, action.entry.target_uri, account=account) session_manager.start_call(None, action.entry.target_uri, account=account)
def _AH_SystemTrayShowWindow(self, checked):
self.show()
self.raise_()
self.activateWindow()
def _AH_QuitActionTriggered(self, checked):
self.close()
if self.system_tray_icon is not None:
self.system_tray_icon.hide()
from blink import Blink
blink = Blink()
blink.quit()
def _SH_AccountStateChanged(self): def _SH_AccountStateChanged(self):
self.activity_note.setText(self.account_state.note) self.activity_note.setText(self.account_state.note)
if self.account_state.state is AccountState.Invisible: if self.account_state.state is AccountState.Invisible:
...@@ -592,6 +617,12 @@ class MainWindow(base_class, ui_class): ...@@ -592,6 +617,12 @@ class MainWindow(base_class, ui_class):
def _SH_PendingWatcherDialogFinished(self, dialog, code): def _SH_PendingWatcherDialogFinished(self, dialog, code):
self.pending_watcher_dialogs.remove(dialog) self.pending_watcher_dialogs.remove(dialog)
def _SH_SystemTrayIconActivated(self, reason):
if reason == QSystemTrayIcon.Trigger:
self.show()
self.raise_()
self.activateWindow()
@run_in_gui_thread @run_in_gui_thread
def handle_notification(self, notification): def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment