diff options
Diffstat (limited to 'src/mirall/owncloudinfo.cpp')
-rw-r--r-- | src/mirall/owncloudinfo.cpp | 79 |
1 files changed, 10 insertions, 69 deletions
diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index e31a7d609..296598e83 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -15,8 +15,8 @@ #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" #include "mirall/theme.h" -#include "mirall/utility.h" #include "mirall/logger.h" +#include "creds/abstractcredentials.h" #include <QtCore> #include <QtGui> @@ -50,14 +50,14 @@ ownCloudInfo::ownCloudInfo() : QObject(0), _manager(0), _authAttempts(0), - _lastQuotaTotalBytes(0), - _lastQuotaUsedBytes(0) + _lastQuotaUsedBytes(0), + _lastQuotaTotalBytes(0) { _connection = Theme::instance()->appName(); connect(this, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString))); - setNetworkAccessManager( new QNetworkAccessManager( this ) ); - + // this will set credentials specific qnam + setCustomConfigHandle(QString()); } void ownCloudInfo::setNetworkAccessManager( QNetworkAccessManager* qnam ) @@ -72,13 +72,7 @@ void ownCloudInfo::setNetworkAccessManager( QNetworkAccessManager* qnam ) connect( _manager, SIGNAL( sslErrors(QNetworkReply*, QList<QSslError>)), this, SIGNAL(sslFailed(QNetworkReply*, QList<QSslError>)) ); - // The authenticationRequired signal is not handled because the creds are set - // in the request header. - connect( _manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), - this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*))); - _certsUntrusted = false; - } ownCloudInfo::~ownCloudInfo() @@ -90,6 +84,8 @@ void ownCloudInfo::setCustomConfigHandle( const QString& handle ) _configHandle = handle; _authAttempts = 0; // allow a couple of tries again. resetSSLUntrust(); + MirallConfigFile cfg(_configHandle); + setNetworkAccessManager (cfg.getCredentials()->getQNAM()); } bool ownCloudInfo::isConfigured() @@ -311,42 +307,6 @@ void ownCloudInfo::slotGetDirectoryListingFinished() reply->deleteLater(); } -// FIXME: remove this later, once the new connection dialog has settled. -void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth ) -{ - if( !(auth && reply) ) return; - QString configHandle; - - // an empty config handle is ok for the default config. - if( _configHandleMap.contains(reply) ) { - configHandle = _configHandleMap[reply]; - qDebug() << "Auth: Have a custom config handle: " << configHandle; - } - - qDebug() << "Auth request to me and I am " << this; - _authAttempts++; - qDebug() << "Authenticating request for " << reply->url(); - if( reply->url().toString().startsWith( webdavUrl( _connection ) ) ) { - QString con = configHandle; - if( con.isEmpty() ) con = DEFAULT_CONNECTION; - if( _credentials.contains(con)) { - oCICredentials creds = _credentials.value(con); - - auth->setUser( creds.user ); - auth->setPassword( creds.passwd ); - } else { - qDebug() << "Unable to get Credentials, not set!"; - reply->close(); - } - } else { - qDebug() << "WRN: attempt to authenticate to different url - attempt " <<_authAttempts; - } - if( _authAttempts > 1) { - qDebug() << "Too many attempts to authenticate. Stop request."; - reply->close(); - } -} - QList<QNetworkCookie> ownCloudInfo::getLastAuthCookies() { QUrl url = QUrl( webdavUrl(_connection)); @@ -483,8 +443,8 @@ void ownCloudInfo::slotReplyFinished() // get version out edition = val; } else if(key == QLatin1String("installed")) { - // Silently ignoring "installed = true" information - } else { + // Silently ignoring "installed = true" information + } else { qDebug() << "Unknown info from ownCloud status.php: "<< key << "=" << val; } } @@ -560,30 +520,11 @@ void ownCloudInfo::slotError( QNetworkReply::NetworkError err) } } -void ownCloudInfo::setCredentials( const QString& user, const QString& passwd, - const QString& configHandle ) -{ - QString con( configHandle ); - if( configHandle.isEmpty() ) - con = DEFAULT_CONNECTION; - - if( _credentials.contains(con) ) { - qDebug() << "Overwriting credentials for connection " << con; - } - - oCICredentials creds; - creds.user = user; - creds.passwd = passwd; - creds.connection = con; - _credentials[con] = creds; -} - // ============================================================================ void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size ) { QUrl url( req.url() ); qDebug() << "Setting up host header: " << url.host(); - req.setRawHeader( QByteArray("User-Agent"), Utility::userAgentString()); if (size) { req.setHeader( QNetworkRequest::ContentLengthHeader, size); @@ -612,4 +553,4 @@ QString ownCloudInfo::webdavUrl(const QString &connection) return url; } -} +} // ns Mirall |