Commit 2030bb49 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Move job classes to kaccounts lib and rename to *Job

Summary: This makes including them from the qml plugin less weird and they might be interesting to use from C++ too.

Test Plan: builds, kcm opens

Reviewers: #frameworks, bshah, leinir

Reviewed By: leinir

Differential Revision: https://phabricator.kde.org/D27709
parent 26a4a890
......@@ -54,7 +54,7 @@ ApplicationWindow
Component {
id: jobComponent
CreateAccount {}
CreateAccountJob {}
}
onClicked: {
......
include_directories(${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/..)
add_library(kaccountsdeclarativeplugin SHARED kaccountsdeclarativeplugin.cpp
../jobs/createaccount.cpp
../jobs/accountservicetoggle.cpp
../lib/uipluginsmanager.cpp)
add_library(kaccountsdeclarativeplugin SHARED kaccountsdeclarativeplugin.cpp)
target_link_libraries(kaccountsdeclarativeplugin Qt5::Qml
KF5::I18n
......
......@@ -17,12 +17,12 @@
*************************************************************************************/
#include "kaccountsdeclarativeplugin.h"
#include "../jobs/createaccount.h"
#include "../jobs/accountservicetoggle.h"
#include "createaccountjob.h"
#include "accountservicetogglejob.h"
#include <qqml.h>
void KAccountsDeclarativePlugin::registerTypes(const char* uri)
{
qmlRegisterType<CreateAccount>(uri, 1, 0, "CreateAccount");
qmlRegisterType<AccountServiceToggle>(uri, 1, 1, "AccountServiceToggle");
qmlRegisterType<CreateAccountJob>(uri, 1, 0, "CreateAccountJob");
qmlRegisterType<AccountServiceToggleJob>(uri, 1, 1, "AccountServiceToggleJob");
}
......@@ -46,7 +46,7 @@ ScrollViewKCM {
Component {
id: jobComponent
CreateAccount {
CreateAccountJob {
onFinished: kcm.pop()
}
}
......
......@@ -74,6 +74,6 @@ ScrollViewKCM {
}
Component {
id: jobComponent
KAccounts.AccountServiceToggle { }
KAccounts.AccountServiceToggleJob { }
}
}
......@@ -21,10 +21,13 @@ ecm_setup_version(${KACCOUNTS_VERSION}
SOVERSION ${KACCOUNTS_SOVERSION})
set (kaccountslib_SRCS
accountservicetogglejob.cpp
createaccountjob.cpp
kaccountsuiplugin.cpp
kaccountsdplugin.cpp
getcredentialsjob.cpp
core.cpp
uipluginsmanager.cpp
)
ecm_generate_headers(kaccountslib_HEADERS
......@@ -33,6 +36,8 @@ ecm_generate_headers(kaccountslib_HEADERS
GetCredentialsJob
KAccountsUiPlugin
KAccountsDPlugin
AccountServiceToggleJob
CreateAccountJob
REQUIRED_HEADERS kaccountslib_HEADERS
)
......@@ -44,6 +49,7 @@ generate_export_header(kaccounts BASE_NAME kaccounts)
target_link_libraries (kaccounts
PUBLIC
KF5::CoreAddons
KF5::I18n
${ACCOUNTSQT_LIBRARIES}
Qt5::Xml
Qt5::Gui
......
......@@ -16,13 +16,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "accountservicetoggle.h"
#include "accountservicetogglejob.h"
#include <QDebug>
#include "core.h"
#include <Accounts/Manager>
class AccountServiceToggle::Private {
class AccountServiceToggleJob::Private {
public:
Private() {}
QString accountId;
......@@ -30,50 +30,50 @@ public:
bool serviceEnabled{false};
};
AccountServiceToggle::AccountServiceToggle(QObject* parent)
AccountServiceToggleJob::AccountServiceToggleJob(QObject* parent)
: KJob(parent)
, d(new Private)
{ }
AccountServiceToggle::~AccountServiceToggle()
AccountServiceToggleJob::~AccountServiceToggleJob()
{
delete d;
}
QString AccountServiceToggle::accountId() const
QString AccountServiceToggleJob::accountId() const
{
return d->accountId;
}
void AccountServiceToggle::setAccountId(const QString& accountId)
void AccountServiceToggleJob::setAccountId(const QString& accountId)
{
d->accountId = accountId;
Q_EMIT accountIdChanged();
}
QString AccountServiceToggle::serviceId() const
QString AccountServiceToggleJob::serviceId() const
{
return d->serviceId;
}
void AccountServiceToggle::setServiceId(const QString& serviceId)
void AccountServiceToggleJob::setServiceId(const QString& serviceId)
{
d->serviceId = serviceId;
Q_EMIT serviceIdChanged();
}
bool AccountServiceToggle::serviceEnabled() const
bool AccountServiceToggleJob::serviceEnabled() const
{
return d->serviceEnabled;
}
void AccountServiceToggle::setServiceEnabled(bool serviceEnabled)
void AccountServiceToggleJob::setServiceEnabled(bool serviceEnabled)
{
d->serviceEnabled = serviceEnabled;
Q_EMIT serviceEnabledChanged();
}
void AccountServiceToggle::start()
void AccountServiceToggleJob::start()
{
Accounts::Manager* accountsManager = KAccounts::accountsManager();
if (accountsManager) {
......
......@@ -19,20 +19,21 @@
#ifndef ACCOUNTSERVICETOGGLE_H
#define ACCOUNTSERVICETOGGLE_H
#include "kaccounts_export.h"
#include <kjob.h>
#include <QStringList>
class AccountServiceToggle : public KJob
class KACCOUNTS_EXPORT AccountServiceToggleJob : public KJob
{
Q_OBJECT
Q_PROPERTY(QString accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged)
Q_PROPERTY(QString serviceId READ serviceId WRITE setServiceId NOTIFY serviceIdChanged)
Q_PROPERTY(bool serviceEnabled READ serviceEnabled WRITE setServiceEnabled NOTIFY serviceEnabledChanged)
public:
explicit AccountServiceToggle(QObject* parent = nullptr);
virtual ~AccountServiceToggle();
explicit AccountServiceToggleJob(QObject* parent = nullptr);
virtual ~AccountServiceToggleJob();
void start() override;
......
......@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "createaccount.h"
#include "lib/kaccountsuiplugin.h"
#include "lib/core.h"
#include "createaccountjob.h"
#include "kaccountsuiplugin.h"
#include "core.h"
#include "uipluginsmanager.h"
#include <QDebug>
......@@ -33,13 +33,13 @@
#include <KLocalizedString>
CreateAccount::CreateAccount(QObject* parent)
: CreateAccount(QString(), parent)
CreateAccountJob::CreateAccountJob(QObject* parent)
: CreateAccountJob(QString(), parent)
{
}
CreateAccount::CreateAccount(const QString &providerName, QObject* parent)
CreateAccountJob::CreateAccountJob(const QString &providerName, QObject* parent)
: KJob(parent)
, m_providerName(providerName)
, m_manager(new Accounts::Manager(this))
......@@ -51,13 +51,13 @@ CreateAccount::CreateAccount(const QString &providerName, QObject* parent)
}
void CreateAccount::start()
void CreateAccountJob::start()
{
qDebug() << m_providerName;
QMetaObject::invokeMethod(this, "processSession");
}
void CreateAccount::processSession()
void CreateAccountJob::processSession()
{
m_account = m_manager->createAccount(m_providerName);
Accounts::Service service;
......@@ -80,7 +80,7 @@ void CreateAccount::processSession()
m_identity = SignOn::Identity::newIdentity(info, this);
m_identity->storeCredentials();
connect(m_identity, &SignOn::Identity::info, this, &CreateAccount::info);
connect(m_identity, &SignOn::Identity::info, this, &CreateAccountJob::info);
connect(m_identity, &SignOn::Identity::error, [=](const SignOn::Error &err) {
qDebug() << "Error storing identity:" << err.message();
});
......@@ -91,14 +91,14 @@ void CreateAccount::processSession()
SignOn::SessionData sessionData(data);
SignOn::AuthSessionP session = m_identity->createSession(m_accInfo->authData().method());
qDebug() << "Starting auth session with" << m_accInfo->authData().method();
connect(session, &SignOn::AuthSession::error, this, &CreateAccount::sessionError);
connect(session, &SignOn::AuthSession::response, this, &CreateAccount::sessionResponse);
connect(session, &SignOn::AuthSession::error, this, &CreateAccountJob::sessionError);
connect(session, &SignOn::AuthSession::response, this, &CreateAccountJob::sessionResponse);
session->process(sessionData, m_accInfo->authData().mechanism());
}
}
void CreateAccount::loadPluginAndShowDialog(const QString &pluginName)
void CreateAccountJob::loadPluginAndShowDialog(const QString &pluginName)
{
KAccountsUiPlugin *ui = KAccounts::UiPluginsManager::pluginForName(pluginName);
......@@ -108,14 +108,14 @@ void CreateAccount::loadPluginAndShowDialog(const QString &pluginName)
return;
}
connect(ui, &KAccountsUiPlugin::success, this, &CreateAccount::pluginFinished, Qt::UniqueConnection);
connect(ui, &KAccountsUiPlugin::error, this, &CreateAccount::pluginError, Qt::UniqueConnection);
connect(ui, &KAccountsUiPlugin::success, this, &CreateAccountJob::pluginFinished, Qt::UniqueConnection);
connect(ui, &KAccountsUiPlugin::error, this, &CreateAccountJob::pluginError, Qt::UniqueConnection);
ui->setProviderName(m_providerName);
ui->init(KAccountsUiPlugin::NewAccountDialog);
}
void CreateAccount::pluginFinished(const QString &screenName, const QString &secret, const QVariantMap &data)
void CreateAccountJob::pluginFinished(const QString &screenName, const QString &secret, const QVariantMap &data)
{
// Set up the new identity
SignOn::IdentityInfo info;
......@@ -138,7 +138,7 @@ void CreateAccount::pluginFinished(const QString &screenName, const QString &sec
}
m_identity = SignOn::Identity::newIdentity(info, this);
connect(m_identity, &SignOn::Identity::info, this, &CreateAccount::info);
connect(m_identity, &SignOn::Identity::info, this, &CreateAccountJob::info);
m_done = true;
......@@ -146,7 +146,7 @@ void CreateAccount::pluginFinished(const QString &screenName, const QString &sec
m_identity->storeCredentials();
}
void CreateAccount::pluginError(const QString &error)
void CreateAccountJob::pluginError(const QString &error)
{
if (error.isEmpty()) {
setError(-1);
......@@ -158,7 +158,7 @@ void CreateAccount::pluginError(const QString &error)
emitResult();
}
void CreateAccount::sessionResponse(const SignOn::SessionData &/*data*/)
void CreateAccountJob::sessionResponse(const SignOn::SessionData &/*data*/)
{
qDebug() << "Received session response";
......@@ -166,7 +166,7 @@ void CreateAccount::sessionResponse(const SignOn::SessionData &/*data*/)
m_identity->queryInfo();
}
void CreateAccount::info(const SignOn::IdentityInfo &info)
void CreateAccountJob::info(const SignOn::IdentityInfo &info)
{
qDebug() << "Info:";
qDebug() << "\tId:" << info.id();
......@@ -213,10 +213,10 @@ void CreateAccount::info(const SignOn::IdentityInfo &info)
m_account->selectService();
m_account->setEnabled(true);
m_account->sync();
connect(m_account, &Accounts::Account::synced, this, &CreateAccount::emitResult);
connect(m_account, &Accounts::Account::synced, this, &CreateAccountJob::emitResult);
}
void CreateAccount::sessionError(const SignOn::Error &signOnError)
void CreateAccountJob::sessionError(const SignOn::Error &signOnError)
{
if (error()) {
// Guard against SignOn sending two error() signals
......@@ -230,7 +230,7 @@ void CreateAccount::sessionError(const SignOn::Error &signOnError)
emitResult();
}
void CreateAccount::setProviderName(const QString &name)
void CreateAccountJob::setProviderName(const QString &name)
{
if (m_providerName != name) {
m_providerName = name;
......
......@@ -19,6 +19,8 @@
#ifndef CREATE_ACCOUNT_JOB_H
#define CREATE_ACCOUNT_JOB_H
#include "kaccounts_export.h"
#include <kjob.h>
#include <QStringList>
......@@ -37,13 +39,13 @@ namespace SignOn
class IdentityInfo;
}
class CreateAccount : public KJob
class KACCOUNTS_EXPORT CreateAccountJob : public KJob
{
Q_OBJECT
Q_PROPERTY(QString providerName READ providerName WRITE setProviderName NOTIFY providerNameChanged)
public:
explicit CreateAccount(QObject* parent = nullptr);
explicit CreateAccount(const QString &providerName, QObject* parent = nullptr);
explicit CreateAccountJob(QObject* parent = nullptr);
explicit CreateAccountJob(const QString &providerName, QObject* parent = nullptr);
QString providerName() const { return m_providerName; }
void setProviderName(const QString &name);
......
......@@ -18,7 +18,7 @@
#include "uipluginsmanager.h"
#include "lib/kaccountsuiplugin.h"
#include "kaccountsuiplugin.h"
#include <QHash>
#include <QStringList>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment