def show_hash_error(self, jid, file_props, account): def on_yes(dummy, fjid, file_props, account): # Delete old file os.remove(file_props.file_name) jid, resource = app.get_room_and_nick_from_fjid(fjid) if resource: contact = app.contacts.get_contact(account, jid, resource) else: contact = app.contacts.get_contact_with_highest_priority( account, jid) fjid = contact.get_full_jid() # Request the file to the sender sid = helpers.get_random_string_16() new_file_props = FilesProp.getNewFileProp(account, sid) new_file_props.file_name = file_props.file_name new_file_props.name = file_props.name new_file_props.desc = file_props.desc new_file_props.size = file_props.size new_file_props.date = file_props.date new_file_props.hash_ = file_props.hash_ new_file_props.type_ = 'r' tsid = app.connections[account].start_file_transfer( fjid, new_file_props, True) new_file_props.transport_sid = tsid self.add_transfer(account, contact, new_file_props) if file_props.type_ == 'r': file_name = os.path.basename(file_props.file_name) else: file_name = file_props.name dialogs.YesNoDialog(('File transfer error'), _('The file %(file)s has been received, but it seems to have ' 'been damaged along the way.\nDo you want to download it again?') % \ {'file': file_name}, on_response_yes=(on_yes, jid, file_props, account), type_=Gtk.MessageType.ERROR)
def relog(self, account): if app.connections[account].connected == 0: return if account == app.ZEROCONF_ACC_NAME: app.connections[app.ZEROCONF_ACC_NAME].update_details() return def login(account, show_before, status_before): """ Login with previous status """ # first make sure connection is really closed, # 0.5 may not be enough app.connections[account].disconnect(True) app.interface.roster.send_status(account, show_before, status_before) def relog(account): show_before = app.SHOW_LIST[app.connections[account].connected] status_before = app.connections[account].status app.interface.roster.send_status(account, 'offline', _('Be right back.')) GLib.timeout_add(500, login, account, show_before, status_before) dialogs.YesNoDialog( _('Relogin now?'), _('If you want all the changes to apply instantly, ' 'you must relogin.'), transient_for=self, on_response_yes=lambda *args: relog(account))
def on_history_manager_window_delete_event(self, widget, event): if not self.AT_LEAST_ONE_DELETION_DONE: Gtk.main_quit() return def on_yes(clicked): self.cur.execute('VACUUM') self.con.commit() Gtk.main_quit() def on_no(): Gtk.main_quit() dialog = dialogs.YesNoDialog( _('Do you want to clean up the database? ' '(STRONGLY NOT RECOMMENDED IF GAJIM IS RUNNING)'), _('Normally allocated database size will not be freed, ' 'it will just become reusable. If you really want to reduce ' 'database filesize, click YES, else click NO.' '\n\nIn case you click YES, please wait…'), on_response_yes=on_yes, on_response_no=on_no) dialog.set_title(_('Database Cleanup')) button_box = dialog.get_children()[0].get_children()[1] button_box.get_children()[0].grab_focus()
def handle_negotiation(self, form): if form.getField('accept') and not form['accept'] in ('1', 'true'): self.cancelled_negotiation() return # encrypted session states. these are described in stanza_session.py try: if form.getType() == 'form' and 'security' in form.asDict(): security_options = [x[1] for x in form.getField('security').\ getOptions()] if security_options == ['none']: self.respond_archiving(form) else: # bob responds # we don't support 3-message negotiation as the responder if 'dhkeys' in form.asDict(): self.fail_bad_negotiation( '3 message negotiation not ' 'supported when responding', ('dhkeys', )) return negotiated, not_acceptable, ask_user = \ self.verify_options_bob(form) if ask_user: def accept_nondefault_options(is_checked): self.dialog.destroy() negotiated.update(ask_user) self.respond_e2e_bob(form, negotiated, not_acceptable) def reject_nondefault_options(): self.dialog.destroy() for key in ask_user.keys(): not_acceptable.append(key) self.respond_e2e_bob(form, negotiated, not_acceptable) self.dialog = dialogs.YesNoDialog( _('Confirm these ' 'session options'), _('The remote client wants to negotiate a session ' 'with these features:\n\n%s\n\nAre these options ' 'acceptable?' '') % (negotiation.describe_features(ask_user)), on_response_yes=accept_nondefault_options, on_response_no=reject_nondefault_options, transient_for=self.control.parent_win.window) else: self.respond_e2e_bob(form, negotiated, not_acceptable) return elif self.status == 'requested-archiving' and form.getType() == \ 'submit': try: self.archiving_accepted(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return # alice accepts elif self.status == 'requested-e2e' and form.getType() == 'submit': negotiated, not_acceptable, ask_user = self.verify_options_alice( form) if ask_user: def accept_nondefault_options(is_checked): if dialog: dialog.destroy() if is_checked: allow_no_log_for = app.config.get_per( 'accounts', self.conn.name, 'allow_no_log_for').split() jid = str(self.jid) if jid not in allow_no_log_for: allow_no_log_for.append(jid) app.config.set_per('accounts', self.conn.name, 'allow_no_log_for', ' '.join(allow_no_log_for)) negotiated.update(ask_user) try: self.accept_e2e_alice(form, negotiated) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) def reject_nondefault_options(): self.reject_negotiation() dialog.destroy() allow_no_log_for = app.config.get_per( 'accounts', self.conn.name, 'allow_no_log_for').split() if str(self.jid) in allow_no_log_for: dialog = None accept_nondefault_options(False) else: dialog = dialogs.YesNoDialog( _('Confirm these session ' 'options'), _('The remote client selected these options:\n\n%s' '\n\nContinue with the session?') % (negotiation.describe_features(ask_user)), _('Always accept for this contact'), on_response_yes=accept_nondefault_options, on_response_no=reject_nondefault_options, transient_for=self.control.parent_win.window) else: try: self.accept_e2e_alice(form, negotiated) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return elif self.status == 'responded-archiving' and form.getType() == \ 'result': try: self.we_accept_archiving(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return elif self.status == 'responded-e2e' and form.getType() == 'result': try: self.accept_e2e_bob(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return elif self.status == 'identified-alice' and form.getType( ) == 'result': try: self.final_steps_alice(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return except exceptions.Cancelled: # user cancelled the negotiation self.reject_negotiation() return if form.getField('terminate') and\ form.getField('terminate').getValue() in ('1', 'true'): self.acknowledge_termination() self.conn.delete_session(str(self.jid), self.thread_id) return # non-esession negotiation. this isn't very useful, but i'm keeping it # around to test my test suite. if form.getType() == 'form': if not self.control: jid, resource = app.get_room_and_nick_from_fjid(str(self.jid)) account = self.conn.name contact = app.contacts.get_contact(account, str(self.jid), resource) if not contact: contact = app.contacts.create_contact( jid=jid, account=account, resource=resource, show=self.conn.get_status()) app.interface.new_chat(contact, account, resource=resource, session=self) negotiation.FeatureNegotiationWindow(account, str(self.jid), self, form)