2005-05-12 15:52:09 +02:00
|
|
|
## systray.py
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
2005-12-09 18:15:30 +01:00
|
|
|
## Contributors for this file:
|
2005-03-11 18:57:35 +01:00
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
2005-08-09 18:33:45 +02:00
|
|
|
## - Dimitur Kirov <dkirov@gmail.com>
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
2005-12-10 00:30:28 +01:00
|
|
|
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Nikos Kouremenos <nkour@jabber.org>
|
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
|
|
|
## 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-07-31 21:21:11 +02:00
|
|
|
import gobject
|
2005-04-14 19:07:55 +02:00
|
|
|
import dialogs
|
2005-06-20 19:45:04 +02:00
|
|
|
import os
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-08-15 01:52:12 +02:00
|
|
|
import tooltips
|
2005-10-31 19:06:36 +01:00
|
|
|
import gtkgui_helpers
|
2005-08-15 01:52:12 +02: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-08-15 21:52:18 +02:00
|
|
|
'''Class for icon in the notification area
|
|
|
|
This class is both base class (for systraywin32.py) and normal class
|
|
|
|
for trayicon in GNU/Linux'''
|
|
|
|
|
2005-10-20 13:17:17 +02:00
|
|
|
def __init__(self):
|
2005-09-24 11:42:10 +02:00
|
|
|
self.jids = [] # Contain things like [account, jid, type_of_msg]
|
2005-07-21 08:25:49 +02:00
|
|
|
self.new_message_handler_id = None
|
2005-06-15 13:14:59 +02:00
|
|
|
self.t = None
|
|
|
|
self.img_tray = gtk.Image()
|
|
|
|
self.status = 'offline'
|
|
|
|
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)
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def set_img(self):
|
|
|
|
if len(self.jids) > 0:
|
2005-08-16 22:24:56 +02:00
|
|
|
state = 'message'
|
2005-03-11 18:57:35 +01:00
|
|
|
else:
|
2005-08-16 22:24:56 +02:00
|
|
|
state = self.status
|
2005-12-12 16:13:31 +01:00
|
|
|
image = gajim.interface.roster.jabber_state_images['16'][state]
|
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())
|
|
|
|
|
2005-09-24 11:42:10 +02:00
|
|
|
def add_jid(self, jid, account, typ):
|
|
|
|
l = [account, jid, typ]
|
2005-10-16 15:18:34 +02:00
|
|
|
# We can keep several single message 'cause we open them one by one
|
|
|
|
if not l in self.jids or typ == 'normal':
|
2005-07-19 22:12:02 +02:00
|
|
|
self.jids.append(l)
|
2005-03-11 18:57:35 +01:00
|
|
|
self.set_img()
|
2005-07-01 19:15:01 +02:00
|
|
|
|
2005-09-24 11:42:10 +02:00
|
|
|
def remove_jid(self, jid, account, typ):
|
|
|
|
l = [account, jid, typ]
|
2005-07-19 22:12:02 +02:00
|
|
|
if l in self.jids:
|
|
|
|
self.jids.remove(l)
|
2005-03-11 18:57:35 +01:00
|
|
|
self.set_img()
|
2005-09-24 11:59:34 +02:00
|
|
|
|
2005-07-31 21:32:06 +02:00
|
|
|
def change_status(self, global_status):
|
|
|
|
''' set tray image to 'global_status' '''
|
2005-07-30 02:20:28 +02:00
|
|
|
# change image and status, only if it is different
|
2005-07-30 11:09:47 +02:00
|
|
|
if global_status is not None and self.status != global_status:
|
2005-07-30 02:20:28 +02:00
|
|
|
self.status = global_status
|
2005-07-30 11:09:47 +02:00
|
|
|
self.set_img()
|
2005-07-30 02:20:28 +02:00
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def start_chat(self, widget, account, jid):
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
|
2005-12-31 22:55:44 +01:00
|
|
|
if gajim.interface.msg_win_mgr.has_window(jid):
|
|
|
|
gajim.interface.msg_win_mgr.get_window(jid).set_active_tab(jid)
|
|
|
|
gajim.interface.msg_win_mgr.get_window(jid).present()
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
elif contact:
|
2005-12-31 22:55:44 +01:00
|
|
|
gajim.interface.roster.new_chat(gajim.contacts[account][jid][0],
|
|
|
|
account)
|
|
|
|
gajim.interface.msg_win_mgr.get_window(jid).set_active_tab(jid)
|
2005-03-14 14:25:34 +01:00
|
|
|
|
|
|
|
def on_new_message_menuitem_activate(self, widget, account):
|
|
|
|
"""When new message menuitem is activated:
|
2005-06-10 23:14:16 +02:00
|
|
|
call the NewMessageDialog class"""
|
2005-10-20 13:17:17 +02:00
|
|
|
dialogs.NewMessageDialog(account)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-08-11 15:20:46 +02:00
|
|
|
def make_menu(self, event = None):
|
|
|
|
'''create chat with and new message (sub) menus/menuitems
|
|
|
|
event is None when we're in Windows
|
|
|
|
'''
|
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')
|
|
|
|
new_message_menuitem = self.xml.get_widget('new_message_menuitem')
|
2005-06-20 19:45:04 +02:00
|
|
|
status_menuitem = self.xml.get_widget('status_menu')
|
2005-07-21 08:25:49 +02:00
|
|
|
|
|
|
|
if self.new_message_handler_id:
|
|
|
|
new_message_menuitem.handler_disconnect(
|
|
|
|
self.new_message_handler_id)
|
|
|
|
self.new_message_handler_id = None
|
2005-06-20 19:45:04 +02:00
|
|
|
|
|
|
|
sub_menu = gtk.Menu()
|
|
|
|
status_menuitem.set_submenu(sub_menu)
|
|
|
|
|
2005-06-20 21:18:53 +02:00
|
|
|
# We need our own set of status icons, let's make 'em!
|
|
|
|
iconset = gajim.config.get('iconset')
|
|
|
|
if not iconset:
|
2005-12-12 16:13:31 +01:00
|
|
|
iconset = 'dcraven'
|
|
|
|
path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
2005-10-20 13:17:17 +02:00
|
|
|
state_images = gajim.interface.roster.load_iconset(path)
|
2005-06-20 19:45:04 +02:00
|
|
|
|
2005-10-27 15:15:03 +02:00
|
|
|
for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
|
2005-10-09 18:08:18 +02:00
|
|
|
uf_show = helpers.get_uf_show(show, use_mnemonic = True)
|
2005-08-09 18:33:45 +02:00
|
|
|
item = gtk.ImageMenuItem(uf_show)
|
|
|
|
item.set_image(state_images[show])
|
2005-06-20 19:45:04 +02:00
|
|
|
sub_menu.append(item)
|
|
|
|
item.connect('activate', self.on_show_menuitem_activate, show)
|
|
|
|
|
2005-10-09 16:49:14 +02:00
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
sub_menu.append(item)
|
|
|
|
|
2005-10-10 00:24:18 +02:00
|
|
|
item = gtk.ImageMenuItem(_('_Change Status Message...'))
|
2005-10-09 20:45:03 +02:00
|
|
|
path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'rename.png')
|
|
|
|
img = gtk.Image()
|
|
|
|
img.set_from_file(path)
|
|
|
|
item.set_image(img)
|
2005-10-09 16:49:14 +02:00
|
|
|
sub_menu.append(item)
|
|
|
|
item.connect('activate', self.on_change_status_message_activate)
|
|
|
|
if not helpers.one_account_connected():
|
|
|
|
item.set_sensitive(False)
|
|
|
|
|
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
sub_menu.append(item)
|
|
|
|
|
2005-10-09 18:08:18 +02:00
|
|
|
uf_show = helpers.get_uf_show('offline', use_mnemonic = True)
|
2005-10-09 16:49:14 +02:00
|
|
|
item = gtk.ImageMenuItem(uf_show)
|
|
|
|
item.set_image(state_images['offline'])
|
|
|
|
sub_menu.append(item)
|
|
|
|
item.connect('activate', self.on_show_menuitem_activate, 'offline')
|
|
|
|
|
2005-06-15 13:14:59 +02:00
|
|
|
iskey = len(gajim.connections) > 0
|
2005-04-22 03:35:36 +02:00
|
|
|
chat_with_menuitem.set_sensitive(iskey)
|
|
|
|
new_message_menuitem.set_sensitive(iskey)
|
2005-03-14 14:25:34 +01:00
|
|
|
|
2005-06-15 13:14:59 +02:00
|
|
|
if len(gajim.connections) >= 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:
|
2005-03-14 14:25:34 +01:00
|
|
|
#for chat_with
|
2005-12-01 19:19:51 +01:00
|
|
|
item = gtk.MenuItem(_('using account ') + account)
|
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-12-01 19:19:51 +01:00
|
|
|
item = gtk.MenuItem(_('using account ') + account)
|
2005-06-15 13:14:59 +02:00
|
|
|
item.connect('activate',
|
2005-03-14 18:30:52 +01:00
|
|
|
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-08-11 15:46:37 +02:00
|
|
|
# one account, no need to show 'as jid'
|
2005-08-11 15:20:46 +02: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
|
|
|
|
2005-08-11 15:20:46 +02: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-09-25 20:37:50 +02:00
|
|
|
if event is None:
|
|
|
|
# None means windows (we explicitly popup in systraywin32.py)
|
2005-08-26 16:36:20 +02:00
|
|
|
if self.added_hide_menuitem is False:
|
2005-08-30 00:25:48 +02:00
|
|
|
self.systray_context_menu.prepend(gtk.SeparatorMenuItem())
|
2005-09-25 20:37:50 +02:00
|
|
|
item = gtk.MenuItem(_('Hide this menu'))
|
2005-08-29 22:47:26 +02:00
|
|
|
self.systray_context_menu.prepend(item)
|
2005-08-26 16:36:20 +02:00
|
|
|
self.added_hide_menuitem = True
|
|
|
|
|
|
|
|
else: # GNU and Unices
|
2005-08-11 15:20:46 +02:00
|
|
|
self.systray_context_menu.popup(None, None, None, event.button, event.time)
|
2005-08-15 21:52:18 +02:00
|
|
|
self.systray_context_menu.show_all()
|
2005-06-15 13:14:59 +02:00
|
|
|
|
2005-10-30 02:08:39 +02:00
|
|
|
def on_show_all_events_menuitem_activate(self, widget):
|
|
|
|
while len(self.jids):
|
|
|
|
self.handle_first_event()
|
|
|
|
|
|
|
|
def on_show_roster_menuitem_activate(self, widget):
|
|
|
|
win = gajim.interface.roster.window
|
|
|
|
win.present()
|
|
|
|
|
2005-06-15 13:14:59 +02:00
|
|
|
def on_preferences_menuitem_activate(self, widget):
|
2005-11-13 16:08:47 +01:00
|
|
|
if gajim.interface.instances['preferences'].window.get_property('visible'):
|
|
|
|
gajim.interface.instances['preferences'].window.present()
|
2005-06-15 13:14:59 +02:00
|
|
|
else:
|
2005-11-13 16:08:47 +01:00
|
|
|
gajim.interface.instances['preferences'].window.show_all()
|
2005-06-15 13:14:59 +02:00
|
|
|
|
2005-03-15 01:40:08 +01:00
|
|
|
def on_quit_menuitem_activate(self, widget):
|
2005-10-20 13:17:17 +02:00
|
|
|
gajim.interface.roster.on_quit_menuitem_activate(widget)
|
2005-03-15 01:40:08 +01:00
|
|
|
|
2005-03-14 18:30:52 +01:00
|
|
|
def make_groups_submenus_for_chat_with(self, account):
|
2005-11-04 16:22:12 +01:00
|
|
|
iconset = gajim.config.get('iconset')
|
|
|
|
if not iconset:
|
2005-12-12 16:14:58 +01:00
|
|
|
iconset = 'dcraven'
|
2005-12-12 16:13:31 +01:00
|
|
|
path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
2005-11-04 16:22:12 +01:00
|
|
|
state_images = gajim.interface.roster.load_iconset(path)
|
|
|
|
|
2005-03-14 18:30:52 +01:00
|
|
|
groups_menu = gtk.Menu()
|
|
|
|
|
2005-07-18 23:08:31 +02:00
|
|
|
for group in gajim.groups[account].keys():
|
2005-07-07 19:25:04 +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)
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
for jid in gajim.contacts.get_jid_list(account):
|
|
|
|
contact = gajim.get_contact_with_highest_priority(account, jid)
|
2005-11-04 16:22:12 +01:00
|
|
|
if group in contact.groups and contact.show != 'offline' and \
|
|
|
|
contact.show != 'error':
|
2005-03-14 18:30:52 +01:00
|
|
|
at_least_one = True
|
2005-11-17 17:28:41 +01:00
|
|
|
s = contact.name.replace('_', '__') # two _ show one _ and no underline happens
|
|
|
|
item = gtk.ImageMenuItem(s)
|
2005-11-04 16:22:12 +01:00
|
|
|
# any given gtk widget can only be used in one place
|
|
|
|
# (here we use it in status menu too)
|
|
|
|
# gtk.Image is a widget, it's better we refactor to use gdk.gdk.Pixbuf allover
|
|
|
|
img = state_images[contact.show]
|
|
|
|
img_copy = gobject.new(gtk.Image, pixbuf=img.get_pixbuf())
|
|
|
|
item.set_image(img_copy)
|
|
|
|
item.connect('activate', self.start_chat, account,
|
|
|
|
contact.jid)
|
2005-03-14 18:30:52 +01:00
|
|
|
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
|
|
|
|
2005-08-11 15:46:37 +02:00
|
|
|
def on_left_click(self):
|
2005-10-20 13:17:17 +02:00
|
|
|
win = gajim.interface.roster.window
|
2005-08-11 15:46:37 +02:00
|
|
|
if len(self.jids) == 0:
|
2005-10-31 19:06:36 +01:00
|
|
|
# no pending events, so toggle visible/hidden for roster window
|
|
|
|
if win.get_property('visible'): # visible in ANY virtual desktop?
|
|
|
|
win.hide() # we hide it from VD that was visible in
|
2005-10-31 20:35:17 +01:00
|
|
|
|
2005-10-31 19:06:36 +01:00
|
|
|
# but we could be in another VD right now. eg vd2
|
|
|
|
# and we want not only to hide it in vd1 but also show it in vd2
|
2005-10-31 20:35:17 +01:00
|
|
|
gtkgui_helpers.possibly_move_window_in_current_desktop(win)
|
2005-06-07 00:51:10 +02:00
|
|
|
else:
|
2005-06-07 01:42:31 +02:00
|
|
|
win.present()
|
2005-08-11 15:46:37 +02:00
|
|
|
else:
|
2005-10-30 02:08:39 +02:00
|
|
|
self.handle_first_event()
|
|
|
|
|
|
|
|
def handle_first_event(self):
|
|
|
|
account = self.jids[0][0]
|
|
|
|
jid = self.jids[0][1]
|
|
|
|
typ = self.jids[0][2]
|
2005-12-11 11:31:42 +01:00
|
|
|
gajim.interface.handle_event(account, jid, typ)
|
2005-10-30 02:08:39 +02:00
|
|
|
|
2005-08-11 15:46:37 +02:00
|
|
|
def on_middle_click(self):
|
2005-10-31 20:35:17 +01:00
|
|
|
'''middle click raises window to have complete focus (fe. get kbd events)
|
|
|
|
but if already raised, it hides it'''
|
2005-10-20 13:17:17 +02:00
|
|
|
win = gajim.interface.roster.window
|
2005-10-31 20:35:17 +01:00
|
|
|
if win.is_active(): # is it fully raised? (eg does it receive kbd events?)
|
2005-08-11 15:46:37 +02:00
|
|
|
win.hide()
|
|
|
|
else:
|
|
|
|
win.present()
|
|
|
|
|
|
|
|
def on_clicked(self, widget, event):
|
|
|
|
self.on_tray_leave_notify_event(widget, None)
|
|
|
|
if event.button == 1: # Left click
|
|
|
|
self.on_left_click()
|
|
|
|
if event.button == 2: # middle click
|
|
|
|
self.on_middle_click()
|
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
|
|
|
|
2005-06-20 19:45:04 +02:00
|
|
|
def on_show_menuitem_activate(self, widget, show):
|
2005-11-08 12:13:47 +01:00
|
|
|
# we all add some fake (we cannot select those nor have them as show)
|
|
|
|
# but this helps to align with roster's status_combobox index positions
|
|
|
|
l = ['online', 'chat', 'away', 'xa', 'dnd', 'invisible', 'SEPARATOR',
|
|
|
|
'CHANGE_STATUS_MSG_MENUITEM', 'SEPARATOR', 'offline']
|
2005-07-19 22:12:02 +02:00
|
|
|
index = l.index(show)
|
2005-10-20 13:17:17 +02:00
|
|
|
gajim.interface.roster.status_combobox.set_active(index)
|
2005-10-09 16:49:14 +02:00
|
|
|
|
|
|
|
def on_change_status_message_activate(self, widget):
|
2005-11-06 18:10:55 +01:00
|
|
|
model = gajim.interface.roster.status_combobox.get_model()
|
2005-11-07 15:06:39 +01:00
|
|
|
active = gajim.interface.roster.status_combobox.get_active()
|
2005-11-05 18:52:49 +01:00
|
|
|
status = model[active][2].decode('utf-8')
|
|
|
|
dlg = dialogs.ChangeStatusMessageDialog(status)
|
2005-10-09 16:49:14 +02:00
|
|
|
message = dlg.run()
|
2005-10-10 00:24:18 +02:00
|
|
|
if message is not None: # None if user press Cancel
|
|
|
|
accounts = gajim.connections.keys()
|
|
|
|
for acct in accounts:
|
2005-10-10 21:10:59 +02:00
|
|
|
if not gajim.config.get_per('accounts', acct,
|
|
|
|
'sync_with_global_status'):
|
|
|
|
continue
|
2005-10-10 00:24:18 +02:00
|
|
|
show = gajim.SHOW_LIST[gajim.connections[acct].connected]
|
2005-10-20 13:17:17 +02:00
|
|
|
gajim.interface.roster.send_status(acct, show, message)
|
2005-10-09 16:49:14 +02:00
|
|
|
|
2005-07-31 21:21:11 +02:00
|
|
|
def show_tooltip(self, widget):
|
|
|
|
position = widget.window.get_origin()
|
|
|
|
if self.tooltip.id == position:
|
|
|
|
size = widget.window.get_size()
|
|
|
|
self.tooltip.show_tooltip('',
|
|
|
|
(widget.window.get_pointer()[0], size[1]), position)
|
|
|
|
|
|
|
|
def on_tray_motion_notify_event(self, widget, event):
|
|
|
|
wireq=widget.size_request()
|
|
|
|
position = widget.window.get_origin()
|
|
|
|
if self.tooltip.timeout > 0:
|
|
|
|
if self.tooltip.id != position:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
if self.tooltip.timeout == 0 and \
|
|
|
|
self.tooltip.id != position:
|
|
|
|
self.tooltip.id = position
|
|
|
|
self.tooltip.timeout = gobject.timeout_add(500,
|
|
|
|
self.show_tooltip, widget)
|
|
|
|
|
|
|
|
def on_tray_leave_notify_event(self, widget, event):
|
|
|
|
position = widget.window.get_origin()
|
|
|
|
if self.tooltip.timeout > 0 and \
|
|
|
|
self.tooltip.id == position:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
|
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-07-30 12:06:58 +02:00
|
|
|
# avoid draw seperate bg color in some gtk themes
|
|
|
|
eb.set_visible_window(False)
|
2005-07-31 21:21:11 +02:00
|
|
|
eb.set_events(gtk.gdk.POINTER_MOTION_MASK)
|
2005-03-15 15:21:09 +01:00
|
|
|
eb.connect('button-press-event', self.on_clicked)
|
2005-07-31 21:21:11 +02:00
|
|
|
eb.connect('motion-notify-event', self.on_tray_motion_notify_event)
|
|
|
|
eb.connect('leave-notify-event', self.on_tray_leave_notify_event)
|
2005-10-20 13:17:17 +02:00
|
|
|
self.tooltip = tooltips.NotificationAreaTooltip()
|
2005-07-31 21:32:06 +02:00
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
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
|