| 1 | # -*- coding:utf-8 -*- |
|---|
| 2 | ## src/statusicon.py |
|---|
| 3 | ## |
|---|
| 4 | ## Copyright (C) 2006 Nikos Kouremenos <kourem AT gmail.com> |
|---|
| 5 | ## Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org> |
|---|
| 6 | ## Copyright (C) 2006-2008 Yann Leboulanger <asterix AT lagaule.org> |
|---|
| 7 | ## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net> |
|---|
| 8 | ## Julien Pivotto <roidelapluie AT gmail.com> |
|---|
| 9 | ## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org> |
|---|
| 10 | ## |
|---|
| 11 | ## This file is part of Gajim. |
|---|
| 12 | ## |
|---|
| 13 | ## Gajim is free software; you can redistribute it and/or modify |
|---|
| 14 | ## it under the terms of the GNU General Public License as published |
|---|
| 15 | ## by the Free Software Foundation; version 3 only. |
|---|
| 16 | ## |
|---|
| 17 | ## Gajim is distributed in the hope that it will be useful, |
|---|
| 18 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 19 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 20 | ## GNU General Public License for more details. |
|---|
| 21 | ## |
|---|
| 22 | ## You should have received a copy of the GNU General Public License |
|---|
| 23 | ## along with Gajim. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 24 | ## |
|---|
| 25 | |
|---|
| 26 | import sys |
|---|
| 27 | import gtk |
|---|
| 28 | import systray |
|---|
| 29 | |
|---|
| 30 | from common import gajim |
|---|
| 31 | from common import helpers |
|---|
| 32 | |
|---|
| 33 | if sys.platform == 'darwin': |
|---|
| 34 | try: |
|---|
| 35 | import osx |
|---|
| 36 | except ImportError: |
|---|
| 37 | pass |
|---|
| 38 | |
|---|
| 39 | class StatusIcon(systray.Systray): |
|---|
| 40 | '''Class for the notification area icon''' |
|---|
| 41 | #NOTE: gtk api does NOT allow: |
|---|
| 42 | # leave, enter motion notify |
|---|
| 43 | # and can't do cool tooltips we use |
|---|
| 44 | def __init__(self): |
|---|
| 45 | systray.Systray.__init__(self) |
|---|
| 46 | self.status_icon = None |
|---|
| 47 | |
|---|
| 48 | def show_icon(self): |
|---|
| 49 | if not self.status_icon: |
|---|
| 50 | self.status_icon = gtk.StatusIcon() |
|---|
| 51 | self.status_icon.connect('activate', self.on_status_icon_left_clicked) |
|---|
| 52 | self.status_icon.connect('popup-menu', |
|---|
| 53 | self.on_status_icon_right_clicked) |
|---|
| 54 | |
|---|
| 55 | self.set_img() |
|---|
| 56 | self.status_icon.set_visible(True) |
|---|
| 57 | self.subscribe_events() |
|---|
| 58 | |
|---|
| 59 | def on_status_icon_right_clicked(self, widget, event_button, event_time): |
|---|
| 60 | self.make_menu(event_button, event_time) |
|---|
| 61 | |
|---|
| 62 | def hide_icon(self): |
|---|
| 63 | self.status_icon.set_visible(False) |
|---|
| 64 | self.unsubscribe_events() |
|---|
| 65 | |
|---|
| 66 | def on_status_icon_left_clicked(self, widget): |
|---|
| 67 | if len(gajim.events.get_systray_events()) == 0: |
|---|
| 68 | self.on_left_click() |
|---|
| 69 | else: |
|---|
| 70 | self.on_middle_click() |
|---|
| 71 | |
|---|
| 72 | def set_img(self): |
|---|
| 73 | '''apart from image, we also update tooltip text here''' |
|---|
| 74 | if not gajim.interface.systray_enabled: |
|---|
| 75 | return |
|---|
| 76 | text = helpers.get_notification_icon_tooltip_text() |
|---|
| 77 | self.status_icon.set_tooltip(text) |
|---|
| 78 | if gajim.events.get_nb_systray_events(): |
|---|
| 79 | if sys.platform == 'darwin': |
|---|
| 80 | try: |
|---|
| 81 | osx.nsapp.requestUserAttention() |
|---|
| 82 | except NameError: |
|---|
| 83 | pass |
|---|
| 84 | state = 'event' |
|---|
| 85 | self.status_icon.set_blinking(True) |
|---|
| 86 | else: |
|---|
| 87 | state = self.status |
|---|
| 88 | self.status_icon.set_blinking(False) |
|---|
| 89 | |
|---|
| 90 | #FIXME: do not always use 16x16 (ask actually used size and use that) |
|---|
| 91 | image = gajim.interface.jabber_state_images['16'][state] |
|---|
| 92 | if image.get_storage_type() == gtk.IMAGE_PIXBUF: |
|---|
| 93 | self.status_icon.set_from_pixbuf(image.get_pixbuf()) |
|---|
| 94 | #FIXME: oops they forgot to support GIF animation? |
|---|
| 95 | #or they were lazy to get it to work under Windows! WTF! |
|---|
| 96 | #elif image.get_storage_type() == gtk.IMAGE_ANIMATION: |
|---|
| 97 | # self.img_tray.set_from_animation(image.get_animation()) |
|---|
| 98 | |
|---|
| 99 | # vim: se ts=3: |
|---|