def _load_avatar(self, vcard): if not self.xml.get_object('information_notebook').get_n_pages() > 4: # TODO: why? return try: avatar, _ = vcard.get_avatar() except Exception as error: log.warning('Failed to load avatar: %s', error) return if avatar is None: return pixbuf = gtkgui_helpers.get_pixbuf_from_data(avatar) pixbuf = gtkgui_helpers.scale_pixbuf(pixbuf, AvatarSize.VCARD) surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.window.get_scale_factor()) image = self.xml.get_object('PHOTO_image') image.set_from_surface(surface) image.show() self.avatar = pixbuf self.xml.get_object('user_avatar_label').show()
def set_values(self, vcard_): button = self.xml.get_object('PHOTO_button') image = button.get_image() text_button = self.xml.get_object('NOPHOTO_button') if not 'PHOTO' in vcard_: # set default image image.set_from_pixbuf(None) button.hide() text_button.show() for i in vcard_.keys(): if i == 'PHOTO': photo_encoded = vcard_[i]['BINVAL'] if photo_encoded == '': continue self.avatar_encoded = photo_encoded photo_decoded = base64.b64decode(photo_encoded.encode('utf-8')) self.avatar_sha = hashlib.sha1(photo_decoded).hexdigest() if 'TYPE' in vcard_[i]: self.avatar_mime_type = vcard_[i]['TYPE'] pixbuf = gtkgui_helpers.get_pixbuf_from_data(photo_decoded) if pixbuf is None: continue pixbuf = pixbuf.scale_simple(AvatarSize.PROFILE, AvatarSize.PROFILE, GdkPixbuf.InterpType.BILINEAR) image.set_from_pixbuf(pixbuf) button.show() text_button.hide() continue if i == 'ADR' or i == 'TEL' or i == 'EMAIL': for entry in vcard_[i]: add_on = '_HOME' if 'WORK' in entry: add_on = '_WORK' for j in entry.keys(): self.set_value(i + add_on + '_' + j + '_entry', entry[j]) if isinstance(vcard_[i], dict): for j in vcard_[i].keys(): self.set_value(i + '_' + j + '_entry', vcard_[i][j]) else: if i == 'DESC': self.xml.get_object('DESC_textview').get_buffer().set_text( vcard_[i], len(vcard_[i].encode('utf-8'))) else: self.set_value(i + '_entry', vcard_[i]) if self.update_progressbar_timeout_id is not None: if self.message_id: self.statusbar.remove(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, _('Information received')) self.remove_statusbar_timeout_id = GLib.timeout_add_seconds( 3, self.remove_statusbar, self.message_id) GLib.source_remove(self.update_progressbar_timeout_id) self.progressbar.hide() self.progressbar.set_fraction(0) self.update_progressbar_timeout_id = None
def _set_values(self, vcard, jid): for i in vcard.keys(): if i == 'PHOTO' and self.xml.get_object('information_notebook').\ get_n_pages() > 4: if 'BINVAL' not in vcard[i]: continue photo_encoded = vcard[i]['BINVAL'] if photo_encoded == '': continue try: photo_decoded = base64.b64decode( photo_encoded.encode('utf-8')) except binascii.Error as error: app.log('avatar').warning('Invalid avatar for %s: %s', jid, error) continue pixbuf = gtkgui_helpers.get_pixbuf_from_data(photo_decoded) if pixbuf is None: continue self.avatar = pixbuf pixbuf = gtkgui_helpers.scale_pixbuf(pixbuf, AvatarSize.VCARD) surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.window.get_scale_factor()) image = self.xml.get_object('PHOTO_image') image.set_from_surface(surface) image.show() self.xml.get_object('user_avatar_label').show() continue if i in ('ADR', 'TEL', 'EMAIL'): for entry in vcard[i]: add_on = '_HOME' if 'WORK' in entry: add_on = '_WORK' for j in entry.keys(): self.set_value(i + add_on + '_' + j + '_label', entry[j]) if isinstance(vcard[i], dict): for j in vcard[i].keys(): self.set_value(i + '_' + j + '_label', vcard[i][j]) else: if i == 'DESC': self.xml.get_object('DESC_textview').get_buffer().set_text( vcard[i], len(vcard[i].encode('utf-8'))) elif i != 'jid': # Do not override jid_label self.set_value(i + '_label', vcard[i]) self.vcard_arrived = True