Warning, file /network/kaccounts-providers/plugins/nextcloud-ui/nextcloud.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Rituka Patwal <ritukapatwal21@gmail.com>
0003  *  SPDX-FileCopyrightText: 2015 Martin Klapetek <mklapetek@kde.org>
0004  *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "nextcloud.h"
0010 #include "nextcloudcontroller.h"
0011 
0012 #include <KLocalizedContext>
0013 #include <KLocalizedString>
0014 #include <KPackage/PackageLoader>
0015 
0016 #include <QIcon>
0017 #include <QQmlApplicationEngine>
0018 #include <QQmlContext>
0019 #include <QWindow>
0020 
0021 NextcloudWizard::NextcloudWizard(QObject *parent)
0022     : KAccountsUiPlugin(parent)
0023 {
0024     qmlRegisterUncreatableType<NextcloudController>("org.kde.kaccounts.nextcloud", 1, 0, "NextcloudController", QStringLiteral("Only for enums"));
0025 }
0026 
0027 NextcloudWizard::~NextcloudWizard()
0028 {
0029 }
0030 
0031 void NextcloudWizard::init(KAccountsUiPlugin::UiType type)
0032 {
0033     QtWebEngineQuick::initialize();
0034 
0035     if (type == KAccountsUiPlugin::NewAccountDialog) {
0036         const QString packagePath(QStringLiteral("org.kde.kaccounts.nextcloud"));
0037         m_engine = new QQmlApplicationEngine;
0038 
0039         auto ctx = new KLocalizedContext(m_engine);
0040         ctx->setTranslationDomain(packagePath);
0041         m_engine->rootContext()->setContextObject(ctx);
0042 
0043         KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML"));
0044         package.setPath(packagePath);
0045         m_data = package.metadata();
0046         NextcloudController *helper = new NextcloudController(m_engine);
0047 
0048         connect(helper, &NextcloudController::wizardFinished, this, [this](const QString &username, const QString &password, const QVariantMap &data) {
0049             m_engine->deleteLater();
0050             Q_EMIT success(username, password, data);
0051         });
0052 
0053         connect(helper, &NextcloudController::wizardCancelled, this, [this] {
0054             m_engine->deleteLater();
0055             Q_EMIT canceled();
0056         });
0057 
0058         m_engine->rootContext()->setContextProperty(QStringLiteral("helper"), helper);
0059         m_engine->load(QUrl::fromLocalFile(package.filePath("mainscript")));
0060 
0061         if (!m_data.isValid()) {
0062             return;
0063         }
0064 
0065         Q_EMIT uiReady();
0066     }
0067 }
0068 
0069 void NextcloudWizard::setProviderName(const QString &providerName)
0070 {
0071     Q_UNUSED(providerName)
0072 }
0073 
0074 void NextcloudWizard::showNewAccountDialog()
0075 {
0076     QWindow *window = qobject_cast<QWindow *>(m_engine->rootObjects().first());
0077     if (window) {
0078         window->setTransientParent(transientParent());
0079         window->show();
0080         window->requestActivate();
0081         window->setTitle(m_data.name());
0082         window->setIcon(QIcon::fromTheme(m_data.iconName()));
0083     }
0084 }
0085 
0086 void NextcloudWizard::showConfigureAccountDialog(const quint32 accountId)
0087 {
0088     Q_UNUSED(accountId)
0089 }
0090 
0091 QStringList NextcloudWizard::supportedServicesForConfig() const
0092 {
0093     return QStringList();
0094 }