mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
WIP: Dissolve owncloudinfo class
This commit is contained in:
parent
a91ba0fd48
commit
29c846a764
16 changed files with 339 additions and 43 deletions
|
@ -1,3 +1,5 @@
|
|||
add_subdirectory(integration)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
qt_add_resources(MIRALL_RC_SRC ../mirall.qrc)
|
||||
|
@ -27,6 +29,7 @@ set(3rdparty_HEADER
|
|||
3rdparty/fancylineedit/fancylineedit.h
|
||||
3rdparty/QProgressIndicator/QProgressIndicator.h
|
||||
)
|
||||
|
||||
qt_wrap_cpp(3rdparty_MOC ${3rdparty_HEADER})
|
||||
|
||||
if(NOT WIN32)
|
||||
|
@ -59,13 +62,14 @@ set(libsync_SRCS
|
|||
mirall/fileutils.cpp
|
||||
mirall/theme.cpp
|
||||
mirall/owncloudtheme.cpp
|
||||
mirall/owncloudinfo.cpp
|
||||
# mirall/owncloudinfo.cpp
|
||||
mirall/logger.cpp
|
||||
mirall/utility.cpp
|
||||
mirall/connectionvalidator.cpp
|
||||
mirall/progressdispatcher.cpp
|
||||
mirall/mirallaccessmanager.cpp
|
||||
mirall/networkjobs.cpp
|
||||
mirall/account.cpp
|
||||
creds/dummycredentials.cpp
|
||||
creds/httpcredentials.cpp
|
||||
creds/credentialsfactory.cpp
|
||||
|
@ -90,12 +94,13 @@ set(libsync_HEADERS
|
|||
mirall/syncjournaldb.h
|
||||
mirall/theme.h
|
||||
mirall/owncloudtheme.h
|
||||
mirall/owncloudinfo.h
|
||||
# mirall/owncloudinfo.h
|
||||
mirall/logger.h
|
||||
mirall/connectionvalidator.h
|
||||
mirall/progressdispatcher.h
|
||||
mirall/mirallaccessmanager.h
|
||||
mirall/networkjobs.h
|
||||
mirall/account.h
|
||||
creds/abstractcredentials.h
|
||||
creds/dummycredentials.h
|
||||
creds/httpcredentials.h
|
||||
|
|
|
@ -15,14 +15,16 @@
|
|||
*/
|
||||
|
||||
#include <QMutex>
|
||||
#include <QDebug>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "creds/httpcredentials.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/account.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/mirallaccessmanager.h"
|
||||
#include "mirall/utility.h"
|
||||
#include "creds/http/credentialstore.h"
|
||||
#include "creds/credentialscommon.h"
|
||||
#include "creds/http/credentialstore.h"
|
||||
#include "creds/httpcredentials.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
@ -105,7 +107,7 @@ void HttpCredentials::syncContextPreStart (CSYNC* ctx)
|
|||
// any way to get "session_key" module property from csync. Had we
|
||||
// have it, then we could remove this code and keep it in
|
||||
// csyncthread code (or folder code, git remembers).
|
||||
QList<QNetworkCookie> cookies(ownCloudInfo::instance()->getLastAuthCookies());
|
||||
QList<QNetworkCookie> cookies(AccountManager::instance()->account()->lastAuthCookies());
|
||||
QString cookiesAsString;
|
||||
|
||||
// Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
|
||||
|
|
141
src/mirall/account.cpp
Normal file
141
src/mirall/account.cpp
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "mirall/account.h"
|
||||
#include "mirall/mirallaccessmanager.h"
|
||||
#include "mirall/theme.h"
|
||||
#include "creds/abstractcredentials.h"
|
||||
#include "creds/credentialsfactory.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QMutex>
|
||||
#include <QNetworkReply>
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
static const char urlC[] = "url";
|
||||
static const char authTypeC[] = "authType";
|
||||
|
||||
AccountManager *AccountManager::_instance = 0;
|
||||
|
||||
AccountManager *AccountManager::instance()
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (!_instance)
|
||||
{
|
||||
mutex.lock();
|
||||
|
||||
if (!_instance) {
|
||||
_instance = new AccountManager;
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
|
||||
Account::Account(QObject *parent)
|
||||
: QObject(parent)
|
||||
, _am(new MirallAccessManager)
|
||||
, _credentials(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Account::save(QSettings &settings)
|
||||
{
|
||||
settings.beginGroup(Theme::instance()->appName());
|
||||
settings.setValue(QLatin1String(urlC), _url);
|
||||
if (_credentials) {
|
||||
settings.setValue(QLatin1String(authTypeC), _credentials->authType());
|
||||
}
|
||||
}
|
||||
|
||||
Account* Account::restore(QSettings settings)
|
||||
{
|
||||
Account *acc = new Account;
|
||||
settings.beginGroup(Theme::instance()->appName());
|
||||
acc->setUrl(settings.value(QLatin1String(urlC)).toUrl());
|
||||
acc->setCredentials(CredentialsFactory::create(settings.value(QLatin1String(authTypeC)).toString()));
|
||||
return acc;
|
||||
}
|
||||
|
||||
AbstractCredentials *Account::credentials() const
|
||||
{
|
||||
return _credentials;
|
||||
}
|
||||
|
||||
void Account::setCredentials(AbstractCredentials *cred)
|
||||
{
|
||||
_credentials = cred;
|
||||
}
|
||||
|
||||
QUrl Account::url() const
|
||||
{
|
||||
return _url;
|
||||
}
|
||||
|
||||
static const char WEBDAV_PATH[] = "remote.php/webdav/";
|
||||
|
||||
QUrl Account::davUrl() const
|
||||
{
|
||||
return concatUrlPath(url(), WEBDAV_PATH);
|
||||
}
|
||||
|
||||
QList<QNetworkCookie> Account::lastAuthCookies() const
|
||||
{
|
||||
return _am->cookieJar()->cookiesForUrl(_url);
|
||||
}
|
||||
|
||||
QNetworkReply *Account::getRequest(const QString &relPath)
|
||||
{
|
||||
QNetworkRequest request(concatUrlPath(url(), relPath));
|
||||
// ### error handling
|
||||
return _am->get(request);
|
||||
}
|
||||
|
||||
QNetworkReply *Account::davRequest(const QString &relPath, const QByteArray &verb, QIODevice *data)
|
||||
{
|
||||
QNetworkRequest request(concatUrlPath(davUrl(), relPath));
|
||||
// ### error handling
|
||||
return _am->sendCustomRequest(request, verb, data);
|
||||
}
|
||||
|
||||
void Account::setUrl(const QUrl &url)
|
||||
{
|
||||
_url = url;
|
||||
}
|
||||
|
||||
QByteArray Account::caCerts() const
|
||||
{
|
||||
return _caCerts;
|
||||
}
|
||||
|
||||
void Account::setCaCerts(const QByteArray &caCerts)
|
||||
{
|
||||
_caCerts = caCerts;
|
||||
}
|
||||
|
||||
QUrl Account::concatUrlPath(const QUrl &url, const QString &concatPath) const
|
||||
{
|
||||
QUrl tmpUrl = url;
|
||||
QString path = tmpUrl.path();
|
||||
if (!path.endsWith('/')) {
|
||||
path += QLatin1Char('/');
|
||||
}
|
||||
path += concatPath;
|
||||
tmpUrl.setPath(path);
|
||||
return tmpUrl;
|
||||
}
|
||||
|
||||
} // namespace Mirall
|
94
src/mirall/account.h
Normal file
94
src/mirall/account.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
class QSettings;
|
||||
class QNetworkReply;
|
||||
class QUrl;
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
class MirallAccessManager;
|
||||
class AbstractCredentials;
|
||||
class Account;
|
||||
|
||||
class AccountManager {
|
||||
public:
|
||||
static AccountManager *instance();
|
||||
~AccountManager();
|
||||
|
||||
void setAccount(Account *account) { _account = account; }
|
||||
Account *account() { return _account; }
|
||||
|
||||
private:
|
||||
AccountManager();
|
||||
Account *_account;
|
||||
static AccountManager *_instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class represents an account on an ownCloud Server
|
||||
*/
|
||||
class Account : public QObject {
|
||||
public:
|
||||
/**
|
||||
* Saves the account to a given settings file
|
||||
*/
|
||||
void save(QSettings &settings);
|
||||
|
||||
/**
|
||||
* Creates an account object from from a given settings file.
|
||||
*/
|
||||
static Account* restore(QSettings settings);
|
||||
|
||||
/** Holds the accounts credentials */
|
||||
AbstractCredentials* credentials() const;
|
||||
void setCredentials(AbstractCredentials *cred);
|
||||
|
||||
/** Server url of the account */
|
||||
void setUrl(const QUrl &url);
|
||||
QUrl url() const;
|
||||
|
||||
/** Returns webdav entry URL, based on url() */
|
||||
QUrl davUrl() const;
|
||||
|
||||
QList<QNetworkCookie> lastAuthCookies() const;
|
||||
|
||||
QNetworkReply* getRequest(const QString &relPath);
|
||||
QNetworkReply* davRequest(const QString &relPath, const QByteArray &verb, QIODevice *data = 0);
|
||||
|
||||
/** The certificates of the account */
|
||||
QByteArray caCerts() const;
|
||||
void setCaCerts(const QByteArray &certs);
|
||||
|
||||
protected:
|
||||
QUrl concatUrlPath(const QUrl &url, const QString &concatPath) const;
|
||||
|
||||
private:
|
||||
Account(QObject *parent = 0);
|
||||
MirallAccessManager *_am;
|
||||
QByteArray _caCerts;
|
||||
QUrl _url;
|
||||
AbstractCredentials* _credentials;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //SERVERCONNECTION_H
|
|
@ -216,7 +216,7 @@ void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f )
|
|||
if( ! item || !f ) return;
|
||||
|
||||
item->setData( f->nativePath(), FolderStatusDelegate::FolderPathRole );
|
||||
item->setData( f->secondPath(), FolderStatusDelegate::FolderSecondPathRole );
|
||||
item->setData( f->remotePath(), FolderStatusDelegate::FolderSecondPathRole );
|
||||
item->setData( f->alias(), FolderStatusDelegate::FolderAliasRole );
|
||||
item->setData( f->syncEnabled(), FolderStatusDelegate::FolderSyncEnabled );
|
||||
|
||||
|
@ -568,7 +568,7 @@ QString AccountSettings::shortenFilename( const QString& folder, const QString&
|
|||
// rip off the whole ownCloud URL.
|
||||
Folder *f = FolderMan::instance()->folder(folder);
|
||||
if( f ) {
|
||||
QString remotePathUrl = ownCloudInfo::instance()->webdavUrl() + QLatin1Char('/') + f->secondPath();
|
||||
QString remotePathUrl = ownCloudInfo::instance()->webdavUrl() + QLatin1Char('/') + f->remotePath();
|
||||
shortFile.remove(Utility::toCSyncScheme(remotePathUrl));
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "mirall/utility.h"
|
||||
#include "mirall/connectionvalidator.h"
|
||||
#include "mirall/socketapi.h"
|
||||
#include "mirall/account.h"
|
||||
|
||||
#include "creds/abstractcredentials.h"
|
||||
|
||||
|
@ -114,6 +115,7 @@ Application::Application(int &argc, char **argv) :
|
|||
|
||||
connect( this, SIGNAL(messageReceived(QString)), SLOT(slotParseOptions(QString)));
|
||||
|
||||
AccountManager::instance()->setAccount(Account::restore(Theme::instance()->appName()));
|
||||
FolderMan::instance()->setSyncEnabled(false);
|
||||
|
||||
setQuitOnLastWindowClosed(false);
|
||||
|
@ -133,7 +135,6 @@ Application::Application(int &argc, char **argv) :
|
|||
_theme->setSystrayUseMonoIcons(cfg.monoIcons());
|
||||
connect (_theme, SIGNAL(systrayUseMonoIconsChanged(bool)), SLOT(slotUseMonoIconsChanged(bool)));
|
||||
|
||||
|
||||
FolderMan::instance()->setupFolders();
|
||||
slotSetupProxy(); // folders have to be defined first.
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
*/
|
||||
|
||||
#include <QtCore>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "mirall/connectionvalidator.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/theme.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/theme.h"
|
||||
#include "mirall/logger.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "owncloudpropagator.h"
|
||||
#include "progressdatabase.h"
|
||||
#include "syncjournaldb.h"
|
||||
|
|
|
@ -15,17 +15,19 @@
|
|||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include "mirall/account.h"
|
||||
#include "mirall/folder.h"
|
||||
#include "mirall/folderman.h"
|
||||
#include "mirall/folderwatcher.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/syncresult.h"
|
||||
#include "mirall/logger.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/utility.h"
|
||||
#include "folderman.h"
|
||||
#include "creds/abstractcredentials.h"
|
||||
#include "mirall/syncjournalfilerecord.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/networkjobs.h"
|
||||
#include "mirall/syncjournalfilerecord.h"
|
||||
#include "mirall/syncresult.h"
|
||||
#include "mirall/utility.h"
|
||||
|
||||
#include "creds/abstractcredentials.h"
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -55,7 +57,7 @@ namespace Mirall {
|
|||
Folder::Folder(const QString &alias, const QString &path, const QString& secondPath, QObject *parent)
|
||||
: QObject(parent)
|
||||
, _path(path)
|
||||
, _secondPath(secondPath)
|
||||
, _remotePath(secondPath)
|
||||
, _alias(alias)
|
||||
, _enabled(true)
|
||||
, _thread(0)
|
||||
|
@ -95,7 +97,7 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP
|
|||
|
||||
bool Folder::init()
|
||||
{
|
||||
QString url = Utility::toCSyncScheme(ownCloudInfo::instance()->webdavUrl() + secondPath());
|
||||
QString url = Utility::toCSyncScheme(remoteUrl().toString());
|
||||
QString localpath = path();
|
||||
|
||||
if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url.toUtf8().data() ) < 0 ) {
|
||||
|
@ -195,9 +197,23 @@ bool Folder::isBusy() const
|
|||
return ( _thread && _thread->isRunning() );
|
||||
}
|
||||
|
||||
QString Folder::secondPath() const
|
||||
QString Folder::remotePath() const
|
||||
{
|
||||
return _secondPath;
|
||||
return _remotePath;
|
||||
}
|
||||
|
||||
QUrl Folder::remoteUrl() const
|
||||
{
|
||||
Account *account = AccountManager::instance()->account();
|
||||
QUrl url = account->url();
|
||||
QString path = url.path();
|
||||
if (path.endsWith('/')) {
|
||||
path.append('/');
|
||||
}
|
||||
path.append(_remotePath);
|
||||
url.setPath(path);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QString Folder::nativePath() const
|
||||
|
@ -256,7 +272,7 @@ void Folder::slotPollTimerTimeout()
|
|||
qDebug() << "** Force Sync now";
|
||||
evaluateSync(QStringList());
|
||||
} else {
|
||||
RequestEtagJob* job = new RequestEtagJob(secondPath(), this);
|
||||
RequestEtagJob* job = new RequestEtagJob(remotePath(), this);
|
||||
// check if the etag is different
|
||||
QObject::connect(job, SIGNAL(etagRetreived(QString)), this, SLOT(etagRetreived(QString)));
|
||||
QObject::connect(job, SIGNAL(networkError()), this, SLOT(slotNetworkUnavailable()));
|
||||
|
@ -486,7 +502,7 @@ void Folder::setProxy()
|
|||
{
|
||||
if( _csync_ctx ) {
|
||||
/* Store proxy */
|
||||
QUrl proxyUrl(ownCloudInfo::instance()->webdavUrl());
|
||||
QUrl proxyUrl = remoteUrl();
|
||||
QList<QNetworkProxy> proxies = QNetworkProxyFactory::proxyForQuery(QNetworkProxyQuery(proxyUrl));
|
||||
// We set at least one in Application
|
||||
Q_ASSERT(proxies.count() > 0);
|
||||
|
@ -579,7 +595,7 @@ void Folder::startSync(const QStringList &pathList)
|
|||
qDebug() << "*** Start syncing";
|
||||
_thread = new QThread(this);
|
||||
setIgnoredFiles();
|
||||
_csync = new CSyncThread( _csync_ctx, path(), QUrl(ownCloudInfo::instance()->webdavUrl() + secondPath()).path(), &_journal);
|
||||
_csync = new CSyncThread( _csync_ctx, path(), remoteUrl().toString(), &_journal);
|
||||
_csync->moveToThread(_thread);
|
||||
|
||||
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
|
||||
|
@ -654,7 +670,8 @@ void Folder::slotCSyncFinished()
|
|||
_thread->quit();
|
||||
}
|
||||
emit syncStateChange();
|
||||
ownCloudInfo::instance()->getQuotaRequest("/");
|
||||
// ### TODO: Where to rig up the quotas
|
||||
// ownCloudInfo::instance()->getQuotaRequest("/");
|
||||
emit syncFinished( _syncResult );
|
||||
}
|
||||
|
||||
|
@ -666,8 +683,7 @@ void Folder::slotTransmissionProgress(const Progress::Info& progress)
|
|||
if(newInfo.current_file.startsWith(QLatin1String("ownclouds://")) ||
|
||||
newInfo.current_file.startsWith(QLatin1String("owncloud://")) ) {
|
||||
// rip off the whole ownCloud URL.
|
||||
QString remotePathUrl = ownCloudInfo::instance()->webdavUrl() + secondPath();
|
||||
newInfo.current_file.remove(Utility::toCSyncScheme(remotePathUrl));
|
||||
newInfo.current_file.remove(Utility::toCSyncScheme(remoteUrl().toString()));
|
||||
}
|
||||
QString localPath = path();
|
||||
if( newInfo.current_file.startsWith(localPath) ) {
|
||||
|
|
|
@ -80,10 +80,16 @@ public:
|
|||
* local folder path
|
||||
*/
|
||||
QString path() const;
|
||||
|
||||
/**
|
||||
* remote folder path
|
||||
*/
|
||||
QString secondPath() const;
|
||||
QString remotePath() const;
|
||||
|
||||
/**
|
||||
* remote folder path with server url
|
||||
*/
|
||||
QUrl remoteUrl() const;
|
||||
|
||||
/**
|
||||
* local folder path with native separators
|
||||
|
@ -193,7 +199,7 @@ protected:
|
|||
void checkLocalPath();
|
||||
|
||||
QString _path;
|
||||
QString _secondPath;
|
||||
QString _remotePath;
|
||||
QString _alias;
|
||||
QString _configFile;
|
||||
QFileSystemWatcher *_pathWatcher;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "mirall/syncresult.h"
|
||||
#include "mirall/inotify.h"
|
||||
#include "mirall/theme.h"
|
||||
#include "owncloudinfo.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
@ -387,7 +386,8 @@ void FolderMan::slotScheduleFolderSync()
|
|||
if( ! _scheduleQueue.isEmpty() ) {
|
||||
const QString alias = _scheduleQueue.dequeue();
|
||||
if( _folderMap.contains( alias ) ) {
|
||||
ownCloudInfo::instance()->getQuotaRequest("/");
|
||||
//### TODO
|
||||
//ownCloudInfo::instance()->getQuotaRequest("/");
|
||||
Folder *f = _folderMap[alias];
|
||||
if( f->syncEnabled() ) {
|
||||
_currentSyncFolder = alias;
|
||||
|
|
|
@ -300,7 +300,7 @@ bool FolderWizardTargetPage::isComplete() const
|
|||
Folder::Map::const_iterator i = map.constBegin();
|
||||
for(i = map.constBegin();i != map.constEnd(); i++ ) {
|
||||
Folder *f = static_cast<Folder*>(i.value());
|
||||
QString curDir = f->secondPath();
|
||||
QString curDir = f->remotePath();
|
||||
if (dir == curDir) {
|
||||
showWarn( tr("This directory is already being synced.") );
|
||||
return false;
|
||||
|
|
|
@ -21,14 +21,23 @@ namespace Mirall
|
|||
|
||||
MirallAccessManager::MirallAccessManager(QObject* parent)
|
||||
: QNetworkAccessManager (parent)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
QNetworkReply* MirallAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData)
|
||||
{
|
||||
QNetworkRequest newRequest(request);
|
||||
|
||||
newRequest.setRawHeader( QByteArray("User-Agent"), Utility::userAgentString());
|
||||
return QNetworkAccessManager::createRequest (op, newRequest, outgoingData);
|
||||
newRequest.setRawHeader(QByteArray("User-Agent"), Utility::userAgentString());
|
||||
if (outgoingData) {
|
||||
newRequest.setHeader( QNetworkRequest::ContentLengthHeader, outgoingData->size());
|
||||
}
|
||||
QByteArray verb = newRequest.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray();
|
||||
// For PROPFIND (assumed to be a WebDAV op), set xml/utf8 as content type/encoding
|
||||
// This needs extension
|
||||
if (verb == "PROPFIND") {
|
||||
newRequest.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml; charset=utf-8"));
|
||||
}
|
||||
return QNetworkAccessManager::createRequest(op, newRequest, outgoingData);
|
||||
}
|
||||
|
||||
} // ns Mirall
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "config.h"
|
||||
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/owncloudtheme.h"
|
||||
#include "mirall/theme.h"
|
||||
#include "mirall/utility.h"
|
||||
|
@ -25,6 +24,12 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
#define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds
|
||||
#define DEFAULT_MAX_LOG_LINES 20000
|
||||
|
|
|
@ -15,16 +15,23 @@
|
|||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QBuffer>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QStringList>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/networkjobs.h"
|
||||
#include "mirall/account.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
AbstractNetworkJob::AbstractNetworkJob(QObject *parent)
|
||||
: QObject(parent), _reply(0)
|
||||
: QObject(parent)
|
||||
, _reply(0)
|
||||
, _account(AccountManager::instance()->account())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -40,6 +47,11 @@ QNetworkReply *AbstractNetworkJob::takeReply()
|
|||
return reply;
|
||||
}
|
||||
|
||||
void AbstractNetworkJob::setAccount(Account *account)
|
||||
{
|
||||
_account = account;
|
||||
}
|
||||
|
||||
void AbstractNetworkJob::slotError()
|
||||
{
|
||||
qDebug() << metaObject()->className() << "Error:" << _reply->errorString();
|
||||
|
@ -58,12 +70,12 @@ void AbstractNetworkJob::setupConnections(QNetworkReply *reply)
|
|||
|
||||
QNetworkReply* AbstractNetworkJob::davRequest(const QByteArray &verb, QNetworkRequest &req, QIODevice *data)
|
||||
{
|
||||
return ownCloudInfo::instance()->davRequest(verb, req, data);
|
||||
return _account->davRequest(verb, req, data);
|
||||
}
|
||||
|
||||
QNetworkReply* AbstractNetworkJob::getRequest(const QUrl &url)
|
||||
{
|
||||
return ownCloudInfo::instance()->simpleGetRequest(url);
|
||||
return _account->getRequest(url);
|
||||
}
|
||||
|
||||
AbstractNetworkJob::~AbstractNetworkJob() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
||||
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
||||
*
|
||||
|
@ -24,6 +24,8 @@ class QUrl;
|
|||
|
||||
namespace Mirall {
|
||||
|
||||
class Account;
|
||||
|
||||
/**
|
||||
* @brief The AbstractNetworkJob class
|
||||
*/
|
||||
|
@ -33,6 +35,9 @@ public:
|
|||
explicit AbstractNetworkJob(QObject* parent = 0);
|
||||
virtual ~AbstractNetworkJob();
|
||||
|
||||
void setAccount(Account *account);
|
||||
Account* account() const { return _account; }
|
||||
|
||||
void setReply(QNetworkReply *reply);
|
||||
QNetworkReply* reply() const { return _reply; }
|
||||
QNetworkReply* takeReply(); // for redirect handling
|
||||
|
@ -51,6 +56,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QNetworkReply *_reply;
|
||||
Account *_account;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue