def _nec_search_form_received(self, obj): if self.pulse_id: GLib.source_remove(self.pulse_id) self.progressbar.hide() self.label.hide() if obj.is_dataform: self.is_form = True self.data_form_widget = dataforms_widget.DataFormWidget() self.dataform = dataforms.ExtendForm(node=obj.data) self.data_form_widget.set_sensitive(True) try: self.data_form_widget.data_form = self.dataform except dataforms.Error: self.label.set_text(_('Error in received dataform')) self.label.show() return if self.data_form_widget.title: self.window.set_title('%s - Search - Gajim' % \ self.data_form_widget.title) else: self.is_form = False self.data_form_widget = config.FakeDataForm(obj.data) self.data_form_widget.show_all() self.search_vbox.pack_start(self.data_form_widget, True, True, 0) self.search_button.set_sensitive(True)
def append(self, stanza): jid = stanza.getFrom() identities, features, data = [], [], [] query_childs = stanza.getQueryChildren() if not query_childs: log.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: from gajim.common.modules import dataforms data.append(dataforms.ExtendForm(node=child)) if nbxmpp.NS_MUC not in features: # Not a MUC, don't cache info return self.cache[jid] = self.DiscoInfo(identities, features, data)
def _on_get_success(self, form, is_form): log.info('Show Form page') self._is_form = is_form if is_form: dataform = dataforms.ExtendForm(node=form) self._data_form_widget = DataFormWidget(dataform) else: from gajim import config self._data_form_widget = config.FakeDataForm(form) page = self.get_nth_page(Page.FORM) page.pack_start(self._data_form_widget, True, True, 0) self._data_form_widget.show_all() self.set_current_page(Page.FORM)
def _config_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError()) return room_jid = stanza.getFrom().getStripped() payload = stanza.getQueryPayload() for form in payload: if form.getNamespace() == nbxmpp.NS_DATA: dataform = dataforms.ExtendForm(node=form) log.info('Config form received for %s', room_jid) app.nec.push_incoming_event( MucOwnerReceivedEvent(None, conn=self._con, form_node=form, dataform=dataform, jid=room_jid)) break
def _received_pb_configuration(self, conn, stanza, node): if not nbxmpp.isResultNode(stanza): log.warning('Error: %s', stanza.getError()) return pubsub = stanza.getTag('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER) if pubsub is None: log.warning( 'Malformed PubSub configure ' 'stanza (no pubsub node): %s', stanza) return configure = pubsub.getTag('configure') if configure is None: log.warning( 'Malformed PubSub configure ' 'stanza (no configure node): %s', stanza) return if configure.getAttr('node') != node: log.warning( 'Malformed PubSub configure ' 'stanza (wrong node): %s', stanza) return form = configure.getTag('x', namespace=nbxmpp.NS_DATA) if form is None: log.warning('Malformed PubSub configure ' 'stanza (no form): %s', stanza) return app.nec.push_incoming_event( PubSubConfigReceivedEvent(None, conn=self._con, node=node, form=dataforms.ExtendForm(node=form)))
def generate(self): self.get_id() self.fjid = self.conn._ft_get_from(self.stanza) self.jid = app.get_jid_without_resource(self.fjid) if self.jingle_content: secu = self.jingle_content.getTag('security') self.FT_content.use_security = bool(secu) if secu: fingerprint = secu.getTag('fingerprint') if fingerprint: self.FT_content.x509_fingerprint = fingerprint.getData() if not self.FT_content.transport: self.FT_content.transport = JingleTransportSocks5() self.FT_content.transport.set_our_jid( self.FT_content.session.ourjid) self.FT_content.transport.set_connection( self.FT_content.session.connection) sid = self.stanza.getTag('jingle').getAttr('sid') self.file_props = FilesProp.getNewFileProp(self.conn.name, sid) self.file_props.transport_sid = self.FT_content.transport.sid self.FT_content.file_props = self.file_props self.FT_content.transport.set_file_props(self.file_props) self.file_props.streamhosts.extend( self.FT_content.transport.remote_candidates) for host in self.file_props.streamhosts: host['initiator'] = self.FT_content.session.initiator host['target'] = self.FT_content.session.responder self.file_props.session_type = 'jingle' self.file_props.stream_methods = nbxmpp.NS_BYTESTREAM desc = self.jingle_content.getTag('description') if self.jingle_content.getAttr('creator') == 'initiator': file_tag = desc.getTag('file') self.file_props.sender = self.fjid self.file_props.receiver = self.conn._ft_get_our_jid() else: file_tag = desc.getTag('file') h = file_tag.getTag('hash') h = h.getData() if h else None n = file_tag.getTag('name') n = n.getData() if n else None pjid = app.get_jid_without_resource(self.fjid) file_info = self.conn.get_file_info(pjid, hash_=h, name=n,account=self.conn.name) self.file_props.file_name = file_info['file-name'] self.file_props.sender = self.conn._ft_get_our_jid() self.file_props.receiver = self.fjid self.file_props.type_ = 's' for child in file_tag.getChildren(): name = child.getName() val = child.getData() if val is None: continue if name == 'name': self.file_props.name = val if name == 'size': self.file_props.size = int(val) if name == 'hash': self.file_props.algo = child.getAttr('algo') self.file_props.hash_ = val if name == 'date': self.file_props.date = val else: si = self.stanza.getTag('si') self.file_props = FilesProp.getNewFileProp(self.conn.name, si.getAttr('id')) self.file_props.transport_sid = self.file_props.sid profile = si.getAttr('profile') if profile != nbxmpp.NS_FILE: self.conn.send_file_rejection(self.file_props, code='400', typ='profile') raise nbxmpp.NodeProcessed feature_tag = si.getTag('feature', namespace=nbxmpp.NS_FEATURE) if not feature_tag: return form_tag = feature_tag.getTag('x', namespace=nbxmpp.NS_DATA) if not form_tag: return self.dataform = dataforms.ExtendForm(node=form_tag) for f in self.dataform.iter_fields(): if f.var == 'stream-method' and f.type_ == 'list-single': values = [o[1] for o in f.options] self.file_props.stream_methods = ' '.join(values) if nbxmpp.NS_BYTESTREAM in values or \ nbxmpp.NS_IBB in values: break else: self.conn.send_file_rejection(self.file_props, code='400', typ='stream') raise nbxmpp.NodeProcessed file_tag = si.getTag('file') for name, val in file_tag.getAttrs().items(): if val is None: continue if name == 'name': self.file_props.name = val if name == 'size': self.file_props.size = int(val) mime_type = si.getAttr('mime-type') if mime_type is not None: self.file_props.mime_type = mime_type self.file_props.sender = self.fjid self.file_props.receiver = self.conn._ft_get_our_jid() self.file_props.request_id = self.id_ file_desc_tag = file_tag.getTag('desc') if file_desc_tag is not None: self.file_props.desc = file_desc_tag.getData() self.file_props.transfered_size = [] return True
def _nec_new_acc_connected(self, obj): """ Connection to server succeded, present the form to the user """ # We receive events from all accounts from GED if obj.conn.name != self.account: return if self.update_progressbar_timeout_id is not None: GLib.source_remove(self.update_progressbar_timeout_id) self.back_button.show() self.forward_button.show() self.is_form = obj.is_form empty_config = True if obj.is_form: dataform = dataforms.ExtendForm(node=obj.config) self.data_form_widget = dataforms_widget.DataFormWidget() self.data_form_widget.selectable = True self.data_form_widget.set_data_form(dataform) empty_config = False else: self.data_form_widget = config.FakeDataForm(obj.config, selectable=True) for field in obj.config: if field in ('key', 'instructions', 'x', 'registered'): continue empty_config = False break self.data_form_widget.show_all() self.xml.get_object('form_vbox').pack_start(self.data_form_widget, True, True, 0) if empty_config: self.forward_button.set_sensitive(False) self.notebook.set_current_page(4) # show form page return self.ssl_fingerprint_sha1 = obj.ssl_fingerprint_sha1 self.ssl_fingerprint_sha256 = obj.ssl_fingerprint_sha256 self.ssl_cert = obj.ssl_cert if obj.ssl_msg: # An SSL warning occured, show it hostname = app.connections[ self.account].new_account_info['hostname'] self.xml.get_object('ssl_label').set_markup( _('<b>Security Warning</b>' '\n\nThe authenticity of the %(hostname)s SSL certificate could' ' be invalid.\nSSL Error: %(error)s\n' 'Do you still want to connect to this server?') % { 'hostname': hostname, 'error': obj.ssl_msg }) if obj.errnum in (18, 27): text = _( 'Add this certificate to the list of trusted ' 'certificates.\nSHA-1 fingerprint of the certificate:\n' '%(sha1)s\nSHA-256 fingerprint of the certificate:\n' '%(sha256)s') % { 'sha1': obj.ssl_fingerprint_sha1, 'sha256': obj.ssl_fingerprint_sha256 } self.xml.get_object('ssl_checkbutton').set_label(text) else: self.xml.get_object('ssl_checkbutton').set_no_show_all(True) self.xml.get_object('ssl_checkbutton').hide() self.notebook.set_current_page(3) # show SSL page else: self.notebook.set_current_page(4) # show form page
def _nec_search_result_received(self, obj): if self.pulse_id: GLib.source_remove(self.pulse_id) self.progressbar.hide() self.label.hide() if not obj.is_dataform: if not obj.data: self.label.set_text(_('No result')) self.label.show() return # We suppose all items have the same fields sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.result_treeview = Gtk.TreeView() self.result_treeview.connect( 'cursor-changed', self.on_result_treeview_cursor_changed) sw.add(self.result_treeview) # Create model fieldtypes = [str] * len(obj.data[0]) model = Gtk.ListStore(*fieldtypes) # Copy data to model for item in obj.data: model.append(item.values()) # Create columns counter = 0 for field in obj.data[0].keys(): self.result_treeview.append_column( Gtk.TreeViewColumn(field, Gtk.CellRendererText(), text=counter)) if field == 'jid': self.jid_column = counter counter += 1 self.result_treeview.set_model(model) sw.show_all() self.search_vbox.pack_start(sw, True, True, 0) if self.jid_column > -1: self.add_contact_button.show() self.information_button.show() return self.dataform = dataforms.ExtendForm(node=obj.data) if len(self.dataform.items) == 0: # No result self.label.set_text(_('No result')) self.label.show() return self.data_form_widget.set_sensitive(True) try: self.data_form_widget.data_form = self.dataform except dataforms.Error: self.label.set_text(_('Error in received dataform')) self.label.show() return self.result_treeview = self.data_form_widget.records_treeview selection = self.result_treeview.get_selection() selection.set_mode(Gtk.SelectionMode.SINGLE) self.result_treeview.connect('cursor-changed', self.on_result_treeview_cursor_changed) counter = 0 for field in self.dataform.reported.iter_fields(): if field.var == 'jid': self.jid_column = counter break counter += 1 self.search_vbox.pack_start(self.data_form_widget, True, True, 0) self.data_form_widget.show() if self.jid_column > -1: self.add_contact_button.show() self.information_button.show() if self.data_form_widget.title: self.window.set_title('%s - Search - Gajim' % \ self.data_form_widget.title)
def stage3_next_form(self, command): if not isinstance(command, nbxmpp.Node): self.stage5(error=_('Service sent malformed data'), senderror=True) return self.sending_form_spinner.stop() if not self.sessionid: self.sessionid = command.getAttr('sessionid') elif self.sessionid != command.getAttr('sessionid'): self.stage5(error=_('Service changed the session identifier.'), senderror=True) return self.form_status = command.getAttr('status') self.commandnode = command.getAttr('node') if command.getTag('x'): self.dataform = dataforms.ExtendForm(node=command.getTag('x')) self.data_form_widget.set_sensitive(True) try: self.data_form_widget.selectable = True self.data_form_widget.data_form = self.dataform except dataforms.Error: self.stage5(error=_('Service sent malformed data'), senderror=True) return self.data_form_widget.show() if self.data_form_widget.title: self.window.set_title(_('%s - Ad-hoc Commands - Gajim') % \ self.data_form_widget.title) else: self.data_form_widget.hide() actions = command.getTag('actions') if actions: # actions, actions, actions... self.close_button.set_sensitive(True) self.back_button.set_sensitive(actions.getTag('prev') is not None) self.forward_button.set_sensitive( actions.getTag('next') is not None) self.execute_button.set_sensitive(True) self.finish_button.set_sensitive(actions.getTag('complete') is not \ None) else: self.close_button.set_sensitive(True) self.back_button.set_sensitive(False) self.forward_button.set_sensitive(False) self.execute_button.set_sensitive(True) self.finish_button.set_sensitive(False) if self.form_status == 'completed': self.close_button.set_sensitive(True) self.back_button.hide() self.forward_button.hide() self.execute_button.hide() self.finish_button.hide() self.close_button.show() self.stage_window_delete_cb = self.stage3_close_button_clicked note = command.getTag('note') if note: self.notes_label.set_text(note.getData()) self.notes_label.set_no_show_all(False) self.notes_label.show() else: self.notes_label.set_no_show_all(True) self.notes_label.hide()
def __init__(self, account, to='', action='', from_whom='', subject='', message='', resource='', session=None, form_node=None): self.instances.append(self) self.account = account self.action = action self.subject = subject self.message = message self.to = to self.from_whom = from_whom self.resource = resource self.session = session self.xml = get_builder('single_message_window.ui') self.window = self.xml.get_object('single_message_window') self.count_chars_label = self.xml.get_object('count_chars_label') self.from_label = self.xml.get_object('from_label') self.from_entry = self.xml.get_object('from_entry') self.to_label = self.xml.get_object('to_label') self.to_entry = self.xml.get_object('to_entry') self.subject_entry = self.xml.get_object('subject_entry') self.message_scrolledwindow = self.xml.get_object( 'message_scrolledwindow') self.message_textview = self.xml.get_object('message_textview') self.message_tv_buffer = self.message_textview.get_buffer() self.conversation_scrolledwindow = self.xml.get_object( 'conversation_scrolledwindow') self.conversation_textview = ConversationTextview( account, used_in_history_window=True) self.conversation_textview.tv.show() self.conversation_tv_buffer = self.conversation_textview.tv.get_buffer() self.xml.get_object('conversation_scrolledwindow').add( self.conversation_textview.tv) self.form_widget = None parent_box = self.xml.get_object('conversation_scrolledwindow').\ get_parent() if form_node: dataform = dataforms.ExtendForm(node=form_node) dataform.type_ = 'submit' self.form_widget = DataFormWidget(dataform) self.form_widget.show_all() parent_box.add(self.form_widget) parent_box.child_set_property(self.form_widget, 'position', parent_box.child_get_property(self.xml.get_object( 'conversation_scrolledwindow'), 'position')) self.action = 'form' self.send_button = self.xml.get_object('send_button') self.reply_button = self.xml.get_object('reply_button') self.send_and_close_button = self.xml.get_object('send_and_close_button') self.cancel_button = self.xml.get_object('cancel_button') self.close_button = self.xml.get_object('close_button') self.message_tv_buffer.connect('changed', self.update_char_counter) if isinstance(to, list): jid = ', '.join( [i[0].get_full_jid() for i in to]) self.to_entry.set_text(jid) self.to_entry.set_sensitive(False) else: self.to_entry.set_text(to) if app.config.get('use_speller') and app.is_installed('GSPELL') and action == 'send': lang = app.config.get('speller_language') gspell_lang = Gspell.language_lookup(lang) if gspell_lang is None: AspellDictError(lang) else: spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer( self.message_textview.get_buffer()) spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang)) spell_view = Gspell.TextView.get_from_gtk_text_view( self.message_textview) spell_view.set_inline_spell_checking(True) spell_view.set_enable_language_menu(True) self.prepare_widgets_for(self.action) # set_text(None) raises TypeError exception if self.subject is None: self.subject = '' self.subject_entry.set_text(self.subject) if to == '': liststore = get_completion_liststore(self.to_entry) self.completion_dict = helpers.get_contact_dict_for_account(account) keys = sorted(self.completion_dict.keys()) for jid in keys: contact = self.completion_dict[jid] status_icon = get_iconset_name_for(contact.show) liststore.append((status_icon, jid)) else: self.completion_dict = {} self.xml.connect_signals(self) # get window position and size from config resize_window(self.window, app.config.get('single-msg-width'), app.config.get('single-msg-height')) move_window(self.window, app.config.get('single-msg-x-position'), app.config.get('single-msg-y-position')) self.window.show_all()