def _subscribe_received(self, _con, _stanza, properties): jid = properties.jid.bare fjid = str(properties.jid) is_transport = app.jid_is_transport(fjid) auto_auth = app.settings.get_account_setting(self._account, 'autoauth') self._log.info( 'Received Subscribe: %s, transport: %s, ' 'auto_auth: %s, user_nick: %s', properties.jid, is_transport, auto_auth, properties.nickname) if auto_auth or jid in self._jids_for_auto_auth: self.send_presence(fjid, 'subscribed') self._jids_for_auto_auth.discard(jid) self._log.info('Auto respond with subscribed: %s', jid) return status = (properties.status or _('I would like to add you to my roster.')) app.nec.push_incoming_event( NetworkEvent('subscribe-presence-received', conn=self._con, jid=jid, fjid=fjid, status=status, user_nick=properties.nickname, is_transport=is_transport)) raise nbxmpp.NodeProcessed
def get_tab_image(self, count_unread=True): jid = self.gc_contact.get_full_jid() if app.config.get('show_avatar_in_tabs'): scale = self.parent_win.window.get_scale_factor() surface = app.contacts.get_avatar( self.account, jid, AvatarSize.TAB, scale) if surface is not None: return surface if count_unread: num_unread = len(app.events.get_events( self.account, jid, ['printed_' + self.type_id, self.type_id])) else: num_unread = 0 transport = None if app.jid_is_transport(jid): transport = app.get_transport_name_from_jid(jid) if self.gc_contact.presence.is_unavailable: show = 'offline' else: show = self.gc_contact.show.value if num_unread and app.config.get('show_unread_tab_icon'): icon_name = get_icon_name('event', transport=transport) else: icon_name = get_icon_name(show, transport=transport) return icon_name
def handle_agent_info_received(self, event): if (NS_HTTPUPLOAD not in event.features or not app.jid_is_transport(event.jid)): return if not event.id_.startswith('Gajim_'): return account = event.conn.name if account != self.name: return self.component = event.jid for form in event.data: form_dict = form.asDict() if form_dict.get('FORM_TYPE', None) != NS_HTTPUPLOAD: continue size = form_dict.get('max-file-size', None) if size is not None: self.max_file_size = int(size) break if self.max_file_size is None: log.warning('%s does not provide maximum file size', account) else: log.info('%s has a maximum file size of: %s MiB', account, self.max_file_size / (1024 * 1024)) self.httpupload = True for ctrl in app.interface.msg_win_mgr.get_controls(acct=self.name): ctrl.update_actions()
def _subscribe_received(self, _con, _stanza, properties): jid = properties.jid.getBare() fjid = str(properties.jid) is_transport = app.jid_is_transport(fjid) auto_auth = app.config.get_per('accounts', self._account, 'autoauth') self._log.info( 'Received Subscribe: %s, transport: %s, ' 'auto_auth: %s, user_nick: %s', properties.jid, is_transport, auto_auth, properties.nickname) if is_transport and fjid in self._con.agent_registrations: self._con.agent_registrations[fjid]['sub_received'] = True if not self._con.agent_registrations[fjid]['roster_push']: # We'll reply after roster push result raise nbxmpp.NodeProcessed if auto_auth or is_transport or jid in self.jids_for_auto_auth: self.send_presence(fjid, 'subscribed') status = (properties.status or _('I would like to add you to my roster.')) app.nec.push_incoming_event( NetworkEvent('subscribe-presence-received', conn=self._con, jid=jid, fjid=fjid, status=status, user_nick=properties.nickname, is_transport=is_transport)) raise nbxmpp.NodeProcessed
def connect_with_roster_draw_contact(self, roster, jid, account, contact): if not self.active: return if app.jid_is_transport(jid): return child_iters = roster._get_contact_iter(jid, account, contact, roster.model) if not child_iters: return icon_name = helpers.get_icon_name_to_show(contact, account) if app.events.get_events(account, jid) or icon_name == 'requested': return host = jid.split('@')[1] server = self.known_servers.get(host, False) if not server: return if server not in roster.transports_state_images['16']: # we don't have iconset for this transport loaded yet. Let's do it self.make_transport_state_images(roster, server) if server in roster.transports_state_images['16'] and \ icon_name in roster.transports_state_images['16'][server]: state_images = roster.transports_state_images['16'][server] img = state_images[icon_name] for child_iter in child_iters: roster.model[child_iter][0] = img
def _subscribe_received(self, con, stanza): from_ = stanza.getFrom() jid = from_.getStripped() fjid = str(from_) status = stanza.getStatus() is_transport = app.jid_is_transport(fjid) auto_auth = app.config.get_per('accounts', self._account, 'autoauth') user_nick = parse_nickname(stanza) log.info( 'Received Subscribe: %s, transport: %s, auto_auth: %s, ' 'user_nick: %s', from_, is_transport, auto_auth, user_nick) if is_transport and fjid in self._con.agent_registrations: self._con.agent_registrations[fjid]['sub_received'] = True if not self.agent_registrations[fjid]['roster_push']: # We'll reply after roster push result raise nbxmpp.NodeProcessed if auto_auth or is_transport or jid in self.jids_for_auto_auth: presence = nbxmpp.Presence(fjid, 'subscribed') presence = self._add_sha(presence) self._con.connection.send(presence) if not status: status = _('I would like to add you to my roster.') app.nec.push_incoming_event( NetworkEvent('subscribe-presence-received', conn=self._con, jid=jid, fjid=fjid, status=status, user_nick=user_nick, is_transport=is_transport)) raise nbxmpp.NodeProcessed
def _update_contact(self, event, properties): # Note: A similar method also exists in connection_zeroconf jid = properties.jid.bare resource = properties.jid.resource status_strings = [ 'offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd' ] event.new_show = status_strings.index(event.show) # Update contact contact_list = app.contacts.get_contacts(self._account, jid) if not contact_list: self._log.warning('No contact found') return event.contact_list = contact_list contact = app.contacts.get_contact_strict(self._account, properties.jid.bare, properties.jid.resource) if contact is None: contact = app.contacts.get_first_contact_from_jid( self._account, jid) if contact is None: self._log.warning('First contact not found') return if (self._is_resource_known(contact_list) and not app.jid_is_transport(jid)): # Another resource of an existing contact connected # Add new contact event.old_show = 0 contact = app.contacts.copy_contact(contact) contact.resource = resource app.contacts.add_contact(self._account, contact) else: # Convert the initial roster contact to a contact with resource contact.resource = resource event.old_show = 0 if contact.show in status_strings: event.old_show = status_strings.index(contact.show) event.need_add_in_roster = True elif contact.show in status_strings: event.old_show = status_strings.index(contact.show) # Update contact with presence data contact.show = event.show contact.status = properties.status contact.priority = properties.priority contact.idle_time = properties.idle_timestamp event.contact = contact if not app.jid_is_transport(jid) and len(contact_list) == 1: # It's not an agent if event.old_show == 0 and event.new_show > 1: if not jid in app.newly_added[self._account]: app.newly_added[self._account].append(jid) if jid in app.to_be_removed[self._account]: app.to_be_removed[self._account].remove(jid) elif event.old_show > 1 and event.new_show == 0 and \ self._con.state.is_available: if not jid in app.to_be_removed[self._account]: app.to_be_removed[self._account].append(jid) if jid in app.newly_added[self._account]: app.newly_added[self._account].remove(jid) if app.jid_is_transport(jid): return if properties.type.is_unavailable: # TODO: This causes problems when another # resource signs off! self._con.get_module('Bytestream').stop_all_active_file_transfers( contact) self._log_presence(properties)
def _nec_presence_received(self, obj): if app.jid_is_transport(obj.jid): if obj.old_show == 0 and obj.new_show > 1: self.transport_signed_in(obj.jid) elif obj.old_show > 1 and obj.new_show == 0: self.transport_signed_out(obj.jid)
def __init__(self, account=None, jid=None, user_nick=None, group=None): Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_position(Gtk.WindowPosition.CENTER) self.set_show_menubar(False) self.set_resizable(False) self.set_title(_('Add Contact')) self.connect('destroy', self._on_destroy) self.connect('key-press-event', self._on_key_press) self.account = account self.adding_jid = False # fill accounts with active accounts accounts = app.get_enabled_accounts_with_labels() if not accounts: return if not account: self.account = accounts[0][0] self.xml = get_builder('add_new_contact_window.ui') self.add(self.xml.get_object('add_contact_box')) self.xml.connect_signals(self) for w in ('account_combobox', 'account_label', 'prompt_label', 'uid_label', 'uid_entry', 'show_contact_info_button', 'protocol_combobox', 'protocol_jid_combobox', 'protocol_label', 'nickname_entry', 'message_scrolledwindow', 'save_message_checkbutton', 'register_hbox', 'add_button', 'message_textview', 'connected_label', 'group_comboboxentry', 'auto_authorize_checkbutton', 'save_message_revealer', 'nickname_label', 'group_label'): self.__dict__[w] = self.xml.get_object(w) self.subscription_table = [ self.uid_label, self.uid_entry, self.show_contact_info_button, self.nickname_label, self.nickname_entry, self.group_label, self.group_comboboxentry ] self.add_button.grab_default() self.agents = {'jabber': []} self.gateway_prompt = {} # types to which we are not subscribed but account has an agent for it self.available_types = [] for acct in accounts: for j in app.contacts.get_jid_list(acct[0]): if app.jid_is_transport(j): type_ = app.get_transport_name_from_jid(j, False) if not type_: continue if type_ in self.agents: self.agents[type_].append(j) else: self.agents[type_] = [j] self.gateway_prompt[j] = {'desc': None, 'prompt': None} # Now add the one to which we can register for acct in accounts: for type_ in app.connections[acct[0]].available_transports: if type_ in self.agents: continue self.agents[type_] = [] for jid_ in app.connections[ acct[0]].available_transports[type_]: if jid_ not in self.agents[type_]: self.agents[type_].append(jid_) self.gateway_prompt[jid_] = { 'desc': None, 'prompt': None } self.available_types.append(type_) uf_type = {'jabber': 'XMPP', 'gadu-gadu': 'Gadu Gadu', 'icq': 'ICQ'} # Jabber as first liststore = self.protocol_combobox.get_model() liststore.append(['XMPP', 'xmpp', 'jabber']) for type_ in self.agents: if type_ == 'jabber': continue if type_ in uf_type: liststore.append([uf_type[type_], type_ + '-online', type_]) else: liststore.append([type_, type_ + '-online', type_]) if account: for service in self.agents[type_]: con = app.connections[account] con.get_module('Gateway').request_gateway_prompt(service) self.protocol_combobox.set_active(0) self.auto_authorize_checkbutton.show() if jid: self.jid_escaped = True type_ = app.get_transport_name_from_jid(jid) if not type_: type_ = 'jabber' if type_ == 'jabber': self.uid_entry.set_text(jid) transport = None else: uid, transport = app.get_name_and_server_from_jid(jid) self.uid_entry.set_text(uid.replace('%', '@', 1)) # set protocol_combobox model = self.protocol_combobox.get_model() iter_ = model.get_iter_first() i = 0 while iter_: if model[iter_][2] == type_: self.protocol_combobox.set_active(i) break iter_ = model.iter_next(iter_) i += 1 # set protocol_jid_combobox self.protocol_jid_combobox.set_active(0) model = self.protocol_jid_combobox.get_model() iter_ = model.get_iter_first() i = 0 while iter_: if model[iter_][0] == transport: self.protocol_jid_combobox.set_active(i) break iter_ = model.iter_next(iter_) i += 1 if user_nick: self.nickname_entry.set_text(user_nick) self.nickname_entry.grab_focus() else: self.jid_escaped = False self.uid_entry.grab_focus() group_names = [] for acct in accounts: for g in app.groups[acct[0]].keys(): if g not in helpers.special_groups and g not in group_names: group_names.append(g) group_names.sort() i = 0 for g in group_names: self.group_comboboxentry.append_text(g) if group == g: self.group_comboboxentry.set_active(i) i += 1 if len(accounts) > 1: liststore = self.account_combobox.get_model() for acc in accounts: liststore.append(acc) self.account_combobox.set_active_id(self.account) self.account_label.show() self.account_combobox.show() if len(self.agents) > 1: self.protocol_label.show() self.protocol_combobox.show() if self.account: message_buffer = self.message_textview.get_buffer() msg = helpers.from_one_line( helpers.get_subscription_request_msg(self.account)) message_buffer.set_text(msg) self.uid_entry.connect('changed', self.on_uid_entry_changed) self.show_all() app.ged.register_event_handler('gateway-prompt-received', ged.GUI1, self._nec_gateway_prompt_received) app.ged.register_event_handler('presence-received', ged.GUI1, self._nec_presence_received)
def handle_incoming_pres_event(self, pres_obj): if app.jid_is_transport(pres_obj.jid): return True account = pres_obj.conn.name self.jid = pres_obj.jid resource = pres_obj.resource or '' # It isn't an agent for c in pres_obj.contact_list: if c.resource == resource: # we look for other connected resources continue if c.show not in ('offline', 'error'): return True # no other resource is connected, let's look in metacontacts family = app.contacts.get_metacontacts_family(account, self.jid) for info in family: acct_ = info['account'] jid_ = info['jid'] c_ = app.contacts.get_contact_with_highest_priority(acct_, jid_) if not c_: continue if c_.jid == self.jid: continue if c_.show not in ('offline', 'error'): return True if pres_obj.old_show < 2 and pres_obj.new_show > 1: event = 'contact_connected' server = app.get_server_from_jid(self.jid) account_server = account + '/' + server block_transport = False if account_server in app.block_signed_in_notifications and \ app.block_signed_in_notifications[account_server]: block_transport = True if helpers.allow_showing_notification(account, 'notify_on_signin') \ and not app.block_signed_in_notifications[account] and \ not block_transport: self.do_popup = True if app.config.get_per('soundevents', 'contact_connected', 'enabled') and not app.block_signed_in_notifications[account] and\ not block_transport and helpers.allow_sound_notification(account, 'contact_connected'): self.sound_event = event self.do_sound = True elif pres_obj.old_show > 1 and pres_obj.new_show < 2: event = 'contact_disconnected' if helpers.allow_showing_notification(account, 'notify_on_signout'): self.do_popup = True if app.config.get_per('soundevents', 'contact_disconnected', 'enabled') and helpers.allow_sound_notification(account, event): self.sound_event = event self.do_sound = True # Status change (not connected/disconnected or error (<1)) elif pres_obj.new_show > 1: event = 'status_change' else: return True if app.jid_is_transport(self.jid): self.transport_name = app.get_transport_name_from_jid(self.jid) self.show = pres_obj.show self.popup_timeout = app.config.get('notification_timeout') nick = i18n.direction_mark + app.get_name_from_jid(account, self.jid) if event == 'status_change': self.popup_title = _('%(nick)s Changed Status') % \ {'nick': nick} self.popup_text = _('%(nick)s is now %(status)s') % \ {'nick': nick, 'status': helpers.get_uf_show(pres_obj.show)} if pres_obj.status: self.popup_text = self.popup_text + " : " + pres_obj.status self.popup_event_type = _('Contact Changed Status') elif event == 'contact_connected': self.popup_title = _('%(nickname)s Signed In') % {'nickname': nick} self.popup_text = '' if pres_obj.status: self.popup_text = pres_obj.status self.popup_event_type = _('Contact Signed In') elif event == 'contact_disconnected': self.popup_title = _('%(nickname)s Signed Out') % {'nickname': nick} self.popup_text = '' if pres_obj.status: self.popup_text = pres_obj.status self.popup_event_type = _('Contact Signed Out')
def _nec_presence_received(self, obj): account = obj.conn.name if account != self.name: return jid = obj.jid resource = obj.resource or '' statuss = [ 'offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd', 'invisible' ] obj.old_show = 0 obj.new_show = statuss.index(obj.show) obj.contact_list = [] highest = app.contacts.get_contact_with_highest_priority(account, jid) obj.was_highest = (highest and highest.resource == resource) # Update contact obj.contact_list = app.contacts.get_contacts(account, jid) obj.contact = None resources = [] for c in obj.contact_list: resources.append(c.resource) if c.resource == resource: obj.contact = c break if obj.contact: if obj.contact.show in statuss: obj.old_show = statuss.index(obj.contact.show) # nick changed if obj.contact_nickname is not None and \ obj.contact.contact_name != obj.contact_nickname: obj.contact.contact_name = obj.contact_nickname obj.need_redraw = True elif obj.old_show != obj.new_show or obj.contact.status != \ obj.status: obj.need_redraw = True else: obj.contact = app.contacts.get_first_contact_from_jid(account, jid) if not obj.contact: # Presence of another resource of our jid # Create self contact and add to roster if resource == obj.conn.server_resource: return # Ignore offline presence of unknown self resource if obj.new_show < 2: return obj.contact = app.contacts.create_self_contact( jid=jid, account=account, show=obj.show, status=obj.status, priority=obj.prio, keyID=obj.keyID, resource=obj.resource) app.contacts.add_contact(account, obj.contact) obj.contact_list.append(obj.contact) elif obj.contact.show in statuss: obj.old_show = statuss.index(obj.contact.show) if (resources != [''] and (len(obj.contact_list) != 1 or \ obj.contact_list[0].show not in ('not in roster', 'offline'))) and \ not app.jid_is_transport(jid): # Another resource of an existing contact connected obj.old_show = 0 obj.contact = app.contacts.copy_contact(obj.contact) obj.contact_list.append(obj.contact) obj.contact.resource = resource obj.need_add_in_roster = True if not app.jid_is_transport(jid) and len(obj.contact_list) == 1: # It's not an agent if obj.old_show == 0 and obj.new_show > 1: if not jid in app.newly_added[account]: app.newly_added[account].append(jid) if jid in app.to_be_removed[account]: app.to_be_removed[account].remove(jid) elif obj.old_show > 1 and obj.new_show == 0 and \ obj.conn.connected > 1: if not jid in app.to_be_removed[account]: app.to_be_removed[account].append(jid) if jid in app.newly_added[account]: app.newly_added[account].remove(jid) obj.need_redraw = True obj.contact.show = obj.show obj.contact.status = obj.status obj.contact.priority = obj.prio attached_keys = app.config.get_per('accounts', account, 'attached_gpg_keys').split() if jid in attached_keys: obj.contact.keyID = attached_keys[attached_keys.index(jid) + 1] else: # Do not override assigned key obj.contact.keyID = obj.keyID obj.contact.contact_nickname = obj.contact_nickname obj.contact.idle_time = obj.idle_time if app.jid_is_transport(jid): return # It isn't an agent # reset chatstate if needed: # (when contact signs out or has errors) if obj.show in ('offline', 'error'): obj.contact.our_chatstate = obj.contact.chatstate = None # TODO: This causes problems when another # resource signs off! self.stop_all_active_file_transfers(obj.contact) if app.config.get('log_contact_status_changes') and \ app.config.should_log(self.name, obj.jid): show = app.logger.convert_show_values_to_db_api_values(obj.show) if show is not None: app.logger.insert_into_logs(self.name, nbxmpp.JID(obj.jid).getStripped(), time_time(), KindConstant.STATUS, message=obj.status, show=show)
def _on_accept_button_clicked(self, _widget): model = self._ui.items_list_treeview.get_model() iter_ = model.get_iter_first() if self.action == 'add': count = 0 while iter_: if model[iter_][0]: count += 1 # It is selected message = _('%s suggested me to add you to my ' 'contact list.' % self.jid_from) # Keep same groups and same nickname groups = model[iter_][3].split(', ') if groups == ['']: groups = [] jid = model[iter_][1] if app.jid_is_transport(self.jid_from): con = app.connections[self.account] con.get_module('Presence').automatically_added.append( jid) app.interface.roster.req_sub(self, jid, message, self.account, groups=groups, nickname=model[iter_][2], auto_auth=True) iter_ = model.iter_next(iter_) InformationDialog( i18n.ngettext('Added %d contact', 'Added %d contacts', count, count, count)) elif self.action == 'modify': count = 0 while iter_: if model[iter_][0]: count += 1 # It is selected jid = model[iter_][1] # Keep same groups and same nickname groups = model[iter_][3].split(', ') if groups == ['']: groups = [] for contact in app.contacts.get_contact(self.account, jid): contact.name = model[iter_][2] con = app.connections[self.account] con.get_module('Roster').update_contact( jid, model[iter_][2], groups) con.get_module('Roster').draw_contact(jid, self.account) # Update opened chats ctrl = app.interface.msg_win_mgr.get_control( jid, self.account) if ctrl: ctrl.update_ui() win = app.interface.msg_win_mgr.get_window( jid, self.account) win.redraw_tab(ctrl) win.show_title() iter_ = model.iter_next(iter_) elif self.action == 'delete': count = 0 while iter_: if model[iter_][0]: count += 1 # It is selected jid = model[iter_][1] app.connections[self.account].get_module( 'Presence').unsubscribe(jid) app.interface.roster.remove_contact(jid, self.account) app.contacts.remove_jid(self.account, jid) iter_ = model.iter_next(iter_) InformationDialog( i18n.ngettext('Removed %d contact', 'Removed %d contacts', count, count, count)) self.destroy()