[clients_icons] Address MR comments and cleanup code
This commit is contained in:
committed by
Philipp Hörist
parent
5a68b17b82
commit
a6a7b57636
@@ -212,15 +212,37 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
16, 16)
|
16, 16)
|
||||||
self.icon_cache = {}
|
self.icon_cache = {}
|
||||||
|
|
||||||
|
@log_calls('ClientsIconsPlugin')
|
||||||
|
def get_client_name(self, contact, client_name):
|
||||||
|
identities = contact.client_caps.get_cache_lookup_strategy()(
|
||||||
|
caps_cache.capscache).identities
|
||||||
|
if identities:
|
||||||
|
log.debug('get_client_name, identities: %s', str(identities))
|
||||||
|
for entry in identities:
|
||||||
|
if entry['category'] == 'client':
|
||||||
|
if entry['name']:
|
||||||
|
client_name = entry['name']
|
||||||
|
break
|
||||||
|
return client_name
|
||||||
|
|
||||||
|
def get_client_icon_by_name(self, client_name):
|
||||||
|
client_icon = None
|
||||||
|
name_splits = client_name.split()
|
||||||
|
name_splits = reversed([" ".join(name_splits[:(i+1)]) for i in range(len(name_splits))])
|
||||||
|
for name in name_splits:
|
||||||
|
if not client_icon:
|
||||||
|
log.debug("get_client_icon_by_name, searching for name fragment '%s'..." % name)
|
||||||
|
client_icon = clients.get(name, (None,))[0]
|
||||||
|
if client_icon:
|
||||||
|
break;
|
||||||
|
return client_icon
|
||||||
|
|
||||||
@log_calls('ClientsIconsPlugin')
|
@log_calls('ClientsIconsPlugin')
|
||||||
def add_tooltip_row(self, tooltip, contact, tooltip_grid):
|
def add_tooltip_row(self, tooltip, contact, tooltip_grid):
|
||||||
caps = contact.client_caps._node
|
caps = contact.client_caps._node
|
||||||
log.debug('connect_with_gc_tooltip_populate, caps: %s', caps)
|
log.debug('connect_with_gc_tooltip_populate, caps: %s', caps)
|
||||||
caps_image, client_name = self.get_icon(caps, contact)
|
caps_image, client_name = self.get_icon(caps, contact)
|
||||||
identities = acontact.client_caps._lookup_in_cache(
|
client_name = self.get_client_name(contact, client_name);
|
||||||
caps_cache.capscache).identities
|
|
||||||
if identities:
|
|
||||||
client_name = identities[0].get('name', client_name)
|
|
||||||
caps_image.set_halign(Gtk.PositionType.RIGHT)
|
caps_image.set_halign(Gtk.PositionType.RIGHT)
|
||||||
log.debug('connect_with_gc_tooltip_populate, client_name: %s', \
|
log.debug('connect_with_gc_tooltip_populate, client_name: %s', \
|
||||||
client_name)
|
client_name)
|
||||||
@@ -244,8 +266,8 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
label.show()
|
label.show()
|
||||||
|
|
||||||
# set client table to tooltip
|
# set client table to tooltip
|
||||||
#tooltip_grid.insert_next_to(tooltip.resource_label,
|
tooltip_grid.insert_next_to(tooltip.resource_label,
|
||||||
#Gtk.PositionType.BOTTOM)
|
Gtk.PositionType.BOTTOM)
|
||||||
tooltip_grid.attach_next_to(label, tooltip.resource_label,
|
tooltip_grid.attach_next_to(label, tooltip.resource_label,
|
||||||
Gtk.PositionType.BOTTOM, 1, 1)
|
Gtk.PositionType.BOTTOM, 1, 1)
|
||||||
tooltip_grid.attach_next_to(self.table, label,
|
tooltip_grid.attach_next_to(self.table, label,
|
||||||
@@ -306,10 +328,7 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
for acontact in contacts_dict[priority]:
|
for acontact in contacts_dict[priority]:
|
||||||
caps = acontact.client_caps._node
|
caps = acontact.client_caps._node
|
||||||
caps_image, client_name = self.get_icon(caps, acontact)
|
caps_image, client_name = self.get_icon(caps, acontact)
|
||||||
identities = acontact.client_caps._lookup_in_cache(
|
client_name = self.get_client_name(acontact, client_name)
|
||||||
caps_cache.capscache).identities
|
|
||||||
if identities:
|
|
||||||
client_name = identities[0].get('name', client_name)
|
|
||||||
caps_image.set_alignment(0, 0)
|
caps_image.set_alignment(0, 0)
|
||||||
self.table.attach(caps_image, 1, vcard_current_row, 1, 1)
|
self.table.attach(caps_image, 1, vcard_current_row, 1, 1)
|
||||||
label = Gtk.Label()
|
label = Gtk.Label()
|
||||||
@@ -330,16 +349,17 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
label.set_markup(_('Client:'))
|
label.set_markup(_('Client:'))
|
||||||
label.show()
|
label.show()
|
||||||
# set clients table to tooltip
|
# set clients table to tooltip
|
||||||
#tooltip_grid.insert_next_to(tooltip.resource_label,
|
tooltip_grid.insert_next_to(tooltip.resource_label,
|
||||||
#Gtk.PositionType.BOTTOM)
|
Gtk.PositionType.BOTTOM)
|
||||||
tooltip_grid.attach_next_to(label, tooltip.resource_label,
|
tooltip_grid.attach_next_to(label, tooltip.resource_label,
|
||||||
Gtk.PositionType.BOTTOM, 1, 1)
|
Gtk.PositionType.BOTTOM, 1, 1)
|
||||||
tooltip_grid.attach_next_to(self.table, label,
|
tooltip_grid.attach_next_to(self.table, label,
|
||||||
Gtk.PositionType.RIGHT, 1, 1)
|
Gtk.PositionType.RIGHT, 1, 1)
|
||||||
|
|
||||||
def get_icon(self, caps, contact):
|
def get_icon(self, caps, contact):
|
||||||
if not caps:
|
client_name = _('Unknown')
|
||||||
return Gtk.Image.new_from_pixbuf(self.default_pixbuf), _('Unknown')
|
caps_ = None
|
||||||
|
if caps:
|
||||||
# libpurple returns pidgin.im/ only, we have to look for ressource name
|
# libpurple returns pidgin.im/ only, we have to look for ressource name
|
||||||
if 'pidgin.im/' in caps:
|
if 'pidgin.im/' in caps:
|
||||||
caps = 'libpurple'
|
caps = 'libpurple'
|
||||||
@@ -349,25 +369,13 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
|
|
||||||
if 'sleekxmpp.com'in caps:
|
if 'sleekxmpp.com'in caps:
|
||||||
caps = 'httр://sleekxmpp.com/ver/1.1.11'
|
caps = 'httр://sleekxmpp.com/ver/1.1.11'
|
||||||
client_name = _('Unknown')
|
|
||||||
caps_from_jid = self.check_jid(contact.jid)
|
caps_from_jid = self.check_jid(contact.jid)
|
||||||
if caps_from_jid:
|
if caps_from_jid:
|
||||||
caps = caps_from_jid
|
caps = caps_from_jid
|
||||||
caps_ = caps.split('#')[0].split()
|
caps_ = caps.split('#')[0].split()
|
||||||
|
|
||||||
client_name = _('Unknown')
|
client_name = self.get_client_name(contact, client_name)
|
||||||
client_icon = None
|
client_icon = self.get_client_icon_by_name(client_name)
|
||||||
identities = contact.client_caps._lookup_in_cache(
|
|
||||||
caps_cache.capscache).identities
|
|
||||||
if identities:
|
|
||||||
log.debug('get_icon, identities: %s', str(identities))
|
|
||||||
client_name = identities[0].get('name', _('Unknown'))
|
|
||||||
name_splits = client_name.split()
|
|
||||||
name_splits = reversed([" ".join(name_splits[:(i+1)]) for i in range(len(name_splits))])
|
|
||||||
for name in name_splits:
|
|
||||||
if not client_icon:
|
|
||||||
log.debug("get_icon, searching for name fragment '%s'..." % name)
|
|
||||||
client_icon = clients.get(name, (None,))[0]
|
|
||||||
|
|
||||||
if caps_ and not client_icon:
|
if caps_ and not client_icon:
|
||||||
client_icon = clients.get(caps_[0].split()[0], (None,))[0]
|
client_icon = clients.get(caps_[0].split()[0], (None,))[0]
|
||||||
@@ -411,6 +419,8 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
return
|
return
|
||||||
if not self.config['show_in_roster']:
|
if not self.config['show_in_roster']:
|
||||||
return
|
return
|
||||||
|
if contact.is_groupchat():
|
||||||
|
return
|
||||||
child_iters = roster._get_contact_iter(jid, account, contact,
|
child_iters = roster._get_contact_iter(jid, account, contact,
|
||||||
roster.model)
|
roster.model)
|
||||||
if not child_iters:
|
if not child_iters:
|
||||||
@@ -462,8 +472,10 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
gc_contact.role, gc_contact.affiliation, gc_contact.status,
|
gc_contact.role, gc_contact.affiliation, gc_contact.status,
|
||||||
gc_contact.jid)
|
gc_contact.jid)
|
||||||
if not self.config['show_in_groupchats']:
|
if not self.config['show_in_groupchats']:
|
||||||
|
log.debug("not showing in groupchats...")
|
||||||
continue
|
continue
|
||||||
caps = gc_contact.client_caps._node
|
caps = gc_contact.client_caps._node
|
||||||
|
log.debug("caps: %s" % str(caps))
|
||||||
self.set_icon(chat_control.model, iter_, self.muc_renderer_num,
|
self.set_icon(chat_control.model, iter_, self.muc_renderer_num,
|
||||||
caps, gc_contact)
|
caps, gc_contact)
|
||||||
chat_control.draw_all_roles()
|
chat_control.draw_all_roles()
|
||||||
@@ -549,6 +561,8 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
roster = app.interface.roster
|
roster = app.interface.roster
|
||||||
contact = app.contacts.get_contact_from_full_jid(iq_obj.conn.name,
|
contact = app.contacts.get_contact_from_full_jid(iq_obj.conn.name,
|
||||||
iq_obj.jid)
|
iq_obj.jid)
|
||||||
|
if contact.is_groupchat():
|
||||||
|
return
|
||||||
if contact is None:
|
if contact is None:
|
||||||
room_jid, nick = app.get_room_and_nick_from_fjid(iq_obj.fjid)
|
room_jid, nick = app.get_room_and_nick_from_fjid(iq_obj.fjid)
|
||||||
contact = app.contacts.get_gc_contact(iq_obj.conn.name, room_jid,
|
contact = app.contacts.get_gc_contact(iq_obj.conn.name, room_jid,
|
||||||
@@ -581,7 +595,7 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
roster = app.interface.roster
|
roster = app.interface.roster
|
||||||
contact = app.contacts.get_contact_with_highest_priority(
|
contact = app.contacts.get_contact_with_highest_priority(
|
||||||
iq_obj.conn.name, iq_obj.jid)
|
iq_obj.conn.name, iq_obj.jid)
|
||||||
if not contact:
|
if not contact or contact.is_groupchat():
|
||||||
return
|
return
|
||||||
|
|
||||||
if iq_obj.resource == 'local':
|
if iq_obj.resource == 'local':
|
||||||
@@ -649,19 +663,8 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
self.set_icon(model, iter_, self.muc_renderer_num, caps, contact)
|
self.set_icon(model, iter_, self.muc_renderer_num, caps, contact)
|
||||||
|
|
||||||
def set_icon(self, model, iter_, pos, caps, contact):
|
def set_icon(self, model, iter_, pos, caps, contact):
|
||||||
client_name = _('Unknown')
|
client_icon = self.get_client_icon_by_name(
|
||||||
client_icon = None
|
self.get_client_name(contact, _('Unknown')))
|
||||||
identities = contact.client_caps._lookup_in_cache(
|
|
||||||
caps_cache.capscache).identities
|
|
||||||
if identities:
|
|
||||||
log.debug('set_icon, identities: %s', str(identities))
|
|
||||||
client_name = identities[0].get('name', _('Unknown'))
|
|
||||||
name_splits = client_name.split()
|
|
||||||
name_splits = reversed([" ".join(name_splits[:(i+1)]) for i in range(len(name_splits))])
|
|
||||||
for name in name_splits:
|
|
||||||
if not client_icon:
|
|
||||||
log.debug("set_icon, searching for name fragment '%s'..." % name)
|
|
||||||
client_icon = clients.get(name, (None,))[0]
|
|
||||||
|
|
||||||
if caps and not client_icon:
|
if caps and not client_icon:
|
||||||
caps_ = caps.split('#')[0].split()
|
caps_ = caps.split('#')[0].split()
|
||||||
|
|||||||
Reference in New Issue
Block a user