2
import gtk, glib, sys, fcntl, os
9
APP_NAME = "indicator-py"
10
locale.setlocale(locale.LC_ALL, 'nl_NL.utf8')
12
class MessagingServer:
13
def __init__(self, subtype, desktop):
18
self.desktop = desktop
20
self.srv = indicate.indicate_server_ref_default()
21
type = "message.%s" % subtype
22
self.srv.set_type(type)
23
self.srv.set_desktop_file(desktop)
26
def show_indicator(self, name, count, draw_attention=True):
27
# update existing indicator, or create new one
29
ind = self.indicators[name]
32
ind = indicate.Indicator()
33
self.indicators[name] = ind
35
ind.set_property('name', name)
36
ind.set_property('count', str(count))
37
ind.set_property('draw-attention', 'true' if draw_attention else 'false')
38
ind.connect('user-display', self.cb_user_display)
40
# hide and reshow actions to keep them at top of list
41
for a in self.actions.values():
44
for a in self.actions.values():
49
def hide_indicator(self, name):
51
self.indicators[name].hide()
52
del(self.indicators[name])
54
print "ERROR: No indicator named '%s' to hide" % name
56
def add_action(self, name, cb):
57
ind = indicate.Indicator()
58
self.actions[name] = ind
59
ind.set_property('name', name)
60
ind.set_property('subtype', 'menu')
61
ind.connect('user-display', cb)
65
def set_user_cb(self, cb):
68
def set_server_cb(self, cb):
71
def cb_server_display(self, srv, id):
72
print "SERVER DISPLAY"
76
def cb_user_display(self, ind, id):
79
self.user_cb(ind.get_property('name'), ind.get_property('count'))
82
def set_nonblock(fd, nonblock):
83
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
88
fcntl.fcntl(fd, fcntl.F_SETFL, fl)
90
def user_display(name, count):
91
os.system("thunderbird -mail&")
93
def server_display(srv):
94
os.system("thunderbird -mail&")
96
def io_cb(f, condition, srv):
98
'show': [srv.show_indicator, 2],
99
'hide': [srv.hide_indicator, 1],
103
if condition == glib.IO_IN:
104
data = f.read().strip()
105
args = data.strip().split("::")
109
fn, numargs = commands[cmd]
111
print "ERROR: command '%s' not known" % cmd
114
if numargs != len(args):
115
print "ERROR: '%s' command takes %d arguments but were %d given" % (cmd,
119
print "CMD: %s" % cmd
124
print "ERROR: I/O Error"
128
if __name__ == "__main__":
131
#Get the local directory since we are not installing anything
132
local_path = os.path.realpath(os.path.dirname(sys.argv[0]))
133
# Init the list of languages to support
135
#Check the default locale
136
lc, encoding = locale.getdefaultlocale()
138
#If we have a default, it's the first in the list
140
# Now lets get all of the supported languages on the system
141
language = os.environ.get('LANGUAGE', None)
143
langs += language.split(":")
144
langs += ["en_US", "nl"]
146
gettext.bindtextdomain(APP_NAME, local_path)
147
gettext.textdomain(APP_NAME)
148
# Get the language to use
149
lang = gettext.translation(APP_NAME, local_path, languages=langs, fallback = True)
152
def action_compose(indicator, id):
153
os.system("thunderbird -compose&")
155
def action_addressbook(indicator, id):
156
os.system("thunderbird -addressbook&")
159
srv.add_action(_("Contacts"), action_addressbook)
160
srv.add_action(_("Compose email"), action_compose)
162
srv = MessagingServer('email', '/usr/share/applications/thunderbird.desktop')
163
srv.set_user_cb(user_display)
164
srv.set_server_cb(server_display)
166
fifopath = sys.argv[1]
167
if not os.path.exists(fifopath):
170
if len(sys.argv) > 2 and sys.argv[2] == 'mkfifoonly':
173
fdr = os.open(fifopath, os.O_RDONLY | os.O_NONBLOCK)
174
fdw = os.open(fifopath, os.O_WRONLY | os.O_NONBLOCK)
176
glib.io_add_watch(f, glib.IO_IN | glib.IO_ERR, io_cb, srv)
178
gobject.timeout_add_seconds(0, timeout, srv)