The Mer Wiki now uses your Mer user account and password (create account on https://bugs.merproject.org/)
Buteo/FWClient Example
(Created page with "== Synchronization Framework Client == For reference headers, please see [http://meego.gitorious.org/meego-middleware/buteo-syncfw/blobs/master/libsyncfwclient/SyncClientInterf…") |
|||
Line 2: | Line 2: | ||
− | For reference headers, please see [ | + | For reference headers, please see [https://github.com/nemomobile/buteo-syncfw/blob/master/libsyncfwclient/SyncClientInterface.h SyncClientInterface.h] and [https://github.com/nemomobile/buteo-syncfw/blob/master/libsyncprofile/Profile.h Profile.h] |
Create a new SyncClientInterface: | Create a new SyncClientInterface: | ||
Line 17: | Line 17: | ||
To load a profile one approach is to use a premade XML-file containing the settings: | To load a profile one approach is to use a premade XML-file containing the settings: | ||
− | QString file = "testsync- | + | QString file = "testsync-memotoo.xml"; |
− | QString profile = " | + | QString profile = "memotoo"; |
QDomElement root = loadProfileFromXML(file); | QDomElement root = loadProfileFromXML(file); | ||
Line 58: | Line 58: | ||
== Slots == | == Slots == | ||
− | For up to date information regarding the meaning of different status code, see [ | + | For up to date information regarding the meaning of different status code, see [https://github.com/nemomobile/buteo-syncfw/blob/master/libsyncfwclient/SyncClientInterface.h SyncClientInterface.h SyncClientInterface.h]. |
void SyncHandler::slotSyncStatus(QString aProfileId, int aStatus, QString aMessage, int aErrorCode) | void SyncHandler::slotSyncStatus(QString aProfileId, int aStatus, QString aMessage, int aErrorCode) | ||
Line 98: | Line 98: | ||
− | == Sample XML files for | + | == Sample XML files for MemoToo == |
− | + | memotoo.com.xml (goes to /etc/sync/profiles/service/): | |
− | + | <?xml version="1.0" encoding="UTF-8"?> | |
− | + | <profile name="memotoo.com" type="service"> | |
− | + | <key name="Remote database" value="http://sync.memotoo.com/syncml" /> | |
− | + | ||
− | <key name=" | + | <key name="Username" value="" /> |
− | <key name=" | + | <key name="Password" 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="contact" /> | ||
+ | </profile> | ||
+ | |||
+ | <profile name="hcalendar" type="storage" > | ||
+ | <key name="Local URI" value="./calendar" /> | ||
+ | <key name="Target URI" value="caltask" /> | ||
+ | <key name="Calendar Format" value="vcalendar" /> | ||
+ | </profile> | ||
+ | |||
+ | <profile name="hnotes" type="storage" > | ||
+ | <key name="Local URI" value="./Notepad" /> | ||
+ | <key name="Target URI" value="note" /> | ||
+ | |||
+ | </profile> | ||
+ | </profile> | ||
+ | |||
+ | memotoo.xml (goes to /etc/sync/profiles/sync/): | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | |||
+ | <profile name="memotoo.com" type="sync" > | ||
+ | <key name="Remote database" value="http://sync.memotoo.com/syncml" /> | ||
+ | |||
+ | <key name="Username" value="" /> | ||
+ | <key name="Password" value="" /> | ||
<key name="destinationtype" value="online"/> | <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" > | <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> | ||
+ | |||
<profile name="hcontacts" type="storage" > | <profile name="hcontacts" type="storage" > | ||
− | + | <key name="enabled" value="true" /> | |
− | + | <key name="Local URI" value="./contacts" /> | |
+ | <key name="Target URI" value="contact" /> | ||
</profile> | </profile> | ||
− | |||
− | + | <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> | </profile> | ||
− | <profile name=" | + | |
+ | <profile name="hnotes" type="storage" > | ||
<key name="enabled" value="true" /> | <key name="enabled" value="true" /> | ||
+ | <key name="Local URI" value="./Notepad" /> | ||
+ | <key name="Target URI" value="note" /> | ||
</profile> | </profile> | ||
− | + | </profile> | |
[[Category:Buteo]] | [[Category:Buteo]] |
Revision as of 17:36, 8 April 2013
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); 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 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.com.xml (goes to /etc/sync/profiles/service/): <?xml version="1.0" encoding="UTF-8"?> <profile name="memotoo.com" type="service">
<key name="Remote database" value="http://sync.memotoo.com/syncml" />
<key name="Username" value="" /> <key name="Password" 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="contact" /> </profile>
<profile name="hcalendar" type="storage" > <key name="Local URI" value="./calendar" /> <key name="Target URI" value="caltask" /> <key name="Calendar Format" value="vcalendar" /> </profile>
<profile name="hnotes" type="storage" > <key name="Local URI" value="./Notepad" /> <key name="Target URI" value="note" />
</profile>
</profile>
memotoo.xml (goes to /etc/sync/profiles/sync/): <?xml version="1.0" encoding="UTF-8"?>
<profile name="memotoo.com" type="sync" >
<key name="Remote database" value="http://sync.memotoo.com/syncml" />
<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>
<profile name="hcontacts" type="storage" > <key name="enabled" value="true" /> <key name="Local URI" value="./contacts" /> <key name="Target URI" value="contact" /> </profile>
<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>
<profile name="hnotes" type="storage" > <key name="enabled" value="true" /> <key name="Local URI" value="./Notepad" /> <key name="Target URI" value="note" /> </profile>
</profile>