nextcloud.cpp 2.29 KB
Newer Older
1 2 3 4 5 6 7
/*
 *  SPDX-FileCopyrightText: 2019 Rituka Patwal <ritukapatwal21@gmail.com>
 *  SPDX-FileCopyrightText: 2015 Martin Klapetek <mklapetek@kde.org>
 *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */
Rituka Patwal's avatar
Rituka Patwal committed
8 9

#include "nextcloud.h"
10
#include "nextcloudcontroller.h"
Rituka Patwal's avatar
Rituka Patwal committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

#include <KLocalizedString>
#include <KDeclarative/QmlObject>

#include <QQmlEngine>
#include <QQmlContext>

NextcloudWizard::NextcloudWizard(QObject *parent)
    : KAccountsUiPlugin(parent)
{
}

NextcloudWizard::~NextcloudWizard()
{
}

void NextcloudWizard::init(KAccountsUiPlugin::UiType type)
{
    if (type == KAccountsUiPlugin::NewAccountDialog) {

        const QString packagePath("org.kde.kaccounts.nextcloud");

        m_object = new KDeclarative::QmlObject();
        m_object->setTranslationDomain(packagePath);
        m_object->setInitializationDelayed(true);
        m_object->loadPackage(packagePath);

38 39 40
        NextcloudController *helper = new NextcloudController(m_object);
        connect(helper, &NextcloudController::wizardFinished, this, &NextcloudWizard::success);
        connect(helper, &NextcloudController::wizardFinished, [=] {
Rituka Patwal's avatar
Rituka Patwal committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
            QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
            if (window) {
                window->close();
            }
            m_object->deleteLater();
        });
        m_object->engine()->rootContext()->setContextProperty("helper", helper);

        m_object->completeInitialization();

        if (!m_object->package().metadata().isValid()) {
            return;
        }

        Q_EMIT uiReady();
    }

}

void NextcloudWizard::setProviderName(const QString &providerName)
{
Nicolas Fella's avatar
Nicolas Fella committed
62
    Q_UNUSED(providerName)
Rituka Patwal's avatar
Rituka Patwal committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
}

void NextcloudWizard::showNewAccountDialog()
{
    QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
    if (window) {
        window->setTransientParent(transientParent());
        window->show();
        window->requestActivate();
        window->setTitle(m_object->package().metadata().name());
        window->setIcon(QIcon::fromTheme(m_object->package().metadata().iconName()));
    }
}

void NextcloudWizard::showConfigureAccountDialog(const quint32 accountId)
{
79
    Q_UNUSED(accountId)
Rituka Patwal's avatar
Rituka Patwal committed
80 81 82 83 84 85
}

QStringList NextcloudWizard::supportedServicesForConfig() const
{
    return QStringList();
}