~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to ubuntuone/platform/linux/notification.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 67.
  • Revision ID: james.westby@ubuntu.com-20110211161811-n18dj9lde7dxqjzr
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
"""Module that implements notification of the end user."""
19
19
 
20
 
import pynotify
 
20
# TODO: We may want to enable different notifiers. When none of them
 
21
# are available, we should fall back to silently discarding
 
22
# notifications.
 
23
 
 
24
try:
 
25
    import pynotify
 
26
    USE_PYNOTIFY = True
 
27
except ImportError:
 
28
    USE_PYNOTIFY = False
21
29
 
22
30
from ubuntuone.status.notification import AbstractNotification
23
31
 
24
32
APPLICATION_NAME = 'Ubuntu One Client'
 
33
ICON_NAME = "ubuntuone"
25
34
 
26
35
 
27
36
class Notification(AbstractNotification):
28
37
    """Notification of the end user."""
29
38
 
 
39
    # pylint: disable=W0231
30
40
    def __init__(self, application_name=APPLICATION_NAME):
31
41
        self.application_name = application_name
 
42
    # pylint: enable=W0231
32
43
 
33
 
    def send_notification(self, title, message, icon=None, append=False):
 
44
    def send_notification(self, title, message, icon=ICON_NAME, append=False):
34
45
        """Send a notification using the underlying library."""
35
 
        pynotify.init(self.application_name)
36
 
        notification = pynotify.Notification(title, message, icon)
37
 
        if append:
38
 
            notification.set_hint_string('append', '')
39
 
        notification.show()
 
46
        if USE_PYNOTIFY:
 
47
            pynotify.init(self.application_name)
 
48
            notification = pynotify.Notification(title, message, icon)
 
49
            if append:
 
50
                notification.set_hint_string('x-canonical-append', '')
 
51
            notification.show()
 
52
            return notification
 
53
 
 
54
    def update_notification(self, notification, new_title, new_message,
 
55
                            new_icon=ICON_NAME):
 
56
        """Update the notification with a new message body."""
 
57
        if USE_PYNOTIFY:
 
58
            notification.update(new_title, new_message, new_icon)
 
59
            notification.show()