Skip to content

Commit

Permalink
[sociald] Remove usages of Sailfish.Accounts. Contributes to JB#19333
Browse files Browse the repository at this point in the history
Before we can open-source sociald, we must remove any usages of closed
source libraries.  This commit removes usages of Sailfish.Accounts in
favour of the base libaccounts-qt5 library.

Contributes to JB#19333
  • Loading branch information
Chris Adams committed Jun 10, 2014
1 parent dcb8c6d commit f44b283
Show file tree
Hide file tree
Showing 16 changed files with 544 additions and 386 deletions.
2 changes: 1 addition & 1 deletion rpm/sociald.spec
Expand Up @@ -14,7 +14,7 @@ BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(buteosyncfw5) >= 0.6.33
BuildRequires: pkgconfig(libsignon-qt5)
BuildRequires: pkgconfig(sailfishaccounts) >= 0.0.65
BuildRequires: pkgconfig(accounts-qt5)
BuildRequires: pkgconfig(socialcache) >= 0.0.23
BuildRequires: pkgconfig(libsailfishkeyprovider)
BuildRequires: qt5-qttools-linguist
Expand Down
3 changes: 2 additions & 1 deletion src/common.pri
Expand Up @@ -2,7 +2,8 @@ QMAKE_CXXFLAGS += -Werror
CONFIG += link_pkgconfig
PKGCONFIG += \
libsailfishkeyprovider \
sailfishaccounts \
libsignon-qt5 \
accounts-qt5 \
buteosyncfw5 \
socialcache

Expand Down
75 changes: 72 additions & 3 deletions src/common/socialdbuteoplugin.cpp
Expand Up @@ -22,7 +22,77 @@
#include <Accounts/Account>
#include <Accounts/Service>

#include <accountsyncmanager.h>
namespace {
static const QString SyncProfileTemplatesKey = QStringLiteral("sync_profile_templates");
static QString SyncProfileIdKey(const QString &templateProfileName)
{
return QStringLiteral("%1/%2").arg(templateProfileName).arg(Buteo::KEY_PROFILE_ID);
}
QString createProfile(Buteo::ProfileManager *profileManager,
const QString &templateProfileName,
Accounts::Account *account,
const Accounts::Service &srv,
bool enableProfile,
const QVariantMap &properties)
{
if (!account || !srv.isValid()) {
qWarning() << "Invalid account or service";
return QString();
}
if (templateProfileName.isEmpty()) {
qWarning() << "Invalid templateProfileName";
return QString();
}

Accounts::Service prevService = account->selectedService();
account->selectService(srv);

Buteo::SyncProfile *templateProfile = profileManager->syncProfile(templateProfileName);
if (!templateProfile) {
account->selectService(prevService);
qWarning() << "Unable to load template profile:" << templateProfileName;
return QString();
}

Buteo::SyncProfile *profile = templateProfile->clone();
if (!profile) {
delete templateProfile;
account->selectService(prevService);
qWarning() << "unable to clone template profile:" << templateProfileName;
return QString();
}

QString accountIdStr = QString::number(account->id());
profile->setName(templateProfileName + "-" + accountIdStr);
profile->setKey(Buteo::KEY_DISPLAY_NAME, templateProfileName + "-" + account->displayName().toHtmlEscaped());
profile->setKey(Buteo::KEY_ACCOUNT_ID, accountIdStr);
profile->setBoolKey(Buteo::KEY_USE_ACCOUNTS, true);
profile->setEnabled(enableProfile);

// enable the profile schedule
Buteo::SyncSchedule schedule = profile->syncSchedule();
schedule.setScheduleEnabled(true);
profile->setSyncSchedule(schedule);

// set custom properties; note this may override any properties already set
Q_FOREACH (const QString &key, properties.keys()) {
profile->setKey(key, properties[key].toString());
}

QString profileId = profileManager->updateProfile(*profile);
if (profileId.isEmpty()) {
qWarning() << "Unable to save sync profile" << templateProfile->name();
} else {
account->setValue(SyncProfileIdKey(templateProfile->name()), profile->name());
}

account->selectService(prevService);
delete profile;
delete templateProfile;

return profileId;
}
}

SocialdButeoPlugin::SocialdButeoPlugin(const QString& pluginName,
const Buteo::SyncProfile& profile,
Expand Down Expand Up @@ -175,7 +245,6 @@ void SocialdButeoPlugin::updateResults(const Buteo::SyncResults &results)
// The caller takes ownership of the list.
QList<Buteo::SyncProfile*> SocialdButeoPlugin::ensurePerAccountSyncProfilesExist()
{
AccountSyncManager sm;
Accounts::Manager am;
Accounts::AccountIdList accountIds = am.accountList();
QList<Buteo::SyncProfile*> syncProfiles = m_profileManager.allSyncProfiles();
Expand Down Expand Up @@ -217,7 +286,7 @@ QList<Buteo::SyncProfile*> SocialdButeoPlugin::ensurePerAccountSyncProfilesExist
.arg(profile().name()).arg(currAccount->id()));

// create the per-account profile... we shouldn't need to do this...
QString profileName = sm.createProfile(profile().name(), currAccount, dataTypeSyncService, true);
QString profileName = createProfile(&m_profileManager, profile().name(), currAccount, dataTypeSyncService, true, QVariantMap());
Buteo::SyncProfile *newProfile = m_profileManager.syncProfile(profileName);
if (!newProfile) {
TRACE(SOCIALD_ERROR,
Expand Down
34 changes: 25 additions & 9 deletions src/common/socialnetworksyncadaptor.cpp
Expand Up @@ -21,9 +21,10 @@

#include "buteosyncfw_p.h"

// sailfish-components-accounts-qt5
#include <accountmanager.h>
#include <account.h>
// libaccounts-qt5
#include <Accounts/Manager>
#include <Accounts/Account>
#include <Accounts/Service>

// libsocialcache
#include <socialnetworksyncdatabase.h>
Expand Down Expand Up @@ -70,7 +71,7 @@ SocialNetworkSyncAdaptor::SocialNetworkSyncAdaptor(const QString &serviceName,
QObject *parent)
: QObject(parent)
, dataType(dataType)
, accountManager(new AccountManager(this))
, accountManager(new Accounts::Manager(this))
, networkAccessManager(new SocialdNetworkAccessManager(this))
, m_accountSyncProfile(NULL)
, m_syncDb(new SocialNetworkSyncDatabase())
Expand Down Expand Up @@ -125,14 +126,18 @@ void SocialNetworkSyncAdaptor::sync(const QString &dataType, int accountId)
void SocialNetworkSyncAdaptor::checkAccounts(SocialNetworkSyncAdaptor::DataType dataType, QList<int> *newIds, QList<int> *purgeIds, QList<int> *updateIds)
{
QList<int> knownIds = syncedAccounts(SocialNetworkSyncAdaptor::dataTypeName(dataType));
QList<int> currentIds = accountManager->accountIdentifiers();
QList<uint> currentAUIds = accountManager->accountList();
QList<int> currentIds;
foreach (uint auid, currentAUIds) {
currentIds.append(static_cast<int>(auid));
}
TRACE(SOCIALD_DEBUG,
QString(QLatin1String("have found %1 accounts which support a sync service; determining old/new/update sets..."))
.arg(currentIds.size()));

foreach (int currId, currentIds) {
Account *act = accountManager->account(currId);
if (!act || act->supportedServiceNames().size() <= 0 || act->providerName() != m_serviceName) {
Accounts::Account *act = accountManager->account(currId);
if (!act || act->services().size() <= 0 || act->providerName() != m_serviceName) {
TRACE(SOCIALD_DEBUG,
QString(QLatin1String("account %1 does not support service %2, ignoring"))
.arg(currId).arg(m_serviceName));
Expand Down Expand Up @@ -177,9 +182,20 @@ void SocialNetworkSyncAdaptor::checkAccounts(SocialNetworkSyncAdaptor::DataType
* The default implementation checks that the account is enabled
* with the accounts&sso service associated with this sync adaptor.
*/
bool SocialNetworkSyncAdaptor::checkAccount(Account *account)
bool SocialNetworkSyncAdaptor::checkAccount(Accounts::Account *account)
{
return account->enabled() && account->isEnabledWithService(syncServiceName());
bool globallyEnabled = account->enabled();
Accounts::Service srv(accountManager->service(syncServiceName()));
if (!srv.isValid()) {
TRACE(SOCIALD_INFORMATION,
QString(QLatin1String("invalid service %1 specified, account %2 will be disabled for %2 %3 sync"))
.arg(syncServiceName()).arg(account->id()).arg(m_serviceName).arg(dataTypeName(dataType)));
return false;
}
account->selectService(srv);
bool serviceEnabled = account->enabled();
account->selectService(Accounts::Service());
return globallyEnabled && serviceEnabled;
}

/*!
Expand Down
11 changes: 7 additions & 4 deletions src/common/socialnetworksyncadaptor.h
Expand Up @@ -22,10 +22,13 @@ class QSqlDatabase;
class QNetworkAccessManager;
class QTimer;
class QNetworkReply;
class Account;
class AccountManager;
class SocialNetworkSyncDatabase;

namespace Accounts {
class Account;
class Manager;
}

class SocialNetworkSyncAdaptor : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -74,7 +77,7 @@ class SocialNetworkSyncAdaptor : public QObject
void enabledChanged();

protected:
virtual bool checkAccount(Account *account);
virtual bool checkAccount(Accounts::Account *account);
virtual void finalCleanup();
virtual void finalize(int accountId);
QDateTime lastSyncTimestamp(const QString &serviceName, const QString &dataType,
Expand All @@ -99,7 +102,7 @@ class SocialNetworkSyncAdaptor : public QObject
static QJsonArray parseJsonArrayReplyData(const QByteArray &replyData, bool *ok);

const SocialNetworkSyncAdaptor::DataType dataType;
AccountManager * const accountManager;
Accounts::Manager * const accountManager;
QNetworkAccessManager * const networkAccessManager;
Buteo::SyncProfile *m_accountSyncProfile;

Expand Down
Expand Up @@ -17,8 +17,9 @@

#include <extendedcalendar.h>
#include <extendedstorage.h>
#include <accountmanager.h>
#include <account.h>

#include <Accounts/Manager>
#include <Accounts/Account>

static const char *FACEBOOK = "Facebook";
static const char *FACEBOOK_COLOR = "#3B5998";
Expand Down
16 changes: 9 additions & 7 deletions src/facebook/facebook-contacts/facebookcontactsyncadaptor.cpp
Expand Up @@ -38,9 +38,8 @@

#include <socialcache/abstractimagedownloader.h>

// sailfish-components-accounts-qt5
#include <accountmanager.h>
#include <account.h>
#include <Accounts/Manager>
#include <Accounts/Account>

#define SOCIALD_FACEBOOK_CONTACTS_ID_PREFIX QLatin1String("facebook-contacts-")
#define SOCIALD_FACEBOOK_CONTACTS_GROUPNAME QLatin1String("sociald-sync-facebook-contacts")
Expand Down Expand Up @@ -991,12 +990,15 @@ void FacebookContactSyncAdaptor::finalCleanup()
// first, get a list of all existing, enabled Facebook account ids
QList<int> facebookAccountIds;
QList<int> purgeAccountIds;
QList<int> currentAccountIds = accountManager->accountIdentifiers();
QList<int> currentAccountIds;
QList<uint> uaids = accountManager->accountList();
foreach (uint uaid, uaids) {
currentAccountIds.append(static_cast<int>(uaid));
}
foreach (int currId, currentAccountIds) {
Account *act = accountManager->account(currId);
Accounts::Account *act = accountManager->account(currId);
if (act) {
if (act->providerName() == QString(QLatin1String("facebook")) && act->enabled()
&& act->isEnabledWithService(syncServiceName())) {
if (act->providerName() == QString(QLatin1String("facebook")) && checkAccount(act)) {
facebookAccountIds.append(currId);
}
act->deleteLater();
Expand Down

0 comments on commit f44b283

Please sign in to comment.