Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. testing carddav:
  2.  
  3. 1) install the accounts&sso template files:
  4.  
  5. // carddav.service-type - install to /usr/share/accounts/service_types/
  6. <?xml version="1.0" encoding="UTF-8"?>
  7. <service-type id="carddav">
  8. <name>vCard Contact Synchronization</name>
  9. <description>A service of this type allows syncing of contact data.</description>
  10. <icon>image://theme/icon-m-sync</icon>
  11. <tags>
  12. <tag>sync</tag>
  13. <tag>pim</tag>
  14. <tag>contacts</tag>
  15. <tag>synchronisation</tag>
  16. <tag>synchronization</tag>
  17. </tags>
  18. </service-type>
  19.  
  20. // onlinesync.provider - install to /usr/share/accounts/providers/
  21. <?xml version="1.0" encoding="UTF-8"?>
  22. <!DOCTYPE provider>
  23. <provider version="1.0" id="onlinesync">
  24. <name>onlinesync</name>
  25. <description>CardDAV account provider</description>
  26. <icon>image://theme/icon-m-sync</icon>
  27. </provider>
  28.  
  29. // carddav.service - install to /usr/share/accounts/services/
  30. <?xml version="1.0" encoding="UTF-8"?>
  31. <service id="carddav">
  32. <type>carddav</type>
  33. <name>CardDAV Sync</name>
  34. <provider>onlinesync</provider>
  35. <icon>image://theme/icon-m-sync</icon>
  36.  
  37. <template>
  38. <setting name="sync_profile_templates" type="as">["carddav-sync"]</setting>
  39. <setting name="CardDAVServerUrl" type="s">https://dav.fruux.com</setting>
  40. <group name="auth">
  41. <setting name="method">password</setting>
  42. <setting name="mechanism">password</setting>
  43. </group>
  44. </template>
  45. </service>
  46.  
  47. 2) install the buteo-sync-plugins-carddav package
  48.  
  49. 3) create a carddav enabled account:
  50. create-online-sync-account https://dav.fruux.com/ legacy <username> <password>
  51. (see the appendix for the source code for that tool)
  52.  
  53. 4) copy the following into /home/nemo/.cache/msyncd/sync/
  54.  
  55. // carddav-sync-X.xml -- where X is the account id of your account (see via ag-tool list-accounts, after devel-su -p pkcon install libaccounts-glib-tools)
  56. <?xml version="1.0" encoding="UTF-8"?>
  57. <profile name="carddav-sync-X" type="sync">
  58. <key name="accountid" value="X"/>
  59. <key name="destinationtype" value="online"/>
  60. <key name="displayname" value="carddav-sync-X"/>
  61. <key name="enabled" value="true"/>
  62. <key name="hidden" value="true"/>
  63. <key name="scheduled" value="true"/>
  64. <key name="sync_always_up_to_date" value="true"/>
  65. <key name="sync_since_days_past" value="30"/>
  66. <key name="use_accounts" value="true"/>
  67. <profile name="carddav" type="client">
  68. <key name="Sync Direction" value="two-way"/>
  69. <key name="Sync Protocol" value="carddav"/>
  70. <key name="Sync Transport" value="HTTP"/>
  71. <key name="conflictpolicy" value="prefer remote"/>
  72. </profile>
  73. <schedule interval="720" syncconfiguredtime="" enabled="true" days="" time="">
  74. <rush interval="15" begin="" enabled="false" days="" end=""/>
  75. </schedule>
  76. </profile>
  77.  
  78. 5) trigger sync:
  79.  
  80. dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'carddav-sync-X'
  81.  
  82.  
  83. Appendix A) create-online-sync-account
  84.  
  85. // create-online-sync-account.pro
  86. TEMPLATE = app
  87. TARGET = create-online-sync-account
  88. CONFIG += link_pkgconfig
  89. PKGCONFIG += accounts-qt5 libsignon-qt5
  90.  
  91. QT += network
  92. SOURCES = main.cpp CreateOnlineSyncAccount.cpp
  93. HEADERS = CreateOnlineSyncAccount.h
  94.  
  95. // CreateOnlineSyncAccount.h
  96. #ifndef CREATEONLINESYNCACCOUNT_H
  97. #define CREATEONLINESYNCACCOUNT_H
  98.  
  99. #include <QObject>
  100.  
  101. #include <Accounts/Account>
  102. #include <Accounts/Manager>
  103. #include <Accounts/AccountService>
  104. #include <SignOn/Error>
  105. #include <SignOn/Identity>
  106. #include <SignOn/AuthSession>
  107. #include <SignOn/SessionData>
  108.  
  109. class CreateOnlineSyncAccount : public QObject
  110. {
  111. Q_OBJECT
  112.  
  113. public:
  114. CreateOnlineSyncAccount(QObject *parent = 0);
  115. ~CreateOnlineSyncAccount();
  116.  
  117. void createOnlineSyncAccount(const QString &remotePath,
  118. const QString &mode,
  119. const QString &username,
  120. const QString &password);
  121.  
  122. public Q_SLOTS:
  123. void credentialsStored(quint32 credentialsId);
  124. void credentialsFailed();
  125.  
  126. Q_SIGNALS:
  127. void done();
  128.  
  129. private:
  130. Accounts::Manager *m_accountManager;
  131. Accounts::Account *m_account;
  132. SignOn::Identity *m_identity;
  133. };
  134.  
  135. #endif
  136.  
  137. // CreateOnlineSyncAccount.cpp
  138. #include "CreateOnlineSyncAccount.h"
  139. #include <QtDebug>
  140. #include <QUrl>
  141. #include <Accounts/Service>
  142. #include <SignOn/Identity>
  143. #include <SignOn/IdentityInfo>
  144.  
  145. CreateOnlineSyncAccount::CreateOnlineSyncAccount(QObject *parent)
  146. : QObject(parent)
  147. , m_accountManager(new Accounts::Manager(this))
  148. , m_account(0)
  149. , m_identity(0)
  150. {
  151. }
  152.  
  153. CreateOnlineSyncAccount::~CreateOnlineSyncAccount()
  154. {
  155. delete m_account;
  156. delete m_identity;
  157. }
  158.  
  159. void CreateOnlineSyncAccount::createOnlineSyncAccount(const QString &remotePath,
  160. const QString &mode,
  161. const QString &username,
  162. const QString &password)
  163. {
  164. Q_UNUSED(mode) // until we take tokenpaths/redirecturis etc as parameters also...
  165.  
  166. m_account = m_accountManager->createAccount("onlinesync");
  167. if (!m_account) {
  168. qWarning() << "error: couldn't create onlinesync account";
  169. emit done();
  170. }
  171.  
  172. Accounts::Service srv = m_accountManager->service("carddav"); // hardcoded for now.
  173. if (!srv.isValid()) {
  174. qWarning() << "error: couldn't retrieve carddav service";
  175. emit done();
  176. }
  177.  
  178. m_account->setDisplayName("carddav account");
  179. m_account->selectService(srv);
  180. m_account->setValue("CardDAVServerUrl", remotePath);
  181. m_account->setValue("auth/method", "password");
  182. m_account->setValue("auth/mechanism", "password");
  183. m_account->setEnabled(true);
  184. m_account->selectService(Accounts::Service());
  185. m_account->setEnabled(false); // disable globally until credentials are set.
  186.  
  187. m_account->syncAndBlock();
  188.  
  189. QMap<QString, QStringList> methodMechs;
  190. methodMechs.insert("password", QStringList() << "password");
  191. SignOn::IdentityInfo *info = new SignOn::IdentityInfo(m_account->displayName(), username, methodMechs);
  192. info->setSecret(password, true);
  193. QUrl url(remotePath);
  194. info->setRealms(QStringList() << url.host());
  195. info->setType(SignOn::IdentityInfo::Application);
  196.  
  197. m_identity = SignOn::Identity::newIdentity(*info);
  198. connect(m_identity, SIGNAL(error(const SignOn::Error &)),
  199. this, SLOT(credentialsFailed()));
  200. connect(m_identity, SIGNAL(credentialsStored(const quint32)),
  201. this, SLOT(credentialsStored(quint32)));
  202.  
  203. m_identity->storeCredentials();
  204. }
  205.  
  206. void CreateOnlineSyncAccount::credentialsFailed()
  207. {
  208. qWarning() << "error: failed to store credentials";
  209. emit done();
  210. }
  211.  
  212. void CreateOnlineSyncAccount::credentialsStored(quint32 credId)
  213. {
  214. Accounts::Service srv = m_accountManager->service("carddav"); // hardcoded for now.
  215. m_account->selectService(srv);
  216. m_account->setCredentialsId(credId);
  217. m_account->setEnabled(true);
  218. m_account->selectService(Accounts::Service());
  219. m_account->setCredentialsId(credId);
  220. m_account->setEnabled(true);
  221. m_account->syncAndBlock();
  222.  
  223. qWarning() << "success!";
  224. emit done();
  225. }
  226.  
  227.  
  228. // main.cpp
  229. #include <QCoreApplication>
  230. #include <QObject>
  231. #include <QtDebug>
  232. #include "CreateOnlineSyncAccount.h"
  233.  
  234. int main(int argc, char *argv[])
  235. {
  236. QCoreApplication app(argc, argv);
  237. CreateOnlineSyncAccount c;
  238. QString remotePath, mode, username, password;
  239.  
  240. if (argc != 3 && argc != 5) {
  241. qWarning() << "usage: create-online-sync-account <remotePath> <oauth2|legacy[ <username> <password>]>";
  242. qWarning() << " e.g.: create-online-sync-account https://dav.fruux.com legacy b1234567 p1234567";
  243. return 1;
  244. }
  245.  
  246. remotePath = QString::fromLatin1(argv[1]);
  247. mode = QString::fromLatin1(argv[2]);
  248. if (argc == 5) username = QString::fromLatin1(argv[3]);
  249. if (argc == 5) password = QString::fromLatin1(argv[4]);
  250.  
  251. if (mode != QStringLiteral("legacy")) {
  252. // actually we don't support oauth2 yet
  253. // to support that, we would also need as parameters:
  254. // auth path / token path / redirect uri / scopes etc.
  255. qWarning() << "oauth2 not currently supported";
  256. return 1;
  257. }
  258.  
  259. QObject::connect(&c, SIGNAL(done()), &app, SLOT(quit()));
  260. c.createOnlineSyncAccount(remotePath, mode, username, password);
  261. return app.exec();
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement