diff --git a/data/gui/add_new_contact_window.ui b/data/gui/add_new_contact_window.ui index 41d642778..79d5b3413 100644 --- a/data/gui/add_new_contact_window.ui +++ b/data/gui/add_new_contact_window.ui @@ -44,6 +44,7 @@ True liststore3 + @@ -256,6 +257,19 @@ 5 + + + _Save subscription message + True + True + False + True + True + + + 6 + + True @@ -293,7 +307,7 @@ proceed. - 6 + 7 @@ -306,7 +320,7 @@ to add a contact from this protocol. False False - 7 + 8 @@ -352,7 +366,7 @@ to add a contact from this protocol. False False - 8 + 9 diff --git a/src/common/config.py b/src/common/config.py index 475200912..82c1b9b3c 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -365,6 +365,7 @@ class Config: '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 --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 8b90fea58..66cbbd82d 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -437,7 +437,7 @@ class ConnectionVcard: 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 @@ class ConnectionVcard: 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 @@ class ConnectionVcard: 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 --git a/src/common/helpers.py b/src/common/helpers.py index 15dc0f7ee..8069470ae 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -41,6 +41,7 @@ import hashlib 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 @@ def group_is_blocked(account, group): 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 --git a/src/dialogs.py b/src/dialogs.py index 306a71ef2..a9f55e5cf 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -827,11 +827,11 @@ class AddNewContactWindow: """ 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 @@ class AddNewContactWindow: 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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 @@ _('Please fill in the data of the contact you want to add in account %s') %accou 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()