summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Klapetek <[email protected]>2015-10-15 16:58:53 -0400
committerMartin Klapetek <[email protected]>2015-10-15 16:58:53 -0400
commita3180be07bca0b8fa2a371182706d8aafc54e1d6 (patch)
tree8460dc6e0bc050f18510a1e0ce3d5395e68b2fca
parent78f998cae87a303fa7d9c0012fb55848949ecb59 (diff)
parentae6e851264aa0a9b445b38a0d7e3d51c41ad9a6d (diff)
Merge the owncloud UI plugin from kaccounts-integration
-rw-r--r--plugins/owncloud-ui/CMakeLists.txt44
-rw-r--r--plugins/owncloud-ui/oaccountwidget.cpp146
-rw-r--r--plugins/owncloud-ui/oaccountwidget.h59
-rw-r--r--plugins/owncloud-ui/owncloud.cpp205
-rw-r--r--plugins/owncloud-ui/owncloud.h76
-rw-r--r--plugins/owncloud-ui/package/contents/ui/BasicInfo.qml112
-rw-r--r--plugins/owncloud-ui/package/contents/ui/Services.qml46
-rw-r--r--plugins/owncloud-ui/package/contents/ui/main.qml100
-rw-r--r--plugins/owncloud-ui/package/metadata.desktop38
-rw-r--r--plugins/owncloud-ui/pages/basicinfo.cpp225
-rw-r--r--plugins/owncloud-ui/pages/basicinfo.h72
-rw-r--r--plugins/owncloud-ui/pages/basicinfo.ui129
-rw-r--r--plugins/owncloud-ui/pages/connecting.cpp87
-rw-r--r--plugins/owncloud-ui/pages/connecting.h48
-rw-r--r--plugins/owncloud-ui/pages/connecting.ui100
-rw-r--r--plugins/owncloud-ui/pages/oservices.cpp80
-rw-r--r--plugins/owncloud-ui/pages/oservices.h48
-rw-r--r--plugins/owncloud-ui/pages/oservices.ui83
-rw-r--r--plugins/owncloud-ui/qmlhelper.cpp242
-rw-r--r--plugins/owncloud-ui/qmlhelper.h77
20 files changed, 2017 insertions, 0 deletions
diff --git a/plugins/owncloud-ui/CMakeLists.txt b/plugins/owncloud-ui/CMakeLists.txt
new file mode 100644
index 0000000..e69f6e1
--- /dev/null
+++ b/plugins/owncloud-ui/CMakeLists.txt
@@ -0,0 +1,44 @@
+project (owncloud-plugin-kaccounts)
+
+include_directories (${CMAKE_CURRENT_BUILD_DIR}
+ ${CMAKE_CURRENT_SOURCE_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
+ ${owncloud_plugin_kaccounts_SRCS}
+)
+
+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
+ ${ACCOUNTSQT_LIBRARIES}
+ ${SIGNONQT_LIBRARIES}
+)
+
+# Install:
+install (TARGETS owncloud_plugin_kaccounts
+ DESTINATION ${PLUGIN_INSTALL_DIR}/kaccounts/ui
+)
+kpackage_install_package(package org.kde.kaccounts.owncloud genericqml)
diff --git a/plugins/owncloud-ui/oaccountwidget.cpp b/plugins/owncloud-ui/oaccountwidget.cpp
new file mode 100644
index 0000000..51343ee
--- /dev/null
+++ b/plugins/owncloud-ui/oaccountwidget.cpp
@@ -0,0 +1,146 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * *
+ * 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);
+ }
+}
diff --git a/plugins/owncloud-ui/oaccountwidget.h b/plugins/owncloud-ui/oaccountwidget.h
new file mode 100644
index 0000000..0832c08
--- /dev/null
+++ b/plugins/owncloud-ui/oaccountwidget.h
@@ -0,0 +1,59 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * *
+ * 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
diff --git a/plugins/owncloud-ui/owncloud.cpp b/plugins/owncloud-ui/owncloud.cpp
new file mode 100644
index 0000000..877627c
--- /dev/null
+++ b/plugins/owncloud-ui/owncloud.cpp
@@ -0,0 +1,205 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 "owncloud.h"
+#include "pages/basicinfo.h"
+#include "pages/connecting.h"
+#include "pages/oservices.h"
+#include "qmlhelper.h"
+
+#include <klocalizedstring.h>
+#include <kstandardguiitem.h>
+#include <KDeclarative/QmlObject>
+
+#include <QQmlEngine>
+#include <QQmlContext>
+
+#include <QPushButton>
+#include <QWizard>
+
+// #include <KWallet/Wallet>
+
+// using namespace KWallet;
+
+OwnCloudWizard::OwnCloudWizard(QWidget *parent)
+ : KAccountsUiPlugin(parent)
+{
+
+}
+
+OwnCloudWizard::~OwnCloudWizard()
+{
+
+}
+
+void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
+{
+ if (type == KAccountsUiPlugin::NewAccountDialog) {
+
+ const QString packagePath("org.kde.kaccounts.owncloud");
+
+ m_object = new KDeclarative::QmlObject();
+ m_object->setTranslationDomain(packagePath);
+ m_object->setInitializationDelayed(true);
+ m_object->loadPackage(packagePath);
+
+ QmlHelper *helper = new QmlHelper(m_object);
+ connect(helper, &QmlHelper::wizardFinished, this, &OwnCloudWizard::success);
+ connect(helper, &QmlHelper::wizardFinished, [=] {
+ 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;
+ }
+ /*
+ 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();
+ }
+
+}
+
+void OwnCloudWizard::setProviderName(const QString &providerName)
+{
+ //TODO: unused?
+ m_providerName = providerName;
+}
+
+void OwnCloudWizard::showNewAccountDialog()
+{
+// if (m_wizard) {
+// m_wizard->exec();
+// }
+ 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 OwnCloudWizard::showConfigureAccountDialog(const quint32 accountId)
+{
+
+}
+
+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;
+}
diff --git a/plugins/owncloud-ui/owncloud.h b/plugins/owncloud-ui/owncloud.h
new file mode 100644
index 0000000..da92932
--- /dev/null
+++ b/plugins/owncloud-ui/owncloud.h
@@ -0,0 +1,76 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 OWNCLOUD_H
+#define OWNCLOUD_H
+
+#include <QUrl>
+#include <QHash>
+
+#include "../lib/kaccountsuiplugin.h"
+
+class QWizard;
+
+namespace KDeclarative {
+ class QmlObject;
+}
+
+class OwnCloudWizard : public KAccountsUiPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.kde.kaccounts.UiPlugin")
+ Q_INTERFACES(KAccountsUiPlugin)
+
+public:
+ explicit OwnCloudWizard(QWidget *parent = 0);
+ virtual ~OwnCloudWizard();
+
+ virtual void init(KAccountsUiPlugin::UiType type) Q_DECL_OVERRIDE;
+ virtual void setProviderName(const QString &providerName) Q_DECL_OVERRIDE;
+ virtual void showNewAccountDialog() Q_DECL_OVERRIDE;
+ 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;
+};
+
+#endif //OWNCLOUD_H
diff --git a/plugins/owncloud-ui/package/contents/ui/BasicInfo.qml b/plugins/owncloud-ui/package/contents/ui/BasicInfo.qml
new file mode 100644
index 0000000..4d7bca9
--- /dev/null
+++ b/plugins/owncloud-ui/package/contents/ui/BasicInfo.qml
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2015 (C) Martin Klapetek <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 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 Library General Public License for more details
+ *
+ * You should have received a copy of the GNU Library 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.
+ */
+
+import QtQuick 2.2
+import QtQuick.Layouts 1.1
+import QtQuick.Controls 1.2
+import org.kde.plasma.core 2.0 as PlasmaCore
+import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.plasma.extras 2.0 as PlasmaExtras
+
+ColumnLayout {
+ id: basicInfoLayout
+ property bool canContinue: !helper.isWorking && helper.noError && nameText.text.length > 0 && passwordText.text.length > 0
+ property bool canRestartTimer: nameText.text.length > 0 && passwordText.text.length > 0 && serverText.text.length > 0
+
+ Timer {
+ id: checkServerTimer
+ interval: 1000
+ repeat: false
+ running: false
+
+ onTriggered: {
+ helper.checkServer(nameText.text, passwordText.text, serverText.text);
+ }
+ }
+
+ PlasmaComponents.TextField {
+ id: nameText
+ Layout.fillWidth: true
+ clearButtonShown: true
+ placeholderText: "Username"
+
+ onTextChanged: {
+ if (basicInfoLayout.canRestartTimer) {
+ checkServerTimer.restart();
+ }
+ }
+ }
+
+ PlasmaComponents.TextField {
+ id: passwordText
+ Layout.fillWidth: true
+ clearButtonShown: true
+ placeholderText: "Password"
+ echoMode: TextInput.Password
+
+ onTextChanged: {
+ if (basicInfoLayout.canRestartTimer) {
+ checkServerTimer.restart();
+ }
+ }
+ }
+
+ PlasmaComponents.TextField {
+ id: serverText
+ Layout.fillWidth: true
+ clearButtonShown: true
+ placeholderText: "Server"
+
+ onTextChanged: {
+ if (basicInfoLayout.canRestartTimer) {
+ checkServerTimer.restart();
+ }
+ }
+ }
+
+ PlasmaComponents.Label {
+ id: errorLabel
+ Layout.fillWidth: true
+ visible: text.length > 0 && !checkServerTimer.running
+ text: helper.errorMessage
+ wrapMode: Text.WordWrap
+ }
+
+ Item {
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+
+ PlasmaComponents.BusyIndicator {
+ id: busy
+ width: parent.height > parent.width ? Math.round(parent.width/2) : Math.round(parent.height/2)
+ height: width
+ anchors.centerIn: parent
+ running: helper.isWorking
+ visible: running
+ }
+
+ PlasmaCore.IconItem {
+ width: busy.width
+ height: width
+ anchors.centerIn: parent
+ source: "dialog-ok"
+ visible: !helper.isWorking && helper.noError && !errorLabel.visible
+ }
+ }
+}
diff --git a/plugins/owncloud-ui/package/contents/ui/Services.qml b/plugins/owncloud-ui/package/contents/ui/Services.qml
new file mode 100644
index 0000000..90fce0c
--- /dev/null
+++ b/plugins/owncloud-ui/package/contents/ui/Services.qml
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2015 (C) Martin Klapetek <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 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 Library General Public License for more details
+ *
+ * You should have received a copy of the GNU Library 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.
+ */
+
+import QtQuick 2.2
+import QtQuick.Layouts 1.1
+import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.plasma.extras 2.0 as PlasmaExtras
+
+ColumnLayout {
+ id: basicInfoLayout
+ property bool canContinue: true
+
+ //FIXME at some point this should become a list of disabled services
+ property alias contactsEnabled: contactsService.checked
+
+ PlasmaExtras.Heading {
+ level: 3
+ text: i18n("Choose services to enable");
+ }
+
+ PlasmaComponents.CheckBox {
+ id: contactsService
+ text: i18n("Contacts")
+ }
+
+ // Just an item padder
+ Item {
+ Layout.fillHeight: true
+ }
+}
diff --git a/plugins/owncloud-ui/package/contents/ui/main.qml b/plugins/owncloud-ui/package/contents/ui/main.qml
new file mode 100644
index 0000000..a4d590a
--- /dev/null
+++ b/plugins/owncloud-ui/package/contents/ui/main.qml
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 (C) Martin Klapetek <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 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 Library General Public License for more details
+ *
+ * You should have received a copy of the GNU Library 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.
+ */
+
+import QtQuick 2.2
+import QtQuick.Layouts 1.1
+import QtQuick.Controls 1.2
+import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.plasma.extras 2.0 as PlasmaExtras
+
+ApplicationWindow {
+ id: kaccountsRoot
+ objectName: "_root"
+
+ width: 400; height: 250
+
+ ColumnLayout {
+ anchors.fill: parent
+ anchors.margins: units.largeSpacing
+
+ PlasmaExtras.Title {
+ text: i18n("Add new ownCloud account")
+ }
+
+ StackView {
+ id: stack
+
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+
+ initialItem: BasicInfo {
+ id: basicInfoPage
+ objectName: "basicInfoPage"
+ }
+ }
+
+ Component {
+ id: servicesComponent
+
+ Services {
+ objectName: "servicesPage"
+ }
+ }
+
+ RowLayout {
+ PlasmaComponents.Button {
+ id: backButton
+ Layout.fillWidth: true
+ text: i18n("Back");
+ enabled: stack.currentItem.objectName == "servicesPage"
+
+ onClicked: {
+ if (stack.currentItem.objectName == "servicesPage") {
+ stack.pop(servicesComponent);
+ }
+ }
+ }
+
+ PlasmaComponents.Button {
+ id: nextButton
+ Layout.fillWidth: true
+ text: i18n("Next")
+ enabled: basicInfoPage.canContinue //: false
+ visible: stack.currentItem == basicInfoPage
+
+ onClicked: {
+ if (stack.currentItem == basicInfoPage) {
+ stack.push(servicesComponent);
+ }
+ }
+ }
+
+ PlasmaComponents.Button {
+ id: finishButton
+ Layout.fillWidth: true
+ text: i18n("Finish")
+ visible: stack.currentItem.objectName == "servicesPage"
+
+ onClicked: {
+ helper.finish(stack.currentItem.contactsEnabled);
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/owncloud-ui/package/metadata.desktop b/plugins/owncloud-ui/package/metadata.desktop
new file mode 100644
index 0000000..89e3026
--- /dev/null
+++ b/plugins/owncloud-ui/package/metadata.desktop
@@ -0,0 +1,38 @@
+[Desktop Entry]
+Name=OwnCloud KAccounts QML plugin
+Name[ca]=Connector OwnCloud en QML per a KAccounts
+Name[en_GB]=OwnCloud KAccounts QML plugin
+Name[fi]=OwnCloud KAccounts QML -liitännäinen
+Name[it]=Estensione QML di KAccounts per OwnCloud
+Name[nl]=OwnCloud KAccounts QML plug-in
+Name[nn]=KAccounts-QML-tillegg for ownCloud
+Name[pl]=Wtyczka QML OwnCloud dla KAccounts
+Name[pt]='Plugin' em QML do KAccounts para o OwnCloud
+Name[pt_BR]=Plugin em QML do KAccounts para o OwnCloud
+Name[ru]=Модуль поддержки OwnCloud для KAccounts (на QML)
+Name[sk]=OwnCloud KAccounts QML plugin
+Name[sl]=Vstavek QML za KAccounts za OwnCloud
+Name[sr]=КуМЛ прикључак Оунклауда за К‑налоге
+Name[[email protected]]=КуМЛ прикључак Оунклауда за К‑налоге
+Name[[email protected]]=QML priključak ownClouda za K‑naloge
+Name[[email protected]]=QML priključak ownClouda za K‑naloge
+Name[sv]=OwnCloud QML-insticksprogram för konton
+Name[tr]=OwnCloud KAccounts QML eklentisi
+Name[uk]=Додаток QML KAccounts OwnCloud
+Name[x-test]=xxOwnCloud KAccounts QML pluginxx
+Name[zh_CN]=OwnCloud KAccounts QML 插件
+
+Encoding=UTF-8
+Type=Service
+Icon=applications-internet
+X-KDE-PluginInfo-Author=Martin Klapetek
+X-KDE-PluginInfo-Name=owncloud_kaccounts_ui
+X-KDE-PluginInfo-Version=1.0
+X-KDE-PluginInfo-Website=http://kde.org
+X-KDE-PluginInfo-Category=Network
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+X-KDE-FormFactors=handset,tablet,mediacenter
+X-Plasma-MainScript=ui/main.qml
diff --git a/plugins/owncloud-ui/pages/basicinfo.cpp b/plugins/owncloud-ui/pages/basicinfo.cpp
new file mode 100644
index 0000000..51e5e5b
--- /dev/null
+++ b/plugins/owncloud-ui/pages/basicinfo.cpp
@@ -0,0 +1,225 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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)
+{
+ m_json.append(data);
+}
+
+void BasicInfo::fileChecked(KJob *job)
+{
+ KIO::TransferJob *kJob = qobject_cast<KIO::TransferJob *>(job);
+ if (kJob->error()) {
+ qDebug() << job->errorString();
+ qDebug() << job->errorText();
+ figureOutServer(kJob->url());
+ return;
+ }
+
+ QJsonDocument parser = QJsonDocument::fromJson(m_json);
+ QJsonObject map = parser.object();
+ if (!map.contains("version")) {
+ figureOutServer(kJob->url());
+ qDebug() << "No json";
+ return;
+ }
+
+ m_server = kJob->url();
+ m_server = m_server.adjusted(QUrl::RemoveFilename);
+ qDebug() << m_server;
+ setResult(true);
+
+ Q_EMIT completeChanged();
+}
+
+void BasicInfo::setWorking(bool start)
+{
+ working->setPixmap(QPixmap());
+
+ if (!start) {
+ m_painter->stop();
+ return;
+ }
+
+ m_painter->start();
+}
+
+void BasicInfo::setResult(bool result)
+{
+ QString icon;
+ if (result) {
+ icon = "dialog-ok-apply";
+ } else {
+ icon = "dialog-close";
+ }
+
+ m_validServer = result;
+ setWorking(false);
+ working->setPixmap(QIcon::fromTheme(icon).pixmap(working->sizeHint()));
+}
diff --git a/plugins/owncloud-ui/pages/basicinfo.h b/plugins/owncloud-ui/pages/basicinfo.h
new file mode 100644
index 0000000..48615a2
--- /dev/null
+++ b/plugins/owncloud-ui/pages/basicinfo.h
@@ -0,0 +1,72 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 BASIC_INFO_H
+#define BASIC_INFO_H
+
+#include "ui_basicinfo.h"
+
+#include <QWizardPage>
+#include <KIO/AccessManager>
+
+namespace KIO
+{
+ class Job;
+};
+class KJob;
+class OwnCloudWizard;
+class KPixmapSequenceOverlayPainter;
+class QTimer;
+
+class BasicInfo : public QWizardPage, Ui_Owncloud
+{
+ Q_OBJECT
+
+public:
+ BasicInfo(QWizard *parent);
+ virtual ~BasicInfo();
+
+ virtual void initializePage();
+ virtual bool validatePage();
+ virtual bool isComplete() const;
+
+private Q_SLOTS:
+ void checkServer();
+ void fileChecked(KJob* job);
+ void dataReceived(KIO::Job *job, const QByteArray &data);
+
+private:
+ bool validData() const;
+ void checkServer(const QString &path);
+ void checkServer(const QUrl &url);
+ void figureOutServer(const QUrl &url);
+
+ void setWorking(bool start);
+ void setResult(bool result);
+
+private:
+ QUrl m_server;
+ bool m_validServer;
+ QByteArray m_json;
+ KPixmapSequenceOverlayPainter *m_painter;
+ QWizard *m_wizard;
+ QTimer *m_timer;
+};
+
+#endif //BASIC_INFO_H
diff --git a/plugins/owncloud-ui/pages/basicinfo.ui b/plugins/owncloud-ui/pages/basicinfo.ui
new file mode 100644
index 0000000..b95957e
--- /dev/null
+++ b/plugins/owncloud-ui/pages/basicinfo.ui
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Owncloud</class>
+ <widget class="QWidget" name="Owncloud">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>470</width>
+ <height>197</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>ownCloud</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="icon">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Username</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="server">
+ <property name="placeholderText">
+ <string>http://my.owncloudserver.org</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="password">
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Server</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="username">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="placeholderText">
+ <string extracomment="A typical username that is used as a hint (placeHolderText) ">JohnDoe</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QLabel" name="working">
+ <property name="minimumSize">
+ <size>
+ <width>24</width>
+ <height>24</height>
+ </size>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>username</tabstop>
+ <tabstop>password</tabstop>
+ <tabstop>server</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plugins/owncloud-ui/pages/connecting.cpp b/plugins/owncloud-ui/pages/connecting.cpp
new file mode 100644
index 0000000..89f6c0a
--- /dev/null
+++ b/plugins/owncloud-ui/pages/connecting.cpp
@@ -0,0 +1,87 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 "connecting.h"
+#include "../owncloud.h"
+
+#include <QDebug>
+
+#include <KPixmapSequenceOverlayPainter>
+#include <KIO/Job>
+
+Connecting::Connecting(QWizard *parent)
+ : QWizardPage(parent)
+ , m_wizard(parent)
+{
+ setupUi(this);
+ KPixmapSequenceOverlayPainter *painter = new KPixmapSequenceOverlayPainter(this);
+ painter->setWidget(working);
+ painter->start();
+}
+
+Connecting::~Connecting()
+{
+
+}
+
+void Connecting::initializePage()
+{
+ QList <QWizard::WizardButton> list;
+ list << QWizard::Stretch;
+ list << QWizard::BackButton;
+ list << QWizard::NextButton;
+ list << QWizard::CancelButton;
+ m_wizard->setButtonLayout(list);
+
+ server->setText(m_wizard->property("server").toUrl().host());
+
+ QMetaObject::invokeMethod(this, "checkAuth", Qt::QueuedConnection);
+}
+
+void Connecting::checkAuth()
+{
+ QUrl url(m_wizard->property("server").toUrl());
+
+ url.setUserName(m_wizard->property("username").toString());
+ url.setPassword(m_wizard->property("password").toString());
+
+ url = url.adjusted(QUrl::StripTrailingSlash);
+ url.setPath(url.path() + '/' + "remote.php/webdav/");
+ qDebug() << "FinalUrL: " << url;
+ KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
+ connect(job, SIGNAL(finished(KJob*)), this, SLOT(httpResult(KJob*)));
+
+ job->setUiDelegate(0);
+}
+
+void Connecting::httpResult(KJob *job)
+{
+ if (job->error()) {
+ qDebug() << job->errorString();
+ qDebug() << job->errorText();
+ }
+
+ KIO::TransferJob *kJob = qobject_cast<KIO::TransferJob*>(job);
+ if (kJob->isErrorPage()) {
+ error->setText(i18n("Unable to authenticate using the provided username and password"));
+ return;
+ }
+
+ m_wizard->next();
+}
diff --git a/plugins/owncloud-ui/pages/connecting.h b/plugins/owncloud-ui/pages/connecting.h
new file mode 100644
index 0000000..9beef9e
--- /dev/null
+++ b/plugins/owncloud-ui/pages/connecting.h
@@ -0,0 +1,48 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 CONNECTING_H
+#define CONNECTING_H
+
+#include "ui_connecting.h"
+
+#include <QWizardPage>
+#include <KJob>
+
+class KJob;
+
+class Connecting : public QWizardPage, Ui::Connecting
+{
+ Q_OBJECT
+
+public:
+ explicit Connecting(QWizard *parent);
+ virtual ~Connecting();
+
+ virtual void initializePage();
+
+private Q_SLOTS:
+ void checkAuth();
+ void httpResult(KJob *job);
+
+private:
+ QWizard *m_wizard;
+};
+
+#endif //CONNECTING_H
diff --git a/plugins/owncloud-ui/pages/connecting.ui b/plugins/owncloud-ui/pages/connecting.ui
new file mode 100644
index 0000000..ade98bc
--- /dev/null
+++ b/plugins/owncloud-ui/pages/connecting.ui
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Connecting</class>
+ <widget class="QWidget" name="Connecting">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QWidget" name="working" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>22</width>
+ <height>22</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>10</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="connecting">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Connecting to:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="server">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QLabel" name="error">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plugins/owncloud-ui/pages/oservices.cpp b/plugins/owncloud-ui/pages/oservices.cpp
new file mode 100644
index 0000000..0d49b7b
--- /dev/null
+++ b/plugins/owncloud-ui/pages/oservices.cpp
@@ -0,0 +1,80 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 "oservices.h"
+#include "../owncloud.h"
+
+#include <QCheckBox>
+#include <QVariant>
+
+OServices::OServices(QWizard *wizard)
+ : QWizardPage()
+ , m_wizard(wizard)
+{
+ setupUi(this);
+}
+
+OServices::~OServices()
+{
+
+}
+
+void OServices::initializePage()
+{
+ QList <QWizard::WizardButton> list;
+ list << QWizard::Stretch;
+ list << QWizard::FinishButton;
+ m_wizard->setButtonLayout(list);
+
+// addOption("File", i18n("Files"));
+// addOption("Calendar", i18n("Calendar"));
+ addOption("owncloud-contacts", i18n("Contacts"));
+}
+
+void OServices::addOption(const QString &id, const QString &displayText)
+{
+ QCheckBox *option = new QCheckBox(displayText, this);
+ option->setChecked(true);
+ option->setProperty("id", id);
+ connect(option, &QCheckBox::toggled, this, &OServices::optionToggled);
+
+ d_layout->addWidget(option);
+}
+
+void OServices::optionToggled(bool checked)
+{
+ if (!sender()) {
+ return;
+ }
+
+ const QString service = sender()->property("id").toString();
+
+ if (checked) {
+ m_disabledServices.removeAll(service);
+ } else {
+ m_disabledServices.append(service);
+ }
+}
+
+bool OServices::validatePage()
+{
+ m_wizard->setProperty("disabledServices", m_disabledServices);
+
+ return true;
+}
diff --git a/plugins/owncloud-ui/pages/oservices.h b/plugins/owncloud-ui/pages/oservices.h
new file mode 100644
index 0000000..4fd9876
--- /dev/null
+++ b/plugins/owncloud-ui/pages/oservices.h
@@ -0,0 +1,48 @@
+/*************************************************************************************
+ * Copyright (C) 2012 by Alejandro Fiestas Olivares <[email protected]> *
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 OSERVICES_H
+#define OSERVICES_H
+
+#include "ui_oservices.h"
+#include <QWizardPage>
+
+class OServices : public QWizardPage, Ui::Services
+{
+ Q_OBJECT
+
+public:
+ explicit OServices(QWizard *wizard);
+ virtual ~OServices();
+
+ virtual void initializePage();
+ virtual bool validatePage();
+
+private Q_SLOTS:
+ void optionToggled(bool checked);
+
+private:
+ void addOption(const QString &id, const QString &displayText);
+
+private:
+ QWizard *m_wizard;
+ QStringList m_disabledServices;
+};
+
+#endif //OSERVICES_H
diff --git a/plugins/owncloud-ui/pages/oservices.ui b/plugins/owncloud-ui/pages/oservices.ui
new file mode 100644
index 0000000..940ded2
--- /dev/null
+++ b/plugins/owncloud-ui/pages/oservices.ui
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Services</class>
+ <widget class="QWidget" name="Services">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>517</width>
+ <height>408</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Select what services you want to activate</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>501</width>
+ <height>173</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QVBoxLayout" name="d_layout"/>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>159</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plugins/owncloud-ui/qmlhelper.cpp b/plugins/owncloud-ui/qmlhelper.cpp
new file mode 100644
index 0000000..ab5db3a
--- /dev/null
+++ b/plugins/owncloud-ui/qmlhelper.cpp
@@ -0,0 +1,242 @@
+/*************************************************************************************
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 "qmlhelper.h"
+
+#include <KIO/Job>
+#include <KIO/DavJob>
+#include <kio/global.h>
+#include <KLocalizedString>
+
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QDebug>
+
+QmlHelper::QmlHelper(QObject *parent)
+ : QObject(parent),
+ m_isWorking(false),
+ m_noError(false),
+ m_errorMessage(QString())
+{
+}
+
+QmlHelper::~QmlHelper()
+{
+}
+
+void QmlHelper::checkServer(const QString &username, const QString &password, const QString &path)
+{
+ m_errorMessage.clear();
+ Q_EMIT errorMessageChanged();
+
+ m_username = username;
+ m_password = password;
+
+ 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 QmlHelper::checkServer(const QUrl &url)
+{
+ qDebug() << "Checking for ownCloud instance at" << url;
+ 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 QmlHelper::figureOutServer(const QUrl& url)
+{
+ if (/*url == QLatin1String("/") ||*/ url.isEmpty()) {
+ serverCheckResult(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 {
+ serverCheckResult(false);
+ }
+}
+
+void QmlHelper::dataReceived(KIO::Job *job, const QByteArray &data)
+{
+ Q_UNUSED(job);
+ m_json.append(data);
+}
+
+void QmlHelper::fileChecked(KJob* job)
+{
+ KIO::TransferJob *kJob = qobject_cast<KIO::TransferJob *>(job);
+ if (kJob->error()) {
+ qDebug() << job->errorString();
+ qDebug() << job->errorText();
+ figureOutServer(kJob->url());
+ return;
+ }
+
+ QJsonDocument parser = QJsonDocument::fromJson(m_json);
+ QJsonObject map = parser.object();
+ if (!map.contains("version")) {
+ figureOutServer(kJob->url());
+ qDebug() << "No json";
+ return;
+ }
+
+ m_server = kJob->url().adjusted(QUrl::RemoveFilename).toString();
+ qDebug() << "ownCloud appears to be running at the specified URL";
+ serverCheckResult(true);
+}
+
+void QmlHelper::setWorking(bool start)
+{
+ if (start == m_isWorking) {
+ return;
+ }
+
+ m_isWorking = start;
+ Q_EMIT isWorkingChanged();
+}
+
+void QmlHelper::serverCheckResult(bool result)
+{
+ m_noError = result;
+ Q_EMIT noErrorChanged();
+
+ if (!result) {
+ m_errorMessage = i18n("Unable to connect to ownCloud at the given server URL. Please check the server URL.");
+ setWorking(false);
+ } else {
+ m_errorMessage.clear();
+
+ qDebug() << "Server URL ok, checking auth...";
+
+ m_json.clear();
+
+ QUrl url(m_server);
+
+ url.setUserName(m_username);
+ url.setPassword(m_password);
+
+ url = url.adjusted(QUrl::StripTrailingSlash);
+ url.setPath(url.path() + '/' + "remote.php/webdav");
+ // Send a basic PROPFIND command to test access
+ const QString requestStr = QStringLiteral(
+ "<d:propfind xmlns:d=\"DAV:\">"
+ "<d:prop>"
+ "<d:current-user-principal />"
+ "</d:prop>"
+ "</d:propfind>");
+
+ KIO::DavJob *job = KIO::davPropFind(url, QDomDocument(requestStr), "1", KIO::HideProgressInfo);
+ connect(job, SIGNAL(finished(KJob*)), this, SLOT(authCheckResult(KJob*)));
+ connect(job, SIGNAL(data(KIO::Job*,QByteArray)), SLOT(dataReceived(KIO::Job*,QByteArray)));
+
+ QVariantMap metadata{{"cookies","none"}, {"no-cache",true}};
+
+ job->setMetaData(metadata);
+ job->setUiDelegate(0);
+ job->start();
+ }
+
+ Q_EMIT errorMessageChanged();
+
+}
+
+void QmlHelper::authCheckResult(KJob *job)
+{
+ if (job->error()) {
+ qDebug() << job->errorString();
+ qDebug() << job->errorText();
+ }
+
+ KIO::DavJob *kJob = qobject_cast<KIO::DavJob*>(job);
+ qDebug() << "Auth job finished, received error page:" << kJob->isErrorPage();
+
+ if (kJob->isErrorPage()) {
+ m_errorMessage = i18n("Unable to authenticate using the provided username and password");
+ } else {
+ m_errorMessage.clear();
+ }
+
+ Q_EMIT errorMessageChanged();
+
+ m_noError = !kJob->isErrorPage();
+ Q_EMIT noErrorChanged();
+ setWorking(false);
+}
+
+bool QmlHelper::isWorking()
+{
+ return m_isWorking;
+}
+
+bool QmlHelper::noError()
+{
+ return m_noError;
+}
+
+QString QmlHelper::errorMessage() const
+{
+ return m_errorMessage;
+}
+
+void QmlHelper::finish(bool contactsEnabled)
+{
+ QVariantMap data;
+ data.insert("server", m_server);
+
+ if (!contactsEnabled) {
+ data.insert("__service/owncloud-contacts", false);
+ }
+
+ QUrl carddavUrl(m_server);
+ carddavUrl.setPath(carddavUrl.path() + QString("/remote.php/carddav/addressbooks/%1").arg(m_username));
+
+ data.insert("carddavUrl", carddavUrl);
+
+ Q_EMIT wizardFinished(m_username, m_password, data);
+}
+
+#include "qmlhelper.moc"
diff --git a/plugins/owncloud-ui/qmlhelper.h b/plugins/owncloud-ui/qmlhelper.h
new file mode 100644
index 0000000..36be67a
--- /dev/null
+++ b/plugins/owncloud-ui/qmlhelper.h
@@ -0,0 +1,77 @@
+/*************************************************************************************
+ * Copyright (C) 2015 by Martin Klapetek <[email protected]> *
+ * *
+ * 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 QMLHELPER_H
+#define QMLHELPER_H
+
+#include <QObject>
+
+#include <KIO/AccessManager>
+
+namespace KIO
+{
+ class Job;
+};
+class KJob;
+
+class QmlHelper : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool isWorking READ isWorking NOTIFY isWorkingChanged)
+ Q_PROPERTY(bool noError READ noError NOTIFY noErrorChanged)
+ Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
+
+public:
+ QmlHelper(QObject *parent = 0);
+ ~QmlHelper();
+
+ Q_INVOKABLE void checkServer(const QString &username, const QString &password, const QString &server);
+ Q_INVOKABLE void finish(bool contactsEnabled);
+ bool isWorking();
+ bool noError();
+ QString errorMessage() const;
+
+Q_SIGNALS:
+ void isWorkingChanged();
+ void noErrorChanged();
+ void errorMessageChanged();
+ void wizardFinished(const QString &username, const QString &password, const QVariantMap &data);
+
+private Q_SLOTS:
+ void fileChecked(KJob *job);
+ void dataReceived(KIO::Job *job, const QByteArray &data);
+ void authCheckResult(KJob *job);
+
+private:
+ void checkServer(const QUrl &url);
+ void figureOutServer(const QUrl &url);
+ void setWorking(bool start);
+ void serverCheckResult(bool result);
+
+ QByteArray m_json;
+ QString m_errorMessage;
+ QString m_server;
+ QString m_username;
+ QString m_password;
+ QStringList m_disabledServices;
+ bool m_isWorking;
+ bool m_noError;
+
+};
+
+#endif // QMLHELPER_H