changeset 69da706a7ea9 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=69da706a7ea9 description: improve subscription request message, ability to save it. Fixes #2176
diffstat:
data/gui/add_new_contact_window.ui | 20 +++++++++++-- src/common/config.py | 1 + src/common/connection_handlers.py | 6 ++-- src/common/helpers.py | 24 ++++++++++++++++ src/dialogs.py | 54 +++++++++++++++++++++++++------------ 5 files changed, 81 insertions(+), 24 deletions(-)
diffs (272 lines):
diff -r 4f78a9e08b3a -r 69da706a7ea9 data/gui/add_new_contact_window.ui --- a/data/gui/add_new_contact_window.ui Tue Jan 26 19:55:28 2010 +0100 +++ b/data/gui/add_new_contact_window.ui Wed Jan 27 17:23:37 2010 +0100 @@ -44,6 +44,7 @@ <object class="GtkComboBox" id="account_combobox"> <property name="visible">True</property> <property name="model">liststore3</property> + <signal name="changed" handler="on_account_combobox_changed"/> <child> <object class="GtkCellRendererText" id="cellrenderertext3"/> <attributes> @@ -257,6 +258,19 @@ </packing> </child> <child> + <object class="GtkCheckButton" id="save_message_checkbutton"> + <property name="label" translatable="yes">_Save subscription message</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="position">6</property> + </packing> + </child> + <child> <object class="GtkHBox" id="register_hbox"> <property name="visible">True</property> <property name="no_show_all">True</property> @@ -293,7 +307,7 @@ </child> </object> <packing> - <property name="position">6</property> + <property name="position">7</property> </packing> </child> <child> @@ -306,7 +320,7 @@ <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">7</property> + <property name="position">8</property> </packing> </child> <child> @@ -352,7 +366,7 @@ <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">8</property> + <property name="position">9</property> </packing> </child> </object> diff -r 4f78a9e08b3a -r 69da706a7ea9 src/common/config.py --- a/src/common/config.py Tue Jan 26 19:55:28 2010 +0100 +++ b/src/common/config.py Wed Jan 27 17:23:37 2010 +0100 @@ -365,6 +365,7 @@ 'log_encrypted_sessions': [opt_bool, True, _('When negotiating an encrypted session, should Gajim assume you want your messages to be logged?')], 'send_idle_time': [ opt_bool, True ], 'roster_version': [opt_str, ''], + 'subscription_request_msg': [opt_str, '', _('Message that is sent to contacts you want to add')], }, {}), 'statusmsg': ({ 'message': [ opt_str, '' ], diff -r 4f78a9e08b3a -r 69da706a7ea9 src/common/connection_handlers.py --- a/src/common/connection_handlers.py Tue Jan 26 19:55:28 2010 +0100 +++ b/src/common/connection_handlers.py Wed Jan 27 17:23:37 2010 +0100 @@ -437,7 +437,7 @@ except IOError, e: self.dispatch('ERROR', (_('Disk Write Error'), str(e)))
- def get_cached_vcard(self, fjid, is_fake_jid = False): + def get_cached_vcard(self, fjid, is_fake_jid=False): """ Return the vcard as a dict. Return {} if vcard was too old. @@ -457,7 +457,7 @@ c = f.read() f.close() try: - card = common.xmpp.Node(node = c) + card = common.xmpp.Node(node=c) except Exception: # We are unable to parse it. Remove it os.remove(path_to_file) @@ -469,7 +469,7 @@ elif 'SHA' in vcard['PHOTO']: cached_sha = vcard['PHOTO']['SHA'] if jid in self.vcard_shas and self.vcard_shas[jid] != \ - cached_sha: + cached_sha: # user change his vcard so don't use the cached one return {} vcard['jid'] = jid diff -r 4f78a9e08b3a -r 69da706a7ea9 src/common/helpers.py --- a/src/common/helpers.py Tue Jan 26 19:55:28 2010 +0100 +++ b/src/common/helpers.py Wed Jan 27 17:23:37 2010 +0100 @@ -41,6 +41,7 @@ import caps_cache
from encodings.punycode import punycode_encode +from string import Template
from i18n import Q_ from i18n import ngettext @@ -1329,4 +1330,27 @@ return ((group in gajim.connections[account].blocked_groups) or \ gajim.connections[account].blocked_all)
+def get_subscription_request_msg(account=None): + s = gajim.config.get_per('accounts', account, 'subscription_request_msg') + if s: + return s + s = _('I would like to add you to my contact list.') + if account: + s = _('Hello, I am $name.') + ' ' + s + our_jid = gajim.get_jid_from_account(account) + vcard = gajim.connections[account].get_cached_vcard(our_jid) + name = '' + if 'N' in vcard: + if 'GIVEN' in vcard['N'] and 'FAMILY' in vcard['N']: + name = vcard['N']['GIVEN'] + ' ' + vcard['N']['FAMILY'] + if not name: + if 'FN' in vcard: + name = vcard['FN'] + nick = gajim.nicks[account] + if name and nick: + name += ' (%s)' % nick + elif nick: + name = nick + s = Template(s).safe_substitute({'name': name}) + return s # vim: se ts=3: diff -r 4f78a9e08b3a -r 69da706a7ea9 src/dialogs.py --- a/src/dialogs.py Tue Jan 26 19:55:28 2010 +0100 +++ b/src/dialogs.py Wed Jan 27 17:23:37 2010 +0100 @@ -827,11 +827,11 @@ """
uid_labels = {'jabber': _('Jabber ID:'), - 'aim': _('AIM Address:'), - 'gadu-gadu': _('GG Number:'), - 'icq': _('ICQ Number:'), - 'msn': _('MSN Address:'), - 'yahoo': _('Yahoo! Address:')} + 'aim': _('AIM Address:'), + 'gadu-gadu': _('GG Number:'), + 'icq': _('ICQ Number:'), + 'msn': _('MSN Address:'), + 'yahoo': _('Yahoo! Address:')}
def __init__(self, account=None, jid=None, user_nick=None, group=None): self.account = account @@ -860,17 +860,18 @@ self.xml.connect_signals(self) self.window = self.xml.get_object('add_new_contact_window') for w in ('account_combobox', 'account_hbox', 'account_label', - 'uid_label', 'uid_entry', 'protocol_combobox', 'protocol_jid_combobox', - 'protocol_hbox', 'nickname_entry', 'message_scrolledwindow', - 'register_hbox', 'subscription_table', 'add_button', - 'message_textview', 'connected_label', 'group_comboboxentry', - 'auto_authorize_checkbutton'): + 'uid_label', 'uid_entry', 'protocol_combobox', 'protocol_jid_combobox', + 'protocol_hbox', 'nickname_entry', 'message_scrolledwindow', + 'save_message_checkbutton', 'register_hbox', 'subscription_table', + 'add_button', 'message_textview', 'connected_label', + 'group_comboboxentry', 'auto_authorize_checkbutton'): self.__dict__[w] = self.xml.get_object(w) if account and len(gajim.connections) >= 2: - prompt_text =\ -_('Please fill in the data of the contact you want to add in account %s') %account + prompt_text = \ +_('Please fill in the data of the contact you want to add in account %s') % account else: - prompt_text = _('Please fill in the data of the contact you want to add') + prompt_text = \ + _('Please fill in the data of the contact you want to add') self.xml.get_object('prompt_label').set_text(prompt_text) self.agents = {'jabber': []} # types to which we are not subscribed but account has an agent for it @@ -908,7 +909,7 @@ self.protocol_combobox.add_attribute(cell, 'text', 0) self.protocol_combobox.set_model(liststore) uf_type = {'jabber': 'Jabber', 'aim': 'AIM', 'gadu-gadu': 'Gadu Gadu', - 'icq': 'ICQ', 'msn': 'MSN', 'yahoo': 'Yahoo'} + 'icq': 'ICQ', 'msn': 'MSN', 'yahoo': 'Yahoo'} # Jabber as first img = gajim.interface.jabber_state_images['16']['online'] liststore.append(['Jabber', img.get_pixbuf(), 'jabber']) @@ -938,7 +939,7 @@ else: uid, transport = gajim.get_name_and_server_from_jid(jid) self.uid_entry.set_text(uid.replace('%', '@', 1)) - #set protocol_combobox + # set protocol_combobox model = self.protocol_combobox.get_model() iter_ = model.get_iter_first() i = 0 @@ -990,6 +991,11 @@ self.account_combobox.set_model(liststore) self.account_combobox.set_active(0)
+ if self.account: + message_buffer = self.message_textview.get_buffer() + message_buffer.set_text(helpers.get_subscription_request_msg( + self.account)) + def on_add_new_contact_window_destroy(self, widget): if self.account: location = gajim.interface.instances[self.account] @@ -1058,7 +1064,7 @@ c = gajim.contacts.get_first_contact_from_jid(self.account, jid) if _('Not in Roster') not in c.groups and c.sub in ('both', 'to'): ErrorDialog(_('Contact already in roster'), - _('This contact is already listed in your roster.')) + _('This contact is already listed in your roster.')) return
if type_ == 'jabber': @@ -1066,6 +1072,9 @@ start_iter = message_buffer.get_start_iter() end_iter = message_buffer.get_end_iter() message = message_buffer.get_text(start_iter, end_iter).decode('utf-8') + if self.save_message_checkbutton.get_active(): + gajim.config.set_per('accounts', self.account, + 'subscription_request_msg', message) else: message= '' group = self.group_comboboxentry.child.get_text().decode('utf-8') @@ -1074,9 +1083,16 @@ groups = [group] auto_auth = self.auto_authorize_checkbutton.get_active() gajim.interface.roster.req_sub(self, jid, message, self.account, - groups = groups, nickname = nickname, auto_auth = auto_auth) + groups=groups, nickname=nickname, auto_auth=auto_auth) self.window.destroy()
+ def on_account_combobox_changed(self, widget): + model = widget.get_model() + iter_ = widget.get_active_iter() + account = model[iter_][0] + message_buffer = self.message_textview.get_buffer() + message_buffer.set_text(helpers.get_subscription_request_msg(account)) + def on_protocol_combobox_changed(self, widget): model = widget.get_model() iter_ = widget.get_active_iter() @@ -1097,8 +1113,10 @@ self.uid_label.set_text(_('User ID:')) if type_ == 'jabber': self.message_scrolledwindow.show() + self.save_message_checkbutton.show() else: self.message_scrolledwindow.hide() + self.save_message_checkbutton.hide() if type_ in self.available_types: self.register_hbox.show() self.auto_authorize_checkbutton.hide() @@ -1110,7 +1128,7 @@ if type_ != 'jabber': jid = self.protocol_jid_combobox.get_active_text() contact = gajim.contacts.get_first_contact_from_jid(self.account, - jid) + jid) if contact.show in ('offline', 'error'): self.subscription_table.hide() self.connected_label.show()