1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# -*- coding: utf-8 -*-
##
import gtk
import os
from plugins.gui import GajimPluginConfigDialog
from plugins import GajimPlugin
from plugins.helpers import log_calls
import gtkgui_helpers
from common import gajim
from common import helpers
from common import ged
class ServerStatusIconsPlugin(GajimPlugin):
@log_calls('ServerStatusIconsPlugin')
def init(self):
self.description = _('Replace standard Gajim status icons with server'
' specific for known XMPP server accounts (vk.com, ...)')
self.pos_list = [_('after statusicon'), _('before avatar')]
self.gui_extension_points = {
'roster_draw_contact': (self.connect_with_roster_draw_contact,
self.disconnect_from_roster_draw_contact)}
self.known_servers = {'chat.facebook.com': 'facebook',
'gmail.com': 'gtalk',
'livejournal.com': 'livejournal',
'odnoklassniki.ru': 'odnoklassniki',
'vk.com': 'vkontakte',
'ya.ru': 'yaonline'}
@log_calls('ServerStatusIconsPlugin')
def connect_with_roster_draw_contact(self, roster, jid, account, contact):
if not self.active:
return
if gajim.jid_is_transport(jid):
return
child_iters = roster._get_contact_iter(jid, account, contact,
roster.model)
if not child_iters:
return
icon_name = helpers.get_icon_name_to_show(contact, account)
if gajim.events.get_events(account, jid) or icon_name == 'requested':
return
host = jid.split('@')[1]
server = self.known_servers.get(host, False)
if not server:
return
if server not in roster.transports_state_images['16']:
# we don't have iconset for this transport loaded yet. Let's do it
self.make_transport_state_images(roster, server)
if server in roster.transports_state_images['16'] and \
icon_name in roster.transports_state_images['16'][server]:
state_images = roster.transports_state_images['16'][server]
img = state_images[icon_name]
for child_iter in child_iters:
roster.model[child_iter][0] = img
def make_transport_state_images(self, roster, transport):
"""
Initialize opened and closed 'transport' iconset dict
"""
folder = os.path.join(self.local_file_path(transport), '16x16')
pixo, pixc = gtkgui_helpers.load_icons_meta()
roster.transports_state_images['opened'][transport] = \
gtkgui_helpers.load_iconset(folder, pixo, transport=True)
roster.transports_state_images['closed'][transport] = \
gtkgui_helpers.load_iconset(folder, pixc, transport=True)
roster.transports_state_images['16'][transport] = \
gtkgui_helpers.load_iconset(folder, transport=True)
folder = os.path.join(self.local_file_path(transport), '32x32')
roster.transports_state_images['32'][transport] = \
gtkgui_helpers.load_iconset(folder, transport=True)
def _nec_our_show(self, obj):
account = obj.conn.name
roster = gajim.interface.roster
status = gajim.connections[account].connected
if account not in gajim.contacts.get_accounts():
return
child_iterA = roster._get_account_iter(account, roster.model)
if not child_iterA:
return
hostname = gajim.config.get_per('accounts', account, 'hostname')
server = self.known_servers.get(hostname, False)
if not server:
return
if not roster.regroup:
show = gajim.SHOW_LIST[status]
else: # accounts merged
show = helpers.get_global_show()
if server not in roster.transports_state_images['16']:
# we don't have iconset for this transport loaded yet. Let's do it
self.make_transport_state_images(roster, server)
if server in roster.transports_state_images['16'] and \
show in roster.transports_state_images['16'][server]:
roster.model[child_iterA][0] = roster.transports_state_images[
'16'][server][show]
@log_calls('ServerStatusIconsPlugin')
def disconnect_from_roster_draw_contact(self, roster, jid, account,
contact):
pass
@log_calls('ServerStatusIconsPlugin')
def activate(self):
self.active = True
gajim.interface.roster.setup_and_draw_roster()
gajim.ged.register_event_handler('our-show', ged.GUI2,
self._nec_our_show)
@log_calls('ServerStatusIconsPlugin')
def deactivate(self):
self.active = None
gajim.ged.remove_event_handler('our-show', ged.GUI2,
self._nec_our_show)
gajim.interface.roster.setup_and_draw_roster()
|