[Gajim-devel] synchronize contacts from another account.

Anthony Lannuzel lannuzel at gmail.com
Tue Mar 13 13:43:04 CET 2007


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
-------------- next part --------------
Here are the modifications I made to the gajim sources :

changed :
data/glade/account_modification_window.glade
src/config.py
src/dialogs.py

added :
data/glade/synchronise_contacts_dialog.glade

contact :
nich2chien at jabber.ubuntu-fr.org
lannuzel at gmail.com
===================================================================
diff on data/glade/account_modification_window.glade :
102c102
<             <property name="n_rows">4</property>
---
>             <property name="n_rows">5</property>
381a382,401
> 
>             <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>
===================================================================
diff on src/config.py :
1589a1590,1598
>       #nich2chien add
>       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
> 
> 
===================================================================
diff on src/dialogs.py :
1324a1325,1411
> #nich2chien add
> 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 can not 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.window.show_all()
>               self.dialog.show_all()
> 
>       def run(self):
>               return message
> 
>       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:
>                       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')
> 
>               local_account = self.account
>               print local_account,
>               print ' syncing with contacts from ',
>               print remote_account
> 
>               #recover local contacts
>               local_jid_list = gajim.contacts.get_jid_list(local_account)
> 
>               #recover remote contacts
>               #old version : we connect the account
>               #but the problem is : we have to wait for the connections to establish
>               #gajim.interface.roster.send_status(remote_account, 'online', 'whatisthis?')
>               if gajim.connections[remote_account].connected < 2:
>                       ErrorDialog(_('This account is not connected to the server'),
>                               _('You can synchronize with an account unless you are connected to it.'))
>                       raise GajimGeneralException, 'You must be connected to both accounts to synchronize them.'
>               else:
>                       remote_jid_list = gajim.contacts.get_jid_list(remote_account)
>                       for remote_jid in remote_jid_list:
>                               already_exists = False
>                               for local_jid in local_jid_list:
>                                       if local_jid == remote_jid:
>                                               already_exists = True
>                               if not already_exists:
>                                       print 'we have to copy',
>                                       print remote_jid
>                                       #if remote_jid == 'nich2chien at jabber.ubuntu-fr.org':
>                                       message='I\'m synchronizing my contacts from my '+remote_account+' account, could you please add this address to your contacts?'
>                                       gajim.interface.roster.req_sub(self, remote_jid, message, local_account,
>                               groups = [''], nickname = '', auto_auth = True)
>                                       print 'req_sub sent to '+remote_jid
>               self.dialog.destroy()
> 
> 
===================================================================
added file : data/glade/synchronise_contacts_dialog.glade :

<?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">150</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="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_ALWAYS</property>
	  <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
	  <property name="shadow_type">GTK_SHADOW_NONE</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>

      <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>
    </widget>
  </child>
</widget>

</glade-interface>


More information about the Gajim-devel mailing list