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…") |
m (updated github link) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
− | For reference headers, please see [ | + | For reference headers, please see [https://github.com/nemomobile/buteo-syncfw/blob/master/libbuteosyncfw/clientfw/SyncClientInterface.h SyncClientInterface.h] and [https://github.com/nemomobile/buteo-syncfw/blob/master/libbuteosyncfw/profile/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 53: | Line 53: | ||
qDebug() << "Running" << i << ":" << lst.at(i); | qDebug() << "Running" << i << ":" << lst.at(i); | ||
} | } | ||
− | |||
− | |||
== 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/libbuteosyncfw/clientfw/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 97: | Line 95: | ||
} | } | ||
+ | == Sample XML files for MemoToo == | ||
+ | '''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="Remote database" value="http://sync. | + | |
− | + | ||
− | <key name=" | + | |
− | <key name=" | + | |
− | + | ||
<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> | |
+ | |||
+ | |||
+ | == 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:'memotoo.com' | ||
+ | |||
+ | 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''' | ||
[[Category:Buteo]] | [[Category:Buteo]] | ||
+ | |||
+ | --[[User:Kavuri|Kavuri]] 17:53, 8 April 2013 (UTC) |
Latest revision as of 02:26, 10 January 2014
Contents |
[edit] 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); }
[edit] 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; }
[edit] Sample XML files for MemoToo
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>
[edit] 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:'memotoo.com'
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)