[clients_icons] Add gc tooltip support

This commit is contained in:
Daniel
2018-02-22 12:35:44 +01:00
committed by Philipp Hörist
parent d4596acb17
commit baa724e212

View File

@@ -4,6 +4,7 @@
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
import os import os
import logging
from gajim.plugins.gui import GajimPluginConfigDialog from gajim.plugins.gui import GajimPluginConfigDialog
from gajim.plugins import GajimPlugin from gajim.plugins import GajimPlugin
@@ -12,6 +13,8 @@ from gajim.common import ged
from gajim.common import app from gajim.common import app
import gajim.cell_renderer_image import gajim.cell_renderer_image
log = logging.getLogger('gajim.plugin_system.clients_icons')
clients = { clients = {
'http://www.adium.im/': ['adium.png', 'Adium'], 'http://www.adium.im/': ['adium.png', 'Adium'],
'http://www.adiumx.com/caps': ['adium.png', 'Adium'], 'http://www.adiumx.com/caps': ['adium.png', 'Adium'],
@@ -114,6 +117,7 @@ clients = {
'Pix-Art Messenger': ['pixart.png', 'Pix-Art Messenger'], 'Pix-Art Messenger': ['pixart.png', 'Pix-Art Messenger'],
'httр://sleekxmpp.com/ver/1.1.11': ['poezio.png', 'Poezio'], 'httр://sleekxmpp.com/ver/1.1.11': ['poezio.png', 'Poezio'],
'http://psi-im.org/caps': ['psi.png', 'Psi'], 'http://psi-im.org/caps': ['psi.png', 'Psi'],
'http://psi-plus.com': ['psiplus.png', 'Psi+'],
'http://psi-dev.googlecode.com/caps': ['psiplus.png', 'Psi+'], 'http://psi-dev.googlecode.com/caps': ['psiplus.png', 'Psi+'],
'psto@psto.net': ['psto.png', 'Psto'], 'psto@psto.net': ['psto.png', 'Psto'],
'http://pyaim': ['pyaim-t.png', 'PyAIM-t'], 'http://pyaim': ['pyaim-t.png', 'PyAIM-t'],
@@ -131,6 +135,8 @@ clients = {
'Siemens': ['siejc.png', 'Siemens'], # Siemens Native Jabber Client 'Siemens': ['siejc.png', 'Siemens'], # Siemens Native Jabber Client
'http://sim-im.org/caps': ['sim.png', 'Sim'], 'http://sim-im.org/caps': ['sim.png', 'Sim'],
'http://www.lonelycatgames.com/slick/caps': ['slick.png', 'Slick'], 'http://www.lonelycatgames.com/slick/caps': ['slick.png', 'Slick'],
'http://slixmpp.com/ver/1.2.4': ['bot.png', 'Slixmpp'],
'http://slixmpp.com/ver/1.3.0': ['bot.png', 'Slixmpp'],
'http://snapi-bot.googlecode.com/caps': ['bot.png', 'Snapi-bot'], 'http://snapi-bot.googlecode.com/caps': ['bot.png', 'Snapi-bot'],
'http://www.igniterealtime.org/project/spark/caps': ['spark.png', 'Spark'], 'http://www.igniterealtime.org/project/spark/caps': ['spark.png', 'Spark'],
'http://spectrum.im/': ['spectrum.png', 'Spectrum'], 'http://spectrum.im/': ['spectrum.png', 'Spectrum'],
@@ -183,13 +189,13 @@ class ClientsIconsPlugin(GajimPlugin):
} }
self.gui_extension_points = { self.gui_extension_points = {
'groupchat_control': (self.connect_with_groupchat_control, 'groupchat_control': (self.connect_with_groupchat_control,
self.disconnect_from_groupchat_control), self.disconnect_from_groupchat_control),
'roster_draw_contact': (self.connect_with_roster_draw_contact, 'roster_draw_contact': (self.connect_with_roster_draw_contact,
self.disconnect_from_roster_draw_contact), self.disconnect_from_roster_draw_contact),
#'roster_tooltip_populate': (self.connect_with_roster_tooltip_populate, #'roster_tooltip_populate': (self.connect_with_roster_tooltip_populate,
# self.disconnect_from_roster_tooltip_populate), # self.disconnect_from_roster_tooltip_populate),
#'gc_tooltip_populate': (self.connect_with_gc_tooltip_populate, 'gc_tooltip_populate': (self.connect_with_gc_tooltip_populate,
# self.disconnect_from_gc_tooltip_populate), self.disconnect_from_gc_tooltip_populate),
} }
self.config_default_values = { self.config_default_values = {
'show_in_roster': (True, ''), 'show_in_roster': (True, ''),
@@ -206,37 +212,63 @@ class ClientsIconsPlugin(GajimPlugin):
self.icon_cache = {} self.icon_cache = {}
@log_calls('ClientsIconsPlugin') @log_calls('ClientsIconsPlugin')
def connect_with_gc_tooltip_populate(self, tooltip, contact, def add_tooltip_row(self, tooltip, contact, tooltip_grid):
vcard_table): caps = contact.client_caps._node
if not self.config['show_in_tooltip']: log.debug('connect_with_gc_tooltip_populate, caps: %s', caps)
return caps_image , client_name = self.get_icon(caps, contact)
caps_image.set_halign(Gtk.PositionType.RIGHT)
log.debug('connect_with_gc_tooltip_populate, client_name: %s', \
client_name)
# fill clients table # fill clients table
self.table = Gtk.Grid() self.table = Gtk.Grid()
self.table.insert_row(0) self.table.set_name('client_icons_grid')
self.table.insert_row(0) self.table.set_property('column-spacing', 5)
self.table.insert_column(0)
self.table.set_property('column-spacing', 2)
caps = contact.client_caps._node
caps_image , client_name = self.get_icon(caps, contact)
caps_image.set_alignment(0, 0)
self.table.attach(caps_image, 1, 1, 1, 1) self.table.attach(caps_image, 1, 1, 1, 1)
label = Gtk.Label() label_name = Gtk.Label()
label.set_alignment(0, 0) label_name.set_halign(Gtk.PositionType.RIGHT)
label.set_markup(client_name) label_name.set_markup(client_name)
self.table.attach(label, 2, 1, 1, 1) self.table.attach(label_name, 2, 1, 1, 1)
self.table.show_all()
# set label # set label
label = Gtk.Label() label = Gtk.Label()
label.set_alignment(0, 0) label.set_name('client_icons_label')
label.set_halign(Gtk.PositionType.RIGHT)
label.set_markup(_('Client:')) label.set_markup(_('Client:'))
vcard_table.attach(label, 1, 100, 1,1) label.show()
# set client table to tooltip # set client table to tooltip
vcard_table.attach(self.table, 2, 100, 1,1) tooltip_grid.insert_next_to(tooltip.resource_label,
Gtk.PositionType.BOTTOM)
tooltip_grid.attach_next_to(label, tooltip.resource_label,
Gtk.PositionType.BOTTOM, 1, 1)
tooltip_grid.attach_next_to(self.table, label,
Gtk.PositionType.RIGHT, 1, 1)
@log_calls('ClientsIconsPlugin')
def connect_with_gc_tooltip_populate(self, tooltip, contact, tooltip_grid):
if not self.config['show_in_tooltip']:
return
# Check if clients info already attached to tooltip
has_attached = False
for child in tooltip_grid.get_children():
if child.get_name() == 'client_icons_grid':
caps = contact.client_caps._node
caps_image , client_name = self.get_icon(caps, contact)
child.remove(child.get_child_at(1, 1))
child.attach(caps_image, 1, 1, 1, 1)
child.get_child_at(2, 1).set_markup(client_name)
child.show_all()
if child.get_name() == 'client_icons_label':
child.show()
has_attached = True
if not has_attached:
self.add_tooltip_row(tooltip, contact, tooltip_grid)
@log_calls('ClientsIconsPlugin') @log_calls('ClientsIconsPlugin')
def connect_with_roster_tooltip_populate(self, tooltip, contacts, def connect_with_roster_tooltip_populate(self, tooltip, contacts,
vcard_table): tooltip_grid):
if not self.config['show_in_tooltip']: if not self.config['show_in_tooltip']:
return return
if len(contacts) == 1 and contacts[0].jid in app.get_our_jids(): if len(contacts) == 1 and contacts[0].jid in app.get_our_jids():
@@ -286,14 +318,15 @@ class ClientsIconsPlugin(GajimPlugin):
if contact.show == 'offline': if contact.show == 'offline':
return return
label.set_markup(_('Client:')) label.set_markup(_('Client:'))
vcard_table.attach(label, 1, first_place, 1, 1) tooltip_grid.attach(label, 1, first_place, 1, 1)
# set clients table to tooltip # set clients table to tooltip
vcard_table.attach(self.table, 2, first_place, 1, 1) tooltip_grid.attach(self.table, 2, first_place, 1, 1)
def get_icon(self, caps, contact=None): def get_icon(self, caps, contact=None):
if not caps: if not caps:
return Gtk.Image.new_from_pixbuf(self.default_pixbuf), _('Unknown') return Gtk.Image.new_from_pixbuf(self.default_pixbuf), _('Unknown')
log.debug('get_icon, caps: %s', caps)
# 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'
for client in libpurple_clients: for client in libpurple_clients:
@@ -302,11 +335,10 @@ 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()
if caps_: if caps_:
client_icon = clients.get(caps_[0].split()[0], (None,))[0] client_icon = clients.get(caps_[0].split()[0], (None,))[0]
@@ -329,7 +361,7 @@ class ClientsIconsPlugin(GajimPlugin):
@log_calls('ClientsIconsPlugin') @log_calls('ClientsIconsPlugin')
def disconnect_from_roster_tooltip_populate(self, tooltip, contacts, def disconnect_from_roster_tooltip_populate(self, tooltip, contacts,
vcard_table): tooltip_grid):
pass pass
def check_jid(self, jid): def check_jid(self, jid):
@@ -509,6 +541,7 @@ class ClientsIconsPlugin(GajimPlugin):
if roster.model[iter_][self.renderer_num] is not None: if roster.model[iter_][self.renderer_num] is not None:
caps = contact.client_caps._node caps = contact.client_caps._node
if caps: if caps:
log.debug('presence_received, caps: %s', caps)
self.set_icon(roster.model, iter_, self.renderer_num, caps) self.set_icon(roster.model, iter_, self.renderer_num, caps)
return return
caps = None caps = None
@@ -543,6 +576,7 @@ class ClientsIconsPlugin(GajimPlugin):
if tag: if tag:
caps = tag[0].getAttr('node') caps = tag[0].getAttr('node')
if caps: if caps:
log.debug('gc_presence_received, caps: %s', caps)
if 'pidgin.im/' in caps: if 'pidgin.im/' in caps:
caps = 'libpurple' caps = 'libpurple'
if 'sleekxmpp.com' in caps: if 'sleekxmpp.com' in caps:
@@ -560,6 +594,7 @@ class ClientsIconsPlugin(GajimPlugin):
return return
caps_ = caps.split('#')[0].split() caps_ = caps.split('#')[0].split()
if caps_: if caps_:
log.debug('set_icon, caps_: %s', caps_)
client_icon = clients.get(caps_[0].split()[0], (None,))[0] client_icon = clients.get(caps_[0].split()[0], (None,))[0]
else: else:
client_icon = None client_icon = None
@@ -599,7 +634,7 @@ class ClientsIconsPlugin(GajimPlugin):
@log_calls('ClientsIconsPlugin') @log_calls('ClientsIconsPlugin')
def disconnect_from_gc_tooltip_populate(self, tooltip, contact, def disconnect_from_gc_tooltip_populate(self, tooltip, contact,
vcard_table): tooltip_grid):
pass pass