added check for the owncloud folder - WIP

This commit is contained in:
Klaas Freitag 2011-10-06 16:55:28 +02:00
parent f3123b6c02
commit f4c5b9adbb
7 changed files with 159 additions and 4 deletions

View File

@ -36,6 +36,7 @@ mirall/statusdialog.cpp
mirall/owncloudwizard.cpp
mirall/owncloudsetup.cpp
mirall/owncloudinfo.cpp
mirall/ownclouddircheck.cpp
)
if(CSYNC_FOUND)
set(mirall_SRCS

View File

@ -20,10 +20,12 @@
#include <QValidator>
#include <QWizardPage>
#include <QDir>
#include <stdlib.h>
#include "mirall/folderwizard.h"
#include "mirall/owncloudinfo.h"
#include "mirall/ownclouddircheck.h"
namespace Mirall
@ -72,8 +74,45 @@ FolderWizardTargetPage::FolderWizardTargetPage()
registerField("targetLocalFolder", _ui.localFolder2LineEdit);
registerField("targetURLFolder", _ui.urlFolderLineEdit);
registerField("targetOCFolder", _ui.OCFolderLineEdit);
connect( _ui.OCFolderLineEdit, SIGNAL(textChanged(QString)),
SLOT(slotFolderTextChanged(QString)));
_timer = new QTimer(this);
_timer->setSingleShot( true );
connect( _timer, SIGNAL(timeout()), SLOT(slotTimerFires()));
_ownCloudInfo = new ownCloudInfo( this );
_ownCloudDirCheck = new ownCloudDirCheck( this );
connect( _ownCloudDirCheck, SIGNAL(directoryExists(QString,bool)),
SLOT(slotInfoReply(QString,bool)));
}
void FolderWizardTargetPage::slotFolderTextChanged( const QString& t)
{
if( t.isEmpty() ) {
_timer->stop();
return;
}
qDebug() << "XX new folder string: " << t;
_timer->start(500);
}
void FolderWizardTargetPage::slotTimerFires()
{
const QString folder = _ui.OCFolderLineEdit->text();
qDebug() << "Querying folder " << folder;
_ownCloudDirCheck->checkDirectory( folder );
}
void FolderWizardTargetPage::slotInfoReply(const QString &url, bool exists )
{
qDebug() << "Got reply from ownCloudInfo: " << url << " :" << exists;
}
FolderWizardTargetPage::~FolderWizardTargetPage()
{

View File

@ -16,6 +16,8 @@
#define MIRALL_FOLDERWIZARD_H
#include <QWizard>
#include <QNetworkReply>
#include <QTimer>
#include "ui_folderwizardsourcepage.h"
#include "ui_folderwizardtargetpage.h"
@ -25,6 +27,9 @@
namespace Mirall {
class ownCloudInfo;
class ownCloudDirCheck;
/**
* page to ask for the local source folder
*/
@ -73,8 +78,16 @@ protected slots:
void slotOwnCloudFound( const QString&, const QString& );
void slotNoOwnCloudFound();
void slotFolderTextChanged( const QString& );
void slotTimerFires();
void slotInfoReply( const QString&, bool );
private:
Ui_FolderWizardTargetPage _ui;
QTimer *_timer;
ownCloudInfo *_ownCloudInfo;
ownCloudDirCheck *_ownCloudDirCheck;
};
class FolderWizardNetworkPage : public QWizardPage

View File

@ -0,0 +1,54 @@
#include <QtCore>
#include "ownclouddircheck.h"
#include "owncloudinfo.h"
namespace Mirall {
ownCloudDirCheck::ownCloudDirCheck(QObject *parent) :
QObject(parent),
_manager( new QNetworkAccessManager ),
_reply(0)
{
connect( _manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(slotReplyFinished(QNetworkReply*)));
}
bool ownCloudDirCheck::checkDirectory( const QString& dir )
{
if( dir.isEmpty() ) {
// assume the root exists on the ownCloud
emit directoryExists( dir, true );
return true;
}
ownCloudInfo info;
if( _reply && _reply->isRunning() ) _reply->abort();
QNetworkRequest request;
request.setUrl( QUrl( info.url() + "/files/webdav.php/"+dir ) );
request.setRawHeader( "User-Agent", "mirall" );
QString concatenated = info.user() + ":" + info.password();
QByteArray data = concatenated.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
request.setRawHeader("Authorization", headerData.toLocal8Bit());
_reply = _manager->get( request );
}
void ownCloudDirCheck::slotReplyFinished( QNetworkReply *reply )
{
bool re = true;
if( reply->error() != QNetworkReply::NoError ) {
qDebug() << "Error in ownCloudDirCheck: " << reply->error();
re = false;
}
qDebug() << "ownCloudDirCheck ret code: " << reply->error();
emit directoryExists( reply->url().toString(), re );
}
}
#include "ownclouddircheck.moc"

View File

@ -0,0 +1,31 @@
#ifndef OWNCLOUDDIRCHECK_H
#define OWNCLOUDDIRCHECK_H
#include <QObject>
#include <QNetworkReply>
namespace Mirall {
class ownCloudDirCheck : public QObject
{
Q_OBJECT
public:
explicit ownCloudDirCheck(QObject *parent = 0);
bool checkDirectory( const QString& );
signals:
void directoryExists( const QString&, bool );
protected slots:
void slotReplyFinished( QNetworkReply* );
private:
QNetworkAccessManager *_manager;
QNetworkReply *_reply;
};
}
#endif // OWNCLOUDDIRCHECK_H

View File

@ -13,8 +13,11 @@
*/
#include "owncloudinfo.h"
#include "QtCore"
#include "QtGui"
#include <QtCore>
#include <QtGui>
#include <QAuthenticator>
namespace Mirall
{
@ -45,7 +48,9 @@ bool ownCloudInfo::isConfigured()
QString ownCloudInfo::url() const
{
QSettings settings( configFile(), QSettings::IniFormat );
return settings.value("ownCloud/url" ).toString();
QString url = settings.value("ownCloud/url").toString();
if( url.endsWith( QChar('/')) ) url.remove( -1, 1);
return url;
}
QString ownCloudInfo::user() const
@ -74,6 +79,14 @@ void ownCloudInfo::checkInstallation()
connect( _reply, SIGNAL( readyRead()), this, SLOT(slotReadyRead()));
}
void ownCloudInfo::slotAuthentication( QNetworkReply*, QAuthenticator *auth )
{
if( auth ) {
qDebug() << "Authenticating request!";
auth->setUser( user() );
auth->setPassword( password() );
}
}
void ownCloudInfo::slotReplyFinished( QNetworkReply *reply )
@ -81,6 +94,8 @@ void ownCloudInfo::slotReplyFinished( QNetworkReply *reply )
const QString version( _readBuffer );
const QString url = reply->url().toString();
emit ownCloudInfoReply( url, reply->error() );
QString info( version );
info.remove(0,1); // remove first char which is a "{"

View File

@ -40,13 +40,15 @@ signals:
void ownCloudInfoFound( const QString&, const QString& );
void noOwncloudFound();
void ownCloudInfoReply( const QString&, QNetworkReply::NetworkError );
public slots:
protected slots:
void slotReplyFinished( QNetworkReply* );
void slotReadyRead();
void slotError( QNetworkReply::NetworkError );
void slotAuthentication( QNetworkReply*, QAuthenticator *);
private:
QNetworkReply *_reply;
QByteArray _readBuffer;