~jhonnyc/cgmail/jonathanc-branch

« back to all changes in this revision

Viewing changes to src/statusicon.py

  • Committer: Marco Ferragina
  • Date: 2007-05-06 15:51:12 UTC
  • Revision ID: marco.ferragina@gmail.com-20070506155112-874uk2m8blrknyuf
Restructured package source dir. Now is much more organized. Implemented right click menu on account window treeview

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import gtk
2
 
import gtk.glade
3
 
import gobject
4
 
 
5
 
import os
6
 
 
7
 
from common import *
8
 
from gconfhelper import GconfHelper
9
 
import utils
10
 
from notifier import Notifier
11
 
 
12
 
GLADE_FILE = os.path.join(GLADE_BASE_PATH, "popupmenu.glade")
13
 
 
14
 
class StatusIcon:
15
 
        def __init__(self, checker, stop_cb):
16
 
                
17
 
                self.checker = checker
18
 
                self.checker.add_status_cb(self.set_status)
19
 
                self.checker.init_checkers(self.no_config)
20
 
                self.stop_main_loop = stop_cb
21
 
 
22
 
                gtk.window_set_default_icon_from_file(NOMAIL_ICON)
23
 
 
24
 
                self.widgets = gtk.glade.XML(GLADE_FILE, domain="cgmail")
25
 
                self.menu = self.widgets.get_widget("menu")
26
 
                dic = {
27
 
                        "on_update_activate" : self.on_update_activate,
28
 
                        "on_reshow_last_notification_activate" : self.on_reshow_last_notification,
29
 
                        "on_exit_activate" : self.exit
30
 
                }
31
 
 
32
 
                self.widgets.signal_autoconnect(dic)
33
 
        
34
 
                self.status_icon = gtk.StatusIcon()
35
 
                #self.status_icon.set_from_stock(gtk.STOCK_CLOSE)
36
 
                self.status_icon.set_from_file(NOMAIL_ICON)
37
 
                self.status_icon.connect("popup-menu", self.on_popup_menu)
38
 
                self.status_icon.connect("activate", self.on_activate)
39
 
 
40
 
                self.call_manage_accounts = False
41
 
                                
42
 
                self.gconf_helper = GconfHelper()
43
 
                
44
 
                #If the user click on systray icon we reshow this message
45
 
                self.notification_message = ""
46
 
                self.notification_title = ""
47
 
 
48
 
                self.notifier = Notifier()
49
 
 
50
 
                self.hide()
51
 
        
52
 
        def hide(self):
53
 
                self.status_icon.set_visible(False)
54
 
                pass
55
 
 
56
 
        def show(self):
57
 
                self.status_icon.set_visible(True)
58
 
                pass
59
 
 
60
 
        def no_config(self):
61
 
                print "No accounts configured founded"
62
 
                AccountsDialog().run()
63
 
                #self.checker.init_checkers(None)
64
 
        
65
 
        
66
 
        def set_status(self, mcount, title, message):
67
 
                if mcount == 0:
68
 
                        self.hide()
69
 
                        self.status_icon.set_from_file(NOMAIL_ICON)
70
 
                        self.notification_message = ""
71
 
                        self.notification_title = ""
72
 
                elif mcount > 5:
73
 
                        self.status_icon.set_from_file(MORE_NEWMAIL_ICON)
74
 
                        self.show()
75
 
                else:
76
 
                        self.status_icon.set_from_file(NEWMAIL_ICON_BASE_PATH % mcount)
77
 
                        self.show()
78
 
 
79
 
                if title is not None:
80
 
                        self.notification_title = title
81
 
                if message is not None:
82
 
                        self.notification_message = message
83
 
 
84
 
        def on_reshow_last_notification(self, arg):
85
 
                self.on_activate(None)
86
 
 
87
 
        def on_activate(self, arg):
88
 
                
89
 
                if self.notification_message != "":
90
 
                        title = self.notification_title
91
 
                        message = self.notification_message
92
 
                        but = True
93
 
                else:
94
 
                        title = _("No messages")
95
 
                        message = _("There are no new messages in your mailboxes")
96
 
                        but = False
97
 
 
98
 
                self.notifier.notify(title, message, 
99
 
                                msec = 10000, force = True, buttons = but)
100
 
 
101
 
        def on_update_activate(self, arg):
102
 
                self.checker.reset()
103
 
                self.status_icon.set_from_file(NOMAIL_ICON)
104
 
                # force check
105
 
                try:
106
 
                        thread.start_new_thread(self.checker.check, ())
107
 
                except Exception, e:
108
 
                        print "Warning: ", e
109
 
        
110
 
        def on_popup_menu(self, si, button, time):
111
 
                #self.menu.popup(None, None, None, button, time, si)
112
 
                self.menu.popup(None, None, gtk.status_icon_position_menu,
113
 
                                button, time, si)
114
 
        
115
 
        def exit(self, arg):
116
 
                self.stop_main_loop()
117