Commit a1c83ab8 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Add and make use of ECM's clang-format support

Coding style is off at times, make it consistent.
parent 9d7705fc
......@@ -46,9 +46,13 @@ include(ECMSetupVersion)
include(ECMGenerateHeaders)
include(GenerateExportHeader)
include(ECMPackageConfigHelpers)
include(KDEClangFormat)
include_directories(${ACCOUNTSQT_INCLUDE_DIRS} ${SIGNONQT_INCLUDE_DIRS})
add_subdirectory(src)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -8,8 +8,8 @@
#include "kaccountsdeclarativeplugin.h"
#include "accountsmodel.h"
#include "servicesmodel.h"
#include "providersmodel.h"
#include "servicesmodel.h"
#include "accountservicetogglejob.h"
#include "changeaccountdisplaynamejob.h"
......@@ -18,23 +18,23 @@
#include <qqml.h>
void KAccountsDeclarativePlugin::registerTypes(const char* uri)
void KAccountsDeclarativePlugin::registerTypes(const char *uri)
{
// Version 1.0
// Consider this registration deprecated - use the one named ...Job below instead
qmlRegisterType<CreateAccountJob>( uri, 1, 0, "CreateAccount");
qmlRegisterType<CreateAccountJob>(uri, 1, 0, "CreateAccount");
// Version 1.1
// Consider this registration deprecated - use the one named ...Job below instead
qmlRegisterType<AccountServiceToggleJob>( uri, 1, 1, "AccountServiceToggle");
qmlRegisterType<AccountServiceToggleJob>(uri, 1, 1, "AccountServiceToggle");
// Version 1.2
qmlRegisterType<AccountsModel>( uri, 1, 2, "AccountsModel");
qmlRegisterType<ProvidersModel>( uri, 1, 2, "ProvidersModel");
qmlRegisterType<ServicesModel>( uri, 1, 2, "ServicesModel");
qmlRegisterType<AccountServiceToggleJob>( uri, 1, 2, "AccountServiceToggleJob");
qmlRegisterType<ChangeAccountDisplayNameJob>( uri, 1, 2, "ChangeAccountDisplayNameJob");
qmlRegisterType<CreateAccountJob>( uri, 1, 2, "CreateAccountJob");
qmlRegisterType<RemoveAccountJob>( uri, 1, 2, "RemoveAccountJob");
qmlRegisterType<AccountsModel>(uri, 1, 2, "AccountsModel");
qmlRegisterType<ProvidersModel>(uri, 1, 2, "ProvidersModel");
qmlRegisterType<ServicesModel>(uri, 1, 2, "ServicesModel");
qmlRegisterType<AccountServiceToggleJob>(uri, 1, 2, "AccountServiceToggleJob");
qmlRegisterType<ChangeAccountDisplayNameJob>(uri, 1, 2, "ChangeAccountDisplayNameJob");
qmlRegisterType<CreateAccountJob>(uri, 1, 2, "CreateAccountJob");
qmlRegisterType<RemoveAccountJob>(uri, 1, 2, "RemoveAccountJob");
}
......@@ -11,10 +11,10 @@
class KAccountsDeclarativePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char* uri) override;
void registerTypes(const char *uri) override;
};
#endif // KACCOUNTSDECLARATIVEPLUGIN_H
......@@ -6,17 +6,16 @@
#include "accounts.h"
#include <KLocalizedString>
#include <KAboutData>
#include <KLocalizedString>
#include <KPluginFactory>
K_PLUGIN_CLASS_WITH_JSON(AccountsSettings, "kcm_kaccounts.json")
AccountsSettings::AccountsSettings(QObject* parent, const QVariantList& args)
AccountsSettings::AccountsSettings(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
{
KAboutData* about = new KAboutData(QStringLiteral("kcm_kaccounts"), i18n("Accounts"),
QStringLiteral("1.0"), QString(), KAboutLicense::LGPL);
KAboutData *about = new KAboutData(QStringLiteral("kcm_kaccounts"), i18n("Accounts"), QStringLiteral("1.0"), QString(), KAboutLicense::LGPL);
about->addAuthor(i18n("Sebastian Kügler"), QString(), QStringLiteral("sebas@kde.org"));
about->addAuthor(i18n("Dan Leinir Turthra Jensen"), QString(), QStringLiteral("admin@leinir.dk"), QString(), QStringLiteral("leinir"));
setAboutData(about);
......
......@@ -7,18 +7,17 @@
#ifndef ACCOUNTSSETTINGS_H
#define ACCOUNTSSETTINGS_H
#include <KQuickAddons/ConfigModule>
#include <QObject>
#include <QVariant>
#include <KQuickAddons/ConfigModule>
class AccountsSettings : public KQuickAddons::ConfigModule
{
Q_OBJECT
public:
explicit AccountsSettings(QObject* parent, const QVariantList& args);
~AccountsSettings() override = default;
public:
explicit AccountsSettings(QObject *parent, const QVariantList &args);
~AccountsSettings() override = default;
};
#endif // ACCOUNTSSETTINGS_H
......@@ -9,45 +9,43 @@
#include <core.h>
#include <KPluginFactory>
#include <KPluginMetaData>
#include <KPluginLoader>
#include <KPluginMetaData>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QPluginLoader>
#include <QCoreApplication>
#include <Accounts/AccountService>
#include <Accounts/Manager>
#include <Accounts/Service>
#include <Accounts/AccountService>
K_PLUGIN_CLASS_WITH_JSON(KDEDAccounts, "kded_accounts.json")
KDEDAccounts::KDEDAccounts(QObject *parent, const QList<QVariant>&)
: KDEDModule(parent)
KDEDAccounts::KDEDAccounts(QObject *parent, const QList<QVariant> &)
: KDEDModule(parent)
{
QMetaObject::invokeMethod(this, "startDaemon", Qt::QueuedConnection);
connect(KAccounts::accountsManager(), &Accounts::Manager::accountCreated, this, &KDEDAccounts::accountCreated);
connect(KAccounts::accountsManager(), &Accounts::Manager::accountRemoved, this, &KDEDAccounts::accountRemoved);
const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(QStringLiteral("kaccounts/daemonplugins"));
for (const KPluginMetaData& metadata : data) {
for (const KPluginMetaData &metadata : data) {
if (!metadata.isValid()) {
qDebug() << "Invalid metadata" << metadata.name();
continue;
}
KPluginLoader loader(metadata.fileName());
KPluginFactory* factory = loader.factory();
KPluginFactory *factory = loader.factory();
if (!factory) {
qDebug() << "KPluginFactory could not load the plugin:" << metadata.pluginId() << loader.errorString();
continue;
}
KAccountsDPlugin* plugin = factory->create<KAccountsDPlugin>(this, QVariantList());
KAccountsDPlugin *plugin = factory->create<KAccountsDPlugin>(this, QVariantList());
if (!plugin) {
qDebug() << "Error loading plugin" << metadata.name() << loader.errorString();
continue;
......@@ -114,7 +112,7 @@ void KDEDAccounts::enabledChanged(const QString &serviceName, bool enabled)
return;
}
const Accounts::AccountId accId = qobject_cast<Accounts::Account*>(sender())->id();
const Accounts::AccountId accId = qobject_cast<Accounts::Account *>(sender())->id();
const Accounts::Service service = KAccounts::accountsManager()->service(serviceName);
if (!enabled) {
......
......@@ -19,7 +19,7 @@ class KDEDAccounts : public KDEDModule
Q_CLASSINFO("D-Bus Interface", "org.kde.Accounts")
public:
KDEDAccounts(QObject *parent, const QList<QVariant>&);
KDEDAccounts(QObject *parent, const QList<QVariant> &);
virtual ~KDEDAccounts();
public Q_SLOTS:
......@@ -31,7 +31,7 @@ public Q_SLOTS:
private:
void monitorAccount(const Accounts::AccountId id);
QList<KAccountsDPlugin*> m_plugins;
QList<KAccountsDPlugin *> m_plugins;
};
#endif /*ACCOUNTS_DAEMON_H*/
......@@ -6,22 +6,26 @@
#include "accountservicetogglejob.h"
#include <QDebug>
#include "core.h"
#include <Accounts/Manager>
#include <QDebug>
class AccountServiceToggleJob::Private {
class AccountServiceToggleJob::Private
{
public:
Private() {}
Private()
{
}
QString accountId;
QString serviceId;
bool serviceEnabled{false};
};
AccountServiceToggleJob::AccountServiceToggleJob(QObject* parent)
AccountServiceToggleJob::AccountServiceToggleJob(QObject *parent)
: KJob(parent)
, d(new Private)
{ }
{
}
AccountServiceToggleJob::~AccountServiceToggleJob()
{
......@@ -33,7 +37,7 @@ QString AccountServiceToggleJob::accountId() const
return d->accountId;
}
void AccountServiceToggleJob::setAccountId(const QString& accountId)
void AccountServiceToggleJob::setAccountId(const QString &accountId)
{
d->accountId = accountId;
Q_EMIT accountIdChanged();
......@@ -44,7 +48,7 @@ QString AccountServiceToggleJob::serviceId() const
return d->serviceId;
}
void AccountServiceToggleJob::setServiceId(const QString& serviceId)
void AccountServiceToggleJob::setServiceId(const QString &serviceId)
{
d->serviceId = serviceId;
Q_EMIT serviceIdChanged();
......@@ -63,15 +67,15 @@ void AccountServiceToggleJob::setServiceEnabled(bool serviceEnabled)
void AccountServiceToggleJob::start()
{
Accounts::Manager* accountsManager = KAccounts::accountsManager();
Accounts::Manager *accountsManager = KAccounts::accountsManager();
if (accountsManager) {
Accounts::Account *account = accountsManager->account(d->accountId.toInt());
if (account) {
Accounts::Service service = accountsManager->service(d->serviceId);
if (!service.isValid()) {
// qWarning() << "Looks like we might have been given a name instead of an ID for the service, which will be expected when using the Ubuntu AccountServiceModel, which only gives you the name";
// qWarning() << "Looks like we might have been given a name instead of an ID for the service, which will be expected when using the Ubuntu AccountServiceModel, which only gives you the name";
const auto services = account->services();
for (const Accounts::Service& aService : services) {
for (const Accounts::Service &aService : services) {
if (aService.displayName() == d->serviceId) {
service = aService;
break;
......@@ -107,7 +111,9 @@ void AccountServiceToggleJob::start()
account->setEnabled(shouldStayEnabled);
}
connect(account, &Accounts::Account::synced, this, [this](){ emitResult(); });
connect(account, &Accounts::Account::synced, this, [this]() {
emitResult();
});
account->sync();
} else {
qWarning() << "No service found with the ID" << d->serviceId << "on account" << account->displayName();
......
......@@ -23,17 +23,17 @@ class KACCOUNTS_EXPORT AccountServiceToggleJob : public KJob
Q_PROPERTY(QString serviceId READ serviceId WRITE setServiceId NOTIFY serviceIdChanged)
Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged)
public:
explicit AccountServiceToggleJob(QObject* parent = nullptr);
explicit AccountServiceToggleJob(QObject *parent = nullptr);
virtual ~AccountServiceToggleJob();
void start() override;
QString accountId() const;
void setAccountId(const QString& accountId);
void setAccountId(const QString &accountId);
Q_SIGNAL void accountIdChanged();
QString serviceId() const;
void setServiceId(const QString& serviceId);
void setServiceId(const QString &serviceId);
Q_SIGNAL void serviceIdChanged();
bool serviceEnabled() const;
......@@ -41,8 +41,9 @@ public:
Q_SIGNALS:
void serviceEnabledChanged();
private:
class Private;
Private* d;
Private *d;
};
#endif//ACCOUNTSERVICETOGGLE_H
#endif // ACCOUNTSERVICETOGGLE_H
......@@ -29,19 +29,17 @@ public:
{
accountIDs = accountsManager->accountList();
connect(accountsManager, &Accounts::Manager::accountCreated,
q, [this](Accounts::AccountId accountId){
int row = accountIDs.count();
q->beginInsertRows(QModelIndex(), row, row);
accountIDs.insert(row, accountId);
q->endInsertRows();
});
connect(accountsManager, &Accounts::Manager::accountRemoved,
q, [this](Accounts::AccountId accountId) {
q->beginRemoveRows(QModelIndex(), accountIDs.indexOf(accountId), accountIDs.indexOf(accountId));
removeAccount(accountId);
q->endRemoveRows();
});
connect(accountsManager, &Accounts::Manager::accountCreated, q, [this](Accounts::AccountId accountId) {
int row = accountIDs.count();
q->beginInsertRows(QModelIndex(), row, row);
accountIDs.insert(row, accountId);
q->endInsertRows();
});
connect(accountsManager, &Accounts::Manager::accountRemoved, q, [this](Accounts::AccountId accountId) {
q->beginRemoveRows(QModelIndex(), accountIDs.indexOf(accountId), accountIDs.indexOf(accountId));
removeAccount(accountId);
q->endRemoveRows();
});
};
virtual ~Private()
{
......@@ -50,30 +48,30 @@ public:
Accounts::Manager *accountsManager;
Accounts::AccountIdList accountIDs;
QHash<int, Accounts::Account*> accounts;
QHash<Accounts::Account*, ServicesModel*> servicesModels;
QHash<int, Accounts::Account *> accounts;
QHash<Accounts::Account *, ServicesModel *> servicesModels;
Accounts::Account* accountById(int id);
Accounts::Account *accountById(int id);
void removeAccount(Accounts::AccountId accountId);
private:
AccountsModel* q;
AccountsModel *q;
};
Accounts::Account* AccountsModel::Private::accountById(int id)
Accounts::Account *AccountsModel::Private::accountById(int id)
{
if (accounts.contains(id)) {
return accounts.value(id);
}
// If we don't yet have this account cached, get it and connect it up to the model
Accounts::Account* account = accountsManager->account(id);
Accounts::Account *account = accountsManager->account(id);
if (!account) {
qDebug() << "\t Failed to get the account from manager";
return nullptr;
}
connect(account, &Accounts::Account::displayNameChanged, q, [this,account](){
connect(account, &Accounts::Account::displayNameChanged, q, [this, account]() {
QModelIndex accountIndex = q->index(accountIDs.indexOf(account->id()));
Q_EMIT q->dataChanged(accountIndex, accountIndex, QVector<int>() << AccountsModel::DisplayNameRole);
});
......@@ -88,9 +86,9 @@ void AccountsModel::Private::removeAccount(Accounts::AccountId accountId)
delete accounts.take(accountId);
}
AccountsModel::AccountsModel(QObject* parent)
: QAbstractListModel(parent)
, d(new AccountsModel::Private(this))
AccountsModel::AccountsModel(QObject *parent)
: QAbstractListModel(parent)
, d(new AccountsModel::Private(this))
{
}
......@@ -101,20 +99,18 @@ AccountsModel::~AccountsModel()
QHash<int, QByteArray> AccountsModel::roleNames() const
{
static QHash<int, QByteArray> roles{
{IdRole, "id"},
{ServicesRole, "services"},
{EnabledRole, "enabled"},
{CredentialsIdRole, "credentialsId"},
{DisplayNameRole, "displayName"},
{ProviderNameRole, "providerName"},
{IconNameRole, "iconName"},
{DataObjectRole, "dataObject"}
};
static QHash<int, QByteArray> roles{{IdRole, "id"},
{ServicesRole, "services"},
{EnabledRole, "enabled"},
{CredentialsIdRole, "credentialsId"},
{DisplayNameRole, "displayName"},
{ProviderNameRole, "providerName"},
{IconNameRole, "iconName"},
{DataObjectRole, "dataObject"}};
return roles;
}
int AccountsModel::rowCount(const QModelIndex& parent) const
int AccountsModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
......@@ -123,56 +119,54 @@ int AccountsModel::rowCount(const QModelIndex& parent) const
return d->accountIDs.count();
}
QVariant AccountsModel::data(const QModelIndex& index, int role) const
QVariant AccountsModel::data(const QModelIndex &index, int role) const
{
QVariant data;
if(checkIndex(index)) {
if (checkIndex(index)) {
Accounts::AccountId accountId = d->accountIDs.value(index.row());
Accounts::Account *account = d->accountById(accountId);
if (account) {
switch (role) {
case IdRole:
data.setValue(account->id());
break;
case ServicesRole:
{
ServicesModel* servicesModel{nullptr};
if (d->servicesModels.contains(account)) {
servicesModel = d->servicesModels.value(account);
} else {
// Not parenting to the account itself, so we can avoid it suddenly
// disappearing. Just to be on the safe side
servicesModel = new ServicesModel(d->accountsManager);
servicesModel->setAccount(account);
d->servicesModels[account] = servicesModel;
}
data.setValue(servicesModel);
break;
case IdRole:
data.setValue(account->id());
break;
case ServicesRole: {
ServicesModel *servicesModel{nullptr};
if (d->servicesModels.contains(account)) {
servicesModel = d->servicesModels.value(account);
} else {
// Not parenting to the account itself, so we can avoid it suddenly
// disappearing. Just to be on the safe side
servicesModel = new ServicesModel(d->accountsManager);
servicesModel->setAccount(account);
d->servicesModels[account] = servicesModel;
}
case EnabledRole:
data.setValue(account->enabled());
break;
case CredentialsIdRole:
data.setValue(account->credentialsId());
break;
case DisplayNameRole:
data.setValue(account->displayName());
break;
case ProviderNameRole:
data.setValue(account->providerName());
break;
case IconNameRole:
{
QString iconName = QStringLiteral("user-identity");
if (account->provider().isValid() && !account->provider().iconName().isEmpty()) {
iconName = account->provider().iconName();
}
data.setValue(iconName);
break;
data.setValue(servicesModel);
break;
}
case EnabledRole:
data.setValue(account->enabled());
break;
case CredentialsIdRole:
data.setValue(account->credentialsId());
break;
case DisplayNameRole:
data.setValue(account->displayName());
break;
case ProviderNameRole:
data.setValue(account->providerName());
break;
case IconNameRole: {
QString iconName = QStringLiteral("user-identity");
if (account->provider().isValid() && !account->provider().iconName().isEmpty()) {
iconName = account->provider().iconName();
}
case DataObjectRole:
data.setValue<QObject*>(account);
break;
data.setValue(iconName);
break;
}
case DataObjectRole:
data.setValue<QObject *>(account);
break;
}
}
}
......
......@@ -34,27 +34,27 @@ class KACCOUNTS_EXPORT AccountsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles {
IdRole = Qt::UserRole + 1,
ServicesRole,
EnabledRole,
CredentialsIdRole,
DisplayNameRole,
ProviderNameRole,
IconNameRole,
DataObjectRole
};
explicit AccountsModel(QObject* parent = nullptr);
virtual ~AccountsModel();
QHash< int, QByteArray > roleNames() const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
private:
class Private;
Private *d;
public:
enum Roles {
IdRole = Qt::UserRole + 1,
ServicesRole,
EnabledRole,
CredentialsIdRole,
DisplayNameRole,
ProviderNameRole,
IconNameRole,
DataObjectRole,
};
explicit AccountsModel(QObject *parent = nullptr);
virtual ~AccountsModel();
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
private:
class Private;
Private *d;
};
#endif //ACCOUNTS_MODEL_H
#endif // ACCOUNTS_MODEL_H
......@@ -11,17 +11,21 @@
#include <KLocalizedString>
#include <QDebug>
class ChangeAccountDisplayNameJob::Private {
class ChangeAccountDisplayNameJob::Private
{
public:
Private() {}
Private()
{
}
QString accountId;
QString displayName;
};
ChangeAccountDisplayNameJob::ChangeAccountDisplayNameJob(QObject* parent)
ChangeAccountDisplayNameJob::ChangeAccountDisplayNameJob(QObject *parent)
: KJob(parent)
, d(new Private)
{ }
{
}