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/3d3940c5c503cb4dba81a924c27aef00= 5d6fd315 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 = * + * = * + * 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-1= 301, USA * + *************************************************************************= ************/ + +#include "basicinfo.h" +#include "owncloud.h" + +#include +#include + +#include +#include + +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 =3D 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 =3D 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 =3D KIO::get(url, KIO::NoReload, KIO::HideProgre= ssInfo); + + 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) =3D=3D "/") { + setResult(false); + return; + } + + m_json.clear(); + url.setFileName(""); + url =3D 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 =3D qobject_cast(job); + if (kJob->error()) { + qDebug() << job->errorString(); + qDebug() << job->errorText(); + figureOutServer(kJob->url().url()); + return; + } + + QJson::Parser parser; + QMap map =3D 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 =3D "dialog-ok-apply"; + } else { + icon =3D "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 = * + * = * + * 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-1= 301, USA * + *************************************************************************= ************/ + +#ifndef BASIC_INFO_H +#define BASIC_INFO_H + +#include "ui_basicinfo.h" + +#include +#include + +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 @@ + + + Owncloud + + + + 0 + 0 + 470 + 197 + + + + Form + + + + + + + + ownCloud + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + Password: + + + + + + + Username + + + + + + + my.owncloudserver.org + + + + + + + QLineEdit::Password + + + + + + + Server + + + + + + + + + + JhonDoe + + + + + + + + 24 + 24 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + 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 = * + * = * + * 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-1= 301, USA * + *************************************************************************= ************/ + +#include "owncloud.h" +#include "basicinfo.h" + +#include +#include +#include + +OwnCloudWizard::OwnCloudWizard(QWidget* parent, Qt::WindowFlags flags): QW= izard(parent, flags) +{ + BasicInfo *basicInfo =3D new BasicInfo(this); + + addPage(basicInfo); + + setButton(QWizard::BackButton, new KPushButton(KStandardGuiItem::back(= KStandardGuiItem::UseRTL))); + setButton(QWizard::NextButton, new KPushButton(KStandardGuiItem::forwa= rd(KStandardGuiItem::UseRTL))); + setButton(QWizard::FinishButton, new KPushButton(KStandardGuiItem::app= ly())); + setButton(QWizard::CancelButton, new KPushButton(KStandardGuiItem::can= cel())); + + //We do not want "Forward" as text + setButtonText(QWizard::NextButton, i18nc("Action to go to the next pag= e on the wizard", "Next")); + setButtonText(QWizard::FinishButton, i18nc("Action to finish the wizar= d", "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 = * + * = * + * 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-1= 301, USA * + *************************************************************************= ************/ + +#ifndef OWNCLOUD_H +#define OWNCLOUD_H + +#include + +class OwnCloudWizard : public QWizard +{ + Q_OBJECT + public: + explicit OwnCloudWizard(QWidget* parent =3D 0, Qt::WindowFlags fla= gs =3D 0); + virtual ~OwnCloudWizard(); +}; + +#endif //OWNCLOUD_H \ No newline at end of file