def _open_uris(self, uris): for uri in uris: app.log('uri_handler').info('open %s', uri) if not uri.startswith('xmpp:'): continue # remove xmpp: uri = uri[5:] try: jid, cmd = uri.split('?') except ValueError: # No query argument jid, cmd = uri, 'message' if cmd == 'join': self.interface.join_gc_minimal(None, jid) elif cmd == 'roster': self.activate_action('add-contact', GLib.Variant('s', jid)) elif cmd.startswith('message'): attributes = cmd.split(';') message = None for key in attributes: if key.startswith('body'): try: message = unquote(key.split('=')[1]) except Exception: app.log('uri_handler').error( 'Invalid URI: %s', cmd) accounts = list(app.connections.keys()) if not accounts: continue if len(accounts) == 1: app.interface.new_chat_from_jid(accounts[0], jid, message) else: self.activate_action('start-chat') start_chat_window = app.interface.instances['start_chat'] start_chat_window.search_entry.set_text(jid)
def _gc_update_received(self, properties): nick = properties.jid.resource gc_contact = app.contacts.get_gc_contact( self._account, properties.jid.bare, nick) if gc_contact is None: self._log.error('no gc contact found: %s', nick) return if properties.avatar_state == AvatarState.EMPTY: # Empty <photo/> tag, means no avatar is advertised self._log.info('%s has no avatar published', nick) gc_contact.avatar_sha = None app.interface.update_avatar(contact=gc_contact) else: self._log.info('Update: %s %s', nick, properties.avatar_sha) if not app.interface.avatar_exists(properties.avatar_sha): if properties.avatar_sha not in self._requested_shas: app.log('avatar').info('Request: %s', nick) self._requested_shas.append(properties.avatar_sha) self._request_vcard(properties.jid, properties.avatar_sha, 'muc-user') return if gc_contact.avatar_sha != properties.avatar_sha: self._log.info('%s changed their Avatar: %s', nick, properties.avatar_sha) gc_contact.avatar_sha = properties.avatar_sha app.interface.update_avatar(contact=gc_contact) else: self._log.info('Avatar already known: %s', nick)
def append(self, stanza): jid = stanza.getFrom() identities, features, data = [], [], [] query_childs = stanza.getQueryChildren() if not query_childs: from gajim.common import app app.log('gajim.muc').warning('%s returned empty disco info', jid) return for child in query_childs: if child.getName() == 'identity': attr = {} for key in child.getAttrs().keys(): attr[key] = child.getAttr(key) identities.append(attr) elif child.getName() == 'feature': features.append(child.getAttr('var')) elif child.getName() == 'x': if child.getNamespace() == nbxmpp.NS_DATA: data.append(nbxmpp.DataForm(node=child)) if nbxmpp.NS_MUC not in features: # Not a MUC, dont cache info return self.cache[jid] = self.DiscoInfo(identities, features, data)
def _populate_grid(self, contact): """ Populate the Tooltip Grid with data of from the contact """ self._hide_grid_childs() self.nick.set_text(contact.get_shown_name()) self.nick.show() # Status Message if contact.status: status = contact.status.strip() if status != '': self.status.set_text(status) self.status.show() # Status show = helpers.get_uf_show(contact.show) self.user_show.set_markup(colorize_status(show)) self.user_show.show() # JID if contact.jid.strip(): self.jid.set_text(contact.jid) self.jid.show() self.jid_label.show() # Resource if hasattr(contact, 'resource') and contact.resource.strip(): self.resource.set_text(contact.resource) self.resource.show() self.resource_label.show() # Affiliation if contact.affiliation != 'none': uf_affiliation = helpers.get_uf_affiliation(contact.affiliation) uf_affiliation = \ _('%(owner_or_admin_or_member)s of this group chat') \ % {'owner_or_admin_or_member': uf_affiliation} uf_affiliation = self.colorize_affiliation(uf_affiliation) self.affiliation.set_markup(uf_affiliation) self.affiliation.show() # Avatar if contact.avatar_sha is not None: app.log('avatar').debug('Load GCTooltip: %s %s', contact.name, contact.avatar_sha) scale = self.tooltip_grid.get_scale_factor() surface = app.interface.get_avatar(contact.avatar_sha, AvatarSize.TOOLTIP, scale) if surface is not None: self.avatar.set_from_surface(surface) self.avatar.show() self.fillelement.show() app.plugin_manager.gui_extension_point('gc_tooltip_populate', self, contact, self.tooltip_grid)
def _nec_pubsub_bookmarks_received(self, obj): if obj.conn.name != self.name: return app.log('bookmarks').info('Received Bookmarks (PubSub)') bm_jids = [b['jid'] for b in self.bookmarks] for bm in obj.bookmarks: if bm['jid'] not in bm_jids: self.bookmarks.append(bm) # We got bookmarks from pubsub, now get those from xml to merge them self.get_bookmarks(storage_type='xml')
def populate(self, contact): """ Populate the Tooltip Grid with data of from the contact """ self.clear_tooltip() self.nick.set_text(contact.get_shown_name()) self.nick.show() # Status Message if contact.status: status = contact.status.strip() if status != '': self.status.set_text(status) self.status.show() # Status show = helpers.get_uf_show(contact.show) self.user_show.set_markup(colorize_status(show)) self.user_show.show() # JID if contact.jid.strip(): self.jid.set_text(contact.jid) self.jid.show() self.jid_label.show() # Resource if hasattr(contact, 'resource') and contact.resource.strip(): self.resource.set_text(contact.resource) self.resource.show() self.resource_label.show() # Affiliation if contact.affiliation != 'none': uf_affiliation = helpers.get_uf_affiliation(contact.affiliation) uf_affiliation = \ _('%(owner_or_admin_or_member)s of this group chat') \ % {'owner_or_admin_or_member': uf_affiliation} uf_affiliation = self.colorize_affiliation(uf_affiliation) self.affiliation.set_markup(uf_affiliation) self.affiliation.show() # Avatar if contact.avatar_sha is not None: app.log('avatar').debug( 'Load GCTooltip: %s %s', contact.name, contact.avatar_sha) pixbuf = app.interface.get_avatar(contact.avatar_sha, AvatarSize.TOOLTIP) if pixbuf is not None: self.avatar.set_from_pixbuf(pixbuf) self.avatar.show() self.fillelement.show()
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
def _open_uris(self, uris): accounts = list(app.connections.keys()) if not accounts: return for uri in uris: app.log('uri_handler').info('open %s', uri) if not uri.startswith('xmpp:'): continue # remove xmpp: uri = uri[5:] try: jid, cmd = uri.split('?') except ValueError: # No query argument jid, cmd = uri, 'message' try: jid = JID(jid) except InvalidJid as error: app.log('uri_handler').warning('Invalid JID %s: %s', uri, error) continue if cmd == 'join' and jid.getResource(): app.log('uri_handler').warning('Invalid MUC JID %s', uri) continue jid = str(jid) if cmd == 'join': if len(accounts) == 1: self.activate_action( 'groupchat-join', GLib.Variant('as', [accounts[0], jid])) else: self.activate_action('start-chat', GLib.Variant('s', jid)) elif cmd == 'roster': self.activate_action('add-contact', GLib.Variant('s', jid)) elif cmd.startswith('message'): attributes = cmd.split(';') message = None for key in attributes: if not key.startswith('body'): continue try: message = unquote(key.split('=')[1]) except Exception: app.log('uri_handler').error('Invalid URI: %s', cmd) if len(accounts) == 1: app.interface.new_chat_from_jid(accounts[0], jid, message) else: self.activate_action('start-chat', GLib.Variant('s', jid))
def _nec_pubsub_avatar_received(self, conn, stanza, jid): try: jid, sha, data = self._validate_avatar_node(stanza) except (StanzaMalformed, binascii.Error) as error: app.log('avatar').warning('Error loading Avatar (Pubsub): %s %s', jid, error) return app.log('avatar').info('Received Avatar (Pubsub): %s %s', jid, sha) app.interface.save_avatar(data) if self.get_own_jid().bareMatch(jid): app.config.set_per('accounts', self.name, 'avatar_sha', sha) else: own_jid = self.get_own_jid().getStripped() app.logger.set_avatar_sha(own_jid, jid, sha) app.contacts.set_avatar(self.name, jid, sha) app.interface.update_avatar(self.name, jid)
def _nec_pubsub_avatar_received(self, obj): if obj.conn.name != self.name: return if obj.jid is None: jid = self.get_own_jid().getStripped() else: jid = obj.jid.getStripped() app.log('avatar').info('Received Avatar (Pubsub): %s %s', jid, obj.sha) app.interface.save_avatar(obj.data) if self.get_own_jid().bareMatch(jid): app.config.set_per('accounts', self.name, 'avatar_sha', obj.sha) else: own_jid = self.get_own_jid().getStripped() app.logger.set_avatar_sha(own_jid, jid, obj.sha) app.contacts.set_avatar(self.name, jid, obj.sha) app.interface.update_avatar(self.name, jid)
def _gc_update_received(self, properties): nick = properties.jid.getResource() gc_contact = app.contacts.get_gc_contact(self._account, properties.jid.getBare(), nick) if gc_contact is None: self._log.error('no gc contact found: %s', nick) return if properties.avatar_state == AvatarState.EMPTY: # Empty <photo/> tag, means no avatar is advertised, remove avatar self._log.info('%s has no avatar published', nick) self._log.debug('Remove: %s', nick) gc_contact.avatar_sha = None app.interface.update_avatar(contact=gc_contact) else: self._log.info('Update: %s %s', nick, properties.avatar_sha) path = os.path.join(configpaths.get('AVATAR'), properties.avatar_sha) if not os.path.isfile(path): if properties.avatar_sha not in self._requested_shas: app.log('avatar').info('Request: %s', nick) self._requested_shas.append(properties.avatar_sha) self._con.get_module('VCardTemp').request_vcard( RequestAvatar.USER, str(properties.jid), room=True, sha=properties.avatar_sha) return if gc_contact.avatar_sha != properties.avatar_sha: self._log.info('%s changed their Avatar: %s', nick, properties.avatar_sha) gc_contact.avatar_sha = properties.avatar_sha app.interface.update_avatar(contact=gc_contact) else: self._log.info('Avatar already known: %s', nick)
def _gc_update_received(self, jid, avatar_sha, show, type_): if show == 'offline' or type_ == 'unavailable': return nick = jid.getResource() gc_contact = app.contacts.get_gc_contact(self._account, jid.getStripped(), nick) if gc_contact is None: log.error('no gc contact found: %s', nick) return if avatar_sha == '': # Empty <photo/> tag, means no avatar is advertised, remove avatar log.info('%s has no avatar published', nick) log.debug('Remove: %s', nick) gc_contact.avatar_sha = None app.interface.update_avatar(contact=gc_contact) else: log.info('Update: %s %s', nick, avatar_sha) path = os.path.join(configpaths.get('AVATAR'), avatar_sha) if not os.path.isfile(path): if avatar_sha not in self._requested_shas: app.log('avatar').info('Request: %s', nick) self._requested_shas.append(avatar_sha) self._con.get_module('VCardTemp').request_vcard( RequestAvatar.USER, str(jid), room=True, sha=avatar_sha) return if gc_contact.avatar_sha != avatar_sha: log.info('%s changed their Avatar: %s', nick, avatar_sha) gc_contact.avatar_sha = avatar_sha app.interface.update_avatar(contact=gc_contact) else: log.info('Avatar already known: %s', nick)
def _on_receive(self, jid, account): con = app.connections[account] if self.avatar is None: # Remove avatar app.log('avatar').debug('Remove (Pubsub): %s', jid) app.contacts.set_avatar(account, jid, None) own_jid = con.get_own_jid().getStripped() app.logger.set_avatar_sha(own_jid, jid, None) app.interface.update_avatar(account, jid) else: sha = app.contacts.get_avatar_sha(account, jid) app.log('avatar').info('Update (Pubsub): %s %s', jid, self.avatar['id']) if sha == self.avatar['id']: app.log('avatar').info('Avatar already known (Pubsub): %s %s', jid, self.avatar['id']) return app.log('avatar').info('Request (Pubsub): %s', jid) con.get_pubsub_avatar(jid, 'urn:xmpp:avatar:data', self.avatar['id'])