Commit de5c5210 authored by Nicolas Fella's avatar Nicolas Fella

Rename qmlhelper to (own|next)cloudcontroller

Qmlhelper is a rather bad name, *Controller is slightly better.
parent 79d4cd7d
set(nextcloud_plugin_kaccounts_SRCS
nextcloud.cpp
qmlhelper.cpp
nextcloudcontroller.cpp
)
add_library(nextcloud_plugin_kaccounts MODULE
......
......@@ -7,7 +7,7 @@
*/
#include "nextcloud.h"
#include "qmlhelper.h"
#include "nextcloudcontroller.h"
#include <KLocalizedString>
#include <KDeclarative/QmlObject>
......@@ -35,9 +35,9 @@ void NextcloudWizard::init(KAccountsUiPlugin::UiType type)
m_object->setInitializationDelayed(true);
m_object->loadPackage(packagePath);
QmlHelper *helper = new QmlHelper(m_object);
connect(helper, &QmlHelper::wizardFinished, this, &NextcloudWizard::success);
connect(helper, &QmlHelper::wizardFinished, [=] {
NextcloudController *helper = new NextcloudController(m_object);
connect(helper, &NextcloudController::wizardFinished, this, &NextcloudWizard::success);
connect(helper, &NextcloudController::wizardFinished, [=] {
QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
if (window) {
window->close();
......
......@@ -4,7 +4,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "qmlhelper.h"
#include "nextcloudcontroller.h"
#include <KIO/Job>
#include <KIO/DavJob>
......@@ -21,16 +22,16 @@
#include <QFileSystemWatcher>
#include <QDesktopServices>
QmlHelper::QmlHelper(QObject *parent)
NextcloudController::NextcloudController(QObject *parent)
: QObject(parent)
{
}
QmlHelper::~QmlHelper()
NextcloudController::~NextcloudController()
{
}
void QmlHelper::checkServer(const QString &path)
void NextcloudController::checkServer(const QString &path)
{
m_errorMessage.clear();
Q_EMIT errorMessageChanged();
......@@ -54,22 +55,22 @@ void QmlHelper::checkServer(const QString &path)
}
//To check if url is correct
void QmlHelper::checkServer(const QUrl &url)
void NextcloudController::checkServer(const QUrl &url)
{
setWorking(true);
KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo);
job->setUiDelegate(0);
connect(job, &KIO::DavJob::data, this, &QmlHelper::dataReceived);
connect(job, &KIO::DavJob::finished, this, &QmlHelper::fileChecked);
connect(job, &KIO::DavJob::data, this, &NextcloudController::dataReceived);
connect(job, &KIO::DavJob::finished, this, &NextcloudController::fileChecked);
}
void QmlHelper::dataReceived(KIO::Job *job, const QByteArray &data)
void NextcloudController::dataReceived(KIO::Job *job, const QByteArray &data)
{
Q_UNUSED(job);
m_json.append(data);
}
void QmlHelper::fileChecked(KJob* job)
void NextcloudController::fileChecked(KJob* job)
{
KIO::TransferJob *kJob = qobject_cast<KIO::TransferJob *>(job);
if (kJob->error()) {
......@@ -92,7 +93,7 @@ void QmlHelper::fileChecked(KJob* job)
}
// When url entered by user is wrong
void QmlHelper::wrongUrlDetected()
void NextcloudController::wrongUrlDetected()
{
m_noError = false;
Q_EMIT noErrorChanged();
......@@ -104,7 +105,7 @@ void QmlHelper::wrongUrlDetected()
// Open Webview for nextcloud login.
// Document for login flow : https://docs.nextcloud.com/server/stable/developer_manual/client_apis/LoginFlow/index.html
void QmlHelper::openWebView()
void NextcloudController::openWebView()
{
QWebEngineHttpRequest request;
// set proper headers
......@@ -129,7 +130,7 @@ void QmlHelper::openWebView()
m_view->resize(424, 650);
}
void QmlHelper::finalUrlHandler(const QUrl &url){
void NextcloudController::finalUrlHandler(const QUrl &url){
m_finalUrl = url;
m_view->close();
delete m_view;
......@@ -151,7 +152,7 @@ void QmlHelper::finalUrlHandler(const QUrl &url){
serverCheckResult();
}
void QmlHelper::setWorking(bool start)
void NextcloudController::setWorking(bool start)
{
if (start == m_isWorking) {
return;
......@@ -161,7 +162,7 @@ void QmlHelper::setWorking(bool start)
Q_EMIT isWorkingChanged();
}
void QmlHelper::serverCheckResult()
void NextcloudController::serverCheckResult()
{
m_noError = true;
Q_EMIT noErrorChanged();
......@@ -182,8 +183,8 @@ void QmlHelper::serverCheckResult()
"</d:propfind>");
KIO::DavJob *job = KIO::davPropFind(url, QDomDocument(requestStr), "1", KIO::HideProgressInfo);
connect(job, &KIO::DavJob::finished, this, &QmlHelper::authCheckResult);
connect(job, &KIO::DavJob::data, this, &QmlHelper::dataReceived);
connect(job, &KIO::DavJob::finished, this, &NextcloudController::authCheckResult);
connect(job, &KIO::DavJob::data, this, &NextcloudController::dataReceived);
QVariantMap metadata{{"cookies","none"}, {"no-cache",true}};
......@@ -194,7 +195,7 @@ void QmlHelper::serverCheckResult()
Q_EMIT errorMessageChanged();
}
void QmlHelper::authCheckResult(KJob *job)
void NextcloudController::authCheckResult(KJob *job)
{
KIO::DavJob *kJob = qobject_cast<KIO::DavJob*>(job);
......@@ -213,27 +214,27 @@ void QmlHelper::authCheckResult(KJob *job)
setWorking(false);
}
bool QmlHelper::isWorking()
bool NextcloudController::isWorking()
{
return m_isWorking;
}
bool QmlHelper::noError()
bool NextcloudController::noError()
{
return m_noError;
}
QString QmlHelper::errorMessage() const
QString NextcloudController::errorMessage() const
{
return m_errorMessage;
}
bool QmlHelper::isLoginComplete()
bool NextcloudController::isLoginComplete()
{
return m_isLoginComplete;
}
void QmlHelper::finish(bool contactsEnabled)
void NextcloudController::finish(bool contactsEnabled)
{
QVariantMap data;
data.insert("server", m_server);
......
......@@ -22,7 +22,7 @@ namespace KIO
class KJob;
class QmlHelper : public QObject
class NextcloudController : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isWorking READ isWorking NOTIFY isWorkingChanged)
......@@ -31,8 +31,8 @@ class QmlHelper : public QObject
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
public:
QmlHelper(QObject *parent = 0);
~QmlHelper();
NextcloudController(QObject *parent = 0);
~NextcloudController();
Q_INVOKABLE void checkServer(const QString &server);
Q_INVOKABLE void finish(bool contactsEnabled);
......
......@@ -4,7 +4,7 @@ include_directories(${CMAKE_CURRENT_BUILD_DIR}
set(owncloud_plugin_kaccounts_SRCS
owncloud.cpp
qmlhelper.cpp
owncloudcontroller.cpp
)
add_library(owncloud_plugin_kaccounts MODULE
......
......@@ -6,7 +6,7 @@
*/
#include "owncloud.h"
#include "qmlhelper.h"
#include "owncloudcontroller.h"
#include <KLocalizedString>
#include <KDeclarative/QmlObject>
......@@ -35,9 +35,9 @@ void OwnCloudWizard::init(KAccountsUiPlugin::UiType type)
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, [=] {
OwncloudController *helper = new OwncloudController(m_object);
connect(helper, &OwncloudController::wizardFinished, this, &OwnCloudWizard::success);
connect(helper, &OwncloudController::wizardFinished, [=] {
QWindow *window = qobject_cast<QWindow *>(m_object->rootObject());
if (window) {
window->close();
......
......@@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "qmlhelper.h"
#include "owncloudcontroller.h"
#include <KIO/Job>
#include <KIO/DavJob>
......@@ -15,7 +15,7 @@
#include <QJsonObject>
#include <QDebug>
QmlHelper::QmlHelper(QObject *parent)
OwncloudController::OwncloudController(QObject *parent)
: QObject(parent),
m_errorMessage(QString()),
m_isWorking(false),
......@@ -23,11 +23,11 @@ QmlHelper::QmlHelper(QObject *parent)
{
}
QmlHelper::~QmlHelper()
OwncloudController::~OwncloudController()
{
}
void QmlHelper::checkServer(const QString &username, const QString &password, const QString &path)
void OwncloudController::checkServer(const QString &username, const QString &password, const QString &path)
{
m_errorMessage.clear();
Q_EMIT errorMessageChanged();
......@@ -56,7 +56,7 @@ void QmlHelper::checkServer(const QString &username, const QString &password, co
checkServer(url);
}
void QmlHelper::checkServer(const QUrl &url)
void OwncloudController::checkServer(const QUrl &url)
{
qDebug() << "Checking for ownCloud instance at" << url;
setWorking(true);
......@@ -66,7 +66,7 @@ void QmlHelper::checkServer(const QUrl &url)
connect(job, SIGNAL(finished(KJob*)), this, SLOT(fileChecked(KJob*)));
}
void QmlHelper::figureOutServer(const QUrl& url)
void OwncloudController::figureOutServer(const QUrl& url)
{
if (/*url == QLatin1String("/") ||*/ url.isEmpty()) {
serverCheckResult(false);
......@@ -88,13 +88,13 @@ void QmlHelper::figureOutServer(const QUrl& url)
}
}
void QmlHelper::dataReceived(KIO::Job *job, const QByteArray &data)
void OwncloudController::dataReceived(KIO::Job *job, const QByteArray &data)
{
Q_UNUSED(job);
m_json.append(data);
}
void QmlHelper::fileChecked(KJob* job)
void OwncloudController::fileChecked(KJob* job)
{
KIO::TransferJob *kJob = qobject_cast<KIO::TransferJob *>(job);
if (kJob->error()) {
......@@ -117,7 +117,7 @@ void QmlHelper::fileChecked(KJob* job)
serverCheckResult(true);
}
void QmlHelper::setWorking(bool start)
void OwncloudController::setWorking(bool start)
{
if (start == m_isWorking) {
return;
......@@ -127,7 +127,7 @@ void QmlHelper::setWorking(bool start)
Q_EMIT isWorkingChanged();
}
void QmlHelper::serverCheckResult(bool result)
void OwncloudController::serverCheckResult(bool result)
{
m_noError = result;
Q_EMIT noErrorChanged();
......@@ -176,7 +176,7 @@ void QmlHelper::serverCheckResult(bool result)
}
void QmlHelper::authCheckResult(KJob *job)
void OwncloudController::authCheckResult(KJob *job)
{
if (job->error()) {
qDebug() << job->errorString();
......@@ -199,22 +199,22 @@ void QmlHelper::authCheckResult(KJob *job)
setWorking(false);
}
bool QmlHelper::isWorking()
bool OwncloudController::isWorking()
{
return m_isWorking;
}
bool QmlHelper::noError()
bool OwncloudController::noError()
{
return m_noError;
}
QString QmlHelper::errorMessage() const
QString OwncloudController::errorMessage() const
{
return m_errorMessage;
}
void QmlHelper::finish(bool contactsEnabled)
void OwncloudController::finish(bool contactsEnabled)
{
QVariantMap data;
data.insert("server", m_server);
......@@ -230,5 +230,3 @@ void QmlHelper::finish(bool contactsEnabled)
Q_EMIT wizardFinished(m_username, m_password, data);
}
#include "qmlhelper.moc"
......@@ -16,7 +16,7 @@ namespace KIO
};
class KJob;
class QmlHelper : public QObject
class OwncloudController : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isWorking READ isWorking NOTIFY isWorkingChanged)
......@@ -24,8 +24,8 @@ class QmlHelper : public QObject
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
public:
explicit QmlHelper(QObject *parent = 0);
~QmlHelper();
explicit OwncloudController(QObject *parent = 0);
~OwncloudController();
Q_INVOKABLE void checkServer(const QString &username, const QString &password, const QString &server);
Q_INVOKABLE void finish(bool contactsEnabled);
......
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