[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kaccounts-providers] /: ownCloud setup wizard with credentials page implemented (BasicInfo)
From:       Alex Fiestas <afiestas () kde ! org>
Date:       2015-10-15 21:01:17
Message-ID: E1ZmpeH-0000yK-Vi () scm ! kde ! org
[Download RAW message or body]

Git commit 3d3940c5c503cb4dba81a924c27aef005d6fd315 by Alex Fiestas.
Committed on 17/04/2012 at 14:30.
Pushed by mklapetek into branch 'master'.

ownCloud setup wizard with credentials page implemented (BasicInfo)

In this case we are calling the credential page "Basic Info" since
it is used to get information about the ownCloud server itself.

A  +154  -0    basicinfo.cpp     [License: GPL (v2+)]
A  +62   -0    basicinfo.h     [License: GPL (v2+)]
A  +127  -0    basicinfo.ui
A  +45   -0    owncloud.cpp     [License: GPL (v2+)]
A  +32   -0    owncloud.h     [License: GPL (v2+)]

http://commits.kde.org/kaccounts-providers/3d3940c5c503cb4dba81a924c27aef005d6fd315

diff --git a/basicinfo.cpp b/basicinfo.cpp
new file mode 100644
index 0000000..8eb62d2
--- /dev/null
+++ b/basicinfo.cpp
@@ -0,0 +1,154 @@
+/*************************************************************************************
+ *  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 "basicinfo.h"
+#include "owncloud.h"
+
+#include <QDebug>
+#include <qjson/parser.h>
+
+#include <kpixmapsequenceoverlaypainter.h>
+#include <KIO/Job>
+
+BasicInfo::BasicInfo(OwnCloudWizard* parent)
+ : QWizardPage(parent)
+ , m_painter(new KPixmapSequenceOverlayPainter(this))
+ , m_wizard(parent)
+{
+    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);
+
+    connect(server, SIGNAL(textChanged(QString)), this, SLOT(checkServer()));
+}
+
+BasicInfo::~BasicInfo()
+{
+
+}
+
+bool BasicInfo::validatePage()
+{
+    return true;
+}
+
+void BasicInfo::checkServer()
+{
+    checkServer(server->text());
+}
+
+void BasicInfo::checkServer(const QString &path)
+{
+    QString fixedUrl;
+    if (!path.startsWith("http://")) {
+        fixedUrl.append("http://");
+        fixedUrl.append(path);
+    } else {
+        fixedUrl = path;
+    }
+
+    KUrl url(fixedUrl);
+    m_json.clear();
+
+    url.setFileName("status.php");
+    url.setQuery("");
+
+    checkServer(url);
+}
+
+void BasicInfo::checkServer(const KUrl& url)
+{
+    qDebug() << url;
+    setWorking(true);
+    KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
+
+    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 QString& urlStr)
+{
+    KUrl url(urlStr);
+    if (url.directory(KUrl::AppendTrailingSlash) == "/") {
+        setResult(false);
+        return;
+    }
+
+    m_json.clear();
+    url.setFileName("");
+    url = url.upUrl();
+    url.setFileName("status.php");
+
+    checkServer(url);
+}
+
+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().url());
+        return;
+    }
+
+    QJson::Parser parser;
+    QMap <QString, QVariant> map = parser.parse(m_json).toMap();
+    if (!map.contains("version")) {
+        figureOutServer(kJob->url().url());
+        return;
+    }
+
+    setResult(true);
+}
+
+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";
+    }
+
+    setWorking(false);
+    working->setPixmap(QIcon::fromTheme(icon).pixmap(working->sizeHint()));
+}
diff --git a/basicinfo.h b/basicinfo.h
new file mode 100644
index 0000000..bec7acd
--- /dev/null
+++ b/basicinfo.h
@@ -0,0 +1,62 @@
+/*************************************************************************************
+ *  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 BASIC_INFO_H
+#define BASIC_INFO_H
+
+#include "ui_basicinfo.h"
+
+#include <QWizardPage>
+#include <KDE/KIO/AccessManager>
+
+namespace KIO
+{
+    class Job;
+};
+class KJob;
+class OwnCloudWizard;
+class KPixmapSequenceOverlayPainter;
+class BasicInfo : public QWizardPage, Ui_Owncloud
+{
+    Q_OBJECT
+    public:
+        BasicInfo(OwnCloudWizard *parent);
+        virtual ~BasicInfo();
+
+        virtual bool validatePage();
+
+    private Q_SLOTS:
+        void checkServer();
+        void fileChecked(KJob* job);
+        void dataReceived(KIO::Job *job, const QByteArray &data);
+
+    private:
+        void checkServer(const QString &path);
+        void checkServer(const KUrl &url);
+        void figureOutServer(const QString& urlStr);
+
+        void setWorking(bool start);
+        void setResult(bool result);
+
+    private:
+        QByteArray m_json;
+        KPixmapSequenceOverlayPainter *m_painter;
+        OwnCloudWizard *m_wizard;
+};
+
+#endif //BASIC_INFO_H
\ No newline at end of file
diff --git a/basicinfo.ui b/basicinfo.ui
new file mode 100644
index 0000000..45a6041
--- /dev/null
+++ b/basicinfo.ui
@@ -0,0 +1,127 @@
+<?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>
+  <property name="windowTitle">
+   <string>Form</string>
+  </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>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="email">
+       <property name="text">
+        <string/>
+       </property>
+       <property name="placeholderText">
+        <string extracomment="A typical username that is used as a hint (placeHolderText) ">JhonDoe</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>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/owncloud.cpp b/owncloud.cpp
new file mode 100644
index 0000000..6a4dcd7
--- /dev/null
+++ b/owncloud.cpp
@@ -0,0 +1,45 @@
+/*************************************************************************************
+ *  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 "owncloud.h"
+#include "basicinfo.h"
+
+#include <klocalizedstring.h>
+#include <kpushbutton.h>
+#include <kstandardguiitem.h>
+
+OwnCloudWizard::OwnCloudWizard(QWidget* parent, Qt::WindowFlags flags): QWizard(parent, flags)
+{
+    BasicInfo *basicInfo = new BasicInfo(this);
+
+    addPage(basicInfo);
+
+    setButton(QWizard::BackButton, new KPushButton(KStandardGuiItem::back(KStandardGuiItem::UseRTL)));
+    setButton(QWizard::NextButton, new KPushButton(KStandardGuiItem::forward(KStandardGuiItem::UseRTL)));
+    setButton(QWizard::FinishButton, new KPushButton(KStandardGuiItem::apply()));
+    setButton(QWizard::CancelButton, new KPushButton(KStandardGuiItem::cancel()));
+
+    //We do not want "Forward" as text
+    setButtonText(QWizard::NextButton, i18nc("Action to go to the next page on the wizard", "Next"));
+    setButtonText(QWizard::FinishButton, i18nc("Action to finish the wizard", "Finish"));
+}
+
+OwnCloudWizard::~OwnCloudWizard()
+{
+
+}
diff --git a/owncloud.h b/owncloud.h
new file mode 100644
index 0000000..0e89ec7
--- /dev/null
+++ b/owncloud.h
@@ -0,0 +1,32 @@
+/*************************************************************************************
+ *  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 OWNCLOUD_H
+#define OWNCLOUD_H
+
+#include <QtGui/QWizard>
+
+class OwnCloudWizard : public QWizard
+{
+    Q_OBJECT
+    public:
+        explicit OwnCloudWizard(QWidget* parent = 0, Qt::WindowFlags flags = 0);
+        virtual ~OwnCloudWizard();
+};
+
+#endif //OWNCLOUD_H
\ No newline at end of file

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic