Anthony Lannuzel wrote:
> Hi,
> I have written a small patch which allows a user to copy his contacts
> from one account to another.
> 
> In the attached file you will find 3 diffs and 1 file to create (I'm
> not used to making patches, hope this is not too ugly).
> 
> After having applied this, go the modification window of the account
> you want to add the contacts to. Click the "synchronize" button and
> select the account containing the contacts, then apply, and the
> necessary subscription requests are sent.
> You have to be connected to both accounts in order for that to work.
> 
> I hope this can be useful.
> 
> Anthony
> 

Hi anthony,

you did a good work!
Attached is your patch reformated (we use tab to indent) with a minor
modif, we now keep group and nickname when we syncronise.

what about adding the "syncronise" button in General tab instead of
Account tab?

What about adding a confirmation dialog: "you're going to send X
authorisation request, do you want to continue?" in order not to send
them by mistake

-- 
Yann

Index: src/config.py
===================================================================
--- src/config.py	(revision 8023)
+++ src/config.py	(working copy)
@@ -1588,6 +1588,13 @@
 			gajim.interface.instances['manage_proxies'] = \
 				ManageProxiesWindow()
 
+	def on_synchronise_contacts_button_clicked(self, widget):
+		try:
+			dialog = dialogs.SynchroniseContactsDialog(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()
Index: src/dialogs.py
===================================================================
--- src/dialogs.py	(revision 8023)
+++ src/dialogs.py	(working copy)
@@ -1319,6 +1319,81 @@
 
 		self.window.destroy()
 
+class SynchroniseContactsDialog:
+	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 cannot synchronise your contacts.'))
+			raise GajimGeneralException, 'You are not connected to the server'
+		self.account = account
+		self.xml = gtkgui_helpers.get_glade('synchronise_contacts_dialog.glade')
+		self.dialog = self.xml.get_widget('synchronise_contacts_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[iter][0].decode('utf-8')
+
+		local_account = self.account
+
+		# recover local contacts
+		local_jid_list = gajim.contacts.get_jid_list(local_account)
+
+		if gajim.connections[remote_account].connected < 2:
+			ErrorDialog(_('This account is not connected to the server'),
+				_('You cannot synchronize with an account unless you are connected '
+				'to it.'))
+			return
+		else:
+			remote_jid_list = gajim.contacts.get_jid_list(remote_account)
+			for remote_jid in remote_jid_list:
+				if remote_jid not in local_jid_list:
+					message = 'I\'m synchronizing my contacts from my %s  account, '
+					'could you please add this address to your contact list?'
+					remote_contact = gajim.contacts.get_first_contact_from_jid(
+						remote_account, remote_jid)
+					# keep same groups and same nickname
+					gajim.interface.roster.req_sub(self, remote_jid, message,
+						local_account, groups = remote_contact.groups,
+						nickname = remote_contact.name, auto_auth = True)
+		self.dialog.destroy()
+
 class NewChatDialog(InputDialog):
 	def __init__(self, account):
 		self.account = account
Index: data/glade/synchronise_contacts_dialog.glade
===================================================================
--- data/glade/synchronise_contacts_dialog.glade	(revision 0)
+++ data/glade/synchronise_contacts_dialog.glade	(revision 0)
@@ -0,0 +1,131 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>
+
+<glade-interface>
+
+<widget class="GtkDialog" id="synchronise_contacts_dialog">
+  <property name="border_width">12</property>
+  <property name="title" translatable="yes">Synchronise contacts</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="default_width">150</property>
+  <property name="default_height">300</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
+  <property name="has_separator">True</property>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="dialog-vbox7">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">6</property>
+
+      <child internal-child="action_area">
+	<widget class="GtkHButtonBox" id="dialog-action_area6">
+	  <property name="visible">True</property>
+	  <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+	  <child>
+	    <widget class="GtkButton" id="cancel_button">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-cancel</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="response_id">-6</property>
+	      <signal name="clicked" handler="on_cancel_button_clicked" last_modification_time="Thu, 01 Mar 2007 14:08:01 GMT"/>
+	    </widget>
+	  </child>
+
+	  <child>
+	    <widget class="GtkButton" id="ok_button">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-ok</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="response_id">-5</property>
+	      <signal name="clicked" handler="on_ok_button_clicked" last_modification_time="Thu, 01 Mar 2007 14:07:38 GMT"/>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">True</property>
+	  <property name="pack_type">GTK_PACK_END</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkLabel" id="label210">
+	  <property name="visible">True</property>
+	  <property name="label" translatable="yes">Select the account with which to synchronise</property>
+	  <property name="use_underline">False</property>
+	  <property name="use_markup">False</property>
+	  <property name="justify">GTK_JUSTIFY_LEFT</property>
+	  <property name="wrap">False</property>
+	  <property name="selectable">False</property>
+	  <property name="xalign">0.5</property>
+	  <property name="yalign">0.5</property>
+	  <property name="xpad">0</property>
+	  <property name="ypad">0</property>
+	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	  <property name="width_chars">-1</property>
+	  <property name="single_line_mode">False</property>
+	  <property name="angle">0</property>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">False</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkScrolledWindow" id="scrolledwindow">
+	  <property name="width_request">150</property>
+	  <property name="visible">True</property>
+	  <property name="can_focus">True</property>
+	  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+	  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+	  <property name="shadow_type">GTK_SHADOW_IN</property>
+	  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+	  <child>
+	    <widget class="GtkTreeView" id="accounts_treeview">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="headers_visible">True</property>
+	      <property name="rules_hint">False</property>
+	      <property name="reorderable">False</property>
+	      <property name="enable_search">True</property>
+	      <property name="fixed_height_mode">False</property>
+	      <property name="hover_selection">False</property>
+	      <property name="hover_expand">False</property>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
+</glade-interface>
Index: data/glade/account_modification_window.glade
===================================================================
--- data/glade/account_modification_window.glade	(revision 8023)
+++ data/glade/account_modification_window.glade	(working copy)
@@ -99,7 +99,7 @@
 	    <widget class="GtkTable" id="table24">
 	      <property name="border_width">6</property>
 	      <property name="visible">True</property>
-	      <property name="n_rows">4</property>
+	      <property name="n_rows">5</property>
 	      <property name="n_columns">3</property>
 	      <property name="homogeneous">False</property>
 	      <property name="row_spacing">6</property>
@@ -379,6 +379,26 @@
 		  <property name="y_options"></property>
 		</packing>
 	      </child>
+
+	      <child>
+		<widget class="GtkButton" id="synchronise_contacts_button">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">Synchronise contacts</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		  <property name="focus_on_click">True</property>
+		  <signal name="clicked" handler="on_synchronise_contacts_button_clicked" last_modification_time="Thu, 01 Mar 2007 11:05:20 GMT"/>
+		</widget>
+		<packing>
+		  <property name="left_attach">1</property>
+		  <property name="right_attach">2</property>
+		  <property name="top_attach">4</property>
+		  <property name="bottom_attach">5</property>
+		  <property name="x_options">fill</property>
+		  <property name="y_options"></property>
+		</packing>
+	      </child>
 	    </widget>
 	    <packing>
 	      <property name="tab_expand">False</property>

_______________________________________________
Gajim-devel mailing list
Gajim-devel@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/gajim-devel

Reply via email to