From 64af5db70c08276b7a2b8a0f09fd0b1702322a70 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 25 Mar 2007 22:38:44 +0000 Subject: [PATCH] [Anthony Lannuzel and I] add ability to synchronise contact list from another account. --- data/glade/account_modification_window.glade | 194 ++++++++++++------ .../synchronise_select_account_dialog.glade | 131 ++++++++++++ .../synchronise_select_contacts_dialog.glade | 131 ++++++++++++ src/config.py | 7 + src/dialogs.py | 130 ++++++++++++ 5 files changed, 527 insertions(+), 66 deletions(-) create mode 100644 data/glade/synchronise_select_account_dialog.glade create mode 100644 data/glade/synchronise_select_contacts_dialog.glade diff --git a/data/glade/account_modification_window.glade b/data/glade/account_modification_window.glade index 6ed71d58c..8fb831072 100644 --- a/data/glade/account_modification_window.glade +++ b/data/glade/account_modification_window.glade @@ -99,7 +99,7 @@ 6 True - 4 + 5 3 False 6 @@ -134,27 +134,6 @@ - - - True - True - True - True - 0 - - True - * - True - - - 1 - 3 - 0 - 1 - - - - True @@ -260,50 +239,6 @@ - - - True - Resource is sent to the Jabber server in order to separate the same JID in two or more parts depending on the number of the clients connected in the same server with the same account. So you might be connected in the same account with resource 'Home' and 'Work' at the same time. The resource which has the highest priority will get the events. (see below) - True - True - True - 0 - Gajim - True - * - False - - - 1 - 2 - 2 - 3 - expand|shrink|fill - - - - - - - True - Click to change account's password - True - Chan_ge Password - True - GTK_RELIEF_NORMAL - True - - - - 2 - 3 - 2 - 3 - fill - - - - True @@ -379,6 +314,133 @@ + + + + True + True + False + 0 + + + + True + True + 11 + + + + True + True + Synchronise contacts + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + True + + + + + + True + Click to change account's password + True + Chan_ge Password + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + True + + + + + + + + True + Administration operations + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + 3 + 4 + 5 + fill + fill + + + + + + True + True + True + True + 0 + + True + * + True + + + 1 + 3 + 0 + 1 + + + + + + + True + Resource is sent to the Jabber server in order to separate the same JID in two or more parts depending on the number of the clients connected in the same server with the same account. So you might be connected in the same account with resource 'Home' and 'Work' at the same time. The resource which has the highest priority will get the events. (see below) + True + True + True + 0 + Gajim + True + * + False + + + 1 + 3 + 2 + 3 + expand|shrink|fill + + + False diff --git a/data/glade/synchronise_select_account_dialog.glade b/data/glade/synchronise_select_account_dialog.glade new file mode 100644 index 000000000..e75ed5d7e --- /dev/null +++ b/data/glade/synchronise_select_account_dialog.glade @@ -0,0 +1,131 @@ + + + + + + + 12 + Synchronise contacts + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 350 + 300 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 6 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + Select the account with which you want to synchronise + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 150 + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + 0 + True + True + + + + + + + diff --git a/data/glade/synchronise_select_contacts_dialog.glade b/data/glade/synchronise_select_contacts_dialog.glade new file mode 100644 index 000000000..3d10b012c --- /dev/null +++ b/data/glade/synchronise_select_contacts_dialog.glade @@ -0,0 +1,131 @@ + + + + + + + 12 + Synchronise : select contacts + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 400 + 300 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 6 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + Select the contacts you want to synchronise + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 150 + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + 0 + True + True + + + + + + + diff --git a/src/config.py b/src/config.py index dd2654412..50bbadd2c 100644 --- a/src/config.py +++ b/src/config.py @@ -1588,6 +1588,13 @@ class AccountModificationWindow: gajim.interface.instances['manage_proxies'] = \ ManageProxiesWindow() + def on_synchronise_contacts_button_clicked(self, widget): + try: + dialog = dialogs.SynchroniseSelectAccountDialog(self.account) + except GajimGeneralException: + # If we showed ErrorDialog, there will not be dialog instance + return + def on_gpg_choose_button_clicked(self, widget, data = None): if gajim.connections.has_key(self.account): secret_keys = gajim.connections[self.account].ask_gpg_secrete_keys() diff --git a/src/dialogs.py b/src/dialogs.py index 85dad7c10..7c44bb5b1 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1319,6 +1319,136 @@ class JoinGroupchatWindow: self.window.destroy() +class SynchroniseSelectAccountDialog: + def __init__(self, account): + # 'account' can be None if we are about to create our first one + if not account or gajim.connections[account].connected < 2: + ErrorDialog(_('You are not connected to the server'), + _('Without a connection, you can not synchronise your contacts.')) + raise GajimGeneralException, 'You are not connected to the server' + self.account = account + self.xml = gtkgui_helpers.get_glade('synchronise_select_account_dialog.glade') + self.dialog = self.xml.get_widget('synchronise_select_account_dialog') + self.accounts_treeview = self.xml.get_widget('accounts_treeview') + model = gtk.ListStore(str, str, bool) + self.accounts_treeview.set_model(model) + # columns + renderer = gtk.CellRendererText() + self.accounts_treeview.insert_column_with_attributes(-1, + _('Name'), renderer, text = 0) + renderer = gtk.CellRendererText() + self.accounts_treeview.insert_column_with_attributes(-1, + _('Server'), renderer, text = 1) + + self.xml.signal_autoconnect(self) + self.init_accounts() + self.dialog.show_all() + + def on_accounts_window_key_press_event(self, widget, event): + if event.keyval == gtk.keysyms.Escape: + self.window.destroy() + + def init_accounts(self): + '''initialize listStore with existing accounts''' + model = self.accounts_treeview.get_model() + model.clear() + for remote_account in gajim.connections: + if remote_account == self.account: + # Do not show the account we're sync'ing + continue + iter = model.append() + model.set(iter, 0, remote_account, 1, gajim.get_hostname_from_account( + remote_account)) + + def on_cancel_button_clicked(self, widget): + self.dialog.destroy() + + def on_ok_button_clicked(self, widget): + sel = self.accounts_treeview.get_selection() + (model, iter) = sel.get_selected() + if not iter: + return + remote_account = model.get_value(iter, 0).decode('utf-8') + + if gajim.connections[remote_account].connected < 2: + ErrorDialog(_('This account is not connected to the server'), + _('You cannot synchronize with an account unless it is connected.')) + return + else: + try: + dialog = SynchroniseSelectContactsDialog(self.account, remote_account) + except GajimGeneralException: + # if we showed ErrorDialog, there will not be dialog instance + return + self.dialog.destroy() + +class SynchroniseSelectContactsDialog: + def __init__(self, account, remote_account): + self.local_account = account + self.remote_account = remote_account + self.xml = gtkgui_helpers.get_glade('synchronise_select_contacts_dialog.glade') + self.dialog = self.xml.get_widget('synchronise_select_contacts_dialog') + self.contacts_treeview = self.xml.get_widget('contacts_treeview') + model = gtk.ListStore(bool, str) + self.contacts_treeview.set_model(model) + # columns + renderer1 = gtk.CellRendererToggle() + renderer1.set_property('activatable', True) + renderer1.connect('toggled', self.toggled_callback) + self.contacts_treeview.insert_column_with_attributes(-1, + _('Synchronise'), renderer1, active = 0) + renderer2 = gtk.CellRendererText() + self.contacts_treeview.insert_column_with_attributes(-1, + _('Name'), renderer2, text = 1) + + self.xml.signal_autoconnect(self) + self.init_contacts() + self.dialog.show_all() + + def toggled_callback(self, cell, path): + model = self.contacts_treeview.get_model() + iter = model.get_iter(path) + model[iter][0] = not cell.get_active() + + def on_contacts_window_key_press_event(self, widget, event): + if event.keyval == gtk.keysyms.Escape: + self.window.destroy() + + def init_contacts(self): + '''initialize listStore with existing accounts''' + model = self.contacts_treeview.get_model() + model.clear() + + # recover local contacts + local_jid_list = gajim.contacts.get_jid_list(self.local_account) + + remote_jid_list = gajim.contacts.get_jid_list(self.remote_account) + for remote_jid in remote_jid_list: + if remote_jid not in local_jid_list: + iter = model.append() + model.set(iter, 0, True, 1, remote_jid) + + def on_cancel_button_clicked(self, widget): + self.dialog.destroy() + + def on_ok_button_clicked(self, widget): + model = self.contacts_treeview.get_model() + iter = model.get_iter_root() + while iter: + if model[iter][0]: + # it is selected + remote_jid = model[iter][1].decode('utf-8') + message = 'I\'m synchronizing my contacts from my %s account, could you please add this address to your contact list?' % \ + gajim.get_hostname_from_account(self.remote_account) + remote_contact = gajim.contacts.get_first_contact_from_jid( + self.remote_account, remote_jid) + # keep same groups and same nickname + gajim.interface.roster.req_sub(self, remote_jid, message, + self.local_account, groups = remote_contact.groups, + nickname = remote_contact.name, auto_auth = True) + iter = model.iter_next(iter) + self.dialog.destroy() + class NewChatDialog(InputDialog): def __init__(self, account): self.account = account