The Mer Wiki now uses your Mer user account and password (create account on

Buteo/FWClient Example

From Mer Wiki
Jump to: navigation, search


Synchronization Framework Client

For reference headers, please see SyncClientInterface.h and Profile.h

Create a new SyncClientInterface:

   sci = new SyncClientInterface();

Connect relevant signals (notification about sync progress and completion):

   connect(sci, SIGNAL(syncStatus(QString,int,QString,int)), this, SLOT(slotSyncStatus(QString,int,QString,int)));
   connect(sci, SIGNAL(profileChanged(QString,int,Buteo::SyncProfile)), this, SLOT(profileChanged(QString,int,Buteo::SyncProfile)));
   connect(sci, SIGNAL(resultsAvailable(QString,Buteo::SyncResults)), this, SLOT(resultsAvailable(QString,Buteo::SyncResults)));
   connect(sci, SIGNAL(transferProgress(QString,int,int,QString)), this, SLOT(slotTransferProgress(QString,int,int,QString)));

To load a profile one approach is to use a premade XML-file containing the settings:

   QString file = "testsync-memotoo.xml";
   QString profile = "memotoo";
   QDomElement root = loadProfileFromXML(file);

Where loadProfileFromXML is implemented as:

   QDomDocument doc("profile");
   QFile file(fileName);
   QDomElement root = doc.documentElement();
   return root;

Create a SyncProfile (which can then be modified to update settings etc):

   SyncProfile syncProfile(root);

Note that this is not the recommended approach. Clients should ask the framework for profiles that were added to the framework. TODO: add example for that part of the API.

Change a setting for the profile:

   syncProfile.setKey("Username", “myusername”);
   syncProfile.setKey("Password", “mypassword”);

Add the profile, and start the sync:


To get a list of the running syncs:

   QStringList lst = sci->getRunningSyncList();
   qDebug() << "Running syncs:" << lst.length();
   for(int i = 0; i < lst.length(); i++) {
       qDebug() << "Running" << i << ":" <<;


For up to date information regarding the meaning of different status code, see SyncClientInterface.h.

 void SyncHandler::slotSyncStatus(QString aProfileId, int aStatus, QString aMessage, int aErrorCode)
   QString stat = "";
   if (aStatus == 0) {
       stat = "QUEUED";
   } else if (aStatus == 1) {
       stat = "RUNNING";
   } else if (aStatus == 2) {
       stat = "PROGRESSING";
   } else if (aStatus == 3) {
       stat = "ERROR";
       emit syncDone(-3);
   } else if (aStatus == 4) {
       stat = "DONE";
   } else if (aStatus == 5) {
       stat = "ABORTED";
   qDebug() << "STATUS CHANGE:" << aProfileId << stat << aMessage << aErrorCode;
 void SyncHandler::profileChanged(QString aProfileId, int aChangeType, Buteo::SyncProfile aProfile)
   qDebug() << "Profile changed:" << aProfileId << aChangeType;
 void SyncHandler::resultsAvailable(QString aProfileId, Buteo::SyncResults aResults)
   qDebug() << "Results available" << aProfileId << aResults.resultCode();
   if (aResults.resultCode() == Buteo::SyncResults::SYNC_RESULT_SUCCESS) {
       // Do something nice when we succeed
   } else if (aResults.resultCode() == Buteo::SyncResults::SYNC_RESULT_FAILED) {
       // Do something nice when there is a failure
 void SyncHandler::slotTransferProgress(QString aProfileId, int aTransferDatabase, int aTransferType, QString aMimeType)
   qDebug() << "Progress:" << aProfileId << aTransferDatabase << aTransferType << aMimeType;

Sample XML files for MemoToo

memotoo.xml (goes to /etc/sync/profiles/sync/)

<?xml version="1.0" encoding="UTF-8"?>
<profile name="" type="sync" >
   <key name="Remote database" value="" />
   <key name="Username" value="" />
   <key name="Password" value="" />
   <key name="destinationtype" value="online"/>
   <key name="displayname" value="Memotoo"/>
   <key name="enabled" value="true" />
   <key name="use_accounts" value="false" />
   <key name="hidden" value="true" />
   <profile name="syncml" type="client" >
       <key name="use_wbxml" value="false" />
       <key name="Sync Transport" value="HTTP" />
       <key name="Sync Direction" value="two-way" />
       <key name="Sync Protocol" value="SyncML12" />
   <profile name="hcontacts" type="storage" >
       <key name="enabled" value="true" />
       <key name="Local URI" value="./contacts" />
       <key name="Target URI" value="contact" />
   <profile name="hcalendar" type="storage" >
       <key name="enabled" value="true" />
       <key name="Notebook Name" value="Personal"/>
       <key name="Local URI" value="./calendar" />
       <key name="Target URI" value="caltask" />
       <key name="Calendar Format" value="vcalendar" />
   <profile name="hnotes" type="storage" >
       <key name="enabled" value="true" />
       <key name="Local URI" value="./Notepad" />
       <key name="Target URI" value="note" />

Starting sync from command-line

Sync can be started from command-line using dbus-send. The command:

dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:''

If you are running this from SB2 environment, export the DBUS_SESSION_BUS_ADDRESS (the value of which can be obtained by running the command dbus-launch)

To enable logging, set the log level to 4 in /etc/buteo/set_sync_log_level file. Restart msyncd. The log file would be generated as ~/.cache/msyncd/synchronizer.log

--Kavuri 17:53, 8 April 2013 (UTC)

Personal tools