changeset 54b0608a5886 in /home/hg/repos/gajim
author: Yann Leboulanger asterix@lagaule.org branches: details:http://hg.gajim.org/gajim?cmd=changeset;node=54b0608a5886 description: add new option to show avatar in chat tabs and window icons instead of status icon. Fixes #8320
diffstat:
data/gui/preferences_window.ui | 16 ++++++++++++++++ src/chat_control.py | 8 ++++++++ src/common/config.py | 1 + src/config.py | 7 +++++++ src/gtkgui_helpers.py | 29 ++++++++++++++++------------- src/message_window.py | 10 ++++++++-- 6 files changed, 56 insertions(+), 15 deletions(-)
diffs (166 lines):
diff -r f3b6c0404847 -r 54b0608a5886 data/gui/preferences_window.ui --- a/data/gui/preferences_window.ui Tue Apr 12 21:59:57 2016 +0200 +++ b/data/gui/preferences_window.ui Tue Apr 12 22:53:41 2016 +0200 @@ -531,6 +531,22 @@ <property name="top_attach">0</property> </packing> </child> + <child> + <object class="GtkCheckButton" id="show_avatar_in_tabs_checkbutton"> + <property name="label" translatable="yes">Show avatar in chat tabs</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="on_show_avatar_in_tabs_checkbutton_toggled" swapped="no"/> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">7</property> + <property name="width">2</property> + </packing> + </child> </object> </child> <child type="label"> diff -r f3b6c0404847 -r 54b0608a5886 src/chat_control.py --- a/src/chat_control.py Tue Apr 12 21:59:57 2016 +0200 +++ b/src/chat_control.py Tue Apr 12 22:53:41 2016 +0200 @@ -2591,6 +2591,14 @@ 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 -r f3b6c0404847 -r 54b0608a5886 src/common/config.py --- a/src/common/config.py Tue Apr 12 21:59:57 2016 +0200 +++ b/src/common/config.py Tue Apr 12 22:53:41 2016 +0200 @@ -317,6 +317,7 @@ '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 -r f3b6c0404847 -r 54b0608a5886 src/config.py --- a/src/config.py Tue Apr 12 21:59:57 2016 +0200 +++ b/src/config.py Tue Apr 12 22:53:41 2016 +0200 @@ -209,6 +209,10 @@ 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 @@ 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 -r f3b6c0404847 -r 54b0608a5886 src/gtkgui_helpers.py --- a/src/gtkgui_helpers.py Tue Apr 12 21:59:57 2016 +0200 +++ b/src/gtkgui_helpers.py Tue Apr 12 22:53:41 2016 +0200 @@ -434,7 +434,7 @@ 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 @@ 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 @@ 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 -r f3b6c0404847 -r 54b0608a5886 src/message_window.py --- a/src/message_window.py Tue Apr 12 21:59:57 2016 +0200 +++ b/src/message_window.py Tue Apr 12 22:53:41 2016 +0200 @@ -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 @@ # 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 @@
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())