Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- testing carddav:
- 1) install the accounts&sso template files:
- // carddav.service-type - install to /usr/share/accounts/service_types/
- <?xml version="1.0" encoding="UTF-8"?>
- <service-type id="carddav">
- <name>vCard Contact Synchronization</name>
- <description>A service of this type allows syncing of contact data.</description>
- <icon>image://theme/icon-m-sync</icon>
- <tags>
- <tag>sync</tag>
- <tag>pim</tag>
- <tag>contacts</tag>
- <tag>synchronisation</tag>
- <tag>synchronization</tag>
- </tags>
- </service-type>
- // onlinesync.provider - install to /usr/share/accounts/providers/
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE provider>
- <provider version="1.0" id="onlinesync">
- <name>onlinesync</name>
- <description>CardDAV account provider</description>
- <icon>image://theme/icon-m-sync</icon>
- </provider>
- // carddav.service - install to /usr/share/accounts/services/
- <?xml version="1.0" encoding="UTF-8"?>
- <service id="carddav">
- <type>carddav</type>
- <name>CardDAV Sync</name>
- <provider>onlinesync</provider>
- <icon>image://theme/icon-m-sync</icon>
- <template>
- <setting name="sync_profile_templates" type="as">["carddav-sync"]</setting>
- <setting name="CardDAVServerUrl" type="s">https://dav.fruux.com</setting>
- <group name="auth">
- <setting name="method">password</setting>
- <setting name="mechanism">password</setting>
- </group>
- </template>
- </service>
- 2) install the buteo-sync-plugins-carddav package
- 3) create a carddav enabled account:
- create-online-sync-account https://dav.fruux.com/ legacy <username> <password>
- (see the appendix for the source code for that tool)
- 4) copy the following into /home/nemo/.cache/msyncd/sync/
- // 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)
- <?xml version="1.0" encoding="UTF-8"?>
- <profile name="carddav-sync-X" type="sync">
- <key name="accountid" value="X"/>
- <key name="destinationtype" value="online"/>
- <key name="displayname" value="carddav-sync-X"/>
- <key name="enabled" value="true"/>
- <key name="hidden" value="true"/>
- <key name="scheduled" value="true"/>
- <key name="sync_always_up_to_date" value="true"/>
- <key name="sync_since_days_past" value="30"/>
- <key name="use_accounts" value="true"/>
- <profile name="carddav" type="client">
- <key name="Sync Direction" value="two-way"/>
- <key name="Sync Protocol" value="carddav"/>
- <key name="Sync Transport" value="HTTP"/>
- <key name="conflictpolicy" value="prefer remote"/>
- </profile>
- <schedule interval="720" syncconfiguredtime="" enabled="true" days="" time="">
- <rush interval="15" begin="" enabled="false" days="" end=""/>
- </schedule>
- </profile>
- 5) trigger sync:
- dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'carddav-sync-X'
- Appendix A) create-online-sync-account
- // create-online-sync-account.pro
- TEMPLATE = app
- TARGET = create-online-sync-account
- CONFIG += link_pkgconfig
- PKGCONFIG += accounts-qt5 libsignon-qt5
- QT += network
- SOURCES = main.cpp CreateOnlineSyncAccount.cpp
- HEADERS = CreateOnlineSyncAccount.h
- // CreateOnlineSyncAccount.h
- #ifndef CREATEONLINESYNCACCOUNT_H
- #define CREATEONLINESYNCACCOUNT_H
- #include <QObject>
- #include <Accounts/Account>
- #include <Accounts/Manager>
- #include <Accounts/AccountService>
- #include <SignOn/Error>
- #include <SignOn/Identity>
- #include <SignOn/AuthSession>
- #include <SignOn/SessionData>
- class CreateOnlineSyncAccount : public QObject
- {
- Q_OBJECT
- public:
- CreateOnlineSyncAccount(QObject *parent = 0);
- ~CreateOnlineSyncAccount();
- void createOnlineSyncAccount(const QString &remotePath,
- const QString &mode,
- const QString &username,
- const QString &password);
- public Q_SLOTS:
- void credentialsStored(quint32 credentialsId);
- void credentialsFailed();
- Q_SIGNALS:
- void done();
- private:
- Accounts::Manager *m_accountManager;
- Accounts::Account *m_account;
- SignOn::Identity *m_identity;
- };
- #endif
- // CreateOnlineSyncAccount.cpp
- #include "CreateOnlineSyncAccount.h"
- #include <QtDebug>
- #include <QUrl>
- #include <Accounts/Service>
- #include <SignOn/Identity>
- #include <SignOn/IdentityInfo>
- CreateOnlineSyncAccount::CreateOnlineSyncAccount(QObject *parent)
- : QObject(parent)
- , m_accountManager(new Accounts::Manager(this))
- , m_account(0)
- , m_identity(0)
- {
- }
- CreateOnlineSyncAccount::~CreateOnlineSyncAccount()
- {
- delete m_account;
- delete m_identity;
- }
- void CreateOnlineSyncAccount::createOnlineSyncAccount(const QString &remotePath,
- const QString &mode,
- const QString &username,
- const QString &password)
- {
- Q_UNUSED(mode) // until we take tokenpaths/redirecturis etc as parameters also...
- m_account = m_accountManager->createAccount("onlinesync");
- if (!m_account) {
- qWarning() << "error: couldn't create onlinesync account";
- emit done();
- }
- Accounts::Service srv = m_accountManager->service("carddav"); // hardcoded for now.
- if (!srv.isValid()) {
- qWarning() << "error: couldn't retrieve carddav service";
- emit done();
- }
- m_account->setDisplayName("carddav account");
- m_account->selectService(srv);
- m_account->setValue("CardDAVServerUrl", remotePath);
- m_account->setValue("auth/method", "password");
- m_account->setValue("auth/mechanism", "password");
- m_account->setEnabled(true);
- m_account->selectService(Accounts::Service());
- m_account->setEnabled(false); // disable globally until credentials are set.
- m_account->syncAndBlock();
- QMap<QString, QStringList> methodMechs;
- methodMechs.insert("password", QStringList() << "password");
- SignOn::IdentityInfo *info = new SignOn::IdentityInfo(m_account->displayName(), username, methodMechs);
- info->setSecret(password, true);
- QUrl url(remotePath);
- info->setRealms(QStringList() << url.host());
- info->setType(SignOn::IdentityInfo::Application);
- m_identity = SignOn::Identity::newIdentity(*info);
- connect(m_identity, SIGNAL(error(const SignOn::Error &)),
- this, SLOT(credentialsFailed()));
- connect(m_identity, SIGNAL(credentialsStored(const quint32)),
- this, SLOT(credentialsStored(quint32)));
- m_identity->storeCredentials();
- }
- void CreateOnlineSyncAccount::credentialsFailed()
- {
- qWarning() << "error: failed to store credentials";
- emit done();
- }
- void CreateOnlineSyncAccount::credentialsStored(quint32 credId)
- {
- Accounts::Service srv = m_accountManager->service("carddav"); // hardcoded for now.
- m_account->selectService(srv);
- m_account->setCredentialsId(credId);
- m_account->setEnabled(true);
- m_account->selectService(Accounts::Service());
- m_account->setCredentialsId(credId);
- m_account->setEnabled(true);
- m_account->syncAndBlock();
- qWarning() << "success!";
- emit done();
- }
- // main.cpp
- #include <QCoreApplication>
- #include <QObject>
- #include <QtDebug>
- #include "CreateOnlineSyncAccount.h"
- int main(int argc, char *argv[])
- {
- QCoreApplication app(argc, argv);
- CreateOnlineSyncAccount c;
- QString remotePath, mode, username, password;
- if (argc != 3 && argc != 5) {
- qWarning() << "usage: create-online-sync-account <remotePath> <oauth2|legacy[ <username> <password>]>";
- qWarning() << " e.g.: create-online-sync-account https://dav.fruux.com legacy b1234567 p1234567";
- return 1;
- }
- remotePath = QString::fromLatin1(argv[1]);
- mode = QString::fromLatin1(argv[2]);
- if (argc == 5) username = QString::fromLatin1(argv[3]);
- if (argc == 5) password = QString::fromLatin1(argv[4]);
- if (mode != QStringLiteral("legacy")) {
- // actually we don't support oauth2 yet
- // to support that, we would also need as parameters:
- // auth path / token path / redirect uri / scopes etc.
- qWarning() << "oauth2 not currently supported";
- return 1;
- }
- QObject::connect(&c, SIGNAL(done()), &app, SLOT(quit()));
- c.createOnlineSyncAccount(remotePath, mode, username, password);
- return app.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement