Commit 6da76d27 authored by Martin Klapetek's avatar Martin Klapetek
Browse files

[owncloud] Remove the QWidgets wizard

The OwnCloud dialog is now QML only
parent a3180be0
project (owncloud-plugin-kaccounts)
project (owncloud-ui-plugin)
include_directories (${CMAKE_CURRENT_BUILD_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
......@@ -7,15 +7,6 @@ include_directories (${CMAKE_CURRENT_BUILD_DIR}
set (owncloud_plugin_kaccounts_SRCS
owncloud.cpp
qmlhelper.cpp
pages/basicinfo.cpp
pages/connecting.cpp
pages/oservices.cpp
)
ki18n_wrap_ui(owncloud_plugin_kaccounts_SRCS
pages/basicinfo.ui
pages/connecting.ui
pages/oservices.ui
)
add_library (owncloud_plugin_kaccounts MODULE
......@@ -24,15 +15,10 @@ add_library (owncloud_plugin_kaccounts MODULE
target_link_libraries (owncloud_plugin_kaccounts
Qt5::Core
Qt5::Widgets
KF5::KIOCore
KF5::KIOWidgets
KF5::CoreAddons
KF5::WidgetsAddons
KF5::IconThemes
KF5::I18n
KF5::Declarative
kaccounts
KAccounts
${ACCOUNTSQT_LIBRARIES}
${SIGNONQT_LIBRARIES}
)
......
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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 "oaccountwidget.h"
#include "google/pages/serviceoption.h"
#include "owncloud/jobs/ocreatecontact.h"
#include "owncloud/jobs/ocreatecalendar.h"
#include "owncloud/jobs/ocreatefile.h"
#include "owncloud/jobs/oremovefile.h"
#include "owncloud/jobs/oremovecalendar.h"
#include "owncloud/jobs/oremovecontact.h"
#include <QDebug>
OAccountWidget::OAccountWidget(KConfigGroup group, QWidget *parent)
: QWidget(parent)
, m_config(group)
{
setupUi(this);
int status = 0;
KConfigGroup services = m_config.group("services");
QStringList keys = services.keyList();
Q_FOREACH(const QString &key, keys) {
status = services.readEntry(key, 0);
m_serviceWidgets[key] = new ServiceOption(key, key, this);
m_serviceWidgets[key]->setStatus(status);
connect(m_serviceWidgets[key], SIGNAL(toggled(QString,bool)),
this, SLOT(serviceChanged(QString,bool)));
d_layout->addWidget(m_serviceWidgets[key]);
}
}
OAccountWidget::~OAccountWidget()
{
}
void OAccountWidget::serviceChanged(const QString &service, bool enabled)
{
if (service == "Calendar") {
modifyCalendar(enabled);
return;
}
if (service == "Contact") {
modifyContact(enabled);
return;
}
if (service == "File") {
modifyFile(enabled);
return;
}
qWarning() << "Not implemented service: " << service;
}
void OAccountWidget::updateService(const QString &name)
{
int status = m_config.group("services").readEntry(name, -1);
m_serviceWidgets[name]->setStatus(status);
}
void OAccountWidget::modifyCalendar(bool enabled)
{
if (!enabled) {
ORemoveCalendar *removeCalendar = new ORemoveCalendar(m_config, this);
connect(removeCalendar, SIGNAL(finished(KJob*)), this, SLOT(updateCalendar()));
removeCalendar->start();
return;
}
OCreateCalendar *createCalendar = new OCreateCalendar(m_config, this);
connect(createCalendar, SIGNAL(finished(KJob*)), this, SLOT(updateCalendar()));
createCalendar->start();
}
void OAccountWidget::modifyFile(bool enabled)
{
if (!enabled) {
ORemoveFile *removeFile = new ORemoveFile(m_config, this);
connect(removeFile, SIGNAL(finished(KJob*)), this, SLOT(updateFile()));
removeFile->start();
return;
}
OCreateFile *createFile = new OCreateFile(m_config, this);
connect(createFile, SIGNAL(finished(KJob*)), this, SLOT(updateFile()));
createFile->start();
}
void OAccountWidget::modifyContact(bool enabled)
{
if (!enabled) {
ORemoveContact *removeContact = new ORemoveContact(m_config, this);
connect(removeContact, SIGNAL(finished(KJob*)), this, SLOT(updateContact()));
removeContact->start();
return;
}
OCreateContact *createContact = new OCreateContact(m_config, this);
connect(createContact, SIGNAL(finished(KJob*)), this, SLOT(updateContact()));
createContact->start();
}
void OAccountWidget::updateCalendar()
{
updateService("Calendar");
}
void OAccountWidget::updateFile()
{
updateService("File");
}
void OAccountWidget::updateContact()
{
updateService("Contact");
}
void OAccountWidget::updateAll()
{
KConfigGroup services = m_config.group("services");
QStringList keys = services.keyList();
Q_FOREACH(const QString &key, keys) {
updateService(key);
}
}
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* 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 O_ACCOUNTWIDGET_H
#define O_ACCOUNTWIDGET_H
#include "ui_services.h"
#include <QWidget>
#include <KConfigGroup>
class ServiceOption;
class OAccountWidget : public QWidget, Ui::Services
{
Q_OBJECT
public:
explicit OAccountWidget(KConfigGroup group, QWidget *parent);
virtual ~OAccountWidget();
public Q_SLOTS:
void serviceChanged(const QString &service, bool enabled);
private Q_SLOTS:
void updateCalendar();
void updateContact();
void updateFile();
void updateAll();
private:
void modifyCalendar(bool enabled);
void modifyContact(bool enabled);
void modifyFile(bool enabled);
void updateService(const QString &name);
private:
KConfigGroup m_config;
QHash<QString, ServiceOption*> m_serviceWidgets;
};
#endif //O_ACCOUNTWIDGET_H
......@@ -18,34 +18,21 @@
*************************************************************************************/
#include "owncloud.h"
#include "pages/basicinfo.h"
#include "pages/connecting.h"
#include "pages/oservices.h"
#include "qmlhelper.h"
#include <klocalizedstring.h>
#include <kstandardguiitem.h>
#include <KLocalizedString>
#include <KDeclarative/QmlObject>
#include <QQmlEngine>
#include <QQmlContext>
#include <QPushButton>
#include <QWizard>
// #include <KWallet/Wallet>
// using namespace KWallet;
OwnCloudWizard::OwnCloudWizard(QWidget *parent)
OwnCloudWizard::OwnCloudWizard(QObject *parent)
: KAccountsUiPlugin(parent)
{
}
OwnCloudWizard::~OwnCloudWizard()
{
}
void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
......@@ -75,41 +62,6 @@ void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
if (!m_object->package().metadata().isValid()) {
return;
}
/*
m_wizard = new QWizard();
m_wizard->setWindowTitle(i18n("Add ownCloud Account"));
BasicInfo *basicInfo = new BasicInfo(m_wizard);
Connecting *connecting = new Connecting(m_wizard);
OServices *services = new OServices(m_wizard);
m_wizard->addPage(basicInfo);
m_wizard->addPage(connecting);
m_wizard->addPage(services);
QPushButton *backButton = new QPushButton(m_wizard);
QPushButton *forwardButton = new QPushButton(m_wizard);
QPushButton *applyButton = new QPushButton(m_wizard);
QPushButton *cancelButton = new QPushButton(m_wizard);
KGuiItem::assign(backButton, KStandardGuiItem::back());
KGuiItem::assign(forwardButton, KStandardGuiItem::forward());
KGuiItem::assign(applyButton, KStandardGuiItem::apply());
KGuiItem::assign(cancelButton, KStandardGuiItem::cancel());
m_wizard->setButton(QWizard::BackButton, backButton);
m_wizard->setButton(QWizard::NextButton, forwardButton);
m_wizard->setButton(QWizard::FinishButton, applyButton);
m_wizard->setButton(QWizard::CancelButton, cancelButton);
// We do not want "Forward" as text
m_wizard->setButtonText(QWizard::NextButton, i18nc("Action to go to the next page on the wizard", "Next"));
m_wizard->setButtonText(QWizard::FinishButton, i18nc("Action to finish the wizard", "Finish"));
m_wizard->setOption(QWizard::NoDefaultButton, false);
connect(m_wizard, &QWizard::accepted, this, &OwnCloudWizard::done);*/
Q_EMIT uiReady();
}
......@@ -124,9 +76,6 @@ void OwnCloudWizard::setProviderName(const QString &providerName)
void OwnCloudWizard::showNewAccountDialog()
{
// if (m_wizard) {
// m_wizard->exec();
// }
QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
if (window) {
window->setTransientParent(transientParent());
......@@ -146,60 +95,3 @@ QStringList OwnCloudWizard::supportedServicesForConfig() const
{
return QStringList();
}
void OwnCloudWizard::done()
{
QVariantMap data;
data.insert("server", m_wizard->property("server"));
Q_FOREACH (const QString &disabledService, m_wizard->property("disabledServices").toStringList()) {
data.insert("__service/" + disabledService, false);
}
const QString username = m_wizard->property("username").toString();
QUrl carddavUrl = m_wizard->property("server").toUrl();
carddavUrl.setPath(carddavUrl.path() + QString("/remote.php/carddav/addressbooks/%1").arg(username));
data.insert("carddavUrl", carddavUrl);
Q_EMIT success(username, m_wizard->property("password").toString(), data);
}
void OwnCloudWizard::setUsername(const QString &username)
{
m_username = username;
}
void OwnCloudWizard::setPassword(const QString &password)
{
m_password = password;
}
void OwnCloudWizard::setServer(const QUrl &server)
{
m_server = server;
}
const QString OwnCloudWizard::username() const
{
return m_username;
}
const QString OwnCloudWizard::password() const
{
return m_password;
}
const QUrl OwnCloudWizard::server() const
{
return m_server;
}
void OwnCloudWizard::activateOption(const QString &name, bool checked)
{
if (!checked) {
m_services[name] = 0;
return;
}
m_services[name] = 2;
}
......@@ -23,9 +23,7 @@
#include <QUrl>
#include <QHash>
#include "../lib/kaccountsuiplugin.h"
class QWizard;
#include <kaccountsuiplugin.h>
namespace KDeclarative {
class QmlObject;
......@@ -38,7 +36,7 @@ class OwnCloudWizard : public KAccountsUiPlugin
Q_INTERFACES(KAccountsUiPlugin)
public:
explicit OwnCloudWizard(QWidget *parent = 0);
explicit OwnCloudWizard(QObject *parent = 0);
virtual ~OwnCloudWizard();
virtual void init(KAccountsUiPlugin::UiType type) Q_DECL_OVERRIDE;
......@@ -47,28 +45,8 @@ public:
virtual void showConfigureAccountDialog(const quint32 accountId) Q_DECL_OVERRIDE;
virtual QStringList supportedServicesForConfig() const Q_DECL_OVERRIDE;
void done();
void setUsername(const QString &username);
void setPassword(const QString &password);
void setServer(const QUrl &server);
const QString username() const;
const QString password() const;
const QUrl server() const;
void activateOption(const QString &name, bool checked);
Q_SIGNALS:
void newAccount(const QString &type, const QString &name);
private:
QWizard *m_wizard;
QString m_username;
QString m_password;
QUrl m_server;
QString m_providerName;
QHash<QString, int> m_services;
KDeclarative::QmlObject *m_object;
};
......
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* Copyright (C) 2015 by Martin Klapetek <mklapetek@kde.org> *
* *
* 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 "basicinfo.h"
#include "../owncloud.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTimer>
#include <KPixmapSequenceOverlayPainter>
#include <KPixmapSequence>
#include <KIO/Job>
#include <kio/global.h>
#include <KIconLoader>
BasicInfo::BasicInfo(QWizard *parent)
: QWizardPage(parent)
, m_validServer(false)
, m_painter(new KPixmapSequenceOverlayPainter(this))
, m_wizard(parent)
, m_timer(new QTimer(this))
{
setupUi(this);
icon->setPixmap(QIcon::fromTheme("owncloud").pixmap(32, 32));
int lineEditHeight = server->sizeHint().height();
QSize workingSize(lineEditHeight, lineEditHeight);
working->setMinimumSize(workingSize);
m_painter->setWidget(working);
m_painter->setSequence(KIconLoader::global()->loadPixmapSequence(QStringLiteral("process-working"), 22));
m_timer->setInterval(2000);
m_timer->setSingleShot(true);
username->setFocus();
connect(server, &QLineEdit::textChanged, [=]{setWorking(true);});
connect(server, SIGNAL(textChanged(QString)), m_timer, SLOT(start()));
connect(m_timer, SIGNAL(timeout()), this, SLOT(checkServer()));
connect(username, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
connect(password, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
}
BasicInfo::~BasicInfo()
{
}
void BasicInfo::initializePage()
{
QList <QWizard::WizardButton> list;
list << QWizard::Stretch;
list << QWizard::NextButton;
list << QWizard::CancelButton;
m_wizard->setButtonLayout(list);
}
bool BasicInfo::validatePage()
{
if (!validData()) {
return false;
}
m_wizard->setProperty("username", username->text());
m_wizard->setProperty("password", password->text());
m_wizard->setProperty("server", m_server);
return true;
}
bool BasicInfo::isComplete() const
{
return validData();
}
void BasicInfo::checkServer()
{
if (!server->text().isEmpty()) {
checkServer(server->text());
}
}
bool BasicInfo::validData() const
{
if (username->text().isEmpty() || password->text().isEmpty()) {
return false;
}
if (!m_validServer) {
return false;
}
return true;
}
void BasicInfo::checkServer(const QString &path)
{
QString fixedUrl;
if (!path.startsWith("http://") && !path.startsWith("https://")) {
fixedUrl.append("https://");
fixedUrl.append(path);
} else {
fixedUrl = path;
}
m_json.clear();
QUrl url(fixedUrl);
url = url.adjusted(QUrl::StripTrailingSlash);
url.setPath(url.path() + '/' + "status.php");
if (url.host().isEmpty()) {
return;
}
checkServer(url);
}
void BasicInfo::checkServer(const QUrl &url)
{
qDebug() << url;
setResult(false);
setWorking(true);
KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
job->setUiDelegate(0);
connect(job, SIGNAL(data(KIO::Job*,QByteArray)), SLOT(dataReceived(KIO::Job*,QByteArray)));
connect(job, SIGNAL(finished(KJob*)), this, SLOT(fileChecked(KJob*)));
}
void BasicInfo::figureOutServer(const QUrl &url)
{
if (/*url == QLatin1String("/") ||*/ url.isEmpty()) {
setResult(false);
return;
}
m_json.clear();
qDebug() << "Received url to figure out:" << url;
// This needs 2x up cause first it just removes the status.php
// and only the second call actually moves up
QUrl urlUp = KIO::upUrl(KIO::upUrl(url));
urlUp.setPath(urlUp.path() + '/' + "status.php");
if (urlUp != url) {
checkServer(urlUp.adjusted(QUrl::NormalizePathSegments));
} else {
setResult(false);
}
}
void BasicInfo::dataReceived(KIO::Job *job, const QByteArray &data)
{