The Mer Wiki now uses your Mer user account and password (create account on https://bugs.merproject.org/)


Buteo/FWClient Example

From Mer Wiki
< Buteo
Revision as of 17:14, 8 April 2013 by Kavuri (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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-scheduleworld.xml";
   QString profile = "scheduleworld";
   QDomElement root = loadProfileFromXML(file);

Where loadProfileFromXML is implemented as:

   QDomDocument doc("profile");
   QFile file(fileName);
   doc.setContent(&file);
   file.close();
   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:

   sci->addProfile(syncProfile);
   sci->startSync(profile);

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 << ":" << lst.at(i);
   }


Slots

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 Scheduleworld

scheduleworld.com.xml (goes to /etc/sync/profiles/service/):

 <?xml version="1.0" encoding="UTF-8"?>
 <profile  name="scheduleworld" type="service">
   <key name="Remote database" value="http://sync.scheduleworld.com/funambol/ds" />
      
   <key name="http_proxy_host" value="" />
   <key name="http_proxy_port" value="" />
   
   <key name="destinationtype" value="online"/>
   
   <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>
   <profile name="hcontacts" type="storage" >
     <key name="Local URI" value="./contacts" />
     <key name="Target URI" value="./card" />
   </profile>
 </profile>

scheduleworld.xml (goes to /etc/sync/profiles/sync/):

 <?xml version="1.0" encoding="UTF-8"?>
 <profile name="scheduleworld" type="sync" >
   <key name="displayname" value="scheduleworld" />
   <key name="enabled" value="true" />
   <key name="use_accounts" value="false" />
   <key name="hidden" value="false" />
   <profile type="service" name="scheduleworld.com" >
   </profile>
   <profile name="hcontacts" type="storage" >
       <key name="enabled" value="true" />
   </profile>
 </profile>
Personal tools