Skip to content

Commit

Permalink
[sociald] Add VK contacts sync adaptor. Contributes to JB#19272
Browse files Browse the repository at this point in the history
This commit adds (one-way) contacts sync adaptor for VKontakte.

Contributes to JB#19272
  • Loading branch information
Chris Adams authored and Antti Seppälä committed Oct 12, 2015
1 parent 87b907f commit 83cd9f2
Show file tree
Hide file tree
Showing 13 changed files with 1,351 additions and 1 deletion.
26 changes: 26 additions & 0 deletions rpm/sociald.spec
Expand Up @@ -529,6 +529,32 @@ rm -f /home/nemo/.cache/msyncd/sync/vk.Calendars.xml
systemctl-user restart msyncd.service || :


%package vk-contacts
Summary: Provides contact synchronisation with VK
License: TBD
Group: System/Libraries
BuildRequires: pkgconfig(Qt5Contacts)
BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions)
Requires: %{name} = %{version}-%{release}

%description vk-contacts
Provides contact synchronisation with VK

%files vk-contacts
#out-of-process-plugin form:
/usr/lib/buteo-plugins-qt5/oopp/vk-contacts-client
#in-process-plugin form:
#/usr/lib/buteo-plugins-qt5/libvk-contacts-client.so
%config %{_sysconfdir}/buteo/profiles/client/vk-contacts.xml
%config %{_sysconfdir}/buteo/profiles/sync/vk.Contacts.xml

%pre vk-contacts
rm -f /home/nemo/.cache/msyncd/sync/client/vk-contacts.xml
rm -f /home/nemo/.cache/msyncd/sync/vk.Contacts.xml

%post vk-contacts
systemctl-user restart msyncd.service || :


%package ts-devel
Summary: Translation source for sociald
Expand Down
1 change: 1 addition & 0 deletions src/sociald/socialdplugin.cpp
Expand Up @@ -102,6 +102,7 @@ bool SocialdPlugin::startSync()
startSyncParams << "vk.Posts";
startSyncParams << "vk.Notifications";
startSyncParams << "vk.Calendars";
startSyncParams << "vk.Contacts";
}

foreach (const QString &param, startSyncParams) {
Expand Down
7 changes: 7 additions & 0 deletions src/vk/vk-contacts/vk-contacts.pri
@@ -0,0 +1,7 @@
CONFIG += link_pkgconfig
PKGCONFIG += Qt5Contacts qtcontacts-sqlite-qt5-extensions
QT += contacts-private
SOURCES += $$PWD/vkcontactsyncadaptor.cpp $$PWD/vkcontactimagedownloader.cpp
HEADERS += $$PWD/vkcontactsyncadaptor.h $$PWD/vkcontactimagedownloader.h
INCLUDEPATH += $$PWD

26 changes: 26 additions & 0 deletions src/vk/vk-contacts/vk-contacts.pro
@@ -0,0 +1,26 @@
TARGET = vk-contacts-client
VERSION = 0.0.1

DEFINES += "CLASSNAME=VKContactsPlugin"
DEFINES += CLASSNAME_H=\\\"vkcontactsplugin.h\\\"
DEFINES += SOCIALD_USE_QTPIM
include($$PWD/../../common.pri)
include($$PWD/../vk-common.pri)
include($$PWD/vk-contacts.pri)

vk_contacts_sync_profile.path = /etc/buteo/profiles/sync
vk_contacts_sync_profile.files = $$PWD/vk.Contacts.xml
vk_contacts_client_plugin_xml.path = /etc/buteo/profiles/client
vk_contacts_client_plugin_xml.files = $$PWD/vk-contacts.xml

HEADERS += vkcontactsplugin.h
SOURCES += vkcontactsplugin.cpp

OTHER_FILES += \
vk.Contacts.xml \
vk-contacts.xml

INSTALLS += \
target \
vk_contacts_sync_profile \
vk_contacts_client_plugin_xml
4 changes: 4 additions & 0 deletions src/vk/vk-contacts/vk-contacts.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile name="vk-contacts" type="client" >
<field name="Sync Direction" />
</profile>
15 changes: 15 additions & 0 deletions src/vk/vk-contacts/vk.Contacts.xml
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile name="vk.Contacts" type="sync" >
<key name="category" value="vk.Contacts" />
<key name="enabled" value="false" />
<key name="use_accounts" value="false" />
<key name="destinationtype" value="online" />
<key name="hidden" value="true" />
<key name="displayname" value="VK Contacts"/>

<schedule enabled="false" interval="" days="1,2,3,4,5,6,7" syncconfiguredtime="" time="05:00:00" />

<profile name="vk-contacts" type="client" >
<key name="Sync Direction" value="from-remote" />
</profile>
</profile>
48 changes: 48 additions & 0 deletions src/vk/vk-contacts/vkcontactimagedownloader.cpp
@@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
**
****************************************************************************/

#include "vkcontactimagedownloader.h"

#include <QUrl>
#include <QUrlQuery>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>

static const char *IMAGE_DOWNLOADER_TOKEN_KEY = "token";
static const char *IMAGE_DOWNLOADER_IDENTIFIER_KEY = "identifier";

VKContactImageDownloader::VKContactImageDownloader()
: AbstractImageDownloader()
{
}

QString VKContactImageDownloader::staticOutputFile(const QString &identifier, const QUrl &url)
{
return makeOutputFile(SocialSyncInterface::VK, SocialSyncInterface::Contacts, identifier, url.toString());
}

QNetworkReply * VKContactImageDownloader::createReply(const QString &url,
const QVariantMap &metadata)
{
Q_D(AbstractImageDownloader);

// XXX TODO: this might not be needed.
QString accessToken = metadata.value(IMAGE_DOWNLOADER_TOKEN_KEY).toString();
QUrl requestUrl(url);
QUrlQuery urlQuery;
urlQuery.addQueryItem("access_token", accessToken);
requestUrl.setQuery(urlQuery);

QNetworkRequest request(requestUrl);
return d->networkAccessManager->get(request);
}

QString VKContactImageDownloader::outputFile(const QString &url, const QVariantMap &data) const
{
return staticOutputFile(data.value(IMAGE_DOWNLOADER_IDENTIFIER_KEY).toString(), url);
}
35 changes: 35 additions & 0 deletions src/vk/vk-contacts/vkcontactimagedownloader.h
@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
**
****************************************************************************/

#ifndef VKCONTACTIMAGEDOWNLOADER_H
#define VKCONTACTIMAGEDOWNLOADER_H

#include <socialcache/abstractimagedownloader.h>
#include <socialcache/abstractimagedownloader_p.h>

#include <QObject>
#include <QString>
#include <QVariantMap>
#include <QUrl>

class QNetworkReply;
class VKContactImageDownloader: public AbstractImageDownloader
{
Q_OBJECT

public:
explicit VKContactImageDownloader();
static QString staticOutputFile(const QString &identifier, const QUrl &url);
protected:
QNetworkReply * createReply(const QString &url, const QVariantMap &metadata);
// This is a reimplemented method, used by AbstractImageDownloader
QString outputFile(const QString &url, const QVariantMap &data) const;
private:
Q_DECLARE_PRIVATE(AbstractImageDownloader)
};

#endif // VKCONTACTIMAGEDOWNLOADER_H
44 changes: 44 additions & 0 deletions src/vk/vk-contacts/vkcontactsplugin.cpp
@@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jolla.com>
**
****************************************************************************/

#include "constants_p.h"
#include <qtcontacts-extensions_impl.h>
#include <qcontactoriginmetadata_impl.h>

#include "vkcontactsplugin.h"
#include "vkcontactsyncadaptor.h"
#include "socialnetworksyncadaptor.h"

extern "C" VKContactsPlugin* createPlugin(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *callbackInterface)
{
return new VKContactsPlugin(pluginName, profile, callbackInterface);
}

extern "C" void destroyPlugin(VKContactsPlugin* plugin)
{
delete plugin;
}

VKContactsPlugin::VKContactsPlugin(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *callbackInterface)
: SocialdButeoPlugin(pluginName, profile, callbackInterface,
QStringLiteral("vk"),
SocialNetworkSyncAdaptor::dataTypeName(SocialNetworkSyncAdaptor::Contacts))
{
}

VKContactsPlugin::~VKContactsPlugin()
{
}

SocialNetworkSyncAdaptor *VKContactsPlugin::createSocialNetworkSyncAdaptor()
{
return new VKContactSyncAdaptor(this);
}
33 changes: 33 additions & 0 deletions src/vk/vk-contacts/vkcontactsplugin.h
@@ -0,0 +1,33 @@
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jolla.com>
**
****************************************************************************/

#ifndef VKCONTACTSPLUGIN_H
#define VKCONTACTSPLUGIN_H

#include "socialdbuteoplugin.h"

class VKContactsPlugin : public SocialdButeoPlugin
{
Q_OBJECT

public:
VKContactsPlugin(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *cbInterface);
~VKContactsPlugin();

protected:
SocialNetworkSyncAdaptor *createSocialNetworkSyncAdaptor();
};

extern "C" VKContactsPlugin* createPlugin(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *cbInterface);

extern "C" void destroyPlugin(VKContactsPlugin* client);

#endif // VKCONTACTSPLUGIN_H

0 comments on commit 83cd9f2

Please sign in to comment.