diff --git a/data/gui/preferences_window.ui b/data/gui/preferences_window.ui index 3d7e6fed5..95342be8f 100644 --- a/data/gui/preferences_window.ui +++ b/data/gui/preferences_window.ui @@ -531,6 +531,22 @@ 0 + + + Show avatar in chat tabs + True + True + False + 0 + True + + + + 0 + 7 + 2 + + diff --git a/src/chat_control.py b/src/chat_control.py index 43427de1c..79a79759b 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -2591,6 +2591,14 @@ class ChatControl(ChatControlBase): jid = self.contact.get_full_jid() else: jid = self.contact.jid + + if gajim.config.get('show_avatar_in_tabs'): + avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) + if avatar_pixbuf not in ('ask', None): + avatar_pixbuf = gtkgui_helpers.get_scaled_pixbuf_by_size( + avatar_pixbuf, 16, 16) + return avatar_pixbuf + if count_unread: num_unread = len(gajim.events.get_events(self.account, jid, ['printed_' + self.type_id, self.type_id])) diff --git a/src/common/config.py b/src/common/config.py index 4798392b8..c5c17e62f 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -317,6 +317,7 @@ class Config: 'ignore_incoming_attention': [opt_bool, False, _('If True, Gajim will ignore incoming attention requestd ("wizz").')], 'remember_opened_chat_controls': [ opt_bool, True, _('If enabled, Gajim will reopen chat windows that were opened last time Gajim was closed.')], 'positive_184_ack': [ opt_bool, False, _('If enabled, Gajim will show an icon to show that sent message has been received by your contact')], + 'show_avatar_in_tabs': [ opt_bool, False, _('Show a mini avatar in chat window tabs and in window icon')], }, {}) __options_per_key = { diff --git a/src/config.py b/src/config.py index bde4a6701..d1e3caac9 100644 --- a/src/config.py +++ b/src/config.py @@ -209,6 +209,10 @@ class PreferencesWindow: st = gajim.config.get('positive_184_ack') self.xml.get_object('positive_184_ack_checkbutton').set_active(st) + # Show avatar in tabs + st = gajim.config.get('show_avatar_in_tabs') + self.xml.get_object('show_avatar_in_tabs_checkbutton').set_active(st) + ### Style tab ### # Themes theme_combobox = self.xml.get_object('theme_combobox') @@ -763,6 +767,9 @@ class PreferencesWindow: def on_positive_184_ack_checkbutton_toggled(self, widget): self.on_checkbutton_toggled(widget, 'positive_184_ack') + def on_show_avatar_in_tabs_checkbutton_toggled(self, widget): + self.on_checkbutton_toggled(widget, 'show_avatar_in_tabs') + def on_theme_combobox_changed(self, widget): model = widget.get_model() active = widget.get_active() diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index ddc1b476b..2936b94fe 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -434,7 +434,7 @@ def get_pixbuf_from_data(file_data, want_type = False): pixbuf = pixbufloader.get_pixbuf() except GLib.GError: # 'unknown image format' pixbufloader.close() - + # try to open and convert this image to png using pillow (if available) log.debug("loading avatar using pixbufloader directly failed, trying to convert avatar image using pillow (if available)") pixbufloader = GdkPixbuf.PixbufLoader() @@ -570,18 +570,7 @@ def get_fade_color(treeview, selected, focused): return Gdk.RGBA(bg.red*p + fg.red*q, bg.green*p + fg.green*q, bg.blue*p + fg.blue*q) -def get_scaled_pixbuf(pixbuf, kind): - """ - Return scaled pixbuf, keeping ratio etc or None kind is either "chat", - "roster", "notification", "tooltip", "vcard" - """ - # resize to a width / height for the avatar not to have distortion - # (keep aspect ratio) - width = gajim.config.get(kind + '_avatar_width') - height = gajim.config.get(kind + '_avatar_height') - if width < 1 or height < 1: - return None - +def get_scaled_pixbuf_by_size(pixbuf, width, height): # Pixbuf size pix_width = pixbuf.get_width() pix_height = pixbuf.get_height() @@ -599,6 +588,20 @@ def get_scaled_pixbuf(pixbuf, kind): scaled_buf = pixbuf.scale_simple(w, h, GdkPixbuf.InterpType.HYPER) return scaled_buf +def get_scaled_pixbuf(pixbuf, kind): + """ + Return scaled pixbuf, keeping ratio etc or None kind is either "chat", + "roster", "notification", "tooltip", "vcard" + """ + # resize to a width / height for the avatar not to have distortion + # (keep aspect ratio) + width = gajim.config.get(kind + '_avatar_width') + height = gajim.config.get(kind + '_avatar_height') + if width < 1 or height < 1: + return None + + return get_scaled_pixbuf_by_size(pixbuf, width, height) + def get_avatar_pixbuf_from_cache(fjid, use_local=True): """ Check if jid has cached avatar and if that avatar is valid image (can be diff --git a/src/message_window.py b/src/message_window.py index 3a2859782..42976b75e 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -29,6 +29,7 @@ from gi.repository import Gtk from gi.repository import Gdk +from gi.repository import GdkPixbuf from gi.repository import GObject from gi.repository import GLib import time @@ -480,7 +481,10 @@ class MessageWindow(object): # chat, pm icon = gtkgui_helpers.load_icon('online') if icon: - self.window.set_icon(icon.get_pixbuf()) + if isinstance(icon, GdkPixbuf.Pixbuf): + self.window.set_icon(icon) + else: + self.window.set_icon(icon.get_pixbuf()) def show_title(self, urgent=True, control=None): """ @@ -658,7 +662,9 @@ class MessageWindow(object): tab_img = ctrl.get_tab_image() if tab_img: - if tab_img.get_storage_type() == Gtk.ImageType.ANIMATION: + if isinstance(tab_img, GdkPixbuf.Pixbuf): + status_img.set_from_pixbuf(tab_img) + elif tab_img.get_storage_type() == Gtk.ImageType.ANIMATION: status_img.set_from_animation(tab_img.get_animation()) else: status_img.set_from_pixbuf(tab_img.get_pixbuf())