diff --git a/CMakeLists.txt b/CMakeLists.txt index fece687..1988462 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,57 +1,58 @@ project(KAccounts) cmake_minimum_required(VERSION 2.8.12) set(REQUIRED_QT_VERSION "5.7.0") set(REQUIRED_KF5_VERSION "5.4.0") find_package(ECM ${REQUIRED_KF5_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) enable_testing() set(KDE_APPLICATIONS_VERSION_MAJOR "19") set(KDE_APPLICATIONS_VERSION_MINOR "11") set(KDE_APPLICATIONS_VERSION_MICRO "70") set(KACCOUNTS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") set(KACCOUNTS_SOVERSION "1") set(ACCOUNTSQT_DEP_VERSION "1.13") set(SIGNONQT_DEP_VERSION "8.55") set(ACCOUNTSGLIB_DEP_VERSION "1.21") find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Widgets) find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED KCMUtils I18n CoreAddons DBusAddons Declarative) find_package(AccountsQt5 ${ACCOUNTSQT_DEP_VERSION} CONFIG) set_package_properties(AccountsQt5 PROPERTIES DESCRIPTION "Accounts management library for Qt applications" URL "https://gitlab.com/accounts-sso/libaccounts-qt" TYPE REQUIRED PURPOSE "Required for building this module") find_package(SignOnQt5 ${SIGNONQT_DEP_VERSION} CONFIG) set_package_properties(SignOnQt5 PROPERTIES DESCRIPTION "D-Bus service which performs user authentication on behalf of its clients" URL "https://gitlab.com/accounts-sso/signond" TYPE REQUIRED PURPOSE "Required for building this module") add_definitions (-fexceptions -DQT_NO_KEYWORDS) add_definitions(-DTRANSLATION_DOMAIN=\"kaccounts-integration\") +add_definitions(-DQT_NO_FOREACH) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMInstallIcons) include(FeatureSummary) include_directories(${ACCOUNTSQT_INCLUDE_DIRS} ${SIGNONQT_INCLUDE_DIRS}) remove_definitions(-DQT_NO_CAST_FROM_ASCII) add_subdirectory(src) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 1e8ca41..f8a7b18 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -1,157 +1,157 @@ /************************************************************************************* * 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 "daemon.h" #include "src/lib/kaccountsdplugin.h" #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(AccountsDaemonFactory, "accounts.json", registerPlugin();) AccountsDaemon::AccountsDaemon(QObject *parent, const QList&) : KDEDModule(parent) { QMetaObject::invokeMethod(this, "startDaemon", Qt::QueuedConnection); connect(KAccounts::accountsManager(), &Accounts::Manager::accountCreated, this, &AccountsDaemon::accountCreated); connect(KAccounts::accountsManager(), &Accounts::Manager::accountRemoved, this, &AccountsDaemon::accountRemoved); QStringList pluginPaths; - QStringList paths = QCoreApplication::libraryPaths(); - Q_FOREACH (const QString &libraryPath, paths) { + const QStringList paths = QCoreApplication::libraryPaths(); + for (const QString &libraryPath : paths) { QString path(libraryPath + QStringLiteral("/kaccounts/daemonplugins")); QDir dir(path); if (!dir.exists()) { continue; } - QStringList dirEntries = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); + const QStringList dirEntries = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); - Q_FOREACH(const QString &file, dirEntries) { + for (const QString &file : dirEntries) { pluginPaths.append(path + '/' + file); } } - Q_FOREACH (const QString &pluginPath, pluginPaths) { + for (const QString &pluginPath : qAsConst(pluginPaths)) { QPluginLoader loader(pluginPath); if (!loader.load()) { qWarning() << "Could not create KAccounts daemon plugin: " << pluginPath; qWarning() << loader.errorString(); continue; } QObject *obj = loader.instance(); if (obj) { KAccountsDPlugin *plugin = qobject_cast(obj); if (!plugin) { qDebug() << "Plugin could not be converted to an KAccountsDPlugin"; qDebug() << pluginPath; continue; } qDebug() << "Loaded KAccounts plugin" << pluginPath; m_plugins << plugin; } else { qDebug() << "Plugin could not creaate instance" << pluginPath; } } } AccountsDaemon::~AccountsDaemon() { qDeleteAll(m_plugins); } void AccountsDaemon::startDaemon() { qDebug(); - Accounts::AccountIdList accList = KAccounts::accountsManager()->accountList(); - Q_FOREACH(const Accounts::AccountId &id, accList) { + const Accounts::AccountIdList accList = KAccounts::accountsManager()->accountList(); + for (const Accounts::AccountId &id : accList) { monitorAccount(id); } } void AccountsDaemon::monitorAccount(const Accounts::AccountId id) { qDebug() << id; Accounts::Account *acc = KAccounts::accountsManager()->account(id); - Accounts::ServiceList services = acc->services(); - Q_FOREACH(const Accounts::Service &service, services) { + const Accounts::ServiceList services = acc->services(); + for (const Accounts::Service &service : services) { acc->selectService(service); } acc->selectService(); connect(acc, &Accounts::Account::enabledChanged, this, &AccountsDaemon::enabledChanged); } void AccountsDaemon::accountCreated(const Accounts::AccountId id) { qDebug() << id; monitorAccount(id); - Accounts::Account *acc = KAccounts::accountsManager()->account(id); - Accounts::ServiceList services = acc->enabledServices(); + const Accounts::Account *acc = KAccounts::accountsManager()->account(id); + const Accounts::ServiceList services = acc->enabledServices(); - Q_FOREACH(KAccountsDPlugin *plugin, m_plugins) { + for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { plugin->onAccountCreated(id, services); } } void AccountsDaemon::accountRemoved(const Accounts::AccountId id) { qDebug() << id; - Q_FOREACH(KAccountsDPlugin *plugin, m_plugins) { + for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { plugin->onAccountRemoved(id); } } void AccountsDaemon::enabledChanged(const QString &serviceName, bool enabled) { qDebug(); if (serviceName.isEmpty()) { qDebug() << "ServiceName is Empty"; return; } - Accounts::AccountId accId = qobject_cast(sender())->id(); + const Accounts::AccountId accId = qobject_cast(sender())->id(); - Accounts::Service service = KAccounts::accountsManager()->service(serviceName); + const Accounts::Service service = KAccounts::accountsManager()->service(serviceName); if (!enabled) { - Q_FOREACH(KAccountsDPlugin *plugin, m_plugins) { + for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { plugin->onServiceDisabled(accId, service); } } else { - Q_FOREACH(KAccountsDPlugin *plugin, m_plugins) { + for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { plugin->onServiceEnabled(accId, service); } } } #include "daemon.moc" diff --git a/src/daemon/kio-webdav/kioservices.cpp b/src/daemon/kio-webdav/kioservices.cpp index d6f7dd9..4f684b8 100644 --- a/src/daemon/kio-webdav/kioservices.cpp +++ b/src/daemon/kio-webdav/kioservices.cpp @@ -1,128 +1,128 @@ /************************************************************************************* * 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 "kioservices.h" #include "createnetattachjob.h" #include "createkioservice.h" #include "removekioservice.h" #include #include #include #include KIOServices::KIOServices(QObject *parent) : KAccountsDPlugin(parent) { } void KIOServices::onAccountCreated(const Accounts::AccountId accId, const Accounts::ServiceList &serviceList) { qDebug(); - Q_FOREACH(const Accounts::Service &service, serviceList) { + for (const Accounts::Service &service : serviceList) { if (service.serviceType() != QLatin1String("dav-storage")) { qDebug() << "Ignoring: " << service.serviceType(); continue; } if (isEnabled(accId, service.name())) { qDebug() << "Already configured: " << service.name(); continue; } qDebug() << "Creating: " << service.name() << "Of type: " << service.serviceType(); enableService(accId, service); } } void KIOServices::onAccountRemoved(const Accounts::AccountId accId) { qDebug(); QString accountId = QString::number(accId) + "_"; QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); path.append(QStringLiteral("/remoteview/")); QDirIterator i(path, QDir::NoDotAndDotDot | QDir::Files); while (i.hasNext()) { i.next(); if (!i.fileName().startsWith(accountId)) { continue; } QString serviceName = i.fileName(); qDebug() << "Removing: " << serviceName; serviceName = serviceName.mid(accountId.count(), serviceName.indexOf(QLatin1String(".desktop")) - accountId.count()); qDebug() << "Removing N: " << serviceName; disableService(accId, serviceName); } } void KIOServices::onServiceEnabled(const Accounts::AccountId accId, const Accounts::Service &service) { if (service.serviceType() != QLatin1String("dav-storage")) { qDebug() << "Ignoring: " << service.serviceType(); return; } if (isEnabled(accId, service.name())) { qDebug() << "Already configured: " << service.name(); return; } enableService(accId, service); } void KIOServices::onServiceDisabled(const Accounts::AccountId accId, const Accounts::Service &service) { if (service.serviceType() != QLatin1String("dav-storage")) { qDebug() << "Ignoring: " << service.serviceType(); return; } if (!isEnabled(accId, service.name())) { qDebug() << "Already not configured: " << service.name(); return; } disableService(accId, service.name()); } void KIOServices::enableService(const Accounts::AccountId accId, const Accounts::Service &service) { CreateKioService *job = new CreateKioService(this); job->setAccountId(accId); job->setServiceName(service.name()); job->setServiceType(service.serviceType()); job->start(); } void KIOServices::disableService(const Accounts::AccountId accId, const QString &serviceName) { RemoveKioService *job = new RemoveKioService(this); job->setServiceName(serviceName); job->setAccountId(accId); job->start(); } bool KIOServices::isEnabled(const Accounts::AccountId accId, const QString &serviceName) { QString uniqueId(QString::number(accId) + "_" + serviceName); QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); path += QStringLiteral("/remoteview/") + uniqueId + QStringLiteral(".desktop"); return QFile::exists(path); } diff --git a/src/daemon/kio-webdav/removenetattachjob.cpp b/src/daemon/kio-webdav/removenetattachjob.cpp index 3854055..d41a2fe 100644 --- a/src/daemon/kio-webdav/removenetattachjob.cpp +++ b/src/daemon/kio-webdav/removenetattachjob.cpp @@ -1,114 +1,114 @@ /************************************************************************************* * Copyright (C) 2012 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 "removenetattachjob.h" #include #include #include #include #include #include #include #include using namespace KWallet; RemoveNetAttachJob::RemoveNetAttachJob(QObject *parent) : KJob(parent) , m_wallet(0) { } RemoveNetAttachJob::~RemoveNetAttachJob() { delete m_wallet; } void RemoveNetAttachJob::start() { QMetaObject::invokeMethod(this, "removeNetAttach", Qt::QueuedConnection); } void RemoveNetAttachJob::removeNetAttach() { WId windowId = 0; if (qApp->activeWindow()) { windowId = qApp->activeWindow()->winId(); } m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), windowId, Wallet::Asynchronous); connect(m_wallet, &KWallet::Wallet::walletOpened, this, &RemoveNetAttachJob::walletOpened); } void RemoveNetAttachJob::walletOpened(bool opened) { qDebug(); if (!opened) { setError(-1); setErrorText("Can't open wallet"); emitResult(); return; } deleteDesktopFile(); } void RemoveNetAttachJob::deleteDesktopFile() { QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); path.append(QStringLiteral("/remoteview/") + m_uniqueId + QStringLiteral(".desktop")); KConfig _desktopFile(path, KConfig::SimpleConfig); KConfigGroup desktopFile(&_desktopFile, "Desktop Entry"); QUrl url(desktopFile.readEntry("URL", QUrl())); Q_ASSERT(!url.isEmpty()); qDebug() << url.userName() << url.host() << url; QFile::remove(path); org::kde::KDirNotify::emitFilesRemoved(QList() << QUrl("remote:/" + m_uniqueId)); QString walletUrl("webdav"); walletUrl.append("-"); walletUrl.append(url.userName()); walletUrl.append("@"); walletUrl.append(url.host()); walletUrl.append(":-1");//Overwrite the first option m_wallet->setFolder("Passwords"); - QStringList entries = m_wallet->entryList(); - Q_FOREACH(const QString &entry, entries) { + const QStringList entries = m_wallet->entryList(); + for (const QString &entry : entries) { if (!entry.startsWith(walletUrl)) { continue; } m_wallet->removeEntry(entry); } emitResult(); } QString RemoveNetAttachJob::uniqueId() const { return m_uniqueId; } void RemoveNetAttachJob::setUniqueId(const QString &uniqueId) { m_uniqueId = uniqueId; } diff --git a/src/jobs/createaccount.cpp b/src/jobs/createaccount.cpp index 97ca975..429bb62 100644 --- a/src/jobs/createaccount.cpp +++ b/src/jobs/createaccount.cpp @@ -1,238 +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 "uipluginsmanager.h" #include #include #include #include #include #include #include #include CreateAccount::CreateAccount(QObject* parent) : CreateAccount(QString(), parent) { } CreateAccount::CreateAccount(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() { qDebug() << m_providerName; QMetaObject::invokeMethod(this, "processSession"); } void CreateAccount::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::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); session->process(sessionData, m_accInfo->authData().mechanism()); } } void CreateAccount::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); ui->setProviderName(m_providerName); ui->init(KAccountsUiPlugin::NewAccountDialog); } void CreateAccount::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); - Q_FOREACH (const QString &key, data.keys()) { + 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); m_done = true; connect(m_identity, &SignOn::Identity::credentialsStored, m_identity, &SignOn::Identity::queryInfo); m_identity->storeCredentials(); } void CreateAccount::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*/) { qDebug() << "Received session response"; m_done = true; m_identity->queryInfo(); } void CreateAccount::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()); } - Accounts::ServiceList services = m_account->services(); - Q_FOREACH(const Accounts::Service &service, services) { + 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); } void CreateAccount::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) { if (m_providerName != name) { m_providerName = name; Q_EMIT providerNameChanged(); } } diff --git a/src/lib/uipluginsmanager.cpp b/src/lib/uipluginsmanager.cpp index 475d773..b819ee0 100644 --- a/src/lib/uipluginsmanager.cpp +++ b/src/lib/uipluginsmanager.cpp @@ -1,145 +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 #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; - QStringList paths = QCoreApplication::libraryPaths(); - Q_FOREACH (const QString &libraryPath, paths) { + const QStringList paths = QCoreApplication::libraryPaths(); + for (const QString &libraryPath : paths) { QString path(libraryPath + QStringLiteral("/kaccounts/ui")); QDir dir(path); if (!dir.exists()) { continue; } - QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); - Q_FOREACH (const QString &fileName, entryList) { + 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); - Q_FOREACH (const QString &service, ui->supportedServicesForConfig()) { + 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); }