owncloud.cpp 2.22 KB
Newer Older
1 2 3 4 5 6
/*
 *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
 *  SPDX-FileCopyrightText: 2015 Martin Klapetek <mklapetek@kde.org>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */
Martin Klapetek's avatar
Martin Klapetek committed
7 8

#include "owncloud.h"
9
#include "owncloudcontroller.h"
Martin Klapetek's avatar
Martin Klapetek committed
10

11
#include <KLocalizedString>
12 13 14 15
#include <KDeclarative/QmlObject>

#include <QQmlEngine>
#include <QQmlContext>
Luca Beltrame's avatar
Luca Beltrame committed
16
#include <QWindow>
Martin Klapetek's avatar
Martin Klapetek committed
17

18
OwnCloudWizard::OwnCloudWizard(QObject *parent)
Martin Klapetek's avatar
Martin Klapetek committed
19 20 21 22 23 24 25 26 27 28 29
    : KAccountsUiPlugin(parent)
{
}

OwnCloudWizard::~OwnCloudWizard()
{
}

void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
{
    if (type == KAccountsUiPlugin::NewAccountDialog) {
30 31 32 33 34 35 36 37

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

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

38 39 40
        OwncloudController *helper = new OwncloudController(m_object);
        connect(helper, &OwncloudController::wizardFinished, this, &OwnCloudWizard::success);
        connect(helper, &OwncloudController::wizardFinished, [=] {
41 42 43 44 45 46
            QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
            if (window) {
                window->close();
            }
            m_object->deleteLater();
        });
47 48 49 50 51 52 53
        m_object->engine()->rootContext()->setContextProperty("helper", helper);

        m_object->completeInitialization();

        if (!m_object->package().metadata().isValid()) {
            return;
        }
Martin Klapetek's avatar
Martin Klapetek committed
54 55 56 57 58 59 60 61

        Q_EMIT uiReady();
    }

}

void OwnCloudWizard::setProviderName(const QString &providerName)
{
Nicolas Fella's avatar
Nicolas Fella committed
62
    Q_UNUSED(providerName)
Martin Klapetek's avatar
Martin Klapetek committed
63 64 65 66
}

void OwnCloudWizard::showNewAccountDialog()
{
67 68
    QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
    if (window) {
69
        window->setTransientParent(transientParent());
70 71 72 73
        window->show();
        window->requestActivate();
        window->setTitle(m_object->package().metadata().name());
        window->setIcon(QIcon::fromTheme(m_object->package().metadata().iconName()));
Martin Klapetek's avatar
Martin Klapetek committed
74 75 76 77 78
    }
}

void OwnCloudWizard::showConfigureAccountDialog(const quint32 accountId)
{
79
    Q_UNUSED(accountId)
Martin Klapetek's avatar
Martin Klapetek committed
80 81 82 83 84 85
}

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