add new option to show avatar in chat tabs and window icons instead of status icon. Fixes #8320

This commit is contained in:
Yann Leboulanger 2016-04-12 22:53:41 +02:00
parent 991df175d7
commit 997e686d57
6 changed files with 56 additions and 15 deletions

View File

@ -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">

View File

@ -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]))

View File

@ -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 = {

View File

@ -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()

View File

@ -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

View File

@ -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())