2013-10-21 23:42:52 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERVERCONNECTION_H
|
|
|
|
#define SERVERCONNECTION_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QNetworkCookie>
|
2013-10-23 16:48:44 +04:00
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <QSslCertificate>
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
class QSettings;
|
|
|
|
class QNetworkReply;
|
|
|
|
class QUrl;
|
2013-10-23 16:48:44 +04:00
|
|
|
class QNetworkAccessManager;
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
class AbstractCredentials;
|
|
|
|
class Account;
|
|
|
|
|
|
|
|
class AccountManager {
|
|
|
|
public:
|
|
|
|
static AccountManager *instance();
|
|
|
|
~AccountManager();
|
|
|
|
|
|
|
|
void setAccount(Account *account) { _account = account; }
|
|
|
|
Account *account() { return _account; }
|
|
|
|
|
|
|
|
private:
|
2013-10-23 16:48:44 +04:00
|
|
|
AccountManager() {}
|
2013-10-21 23:42:52 +04:00
|
|
|
Account *_account;
|
|
|
|
static AccountManager *_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This class represents an account on an ownCloud Server
|
|
|
|
*/
|
|
|
|
class Account : public QObject {
|
|
|
|
public:
|
2013-10-23 16:48:44 +04:00
|
|
|
Account(QObject *parent = 0);
|
2013-10-21 23:42:52 +04:00
|
|
|
/**
|
|
|
|
* Saves the account to a given settings file
|
|
|
|
*/
|
|
|
|
void save(QSettings &settings);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an account object from from a given settings file.
|
|
|
|
*/
|
2013-10-23 16:48:44 +04:00
|
|
|
static Account* restore(QSettings &settings);
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
/** Holds the accounts credentials */
|
|
|
|
AbstractCredentials* credentials() const;
|
|
|
|
void setCredentials(AbstractCredentials *cred);
|
|
|
|
|
|
|
|
/** Server url of the account */
|
|
|
|
void setUrl(const QUrl &url);
|
2013-10-23 16:48:44 +04:00
|
|
|
QUrl url() const { return _url; }
|
|
|
|
|
|
|
|
/** User name of the account */
|
|
|
|
void setUser(const QString &user);
|
|
|
|
QString user() const { return _user; }
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
/** Returns webdav entry URL, based on url() */
|
|
|
|
QUrl davUrl() const;
|
|
|
|
|
|
|
|
QList<QNetworkCookie> lastAuthCookies() const;
|
|
|
|
|
|
|
|
QNetworkReply* getRequest(const QString &relPath);
|
2013-10-23 16:48:44 +04:00
|
|
|
QNetworkReply* davRequest(const QByteArray &verb, const QString &relPath, QNetworkRequest req, QIODevice *data = 0);
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
/** The certificates of the account */
|
2013-10-23 16:48:44 +04:00
|
|
|
QByteArray caCerts() const { return _caCerts; }
|
2013-10-21 23:42:52 +04:00
|
|
|
void setCaCerts(const QByteArray &certs);
|
2013-10-23 16:48:44 +04:00
|
|
|
/** The certificates of the account */
|
|
|
|
QByteArray acceptedCaCerts() const { return _acceptedCaCerts; }
|
|
|
|
void setAcceptedCaCerts(const QByteArray &certs);
|
2013-10-21 23:42:52 +04:00
|
|
|
|
2013-10-23 16:48:44 +04:00
|
|
|
QList<QSslCertificate> certificateChain() const;
|
|
|
|
|
|
|
|
static QUrl concatUrlPath(const QUrl &url, const QString &concatPath);
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
private:
|
2013-10-23 16:48:44 +04:00
|
|
|
QNetworkAccessManager *_am;
|
2013-10-21 23:42:52 +04:00
|
|
|
QByteArray _caCerts;
|
2013-10-23 16:48:44 +04:00
|
|
|
QByteArray _acceptedCaCerts;
|
2013-10-21 23:42:52 +04:00
|
|
|
QUrl _url;
|
2013-10-23 16:48:44 +04:00
|
|
|
QString _user;
|
2013-10-21 23:42:52 +04:00
|
|
|
AbstractCredentials* _credentials;
|
2013-10-23 16:48:44 +04:00
|
|
|
QList<QSslCertificate> _certificateChain;
|
2013-10-21 23:42:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SERVERCONNECTION_H
|