[clients_icons] Adapt to Gajim changes
This commit is contained in:
@@ -33,16 +33,16 @@ log = logging.getLogger('gajim.p.client_icons')
|
|||||||
|
|
||||||
class ClientsIconsPlugin(GajimPlugin):
|
class ClientsIconsPlugin(GajimPlugin):
|
||||||
def init(self):
|
def init(self):
|
||||||
self.description = _('Shows client icons in roster'
|
self.description = _('Shows client icons in your contact list '
|
||||||
' and in groupchats.')
|
'and in the groupchat participants list.')
|
||||||
self.config_dialog = partial(ClientsIconsConfigDialog, self)
|
self.config_dialog = partial(ClientsIconsConfigDialog, self)
|
||||||
|
|
||||||
self.gui_extension_points = {
|
self.gui_extension_points = {
|
||||||
'roster_tooltip_populate': (
|
'roster_tooltip_resource_populate': (
|
||||||
self.connect_with_roster_tooltip_populate,
|
self._roster_tooltip_resource_populate,
|
||||||
None),
|
None),
|
||||||
'gc_tooltip_populate': (
|
'gc_tooltip_populate': (
|
||||||
self.connect_with_gc_tooltip_populate,
|
self._gc_roster_tooltip_populate,
|
||||||
None),
|
None),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +62,7 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
return identity.name
|
return identity.name
|
||||||
|
|
||||||
def _get_image_and_client_name(self, contact, widget):
|
def _get_image_and_client_name(self, contact, widget):
|
||||||
disco_info = app.storage.cache.get_last_disco_info(
|
disco_info = app.storage.cache.get_last_disco_info(contact.jid)
|
||||||
contact.get_full_jid())
|
|
||||||
if disco_info is None:
|
if disco_info is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -78,46 +77,26 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
surface = load_icon(icon_name, widget=widget)
|
surface = load_icon(icon_name, widget=widget)
|
||||||
return Gtk.Image.new_from_surface(surface), client_name
|
return Gtk.Image.new_from_surface(surface), client_name
|
||||||
|
|
||||||
@staticmethod
|
def _roster_tooltip_resource_populate(self, resource_box, resource):
|
||||||
def _is_groupchat(contact):
|
if not self.config['show_in_tooltip']:
|
||||||
if hasattr(contact, 'is_groupchat'):
|
return
|
||||||
return contact.is_groupchat
|
|
||||||
return False
|
|
||||||
|
|
||||||
def add_tooltip_row(self, tooltip, contact, tooltip_grid):
|
result = self._get_image_and_client_name(resource, resource_box)
|
||||||
caps = contact.client_caps._node
|
if result is None:
|
||||||
caps_image, client_name = self.get_icon(caps, contact, tooltip_grid)
|
return
|
||||||
caps_image.set_halign(Gtk.Align.END)
|
|
||||||
|
|
||||||
# Fill clients grid
|
image, client_name = result
|
||||||
self.grid = Gtk.Grid()
|
label = Gtk.Label(label=client_name)
|
||||||
self.grid.set_name('client_icons_grid')
|
|
||||||
self.grid.set_property('column-spacing', 5)
|
|
||||||
self.grid.attach(caps_image, 1, 1, 1, 1)
|
|
||||||
label_name = Gtk.Label()
|
|
||||||
label_name.set_halign(Gtk.Align.END)
|
|
||||||
label_name.set_valign(Gtk.Align.CENTER)
|
|
||||||
label_name.set_markup(client_name)
|
|
||||||
self.grid.attach(label_name, 2, 1, 1, 1)
|
|
||||||
self.grid.show_all()
|
|
||||||
|
|
||||||
# Set label
|
client_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
|
||||||
label = Gtk.Label()
|
halign=Gtk.Align.START)
|
||||||
label.set_name('client_icons_label')
|
client_box.add(image)
|
||||||
label.set_halign(Gtk.Align.END)
|
client_box.add(label)
|
||||||
label.set_valign(Gtk.Align.CENTER)
|
|
||||||
label.set_markup(_('Client:'))
|
|
||||||
label.show()
|
|
||||||
|
|
||||||
# Set client grid to tooltip
|
children = resource_box.get_children()
|
||||||
tooltip_grid.insert_next_to(tooltip.resource_label,
|
children[0].add(client_box)
|
||||||
Gtk.PositionType.BOTTOM)
|
|
||||||
tooltip_grid.attach_next_to(label, tooltip.resource_label,
|
|
||||||
Gtk.PositionType.BOTTOM, 1, 1)
|
|
||||||
tooltip_grid.attach_next_to(self.grid, label,
|
|
||||||
Gtk.PositionType.RIGHT, 1, 1)
|
|
||||||
|
|
||||||
def connect_with_gc_tooltip_populate(self, tooltip, contact, tooltip_grid):
|
def _gc_roster_tooltip_populate(self, tooltip, contact, tooltip_grid):
|
||||||
if not self.config['show_in_tooltip']:
|
if not self.config['show_in_tooltip']:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -138,74 +117,3 @@ class ClientsIconsPlugin(GajimPlugin):
|
|||||||
Gtk.PositionType.BOTTOM)
|
Gtk.PositionType.BOTTOM)
|
||||||
tooltip_grid.attach_next_to(box, tooltip._ui.affiliation,
|
tooltip_grid.attach_next_to(box, tooltip._ui.affiliation,
|
||||||
Gtk.PositionType.BOTTOM, 1, 1)
|
Gtk.PositionType.BOTTOM, 1, 1)
|
||||||
|
|
||||||
def connect_with_roster_tooltip_populate(self, tooltip, contacts,
|
|
||||||
tooltip_grid):
|
|
||||||
if not self.config['show_in_tooltip']:
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(contacts) == 1 and contacts[0].jid in app.get_our_jids():
|
|
||||||
return
|
|
||||||
|
|
||||||
if self._is_groupchat(contacts[0]):
|
|
||||||
return
|
|
||||||
|
|
||||||
# Put contacts in dict, where key is priority
|
|
||||||
num_resources = 0
|
|
||||||
contacts_dict = {}
|
|
||||||
for contact in contacts:
|
|
||||||
if contact.show == 'offline':
|
|
||||||
return
|
|
||||||
if contact.resource:
|
|
||||||
num_resources += 1
|
|
||||||
if int(contact.priority) in contacts_dict:
|
|
||||||
contacts_dict[int(contact.priority)].append(contact)
|
|
||||||
else:
|
|
||||||
contacts_dict[int(contact.priority)] = [contact]
|
|
||||||
contact_keys = sorted(contacts_dict.keys())
|
|
||||||
contact_keys.reverse()
|
|
||||||
|
|
||||||
# Fill clients grid
|
|
||||||
grid = Gtk.Grid()
|
|
||||||
grid.insert_row(0)
|
|
||||||
grid.insert_row(0)
|
|
||||||
grid.insert_column(0)
|
|
||||||
grid.set_property('column-spacing', 2)
|
|
||||||
|
|
||||||
vcard_current_row = 0
|
|
||||||
for priority in contact_keys:
|
|
||||||
for acontact in contacts_dict[priority]:
|
|
||||||
|
|
||||||
result = self._get_image_and_client_name(acontact, tooltip_grid)
|
|
||||||
if result is None:
|
|
||||||
continue
|
|
||||||
image, client_name = result
|
|
||||||
|
|
||||||
image.set_valign(Gtk.Align.START)
|
|
||||||
grid.attach(image, 1, vcard_current_row, 1, 1)
|
|
||||||
label = Gtk.Label(label=client_name)
|
|
||||||
label.set_valign(Gtk.Align.START)
|
|
||||||
label.set_halign(Gtk.Align.START)
|
|
||||||
label.set_xalign(0)
|
|
||||||
grid.attach(label, 2, vcard_current_row, 1, 1)
|
|
||||||
vcard_current_row += 1
|
|
||||||
grid.show_all()
|
|
||||||
grid.set_valign(Gtk.Align.START)
|
|
||||||
|
|
||||||
# Set label
|
|
||||||
label = Gtk.Label()
|
|
||||||
label.set_halign(Gtk.Align.END)
|
|
||||||
label.set_valign(Gtk.Align.START)
|
|
||||||
if num_resources > 1:
|
|
||||||
label.set_text(_('Clients:'))
|
|
||||||
else:
|
|
||||||
label.set_text(_('Client:'))
|
|
||||||
label.show()
|
|
||||||
|
|
||||||
# Set clients grid to tooltip
|
|
||||||
tooltip_grid.insert_next_to(tooltip._ui.resource_label,
|
|
||||||
Gtk.PositionType.BOTTOM)
|
|
||||||
tooltip_grid.attach_next_to(label, tooltip._ui.resource_label,
|
|
||||||
Gtk.PositionType.BOTTOM, 1, 1)
|
|
||||||
tooltip_grid.attach_next_to(grid, label,
|
|
||||||
Gtk.PositionType.RIGHT, 1, 1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user