Philipp Hörist pushed to branch master at gajim / gajim
Commits: 032930ce by Philipp Hörist at 2019-09-03T20:47:30Z Avatar: Add indicator for show value
- - - - - 279143f8 by Philipp Hörist at 2019-09-03T20:50:27Z StartChat: Display show value with avatar
- - - - - d15ec5e7 by Philipp Hörist at 2019-09-03T20:50:31Z ChatControl: Display show value with avatar
- - - - -
7 changed files:
- gajim/chat_control.py - gajim/common/contacts.py - gajim/data/gui/chat_control.ui - gajim/gtk/avatar.py - gajim/gtk/const.py - gajim/gtk/start_chat.py - gajim/gui_interface.py
Changes:
===================================== gajim/chat_control.py ===================================== @@ -678,19 +678,7 @@ class ChatControl(ChatControlBase): # The name banner is drawn here ChatControlBase.update_ui(self) self.update_toolbar() - - def _update_banner_state_image(self): - contact = app.contacts.get_contact_with_highest_priority( - self.account, self.contact.jid) - if not contact or self.resource: - # For transient contacts - contact = self.contact - show = contact.show - - # Set banner image - icon = get_icon_name(show) - banner_status_img = self.xml.get_object('banner_status_image') - banner_status_img.set_from_icon_name(icon, Gtk.IconSize.DND) + self.show_avatar()
def draw_banner_text(self): """ @@ -1239,11 +1227,13 @@ class ChatControl(ChatControlBase): return
scale = self.parent_win.window.get_scale_factor() - surface = app.contacts.get_avatar( - self.account, self.contact.jid, AvatarSize.CHAT, scale) + surface = app.contacts.get_avatar(self.account, + self.contact.jid, + AvatarSize.CHAT, + scale, + self.contact.show)
- image = self.xml.get_object('avatar_image') - image.set_from_surface(surface) + self.xml.avatar_image.set_from_surface(surface)
def _nec_update_avatar(self, obj): if obj.account != self.account:
===================================== gajim/common/contacts.py ===================================== @@ -600,13 +600,13 @@ class Contacts(): if contacts[0].is_groupchat: return contacts[0]
- def get_avatar(self, jid, size, scale): + def get_avatar(self, jid, size, scale, show=None): if jid not in self._contacts: return None
for resource in self._contacts[jid]: avatar = common.app.interface.get_avatar( - resource, size, scale) + resource, size, scale, show) if avatar is None: self.set_avatar(jid, None) return avatar
===================================== gajim/data/gui/chat_control.ui ===================================== @@ -560,17 +560,7 @@ </packing> </child> <child> - <object class="GtkImage" id="banner_status_image"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="stock">gtk-missing-image</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="padding">5</property> - <property name="position">3</property> - </packing> + <placeholder/> </child> </object> </child>
===================================== gajim/gtk/avatar.py ===================================== @@ -32,6 +32,7 @@ from gajim.common.const import AvatarSize from gajim.gtk.util import load_pixbuf from gajim.gtk.util import text_to_color from gajim.gtk.util import scale_with_ratio +from gajim.gtk.const import SHOW_COLORS
log = logging.getLogger('gajim.gtk.avatar') @@ -84,6 +85,40 @@ def generate_avatar(letters, color, size, scale): return context.get_target()
+def add_status_to_avatar(surface, show): + width = surface.get_width() + height = surface.get_height() + + new_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + new_surface.set_device_scale(*surface.get_device_scale()) + + scale = surface.get_device_scale()[0] + + context = cairo.Context(new_surface) + context.set_source_surface(surface, 0, 0) + context.paint() + + # Correct height and width for scale + width = width / scale + height = height / scale + + clip_size = width / 5 + context.set_source_rgb(255, 255, 255) + context.set_operator(cairo.Operator.CLEAR) + context.arc(width - clip_size, height - clip_size, clip_size, 0, 2 * pi) + context.fill() + + color = SHOW_COLORS[show] + show_size = width / 5 + show_radius = show_size * 0.80 + context.set_source_rgb(*color) + context.set_operator(cairo.Operator.OVER) + context.arc(width - show_size, height - show_size, show_radius, 0, 2 * pi) + context.fill() + + return context.get_target() + + def clip_circle(surface): new_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, surface.get_width(), @@ -113,22 +148,24 @@ class AvatarStorage(metaclass=Singleton): def invalidate_cache(self, jid): self._cache.pop(jid, None)
- def get_pixbuf(self, contact, size, scale): - surface = self.get_surface(contact, size, scale) + def get_pixbuf(self, contact, size, scale, show=None): + surface = self.get_surface(contact, size, scale, show) return Gdk.pixbuf_get_from_surface(surface, 0, 0, size, size)
- def get_surface(self, contact, size, scale): + def get_surface(self, contact, size, scale, show=None): jid = contact.jid if contact.is_gc_contact: jid = contact.get_full_jid()
- surface = self._cache[jid].get((size, scale)) + surface = self._cache[jid].get((size, scale, show)) if surface is not None: return surface
surface = self._get_avatar_from_storage(contact, size, scale) if surface is not None: - self._cache[jid][(size, scale)] = surface + if show is not None: + surface = add_status_to_avatar(surface, show) + self._cache[jid][(size, scale, show)] = surface return surface
name = contact.get_shown_name() @@ -141,7 +178,9 @@ class AvatarStorage(metaclass=Singleton): letter = self._generate_letter(name) surface = self._generate_default_avatar( letter, color_string, size, scale) - self._cache[jid][(size, scale)] = surface + if show is not None: + surface = add_status_to_avatar(surface, show) + self._cache[jid][(size, scale, show)] = surface return surface
def get_muc_surface(self, account, jid, size, scale):
===================================== gajim/gtk/const.py ===================================== @@ -67,3 +67,14 @@ class SettingType(IntEnum): VALUE = 2 ACTION = 3 DIALOG = 4 + + +SHOW_COLORS = { + 'online': (102/255, 191/255, 16/255), + 'offline': (154/255, 154/255, 154/255), + 'not in roster': (154/255, 154/255, 154/255), + 'chat': (102/255, 191/255, 16/255), + 'away': (255/255, 133/255, 51/255), + 'dnd': (230/255, 46/255, 0), + 'xa': (106/255, 0, 242/255) +}
===================================== gajim/gtk/start_chat.py ===================================== @@ -24,7 +24,6 @@ from gi.repository import Pango from nbxmpp.util import is_error_result
from gajim.common import app -from gajim.common import helpers from gajim.common.helpers import validate_jid from gajim.common.helpers import to_user_string from gajim.common.helpers import get_groupchat_name @@ -580,12 +579,13 @@ class ContactRow(Gtk.ListBoxRow): self.groupchat = groupchat self.new = jid == ''
+ show = contact.show if contact else 'offline'
grid = Gtk.Grid() grid.set_column_spacing(12) grid.set_size_request(260, -1)
- image = self._get_avatar_image(account, jid) + image = self._get_avatar_image(account, jid, show) image.set_size_request(AvatarSize.CHAT, AvatarSize.CHAT) grid.add(image)
@@ -604,11 +604,6 @@ class ContactRow(Gtk.ListBoxRow): self.name_label.set_width_chars(25) self.name_label.set_halign(Gtk.Align.START) self.name_label.get_style_context().add_class('bold16') - - status = contact.show if contact else 'offline' - css_class = helpers.get_css_show_color(status) - if css_class is not None: - self.name_label.get_style_context().add_class(css_class) middle_box.add(self.name_label)
self.jid_label = Gtk.Label(label=jid) @@ -634,7 +629,7 @@ class ContactRow(Gtk.ListBoxRow): self.add(grid) self.show_all()
- def _get_avatar_image(self, account, jid): + def _get_avatar_image(self, account, jid, show): if self.new: icon_name = 'avatar-default' if self.groupchat: @@ -648,7 +643,7 @@ class ContactRow(Gtk.ListBoxRow): return Gtk.Image.new_from_surface(surface)
avatar = app.contacts.get_avatar( - account, jid, AvatarSize.CHAT, scale) + account, jid, AvatarSize.CHAT, scale, show) return Gtk.Image.new_from_surface(avatar)
def update_jid(self, jid):
===================================== gajim/gui_interface.py ===================================== @@ -1994,10 +1994,10 @@ class Interface: def save_avatar(self, data): return self.avatar_storage.save_avatar(data)
- def get_avatar(self, contact, size, scale, pixbuf=False): + def get_avatar(self, contact, size, scale, show=None, pixbuf=False): if pixbuf: - return self.avatar_storage.get_pixbuf(contact, size, scale) - return self.avatar_storage.get_surface(contact, size, scale) + return self.avatar_storage.get_pixbuf(contact, size, scale, show) + return self.avatar_storage.get_surface(contact, size, scale, show)
def avatar_exists(self, filename): return self.avatar_storage.get_avatar_path(filename) is not None
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/1044d1c7ba143c4d3916f48e025e7b0bd7...