From 8514e51675f582ffd14dff4327db7e5cb0b11d0a Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 7 Apr 2009 17:07:04 +0000 Subject: [PATCH] factorize send_file action in chat / groupchat / private chat. see #3948 --- src/chat_control.py | 35 +++++++++++++++++++++++++++++------ src/common/contacts.py | 6 +++--- src/groupchat_control.py | 19 +------------------ 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 659903cfb..de4b8382b 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -836,6 +836,34 @@ class ChatControlBase(MessageControl): gajim.interface.instances['logs'] = \ history_window.HistoryWindow(jid, self.account) + def _on_send_file(self, gc_contact=None): + '''gc_contact can be set when we are in a groupchat control''' + def _on_ok(c): + gajim.interface.instances['file_transfers'].show_file_send_request( + self.account, c) + if self.TYPE_ID == message_control.TYPE_PM: + gc_contact = self.gc_contact + if gc_contact: + # gc or pm + gc_control = gajim.interface.msg_win_mgr.get_gc_control( + gc_contact.room_jid, self.account) + self_contact = gajim.contacts.get_gc_contact(self.account, + gc_control.room_jid, gc_control.nick) + if gc_control.is_anonymous and gc_contact.affiliation not in ['admin', + 'owner'] and self_contact.affiliation in ['admin', 'owner']: + contact = gajim.contacts.get_contact(self.account, gc_contact.jid) + if not contact or contact.sub not in ('both', 'to'): + prim_text = _('Really send file?') + sec_text = _('If you send a file to %s, he/she will know your ' + 'real Jabber ID.') % gc_contact.name + dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text, + on_response_ok = (_on_ok, gc_contact)) + dialog.popup() + return + _on_ok(gc_contact) + return + _on_ok(self.contact) + def on_minimize_menuitem_toggled(self, widget): '''When a grouchat is minimized, unparent the tab, put it in roster etc''' old_value = False @@ -2635,12 +2663,7 @@ class ChatControl(ChatControlBase): self.bigger_avatar_window.window.set_cursor(cursor) def _on_send_file_menuitem_activate(self, widget): - if self.TYPE_ID == message_control.TYPE_PM: - c = self.gc_contact - else: - c = self.contact - gajim.interface.instances['file_transfers'].show_file_send_request( - self.account, c) + self._on_send_file() def _on_add_to_roster_menuitem_activate(self, widget): dialogs.AddNewContactWindow(self.account, self.contact.jid) diff --git a/src/common/contacts.py b/src/common/contacts.py index 8c2aca6ab..91e7d48c4 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -576,9 +576,9 @@ class Contacts: def contact_from_gc_contact(self, gc_contact): '''Create a Contact instance from a GC_Contact instance''' jid = gc_contact.get_full_jid() - return Contact(jid=jid, resource='', name=gc_contact.name, groups=[], - show=gc_contact.show, status=gc_contact.status, sub='none', - caps_node=gc_contact.caps_node, + return Contact(jid=jid, resource=gc_contact.resource, + name=gc_contact.name, groups=[], show=gc_contact.show, + status=gc_contact.status, sub='none', caps_node=gc_contact.caps_node, caps_hash_method=gc_contact.caps_hash_method, caps_hash=gc_contact.caps_hash) diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 2cacbad69..70be4f67c 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -1004,24 +1004,7 @@ class GroupchatControl(ChatControlBase): def on_send_file(self, widget, gc_contact): '''sends a file to a contact in the room''' - def _on_send_files(gc_c): - gajim.interface.instances['file_transfers'].show_file_send_request( - self.account, gc_c) - self_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, - self.nick) - if self.is_anonymous and gc_contact.affiliation not in ['admin', 'owner']\ - and self_contact.affiliation in ['admin', 'owner'] and \ - gc_contact.jid not in gajim.contacts.get_jid_list(self.account): - contact = gajim.contacts.get_contact(self.account, gc_contact.jid) - if not contact or contact.sub not in ('both', 'to'): - prim_text = _('Really send file?') - sec_text = _('If you send a file to %s, he/she will know your real ' - 'Jabber ID.') % gc_contact.name - dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text, - on_response_ok = (_on_send_files, gc_contact)) - dialog.popup() - return - _on_send_files(gc_contact) + self._on_send_file(gc_contact) def draw_contact(self, nick, selected=False, focus=False): iter_ = self.get_contact_iter(nick)