~ubuntu-branches/ubuntu/oneiric/ubuntuone-control-panel/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/systray.py

* New upstream release:
  [ Alejandro J. Cura <alecu@canonical.com>]
    - Do not throw a webclient error when closing
      (LP: #845105).
  [ Natalia B. Bidart <natalia.bidart@canonical.com> ]
    - Removed all code related to Bookmarks (LP: #850142).
    - Replaces references to "Evolution" by "Thunderbird" (LP: #849494).
  [ Rodney Dawes <rodney.dawes@canonical.com> ]
    - Don't install a .desktop file for control panel
      (part of LP: #838778).
    - Point the indicator/Unity API at the installer .desktop file
      (part of LP: #838778).
    - Set the WMCLASS so Unity will fall back properly
      (part of LP: #838778).
    - Fix a few grammar mistakes (LP: #835093).
    - Don't show the "Get NGB free!" label on "Join now" button at all
      (LP: #819955).
* debian/control:
  - ubuntuone-control-panel-gtk depends now on ubuntuone-installer >= 2.0.0.
  - require ubuntuone-client >= 2.0.0.
  - require ubuntu-sso-client >= 1.4.0.
  - no longer install a .desktop file (will be installed by ubuntuone-installer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Authors: Roberto Alsina <roberto.alsina@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify it
 
8
# under the terms of the GNU General Public License version 3, as published
 
9
# by the Free Software Foundation.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but
 
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
# PURPOSE.  See the GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along
 
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
"""System notification area icon."""
 
19
 
 
20
from PyQt4 import QtGui
 
21
 
 
22
 
 
23
class TrayIcon(QtGui.QSystemTrayIcon):
 
24
 
 
25
    """System notification icon."""
 
26
 
 
27
    def __init__(self, window=None):
 
28
        super(TrayIcon, self).__init__(None)
 
29
        self.setIcon(QtGui.QIcon(":/u1icon.png"))
 
30
        self.setVisible(True)
 
31
        self.window = window
 
32
        self.activated.connect(self.on_activated)
 
33
        self.context_menu = QtGui.QMenu()
 
34
        self.restore = QtGui.QAction("Restore", self,
 
35
            triggered=self.restore_window)
 
36
        self.quit = QtGui.QAction("Quit Ubuntu One", self,
 
37
            triggered=self.stop)
 
38
        self.context_menu.addAction(self.restore)
 
39
        self.context_menu.addSeparator()
 
40
        self.context_menu.addAction(self.quit)
 
41
        self.setContextMenu(self.context_menu)
 
42
 
 
43
    def on_activated(self, reason):
 
44
        """The user activated the icon."""
 
45
        if reason == self.Trigger:  # Left-click
 
46
            self.restore_window()
 
47
 
 
48
    def restore_window(self):
 
49
        """Show the main window."""
 
50
        if self.window is None:
 
51
            # pylint: disable=W0404
 
52
            from ubuntuone.controlpanel.gui.qt.gui import MainWindow
 
53
            # pylint: enable=W0404
 
54
            self.window = MainWindow(close_callback=self.delete_window)
 
55
        self.window.show()
 
56
 
 
57
    def delete_window(self):
 
58
        """Close and remove the main window."""
 
59
        if self.window is not None:
 
60
            self.window.close()
 
61
            self.window = None
 
62
 
 
63
    def stop(self):
 
64
        """Stop the application."""
 
65
        # pylint: disable=W0404
 
66
        from twisted.internet import reactor
 
67
        # pylint: enable=W0404
 
68
        reactor.stop()