Commit 3d3940c5 authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

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.
parents
/*************************************************************************************
* 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()));
}
/*************************************************************************************
* 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
<?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>
/*************************************************************************************
* 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()
{
}
/*************************************************************************************
* 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment