diff --git a/data/glade/add_new_contact_window.glade b/data/glade/add_new_contact_window.glade index 791b3c5b7..77d62ceb8 100644 --- a/data/glade/add_new_contact_window.glade +++ b/data/glade/add_new_contact_window.glade @@ -54,45 +54,116 @@ 6 True - 6 + 7 2 False 6 6 - + True - User ID: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + True + Au_tomatically authorize contact + True + GTK_RELIEF_NORMAL + True + True + False + True - 0 - 1 - 0 - 1 + 1 + 2 + 6 + 7 fill - + True - Protocol: - False + + False + True + True + + + 1 + 2 + 5 + 6 + fill + + + + + + True + True + True + True + 0 + + True + * + True + + + 1 + 2 + 4 + 5 + + + + + + + True + False + False + True + 0 + + True + * + False + + + 1 + 2 + 3 + 4 + + + + + + + True + + False + True + + + + 1 + 2 + 2 + 3 + fill + fill + + + + + + True + _Group: + True False GTK_JUSTIFY_LEFT False @@ -109,8 +180,37 @@ 0 1 - 1 - 2 + 5 + 6 + fill + + + + + + + True + _Nickname: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + nickname_entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 4 + 5 fill @@ -119,8 +219,36 @@ True - Jabber ID: - False + _Jabber ID: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + _Protocol: + True False GTK_JUSTIFY_LEFT False @@ -145,10 +273,10 @@ - + True - Nickname: - False + _User ID: + True False GTK_JUSTIFY_LEFT False @@ -157,6 +285,7 @@ 0.5 0 0 + uid_entry PANGO_ELLIPSIZE_NONE -1 False @@ -165,8 +294,8 @@ 0 1 - 3 - 4 + 1 + 2 fill @@ -185,102 +314,20 @@ True - - 1 - 2 - 0 - 1 - - - - - - - True - - False - True - - 1 2 1 2 - fill - fill - - - - - - True - True - True - True - 0 - - True - * - True - - - 1 - 2 - 3 - 4 - + True - False - False - True - 0 - - True - * - False - - - 1 - 2 - 2 - 3 - - - - - - - True - True - Automatically authorize contact + _Account: True - GTK_RELIEF_NORMAL - True - True - False - True - - - 1 - 2 - 5 - 6 - fill - - - - - - - True - Group: - False False GTK_JUSTIFY_LEFT False @@ -297,26 +344,25 @@ 0 1 - 4 - 5 + 0 + 1 fill - + True False - True True 1 2 - 4 - 5 + 0 + 1 fill fill diff --git a/src/dialogs.py b/src/dialogs.py index da4b4dc4b..58ac9b086 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -362,15 +362,29 @@ class ChangeStatusMessageDialog: class AddNewContactWindow: '''Class for AddNewContactWindow''' - def __init__(self, account, jid = None): + def __init__(self, account = None, jid = None): self.account = account + if account == None: + # fill accounts with active accounts + accounts = [] + for account in gajim.connections.keys(): + if gajim.connections[account].connected > 1: + accounts.append(account) + if not accounts: + return + if len(accounts) == 1: + self.account = account + else: + accounts = [self.account] self.xml = gtkgui_helpers.get_glade('add_new_contact_window.glade') + self.account_combobox = self.xml.get_widget('account_combobox') + self.account_label = self.xml.get_widget('account_label') self.window = self.xml.get_widget('add_new_contact_window') self.uid_entry = self.xml.get_widget('uid_entry') self.protocol_combobox = self.xml.get_widget('protocol_combobox') self.jid_entry = self.xml.get_widget('jid_entry') self.nickname_entry = self.xml.get_widget('nickname_entry') - if len(gajim.connections) >= 2: + 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 else: @@ -381,11 +395,12 @@ _('Please fill in the data of the contact you want to add in account %s') %accou liststore.append(['Jabber', '']) self.agents = ['Jabber'] jid_agents = [] - for j in gajim.contacts.get_jid_list(account): - contact = gajim.contacts.get_first_contact_from_jid(account, j) - if _('Transports') in contact.groups and contact.show != 'offline' and\ - contact.show != 'error': - jid_agents.append(j) + for acct in accounts: + for j in gajim.contacts.get_jid_list(acct): + contact = gajim.contacts.get_first_contact_from_jid(acct, j) + if _('Transports') in contact.groups and contact.show != 'offline' and\ + contact.show != 'error': + jid_agents.append(j) for a in jid_agents: if a.find('aim') > -1: name = 'AIM' @@ -397,9 +412,8 @@ _('Please fill in the data of the contact you want to add in account %s') %accou name = 'Yahoo!' else: name = a - iter = liststore.append([name, a]) + liststore.append([name, a]) self.agents.append(name) - self.protocol_combobox.set_model(liststore) self.protocol_combobox.set_active(0) self.fill_jid() @@ -417,13 +431,15 @@ _('Please fill in the data of the contact you want to add in account %s') %accou self.protocol_combobox.set_active(0) self.set_nickname() self.nickname_entry.grab_focus() - self.group_comboboxentry = self.xml.get_widget('group_comboboxentry') liststore = gtk.ListStore(str) self.group_comboboxentry.set_model(liststore) - for g in gajim.groups[account].keys(): - if g not in helpers.special_groups: - self.group_comboboxentry.append_text(g) + group_names = [] + for acct in accounts: + for g in gajim.groups[acct].keys(): + if g not in helpers.special_groups and g not in group_names: + group_names.append(g) + self.group_comboboxentry.append_text(g) if not jid_agents: # There are no transports, so hide the protocol combobox and label @@ -432,7 +448,17 @@ _('Please fill in the data of the contact you want to add in account %s') %accou protocol_label = self.xml.get_widget('protocol_label') protocol_label.hide() protocol_label.set_no_show_all(True) - + if self.account: + self.account_label.hide() + self.account_combobox.hide() + self.account_label.set_no_show_all(True) + self.account_combobox.set_no_show_all(True) + else: + liststore = gtk.ListStore(str, str) + for acct in accounts: + liststore.append([acct, acct]) + self.account_combobox.set_model(liststore) + self.account_combobox.set_active(0) self.xml.signal_autoconnect(self) self.window.show_all() @@ -465,6 +491,12 @@ _('Please fill in the data of the contact you want to add in account %s') %accou ErrorDialog(pritext, _('The user ID must not contain a resource.')) return + # get value of account combobox, if account was not specified + if not self.account: + model = self.account_combobox.get_model() + index = self.account_combobox.get_active() + self.account = model[index][1] + # Check if jid is already in roster if jid in gajim.contacts.get_jid_list(self.account): c = gajim.contacts.get_first_contact_from_jid(self.account, jid) diff --git a/src/gajim-remote.py b/src/gajim-remote.py index 0f3b4c243..478990092 100755 --- a/src/gajim-remote.py +++ b/src/gajim-remote.py @@ -194,7 +194,8 @@ class GajimRemote: 'add_contact': [ _('Adds contact to roster'), [ - (_('account'), _('Adds new contact to this account.'), True) + (_('jid'), _('JID of the contact'), True), + (_('account'), _('Adds new contact to this account'), False) ] ], diff --git a/src/remote_control.py b/src/remote_control.py index e455db362..52b36acb9 100644 --- a/src/remote_control.py +++ b/src/remote_control.py @@ -472,12 +472,19 @@ class SignalObject(DbusPrototype): return True def add_contact(self, *args): - [account] = self._get_real_arguments(args, 1) - accounts = gajim.contacts.get_accounts() - if account in accounts: - AddNewContactWindow(account) - return True - return False + [jid, account] = self._get_real_arguments(args, 2) + if account: + if account in gajim.connections and \ + gajim.connections[account].connected > 1: + # if given account is active, use it + AddNewContactWindow(account = account, jid = jid) + else: + # wrong account + return False + else: + # if account is not given, show account combobox + AddNewContactWindow(account = None, jid = jid) + return True def remove_contact(self, *args): [jid, account] = self._get_real_arguments(args, 2)