diff --git a/example/accounts.qml b/example/accounts.qml index ffa48fd..7324b68 100644 --- a/example/accounts.qml +++ b/example/accounts.qml @@ -1,67 +1,67 @@ import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 import Ubuntu.OnlineAccounts 0.1 as OA import org.kde.kaccounts 1.0 ApplicationWindow { StackView { id: stack anchors.fill: parent initialItem: ListView { Layout.fillWidth: true Layout.fillHeight: true header: Label { font.pointSize: 20 text: "Accounts" } footer: Button { text: "Add new Account" onClicked: stack.push(addProviderComponent) } model: OA.AccountServiceModel { id: accountsModel service: "global" includeDisabled: true } delegate: Label { text: displayName } } } Component { id: addProviderComponent ListView { Layout.fillWidth: true Layout.fillHeight: true header: Label { anchors.horizontalCenter: parent.horizontalCenter font.pointSize: 20 text: "Available Accounts" } model: OA.ProviderModel {} delegate: Button { anchors.horizontalCenter: parent.horizontalCenter text: displayName Component { id: jobComponent - CreateAccount {} + CreateAccountJob {} } onClicked: { var job = jobComponent.createObject(stack, { providerName: providerId}) job.start() } } } } } diff --git a/src/declarative/CMakeLists.txt b/src/declarative/CMakeLists.txt index c67c62d..e202cdf 100644 --- a/src/declarative/CMakeLists.txt +++ b/src/declarative/CMakeLists.txt @@ -1,16 +1,11 @@ -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 kaccounts ${SIGNONQT_LIBRARIES}) target_include_directories(kaccountsdeclarativeplugin PRIVATE "${SIGNONQT_INCLUDE_DIRS}") install(TARGETS kaccountsdeclarativeplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kaccounts) install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kaccounts) diff --git a/src/declarative/kaccountsdeclarativeplugin.cpp b/src/declarative/kaccountsdeclarativeplugin.cpp index daf346c..702b8b8 100644 --- a/src/declarative/kaccountsdeclarativeplugin.cpp +++ b/src/declarative/kaccountsdeclarativeplugin.cpp @@ -1,28 +1,28 @@ /************************************************************************************* * Copyright (C) 2015 by Aleix Pol * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #include "kaccountsdeclarativeplugin.h" -#include "../jobs/createaccount.h" -#include "../jobs/accountservicetoggle.h" +#include "createaccountjob.h" +#include "accountservicetogglejob.h" #include void KAccountsDeclarativePlugin::registerTypes(const char* uri) { - qmlRegisterType(uri, 1, 0, "CreateAccount"); - qmlRegisterType(uri, 1, 1, "AccountServiceToggle"); + qmlRegisterType(uri, 1, 0, "CreateAccountJob"); + qmlRegisterType(uri, 1, 1, "AccountServiceToggleJob"); } diff --git a/src/kcm/package/contents/ui/AvailableAccounts.qml b/src/kcm/package/contents/ui/AvailableAccounts.qml index 7b1c5d0..e0db0f1 100644 --- a/src/kcm/package/contents/ui/AvailableAccounts.qml +++ b/src/kcm/package/contents/ui/AvailableAccounts.qml @@ -1,53 +1,53 @@ /* * Copyright 2019 Nicolas Fella * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import QtQuick.Layouts 1.11 import QtQuick.Controls 2.0 as Controls import org.kde.kirigami 2.4 as Kirigami import org.kde.kaccounts 1.0 import org.kde.kcm 1.2 import Ubuntu.OnlineAccounts 0.1 as OA ScrollViewKCM { id: root title: i18n("Add new Account") view: ListView { model: OA.ProviderModel {} delegate: Kirigami.BasicListItem { icon: model.iconName label: model.displayName width: parent.width onClicked: { var job = jobComponent.createObject(root, { "providerName": providerId }) job.start() } } } Component { id: jobComponent - CreateAccount { + CreateAccountJob { onFinished: kcm.pop() } } } diff --git a/src/kcm/package/contents/ui/AvailableServices.qml b/src/kcm/package/contents/ui/AvailableServices.qml index ad2172b..9bcbc8e 100644 --- a/src/kcm/package/contents/ui/AvailableServices.qml +++ b/src/kcm/package/contents/ui/AvailableServices.qml @@ -1,79 +1,79 @@ /* * Copyright 2019 Nicolas Fella * Copyright 2020 Dan Leinir Turthra Jensen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import QtQuick.Layouts 1.11 import QtQuick.Controls 2.0 as Controls import org.kde.kirigami 2.4 as Kirigami import org.kde.kaccounts 1.1 as KAccounts import org.kde.kcm 1.2 import Ubuntu.OnlineAccounts 0.1 as OA ScrollViewKCM { id: component; title: i18n("Available Services") property alias accountId: servicesModel.accountId view: ListView { model: OA.AccountServiceModel { id: servicesModel includeDisabled: true function refreshData() { // Because AccountServiceModel seems to not pick this up itself, we'll reset the model... like so, because there's no reset var oldId = component.accountId; component.accountId = ""; component.accountId = oldId; } } delegate: Kirigami.AbstractListItem { width: parent.width Controls.CheckBox { id: serviceCheck text: model.serviceName checked: model.enabled Binding { target: serviceCheck property: "checked" value: model.enabled } onClicked: { var job = jobComponent.createObject(component, { "accountId": component.accountId, "serviceId": model.serviceName, "serviceEnabled": !model.enabled }) job.result.connect(servicesModel.refreshData); job.start() } } } Controls.Label { anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter wrapMode: Text.Wrap visible: parent.count === 0 opacity: 0.5 text: i18nc("A text shown when an account has no configurable services", "(No services for this account)") } } Component { id: jobComponent - KAccounts.AccountServiceToggle { } + KAccounts.AccountServiceToggleJob { } } } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 2ba24f5..8e61689 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,85 +1,91 @@ project (kaccounts-support-library) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KAccounts") include(ECMGenerateHeaders) include(ECMPackageConfigHelpers) include(ECMSetupVersion) include(CMakePackageConfigHelpers) include(WriteBasicConfigVersionFile) include(KDECMakeSettings) include(GenerateExportHeader) ecm_setup_version(${KACCOUNTS_VERSION} VARIABLE_PREFIX KACCOUNTS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kaccounts_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfigVersion.cmake" 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 HEADER_NAMES Core GetCredentialsJob KAccountsUiPlugin KAccountsDPlugin + AccountServiceToggleJob + CreateAccountJob REQUIRED_HEADERS kaccountslib_HEADERS ) add_library (kaccounts SHARED ${kaccountslib_SRCS} ) generate_export_header(kaccounts BASE_NAME kaccounts) target_link_libraries (kaccounts PUBLIC KF5::CoreAddons + KF5::I18n ${ACCOUNTSQT_LIBRARIES} Qt5::Xml Qt5::Gui PRIVATE ${SIGNONQT_LIBRARIES} ) target_include_directories(kaccounts INTERFACE "$" PUBLIC "${ACCOUNTSQT_INCLUDE_DIRS}" PRIVATE "${SIGNONQT_INCLUDE_DIRS}") set_target_properties(kaccounts PROPERTIES VERSION ${KACCOUNTS_VERSION} SOVERSION ${KACCOUNTS_SOVERSION} EXPORT_NAME KAccounts ) ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KAccountsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "KAccountsMacros.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(TARGETS kaccounts EXPORT KAccountsTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(EXPORT KAccountsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KAccountsTargets.cmake ) #NAMESPACE KF5:: install (FILES ${CMAKE_CURRENT_BINARY_DIR}/kaccounts_export.h ${kaccountslib_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/kaccounts_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KAccounts COMPONENT Devel ) add_subdirectory(cmake) diff --git a/src/jobs/accountservicetoggle.cpp b/src/lib/accountservicetogglejob.cpp similarity index 88% rename from src/jobs/accountservicetoggle.cpp rename to src/lib/accountservicetogglejob.cpp index 27e85d0..1819a47 100644 --- a/src/jobs/accountservicetoggle.cpp +++ b/src/lib/accountservicetogglejob.cpp @@ -1,134 +1,134 @@ /************************************************************************************* * Copyright (C) 2020 by Dan Leinir Turthra Jensen * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ -#include "accountservicetoggle.h" +#include "accountservicetogglejob.h" #include #include "core.h" #include -class AccountServiceToggle::Private { +class AccountServiceToggleJob::Private { public: Private() {} QString accountId; QString serviceId; 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) { 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"; for (const Accounts::Service& aService : account->services()) { if (aService.displayName() == d->serviceId) { service = aService; break; } } } if (service.isValid()) { account->selectService(service); account->setEnabled(d->serviceEnabled); if (d->serviceEnabled) { account->selectService(); account->setEnabled(true); } else { bool shouldStayEnabled = false; for (const Accounts::Service &accountService : account->services()) { // Skip the current service, that is not synced to the account yet // so it would return the state before the user clicked the checkbox if (accountService == service) { continue; } account->selectService(accountService); if (account->isEnabled()) { // At least one service is enabled, leave the account enabled shouldStayEnabled = true; break; } } // Make sure we're operating on the global account account->selectService(); account->setEnabled(shouldStayEnabled); } connect(account, &Accounts::Account::synced, this, [this](){ emitResult(); }); account->sync(); } else { qWarning() << "No service found with the ID" << d->serviceId << "on account" << account->displayName(); emitResult(); } } else { qWarning() << "No account found with the ID" << d->accountId; emitResult(); } } else { qWarning() << "No accounts manager, this is not awesome."; emitResult(); } } diff --git a/src/jobs/accountservicetoggle.h b/src/lib/accountservicetogglejob.h similarity index 92% rename from src/jobs/accountservicetoggle.h rename to src/lib/accountservicetogglejob.h index 9b91173..618ef72 100644 --- a/src/jobs/accountservicetoggle.h +++ b/src/lib/accountservicetogglejob.h @@ -1,54 +1,55 @@ /************************************************************************************* * Copyright (C) 2020 by Dan Leinir Turthra Jensen * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #ifndef ACCOUNTSERVICETOGGLE_H #define ACCOUNTSERVICETOGGLE_H +#include "kaccounts_export.h" #include #include -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; QString accountId() const; void setAccountId(const QString& accountId); Q_SIGNAL void accountIdChanged(); QString serviceId() const; void setServiceId(const QString& serviceId); Q_SIGNAL void serviceIdChanged(); bool serviceEnabled() const; void setServiceEnabled(bool serviceEnabled); Q_SIGNAL void serviceEnabledChanged(); private: class Private; Private* d; }; #endif//ACCOUNTSERVICETOGGLE_H diff --git a/src/jobs/createaccount.cpp b/src/lib/createaccountjob.cpp similarity index 86% rename from src/jobs/createaccount.cpp rename to src/lib/createaccountjob.cpp index 429bb62..4d516e3 100644 --- a/src/jobs/createaccount.cpp +++ b/src/lib/createaccountjob.cpp @@ -1,239 +1,239 @@ /************************************************************************************* * Copyright (C) 2013 by Alejandro Fiestas Olivares * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * 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 #include #include #include #include #include #include #include -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)) , m_account(nullptr) , m_accInfo(nullptr) , m_identity(nullptr) , m_done(false) { } -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; if (m_account->services().size() == 1) { service = m_account->services().at(0); } m_accInfo = new Accounts::AccountService(m_account, service, this); const QString pluginName = m_account->provider().pluginName(); qDebug() << "Looking for plugin" << pluginName; if (!pluginName.isEmpty()) { loadPluginAndShowDialog(pluginName); } else { SignOn::IdentityInfo info; info.setCaption(m_providerName); info.setAccessControlList(QStringList("*")); info.setType(SignOn::IdentityInfo::Application); info.setStoreSecret(true); 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(); }); QVariantMap data = m_accInfo->authData().parameters(); data.insert("Embedded", false); 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); if (!ui) { qDebug() << "Plugin could not be loaded"; pluginError(i18nc("The %1 is for plugin name, eg. Could not load UI plugin", "Could not load %1 plugin, please check your installation", 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; info.setStoreSecret(true); info.setUserName(screenName); info.setSecret(secret, true); info.setCaption(m_providerName); info.setAccessControlList(QStringList(QLatin1String("*"))); info.setType(SignOn::IdentityInfo::Application); const auto keys = data.keys(); for (const QString &key : keys) { // If a key with __service/ prefix exists and its value is false, // add it to m_disabledServices which will later be used for disabling // the services contained in that list if (key.startsWith(QLatin1String("__service/")) && !data.value(key).toBool()) { m_disabledServices << key.mid(10); } m_account->setValue(key, data.value(key).toString()); } 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; connect(m_identity, &SignOn::Identity::credentialsStored, m_identity, &SignOn::Identity::queryInfo); m_identity->storeCredentials(); } -void CreateAccount::pluginError(const QString &error) +void CreateAccountJob::pluginError(const QString &error) { if (error.isEmpty()) { setError(-1); } else { setError(KJob::UserDefinedError); } setErrorText(error); // Delete the dialog emitResult(); } -void CreateAccount::sessionResponse(const SignOn::SessionData &/*data*/) +void CreateAccountJob::sessionResponse(const SignOn::SessionData &/*data*/) { qDebug() << "Received session response"; m_done = true; m_identity->queryInfo(); } -void CreateAccount::info(const SignOn::IdentityInfo &info) +void CreateAccountJob::info(const SignOn::IdentityInfo &info) { qDebug() << "Info:"; qDebug() << "\tId:" << info.id(); qDebug() << "\tcaption:" << info.caption(); qDebug() << "\towner:" << info.owner(); qDebug() << "\tuserName:" << info.userName(); if (!m_done) { return; } m_account->selectService(); if (m_account->displayName().isEmpty()) { m_account->setDisplayName(info.userName()); } m_account->setValue("username", info.userName()); m_account->setCredentialsId(info.id()); Accounts::AuthData authData = m_accInfo->authData(); m_account->setValue("auth/mechanism", authData.mechanism()); m_account->setValue("auth/method", authData.method()); QString base("auth/"); base.append(authData.method()); base.append("/"); base.append(authData.mechanism()); base.append("/"); QVariantMap data = authData.parameters(); QMapIterator i(data); while (i.hasNext()) { i.next(); m_account->setValue(base + i.key(), i.value()); } const Accounts::ServiceList services = m_account->services(); for (const Accounts::Service &service : services) { m_account->selectService(service); m_account->setEnabled(m_disabledServices.contains(service.name()) ? false : true); } 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 return; } qWarning() << "Error:"; qWarning() << "\t" << signOnError.message(); setError(KJob::UserDefinedError); setErrorText(i18n("There was an error while trying to process the request: %1", signOnError.message())); emitResult(); } -void CreateAccount::setProviderName(const QString &name) +void CreateAccountJob::setProviderName(const QString &name) { if (m_providerName != name) { m_providerName = name; Q_EMIT providerNameChanged(); } } diff --git a/src/jobs/createaccount.h b/src/lib/createaccountjob.h similarity index 92% rename from src/jobs/createaccount.h rename to src/lib/createaccountjob.h index 137a277..a86635b 100644 --- a/src/jobs/createaccount.h +++ b/src/lib/createaccountjob.h @@ -1,74 +1,76 @@ /************************************************************************************* * Copyright (C) 2013 by Alejandro Fiestas Olivares * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #ifndef CREATE_ACCOUNT_JOB_H #define CREATE_ACCOUNT_JOB_H +#include "kaccounts_export.h" + #include #include namespace Accounts { class Account; class Manager; class AccountService; } namespace SignOn { class Error; class Identity; class SessionData; 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); void start() override; private Q_SLOTS: void processSession(); void sessionError(const SignOn::Error &signOnError); void sessionResponse(const SignOn::SessionData &data); void info(const SignOn::IdentityInfo &info); void pluginFinished(const QString &screenName, const QString &secret, const QVariantMap &map); void pluginError(const QString &error); Q_SIGNALS: void providerNameChanged(); private: void loadPluginAndShowDialog(const QString &pluginName); QString m_providerName; QStringList m_disabledServices; Accounts::Manager *m_manager; Accounts::Account *m_account; Accounts::AccountService *m_accInfo; SignOn::Identity *m_identity; bool m_done; }; #endif //CREATE_ACCOUNT_JOB_H diff --git a/src/lib/uipluginsmanager.cpp b/src/lib/uipluginsmanager.cpp index 10a4f50..af8d48c 100644 --- a/src/lib/uipluginsmanager.cpp +++ b/src/lib/uipluginsmanager.cpp @@ -1,146 +1,146 @@ /************************************************************************************* * Copyright (C) 2015 by Martin Klapetek * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #include "uipluginsmanager.h" -#include "lib/kaccountsuiplugin.h" +#include "kaccountsuiplugin.h" #include #include #include #include #include #include #include #include using namespace KAccounts; class UiPluginsManagerPrivate { public: UiPluginsManagerPrivate(); ~UiPluginsManagerPrivate(); void loadPlugins(); QHash pluginsForNames; QHash pluginsForServices; bool pluginsLoaded; }; Q_GLOBAL_STATIC(UiPluginsManagerPrivate, s_instance) UiPluginsManagerPrivate::UiPluginsManagerPrivate() : pluginsLoaded(false) { } UiPluginsManagerPrivate::~UiPluginsManagerPrivate() { qDeleteAll(pluginsForNames.values()); } void UiPluginsManagerPrivate::loadPlugins() { QString pluginPath; const QStringList paths = QCoreApplication::libraryPaths(); for (const QString &libraryPath : paths) { QString path(libraryPath + QStringLiteral("/kaccounts/ui")); QDir dir(path); if (!dir.exists()) { continue; } const QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); for (const QString &fileName : entryList) { QPluginLoader loader(dir.absoluteFilePath(fileName)); if (!loader.load()) { qWarning() << "Could not create KAccountsUiPlugin: " << pluginPath; qWarning() << loader.errorString(); continue; } QObject *obj = loader.instance(); if (obj) { KAccountsUiPlugin *ui = qobject_cast(obj); if (!ui) { qDebug() << "Plugin could not be converted to an KAccountsUiPlugin"; qDebug() << pluginPath; continue; } qDebug() << "Adding plugin" << ui << fileName; const QWindowList topLevelWindows = QGuiApplication::topLevelWindows(); if (topLevelWindows.size() == 1) { QWindow *topLevelWindow = topLevelWindows.at(0); obj->setProperty("transientParent", QVariant::fromValue(topLevelWindow)); } else { qWarning() << "Unexpected topLevelWindows found:" << topLevelWindows.size() << "please report a bug"; } // When the plugin has finished building the UI, show it right away QObject::connect(ui, &KAccountsUiPlugin::uiReady, ui, &KAccountsUiPlugin::showNewAccountDialog, Qt::UniqueConnection); pluginsForNames.insert(fileName, ui); const auto services = ui->supportedServicesForConfig(); for (const QString &service : services) { qDebug() << " Adding service" << service; pluginsForServices.insert(service, ui); } } else { qDebug() << "Plugin could not creaate instance" << pluginPath; } } } pluginsLoaded = true; } QList UiPluginsManager::uiPlugins() { if (!s_instance->pluginsLoaded) { s_instance->loadPlugins(); } return s_instance->pluginsForNames.values(); } KAccountsUiPlugin* UiPluginsManager::pluginForName(const QString &name) { if (!s_instance->pluginsLoaded) { s_instance->loadPlugins(); } return s_instance->pluginsForNames.value(name + ".so"); } KAccountsUiPlugin* UiPluginsManager::pluginForService(const QString &service) { if (!s_instance->pluginsLoaded) { s_instance->loadPlugins(); } return s_instance->pluginsForServices.value(service); }