2005-05-12 15:52:09 +02:00
|
|
|
## systray.py
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
|
|
|
## Gajim Team:
|
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2005-04-14 19:07:55 +02:00
|
|
|
import dialogs
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-04-17 18:06:12 +02:00
|
|
|
from common import gajim
|
2005-05-20 17:58:23 +02:00
|
|
|
from common import helpers
|
2005-03-11 18:57:35 +01:00
|
|
|
from common import i18n
|
|
|
|
|
2005-05-17 22:31:43 +02:00
|
|
|
try:
|
|
|
|
import egg.trayicon as trayicon # gnomepythonextras trayicon
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
import trayicon # our trayicon
|
|
|
|
except:
|
|
|
|
gajim.log.debug('No trayicon module available')
|
|
|
|
pass
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
_ = i18n._
|
|
|
|
APP = i18n.APP
|
|
|
|
gtk.glade.bindtextdomain(APP, i18n.DIR)
|
|
|
|
gtk.glade.textdomain(APP)
|
|
|
|
|
2005-04-22 01:20:18 +02:00
|
|
|
GTKGUI_GLADE = 'gtkgui.glade'
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-03-29 18:37:59 +02:00
|
|
|
class Systray:
|
2005-03-11 18:57:35 +01:00
|
|
|
"""Class for icon in the systray"""
|
|
|
|
def set_img(self):
|
|
|
|
if len(self.jids) > 0:
|
|
|
|
status = 'message'
|
|
|
|
else:
|
|
|
|
status = self.status
|
2005-04-23 03:37:05 +02:00
|
|
|
image = self.plugin.roster.jabber_state_images[status]
|
2005-03-11 18:57:35 +01:00
|
|
|
if image.get_storage_type() == gtk.IMAGE_ANIMATION:
|
|
|
|
self.img_tray.set_from_animation(image.get_animation())
|
|
|
|
elif image.get_storage_type() == gtk.IMAGE_PIXBUF:
|
|
|
|
self.img_tray.set_from_pixbuf(image.get_pixbuf())
|
|
|
|
|
|
|
|
def add_jid(self, jid, account):
|
|
|
|
list = [account, jid]
|
|
|
|
if not list in self.jids:
|
|
|
|
self.jids.append(list)
|
|
|
|
self.set_img()
|
2005-03-22 00:14:27 +01:00
|
|
|
#we look for the number of unread messages
|
|
|
|
#in roster
|
|
|
|
nb = self.plugin.roster.nb_unread
|
2005-04-17 17:23:52 +02:00
|
|
|
for acct in gajim.connections:
|
2005-03-22 00:14:27 +01:00
|
|
|
#in chat / groupchat windows
|
|
|
|
for kind in ['chats', 'gc']:
|
2005-04-22 03:35:36 +02:00
|
|
|
jids = self.plugin.windows[acct][kind]
|
|
|
|
for jid in jids:
|
2005-03-22 00:14:27 +01:00
|
|
|
if jid != 'tabbed':
|
2005-04-22 03:35:36 +02:00
|
|
|
nb += jids[jid].nb_unread[jid]
|
2005-03-22 00:14:27 +01:00
|
|
|
if nb > 1:
|
|
|
|
label = _('Gajim - %s unread messages') % nb
|
|
|
|
else:
|
|
|
|
label = _('Gajim - 1 unread message')
|
|
|
|
self.tip.set_tip(self.t, label)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def remove_jid(self, jid, account):
|
|
|
|
list = [account, jid]
|
|
|
|
if list in self.jids:
|
|
|
|
self.jids.remove(list)
|
|
|
|
self.set_img()
|
2005-03-22 00:14:27 +01:00
|
|
|
#we look for the number of unread messages
|
|
|
|
#in roster
|
|
|
|
nb = self.plugin.roster.nb_unread
|
2005-04-17 17:23:52 +02:00
|
|
|
for acct in gajim.connections:
|
2005-03-22 00:14:27 +01:00
|
|
|
#in chat / groupchat windows
|
|
|
|
for kind in ['chats', 'gc']:
|
|
|
|
for jid in self.plugin.windows[acct][kind]:
|
|
|
|
if jid != 'tabbed':
|
|
|
|
nb += self.plugin.windows[acct][kind][jid].nb_unread[jid]
|
|
|
|
if nb > 1:
|
|
|
|
label = _('Gajim - %s unread messages') % nb
|
|
|
|
elif nb == 1:
|
|
|
|
label = _('Gajim - 1 unread message')
|
|
|
|
else:
|
|
|
|
label = 'Gajim'
|
|
|
|
self.tip.set_tip(self.t, label)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def set_status(self, status):
|
|
|
|
self.status = status
|
|
|
|
self.set_img()
|
|
|
|
|
|
|
|
def start_chat(self, widget, account, jid):
|
|
|
|
if self.plugin.windows[account]['chats'].has_key(jid):
|
|
|
|
self.plugin.windows[account]['chats'][jid].window.present()
|
|
|
|
elif self.plugin.roster.contacts[account].has_key(jid):
|
|
|
|
self.plugin.roster.new_chat(
|
|
|
|
self.plugin.roster.contacts[account][jid][0], account)
|
2005-03-14 14:25:34 +01:00
|
|
|
|
|
|
|
def on_new_message_menuitem_activate(self, widget, account):
|
|
|
|
"""When new message menuitem is activated:
|
|
|
|
call the New_message_dialog class"""
|
2005-04-14 19:07:55 +02:00
|
|
|
dialogs.New_message_dialog(self.plugin, account)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-05-18 14:51:01 +02:00
|
|
|
def make_menu(self, event):
|
2005-03-14 18:30:52 +01:00
|
|
|
"""create chat with and new message (sub) menus/menuitems"""
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-03-15 01:40:08 +01:00
|
|
|
chat_with_menuitem = self.xml.get_widget('chat_with_menuitem')
|
|
|
|
#menu.append(chat_with_menuitem)
|
|
|
|
new_message_menuitem = self.xml.get_widget('new_message_menuitem')
|
|
|
|
#menu.append(new_message_menuitem)
|
2005-03-14 14:25:34 +01:00
|
|
|
|
2005-04-22 03:35:36 +02:00
|
|
|
iskey = len(gajim.connections.keys()) > 0
|
|
|
|
chat_with_menuitem.set_sensitive(iskey)
|
|
|
|
new_message_menuitem.set_sensitive(iskey)
|
2005-03-14 14:25:34 +01:00
|
|
|
|
2005-05-17 21:23:55 +02:00
|
|
|
if len(gajim.connections.keys()) >= 2: # 2 or more connections? make submenus
|
2005-03-14 18:30:52 +01:00
|
|
|
account_menu_for_chat_with = gtk.Menu()
|
|
|
|
chat_with_menuitem.set_submenu(account_menu_for_chat_with)
|
|
|
|
|
|
|
|
account_menu_for_new_message = gtk.Menu()
|
|
|
|
new_message_menuitem.set_submenu(account_menu_for_new_message)
|
|
|
|
|
2005-04-17 17:23:52 +02:00
|
|
|
for account in gajim.connections:
|
|
|
|
our_jid = gajim.config.get_per('accounts', account, 'name') + '@' +\
|
|
|
|
gajim.config.get_per('accounts', account, 'hostname')
|
2005-03-14 14:25:34 +01:00
|
|
|
#for chat_with
|
2005-03-27 22:30:00 +02:00
|
|
|
item = gtk.MenuItem(_('as ') + our_jid)
|
2005-03-14 18:30:52 +01:00
|
|
|
account_menu_for_chat_with.append(item)
|
|
|
|
group_menu = self.make_groups_submenus_for_chat_with(account)
|
|
|
|
item.set_submenu(group_menu)
|
|
|
|
#for new_message
|
2005-03-27 22:30:00 +02:00
|
|
|
item = gtk.MenuItem(_('as ') + our_jid)
|
2005-03-14 18:30:52 +01:00
|
|
|
item.connect('activate',\
|
|
|
|
self.on_new_message_menuitem_activate, account)
|
|
|
|
account_menu_for_new_message.append(item)
|
|
|
|
|
2005-04-17 17:23:52 +02:00
|
|
|
elif len(gajim.connections) == 1: # one account
|
2005-03-27 21:39:50 +02:00
|
|
|
#one account, no need to show 'as jid
|
2005-03-14 14:25:34 +01:00
|
|
|
#for chat_with
|
2005-04-17 17:23:52 +02:00
|
|
|
account = gajim.connections.keys()[0]
|
2005-03-14 18:30:52 +01:00
|
|
|
|
|
|
|
group_menu = self.make_groups_submenus_for_chat_with(account)
|
|
|
|
chat_with_menuitem.set_submenu(group_menu)
|
2005-03-14 14:25:34 +01:00
|
|
|
|
|
|
|
#for new message
|
2005-05-17 21:23:55 +02:00
|
|
|
self.new_message_handler_id = new_message_menuitem.connect(
|
2005-03-14 14:25:34 +01:00
|
|
|
'activate', self.on_new_message_menuitem_activate, account)
|
|
|
|
|
2005-03-15 01:40:08 +01:00
|
|
|
self.systray_context_menu.popup(None, None, None, event.button, event.time)
|
|
|
|
self.systray_context_menu.show_all()
|
|
|
|
self.systray_context_menu.reposition()
|
2005-03-14 18:30:52 +01:00
|
|
|
|
2005-03-15 01:40:08 +01:00
|
|
|
def on_quit_menuitem_activate(self, widget):
|
|
|
|
self.plugin.roster.on_quit_menuitem_activate(widget)
|
|
|
|
|
2005-03-14 18:30:52 +01:00
|
|
|
def make_groups_submenus_for_chat_with(self, account):
|
|
|
|
groups_menu = gtk.Menu()
|
|
|
|
|
|
|
|
for group in self.plugin.roster.groups[account].keys():
|
2005-05-12 15:52:09 +02:00
|
|
|
if group == 'Transports':
|
2005-03-14 18:30:52 +01:00
|
|
|
continue
|
2005-05-13 18:53:30 +02:00
|
|
|
# at least one 'not offline' or 'without errors' in this group
|
2005-03-14 18:30:52 +01:00
|
|
|
at_least_one = False
|
|
|
|
item = gtk.MenuItem(group)
|
|
|
|
groups_menu.append(item)
|
|
|
|
contacts_menu = gtk.Menu()
|
|
|
|
item.set_submenu(contacts_menu)
|
|
|
|
for users in self.plugin.roster.contacts[account].values():
|
|
|
|
user = users[0]
|
|
|
|
if group in user.groups and user.show != 'offline' and \
|
|
|
|
user.show != 'error':
|
|
|
|
at_least_one = True
|
2005-05-20 18:31:52 +02:00
|
|
|
show = helpers.get_uf_show(user.show)
|
|
|
|
s = user.name.replace('_', '__') + ' (' + show + ')'
|
2005-03-14 18:30:52 +01:00
|
|
|
item = gtk.MenuItem(s)
|
|
|
|
item.connect('activate', self.start_chat, account,\
|
|
|
|
user.jid)
|
|
|
|
contacts_menu.append(item)
|
|
|
|
|
|
|
|
if not at_least_one:
|
|
|
|
message = _('All contacts in this group are offline or have errors')
|
|
|
|
item = gtk.MenuItem(message)
|
|
|
|
item.set_sensitive(False)
|
|
|
|
contacts_menu.append(item)
|
|
|
|
|
|
|
|
return groups_menu
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def on_clicked(self, widget, event):
|
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
|
|
|
|
if len(self.jids) == 0:
|
|
|
|
win = self.plugin.roster.window
|
2005-03-15 02:05:28 +01:00
|
|
|
if win.is_active():
|
2005-03-16 01:03:45 +01:00
|
|
|
win.hide()
|
2005-03-11 18:57:35 +01:00
|
|
|
else:
|
2005-03-15 02:05:28 +01:00
|
|
|
win.present()
|
2005-03-11 18:57:35 +01:00
|
|
|
else:
|
|
|
|
account = self.jids[0][0]
|
|
|
|
jid = self.jids[0][1]
|
2005-04-22 03:35:36 +02:00
|
|
|
acc = self.plugin.windows[account]
|
|
|
|
if acc['gc'].has_key(jid):
|
2005-05-03 18:39:27 +02:00
|
|
|
acc['gc'][jid].set_active_tab(jid)
|
2005-04-22 03:35:36 +02:00
|
|
|
acc['gc'][jid].window.present()
|
|
|
|
elif acc['chats'].has_key(jid):
|
2005-05-03 18:39:27 +02:00
|
|
|
acc['chats'][jid].set_active_tab(jid)
|
2005-04-22 03:35:36 +02:00
|
|
|
acc['chats'][jid].window.present()
|
2005-03-11 18:57:35 +01:00
|
|
|
else:
|
|
|
|
self.plugin.roster.new_chat(
|
|
|
|
self.plugin.roster.contacts[account][jid][0], account)
|
2005-05-06 19:35:57 +02:00
|
|
|
acc['chats'][jid].set_active_tab(jid)
|
2005-04-27 21:09:34 +02:00
|
|
|
acc['chats'][jid].window.present()
|
2005-03-15 02:05:28 +01:00
|
|
|
if event.button == 3: # right click
|
2005-05-18 14:51:01 +02:00
|
|
|
self.make_menu(event)
|
2005-03-15 01:40:08 +01:00
|
|
|
|
|
|
|
def on_online_menuitem_activate(self, widget):
|
2005-04-02 23:48:12 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(0) # 0 is online
|
2005-04-19 01:55:13 +02:00
|
|
|
|
|
|
|
def on_free_for_chat_menuitem_activate(self, widget):
|
2005-04-19 09:52:06 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(1) # 1 is free for chat
|
2005-04-19 01:55:13 +02:00
|
|
|
|
2005-03-15 01:40:08 +01:00
|
|
|
def on_away_menuitem_activate(self, widget):
|
2005-04-19 09:52:06 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(2) # 2 is away
|
2005-03-15 01:40:08 +01:00
|
|
|
|
|
|
|
def on_xa_menuitem_activate(self, widget):
|
2005-04-19 09:52:06 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(3) # 3 is xa
|
2005-03-15 01:40:08 +01:00
|
|
|
|
2005-03-15 03:33:29 +01:00
|
|
|
def on_dnd_menuitem_activate(self, widget):
|
2005-04-19 09:52:06 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(4) # 4 is dnd
|
2005-03-15 01:40:08 +01:00
|
|
|
|
2005-03-15 03:33:29 +01:00
|
|
|
def on_invisible_menuitem_activate(self, widget):
|
2005-04-19 09:52:06 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(5) # 5 is invisible
|
2005-03-15 01:40:08 +01:00
|
|
|
|
2005-03-15 03:33:29 +01:00
|
|
|
def on_offline_menuitem_activate(self, widget):
|
2005-04-19 09:52:06 +02:00
|
|
|
self.plugin.roster.status_combobox.set_active(6) # 6 is offline
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def show_icon(self):
|
|
|
|
if not self.t:
|
2005-03-15 15:21:09 +01:00
|
|
|
self.t = trayicon.TrayIcon('Gajim')
|
2005-03-11 18:57:35 +01:00
|
|
|
eb = gtk.EventBox()
|
2005-03-15 15:21:09 +01:00
|
|
|
eb.connect('button-press-event', self.on_clicked)
|
2005-03-11 18:57:35 +01:00
|
|
|
self.tip.set_tip(self.t, 'Gajim')
|
|
|
|
self.img_tray = gtk.Image()
|
|
|
|
eb.add(self.img_tray)
|
|
|
|
self.t.add(eb)
|
|
|
|
self.set_img()
|
|
|
|
self.t.show_all()
|
|
|
|
|
|
|
|
def hide_icon(self):
|
|
|
|
if self.t:
|
|
|
|
self.t.destroy()
|
|
|
|
self.t = None
|
|
|
|
|
|
|
|
def __init__(self, plugin):
|
|
|
|
self.plugin = plugin
|
|
|
|
self.jids = []
|
|
|
|
self.t = None
|
2005-03-27 10:38:26 +02:00
|
|
|
self.tip = gtk.Tooltips()
|
2005-03-11 18:57:35 +01:00
|
|
|
self.img_tray = gtk.Image()
|
|
|
|
self.status = 'offline'
|
2005-03-15 01:40:08 +01:00
|
|
|
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'systray_context_menu', APP)
|
|
|
|
self.systray_context_menu = self.xml.get_widget('systray_context_menu')
|
|
|
|
self.xml.signal_autoconnect(self)
|