implement MKCOL with QHttp to make it work with Qt 4.6

This commit is contained in:
Thomas Müller 2012-04-20 23:58:09 +02:00
parent 9e163a3c28
commit 8695b8fb3c
6 changed files with 98 additions and 20 deletions

View file

@ -174,8 +174,8 @@ FolderWizardTargetPage::FolderWizardTargetPage()
connect( _ownCloudDirCheck, SIGNAL(ownCloudDirExists(QString,QNetworkReply*)),
SLOT(slotDirCheckReply(QString,QNetworkReply*)));
connect( _ownCloudDirCheck, SIGNAL(webdavColCreated(QNetworkReply*)),
SLOT(slotCreateRemoteFolderFinished( QNetworkReply* )));
connect( _ownCloudDirCheck, SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),
SLOT(slotCreateRemoteFolderFinished( QNetworkReply::NetworkError )));
}
void FolderWizardTargetPage::slotFolderTextChanged( const QString& t)
@ -223,14 +223,14 @@ void FolderWizardTargetPage::slotCreateRemoteFolder()
_ownCloudDirCheck->mkdirRequest( folder );
}
void FolderWizardTargetPage::slotCreateRemoteFolderFinished( QNetworkReply *reply )
void FolderWizardTargetPage::slotCreateRemoteFolderFinished( QNetworkReply::NetworkError error )
{
qDebug() << "** webdav mkdir request finished " << reply->error();
qDebug() << "** webdav mkdir request finished " << error;
_ui.OCFolderLineEdit->setEnabled( true );
// the webDAV server seems to return a 202 even if mkdir was successful.
if( reply->error() == QNetworkReply::NoError ||
reply->error() == QNetworkReply::ContentOperationNotPermittedError) {
if( error == QNetworkReply::NoError ||
error == QNetworkReply::ContentOperationNotPermittedError) {
showWarn( tr("Folder on ownCloud was successfully created."), false );
slotTimerFires();
} else {

View file

@ -92,7 +92,7 @@ protected slots:
void slotDirCheckReply( const QString&, QNetworkReply* );
void showWarn( const QString& = QString(), bool showCreateButton = false ) const;
void slotCreateRemoteFolder();
void slotCreateRemoteFolderFinished( QNetworkReply* );
void slotCreateRemoteFolderFinished( QNetworkReply::NetworkError error );
private:
Ui_FolderWizardTargetPage _ui;

View file

@ -24,6 +24,10 @@
#include "mirall/version.h"
#include "mirall/sslerrordialog.h"
#if QT46_IMPL
#include <QHttp>
#endif
namespace Mirall
{
@ -91,9 +95,72 @@ void ownCloudInfo::getRequest( const QString& path, bool webdav )
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
this, SLOT(slotError( QNetworkReply::NetworkError )));
}
#if QT46_IMPL
void ownCloudInfo::mkdirRequest( const QString& dir )
{
qDebug() << "OCInfo Making dir " << dir;
MirallConfigFile cfgFile;
QUrl url = QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir );
QHttp::ConnectionMode conMode = QHttp::ConnectionModeHttp;
if (url.scheme() == "https")
conMode = QHttp::ConnectionModeHttps;
QHttp* qhttp = new QHttp(url.host(), conMode, 0, this);
qhttp->setUser( cfgFile.ownCloudUser( _connection ), cfgFile.ownCloudPasswd( _connection ));
connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int)));
connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
connect(qhttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(qhttpResponseHeaderReceived(QHttpResponseHeader)));
//connect(qhttp, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), this, SLOT(qhttpAuthenticationRequired(QString,quint16,QAuthenticator*)));
QHttpRequestHeader header("MKCOL", url.path(), 1,1); /* header */
header.setValue("Host", url.host() );
header.setValue("User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii() );
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
header.setValue("Connection", "keep-alive");
header.setContentType("application/x-www-form-urlencoded"); //important
header.setContentLength(0);
header.setValue("Authorization", cfgFile.basicAuthHeader());
int david = qhttp->request(header,0,0);
//////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int)));
/////////////////connect(davinfo, SIGNAL(done(bool)), this,SLOT(DavWake(bool)));
//connect(_http, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
///////////connect(davinfo, SIGNAL(responseHeaderReceived(constQHttpResponseHeader &)), this, SLOT(RegisterBackHeader(constQHttpResponseHeader &)));
}
void ownCloudInfo::qhttpResponseHeaderReceived(const QHttpResponseHeader& header)
{
qDebug() << "Resp:" << header.toString();
if (header.statusCode() == 201)
emit webdavColCreated( QNetworkReply::NoError );
else
qDebug() << "http request failed" << header.toString();
}
void ownCloudInfo::qhttpRequestStarted(int id)
{
qDebug() << "QHttp based request started " << id;
}
void ownCloudInfo::qhttpRequestFinished(int id, bool success )
{
qDebug() << "HIT!";
QHttp* qhttp = qobject_cast<QHttp*>(sender());
if( success ) {
qDebug() << "QHttp based request successful";
} else {
qDebug() << "QHttp based request failed: " << qhttp->errorString();
}
}
#else
void ownCloudInfo::mkdirRequest( const QString& dir )
{
qDebug() << "OCInfo Making dir " << dir;
@ -120,11 +187,11 @@ void ownCloudInfo::slotMkdirFinished()
return;
}
emit webdavColCreated( reply );
emit webdavColCreated( reply->error() );
qDebug() << "mkdir slot hit.";
reply->deleteLater();
}
#endif
void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth )
{
@ -269,8 +336,6 @@ void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
QNetworkReply* ownCloudInfo::davRequest(const QString& reqVerb, QNetworkRequest& req, QByteArray *data)
{
MirallConfigFile cfgFile;
setupHeaders(req, quint64(data ? data->size() : 0));
if( data ) {
QBuffer iobuf( data );

View file

@ -18,6 +18,12 @@
#include <QObject>
#include <QtNetwork>
#if QT_VERSION >= 0x040700
#define QT46_IMPL 0
#else
#define QT46_IMPL 1
#endif
namespace Mirall
{
@ -65,7 +71,7 @@ signals:
void noOwncloudFound( QNetworkReply* );
void ownCloudDirExists( const QString&, QNetworkReply* );
void webdavColCreated( QNetworkReply* );
void webdavColCreated( QNetworkReply::NetworkError );
public slots:
@ -75,7 +81,14 @@ protected slots:
void slotAuthentication( QNetworkReply*, QAuthenticator *);
void slotSSLFailed( QNetworkReply *reply, QList<QSslError> errors );
#if QT46_IMPL
void qhttpRequestFinished(int id, bool success );
void qhttpRequestStarted(int id);
void qhttpResponseHeaderReceived(const QHttpResponseHeader& header);
// void qhttpAuthenticationRequired(const QString& hostname, quint16 port ,QAuthenticator* authenticator);
#else
void slotMkdirFinished();
#endif
private:
void setupHeaders(QNetworkRequest &req, quint64 size );

View file

@ -74,7 +74,7 @@ OwncloudSetupWizard::OwncloudSetupWizard( FolderMan *folderMan, Theme *theme, QO
_ocInfo = new ownCloudInfo;
connect(_ocInfo,SIGNAL(ownCloudInfoFound(QString,QString)),SLOT(slotOwnCloudFound(QString,QString)));
connect(_ocInfo,SIGNAL(noOwncloudFound(QNetworkReply*)),SLOT(slotNoOwnCloudFound(QNetworkReply*)));
connect(_ocInfo,SIGNAL(webdavColCreated(QNetworkReply*)),SLOT(slotCreateRemoteFolderFinished(QNetworkReply*)));
connect(_ocInfo,SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));
}
OwncloudSetupWizard::~OwncloudSetupWizard()
@ -359,11 +359,11 @@ bool OwncloudSetupWizard::createRemoteFolder( const QString& folder )
return true;
}
void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply *reply )
void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply::NetworkError error )
{
qDebug() << "** webdav mkdir request finished " << reply->error();
qDebug() << "** webdav mkdir request finished " << error;
if( reply->error() == QNetworkReply::NoError ) {
if( error == QNetworkReply::NoError ) {
_ocWizard->appendToResultWidget( tr("Remote folder %1 created sucessfully.").arg(_remoteFolder));
// Now write the resulting folder definition
@ -371,13 +371,13 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply *reply )
_folderMan->addFolderDefinition("owncloud", "ownCloud", _localFolder, _remoteFolder, false );
_ocWizard->appendToResultWidget(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(_localFolder));
}
} else if( reply->error() == 202 ) {
} else if( error == 202 ) {
_ocWizard->appendToResultWidget(tr("The remote folder %1 already exists. Automatic sync setup is skipped for security reasons. Please configure your sync folder manually.").arg(_remoteFolder));
} else if( reply->error() == QNetworkReply::OperationCanceledError ) {
} else if( error == QNetworkReply::OperationCanceledError ) {
_ocWizard->appendToResultWidget( tr("<p><font color=\"red\">Remote folder creation failed probably because the provided credentials are wrong.</font>"
"<br/>Please go back and check your credentials.</p>"));
} else {
_ocWizard->appendToResultWidget( tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(_remoteFolder).arg(reply->errorString()));
_ocWizard->appendToResultWidget( tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(_remoteFolder).arg(error));
}
}

View file

@ -80,7 +80,7 @@ protected slots:
private slots:
void slotOwnCloudFound( const QString&, const QString& );
void slotNoOwnCloudFound( QNetworkReply* );
void slotCreateRemoteFolderFinished( QNetworkReply* );
void slotCreateRemoteFolderFinished( QNetworkReply::NetworkError );
private:
bool checkOwncloudAdmin( const QString& );