From 582ce4cfa0d69efab18ec6348f2c40682cff9c63 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 22 Jul 2013 14:54:14 +0200 Subject: Cleanup setup wizard. Split setup page into two. First page is for giving server URL and advanced setup and second page is for giving credentials. Second page will differ based on authentication type supported by ownCloud server. For now only HTTP credentials are supported. --- src/CMakeLists.txt | 17 +- src/mirall/owncloudhttpcredspage.ui | 130 +++++ src/mirall/owncloudsetupnocredspage.ui | 417 ++++++++++++++++ src/mirall/owncloudsetupwizard.cpp | 188 ++++++-- src/mirall/owncloudsetupwizard.h | 9 +- src/mirall/owncloudwizard.cpp | 627 ------------------------- src/mirall/owncloudwizard.h | 191 -------- src/mirall/wizard/owncloudhttpcredspage.cpp | 137 ++++++ src/mirall/wizard/owncloudhttpcredspage.h | 58 +++ src/mirall/wizard/owncloudsetuppage.cpp | 353 ++++++++++++++ src/mirall/wizard/owncloudsetuppage.h | 92 ++++ src/mirall/wizard/owncloudwizard.cpp | 173 +++++++ src/mirall/wizard/owncloudwizard.h | 86 ++++ src/mirall/wizard/owncloudwizardcommon.cpp | 72 +++ src/mirall/wizard/owncloudwizardcommon.h | 54 +++ src/mirall/wizard/owncloudwizardresultpage.cpp | 116 +++++ src/mirall/wizard/owncloudwizardresultpage.h | 57 +++ 17 files changed, 1909 insertions(+), 868 deletions(-) create mode 100644 src/mirall/owncloudhttpcredspage.ui create mode 100644 src/mirall/owncloudsetupnocredspage.ui delete mode 100644 src/mirall/owncloudwizard.cpp delete mode 100644 src/mirall/owncloudwizard.h create mode 100644 src/mirall/wizard/owncloudhttpcredspage.cpp create mode 100644 src/mirall/wizard/owncloudhttpcredspage.h create mode 100644 src/mirall/wizard/owncloudsetuppage.cpp create mode 100644 src/mirall/wizard/owncloudsetuppage.h create mode 100644 src/mirall/wizard/owncloudwizard.cpp create mode 100644 src/mirall/wizard/owncloudwizard.h create mode 100644 src/mirall/wizard/owncloudwizardcommon.cpp create mode 100644 src/mirall/wizard/owncloudwizardcommon.h create mode 100644 src/mirall/wizard/owncloudwizardresultpage.cpp create mode 100644 src/mirall/wizard/owncloudwizardresultpage.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 504b60740..56f99ef1d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,8 +16,6 @@ set(synclib_NAME ${APPLICATION_SHORTNAME}sync) set(mirall_UI mirall/folderwizardsourcepage.ui mirall/folderwizardtargetpage.ui -mirall/owncloudsetuppage_ng.ui -mirall/owncloudwizardresultpage.ui mirall/sslerrordialog.ui mirall/settingsdialog.ui mirall/generalsettings.ui @@ -25,6 +23,9 @@ mirall/networksettings.ui mirall/accountsettings.ui mirall/ignorelisteditor.ui mirall/fileitemdialog.ui +mirall/owncloudsetupnocredspage.ui +mirall/owncloudhttpcredspage.ui +mirall/owncloudwizardresultpage.ui ) set(3rdparty_SRC @@ -152,7 +153,11 @@ set(mirall_SRCS mirall/systray.cpp mirall/folderwizard.cpp mirall/folderstatusmodel.cpp - mirall/owncloudwizard.cpp + mirall/wizard/owncloudwizard.cpp + mirall/wizard/owncloudsetuppage.cpp + mirall/wizard/owncloudhttpcredspage.cpp + mirall/wizard/owncloudwizardresultpage.cpp + mirall/wizard/owncloudwizardcommon.cpp mirall/owncloudsetupwizard.cpp mirall/updatedetector.cpp mirall/occinfo.cpp @@ -171,7 +176,11 @@ set(mirall_HEADERS mirall/systray.h mirall/folderwizard.h mirall/owncloudsetupwizard.h - mirall/owncloudwizard.h + mirall/wizard/owncloudwizard.h + mirall/wizard/owncloudsetuppage.h + mirall/wizard/owncloudhttpcredspage.h + mirall/wizard/owncloudwizardresultpage.h + mirall/wizard/owncloudwizardcommon.h mirall/folderstatusmodel.h mirall/updatedetector.h mirall/sslerrordialog.h diff --git a/src/mirall/owncloudhttpcredspage.ui b/src/mirall/owncloudhttpcredspage.ui new file mode 100644 index 000000000..35f539a25 --- /dev/null +++ b/src/mirall/owncloudhttpcredspage.ui @@ -0,0 +1,130 @@ + + + OwncloudHttpCredsPage + + + + 0 + 0 + 350 + 196 + + + + Form + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + &Username + + + leUsername + + + + + + + &Password + + + lePassword + + + + + + + Error Label + + + + + + + + + + QLineEdit::Password + + + + + + + + + Qt::Vertical + + + + 20 + 68 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + + TextLabel + + + + + + + TextLabel + + + + + horizontalSpacer + verticalSpacer + horizontalSpacer_2 + horizontalLayoutWidget + topLabel + bottomLabel + + + + diff --git a/src/mirall/owncloudsetupnocredspage.ui b/src/mirall/owncloudsetupnocredspage.ui new file mode 100644 index 000000000..5e08a64b1 --- /dev/null +++ b/src/mirall/owncloudsetupnocredspage.ui @@ -0,0 +1,417 @@ + + + OwncloudSetupPage + + + + 0 + 0 + 583 + 498 + + + + + 0 + 0 + + + + Form + + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 68 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + 0 + + + + + + + true + + + + 0 + + + 0 + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + 0 + 0 + + + + &Local Folder + + + pbSelectLocalFolder + + + + + + + + 0 + 0 + + + + pbSelectLocalFolder + + + + + + + + QLayout::SetMinimumSize + + + QFormLayout::ExpandingFieldsGrow + + + + + &Keep local data + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + <small>Syncs your existing data to new location.</small> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 0 + + + + + + + <html><head/><body><p>If this box is checked, existing content in the local directory will be erased to start a clean sync from the server.</p><p>Do not check this if the local content should be uploaded to the servers directory.</p></body></html> + + + &Start a clean sync + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + <small>Erases the contents of the local folder before syncing using the new settings.</small> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 0 + + + + + + + + + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Server &Address + + + leUrl + + + + + + + + 0 + 0 + + + + Enter the url of the ownCloud you want to connect to (without http or https). + + + https://... + + + + + + + + 0 + 0 + + + + Error Label + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Advanced &Settings + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Status message + + + Qt::AlignCenter + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 58 + + + + + + + + TextLabel + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + + Utils::FancyLineEdit + QLineEdit +
fancylineedit.h
+
+
+ + +
diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index 506a16c29..ffb8abc2f 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak * * 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 @@ -12,11 +13,13 @@ * for more details. */ +#include #include #include #include #include +#include "mirall/wizard/owncloudwizardcommon.h" #include "mirall/owncloudsetupwizard.h" #include "mirall/mirallconfigfile.h" #include "mirall/owncloudinfo.h" @@ -36,6 +39,9 @@ OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent ) : connect( _ocWizard, SIGNAL(connectToOCUrl( const QString& ) ), this, SLOT(slotConnectToOCUrl( const QString& ))); + connect( _ocWizard, SIGNAL(determineAuthType(const QString&)), + this, SLOT(slotDetermineAuthType(const QString&))); + connect( _ocWizard, SIGNAL(finished(int)),this,SLOT(slotAssistantFinished(int))); connect( _ocWizard, SIGNAL(clearPendingRequests()), @@ -91,7 +97,7 @@ void OwncloudSetupWizard::startWizard() _ocWizard->setProperty("localFolder", localFolder); _ocWizard->setRemoteFolder(_remoteFolder); - _ocWizard->setStartId(OwncloudWizard::Page_oCSetup); + _ocWizard->setStartId(WizardCommon::Page_oCSetup); _ocWizard->restart(); @@ -250,32 +256,6 @@ void OwncloudSetupWizard::testOwnCloudConnect() prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); } - // now start ownCloudInfo to check the connection. - ownCloudInfo* info = ownCloudInfo::instance(); - info->setCustomConfigHandle( _configHandle ); - if( info->isConfigured() ) { - // reset the SSL Untrust flag to let the SSL dialog appear again. - info->resetSSLUntrust(); - connect(info, SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), - SLOT(slotOwnCloudFound(QString,QString,QString,QString))); - connect(info, SIGNAL(noOwncloudFound(QNetworkReply*)), - SLOT(slotNoOwnCloudFound(QNetworkReply*))); - _checkInstallationRequest = info->checkInstallation(); - } else { - qDebug() << " ownCloud seems not to be configured, can not start test connect."; - } -} - -void OwncloudSetupWizard::slotOwnCloudFound( const QString& url, const QString& infoString, const QString& version, const QString& ) -{ - disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), - this, SLOT(slotOwnCloudFound(QString,QString,QString,QString))); - disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), - this, SLOT(slotNoOwnCloudFound(QNetworkReply*))); - - _ocWizard->appendToConfigurationLog(tr("Successfully connected to %1: %2 version %3 (%4)

") - .arg( url ).arg(Theme::instance()->appNameGUI()).arg(infoString).arg(version)); - // enable the finish button. _ocWizard->button( QWizard::FinishButton )->setEnabled( true ); @@ -283,22 +263,6 @@ void OwncloudSetupWizard::slotOwnCloudFound( const QString& url, const QString& setupLocalSyncFolder(); } -void OwncloudSetupWizard::slotNoOwnCloudFound( QNetworkReply *err ) -{ - disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), - this, SLOT(slotOwnCloudFound(QString,QString,QString,QString))); - disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), - this, SLOT(slotNoOwnCloudFound(QNetworkReply*))); - - _ocWizard->displayError(tr("Failed to connect to %1:
%2"). - arg(Theme::instance()->appNameGUI()).arg(err->errorString())); - - // remove the config file again - MirallConfigFile cfgFile( _configHandle ); - cfgFile.cleanupCustomConfig(); - finalizeSetup( false ); -} - void OwncloudSetupWizard::setupLocalSyncFolder() { const QString localFolder = _ocWizard->property("localFolder").toString(); @@ -457,4 +421,142 @@ void OwncloudSetupWizard::finalizeSetup( bool success ) _ocWizard->successfullyConnected(success); } +void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) +{ + QString url(serverUrl); + qDebug() << "Connect to url: " << url; + _ocWizard->setField(QLatin1String("OCUrl"), url ); + _ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 to determine authentication type...") + .arg( Theme::instance()->appNameGUI() ).arg(url) ); + // write a temporary config. + QDateTime now = QDateTime::currentDateTime(); + + // remove a possibly existing custom config. + if( ! _configHandle.isEmpty() ) { + // remove the old config file. + MirallConfigFile oldConfig( _configHandle ); + oldConfig.cleanupCustomConfig(); + } + + _configHandle = now.toString(QLatin1String("MMddyyhhmmss")); + + MirallConfigFile cfgFile( _configHandle ); + if( url.isEmpty() ) return; + if( !( url.startsWith(QLatin1String("https://")) || url.startsWith(QLatin1String("http://"))) ) { + qDebug() << "url does not start with a valid protocol, assuming https."; + url.prepend(QLatin1String("https://")); + // FIXME: give a hint about the auto completion + _ocWizard->setOCUrl(url); + } + // FIXME: Create AbstractUserCreds class and maybe three subclasses: + // DummyCreds (empty), ShibbolethCreds and HttpCreds + // writeOwnCloudConfig could then take AbstractUserCreds instead. + // no user and no password - we are trying to determine whether + // the auth type is the old HTTPS headers one or rather a + // shibboleth one. + cfgFile.writeOwncloudConfig( Theme::instance()->appName(), + url, + QLatin1String(""), + QLatin1String("")); + + // If there is already a config, take its proxy config. + if( ownCloudInfo::instance()->isConfigured() ) { + MirallConfigFile prevCfg; + cfgFile.setProxyType( prevCfg.proxyType(), prevCfg.proxyHostName(), prevCfg.proxyPort(), + prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); + } + + // now start ownCloudInfo to check the connection. + ownCloudInfo* info = ownCloudInfo::instance(); + info->setCustomConfigHandle( _configHandle ); + if( info->isConfigured() ) { + // reset the SSL Untrust flag to let the SSL dialog appear again. + info->resetSSLUntrust(); + connect(info, SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), + SLOT(slotOwnCloudFoundAuth(QString,QString,QString,QString))); + connect(info, SIGNAL(noOwncloudFound(QNetworkReply*)), + SLOT(slotNoOwnCloudFoundAuth(QNetworkReply*))); + _checkInstallationRequest = info->checkInstallation(); + } else { + qDebug() << " ownCloud seems not to be configured, can not start test connect."; + } +} + +void OwncloudSetupWizard::slotOwnCloudFoundAuth( const QString& url, const QString& infoString, const QString& version, const QString& ) +{ + disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), + this, SLOT(slotOwnCloudFoundAuth(QString,QString,QString,QString))); + disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), + this, SLOT(slotNoOwnCloudFoundAuth(QNetworkReply*))); + + _ocWizard->appendToConfigurationLog(tr("Successfully connected to %1: %2 version %3 (%4)

") + .arg( url ).arg(Theme::instance()->appNameGUI()).arg(infoString).arg(version)); + + QNetworkAccessManager* nm = new QNetworkAccessManager(this); + QNetworkReply* reply = nm->get (QNetworkRequest (url + "/remote.php/webdav/")); + + connect (reply, SIGNAL(finished()), + this, SLOT(slotAuthCheckReplyFinished())); + + nm->setProperty ("mirallRedirs", QVariant (0)); +} + +void OwncloudSetupWizard::slotAuthCheckReplyFinished() +{ + QNetworkReply* reply = qobject_cast< QNetworkReply* > (sender ()); + QUrl redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); + QNetworkAccessManager* nm = reply->manager (); + const int redirCount = nm->property ("mirallRedirs").toInt(); + + if (redirCount > 10) { + redirection.clear (); + } + + disconnect (reply, SIGNAL(finished()), + this, SLOT(slotAuthCheckReplyFinished())); + if ((reply->error () == QNetworkReply::AuthenticationRequiredError) || redirection.isEmpty()) { + reply->deleteLater(); + nm->deleteLater(); + _ocWizard->setAuthType (WizardCommon::HttpCreds); + } else if (redirection.toString().endsWith ("remote.php/webdav/")) { + QNetworkReply* newReply = nm->get (QNetworkRequest(redirection)); + + connect (newReply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(slotAuthCheckReplyError(QNetworkReply::NetworkError))); + connect (newReply, SIGNAL(finished()), + this, SLOT(slotAuthCheckReplyFinished(QNetworkReply::NetworkError))); + reply->deleteLater(); + + nm->setProperty ("mirallRedirs", QVariant(redirCount + 1)); + } else { + QRegExp shibbolethyWords ("SAML|wayf"); + + shibbolethyWords.setCaseSensitivity (Qt::CaseInsensitive); + if (redirection.toString ().contains (shibbolethyWords)) { + _ocWizard->setAuthType(WizardCommon::Shibboleth); + } else { + // eh? + _ocWizard->setAuthType (WizardCommon::HttpCreds); + } + reply->deleteLater(); + nm->deleteLater(); + } +} + +void OwncloudSetupWizard::slotNoOwnCloudFoundAuth( QNetworkReply *err ) +{ + disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), + this, SLOT(slotOwnCloudFound(QString,QString,QString,QString))); + disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), + this, SLOT(slotNoOwnCloudFound(QNetworkReply*))); + + _ocWizard->displayError(tr("Failed to connect to %1:
%2"). + arg(Theme::instance()->appNameGUI()).arg(err->errorString())); + + // remove the config file again + MirallConfigFile cfgFile( _configHandle ); + cfgFile.cleanupCustomConfig(); + finalizeSetup( false ); +} + } diff --git a/src/mirall/owncloudsetupwizard.h b/src/mirall/owncloudsetupwizard.h index 3fd70766e..540255dce 100644 --- a/src/mirall/owncloudsetupwizard.h +++ b/src/mirall/owncloudsetupwizard.h @@ -21,7 +21,7 @@ #include #include -#include "mirall/owncloudwizard.h" +#include "mirall/wizard/owncloudwizard.h" #include "mirall/theme.h" namespace Mirall { @@ -72,14 +72,17 @@ public slots: protected slots: // wizard dialog signals void slotConnectToOCUrl( const QString& ); + void slotDetermineAuthType(const QString&); private slots: - void slotOwnCloudFound( const QString&, const QString&, const QString&, const QString& ); - void slotNoOwnCloudFound( QNetworkReply* ); void slotCreateRemoteFolderFinished( QNetworkReply::NetworkError ); void slotAssistantFinished( int ); void slotClearPendingRequests(); void slotAuthCheckReply( const QString&, QNetworkReply * ); + + void slotOwnCloudFoundAuth( const QString&, const QString&, const QString&, const QString& ); + void slotNoOwnCloudFoundAuth( QNetworkReply* ); + void slotAuthCheckReplyFinished(); private: bool createRemoteFolder(); void checkRemoteFolder(); diff --git a/src/mirall/owncloudwizard.cpp b/src/mirall/owncloudwizard.cpp deleted file mode 100644 index 68fc05ba2..000000000 --- a/src/mirall/owncloudwizard.cpp +++ /dev/null @@ -1,627 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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/owncloudwizard.h" -#include "mirall/mirallconfigfile.h" -#include "mirall/theme.h" - -#include "QProgressIndicator.h" - -#include -#include - -#include - -namespace Mirall -{ - -void setupCustomMedia( QVariant variant, QLabel *label ) -{ - if( !label ) return; - - QPixmap pix = variant.value(); - if( !pix.isNull() ) { - label->setPixmap(pix); - label->setAlignment( Qt::AlignTop | Qt::AlignRight ); - label->setVisible(true); - } else { - QString str = variant.toString(); - if( !str.isEmpty() ) { - label->setText( str ); - label->setTextFormat( Qt::RichText ); - label->setVisible(true); - label->setOpenExternalLinks(true); - } - } -} - -// ====================================================================== - -OwncloudSetupPage::OwncloudSetupPage() -{ - _ui.setupUi(this); - - Theme *theme = Theme::instance(); - setTitle( tr("Connect to %2") - .arg(theme->wizardHeaderTitleColor().name()).arg( theme->appNameGUI())); - setSubTitle( tr("Enter user credentials") - .arg(theme->wizardHeaderTitleColor().name())); - - registerField( QLatin1String("OCUrl"), _ui.leUrl ); - registerField( QLatin1String("OCUser"), _ui.leUsername ); - registerField( QLatin1String("OCPasswd"), _ui.lePassword); - registerField( QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch); - - _ui.errorLabel->setVisible(true); - _ui.advancedBox->setVisible(false); - - _progressIndi = new QProgressIndicator; - _ui.resultLayout->addWidget( _progressIndi ); - _progressIndi->setVisible(false); - _ui.resultLayout->setEnabled(false); - - // Error label - QString style = QLatin1String("border: 1px solid #eed3d7; border-radius: 5px; padding: 3px;" - "background-color: #f2dede; color: #b94a48;"); - - - _ui.errorLabel->setStyleSheet( style ); - _ui.errorLabel->setWordWrap(true); - _ui.errorLabel->setVisible(false); - - _checking = false; - - setupCustomization(); - - connect(_ui.leUrl, SIGNAL(textChanged(QString)), SLOT(slotUrlChanged(QString))); - connect( _ui.leUsername, SIGNAL(textChanged(QString)), this, SLOT(slotUserChanged(QString))); - - connect( _ui.lePassword, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); - connect( _ui.leUsername, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); - connect( _ui.cbAdvanced, SIGNAL(stateChanged (int)), SLOT(slotToggleAdvanced(int))); - connect( _ui.pbSelectLocalFolder, SIGNAL(clicked()), SLOT(slotSelectFolder())); -} - -OwncloudSetupPage::~OwncloudSetupPage() -{ - delete _progressIndi; -} - -void OwncloudSetupPage::slotToggleAdvanced(int state) -{ - _ui.advancedBox->setVisible( state == Qt::Checked ); - slotHandleUserInput(); - QSize size = wizard()->sizeHint(); - // need to substract header for some reason - size -= QSize(0, 63); - - wizard()->setMinimumSize(size); - wizard()->resize(size); -} - -void OwncloudSetupPage::setOCUser( const QString & user ) -{ - _ocUser = user; - _ui.leUsername->setText(user); -} - -void OwncloudSetupPage::setServerUrl( const QString& newUrl ) -{ - _oCUrl = newUrl; - if( _oCUrl.isEmpty() ) { - _ui.leUrl->clear(); - return; - } - - _ui.leUrl->setText( _oCUrl ); -} - -void OwncloudSetupPage::setupCustomization() -{ - // set defaults for the customize labels. - _ui.topLabel->hide(); - _ui.bottomLabel->hide(); - - Theme *theme = Theme::instance(); - QVariant variant = theme->customMedia( Theme::oCSetupTop ); - if( !variant.isNull() ) { - setupCustomMedia( variant, _ui.topLabel ); - } - - variant = theme->customMedia( Theme::oCSetupBottom ); - setupCustomMedia( variant, _ui.bottomLabel ); - - QString fixUrl = theme->overrideServerUrl(); - if( !fixUrl.isEmpty() ) { - _ui.label_2->hide(); - setServerUrl( fixUrl ); - _ui.leUrl->setEnabled( false ); - _ui.leUrl->hide(); - } -} - -void OwncloudSetupPage::slotUserChanged(const QString& user ) -{ - slotHandleUserInput(); -} - -// slot hit from textChanged of the url entry field. -void OwncloudSetupPage::slotUrlChanged(const QString& ocUrl) -{ - slotHandleUserInput(); - -#if 0 - QString url = ocUrl; - bool visible = false; - - if (url.startsWith(QLatin1String("https://"))) { - _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-high.png")); - _ui.urlLabel->setToolTip(tr("This url is secure. You can use it.")); - visible = true; - } - if (url.startsWith(QLatin1String("http://"))) { - _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-low.png")); - _ui.urlLabel->setToolTip(tr("This url is NOT secure. You should not use it.")); - visible = true; - } -#endif -} - -bool OwncloudSetupPage::isComplete() const -{ - if( _ui.leUrl->text().isEmpty() ) return false; - if( _checking ) return false; - - return !( _ui.lePassword->text().isEmpty() || _ui.leUsername->text().isEmpty() ); -} - -void OwncloudSetupPage::initializePage() -{ - _connected = false; - _checking = false; - _multipleFoldersExist = false; - - // call to init label - slotHandleUserInput(); - - if( _configExists ) { - _ui.lePassword->setFocus(); - } else { - _ui.leUrl->setFocus(); - } -} - -bool OwncloudSetupPage::urlHasChanged() -{ - bool change = false; - const QChar slash('/'); - - QUrl currentUrl( url() ); - QUrl initialUrl( _oCUrl ); - - QString currentPath = currentUrl.path(); - QString initialPath = initialUrl.path(); - - // add a trailing slash. - if( ! currentPath.endsWith( slash )) currentPath += slash; - if( ! initialPath.endsWith( slash )) initialPath += slash; - - if( currentUrl.host() != initialUrl.host() || - currentUrl.port() != initialUrl.port() || - currentPath != initialPath ) { - change = true; - } - - if( !change) { // no change yet, check the user. - QString user = _ui.leUsername->text().simplified(); - if( user != _ocUser ) change = true; - } - - return change; -} - -// Called if the user changes the user- or url field. Adjust the texts and -// evtl. warnings on the dialog. -void OwncloudSetupPage::slotHandleUserInput() -{ - // if the url has not changed, return. - if( ! urlHasChanged() ) { - // disable the advanced button as nothing has changed. - _ui.cbAdvanced->setEnabled(false); - _ui.advancedBox->setEnabled(false); - } else { - // Enable advanced stuff for new connection configuration. - _ui.cbAdvanced->setEnabled(true); - _ui.advancedBox->setEnabled(true); - } - - const QString locFolder = localFolder(); - - // check if the local folder exists. If so, and if its not empty, show a warning. - QDir dir( locFolder ); - QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot); - - QString t; - - if( !urlHasChanged() && _configExists ) { - // This is the password change mode: No change to the url and a config - // to an ownCloud exists. - t = tr("Change the Password for your configured account."); - } else { - // Complete new setup. - _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); - - if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { - t = tr("Your entire account will be synced to the local folder '%1'.") - .arg(QDir::toNativeSeparators(locFolder)); - } else { - t = tr("%1 folder '%2' is synced to local folder '%3'") - .arg(Theme::instance()->appName()).arg(_remoteFolder) - .arg(QDir::toNativeSeparators(locFolder)); - } - - if ( _multipleFoldersExist ) { - t += tr("

Warning: You currently have multiple folders " - "configured. If you continue with the current settings, the folder configurations " - "will be discarded and a single root folder sync will be created!

"); - } - - if( entries.count() > 0) { - // the directory is not empty - if (!_ui.cbAdvanced->isChecked()) { - t += tr("

Warning: The local directory is not empty. " - "Pick a resolution in the advanced settings!

"); - } - _ui.resolutionWidget->setVisible(true); - } else { - // the dir is empty, which means that there is no problem. - _ui.resolutionWidget->setVisible(false); - } - } - - _ui.syncModeLabel->setText(t); - _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); -} - -int OwncloudSetupPage::nextId() const -{ - return OwncloudWizard::Page_Result; -} - -QString OwncloudSetupPage::url() const -{ - QString url = _ui.leUrl->text().simplified(); - return url; -} - -QString OwncloudSetupPage::localFolder() const -{ - QString folder = wizard()->property("localFolder").toString(); - return folder; -} - -void OwncloudSetupPage::setConnected( bool comp ) -{ - _connected = comp; - _ui.resultLayout->setEnabled(true); - _progressIndi->setVisible(false); - _progressIndi->stopAnimation(); -} - -bool OwncloudSetupPage::validatePage() -{ - bool re = false; - - if( ! _connected) { - setErrorString(QString::null); - _checking = true; - _ui.resultLayout->setEnabled(true); - _progressIndi->setVisible(true); - _progressIndi->startAnimation(); - emit completeChanged(); - - emit connectToOCUrl( url() ); - return false; - } else { - // connecting is running - stopSpinner(); - _checking = false; - emit completeChanged(); - return true; - } -} - -void OwncloudSetupPage::setErrorString( const QString& err ) -{ - if( err.isEmpty()) { - _ui.errorLabel->setVisible(false); - } else { - _ui.errorLabel->setVisible(true); - _ui.errorLabel->setText(err); - } - _checking = false; - emit completeChanged(); - stopSpinner(); -} - -void OwncloudSetupPage::stopSpinner() -{ - _ui.resultLayout->setEnabled(false); - _progressIndi->setVisible(false); - _progressIndi->stopAnimation(); -} - -OwncloudSetupPage::SyncMode OwncloudSetupPage::syncMode() -{ - return BoxMode; -} - -void OwncloudSetupPage::setRemoteFolder( const QString& remoteFolder ) -{ - if( !remoteFolder.isEmpty() ) { - _remoteFolder = remoteFolder; - } -} - -void OwncloudSetupPage::setMultipleFoldersExist(bool exist) -{ - _multipleFoldersExist = exist; -} - -void OwncloudSetupPage::slotSelectFolder() -{ - - QString dir = QFileDialog::getExistingDirectory(0, tr("Local Sync Folder"), QDir::homePath()); - if( !dir.isEmpty() ) { - _ui.pbSelectLocalFolder->setText(dir); - wizard()->setProperty("localFolder", dir); - slotHandleUserInput(); - } -} - -OwncloudSetupPage::SyncMode OwncloudWizard::syncMode() -{ - return _setupPage->syncMode(); - return OwncloudSetupPage::BoxMode; -} - -void OwncloudWizard::setMultipleFoldersExist(bool exist) -{ - _setupPage->setMultipleFoldersExist(exist); -} - -void OwncloudSetupPage::setConfigExists( bool config ) -{ - _configExists = config; - - if (config == true) { - setSubTitle( tr("Change your user credentials") - .arg(Theme::instance()->wizardHeaderTitleColor().name())); - } -} - -// ====================================================================== - -OwncloudWizardResultPage::OwncloudWizardResultPage() -{ - _ui.setupUi(this); - // no fields to register. - - Theme *theme = Theme::instance(); - setTitle( tr("Everything set up!") - .arg(theme->wizardHeaderTitleColor().name())); - // required to show header in QWizard's modern style - setSubTitle( QLatin1String(" ") ); - - _ui.pbOpenLocal->setText("Open local folder"); - _ui.pbOpenServer->setText(tr("Open %1").arg(Theme::instance()->appNameGUI())); - - _ui.pbOpenLocal->setIcon(QIcon(":/mirall/resources/folder-sync.png")); - _ui.pbOpenLocal->setText(tr("Open Local Folder")); - _ui.pbOpenLocal->setIconSize(QSize(48, 48)); - connect(_ui.pbOpenLocal, SIGNAL(clicked()), SLOT(slotOpenLocal())); - - _ui.pbOpenLocal->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - - QIcon appIcon = theme->applicationIcon(); - _ui.pbOpenServer->setIcon(appIcon.pixmap(48)); - _ui.pbOpenServer->setText(tr("Open %1").arg(theme->appNameGUI())); - _ui.pbOpenServer->setIconSize(QSize(48, 48)); - _ui.pbOpenServer->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - connect(_ui.pbOpenServer, SIGNAL(clicked()), SLOT(slotOpenServer())); - setupCustomization(); -} - -OwncloudWizardResultPage::~OwncloudWizardResultPage() -{ -} - -void OwncloudWizardResultPage::setComplete(bool complete) -{ - _complete = complete; - emit completeChanged(); -} - -bool OwncloudWizardResultPage::isComplete() const -{ - return _complete; -} - -void OwncloudWizardResultPage::initializePage() -{ - const QString localFolder = wizard()->property("localFolder").toString(); - QString text; - if( _remoteFolder == QLatin1String("/") || _remoteFolder.isEmpty() ) { - text = tr("Your entire account is synced to the local folder %1") - .arg(QDir::toNativeSeparators(localFolder)); - } else { - text = tr("ownCloud folder %1 is synced to local folder %2") - .arg(_remoteFolder).arg(QDir::toNativeSeparators(localFolder)); - } - _ui.localFolderLabel->setText( text ); - -} - -void OwncloudWizardResultPage::setRemoteFolder(const QString &remoteFolder) -{ - _remoteFolder = remoteFolder; -} - -void OwncloudWizardResultPage::setupCustomization() -{ - // set defaults for the customize labels. - _ui.topLabel->setText( QString::null ); - _ui.topLabel->hide(); - - QVariant variant = Theme::instance()->customMedia( Theme::oCSetupResultTop ); - setupCustomMedia( variant, _ui.topLabel ); -} - -// ====================================================================== - -/** - * Folder wizard itself - */ - -OwncloudWizard::OwncloudWizard(QWidget *parent) - : QWizard(parent), - _configExists(false) -{ - _setupPage = new OwncloudSetupPage; - _resultPage = new OwncloudWizardResultPage; - setPage(Page_oCSetup, _setupPage ); - setPage(Page_Result, _resultPage ); - - // note: start Id is set by the calling class depending on if the - // welcome text is to be shown or not. - setWizardStyle( QWizard::ModernStyle ); - - connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int))); - - connect( _setupPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); - - - Theme *theme = Theme::instance(); - setWizardStyle(QWizard::ModernStyle); - setPixmap( QWizard::BannerPixmap, theme->wizardHeaderBanner() ); - setPixmap( QWizard::LogoPixmap, theme->wizardHeaderLogo() ); - setOption( QWizard::NoBackButtonOnStartPage ); - setOption( QWizard::NoBackButtonOnLastPage ); - setOption( QWizard::NoCancelButton ); - setTitleFormat(Qt::RichText); - setSubTitleFormat(Qt::RichText); -} - -QString OwncloudWizard::localFolder() const -{ - return(_setupPage->localFolder()); -} - -QString OwncloudWizard::ocUrl() const -{ - QString url = field("OCUrl").toString().simplified(); - return url; -} - -void OwncloudWizard::enableFinishOnResultWidget(bool enable) -{ - _resultPage->setComplete(enable); -} - -void OwncloudWizard::setRemoteFolder( const QString& remoteFolder ) -{ - _setupPage->setRemoteFolder( remoteFolder ); - _resultPage->setRemoteFolder( remoteFolder ); -} - -void OwncloudWizard::showConnectInfo( const QString& msg ) -{ - if( _setupPage ) { - _setupPage->setErrorString( msg ); - } -} - -void OwncloudWizard::successfullyConnected(bool enable) -{ - _setupPage->setConnected( enable ); - - if( enable ) { - next(); - } -} - -void OwncloudWizard::slotCurrentPageChanged( int id ) -{ - qDebug() << "Current Wizard page changed to " << id; - - if( id == Page_oCSetup ) { - setButtonText( QWizard::NextButton, tr("Connect...") ); - emit clearPendingRequests(); - _setupPage->initializePage(); - - } - - if( id == Page_Result ) { - appendToConfigurationLog( QString::null ); - } -} - -void OwncloudWizard::displayError( const QString& msg ) -{ - _setupPage->setErrorString( msg ); -} - -void OwncloudWizard::appendToConfigurationLog( const QString& msg, LogType type ) -{ - _setupLog << msg; - qDebug() << "Setup-Log: " << msg; -} - -void OwncloudWizard::setOCUrl( const QString& url ) -{ - _setupPage->setServerUrl( url ); -} - -void OwncloudWizard::setOCUser( const QString& user ) -{ - _oCUser = user; - _setupPage->setOCUser( user ); -} - -void OwncloudWizard::setConfigExists( bool config ) -{ - _configExists = config; - _setupPage->setConfigExists( config ); -} - -bool OwncloudWizard::configExists() -{ - return _configExists; -} - -void OwncloudWizardResultPage::slotOpenLocal() -{ - const QString localFolder = wizard()->property("localFolder").toString(); - QDesktopServices::openUrl(QUrl::fromLocalFile(localFolder)); -} - -void OwncloudWizardResultPage::slotOpenServer() -{ - QUrl url = field("OCUrl").toUrl(); - qDebug() << Q_FUNC_INFO << url; - QDesktopServices::openUrl(url); -} - - -} // end namespace diff --git a/src/mirall/owncloudwizard.h b/src/mirall/owncloudwizard.h deleted file mode 100644 index ceccf1209..000000000 --- a/src/mirall/owncloudwizard.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_OWNCLOUDWIZARD_H -#define MIRALL_OWNCLOUDWIZARD_H - -#include - -#include "ui_owncloudsetuppage_ng.h" -#include "ui_owncloudwizardresultpage.h" - -class QLabel; -class QVariant; -class QProgressIndicator; - -namespace Mirall { - -class OwncloudSetupPage; -class OwncloudWizardResultPage; - -class OwncloudSetupPage: public QWizardPage -{ - Q_OBJECT -public: - OwncloudSetupPage(); - ~OwncloudSetupPage(); - - enum SyncMode { - SelectiveMode, - BoxMode - }; - - virtual bool isComplete() const; - virtual void initializePage(); - virtual int nextId() const; - void setServerUrl( const QString& ); - void setOCUser( const QString& ); - void setAllowPasswordStorage( bool ); - bool validatePage(); - QString url() const; - QString localFolder() const; - void setConnected(bool complete); - void setRemoteFolder( const QString& remoteFolder); - void setMultipleFoldersExist( bool exist ); - - SyncMode syncMode(); - -public slots: - void setErrorString( const QString& ); - void setConfigExists( bool ); - void stopSpinner(); - -protected slots: - void slotUrlChanged(const QString&); - void slotUserChanged(const QString&); - - void setupCustomization(); - void slotToggleAdvanced(int state); - void slotSelectFolder(); - -signals: - void connectToOCUrl( const QString& ); - -protected: - void updateFoldersInfo(); - -private slots: - void slotHandleUserInput(); - -private: - bool urlHasChanged(); - - Ui_OwncloudSetupPage _ui; - QString _oCUrl; - QString _ocUser; - bool _connected; - bool _checking; - bool _configExists; - bool _multipleFoldersExist; - - QProgressIndicator *_progressIndi; - QButtonGroup *_selectiveSyncButtons; - QString _remoteFolder; -}; - -class OwncloudWizard: public QWizard -{ - Q_OBJECT -public: - - enum { - Page_oCSetup, - Page_Result - }; - - enum LogType { - LogPlain, - LogParagraph - }; - - OwncloudWizard(QWidget *parent = 0); - - void setOCUrl( const QString& ); - void setOCUser( const QString& ); - - void setupCustomMedia( QVariant, QLabel* ); - QString ocUrl() const; - QString localFolder() const; - - void enableFinishOnResultWidget(bool enable); - - void displayError( const QString& ); - OwncloudSetupPage::SyncMode syncMode(); - void setMultipleFoldersExist( bool ); - void setConfigExists( bool ); - bool configExists(); - -public slots: - void setRemoteFolder( const QString& ); - void appendToConfigurationLog( const QString& msg, LogType type = LogParagraph ); - void slotCurrentPageChanged( int ); - - void showConnectInfo( const QString& ); - void successfullyConnected(bool); - -signals: - void clearPendingRequests(); - void connectToOCUrl( const QString& ); - -private: - OwncloudSetupPage *_setupPage; - OwncloudWizardResultPage *_resultPage; - - QString _configFile; - QString _oCUser; - QStringList _setupLog; - bool _configExists; -}; - - -/** - * page to ask for the type of Owncloud to connect to - */ - -/** - * page to display the install result - */ -class OwncloudWizardResultPage : public QWizardPage -{ - Q_OBJECT -public: - OwncloudWizardResultPage(); - ~OwncloudWizardResultPage(); - - bool isComplete() const; - void initializePage(); - void setRemoteFolder( const QString& remoteFolder); - -public slots: - void setComplete(bool complete); - -protected slots: - void slotOpenLocal(); - void slotOpenServer(); - -protected: - void setupCustomization(); - -private: - QString _localFolder; - QString _remoteFolder; - bool _complete; - - Ui_OwncloudWizardResultPage _ui; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/wizard/owncloudhttpcredspage.cpp b/src/mirall/wizard/owncloudhttpcredspage.cpp new file mode 100644 index 000000000..99d06accc --- /dev/null +++ b/src/mirall/wizard/owncloudhttpcredspage.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 "QProgressIndicator.h" + +#include "mirall/wizard/owncloudhttpcredspage.h" +#include "mirall/theme.h" +#include "mirall/wizard/owncloudwizardcommon.h" + +namespace Mirall +{ + +OwncloudHttpCredsPage::OwncloudHttpCredsPage() + : QWizardPage(), + _ui(), + _connected(false), + _checking(false), + _progressIndi(new QProgressIndicator (this)) +{ + _ui.setupUi(this); + + registerField( QLatin1String("OCUser*"), _ui.leUsername); + registerField( QLatin1String("OCPasswd*"), _ui.lePassword); + + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Enter user credentials"))); + + _ui.resultLayout->addWidget( _progressIndi ); + stopSpinner(); + setupCustomization(); +} + +void OwncloudHttpCredsPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); +} + +void OwncloudHttpCredsPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + _ui.leUsername->setFocus(); +} + +void OwncloudHttpCredsPage::cleanupPage() +{ + _ui.leUsername->clear(); + _ui.lePassword->clear(); +} + +bool OwncloudHttpCredsPage::validatePage() +{ + if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) { + return false; + } + + if (!_connected) { + _checking = true; + emit completeChanged(); + emit connectToOCUrl(field("OCUrl").toString().simplified()); + + return false; + } else { + _checking = false; + emit completeChanged(); + return true; + } + return true; +} + +int OwncloudHttpCredsPage::nextId() const +{ + return WizardCommon::Page_Result; +} + +void OwncloudHttpCredsPage::setConnected( bool comp ) +{ + _connected = comp; + stopSpinner (); +} + +void OwncloudHttpCredsPage::startSpinner() +{ + _ui.resultLayout->setEnabled(true); + _progressIndi->setVisible(true); + _progressIndi->startAnimation(); +} + +void OwncloudHttpCredsPage::stopSpinner() +{ + _ui.resultLayout->setEnabled(false); + _progressIndi->setVisible(false); + _progressIndi->stopAnimation(); +} + +void OwncloudHttpCredsPage::setOCUser(const QString& user) +{ + _ui.leUsername->setText(user); +} + +void OwncloudHttpCredsPage::setErrorString(const QString& err) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + _checking = false; + emit completeChanged(); + stopSpinner(); +} + +} // ns Mirall diff --git a/src/mirall/wizard/owncloudhttpcredspage.h b/src/mirall/wizard/owncloudhttpcredspage.h new file mode 100644 index 000000000..c9eadbd9f --- /dev/null +++ b/src/mirall/wizard/owncloudhttpcredspage.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H +#define MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H + +#include + +#include "ui_owncloudhttpcredspage.h" + +class QProgressIndicator; + +namespace Mirall { + +class OwncloudHttpCredsPage : public QWizardPage +{ + Q_OBJECT +public: + OwncloudHttpCredsPage(); + + void setOCUser(const QString& user); + void initializePage(); + void cleanupPage(); + bool validatePage(); + int nextId() const; + void setConnected(bool connected); + void setErrorString( const QString& err ); + +Q_SIGNALS: + void connectToOCUrl(const QString&); + +private: + void startSpinner(); + void stopSpinner(); + void setupCustomization(); + + Ui_OwncloudHttpCredsPage _ui; + bool _connected; + bool _checking; + QProgressIndicator* _progressIndi; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/wizard/owncloudsetuppage.cpp b/src/mirall/wizard/owncloudsetuppage.cpp new file mode 100644 index 000000000..e32381a52 --- /dev/null +++ b/src/mirall/wizard/owncloudsetuppage.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "QProgressIndicator.h" + +#include "mirall/wizard/owncloudwizardcommon.h" +#include "mirall/wizard/owncloudsetuppage.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +OwncloudSetupPage::OwncloudSetupPage() + : QWizardPage(), + _ui(), + _oCUrl(), + _ocUser(), + _authTypeKnown(false), + _checking(false), + _multipleFoldersExist(false), + _authType(WizardCommon::HttpCreds), + _progressIndi(new QProgressIndicator (this)), + _selectiveSyncButtons(0), + _remoteFolder() +{ + _ui.setupUi(this); + + Theme *theme = Theme::instance(); + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(theme->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Setup ownCloud server"))); + + registerField( QLatin1String("OCUrl*"), _ui.leUrl ); + registerField( QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch); + + _ui.advancedBox->setVisible(false); + + _ui.resultLayout->addWidget( _progressIndi ); + stopSpinner(); + + setupCustomization(); + + connect(_ui.leUrl, SIGNAL(textChanged(QString)), SLOT(slotUrlChanged(QString))); + connect( _ui.cbAdvanced, SIGNAL(stateChanged (int)), SLOT(slotToggleAdvanced(int))); + connect( _ui.pbSelectLocalFolder, SIGNAL(clicked()), SLOT(slotSelectFolder())); +} + +void OwncloudSetupPage::slotToggleAdvanced(int state) +{ + _ui.advancedBox->setVisible( state == Qt::Checked ); + slotHandleUserInput(); + QSize size = wizard()->sizeHint(); + // need to substract header for some reason + size -= QSize(0, 63); + + wizard()->setMinimumSize(size); + wizard()->resize(size); +} + +void OwncloudSetupPage::setServerUrl( const QString& newUrl ) +{ + _oCUrl = newUrl; + if( _oCUrl.isEmpty() ) { + _ui.leUrl->clear(); + return; + } + + _ui.leUrl->setText( _oCUrl ); +} + +void OwncloudSetupPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); + + QString fixUrl = theme->overrideServerUrl(); + if( !fixUrl.isEmpty() ) { + _ui.label_2->hide(); + setServerUrl( fixUrl ); + _ui.leUrl->setEnabled( false ); + _ui.leUrl->hide(); + } +} + +// slot hit from textChanged of the url entry field. +void OwncloudSetupPage::slotUrlChanged(const QString& ocUrl) +{ + slotHandleUserInput(); + +#if 0 + QString url = ocUrl; + bool visible = false; + + if (url.startsWith(QLatin1String("https://"))) { + _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-high.png")); + _ui.urlLabel->setToolTip(tr("This url is secure. You can use it.")); + visible = true; + } + if (url.startsWith(QLatin1String("http://"))) { + _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-low.png")); + _ui.urlLabel->setToolTip(tr("This url is NOT secure. You should not use it."));W + visible = true; + } +#endif +} + +bool OwncloudSetupPage::isComplete() const +{ + return !_ui.leUrl->text().isEmpty() && !_checking; +} + +void OwncloudSetupPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + + _authTypeKnown = false; + _checking = false; + _multipleFoldersExist = false; + + // call to init label + slotHandleUserInput(); + + _ui.leUrl->setFocus(); +} + +bool OwncloudSetupPage::urlHasChanged() +{ + bool change = false; + const QChar slash('/'); + + QUrl currentUrl( url() ); + QUrl initialUrl( _oCUrl ); + + QString currentPath = currentUrl.path(); + QString initialPath = initialUrl.path(); + + // add a trailing slash. + if( ! currentPath.endsWith( slash )) currentPath += slash; + if( ! initialPath.endsWith( slash )) initialPath += slash; + + if( currentUrl.host() != initialUrl.host() || + currentUrl.port() != initialUrl.port() || + currentPath != initialPath ) { + change = true; + } + + return change; +} + +// Called if the user changes the user- or url field. Adjust the texts and +// evtl. warnings on the dialog. +void OwncloudSetupPage::slotHandleUserInput() +{ + // if the url has not changed, return. + if( ! urlHasChanged() ) { + // disable the advanced button as nothing has changed. + _ui.cbAdvanced->setEnabled(false); + _ui.advancedBox->setEnabled(false); + } else { + // Enable advanced stuff for new connection configuration. + _ui.cbAdvanced->setEnabled(true); + _ui.advancedBox->setEnabled(true); + } + + const QString locFolder = localFolder(); + + // check if the local folder exists. If so, and if its not empty, show a warning. + QDir dir( locFolder ); + QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot); + + QString t; + + if( !urlHasChanged() && _configExists ) { + // This is the password change mode: No change to the url and a config + // to an ownCloud exists. + t = tr("Press Next to change the Password for your configured account."); + } else { + // Complete new setup. + _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); + + if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { + t = tr("Your entire account will be synced to the local folder '%1'.") + .arg(QDir::toNativeSeparators(locFolder)); + } else { + t = tr("%1 folder '%2' is synced to local folder '%3'") + .arg(Theme::instance()->appName()).arg(_remoteFolder) + .arg(QDir::toNativeSeparators(locFolder)); + } + + if ( _multipleFoldersExist ) { + t += tr("

Warning: You currently have multiple folders " + "configured. If you continue with the current settings, the folder configurations " + "will be discarded and a single root folder sync will be created!

"); + } + + if( entries.count() > 0) { + // the directory is not empty + if (!_ui.cbAdvanced->isChecked()) { + t += tr("

Warning: The local directory is not empty. " + "Pick a resolution in the advanced settings!

"); + } + _ui.resolutionWidget->setVisible(true); + } else { + // the dir is empty, which means that there is no problem. + _ui.resolutionWidget->setVisible(false); + } + } + + _ui.syncModeLabel->setText(t); + _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); +} + +int OwncloudSetupPage::nextId() const +{ + if (_authType == WizardCommon::HttpCreds) { + return WizardCommon::Page_HttpCreds; + } else { + // TODO: rather display some browser component. maybe different page. + return WizardCommon::Page_Result; + } +} + +QString OwncloudSetupPage::url() const +{ + QString url = _ui.leUrl->text().simplified(); + return url; +} + +QString OwncloudSetupPage::localFolder() const +{ + QString folder = wizard()->property("localFolder").toString(); + return folder; +} + +bool OwncloudSetupPage::validatePage() +{ + bool re = false; + + if( ! _authTypeKnown) { + setErrorString(QString::null); + _checking = true; + startSpinner (); + emit completeChanged(); + + emit determineAuthType(url()); + return false; + } else { + // connecting is running + stopSpinner(); + _checking = false; + emit completeChanged(); + return true; + } +} + +void OwncloudSetupPage::setAuthType (WizardCommon::AuthType type) +{ + _authTypeKnown = true; + _authType = type; + stopSpinner(); +} + +void OwncloudSetupPage::setErrorString( const QString& err ) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + _checking = false; + emit completeChanged(); + stopSpinner(); +} + +void OwncloudSetupPage::startSpinner() +{ + _ui.resultLayout->setEnabled(true); + _progressIndi->setVisible(true); + _progressIndi->startAnimation(); +} + +void OwncloudSetupPage::stopSpinner() +{ + _ui.resultLayout->setEnabled(false); + _progressIndi->setVisible(false); + _progressIndi->stopAnimation(); +} + +WizardCommon::SyncMode OwncloudSetupPage::syncMode() +{ + return WizardCommon::BoxMode; +} + +void OwncloudSetupPage::setRemoteFolder( const QString& remoteFolder ) +{ + if( !remoteFolder.isEmpty() ) { + _remoteFolder = remoteFolder; + } +} + +void OwncloudSetupPage::setMultipleFoldersExist(bool exist) +{ + _multipleFoldersExist = exist; +} + +void OwncloudSetupPage::slotSelectFolder() +{ + QString dir = QFileDialog::getExistingDirectory(0, tr("Local Sync Folder"), QDir::homePath()); + if( !dir.isEmpty() ) { + _ui.pbSelectLocalFolder->setText(dir); + wizard()->setProperty("localFolder", dir); + slotHandleUserInput(); + } +} + +void OwncloudSetupPage::setConfigExists( bool config ) +{ + _configExists = config; + + if (config == true) { + setSubTitle( tr("Change your user credentials") + .arg(Theme::instance()->wizardHeaderTitleColor().name())); + } +} + +} // ns Mirall diff --git a/src/mirall/wizard/owncloudsetuppage.h b/src/mirall/wizard/owncloudsetuppage.h new file mode 100644 index 000000000..c56dd1550 --- /dev/null +++ b/src/mirall/wizard/owncloudsetuppage.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_SETUP_PAGE_H +#define MIRALL_OWNCLOUD_SETUP_PAGE_H + +#include + +#include "mirall/wizard/owncloudwizardcommon.h" +#include "ui_owncloudsetupnocredspage.h" + +class QLabel; +class QVariant; +class QProgressIndicator; + +namespace Mirall { + +class OwncloudSetupPage: public QWizardPage +{ + Q_OBJECT +public: + OwncloudSetupPage(); + + virtual bool isComplete() const; + virtual void initializePage(); + virtual int nextId() const; + void setServerUrl( const QString& ); + void setAllowPasswordStorage( bool ); + bool validatePage(); + QString url() const; + QString localFolder() const; + void setRemoteFolder( const QString& remoteFolder); + void setMultipleFoldersExist( bool exist ); + + WizardCommon::SyncMode syncMode(); + void setAuthType(WizardCommon::AuthType type); + +public slots: + void setErrorString( const QString& ); + void setConfigExists( bool ); + void startSpinner(); + void stopSpinner(); + +protected slots: + void slotUrlChanged(const QString&); + + void setupCustomization(); + void slotToggleAdvanced(int state); + void slotSelectFolder(); + +signals: + void determineAuthType(const QString&); + +protected: + void updateFoldersInfo(); + +private slots: + void slotHandleUserInput(); + +private: + bool urlHasChanged(); + + Ui_OwncloudSetupPage _ui; + QString _oCUrl; + QString _ocUser; + bool _authTypeKnown; + bool _checking; + bool _configExists; + bool _multipleFoldersExist; + WizardCommon::AuthType _authType; + + QProgressIndicator* _progressIndi; + QButtonGroup* _selectiveSyncButtons; + QString _remoteFolder; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/wizard/owncloudwizard.cpp b/src/mirall/wizard/owncloudwizard.cpp new file mode 100644 index 000000000..b5d21e007 --- /dev/null +++ b/src/mirall/wizard/owncloudwizard.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/wizard/owncloudwizard.h" +#include "mirall/mirallconfigfile.h" +#include "mirall/theme.h" +#include "mirall/wizard/owncloudsetuppage.h" +#include "mirall/wizard/owncloudhttpcredspage.h" +#include "mirall/wizard/owncloudwizardresultpage.h" + +#include "QProgressIndicator.h" + +#include +#include + +#include + +namespace Mirall +{ + +WizardCommon::SyncMode OwncloudWizard::syncMode() +{ + return _setupPage->syncMode(); + return WizardCommon::BoxMode; +} + +void OwncloudWizard::setMultipleFoldersExist(bool exist) +{ + _setupPage->setMultipleFoldersExist(exist); +} + +OwncloudWizard::OwncloudWizard(QWidget *parent) + : QWizard(parent), + _configExists(false) +{ + _setupPage = new OwncloudSetupPage; + _httpCredsPage = new OwncloudHttpCredsPage; + _resultPage = new OwncloudWizardResultPage; + setPage(WizardCommon::Page_oCSetup, _setupPage ); + setPage(WizardCommon::Page_HttpCreds, _httpCredsPage); + setPage(WizardCommon::Page_Result, _resultPage ); + + // note: start Id is set by the calling class depending on if the + // welcome text is to be shown or not. + setWizardStyle( QWizard::ModernStyle ); + + connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int))); + connect( _setupPage, SIGNAL(determineAuthType(QString)), SIGNAL(determineAuthType(QString))); + connect( _httpCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); + + + Theme *theme = Theme::instance(); + setWizardStyle(QWizard::ModernStyle); + setPixmap( QWizard::BannerPixmap, theme->wizardHeaderBanner() ); + setPixmap( QWizard::LogoPixmap, theme->wizardHeaderLogo() ); + setOption( QWizard::NoBackButtonOnStartPage ); + setOption( QWizard::NoBackButtonOnLastPage ); + setOption( QWizard::NoCancelButton ); + setTitleFormat(Qt::RichText); + setSubTitleFormat(Qt::RichText); +} + +QString OwncloudWizard::localFolder() const +{ + return(_setupPage->localFolder()); +} + +QString OwncloudWizard::ocUrl() const +{ + QString url = field("OCUrl").toString().simplified(); + return url; +} + +void OwncloudWizard::enableFinishOnResultWidget(bool enable) +{ + _resultPage->setComplete(enable); +} + +void OwncloudWizard::setRemoteFolder( const QString& remoteFolder ) +{ + _setupPage->setRemoteFolder( remoteFolder ); + _resultPage->setRemoteFolder( remoteFolder ); +} + +void OwncloudWizard::showConnectInfo( const QString& msg ) +{ + if( _setupPage ) { + _setupPage->setErrorString( msg ); + } +} + +void OwncloudWizard::successfullyConnected(bool enable) +{ + _httpCredsPage->setConnected( enable ); + + if( enable ) { + next(); + } +} + +void OwncloudWizard::setAuthType(WizardCommon::AuthType type) +{ + _setupPage->setAuthType(type); + next(); +} + +void OwncloudWizard::slotCurrentPageChanged( int id ) +{ + qDebug() << "Current Wizard page changed to " << id; + + if( id == WizardCommon::Page_oCSetup ) { + setButtonText( QWizard::NextButton, tr("Connect...") ); + emit clearPendingRequests(); + _setupPage->initializePage(); + + } + + if( id == WizardCommon::Page_Result ) { + appendToConfigurationLog( QString::null ); + } +} + +void OwncloudWizard::displayError( const QString& msg ) +{ + if (currentId() == WizardCommon::Page_oCSetup) { + _setupPage->setErrorString( msg ); + } else { + _httpCredsPage->setErrorString(msg); + } +} + +void OwncloudWizard::appendToConfigurationLog( const QString& msg, LogType type ) +{ + _setupLog << msg; + qDebug() << "Setup-Log: " << msg; +} + +void OwncloudWizard::setOCUrl( const QString& url ) +{ + _setupPage->setServerUrl( url ); +} + +void OwncloudWizard::setOCUser( const QString& user ) +{ + _oCUser = user; + _httpCredsPage->setOCUser( user ); +} + +void OwncloudWizard::setConfigExists( bool config ) +{ + _configExists = config; + _setupPage->setConfigExists( config ); +} + +bool OwncloudWizard::configExists() +{ + return _configExists; +} + +} // end namespace diff --git a/src/mirall/wizard/owncloudwizard.h b/src/mirall/wizard/owncloudwizard.h new file mode 100644 index 000000000..bd6cf6814 --- /dev/null +++ b/src/mirall/wizard/owncloudwizard.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_WIZARD_H +#define MIRALL_OWNCLOUD_WIZARD_H + +#include + +#include "owncloudwizardcommon.h" + +namespace Mirall { + +class OwncloudSetupPage; +class OwncloudHttpCredsPage; +class OwncloudWizardResultPage; + +class OwncloudWizard: public QWizard +{ + Q_OBJECT +public: + + enum LogType { + LogPlain, + LogParagraph + }; + + OwncloudWizard(QWidget *parent = 0); + + void setOCUrl( const QString& ); + void setOCUser( const QString& ); + + void setupCustomMedia( QVariant, QLabel* ); + QString ocUrl() const; + QString localFolder() const; + + void enableFinishOnResultWidget(bool enable); + + void displayError( const QString& ); + WizardCommon::SyncMode syncMode(); + void setMultipleFoldersExist( bool ); + void setConfigExists( bool ); + bool configExists(); + +public slots: + void setRemoteFolder( const QString& ); + void appendToConfigurationLog( const QString& msg, LogType type = LogParagraph ); + void slotCurrentPageChanged( int ); + + void showConnectInfo( const QString& ); + +public: + void successfullyConnected(bool); + void setAuthType(WizardCommon::AuthType type); + +signals: + void clearPendingRequests(); + void connectToOCUrl( const QString& ); + void determineAuthType(const QString&); + +private: + OwncloudSetupPage* _setupPage; + OwncloudHttpCredsPage* _httpCredsPage; + OwncloudWizardResultPage* _resultPage; + + QString _configFile; + QString _oCUser; + QStringList _setupLog; + bool _configExists; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/wizard/owncloudwizardcommon.cpp b/src/mirall/wizard/owncloudwizardcommon.cpp new file mode 100644 index 000000000..10e66bb1b --- /dev/null +++ b/src/mirall/wizard/owncloudwizardcommon.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "mirall/wizard/owncloudwizardcommon.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +namespace WizardCommon +{ + +void setupCustomMedia( const QVariant& variant, QLabel *label ) +{ + if( !label ) return; + + QPixmap pix = variant.value(); + if( !pix.isNull() ) { + label->setPixmap(pix); + label->setAlignment( Qt::AlignTop | Qt::AlignRight ); + label->setVisible(true); + } else { + QString str = variant.toString(); + if( !str.isEmpty() ) { + label->setText( str ); + label->setTextFormat( Qt::RichText ); + label->setVisible(true); + label->setOpenExternalLinks(true); + } + } +} + +QString titleTemplate() +{ + return QString::fromLatin1("").arg(Theme::instance()->wizardHeaderTitleColor().name()) + QString::fromLatin1("%1"); +} + +QString subTitleTemplate() +{ + return QString::fromLatin1("").arg(Theme::instance()->wizardHeaderTitleColor().name()) + QString::fromLatin1("%1"); +} + +void initErrorLabel(QLabel* errorLabel) +{ + QString style = QLatin1String("border: 1px solid #eed3d7; border-radius: 5px; padding: 3px;" + "background-color: #f2dede; color: #b94a48;"); + + errorLabel->setStyleSheet(style); + errorLabel->setWordWrap(true); + errorLabel->setVisible(false); +} + +} // ns WizardCommon + +} // ns Mirall diff --git a/src/mirall/wizard/owncloudwizardcommon.h b/src/mirall/wizard/owncloudwizardcommon.h new file mode 100644 index 000000000..d4b0ec21c --- /dev/null +++ b/src/mirall/wizard/owncloudwizardcommon.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_WIZARD_COMMON_H +#define MIRALL_OWNCLOUD_WIZARD_COMMON_H + +class QVariant; +class QLabel; + +namespace Mirall +{ + +namespace WizardCommon +{ + +void setupCustomMedia( const QVariant& variant, QLabel *label ); +QString titleTemplate(); +QString subTitleTemplate(); +void initErrorLabel(QLabel* errorLabel); + +enum AuthType { + HttpCreds, + Shibboleth +}; + +enum SyncMode { + SelectiveMode, + BoxMode +}; + +enum Pages { + Page_oCSetup, + Page_HttpCreds, + Page_Result +}; + +} // ns WizardCommon + +} // ns Mirall + +#endif // MIRALL_OWNCLOUD_WIZARD_COMMON_H diff --git a/src/mirall/wizard/owncloudwizardresultpage.cpp b/src/mirall/wizard/owncloudwizardresultpage.cpp new file mode 100644 index 000000000..a4ece4236 --- /dev/null +++ b/src/mirall/wizard/owncloudwizardresultpage.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include +#include + +#include "mirall/wizard/owncloudwizardresultpage.h" +#include "mirall/wizard/owncloudwizardcommon.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +OwncloudWizardResultPage::OwncloudWizardResultPage() + : QWizardPage(), + _localFolder(), + _remoteFolder(), + _complete(false), + _ui() +{ + _ui.setupUi(this); + // no fields to register. + + setTitle(WizardCommon::subTitleTemplate().arg(tr("Everything set up!"))); + // required to show header in QWizard's modern style + setSubTitle( QLatin1String(" ") ); + + _ui.pbOpenLocal->setText(tr("Open Local Folder")); + _ui.pbOpenLocal->setIcon(QIcon(":/mirall/resources/folder-sync.png")); + _ui.pbOpenLocal->setIconSize(QSize(48, 48)); + _ui.pbOpenLocal->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + connect(_ui.pbOpenLocal, SIGNAL(clicked()), SLOT(slotOpenLocal())); + + Theme* theme = Theme::instance(); + QIcon appIcon = theme->applicationIcon(); + _ui.pbOpenServer->setText(tr("Open %1").arg(theme->appNameGUI())); + _ui.pbOpenServer->setIcon(appIcon.pixmap(48)); + _ui.pbOpenServer->setIconSize(QSize(48, 48)); + _ui.pbOpenServer->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + connect(_ui.pbOpenServer, SIGNAL(clicked()), SLOT(slotOpenServer())); + setupCustomization(); +} + +OwncloudWizardResultPage::~OwncloudWizardResultPage() +{} + +void OwncloudWizardResultPage::setComplete(bool complete) +{ + _complete = complete; + emit completeChanged(); +} + +bool OwncloudWizardResultPage::isComplete() const +{ + return _complete; +} + +void OwncloudWizardResultPage::initializePage() +{ + const QString localFolder = wizard()->property("localFolder").toString(); + QString text; + if( _remoteFolder == QLatin1String("/") || _remoteFolder.isEmpty() ) { + text = tr("Your entire account is synced to the local folder %1") + .arg(QDir::toNativeSeparators(localFolder)); + } else { + text = tr("ownCloud folder %1 is synced to local folder %2") + .arg(_remoteFolder).arg(QDir::toNativeSeparators(localFolder)); + } + _ui.localFolderLabel->setText( text ); + +} + +void OwncloudWizardResultPage::setRemoteFolder(const QString &remoteFolder) +{ + _remoteFolder = remoteFolder; +} + +void OwncloudWizardResultPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->setText( QString::null ); + _ui.topLabel->hide(); + + QVariant variant = Theme::instance()->customMedia( Theme::oCSetupResultTop ); + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); +} + +void OwncloudWizardResultPage::slotOpenLocal() +{ + const QString localFolder = wizard()->property("localFolder").toString(); + QDesktopServices::openUrl(QUrl::fromLocalFile(localFolder)); +} + +void OwncloudWizardResultPage::slotOpenServer() +{ + QUrl url = field("OCUrl").toUrl(); + qDebug() << Q_FUNC_INFO << url; + QDesktopServices::openUrl(url); +} + +} // ns Mirall diff --git a/src/mirall/wizard/owncloudwizardresultpage.h b/src/mirall/wizard/owncloudwizardresultpage.h new file mode 100644 index 000000000..64158e130 --- /dev/null +++ b/src/mirall/wizard/owncloudwizardresultpage.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_WIZARD_RESULT_PAGE_H +#define MIRALL_OWNCLOUD_WIZARD_RESULT_PAGE_H + +#include + +#include "ui_owncloudwizardresultpage.h" + +namespace Mirall { + +class OwncloudWizardResultPage : public QWizardPage +{ + Q_OBJECT +public: + OwncloudWizardResultPage(); + ~OwncloudWizardResultPage(); + + bool isComplete() const; + void initializePage(); + void setRemoteFolder( const QString& remoteFolder); + +public slots: + void setComplete(bool complete); + +protected slots: + void slotOpenLocal(); + void slotOpenServer(); + +protected: + void setupCustomization(); + +private: + QString _localFolder; + QString _remoteFolder; + bool _complete; + + Ui_OwncloudWizardResultPage _ui; +}; + +} // ns Mirall + +#endif -- cgit v1.2.3 From 92af3ea725a116931375b8731a2fdbf087cab5b8 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 29 Jul 2013 14:28:19 +0200 Subject: Add and use credentials abstraction. Implement HTTP and dummy credentials. To achieve that MirallConfigFile now exports several general settings-related methods for subclasses (here: for HttpConfigFile), so it does not have to contain any code targeted for specific credentials. --- src/CMakeLists.txt | 11 +- src/mirall/application.cpp | 31 +++- src/mirall/application.h | 2 + src/mirall/connectionvalidator.cpp | 46 +---- src/mirall/connectionvalidator.h | 2 - src/mirall/credentialstore.cpp | 28 +-- src/mirall/creds/abstractcredentials.h | 49 +++++ src/mirall/creds/credentialsfactory.cpp | 42 +++++ src/mirall/creds/credentialsfactory.h | 35 ++++ src/mirall/creds/dummycredentials.cpp | 57 ++++++ src/mirall/creds/dummycredentials.h | 41 ++++ src/mirall/creds/httpconfigfile.cpp | 84 +++++++++ src/mirall/creds/httpconfigfile.h | 43 +++++ src/mirall/creds/httpcredentials.cpp | 247 +++++++++++++++++++++++++ src/mirall/creds/httpcredentials.h | 63 +++++++ src/mirall/csyncthread.cpp | 41 ++-- src/mirall/csyncthread.h | 4 - src/mirall/folder.cpp | 73 +------- src/mirall/folder.h | 7 - src/mirall/mirallconfigfile.cpp | 277 ++++++++++++---------------- src/mirall/mirallconfigfile.h | 25 +-- src/mirall/owncloudinfo.cpp | 55 +----- src/mirall/owncloudinfo.h | 1 - src/mirall/owncloudsetupwizard.cpp | 61 +++--- src/mirall/syncresult.cpp | 6 +- src/mirall/wizard/abstractcredswizardpage.h | 35 ++++ src/mirall/wizard/owncloudhttpcredspage.cpp | 8 +- src/mirall/wizard/owncloudhttpcredspage.h | 6 +- src/mirall/wizard/owncloudsetuppage.cpp | 4 +- src/mirall/wizard/owncloudwizard.cpp | 47 +++-- src/mirall/wizard/owncloudwizard.h | 10 +- src/mirall/wizard/owncloudwizardcommon.cpp | 2 +- 32 files changed, 1003 insertions(+), 440 deletions(-) create mode 100644 src/mirall/creds/abstractcredentials.h create mode 100644 src/mirall/creds/credentialsfactory.cpp create mode 100644 src/mirall/creds/credentialsfactory.h create mode 100644 src/mirall/creds/dummycredentials.cpp create mode 100644 src/mirall/creds/dummycredentials.h create mode 100644 src/mirall/creds/httpconfigfile.cpp create mode 100644 src/mirall/creds/httpconfigfile.h create mode 100644 src/mirall/creds/httpcredentials.cpp create mode 100644 src/mirall/creds/httpcredentials.h create mode 100644 src/mirall/wizard/abstractcredswizardpage.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56f99ef1d..368d72080 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,8 +78,12 @@ set(libsync_SRCS mirall/utility.cpp mirall/connectionvalidator.cpp mirall/progressdispatcher.cpp + mirall/creds/dummycredentials.cpp + mirall/creds/httpcredentials.cpp + mirall/creds/credentialsfactory.cpp + mirall/creds/httpconfigfile.cpp ) -set(libsync_HEADERS +set(libsync_HEADERS mirall/folderman.h mirall/folder.h mirall/folderwatcher.h @@ -91,6 +95,11 @@ set(libsync_HEADERS mirall/logger.h mirall/connectionvalidator.h mirall/progressdispatcher.h + mirall/creds/abstractcredentials.h + mirall/creds/dummycredentials.h + mirall/creds/httpcredentials.h + mirall/creds/credentialsfactory.h + mirall/creds/httpconfigfile.h ) IF( INOTIFY_FOUND ) diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 928b48577..bef9adc3f 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -37,6 +37,8 @@ #include "mirall/inotify.h" #include "mirall/connectionvalidator.h" +#include "mirall/creds/abstractcredentials.h" + #if defined(Q_OS_WIN) #include #endif @@ -191,6 +193,30 @@ void Application::slotStartUpdateDetector() } void Application::slotCheckConnection() +{ + MirallConfigFile cfg; + AbstractCredentials* credentials(cfg.getCredentials()); + + if (! credentials->ready()) { + connect( credentials, SIGNAL(fetched()), + this, SLOT(slotCredentialsFetched())); + credentials->fetch(); + } else { + runValidator(); + } +} + +void Application::slotCredentialsFetched() +{ + MirallConfigFile cfg; + AbstractCredentials* credentials(cfg.getCredentials()); + + disconnect(credentials, SIGNAL(fetched()), + this, SLOT(slotCredentialsFetched())); + runValidator(); +} + +void Application::runValidator() { _conValidator = new ConnectionValidator(); connect( _conValidator, SIGNAL(connectionResult(ConnectionValidator::Status)), @@ -198,7 +224,6 @@ void Application::slotCheckConnection() _conValidator->checkConnection(); } - void Application::slotConnectionValidatorResult(ConnectionValidator::Status status) { qDebug() << "Connection Validator Result: " << _conValidator->statusString(status); @@ -698,7 +723,7 @@ void Application::parseOptions(const QStringList &options) //parse options; if help or bad option exit while (it.hasNext()) { QString option = it.next(); - if (option == QLatin1String("--help") || option == QLatin1String("-h")) { + if (option == QLatin1String("--help") || option == QLatin1String("-h")) { setHelp(); break; } else if (option == QLatin1String("--logwindow") || @@ -735,7 +760,7 @@ void Application::parseOptions(const QStringList &options) setHelp(); break; } - } + } } void Application::computeOverallSyncStatus() diff --git a/src/mirall/application.h b/src/mirall/application.h index 5372a6cb9..3e906d86d 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -104,10 +104,12 @@ protected slots: void slotDisplayIdle(); void slotHelp(); void slotShowRecentChanges(); + void slotCredentialsFetched(); private: void setHelp(); void raiseDialog( QWidget* ); void rebuildRecentMenus(); + void runValidator(); Systray *_tray; QAction *_actionOpenoC; diff --git a/src/mirall/connectionvalidator.cpp b/src/mirall/connectionvalidator.cpp index 0d2536f0d..b9de32662 100644 --- a/src/mirall/connectionvalidator.cpp +++ b/src/mirall/connectionvalidator.cpp @@ -115,7 +115,7 @@ void ConnectionValidator::slotStatusFound( const QString& url, const QString& ve return; } - QTimer::singleShot( 0, this, SLOT( slotFetchCredentials() )); + QTimer::singleShot( 0, this, SLOT( slotCheckAuthentication() )); } // status.php could not be loaded. @@ -133,50 +133,6 @@ void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply) } -void ConnectionValidator::slotFetchCredentials() -{ - if( _connection.isEmpty() ) { - connect( CredentialStore::instance(), SIGNAL(fetchCredentialsFinished(bool)), - this, SLOT(slotCredentialsFetched(bool)) ); - CredentialStore::instance()->fetchCredentials(); - } else { - // Pull credentials from Mirall config. - slotCredentialsFetched( true ); - } -} - -void ConnectionValidator::slotCredentialsFetched( bool ok ) -{ - qDebug() << "Credentials successfully fetched: " << ok; - disconnect( CredentialStore::instance(), SIGNAL(fetchCredentialsFinished(bool)) ); - - if( ! ok ) { - Status stat; - _errors << tr("Error: Could not retrieve the password!"); - _errors << CredentialStore::instance()->errorMessage(); - stat = CredentialError; - - qDebug() << "Could not fetch credentials" << _errors; - - emit connectionResult( stat ); - } else { - QString user, pwd; - if( _connection.isEmpty() ) { - user = CredentialStore::instance()->user(); - pwd = CredentialStore::instance()->password(); - } else { - // in case of reconfiguration, the _connection is set. - MirallConfigFile cfg(_connection); - user = cfg.ownCloudUser(); - pwd = cfg.ownCloudPasswd(); - } - ownCloudInfo::instance()->setCredentials( user, pwd ); - - // Credential fetched ok. - QTimer::singleShot( 0, this, SLOT( slotCheckAuthentication() )); - } -} - void ConnectionValidator::slotCheckAuthentication() { connect( ownCloudInfo::instance(), SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), diff --git a/src/mirall/connectionvalidator.h b/src/mirall/connectionvalidator.h index 51237ed4e..93998eb3f 100644 --- a/src/mirall/connectionvalidator.h +++ b/src/mirall/connectionvalidator.h @@ -58,8 +58,6 @@ protected slots: void slotStatusFound( const QString&, const QString&, const QString&, const QString& ); void slotNoStatusFound(QNetworkReply *); - void slotFetchCredentials(); - void slotCredentialsFetched( bool ); void slotCheckAuthentication(); void slotAuthCheck( const QString& ,QNetworkReply * ); diff --git a/src/mirall/credentialstore.cpp b/src/mirall/credentialstore.cpp index 503483eff..4bd316282 100644 --- a/src/mirall/credentialstore.cpp +++ b/src/mirall/credentialstore.cpp @@ -17,7 +17,7 @@ #include "config.h" #include "mirall/credentialstore.h" -#include "mirall/mirallconfigfile.h" +#include "mirall/creds/httpconfigfile.h" #include "mirall/theme.h" #ifdef WITH_QTKEYCHAIN @@ -68,11 +68,11 @@ CredentialStore::CredState CredentialStore::state() void CredentialStore::fetchCredentials() { - MirallConfigFile cfgFile; + HttpConfigFile cfgFile; bool ok = false; QString pwd; - _user = cfgFile.ownCloudUser(); + _user = cfgFile.user(); _url = cfgFile.ownCloudUrl(); QString key = keyChainKey(_url); @@ -88,8 +88,9 @@ void CredentialStore::fetchCredentials() case CredentialStore::Settings: { /* Read from config file. */ _state = Fetching; - if( cfgFile.ownCloudPasswordExists() ) { - pwd = cfgFile.ownCloudPasswd(); + cfgFile.fixupOldPassword(); + if( cfgFile.passwordExists() ) { + pwd = cfgFile.password(); ok = true; } else { ok = false; @@ -210,7 +211,7 @@ void CredentialStore::slotKeyChainReadFinished(QKeychain::Job* job) if( _state == NoKeychainBackend ) { qDebug() << "No Storage Backend, falling back to Settings mode."; _type = CredentialStore::Settings; - fetchCredentials(); + fetchCredentials(_user); return; } @@ -255,21 +256,21 @@ void CredentialStore::setCredentials( const QString& url, const QString& user, void CredentialStore::saveCredentials( ) { - MirallConfigFile cfgFile; + HttpConfigFile cfgFile; QString key = keyChainKey(_url); if( key.isNull() ) { qDebug() << "Error: Can not save credentials, URL is zero!"; return; } #ifdef WITH_QTKEYCHAIN - WritePasswordJob *job = NULL; #endif + cfgFile.setUser(_user); switch( _type ) { - case CredentialStore::KeyChain: + case CredentialStore::KeyChain: { #ifdef WITH_QTKEYCHAIN + WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName()); // Set password in KeyChain - job = new WritePasswordJob(Theme::instance()->appName()); job->setKey( key ); job->setTextData(_passwd); @@ -278,9 +279,10 @@ void CredentialStore::saveCredentials( ) _state = AsyncWriting; job->start(); #endif + } break; case CredentialStore::Settings: - cfgFile.writePassword( _passwd ); + cfgFile.setPassword( _passwd ); reset(); break; default: @@ -309,8 +311,8 @@ void CredentialStore::slotKeyChainWriteFinished( QKeychain::Job *job ) } else { qDebug() << "Successfully stored password for user " << _user; // Try to remove password formerly stored in the config file. - MirallConfigFile cfgFile; - cfgFile.clearPasswordFromConfig(); + HttpConfigFile cfgFile; + cfgFile.removePassword(); _state = NotFetched; } } else { diff --git a/src/mirall/creds/abstractcredentials.h b/src/mirall/creds/abstractcredentials.h new file mode 100644 index 000000000..a61e7a324 --- /dev/null +++ b/src/mirall/creds/abstractcredentials.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_ABSTRACT_CREDENTIALS_H +#define MIRALL_CREDS_ABSTRACT_CREDENTIALS_H + +#include + +#include + +class QNetworkAccessManager; + +namespace Mirall +{ + +class AbstractCredentials : public QObject +{ + Q_OBJECT + +public: + // No need for virtual destructor - QObject already has one. + virtual void prepareSyncContext(CSYNC* ctx) = 0; + virtual bool changed(AbstractCredentials* credentials) const = 0; + virtual QString authType() const = 0; + virtual QNetworkAccessManager* getQNAM() const = 0; + virtual bool ready() const = 0; + virtual void fetch() = 0; + virtual void persistForUrl(const QString& url) = 0; + +Q_SIGNALS: + void fetched(); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/credentialsfactory.cpp b/src/mirall/creds/credentialsfactory.cpp new file mode 100644 index 000000000..0dcc5a279 --- /dev/null +++ b/src/mirall/creds/credentialsfactory.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +#include "mirall/creds/httpcredentials.h" +#include "mirall/creds/dummycredentials.h" + +namespace Mirall +{ + +namespace CredentialsFactory +{ + +AbstractCredentials* create(const QString& type) +{ + if (type == "http") { + return new HttpCredentials; + } else if (type == "dummy") { + return new DummyCredentials; + } else { + // TODO: warn! + return new DummyCredentials; + } +} + +} // ns CredentialsFactory + +} // ns Mirall diff --git a/src/mirall/creds/credentialsfactory.h b/src/mirall/creds/credentialsfactory.h new file mode 100644 index 000000000..170610e5e --- /dev/null +++ b/src/mirall/creds/credentialsfactory.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_CREDENTIALS_FACTORY_H +#define MIRALL_CREDS_CREDENTIALS_FACTORY_H + +class AbstractCredentials; +class QString; + +namespace Mirall +{ + +namespace CredentialsFactory +{ + +AbstractCredentials* create(const QString& type); + +} // ns CredentialsFactory + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/dummycredentials.cpp b/src/mirall/creds/dummycredentials.cpp new file mode 100644 index 000000000..1747a6041 --- /dev/null +++ b/src/mirall/creds/dummycredentials.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +#include "dummycredentials.h" + +namespace Mirall +{ + +void DummyCredentials::prepareSyncContext(CSYNC*) +{} + +bool DummyCredentials::changed(AbstractCredentials* credentials) const +{ + DummyCredentials* dummy(dynamic_cast< DummyCredentials* >(credentials)); + + return dummy == 0; +} + +QString DummyCredentials::authType() const +{ + return QString::fromLatin1("dummy"); +} + +QNetworkAccessManager* DummyCredentials::getQNAM() const +{ + return new QNetworkAccessManager; +} + +bool DummyCredentials::ready() const +{ + return true; +} + +void DummyCredentials::fetch() +{ + Q_EMIT(fetched()); +} + +void DummyCredentials::persistForUrl(const QString&) +{} + +} // ns Mirall diff --git a/src/mirall/creds/dummycredentials.h b/src/mirall/creds/dummycredentials.h new file mode 100644 index 000000000..16f7af2c9 --- /dev/null +++ b/src/mirall/creds/dummycredentials.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_DUMMY_CREDENTIALS_H +#define MIRALL_CREDS_DUMMY_CREDENTIALS_H + +#include "mirall/creds/abstractcredentials.h" + +namespace Mirall +{ + +class DummyCredentials : public AbstractCredentials +{ + Q_OBJECT + +public: + void prepareSyncContext(CSYNC* ctx); + bool changed(AbstractCredentials* credentials) const; + QString authType() const; + QNetworkAccessManager* getQNAM() const; + bool ready() const; + void fetch(); + void persistForUrl(const QString& url); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/httpconfigfile.cpp b/src/mirall/creds/httpconfigfile.cpp new file mode 100644 index 000000000..f979ef693 --- /dev/null +++ b/src/mirall/creds/httpconfigfile.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/creds/httpconfigfile.h" + +namespace Mirall +{ + +namespace +{ + +const char userC[] = "user"; +const char passwdC[] = "passwd"; +const char oldPasswdC[] = "password"; + +} // ns + +QString HttpConfigFile::user() const +{ + return retrieveData(QString(), QLatin1String(userC)).toString(); +} + +void HttpConfigFile::setUser(const QString& user) +{ + storeData(QString(), QLatin1String(userC), QVariant(user)); +} + +QString HttpConfigFile::password() const +{ + const QVariant passwd(retrieveData(QString(), QLatin1String(passwdC))); + + if (passwd.isValid()) { + return QString::fromUtf8(QByteArray::fromBase64(passwd.toByteArray())); + } + + return QString(); +} + +void HttpConfigFile::setPassword(const QString& password) +{ + QByteArray pwdba = password.toUtf8(); + storeData( QString(), QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); + removeOldPassword(); +} + +bool HttpConfigFile::passwordExists() const +{ + dataExists(QString(), QLatin1String(passwdC)); +} + +void HttpConfigFile::removePassword() +{ + removeOldPassword(); + removeData(QString(), QLatin1String(passwdC)); +} + +void HttpConfigFile::fixupOldPassword() +{ + const QString old(QString::fromLatin1(oldPasswdC)); + + if (dataExists(QString(), old)) { + setPassword(retrieveData(QString(), old).toString()); + } +}; + +void HttpConfigFile::removeOldPassword() +{ + removeData(QString(), QLatin1String(oldPasswdC)); +} + +} // ns Mirall diff --git a/src/mirall/creds/httpconfigfile.h b/src/mirall/creds/httpconfigfile.h new file mode 100644 index 000000000..ae69329a9 --- /dev/null +++ b/src/mirall/creds/httpconfigfile.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_HTTP_CONFIG_FILE_H +#define MIRALL_CREDS_HTTP_CONFIG_FILE_H + +#include "mirall/mirallconfigfile.h" + +namespace Mirall +{ + +class HttpConfigFile : public MirallConfigFile +{ +public: + QString user() const; + void setUser(const QString& user); + + QString password() const; + void setPassword(const QString& password); + bool passwordExists() const; + void removePassword(); + void fixupOldPassword(); + +private: + void removeOldPassword(); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/httpcredentials.cpp b/src/mirall/creds/httpcredentials.cpp new file mode 100644 index 000000000..939210b28 --- /dev/null +++ b/src/mirall/creds/httpcredentials.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +#include "mirall/creds/httpcredentials.h" +#include "mirall/owncloudinfo.h" +#include "mirall/mirallconfigfile.h" +#include "mirall/utility.h" +#include "mirall/credentialstore.h" + +namespace Mirall +{ + +namespace +{ + +int getauth(const char *prompt, + char *buf, + size_t len, + int echo, + int verify, + void *userdata) +{ + int re = 0; + QMutex mutex; + MirallConfigFile cfg; + HttpCredentials* http_credentials = dynamic_cast< HttpCredentials* > (cfg.getCredentials()); + + if (!http_credentials) { + qDebug() << "Not a HTTP creds instance!"; + return -1; + } + + QString qPrompt = QString::fromLatin1( prompt ).trimmed(); + QString user = http_credentials->user(); + QString pwd = http_credentials->password(); + + if( qPrompt == QLatin1String("Enter your username:") ) { + // qDebug() << "OOO Username requested!"; + QMutexLocker locker( &mutex ); + qstrncpy( buf, user.toUtf8().constData(), len ); + } else if( qPrompt == QLatin1String("Enter your password:") ) { + QMutexLocker locker( &mutex ); + // qDebug() << "OOO Password requested!"; + qstrncpy( buf, pwd.toUtf8().constData(), len ); + } else { + if( qPrompt.startsWith( QLatin1String("There are problems with the SSL certificate:"))) { + // SSL is requested. If the program came here, the SSL check was done by mirall + // It needs to be checked if the chain is still equal to the one which + // was verified by the user. + QRegExp regexp("fingerprint: ([\\w\\d:]+)"); + bool certOk = false; + + int pos = 0; + + // This is the set of certificates which QNAM accepted, so we should accept + // them as well + QList certs = ownCloudInfo::instance()->certificateChain(); + + while (!certOk && (pos = regexp.indexIn(qPrompt, 1+pos)) != -1) { + QString neon_fingerprint = regexp.cap(1); + + foreach( const QSslCertificate& c, certs ) { + QString verified_shasum = Utility::formatFingerprint(c.digest(QCryptographicHash::Sha1).toHex()); + qDebug() << "SSL Fingerprint from neon: " << neon_fingerprint << " compared to verified: " << verified_shasum; + if( verified_shasum == neon_fingerprint ) { + certOk = true; + break; + } + } + } + // certOk = false; DEBUG setting, keep disabled! + if( !certOk ) { // Problem! + qstrcpy( buf, "no" ); + re = -1; + } else { + qstrcpy( buf, "yes" ); // Certificate is fine! + } + } else { + qDebug() << "Unknown prompt: <" << prompt << ">"; + re = -1; + } + } + return re; +} + +} // ns + +HttpCredentials::HttpCredentials() + : _user(), + _password(), + _ready(false), + _attempts() +{} + +HttpCredentials::HttpCredentials(const QString& user, const QString& password) + : _user(user), + _password(password), + _ready(true) +{} + +void HttpCredentials::prepareSyncContext (CSYNC* ctx) +{ + // TODO: This should not be a part of this method, but we don't have + // 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 cookies(ownCloudInfo::instance()->getLastAuthCookies()); + QString cookiesAsString; + + // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply + // when https://github.com/owncloud/core/pull/4042 is merged. + foreach(QNetworkCookie c, cookies) { + cookiesAsString += c.name(); + cookiesAsString += '='; + cookiesAsString += c.value(); + cookiesAsString += "; "; + } + + csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); + csync_set_auth_callback (ctx, getauth); +} + +bool HttpCredentials::changed(AbstractCredentials* credentials) const +{ + HttpCredentials* other(dynamic_cast< HttpCredentials* >(credentials)); + + if (!other || other->user() != this->user()) { + return true; + } + + return false; +} + +QString HttpCredentials::authType() const +{ + return QString::fromLatin1("http"); +} + +QString HttpCredentials::user() const +{ + return _user; +} + +QString HttpCredentials::password() const +{ + return _password; +} + +QNetworkAccessManager* HttpCredentials::getQNAM() const +{ + QNetworkAccessManager* qnam = new QNetworkAccessManager; + + connect( qnam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), + this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*))); + + return qnam; +} + +bool HttpCredentials::ready() const +{ + return _ready; +} + +void HttpCredentials::fetch() +{ + if (_ready) { + Q_EMIT fetched(); + } else { + // TODO: merge CredentialStore into HttpCredentials? + CredentialStore* store(CredentialStore::instance()); + connect(store, SIGNAL(fetchCredentialsFinished(bool)), + this, SLOT(slotCredentialsFetched(bool))); + store->fetchCredentials(); + } +} + +void HttpCredentials::persistForUrl(const QString& url) +{ + CredentialStore* store(CredentialStore::instance()); + store->setCredentials(url, _user, _password); + store->saveCredentials(); +} + +void HttpCredentials::slotCredentialsFetched(bool ok) +{ + _ready = ok; + if (_ready) { + CredentialStore* store(CredentialStore::instance()); + _user = store->user(); + _password = store->password(); + } + Q_EMIT fetched(); +} + +void HttpCredentials::slotAuthentication(QNetworkReply* reply, QAuthenticator* authenticator) +{ + if( !(authenticator && reply) ) return; + + qDebug() << "Authenticating request for " << reply->url(); + + if (_attempts.contains(reply)) { + ++_attempts[reply]; + } else { + connect(reply, SIGNAL(finished()), + this, SLOT(slotReplyFinished())); + _attempts[reply] = 1; + } + // TODO: Replace it with something meaningful... + //if( reply->url().toString().startsWith( webdavUrl( _connection ) ) ) { + if (_attempts[reply] > 1) { + qDebug() << "Too many attempts to authenticate. Stop request."; + reply->close(); + } else { + authenticator->setUser( _user ); + authenticator->setPassword( _password ); + } + //} else { + // qDebug() << "WRN: attempt to authenticate to different url - closing."; + // reply->close(); + //} +} + +void HttpCredentials::slotReplyFinished() +{ + QNetworkReply* reply = qobject_cast< QNetworkReply* >(sender()); + + disconnect(reply, SIGNAL(finished()), + this, SLOT(slotReplyFinished())); + _attempts.remove (reply); +} + +} // ns Mirall diff --git a/src/mirall/creds/httpcredentials.h b/src/mirall/creds/httpcredentials.h new file mode 100644 index 000000000..7c044bea9 --- /dev/null +++ b/src/mirall/creds/httpcredentials.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_HTTP_CREDENTIALS_H +#define MIRALL_CREDS_HTTP_CREDENTIALS_H + +#include + +#include "mirall/creds/abstractcredentials.h" + +class QNetworkReply; +class QAuthenticator; + +namespace Mirall +{ + +class HttpCredentials : public AbstractCredentials +{ + Q_OBJECT + +public: + HttpCredentials(); + HttpCredentials(const QString& user, const QString& password); + + void prepareSyncContext (CSYNC* ctx); + bool changed(AbstractCredentials* credentials) const; + QString authType() const; + QNetworkAccessManager* getQNAM() const; + bool ready() const; + void fetch(); + void persistForUrl(const QString& url); + + QString user() const; + QString password() const; + +private Q_SLOTS: + void slotCredentialsFetched(bool); + void slotAuthentication(QNetworkReply*, QAuthenticator*); + void slotReplyFinished(); + +private: + QString _user; + QString _password; + bool _ready; + QMap _attempts; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 1f3d3b8c6..7576b9d27 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -338,21 +338,28 @@ void CSyncThread::startSync() csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); csync_set_userdata(_csync_ctx, this); - if (_lastAuthCookies.length() > 0) { - // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply - // when https://github.com/owncloud/core/pull/4042 is merged. - QString cookiesAsString; - foreach(QNetworkCookie c, _lastAuthCookies) { - cookiesAsString += c.name(); - cookiesAsString += '='; - cookiesAsString += c.value(); - cookiesAsString += "; "; - } - csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.toAscii().data()); - } + // TODO: This should be a part of this method, but we don't have + // any way to get "session_key" module property from csync. Had we + // have it, then we could keep this code and remove it from + // AbstractCredentials implementations. + + // if (_lastAuthCookies.length() > 0) { + // // Stuff cookies inside csync, then we can avoid the intermediate HTTP + // // when https://github.com/owncloud/core/pull/4042 is merged. + // QString cookiesAsString; + // foreach(QNetworkCookie c, _lastAuthCookies) { + // cookiesAsString += c.name(); + // cookiesAsString += '='; + // cookiesAsString += c.value(); + // cookiesAsString += "; "; + // } + // csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.to + // } // csync_set_auth_callback( _csync_ctx, getauth ); + + qDebug() << "#### Update start #################################################### >>"; if( csync_update(_csync_ctx) < 0 ) { handleSyncError(_csync_ctx, "csync_update"); @@ -361,7 +368,7 @@ void CSyncThread::startSync() qDebug() << "<<#### Update end ###########################################################"; if( csync_reconcile(_csync_ctx) < 0 ) { - handleSyncError(_csync_ctx, "cysnc_reconcile"); + handleSyncError(_csync_ctx, "csync_reconcile"); return; } @@ -473,10 +480,4 @@ void CSyncThread::cb_progress( CSYNC_PROGRESS *progress, void *userdata ) } -void CSyncThread::setLastAuthCookies(QList c) -{ - _lastAuthCookies = c; -} - - -} +} // ns Mirall diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 40a376035..c737908ee 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -44,8 +44,6 @@ public: Q_INVOKABLE void startSync(); - void setLastAuthCookies(QList c); - signals: void fileReceived( const QString& ); void fileRemoved( const QString& ); @@ -87,8 +85,6 @@ private: bool _hasFiles; // true if there is at least one file that is not ignored or removed - QList _lastAuthCookies; - friend class CSyncRunScopeHelper; }; } diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 566cc8f70..c28874aa4 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -21,8 +21,7 @@ #include "mirall/syncresult.h" #include "mirall/logger.h" #include "mirall/owncloudinfo.h" -#include "mirall/credentialstore.h" -#include "mirall/utility.h" +#include "mirall/creds/abstractcredentials.h" #include #include @@ -121,7 +120,10 @@ bool Folder::init() csync_enable_conflictcopys(_csync_ctx); setIgnoredFiles(); - csync_set_auth_callback( _csync_ctx, getauth ); + AbstractCredentials* credentials(cfgFile.getCredentials()); + if (credentials) { + credentials->prepareSyncContext (_csync_ctx); + } if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_error(_csync_ctx) << csync_get_error_string(_csync_ctx); @@ -461,70 +463,6 @@ const char* Folder::proxyTypeToCStr(QNetworkProxy::ProxyType type) } } -int Folder::getauth(const char *prompt, - char *buf, - size_t len, - int echo, - int verify, - void *userdata - ) -{ - int re = 0; - QMutex mutex; - - QString qPrompt = QString::fromLatin1( prompt ).trimmed(); - QString user = CredentialStore::instance()->user(); - QString pwd = CredentialStore::instance()->password(); - - if( qPrompt == QLatin1String("Enter your username:") ) { - // qDebug() << "OOO Username requested!"; - QMutexLocker locker( &mutex ); - qstrncpy( buf, user.toUtf8().constData(), len ); - } else if( qPrompt == QLatin1String("Enter your password:") ) { - QMutexLocker locker( &mutex ); - // qDebug() << "OOO Password requested!"; - qstrncpy( buf, pwd.toUtf8().constData(), len ); - } else { - if( qPrompt.startsWith( QLatin1String("There are problems with the SSL certificate:"))) { - // SSL is requested. If the program came here, the SSL check was done by mirall - // It needs to be checked if the chain is still equal to the one which - // was verified by the user. - QRegExp regexp("fingerprint: ([\\w\\d:]+)"); - bool certOk = false; - - int pos = 0; - - // This is the set of certificates which QNAM accepted, so we should accept - // them as well - QList certs = ownCloudInfo::instance()->certificateChain(); - - while (!certOk && (pos = regexp.indexIn(qPrompt, 1+pos)) != -1) { - QString neon_fingerprint = regexp.cap(1); - - foreach( const QSslCertificate& c, certs ) { - QString verified_shasum = Utility::formatFingerprint(c.digest(QCryptographicHash::Sha1).toHex()); - qDebug() << "SSL Fingerprint from neon: " << neon_fingerprint << " compared to verified: " << verified_shasum; - if( verified_shasum == neon_fingerprint ) { - certOk = true; - break; - } - } - } - // certOk = false; DEBUG setting, keep disabled! - if( !certOk ) { // Problem! - qstrcpy( buf, "no" ); - re = -1; - } else { - qstrcpy( buf, "yes" ); // Certificate is fine! - } - } else { - qDebug() << "Unknown prompt: <" << prompt << ">"; - re = -1; - } - } - return re; -} - void Folder::startSync(const QStringList &pathList) { Q_UNUSED(pathList) @@ -562,7 +500,6 @@ void Folder::startSync(const QStringList &pathList) _thread->setPriority(QThread::LowPriority); setIgnoredFiles(); _csync = new CSyncThread( _csync_ctx ); - _csync->setLastAuthCookies(ownCloudInfo::instance()->getLastAuthCookies()); _csync->moveToThread(_thread); diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 653c99301..3f8dfdcb4 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -205,13 +205,6 @@ protected: void setIgnoredFiles(); void setProxy(); - static int getauth(const char *prompt, - char *buf, - size_t len, - int echo, - int verify, - void *userdata - ); const char* proxyTypeToCStr(QNetworkProxy::ProxyType type); /** diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index 21817c944..c62ad272b 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -19,7 +19,8 @@ #include "mirall/owncloudtheme.h" #include "mirall/theme.h" #include "mirall/credentialstore.h" - +#include "mirall/creds/abstractcredentials.h" +#include "mirall/creds/credentialsfactory.h" #include #include @@ -29,8 +30,7 @@ namespace Mirall { static const char urlC[] = "url"; -static const char userC[] = "user"; -static const char passwdC[] = "passwd"; +static const char authTypeC[] = "authType"; static const char caCertsKeyC[] = "CaCertificates"; static const char remotePollIntervalC[] = "remotePollInterval"; @@ -57,11 +57,29 @@ static const char maxLogLinesC[] = "Logging/maxLogLines"; QString MirallConfigFile::_oCVersion; QString MirallConfigFile::_confDir = QString::null; bool MirallConfigFile::_askedUser = false; +QMap< QString, MirallConfigFile::SharedCreds > MirallConfigFile::credentialsPerConfig; MirallConfigFile::MirallConfigFile( const QString& appendix ) :_customHandle(appendix) { QSettings::setDefaultFormat(QSettings::IniFormat); + if (! credentialsPerConfig.contains(_customHandle)) { + QString con( _customHandle ); + if( _customHandle.isEmpty() ) con = defaultConnection(); + + const QString config = configFile(); + qDebug() << "Loading config: " << config; + + QSettings settings(config, QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + settings.beginGroup( con ); + + QString type = settings.value( QLatin1String(authTypeC) ).toString(); + + qDebug() << "Getting credentials of type " << type << " for " << _customHandle; + + credentialsPerConfig.insert(_customHandle, SharedCreds(CredentialsFactory::create (type))); + } } void MirallConfigFile::setConfDir(const QString &value) @@ -77,30 +95,30 @@ void MirallConfigFile::setConfDir(const QString &value) bool MirallConfigFile::optionalDesktopNotifications() const { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); return settings.value(QLatin1String(optionalDesktopNoficationsC), true).toBool(); } void MirallConfigFile::setOptionalDesktopNotifications(bool show) { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.setValue(QLatin1String(optionalDesktopNoficationsC), show); settings.sync(); } QString MirallConfigFile::seenVersion() const { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); return settings.value(QLatin1String(seenVersionC)).toString(); } void MirallConfigFile::setSeenVersion(const QString &version) { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.setValue(QLatin1String(seenVersionC), version); settings.sync(); } @@ -108,8 +126,8 @@ void MirallConfigFile::setSeenVersion(const QString &version) void MirallConfigFile::saveGeometry(QWidget *w) { Q_ASSERT(!w->objectName().isNull()); - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup(w->objectName()); settings.setValue(QLatin1String(geometryC), w->saveGeometry()); settings.sync(); @@ -122,9 +140,10 @@ void MirallConfigFile::restoreGeometry(QWidget *w) QString MirallConfigFile::configPath() const { - QString dir = _confDir; - if( _confDir.isEmpty() ) + if( _confDir.isEmpty() ) { _confDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + } + QString dir = _confDir; if( !dir.endsWith(QLatin1Char('/')) ) dir.append(QLatin1Char('/')); return dir; @@ -176,13 +195,13 @@ QString MirallConfigFile::configFile() const if( qApp->applicationName().isEmpty() ) { qApp->setApplicationName( Theme::instance()->appNameGUI() ); } - QString dir = configPath() + Theme::instance()->configFileName(); + QString file = configPath() + Theme::instance()->configFileName(); if( !_customHandle.isEmpty() ) { - dir.append( QLatin1Char('_')); - dir.append( _customHandle ); - qDebug() << " OO Custom config file in use: " << dir; + file.append( QLatin1Char('_')); + file.append( _customHandle ); + qDebug() << __PRETTY_FUNCTION__ << " OO Custom config file in use: " << file; } - return dir; + return file; } bool MirallConfigFile::exists() @@ -201,8 +220,8 @@ bool MirallConfigFile::connectionExists( const QString& conn ) QString con = conn; if( conn.isEmpty() ) con = defaultConnection(); - QSettings settings( configFile(), QSettings::IniFormat); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup(conn); return settings.contains( QLatin1String(urlC) ); @@ -211,87 +230,80 @@ bool MirallConfigFile::connectionExists( const QString& conn ) void MirallConfigFile::writeOwncloudConfig( const QString& connection, const QString& url, - const QString& user, - const QString& passwd ) + AbstractCredentials* credentials) { const QString file = configFile(); qDebug() << "*** writing mirall config to " << file; - QSettings settings( file, QSettings::IniFormat); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup( connection ); settings.setValue( QLatin1String(urlC), url ); - settings.setValue( QLatin1String(userC), user ); - - -#ifdef WITH_QTKEYCHAIN - // Password is stored to QtKeyChain now by default in CredentialStore - // The CredentialStore calls clearPasswordFromConfig after the creds - // were successfully wiritten to delete the passwd entry from config. - qDebug() << "Going to delete the password from settings file."; -#endif - writePassword( passwd ); - + settings.setValue(QLatin1String(authTypeC), credentials->authType()); + credentialsPerConfig.insert(_customHandle, SharedCreds(credentials)); settings.sync(); // check the perms, only read-write for the owner. QFile::setPermissions( file, QFile::ReadOwner|QFile::WriteOwner ); // Store credentials temporar until the config is finalized. - ownCloudInfo::instance()->setCredentials( user, passwd, _customHandle ); + //ownCloudInfo::instance()->setCredentials( user, passwd, _customHandle ); } -// This method is called after the password was successfully stored into the -// QKeyChain in CredentialStore. -void MirallConfigFile::clearPasswordFromConfig( const QString& connection ) +void MirallConfigFile::storeData(const QString& group, const QString& key, const QVariant& value) { - const QString file = configFile(); - QString con( defaultConnection() ); - if( !connection.isEmpty() ) - con = connection; + const QString con(group.isEmpty() ? defaultConnection() : group); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); - QSettings settings( file, QSettings::IniFormat); - settings.setIniCodec( "UTF-8" ); - settings.beginGroup( con ); - settings.remove(QLatin1String(passwdC)); - // old key name - settings.remove(QLatin1String("password")); + settings.beginGroup(con); + settings.setValue(key, value); settings.sync(); } -bool MirallConfigFile::writePassword( const QString& passwd, const QString& connection ) +QVariant MirallConfigFile::retrieveData(const QString& group, const QString& key) const { - const QString file = configFile(); - QString pwd( passwd ); - QString con( defaultConnection() ); - if( !connection.isEmpty() ) - con = connection; + const QString con(group.isEmpty() ? defaultConnection() : group); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); - QSettings settings( file, QSettings::IniFormat); - settings.setIniCodec( "UTF-8" ); + settings.beginGroup(con); + return settings.value(key); +} - // store password into settings file. - settings.beginGroup( con ); - QByteArray pwdba = pwd.toUtf8(); - settings.setValue( QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); - settings.sync(); +void MirallConfigFile::removeData(const QString& group, const QString& key) +{ + const QString con(group.isEmpty() ? defaultConnection() : group); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); - return true; + settings.beginGroup(con); + settings.remove(key); +} + +bool MirallConfigFile::dataExists(const QString& group, const QString& key) const +{ + const QString con(group.isEmpty() ? defaultConnection() : group); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + + settings.beginGroup(con); + return settings.contains(key); } QByteArray MirallConfigFile::caCerts( ) { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); return settings.value( QLatin1String(caCertsKeyC) ).toByteArray(); } void MirallConfigFile::setCaCerts( const QByteArray & certs ) { - const QString file = configFile(); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); - QSettings settings( file, QSettings::IniFormat); settings.setIniCodec( "UTF-8" ); settings.setValue( QLatin1String(caCertsKeyC), certs ); settings.sync(); @@ -306,6 +318,7 @@ void MirallConfigFile::removeConnection( const QString& connection ) qDebug() << " removing the config file for connection " << con; // Currently its just removing the entire config file + // TODO: Eh? Shouldn't it try to load a file under configFile() and set it to INI? QSettings settings; settings.setIniCodec( "UTF-8" ); settings.beginGroup( con ); @@ -323,8 +336,8 @@ QString MirallConfigFile::ownCloudUrl( const QString& connection) const QString con( connection ); if( connection.isEmpty() ) con = defaultConnection(); - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup( con ); QString url = settings.value( QLatin1String(urlC) ).toString(); @@ -332,22 +345,7 @@ QString MirallConfigFile::ownCloudUrl( const QString& connection) const if( ! url.endsWith(QLatin1Char('/'))) url.append(QLatin1String("/")); } - return url; -} - -QString MirallConfigFile::ownCloudUser( const QString& connection ) const -{ - QString con( connection ); - if( connection.isEmpty() ) con = defaultConnection(); - - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); - settings.beginGroup( con ); - - QString user = settings.value( QLatin1String("user") ).toString(); - // qDebug() << "Returning configured owncloud user: " << user; - - return user; + return url; } int MirallConfigFile::remotePollInterval( const QString& connection ) const @@ -355,8 +353,8 @@ int MirallConfigFile::remotePollInterval( const QString& connection ) const QString con( connection ); if( connection.isEmpty() ) con = defaultConnection(); - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup( con ); int remoteInterval = settings.value( QLatin1String(remotePollIntervalC), DEFAULT_REMOTE_POLL_INTERVAL ).toInt(); @@ -376,57 +374,13 @@ void MirallConfigFile::setRemotePollInterval(int interval, const QString &connec qDebug() << "Remote Poll interval of " << interval << " is below fife seconds."; return; } - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup( con ); settings.setValue(QLatin1String(remotePollIntervalC), interval ); settings.sync(); } -bool MirallConfigFile::ownCloudPasswordExists( const QString& connection ) const -{ - QString con( connection ); - if( connection.isEmpty() ) con = defaultConnection(); - - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); - settings.beginGroup( con ); - - bool rc = false; - if( settings.contains(QLatin1String(passwdC)) ) { - rc = true; - } - return rc; -} - -QString MirallConfigFile::ownCloudPasswd( const QString& connection ) const -{ - QString con( connection ); - if( connection.isEmpty() ) con = defaultConnection(); - - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); - settings.beginGroup( con ); - - QByteArray pwdba = settings.value(QLatin1String(passwdC)).toByteArray(); - if( !pwdba.isEmpty() ) { - return QString::fromUtf8( QByteArray::fromBase64(pwdba) ); - } - - // check the password entry, cleartext from before - // read it and convert to base64, delete the cleartext entry. - QString p = settings.value(QLatin1String("password")).toString(); - - if( ! p.isEmpty() ) { - // its there, save base64-encoded and delete. - pwdba = p.toUtf8(); - settings.setValue( QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); - settings.remove( QLatin1String("password") ); - settings.sync(); - } - return p; -} - QString MirallConfigFile::ownCloudVersion() const { return _oCVersion; @@ -444,8 +398,8 @@ bool MirallConfigFile::ownCloudSkipUpdateCheck( const QString& connection ) cons QString con( connection ); if( connection.isEmpty() ) con = defaultConnection(); - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup( con ); bool skipIt = settings.value( QLatin1String(skipUpdateCheckC), false ).toBool(); @@ -458,8 +412,8 @@ void MirallConfigFile::setOwnCloudSkipUpdateCheck( bool skip, const QString& con QString con( connection ); if( connection.isEmpty() ) con = defaultConnection(); - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.beginGroup( con ); settings.setValue( QLatin1String(skipUpdateCheckC), QVariant(skip) ); @@ -469,15 +423,15 @@ void MirallConfigFile::setOwnCloudSkipUpdateCheck( bool skip, const QString& con int MirallConfigFile::maxLogLines() const { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); return settings.value( QLatin1String(maxLogLinesC), DEFAULT_MAX_LOG_LINES ).toInt(); } void MirallConfigFile::setMaxLogLines( int lines ) { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.setValue(QLatin1String(maxLogLinesC), lines); settings.sync(); } @@ -505,6 +459,8 @@ void MirallConfigFile::acceptCustomConfig() QString srcConfig = configFile(); // this considers the custom handle + credentialsPerConfig.insert(QString(), credentialsPerConfig[_customHandle]); + credentialsPerConfig.remove(_customHandle); _customHandle.clear(); QString targetConfig = configFile(); QString targetBak = targetConfig + QLatin1String(".bak"); @@ -526,17 +482,7 @@ void MirallConfigFile::acceptCustomConfig() } QFile::remove( targetBak ); - // inform the credential store about the password change. - QString url = ownCloudUrl(); - QString user = ownCloudUser(); - QString pwd = ownCloudPasswd(); - - if( pwd.isEmpty() ) { - qDebug() << "Password is empty, skipping to write cred store."; - } else { - CredentialStore::instance()->setCredentials(url, user, pwd); - CredentialStore::instance()->saveCredentials(); - } + credentialsPerConfig[QString()]->persistForUrl(ownCloudUrl()); } void MirallConfigFile::setProxyType(int proxyType, @@ -545,8 +491,8 @@ void MirallConfigFile::setProxyType(int proxyType, const QString& user, const QString& pass) { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.setValue(QLatin1String(proxyTypeC), proxyType); @@ -564,8 +510,8 @@ void MirallConfigFile::setProxyType(int proxyType, QVariant MirallConfigFile::getValue(const QString& param, const QString& group, const QVariant& defaultValue) const { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); if (!group.isEmpty()) settings.beginGroup(group); @@ -574,8 +520,8 @@ QVariant MirallConfigFile::getValue(const QString& param, const QString& group, void MirallConfigFile::setValue(const QString& key, const QVariant &value) { - QSettings settings( configFile(), QSettings::IniFormat ); - settings.setIniCodec( "UTF-8" ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.setValue(key, value); } @@ -653,14 +599,21 @@ void MirallConfigFile::setDownloadLimit(int kbytes) bool MirallConfigFile::monoIcons() const { - QSettings settings( configFile(), QSettings::IniFormat ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); return settings.value(QLatin1String(monoIconsC), false).toBool(); } void MirallConfigFile::setMonoIcons(bool useMonoIcons) { - QSettings settings( configFile(), QSettings::IniFormat ); + QSettings settings(configFile(), QSettings::IniFormat); + settings.setIniCodec("UTF-8"); settings.setValue(QLatin1String(monoIconsC), useMonoIcons); } +AbstractCredentials* MirallConfigFile::getCredentials() const +{ + return credentialsPerConfig[_customHandle].data(); +} + } diff --git a/src/mirall/mirallconfigfile.h b/src/mirall/mirallconfigfile.h index e2707fd3d..fe24d9ca0 100644 --- a/src/mirall/mirallconfigfile.h +++ b/src/mirall/mirallconfigfile.h @@ -15,6 +15,7 @@ #ifndef MIRALLCONFIGFILE_H #define MIRALLCONFIGFILE_H +#include #include #include @@ -22,12 +23,10 @@ class QWidget; namespace Mirall { +class AbstractCredentials; + class MirallConfigFile { - /* let only CredentialStore read the password from the file. All other classes - * should work with CredentialStore to get the credentials. */ - friend class CredentialStore; - friend class ConnectionValidator; public: MirallConfigFile( const QString& appendix = QString() ); @@ -44,12 +43,12 @@ public: void writeOwncloudConfig( const QString& connection, const QString& url, - const QString& user, - const QString& passwd ); + AbstractCredentials* credentials); + + AbstractCredentials* getCredentials() const; void removeConnection( const QString& connection = QString() ); - QString ownCloudUser( const QString& connection = QString() ) const; QString ownCloudUrl( const QString& connection = QString() ) const; // the certs do not depend on a connection. @@ -117,11 +116,10 @@ public: void restoreGeometry(QWidget *w); protected: - // these classes can only be access from CredentialStore as a friend class. - bool ownCloudPasswordExists( const QString& connection = QString() ) const; - QString ownCloudPasswd( const QString& connection = QString() ) const; - void clearPasswordFromConfig( const QString& connect = QString() ); - bool writePassword( const QString& passwd, const QString& connection = QString() ); + void storeData(const QString& group, const QString& key, const QVariant& value); + QVariant retrieveData(const QString& group, const QString& key) const; + void removeData(const QString& group, const QString& key); + bool dataExists(const QString& group, const QString& key) const; private: QVariant getValue(const QString& param, const QString& group = QString::null, @@ -129,9 +127,12 @@ private: void setValue(const QString& key, const QVariant &value); private: + typedef QSharedPointer< AbstractCredentials > SharedCreds; + static bool _askedUser; static QString _oCVersion; static QString _confDir; + static QMap< QString, SharedCreds > credentialsPerConfig; QString _customHandle; }; diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index 9a0bbda0d..daca4c8eb 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -17,6 +17,7 @@ #include "mirall/theme.h" #include "mirall/utility.h" #include "mirall/logger.h" +#include "mirall/creds/abstractcredentials.h" #include #include @@ -56,8 +57,8 @@ ownCloudInfo::ownCloudInfo() : _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 +73,7 @@ void ownCloudInfo::setNetworkAccessManager( QNetworkAccessManager* qnam ) connect( _manager, SIGNAL( sslErrors(QNetworkReply*, QList)), this, SIGNAL(sslFailed(QNetworkReply*, QList)) ); - // 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 +85,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() @@ -306,42 +303,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 ownCloudInfo::getLastAuthCookies() { QUrl url = QUrl( webdavUrl(_connection)); @@ -478,8 +439,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; } } @@ -606,4 +567,4 @@ QString ownCloudInfo::webdavUrl(const QString &connection) return url; } -} +} // ns Mirall diff --git a/src/mirall/owncloudinfo.h b/src/mirall/owncloudinfo.h index d88fac0b9..901a17799 100644 --- a/src/mirall/owncloudinfo.h +++ b/src/mirall/owncloudinfo.h @@ -134,7 +134,6 @@ signals: protected slots: void slotReplyFinished( ); void slotError( QNetworkReply::NetworkError ); - void slotAuthentication( QNetworkReply*, QAuthenticator *); void slotMkdirFinished(); void slotGetQuotaFinished(); diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index ffb8abc2f..ba5b9f5d9 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -26,6 +26,8 @@ #include "mirall/folderman.h" #include "mirall/credentialstore.h" #include "mirall/utility.h" +#include "mirall/creds/abstractcredentials.h" +#include "mirall/creds/dummycredentials.h" namespace Mirall { @@ -40,7 +42,7 @@ OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent ) : this, SLOT(slotConnectToOCUrl( const QString& ))); connect( _ocWizard, SIGNAL(determineAuthType(const QString&)), - this, SLOT(slotDetermineAuthType(const QString&))); + this, SLOT(slotDetermineAuthType(const QString&))); connect( _ocWizard, SIGNAL(finished(int)),this,SLOT(slotAssistantFinished(int))); @@ -73,13 +75,13 @@ void OwncloudSetupWizard::startWizard() MirallConfigFile cfgFile; // Fill the entry fields with existing values. QString url = cfgFile.ownCloudUrl(); - QString user = cfgFile.ownCloudUser(); - bool configExists = !( url.isEmpty() || user.isEmpty() ); + //QString user = cfgFile.ownCloudUser(); + bool configExists = !( url.isEmpty()/* || user.isEmpty()*/ ); _ocWizard->setConfigExists( configExists ); - if( !user.isEmpty() ) { - _ocWizard->setOCUser( user ); - } + //if( !user.isEmpty() ) { + // _ocWizard->setOCUser( user ); + //} if( !url.isEmpty() ) { _ocWizard->setOCUrl( url ); @@ -121,19 +123,22 @@ void OwncloudSetupWizard::slotAssistantFinished( int result ) cfg.cleanupCustomConfig(); qDebug() << "Rejected the new config, use the old!"; } else if( result == QDialog::Accepted ) { + AbstractCredentials* credentials(_ocWizard->getCredentials()); + qDebug() << "Config Changes were accepted!"; // go through all folders and remove the journals if the server changed. MirallConfigFile prevCfg; QUrl prevUrl( prevCfg.ownCloudUrl() ); QUrl newUrl( cfg.ownCloudUrl() ); + AbstractCredentials* oldCredentials(prevCfg.getCredentials()); bool urlHasChanged = (prevUrl.host() != newUrl.host() || prevUrl.port() != newUrl.port() || prevUrl.path() != newUrl.path()); // if the user changed, its also a changed url. - if( prevCfg.ownCloudUser() != cfg.ownCloudUser() ) { + if(credentials->changed(oldCredentials)) { urlHasChanged = true; qDebug() << "The User has changed, same as url change."; } @@ -147,7 +152,7 @@ void OwncloudSetupWizard::slotAssistantFinished( int result ) folderMan->unloadAllFolders(); - bool startFromScratch = _ocWizard->field( "OCSyncFromScratch" ).toBool(); + bool startFromScratch = _ocWizard->field( "OCSyncFromScratch" ).toBool(); if( startFromScratch ) { // first try to rename (backup) the current local dir. bool renameOk = false; @@ -246,11 +251,12 @@ void OwncloudSetupWizard::testOwnCloudConnect() } cfgFile.writeOwncloudConfig( Theme::instance()->appName(), url, - _ocWizard->field(QLatin1String("OCUser")).toString(), - _ocWizard->field(QLatin1String("OCPasswd")).toString() ); + _ocWizard->getCredentials()); + ownCloudInfo* info(ownCloudInfo::instance()); + info->setCustomConfigHandle( _configHandle ); // If there is already a config, take its proxy config. - if( ownCloudInfo::instance()->isConfigured() ) { + if( info->isConfigured() ) { MirallConfigFile prevCfg; cfgFile.setProxyType( prevCfg.proxyType(), prevCfg.proxyHostName(), prevCfg.proxyPort(), prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); @@ -297,12 +303,13 @@ void OwncloudSetupWizard::setupLocalSyncFolder() void OwncloudSetupWizard::checkRemoteFolder() { - connect( ownCloudInfo::instance(),SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), + ownCloudInfo* info(ownCloudInfo::instance()); + connect( info,SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), this,SLOT(slotAuthCheckReply(QString,QNetworkReply*))); qDebug() << "# checking for authentication settings."; - ownCloudInfo::instance()->setCustomConfigHandle(_configHandle); - _checkRemoteFolderRequest = ownCloudInfo::instance()->getWebDAVPath(_remoteFolder ); // this call needs to be authenticated. + info->setCustomConfigHandle(_configHandle); + _checkRemoteFolderRequest = info->getWebDAVPath(_remoteFolder ); // this call needs to be authenticated. // continue in slotAuthCheckReply } @@ -354,10 +361,11 @@ bool OwncloudSetupWizard::createRemoteFolder() if( _remoteFolder.isEmpty() ) return false; _ocWizard->appendToConfigurationLog( tr("creating folder on ownCloud: %1" ).arg( _remoteFolder )); - connect(ownCloudInfo::instance(), SIGNAL(webdavColCreated(QNetworkReply::NetworkError)), + ownCloudInfo* info(ownCloudInfo::instance()); + connect(info, SIGNAL(webdavColCreated(QNetworkReply::NetworkError)), this, SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError))); - _mkdirRequestReply = ownCloudInfo::instance()->mkdirRequest( _remoteFolder ); + _mkdirRequestReply = info->mkdirRequest( _remoteFolder ); return (_mkdirRequestReply != NULL); } @@ -427,7 +435,7 @@ void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) qDebug() << "Connect to url: " << url; _ocWizard->setField(QLatin1String("OCUrl"), url ); _ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 to determine authentication type...") - .arg( Theme::instance()->appNameGUI() ).arg(url) ); + .arg( Theme::instance()->appNameGUI() ).arg(url) ); // write a temporary config. QDateTime now = QDateTime::currentDateTime(); @@ -456,18 +464,16 @@ void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) // shibboleth one. cfgFile.writeOwncloudConfig( Theme::instance()->appName(), url, - QLatin1String(""), - QLatin1String("")); + new DummyCredentials); + ownCloudInfo* info(ownCloudInfo::instance()); // If there is already a config, take its proxy config. - if( ownCloudInfo::instance()->isConfigured() ) { + if( info->isConfigured() ) { MirallConfigFile prevCfg; cfgFile.setProxyType( prevCfg.proxyType(), prevCfg.proxyHostName(), prevCfg.proxyPort(), prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); } - // now start ownCloudInfo to check the connection. - ownCloudInfo* info = ownCloudInfo::instance(); info->setCustomConfigHandle( _configHandle ); if( info->isConfigured() ) { // reset the SSL Untrust flag to let the SSL dialog appear again. @@ -479,7 +485,7 @@ void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) _checkInstallationRequest = info->checkInstallation(); } else { qDebug() << " ownCloud seems not to be configured, can not start test connect."; - } + } } void OwncloudSetupWizard::slotOwnCloudFoundAuth( const QString& url, const QString& infoString, const QString& version, const QString& ) @@ -496,7 +502,7 @@ void OwncloudSetupWizard::slotOwnCloudFoundAuth( const QString& url, const QStri QNetworkReply* reply = nm->get (QNetworkRequest (url + "/remote.php/webdav/")); connect (reply, SIGNAL(finished()), - this, SLOT(slotAuthCheckReplyFinished())); + this, SLOT(slotAuthCheckReplyFinished())); nm->setProperty ("mirallRedirs", QVariant (0)); } @@ -513,7 +519,7 @@ void OwncloudSetupWizard::slotAuthCheckReplyFinished() } disconnect (reply, SIGNAL(finished()), - this, SLOT(slotAuthCheckReplyFinished())); + this, SLOT(slotAuthCheckReplyFinished())); if ((reply->error () == QNetworkReply::AuthenticationRequiredError) || redirection.isEmpty()) { reply->deleteLater(); nm->deleteLater(); @@ -522,9 +528,9 @@ void OwncloudSetupWizard::slotAuthCheckReplyFinished() QNetworkReply* newReply = nm->get (QNetworkRequest(redirection)); connect (newReply, SIGNAL(error(QNetworkReply::NetworkError)), - this, SLOT(slotAuthCheckReplyError(QNetworkReply::NetworkError))); + this, SLOT(slotAuthCheckReplyError(QNetworkReply::NetworkError))); connect (newReply, SIGNAL(finished()), - this, SLOT(slotAuthCheckReplyFinished(QNetworkReply::NetworkError))); + this, SLOT(slotAuthCheckReplyFinished(QNetworkReply::NetworkError))); reply->deleteLater(); nm->setProperty ("mirallRedirs", QVariant(redirCount + 1)); @@ -556,7 +562,6 @@ void OwncloudSetupWizard::slotNoOwnCloudFoundAuth( QNetworkReply *err ) // remove the config file again MirallConfigFile cfgFile( _configHandle ); cfgFile.cleanupCustomConfig(); - finalizeSetup( false ); } } diff --git a/src/mirall/syncresult.cpp b/src/mirall/syncresult.cpp index 7e1ffccab..2a7a71726 100644 --- a/src/mirall/syncresult.cpp +++ b/src/mirall/syncresult.cpp @@ -56,9 +56,9 @@ QString SyncResult::statusString() const case SetupError: re = QLatin1String("SetupError"); break; - case SyncPrepare: - re = QLatin1String("SyncPrepare"); - break; + case SyncPrepare: + re = QLatin1String("SyncPrepare"); + break; case Unavailable: re = QLatin1String("Not availabe"); break; diff --git a/src/mirall/wizard/abstractcredswizardpage.h b/src/mirall/wizard/abstractcredswizardpage.h new file mode 100644 index 000000000..563d81d5e --- /dev/null +++ b/src/mirall/wizard/abstractcredswizardpage.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_ABSTRACT_CREDS_WIZARD_PAGE_H +#define MIRALL_WIZARD_ABSTRACT_CREDS_WIZARD_PAGE_H + +#include + +namespace Mirall +{ + +class AbstractCredentials; + +class AbstractCredentialsWizardPage : public QWizardPage +{ +public: + virtual AbstractCredentials* getCredentials() const = 0; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/wizard/owncloudhttpcredspage.cpp b/src/mirall/wizard/owncloudhttpcredspage.cpp index 99d06accc..9df58c5a2 100644 --- a/src/mirall/wizard/owncloudhttpcredspage.cpp +++ b/src/mirall/wizard/owncloudhttpcredspage.cpp @@ -19,12 +19,13 @@ #include "mirall/wizard/owncloudhttpcredspage.h" #include "mirall/theme.h" #include "mirall/wizard/owncloudwizardcommon.h" +#include "mirall/creds/httpcredentials.h" namespace Mirall { OwncloudHttpCredsPage::OwncloudHttpCredsPage() - : QWizardPage(), + : AbstractCredentialsWizardPage(), _ui(), _connected(false), _checking(false), @@ -134,4 +135,9 @@ void OwncloudHttpCredsPage::setErrorString(const QString& err) stopSpinner(); } +AbstractCredentials* OwncloudHttpCredsPage::getCredentials() const +{ + return new HttpCredentials(_ui.leUsername->text(), _ui.lePassword->text()); +} + } // ns Mirall diff --git a/src/mirall/wizard/owncloudhttpcredspage.h b/src/mirall/wizard/owncloudhttpcredspage.h index c9eadbd9f..40cd7e8fa 100644 --- a/src/mirall/wizard/owncloudhttpcredspage.h +++ b/src/mirall/wizard/owncloudhttpcredspage.h @@ -17,7 +17,7 @@ #ifndef MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H #define MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H -#include +#include "mirall/wizard/abstractcredswizardpage.h" #include "ui_owncloudhttpcredspage.h" @@ -25,12 +25,14 @@ class QProgressIndicator; namespace Mirall { -class OwncloudHttpCredsPage : public QWizardPage +class OwncloudHttpCredsPage : public AbstractCredentialsWizardPage { Q_OBJECT public: OwncloudHttpCredsPage(); + AbstractCredentials* getCredentials() const; + void setOCUser(const QString& user); void initializePage(); void cleanupPage(); diff --git a/src/mirall/wizard/owncloudsetuppage.cpp b/src/mirall/wizard/owncloudsetuppage.cpp index e32381a52..2a7f6a4a9 100644 --- a/src/mirall/wizard/owncloudsetuppage.cpp +++ b/src/mirall/wizard/owncloudsetuppage.cpp @@ -265,10 +265,10 @@ bool OwncloudSetupPage::validatePage() if( ! _authTypeKnown) { setErrorString(QString::null); _checking = true; - startSpinner (); + startSpinner (); emit completeChanged(); - emit determineAuthType(url()); + emit determineAuthType(url()); return false; } else { // connecting is running diff --git a/src/mirall/wizard/owncloudwizard.cpp b/src/mirall/wizard/owncloudwizard.cpp index b5d21e007..056d5ba40 100644 --- a/src/mirall/wizard/owncloudwizard.cpp +++ b/src/mirall/wizard/owncloudwizard.cpp @@ -31,24 +31,17 @@ namespace Mirall { -WizardCommon::SyncMode OwncloudWizard::syncMode() -{ - return _setupPage->syncMode(); - return WizardCommon::BoxMode; -} - -void OwncloudWizard::setMultipleFoldersExist(bool exist) -{ - _setupPage->setMultipleFoldersExist(exist); -} - OwncloudWizard::OwncloudWizard(QWidget *parent) : QWizard(parent), + _setupPage(new OwncloudSetupPage), + _httpCredsPage(new OwncloudHttpCredsPage), + _resultPage(new OwncloudWizardResultPage), + _credentialsPage(0), + _configFile(), + _oCUser(), + _setupLog(), _configExists(false) { - _setupPage = new OwncloudSetupPage; - _httpCredsPage = new OwncloudHttpCredsPage; - _resultPage = new OwncloudWizardResultPage; setPage(WizardCommon::Page_oCSetup, _setupPage ); setPage(WizardCommon::Page_HttpCreds, _httpCredsPage); setPage(WizardCommon::Page_Result, _resultPage ); @@ -73,6 +66,17 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) setSubTitleFormat(Qt::RichText); } +WizardCommon::SyncMode OwncloudWizard::syncMode() +{ + return _setupPage->syncMode(); + return WizardCommon::BoxMode; +} + +void OwncloudWizard::setMultipleFoldersExist(bool exist) +{ + _setupPage->setMultipleFoldersExist(exist); +} + QString OwncloudWizard::localFolder() const { return(_setupPage->localFolder()); @@ -114,6 +118,11 @@ void OwncloudWizard::successfullyConnected(bool enable) void OwncloudWizard::setAuthType(WizardCommon::AuthType type) { _setupPage->setAuthType(type); + if (type == WizardCommon::Shibboleth) { + _credentialsPage = 0; + } else { + _credentialsPage = _httpCredsPage; + } next(); } @@ -170,4 +179,14 @@ bool OwncloudWizard::configExists() return _configExists; } +AbstractCredentials* OwncloudWizard::getCredentials() const +{ + if (_credentialsPage) { + return _credentialsPage->getCredentials(); + } + + return 0; +} + + } // end namespace diff --git a/src/mirall/wizard/owncloudwizard.h b/src/mirall/wizard/owncloudwizard.h index bd6cf6814..fcfad61d9 100644 --- a/src/mirall/wizard/owncloudwizard.h +++ b/src/mirall/wizard/owncloudwizard.h @@ -26,6 +26,8 @@ namespace Mirall { class OwncloudSetupPage; class OwncloudHttpCredsPage; class OwncloudWizardResultPage; +class AbstractCredentials; +class AbstractCredentialsWizardPage; class OwncloudWizard: public QWizard { @@ -53,6 +55,9 @@ public: void setMultipleFoldersExist( bool ); void setConfigExists( bool ); bool configExists(); + void successfullyConnected(bool); + void setAuthType(WizardCommon::AuthType type); + AbstractCredentials* getCredentials() const; public slots: void setRemoteFolder( const QString& ); @@ -61,10 +66,6 @@ public slots: void showConnectInfo( const QString& ); -public: - void successfullyConnected(bool); - void setAuthType(WizardCommon::AuthType type); - signals: void clearPendingRequests(); void connectToOCUrl( const QString& ); @@ -74,6 +75,7 @@ private: OwncloudSetupPage* _setupPage; OwncloudHttpCredsPage* _httpCredsPage; OwncloudWizardResultPage* _resultPage; + AbstractCredentialsWizardPage* _credentialsPage; QString _configFile; QString _oCUser; diff --git a/src/mirall/wizard/owncloudwizardcommon.cpp b/src/mirall/wizard/owncloudwizardcommon.cpp index 10e66bb1b..e2aabef0e 100644 --- a/src/mirall/wizard/owncloudwizardcommon.cpp +++ b/src/mirall/wizard/owncloudwizardcommon.cpp @@ -60,7 +60,7 @@ QString subTitleTemplate() void initErrorLabel(QLabel* errorLabel) { QString style = QLatin1String("border: 1px solid #eed3d7; border-radius: 5px; padding: 3px;" - "background-color: #f2dede; color: #b94a48;"); + "background-color: #f2dede; color: #b94a48;"); errorLabel->setStyleSheet(style); errorLabel->setWordWrap(true); -- cgit v1.2.3 From 367bc401ee57c9c9a5226796d05d083baf49ac6d Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 29 Jul 2013 14:28:45 +0200 Subject: Add Shibboleth credentials implementation. --- src/CMakeLists.txt | 12 ++ src/mirall/creds/credentialsfactory.cpp | 5 +- src/mirall/creds/shibbolethaccessmanager.cpp | 38 ++++++ src/mirall/creds/shibbolethaccessmanager.h | 40 ++++++ src/mirall/creds/shibbolethcookiejar.cpp | 35 +++++ src/mirall/creds/shibbolethcookiejar.h | 42 ++++++ src/mirall/creds/shibbolethcredentials.cpp | 122 +++++++++++++++++ src/mirall/creds/shibbolethcredentials.h | 58 ++++++++ src/mirall/creds/shibbolethwebview.cpp | 50 +++++++ src/mirall/creds/shibbolethwebview.h | 43 ++++++ src/mirall/owncloudsetupwizard.cpp | 6 - src/mirall/owncloudshibbolethcredspage.ui | 121 +++++++++++++++++ src/mirall/wizard/owncloudsetuppage.cpp | 11 +- src/mirall/wizard/owncloudshibbolethcredspage.cpp | 154 ++++++++++++++++++++++ src/mirall/wizard/owncloudshibbolethcredspage.h | 70 ++++++++++ src/mirall/wizard/owncloudwizard.cpp | 15 ++- src/mirall/wizard/owncloudwizard.h | 2 + src/mirall/wizard/owncloudwizardcommon.h | 1 + 18 files changed, 808 insertions(+), 17 deletions(-) create mode 100644 src/mirall/creds/shibbolethaccessmanager.cpp create mode 100644 src/mirall/creds/shibbolethaccessmanager.h create mode 100644 src/mirall/creds/shibbolethcookiejar.cpp create mode 100644 src/mirall/creds/shibbolethcookiejar.h create mode 100644 src/mirall/creds/shibbolethcredentials.cpp create mode 100644 src/mirall/creds/shibbolethcredentials.h create mode 100644 src/mirall/creds/shibbolethwebview.cpp create mode 100644 src/mirall/creds/shibbolethwebview.h create mode 100644 src/mirall/owncloudshibbolethcredspage.ui create mode 100644 src/mirall/wizard/owncloudshibbolethcredspage.cpp create mode 100644 src/mirall/wizard/owncloudshibbolethcredspage.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 368d72080..a4340ef45 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ mirall/fileitemdialog.ui mirall/owncloudsetupnocredspage.ui mirall/owncloudhttpcredspage.ui mirall/owncloudwizardresultpage.ui +mirall/owncloudshibbolethcredspage.ui ) set(3rdparty_SRC @@ -82,7 +83,12 @@ set(libsync_SRCS mirall/creds/httpcredentials.cpp mirall/creds/credentialsfactory.cpp mirall/creds/httpconfigfile.cpp + mirall/creds/shibbolethcredentials.cpp + mirall/creds/shibbolethaccessmanager.cpp + mirall/creds/shibbolethcookiejar.cpp + mirall/creds/shibbolethwebview.cpp ) + set(libsync_HEADERS mirall/folderman.h mirall/folder.h @@ -100,6 +106,10 @@ set(libsync_HEADERS mirall/creds/httpcredentials.h mirall/creds/credentialsfactory.h mirall/creds/httpconfigfile.h + mirall/creds/shibbolethcredentials.h + mirall/creds/shibbolethaccessmanager.h + mirall/creds/shibbolethcookiejar.h + mirall/creds/shibbolethwebview.h ) IF( INOTIFY_FOUND ) @@ -167,6 +177,7 @@ set(mirall_SRCS mirall/wizard/owncloudhttpcredspage.cpp mirall/wizard/owncloudwizardresultpage.cpp mirall/wizard/owncloudwizardcommon.cpp + mirall/wizard/owncloudshibbolethcredspage.cpp mirall/owncloudsetupwizard.cpp mirall/updatedetector.cpp mirall/occinfo.cpp @@ -190,6 +201,7 @@ set(mirall_HEADERS mirall/wizard/owncloudhttpcredspage.h mirall/wizard/owncloudwizardresultpage.h mirall/wizard/owncloudwizardcommon.h + mirall/wizard/owncloudshibbolethcredspage.h mirall/folderstatusmodel.h mirall/updatedetector.h mirall/sslerrordialog.h diff --git a/src/mirall/creds/credentialsfactory.cpp b/src/mirall/creds/credentialsfactory.cpp index 0dcc5a279..1a1bd65e1 100644 --- a/src/mirall/creds/credentialsfactory.cpp +++ b/src/mirall/creds/credentialsfactory.cpp @@ -18,6 +18,7 @@ #include "mirall/creds/httpcredentials.h" #include "mirall/creds/dummycredentials.h" +#include "mirall/creds/shibbolethcredentials.h" namespace Mirall { @@ -31,8 +32,10 @@ AbstractCredentials* create(const QString& type) return new HttpCredentials; } else if (type == "dummy") { return new DummyCredentials; + } else if (type == "shibboleth") { + return new ShibbolethCredentials; } else { - // TODO: warn! + qWarning("Unknown credentials type: %d", qPrintable(type)); return new DummyCredentials; } } diff --git a/src/mirall/creds/shibbolethaccessmanager.cpp b/src/mirall/creds/shibbolethaccessmanager.cpp new file mode 100644 index 000000000..17cbce97c --- /dev/null +++ b/src/mirall/creds/shibbolethaccessmanager.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +#include "mirall/creds/shibbolethaccessmanager.h" + +namespace Mirall +{ + +ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent) + : QNetworkAccessManager (parent), + _cookie(cookie) +{} + +QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) +{ + QNetworkRequest newRequest(request); + QList cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >()); + + cookies << _cookie; + newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies)); + + return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); +} + +} // ns Mirall diff --git a/src/mirall/creds/shibbolethaccessmanager.h b/src/mirall/creds/shibbolethaccessmanager.h new file mode 100644 index 000000000..3300dae21 --- /dev/null +++ b/src/mirall/creds/shibbolethaccessmanager.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H +#define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H + +#include +#include + +namespace Mirall +{ + +class ShibbolethAccessManager : public QNetworkAccessManager +{ + Q_OBJECT + +public: + ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0); + +protected: + QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); + +private: + QNetworkCookie _cookie; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/shibbolethcookiejar.cpp b/src/mirall/creds/shibbolethcookiejar.cpp new file mode 100644 index 000000000..97f4c92c2 --- /dev/null +++ b/src/mirall/creds/shibbolethcookiejar.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/creds/shibbolethcookiejar.h" + +namespace Mirall +{ + +ShibbolethCookieJar::ShibbolethCookieJar (QObject* parent) + : QNetworkCookieJar (parent) +{} + +bool ShibbolethCookieJar::setCookiesFromUrl (const QList& cookieList, const QUrl& url) +{ + if (QNetworkCookieJar::setCookiesFromUrl (cookieList, url)) { + Q_EMIT newCookiesForUrl (cookieList, url); + + return true; + } + + return false; +} + +} // ns Mirall diff --git a/src/mirall/creds/shibbolethcookiejar.h b/src/mirall/creds/shibbolethcookiejar.h new file mode 100644 index 000000000..9d263571b --- /dev/null +++ b/src/mirall/creds/shibbolethcookiejar.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H +#define MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H + +#include +#include + +class QUrl; +class QNetworkCookie; + +namespace Mirall +{ + +class ShibbolethCookieJar : public QNetworkCookieJar +{ + Q_OBJECT + +public: + ShibbolethCookieJar (QObject* parent = 0); + + virtual bool setCookiesFromUrl (const QList& cookieList, const QUrl& url); + +Q_SIGNALS: + void newCookiesForUrl (const QList& cookieList, const QUrl& url); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/shibbolethcredentials.cpp b/src/mirall/creds/shibbolethcredentials.cpp new file mode 100644 index 000000000..87796727e --- /dev/null +++ b/src/mirall/creds/shibbolethcredentials.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/creds/shibbolethcredentials.h" +#include "mirall/creds/shibbolethaccessmanager.h" +#include "mirall/creds/shibbolethwebview.h" +#include "mirall/owncloudinfo.h" +#include "mirall/mirallconfigfile.h" + +namespace Mirall +{ + +ShibbolethCredentials::ShibbolethCredentials() + : _shibCookie(), + _ready(false), + _browser(0) +{} + +ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie) + : _shibCookie(cookie), + _ready(true), + _browser(0) +{} + +void ShibbolethCredentials::prepareSyncContext (CSYNC* ctx) +{ + QString cookiesAsString; + // TODO: This should not be a part of this method, but we don't + // have any way to get "session_key" module property from + // csync. Had we have it, then we could just append shibboleth + // cookies to the "session_key" value and set it in csync module. + QList cookies(ownCloudInfo::instance()->getLastAuthCookies()); + + cookies << _shibCookie; + // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply + // when https://github.com/owncloud/core/pull/4042 is merged. + foreach(QNetworkCookie c, cookies) { + cookiesAsString += c.name(); + cookiesAsString += '='; + cookiesAsString += c.value(); + cookiesAsString += "; "; + } + + csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); +} + +bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const +{ + ShibbolethCredentials* other(dynamic_cast< ShibbolethCredentials* >(credentials)); + + if (!other || other->cookie() != this->cookie()) { + return true; + } + + return false; +} + +QString ShibbolethCredentials::authType() const +{ + return QString::fromLatin1("shibboleth"); +} + +QNetworkCookie ShibbolethCredentials::cookie() const +{ + return _shibCookie; +} + +QNetworkAccessManager* ShibbolethCredentials::getQNAM() const +{ + return new ShibbolethAccessManager(_shibCookie); +} + +bool ShibbolethCredentials::ready() const +{ + return _ready; +} + +void ShibbolethCredentials::fetch() +{ + if (_ready) { + Q_EMIT fetched(); + } else { + MirallConfigFile cfg; + + _browser = new ShibbolethWebView(QUrl(cfg.ownCloudUrl())); + connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + _browser->show (); + } +} + +void ShibbolethCredentials::persistForUrl(const QString& url) +{ + // nothing to do here, we don't store session cookies. +} + +void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& cookie) +{ + _browser->hide(); + disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + _browser->deleteLater(); + _browser = 0; + _ready = true; + _shibCookie = cookie; + Q_EMIT fetched(); +} + +} // ns Mirall diff --git a/src/mirall/creds/shibbolethcredentials.h b/src/mirall/creds/shibbolethcredentials.h new file mode 100644 index 000000000..b17c39db2 --- /dev/null +++ b/src/mirall/creds/shibbolethcredentials.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H +#define MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H + +#include + +#include "mirall/creds/abstractcredentials.h" + +namespace Mirall +{ + +class ShibbolethWebView; + +class ShibbolethCredentials : public AbstractCredentials +{ +Q_OBJECT + +public: + ShibbolethCredentials(); + ShibbolethCredentials(const QNetworkCookie& cookie); + + void prepareSyncContext (CSYNC* ctx); + bool changed(AbstractCredentials* credentials) const; + QString authType() const; + QNetworkAccessManager* getQNAM() const; + bool ready() const; + void fetch(); + void persistForUrl(const QString& url); + + QNetworkCookie cookie() const; + +private Q_SLOTS: + void onShibbolethCookieReceived(const QNetworkCookie& cookie); + +private: + QNetworkCookie _shibCookie; + bool _ready; + ShibbolethWebView* _browser; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/shibbolethwebview.cpp b/src/mirall/creds/shibbolethwebview.cpp new file mode 100644 index 000000000..70380aa9e --- /dev/null +++ b/src/mirall/creds/shibbolethwebview.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "mirall/creds/shibbolethcookiejar.h" +#include "mirall/creds/shibbolethwebview.h" + +namespace Mirall +{ + +ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) + : QWebView(parent) +{ + ShibbolethCookieJar* jar = new ShibbolethCookieJar(this); + QWebPage* page = new QWebPage(this); + + connect (jar, SIGNAL (newCookiesForUrl (QList, QUrl)), + this, SLOT (onNewCookiesForUrl (QList, QUrl))); + + page->networkAccessManager()->setCookieJar(jar); + page->mainFrame ()->load (url); + this->setPage (page); +} + +void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& url) +{ + Q_FOREACH (const QNetworkCookie& cookie, cookieList) { + if (cookie.name().startsWith ("_shibsession_")) { + Q_EMIT shibbolethCookieReceived (cookie); + + return; + } + } +} + +} // ns Mirall diff --git a/src/mirall/creds/shibbolethwebview.h b/src/mirall/creds/shibbolethwebview.h new file mode 100644 index 000000000..e36f0981d --- /dev/null +++ b/src/mirall/creds/shibbolethwebview.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H +#define MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H + +#include +#include + +class QNetworkCookie; +class QUrl; + +namespace Mirall +{ + +class ShibbolethWebView : public QWebView +{ + Q_OBJECT + +public: + ShibbolethWebView(const QUrl& url, QWidget* parent = 0); + +Q_SIGNALS: + void shibbolethCookieReceived (const QNetworkCookie& cookie); + +private Q_SLOTS: + void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index ba5b9f5d9..69b43a1b1 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -456,12 +456,6 @@ void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) // FIXME: give a hint about the auto completion _ocWizard->setOCUrl(url); } - // FIXME: Create AbstractUserCreds class and maybe three subclasses: - // DummyCreds (empty), ShibbolethCreds and HttpCreds - // writeOwnCloudConfig could then take AbstractUserCreds instead. - // no user and no password - we are trying to determine whether - // the auth type is the old HTTPS headers one or rather a - // shibboleth one. cfgFile.writeOwncloudConfig( Theme::instance()->appName(), url, new DummyCredentials); diff --git a/src/mirall/owncloudshibbolethcredspage.ui b/src/mirall/owncloudshibbolethcredspage.ui new file mode 100644 index 000000000..832d7eb44 --- /dev/null +++ b/src/mirall/owncloudshibbolethcredspage.ui @@ -0,0 +1,121 @@ + + + OwncloudShibbolethCredsPage + + + + 0 + 0 + 640 + 451 + + + + Form + + + + + + QLayout::SetMaximumSize + + + + + TextLabel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 45 + 17 + + + + + + + + + + + 0 + 0 + + + + Error Label + + + + + + + info label + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + Qt::Vertical + + + + 17 + 38 + + + + + + + + TextLabel + + + + + + + horizontalSpacer + verticalSpacer + horizontalSpacer_2 + topLabel + bottomLabel + errorLabel_2 + + + + diff --git a/src/mirall/wizard/owncloudsetuppage.cpp b/src/mirall/wizard/owncloudsetuppage.cpp index 2a7f6a4a9..41b7d9584 100644 --- a/src/mirall/wizard/owncloudsetuppage.cpp +++ b/src/mirall/wizard/owncloudsetuppage.cpp @@ -238,12 +238,11 @@ void OwncloudSetupPage::slotHandleUserInput() int OwncloudSetupPage::nextId() const { - if (_authType == WizardCommon::HttpCreds) { - return WizardCommon::Page_HttpCreds; - } else { - // TODO: rather display some browser component. maybe different page. - return WizardCommon::Page_Result; - } + if (_authType == WizardCommon::HttpCreds) { + return WizardCommon::Page_HttpCreds; + } else { + return WizardCommon::Page_ShibbolethCreds; + } } QString OwncloudSetupPage::url() const diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.cpp b/src/mirall/wizard/owncloudshibbolethcredspage.cpp new file mode 100644 index 000000000..f519fda15 --- /dev/null +++ b/src/mirall/wizard/owncloudshibbolethcredspage.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/wizard/owncloudshibbolethcredspage.h" +#include "mirall/theme.h" +#include "mirall/wizard/owncloudwizardcommon.h" +#include "mirall/creds/shibbolethcredentials.h" +#include "mirall/creds/shibbolethwebview.h" + +namespace Mirall +{ + +OwncloudShibbolethCredsPage::OwncloudShibbolethCredsPage() + : AbstractCredentialsWizardPage(), + _ui(), + _stage(INITIAL_STEP), + _browser(0), + _cookie() +{ + _ui.setupUi(this); + + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Process through Shibboleth form"))); + + setupCustomization(); +} + +void OwncloudShibbolethCredsPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); +} + +void OwncloudShibbolethCredsPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + _browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified()), this); + + connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + + _ui.contentLayout->insertWidget(0, _browser); + _browser->show(); + _browser->setFocus(); + _ui.infoLabel->show(); + _ui.infoLabel->setText(tr("Please follow the steps on displayed page above")); + _stage = INITIAL_STEP; + _cookie = QNetworkCookie(); +} + +void OwncloudShibbolethCredsPage::disposeBrowser(bool later) +{ + _browser->hide(); + disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + if (later) { + _browser->deleteLater(); + } else { + delete _browser; + } + _browser = 0; +} + +void OwncloudShibbolethCredsPage::cleanupPage() +{ + disposeBrowser(false); +} + +bool OwncloudShibbolethCredsPage::validatePage() +{ + switch (_stage) { + case INITIAL_STEP: + return false; + + case GOT_COOKIE: + _stage = CHECKING; + emit completeChanged(); + emit connectToOCUrl(field("OCUrl").toString().simplified()); + return false; + + case CHECKING: + return false; + + case CONNECTED: + return true; + } + + return false; +} + +int OwncloudShibbolethCredsPage::nextId() const +{ + return WizardCommon::Page_Result; +} + +void OwncloudShibbolethCredsPage::setConnected( bool comp ) +{ + if (comp) { + _stage = CONNECTED; + } else { + // sets stage to INITIAL + initializePage(); + } +} + +void OwncloudShibbolethCredsPage::setErrorString(const QString& err) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + initializePage(); + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + emit completeChanged(); +} + +AbstractCredentials* OwncloudShibbolethCredsPage::getCredentials() const +{ + return new ShibbolethCredentials(_cookie); +} + +void OwncloudShibbolethCredsPage::onShibbolethCookieReceived(const QNetworkCookie& cookie) +{ + disposeBrowser(true); + _stage = GOT_COOKIE; + _cookie = cookie; + _ui.infoLabel->setText("Please click \"Connect\" to check received Shibboleth session."); +} + +} // ns Mirall diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.h b/src/mirall/wizard/owncloudshibbolethcredspage.h new file mode 100644 index 000000000..7f7aaff5b --- /dev/null +++ b/src/mirall/wizard/owncloudshibbolethcredspage.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H +#define MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H + +#include + +#include "mirall/wizard/abstractcredswizardpage.h" + +#include "ui_owncloudshibbolethcredspage.h" + +namespace Mirall { + +class ShibbolethWebView; + +class OwncloudShibbolethCredsPage : public AbstractCredentialsWizardPage +{ + Q_OBJECT +public: + OwncloudShibbolethCredsPage(); + + AbstractCredentials* getCredentials() const; + + void initializePage(); + void cleanupPage(); + bool validatePage(); + int nextId() const; + void setConnected(bool connected); + void setErrorString(const QString& err); + +Q_SIGNALS: + void connectToOCUrl(const QString&); + +private Q_SLOTS: + void onShibbolethCookieReceived(const QNetworkCookie& cookie); + +private: + enum Stage { + INITIAL_STEP, + GOT_COOKIE, + CHECKING, + CONNECTED + }; + + void setupCustomization(); + void disposeBrowser(bool later); + + Ui_OwncloudShibbolethCredsPage _ui; + Stage _stage; + ShibbolethWebView* _browser; + QNetworkCookie _cookie; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/wizard/owncloudwizard.cpp b/src/mirall/wizard/owncloudwizard.cpp index 056d5ba40..883d7728d 100644 --- a/src/mirall/wizard/owncloudwizard.cpp +++ b/src/mirall/wizard/owncloudwizard.cpp @@ -19,6 +19,7 @@ #include "mirall/theme.h" #include "mirall/wizard/owncloudsetuppage.h" #include "mirall/wizard/owncloudhttpcredspage.h" +#include "mirall/wizard/owncloudshibbolethcredspage.h" #include "mirall/wizard/owncloudwizardresultpage.h" #include "QProgressIndicator.h" @@ -35,6 +36,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) : QWizard(parent), _setupPage(new OwncloudSetupPage), _httpCredsPage(new OwncloudHttpCredsPage), + _shibbolethCredsPage(new OwncloudShibbolethCredsPage), _resultPage(new OwncloudWizardResultPage), _credentialsPage(0), _configFile(), @@ -44,6 +46,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) { setPage(WizardCommon::Page_oCSetup, _setupPage ); setPage(WizardCommon::Page_HttpCreds, _httpCredsPage); + setPage(WizardCommon::Page_ShibbolethCreds, _shibbolethCredsPage); setPage(WizardCommon::Page_Result, _resultPage ); // note: start Id is set by the calling class depending on if the @@ -53,7 +56,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int))); connect( _setupPage, SIGNAL(determineAuthType(QString)), SIGNAL(determineAuthType(QString))); connect( _httpCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); - + connect( _shibbolethCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); Theme *theme = Theme::instance(); setWizardStyle(QWizard::ModernStyle); @@ -119,7 +122,7 @@ void OwncloudWizard::setAuthType(WizardCommon::AuthType type) { _setupPage->setAuthType(type); if (type == WizardCommon::Shibboleth) { - _credentialsPage = 0; + _credentialsPage = _shibbolethCredsPage; } else { _credentialsPage = _httpCredsPage; } @@ -144,10 +147,14 @@ void OwncloudWizard::slotCurrentPageChanged( int id ) void OwncloudWizard::displayError( const QString& msg ) { - if (currentId() == WizardCommon::Page_oCSetup) { + int id(currentId()); + + if (id == WizardCommon::Page_oCSetup) { _setupPage->setErrorString( msg ); - } else { + } else if (id == WizardCommon::Page_HttpCreds) { _httpCredsPage->setErrorString(msg); + } else if (id == WizardCommon::Page_ShibbolethCreds) { + _shibbolethCredsPage->setErrorString(msg); } } diff --git a/src/mirall/wizard/owncloudwizard.h b/src/mirall/wizard/owncloudwizard.h index fcfad61d9..03f20d62f 100644 --- a/src/mirall/wizard/owncloudwizard.h +++ b/src/mirall/wizard/owncloudwizard.h @@ -25,6 +25,7 @@ namespace Mirall { class OwncloudSetupPage; class OwncloudHttpCredsPage; +class OwncloudShibbolethCredsPage; class OwncloudWizardResultPage; class AbstractCredentials; class AbstractCredentialsWizardPage; @@ -74,6 +75,7 @@ signals: private: OwncloudSetupPage* _setupPage; OwncloudHttpCredsPage* _httpCredsPage; + OwncloudShibbolethCredsPage* _shibbolethCredsPage; OwncloudWizardResultPage* _resultPage; AbstractCredentialsWizardPage* _credentialsPage; diff --git a/src/mirall/wizard/owncloudwizardcommon.h b/src/mirall/wizard/owncloudwizardcommon.h index d4b0ec21c..8e4ca7fa1 100644 --- a/src/mirall/wizard/owncloudwizardcommon.h +++ b/src/mirall/wizard/owncloudwizardcommon.h @@ -44,6 +44,7 @@ enum SyncMode { enum Pages { Page_oCSetup, Page_HttpCreds, + Page_ShibbolethCreds, Page_Result }; -- cgit v1.2.3 From eacb849353cc9e06125ce4abb85eb9ff653b100e Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 29 Jul 2013 14:44:54 +0200 Subject: Fix credentials handling in csync. CSync module's properties can be set only after it was initialized, so we split the sync context vfunc into two: the one ran before initialization and the one ran before sync beginning. --- src/mirall/creds/abstractcredentials.h | 3 ++- src/mirall/creds/dummycredentials.cpp | 5 ++++- src/mirall/creds/dummycredentials.h | 3 ++- src/mirall/creds/httpcredentials.cpp | 8 ++++++-- src/mirall/creds/httpcredentials.h | 3 ++- src/mirall/creds/shibbolethcredentials.cpp | 5 ++++- src/mirall/creds/shibbolethcredentials.h | 3 ++- src/mirall/csyncthread.cpp | 5 +++-- src/mirall/folder.cpp | 5 +---- 9 files changed, 26 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/mirall/creds/abstractcredentials.h b/src/mirall/creds/abstractcredentials.h index a61e7a324..0c04adc92 100644 --- a/src/mirall/creds/abstractcredentials.h +++ b/src/mirall/creds/abstractcredentials.h @@ -32,7 +32,8 @@ class AbstractCredentials : public QObject public: // No need for virtual destructor - QObject already has one. - virtual void prepareSyncContext(CSYNC* ctx) = 0; + virtual void syncContextPreInit(CSYNC* ctx) = 0; + virtual void syncContextPreStart(CSYNC* ctx) = 0; virtual bool changed(AbstractCredentials* credentials) const = 0; virtual QString authType() const = 0; virtual QNetworkAccessManager* getQNAM() const = 0; diff --git a/src/mirall/creds/dummycredentials.cpp b/src/mirall/creds/dummycredentials.cpp index 1747a6041..58ff429d0 100644 --- a/src/mirall/creds/dummycredentials.cpp +++ b/src/mirall/creds/dummycredentials.cpp @@ -21,7 +21,10 @@ namespace Mirall { -void DummyCredentials::prepareSyncContext(CSYNC*) +void DummyCredentials::syncContextPreInit(CSYNC*) +{} + +void DummyCredentials::syncContextPreStart(CSYNC*) {} bool DummyCredentials::changed(AbstractCredentials* credentials) const diff --git a/src/mirall/creds/dummycredentials.h b/src/mirall/creds/dummycredentials.h index 16f7af2c9..af178922f 100644 --- a/src/mirall/creds/dummycredentials.h +++ b/src/mirall/creds/dummycredentials.h @@ -27,7 +27,8 @@ class DummyCredentials : public AbstractCredentials Q_OBJECT public: - void prepareSyncContext(CSYNC* ctx); + void syncContextPreInit(CSYNC* ctx); + void syncContextPreStart(CSYNC* ctx); bool changed(AbstractCredentials* credentials) const; QString authType() const; QNetworkAccessManager* getQNAM() const; diff --git a/src/mirall/creds/httpcredentials.cpp b/src/mirall/creds/httpcredentials.cpp index 939210b28..308042c9d 100644 --- a/src/mirall/creds/httpcredentials.cpp +++ b/src/mirall/creds/httpcredentials.cpp @@ -113,7 +113,12 @@ HttpCredentials::HttpCredentials(const QString& user, const QString& password) _ready(true) {} -void HttpCredentials::prepareSyncContext (CSYNC* ctx) +void HttpCredentials::syncContextPreInit (CSYNC* ctx) +{ + csync_set_auth_callback (ctx, getauth); +} + +void HttpCredentials::syncContextPreStart (CSYNC* ctx) { // TODO: This should not be a part of this method, but we don't have // any way to get "session_key" module property from csync. Had we @@ -132,7 +137,6 @@ void HttpCredentials::prepareSyncContext (CSYNC* ctx) } csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); - csync_set_auth_callback (ctx, getauth); } bool HttpCredentials::changed(AbstractCredentials* credentials) const diff --git a/src/mirall/creds/httpcredentials.h b/src/mirall/creds/httpcredentials.h index 7c044bea9..f1c74e02b 100644 --- a/src/mirall/creds/httpcredentials.h +++ b/src/mirall/creds/httpcredentials.h @@ -35,7 +35,8 @@ public: HttpCredentials(); HttpCredentials(const QString& user, const QString& password); - void prepareSyncContext (CSYNC* ctx); + void syncContextPreInit(CSYNC* ctx); + void syncContextPreStart(CSYNC* ctx); bool changed(AbstractCredentials* credentials) const; QString authType() const; QNetworkAccessManager* getQNAM() const; diff --git a/src/mirall/creds/shibbolethcredentials.cpp b/src/mirall/creds/shibbolethcredentials.cpp index 87796727e..f32e9cb1e 100644 --- a/src/mirall/creds/shibbolethcredentials.cpp +++ b/src/mirall/creds/shibbolethcredentials.cpp @@ -35,7 +35,10 @@ ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie) _browser(0) {} -void ShibbolethCredentials::prepareSyncContext (CSYNC* ctx) +void ShibbolethCredentials::syncContextPreInit (CSYNC*) +{} + +void ShibbolethCredentials::syncContextPreStart (CSYNC* ctx) { QString cookiesAsString; // TODO: This should not be a part of this method, but we don't diff --git a/src/mirall/creds/shibbolethcredentials.h b/src/mirall/creds/shibbolethcredentials.h index b17c39db2..79baa3aac 100644 --- a/src/mirall/creds/shibbolethcredentials.h +++ b/src/mirall/creds/shibbolethcredentials.h @@ -34,7 +34,8 @@ public: ShibbolethCredentials(); ShibbolethCredentials(const QNetworkCookie& cookie); - void prepareSyncContext (CSYNC* ctx); + void syncContextPreInit(CSYNC* ctx); + void syncContextPreStart(CSYNC* ctx); bool changed(AbstractCredentials* credentials) const; QString authType() const; QNetworkAccessManager* getQNAM() const; diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 7576b9d27..2f91f4bb9 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -18,6 +18,7 @@ #include "mirall/theme.h" #include "mirall/logger.h" #include "mirall/owncloudinfo.h" +#include "mirall/creds/abstractcredentials.h" #ifdef Q_OS_WIN #include @@ -342,9 +343,9 @@ void CSyncThread::startSync() // any way to get "session_key" module property from csync. Had we // have it, then we could keep this code and remove it from // AbstractCredentials implementations. - + cfg.getCredentials()->syncContextPreStart(_csync_ctx); // if (_lastAuthCookies.length() > 0) { - // // Stuff cookies inside csync, then we can avoid the intermediate HTTP + // // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply // // when https://github.com/owncloud/core/pull/4042 is merged. // QString cookiesAsString; // foreach(QNetworkCookie c, _lastAuthCookies) { diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index c28874aa4..b8baaad81 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -120,10 +120,7 @@ bool Folder::init() csync_enable_conflictcopys(_csync_ctx); setIgnoredFiles(); - AbstractCredentials* credentials(cfgFile.getCredentials()); - if (credentials) { - credentials->prepareSyncContext (_csync_ctx); - } + cfgFile.getCredentials()->syncContextPreInit(_csync_ctx); if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_error(_csync_ctx) << csync_get_error_string(_csync_ctx); -- cgit v1.2.3 From 7f6dc291c097398d2bebe6d4f7159adb6ed93a8f Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 29 Jul 2013 14:46:11 +0200 Subject: Create HTTP credentials object for config without type value. --- src/mirall/creds/credentialsfactory.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mirall/creds/credentialsfactory.cpp b/src/mirall/creds/credentialsfactory.cpp index 1a1bd65e1..ebade2466 100644 --- a/src/mirall/creds/credentialsfactory.cpp +++ b/src/mirall/creds/credentialsfactory.cpp @@ -28,7 +28,8 @@ namespace CredentialsFactory AbstractCredentials* create(const QString& type) { - if (type == "http") { + // empty string might happen for old version of configuration + if (type == "http" || type == "") { return new HttpCredentials; } else if (type == "dummy") { return new DummyCredentials; -- cgit v1.2.3 From 52b3f7105d4daea7801bf9b98c733804a5e3bdba Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 29 Jul 2013 14:46:53 +0200 Subject: Remove unused stuff. --- src/mirall/mirallconfigfile.cpp | 2 +- src/mirall/owncloudinfo.cpp | 18 ------------------ src/mirall/owncloudinfo.h | 14 -------------- 3 files changed, 1 insertion(+), 33 deletions(-) (limited to 'src') diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index c62ad272b..3617ff744 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -613,7 +613,7 @@ void MirallConfigFile::setMonoIcons(bool useMonoIcons) AbstractCredentials* MirallConfigFile::getCredentials() const { - return credentialsPerConfig[_customHandle].data(); + return credentialsPerConfig[_customHandle].data(); } } diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index daca4c8eb..5d6aaac5e 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -516,24 +516,6 @@ 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 ) { diff --git a/src/mirall/owncloudinfo.h b/src/mirall/owncloudinfo.h index 901a17799..a9d467e70 100644 --- a/src/mirall/owncloudinfo.h +++ b/src/mirall/owncloudinfo.h @@ -21,12 +21,6 @@ namespace Mirall { -typedef struct { - QString user; - QString passwd; - QString connection; -} oCICredentials; - class ownCloudInfo : public QObject { Q_OBJECT @@ -101,13 +95,6 @@ public: */ QList certificateChain() const; - /** - * Store credentials for a given connection. Empty connection parameter - * means "default connection". - */ - void setCredentials( const QString&, const QString&, - const QString& configHandle = QString::null ); - /** * returns the owncloud webdav url. * It may be different from the one in the config if there was a HTTP redirection @@ -163,7 +150,6 @@ private: QList _certificateChain; bool _certsUntrusted; int _authAttempts; - QMap _credentials; QMutex _certChainMutex; int _redirectCount; qint64 _lastQuotaUsedBytes; -- cgit v1.2.3 From d5885daf0fc66342c6a586ace28c48b487baf0d7 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 29 Jul 2013 14:58:09 +0200 Subject: Move credential related files to creds directory. CredentialStore is now only used for HTTP credentials, so it was moved into http directory under creds. --- src/CMakeLists.txt | 20 +- src/mirall/accountsettings.cpp | 4 +- src/mirall/application.cpp | 1 - src/mirall/connectionvalidator.cpp | 1 - src/mirall/credentialstore.cpp | 338 --------------------- src/mirall/credentialstore.h | 132 -------- src/mirall/creds/http/credentialstore.cpp | 338 +++++++++++++++++++++ src/mirall/creds/http/credentialstore.h | 132 ++++++++ src/mirall/creds/http/httpconfigfile.cpp | 84 +++++ src/mirall/creds/http/httpconfigfile.h | 43 +++ src/mirall/creds/httpconfigfile.cpp | 84 ----- src/mirall/creds/httpconfigfile.h | 43 --- src/mirall/creds/httpcredentials.cpp | 2 +- .../creds/shibboleth/shibbolethaccessmanager.cpp | 38 +++ .../creds/shibboleth/shibbolethaccessmanager.h | 40 +++ .../creds/shibboleth/shibbolethcookiejar.cpp | 35 +++ src/mirall/creds/shibboleth/shibbolethcookiejar.h | 42 +++ src/mirall/creds/shibboleth/shibbolethwebview.cpp | 50 +++ src/mirall/creds/shibboleth/shibbolethwebview.h | 43 +++ src/mirall/creds/shibbolethaccessmanager.cpp | 38 --- src/mirall/creds/shibbolethaccessmanager.h | 40 --- src/mirall/creds/shibbolethcookiejar.cpp | 35 --- src/mirall/creds/shibbolethcookiejar.h | 42 --- src/mirall/creds/shibbolethcredentials.cpp | 4 +- src/mirall/creds/shibbolethwebview.cpp | 50 --- src/mirall/creds/shibbolethwebview.h | 43 --- src/mirall/mirallconfigfile.cpp | 1 - src/mirall/owncloudsetupwizard.cpp | 1 - src/mirall/wizard/owncloudshibbolethcredspage.cpp | 2 +- 29 files changed, 860 insertions(+), 866 deletions(-) delete mode 100644 src/mirall/credentialstore.cpp delete mode 100644 src/mirall/credentialstore.h create mode 100644 src/mirall/creds/http/credentialstore.cpp create mode 100644 src/mirall/creds/http/credentialstore.h create mode 100644 src/mirall/creds/http/httpconfigfile.cpp create mode 100644 src/mirall/creds/http/httpconfigfile.h delete mode 100644 src/mirall/creds/httpconfigfile.cpp delete mode 100644 src/mirall/creds/httpconfigfile.h create mode 100644 src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp create mode 100644 src/mirall/creds/shibboleth/shibbolethaccessmanager.h create mode 100644 src/mirall/creds/shibboleth/shibbolethcookiejar.cpp create mode 100644 src/mirall/creds/shibboleth/shibbolethcookiejar.h create mode 100644 src/mirall/creds/shibboleth/shibbolethwebview.cpp create mode 100644 src/mirall/creds/shibboleth/shibbolethwebview.h delete mode 100644 src/mirall/creds/shibbolethaccessmanager.cpp delete mode 100644 src/mirall/creds/shibbolethaccessmanager.h delete mode 100644 src/mirall/creds/shibbolethcookiejar.cpp delete mode 100644 src/mirall/creds/shibbolethcookiejar.h delete mode 100644 src/mirall/creds/shibbolethwebview.cpp delete mode 100644 src/mirall/creds/shibbolethwebview.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a4340ef45..cc0d8ae52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,7 +69,6 @@ set(libsync_SRCS mirall/syncresult.cpp mirall/networklocation.cpp mirall/mirallconfigfile.cpp - mirall/credentialstore.cpp mirall/csyncthread.cpp mirall/fileutils.cpp mirall/theme.cpp @@ -82,11 +81,12 @@ set(libsync_SRCS mirall/creds/dummycredentials.cpp mirall/creds/httpcredentials.cpp mirall/creds/credentialsfactory.cpp - mirall/creds/httpconfigfile.cpp + mirall/creds/http/credentialstore.cpp + mirall/creds/http/httpconfigfile.cpp mirall/creds/shibbolethcredentials.cpp - mirall/creds/shibbolethaccessmanager.cpp - mirall/creds/shibbolethcookiejar.cpp - mirall/creds/shibbolethwebview.cpp + mirall/creds/shibboleth/shibbolethaccessmanager.cpp + mirall/creds/shibboleth/shibbolethcookiejar.cpp + mirall/creds/shibboleth/shibbolethwebview.cpp ) set(libsync_HEADERS @@ -97,7 +97,6 @@ set(libsync_HEADERS mirall/theme.h mirall/owncloudtheme.h mirall/owncloudinfo.h - mirall/credentialstore.h mirall/logger.h mirall/connectionvalidator.h mirall/progressdispatcher.h @@ -105,11 +104,12 @@ set(libsync_HEADERS mirall/creds/dummycredentials.h mirall/creds/httpcredentials.h mirall/creds/credentialsfactory.h - mirall/creds/httpconfigfile.h + mirall/creds/http/credentialstore.h + mirall/creds/http/httpconfigfile.h mirall/creds/shibbolethcredentials.h - mirall/creds/shibbolethaccessmanager.h - mirall/creds/shibbolethcookiejar.h - mirall/creds/shibbolethwebview.h + mirall/creds/shibboleth/shibbolethaccessmanager.h + mirall/creds/shibboleth/shibbolethcookiejar.h + mirall/creds/shibboleth/shibbolethwebview.h ) IF( INOTIFY_FOUND ) diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index c08194e47..29f4fbc73 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -18,7 +18,6 @@ #include "mirall/theme.h" #include "mirall/folderman.h" #include "mirall/owncloudinfo.h" -#include "mirall/credentialstore.h" #include "mirall/folderwizard.h" #include "mirall/folderstatusmodel.h" #include "mirall/utility.h" @@ -416,8 +415,7 @@ void AccountSettings::slotOCInfo( const QString& url, const QString& versionStr, qDebug() << "#-------# oC found on " << url; /* enable the open button */ ui->connectLabel->setOpenExternalLinks(true); - ui->connectLabel->setText( tr("Connected to %1 as %2.") - .arg(url).arg( CredentialStore::instance()->user()) ); + ui->connectLabel->setText( tr("Connected to %1.") ); ui->connectLabel->setToolTip( tr("Version: %1 (%2)").arg(versionStr).arg(version)); ui->_ButtonAdd->setEnabled(true); diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index bef9adc3f..11e487403 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -30,7 +30,6 @@ #include "mirall/theme.h" #include "mirall/mirallconfigfile.h" #include "mirall/updatedetector.h" -#include "mirall/credentialstore.h" #include "mirall/logger.h" #include "mirall/settingsdialog.h" #include "mirall/utility.h" diff --git a/src/mirall/connectionvalidator.cpp b/src/mirall/connectionvalidator.cpp index b9de32662..e89c4b495 100644 --- a/src/mirall/connectionvalidator.cpp +++ b/src/mirall/connectionvalidator.cpp @@ -17,7 +17,6 @@ #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" #include "mirall/theme.h" -#include "mirall/credentialstore.h" namespace Mirall { diff --git a/src/mirall/credentialstore.cpp b/src/mirall/credentialstore.cpp deleted file mode 100644 index 4bd316282..000000000 --- a/src/mirall/credentialstore.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (C) by Klaas Freitag - * - * 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 -#include - -#include "config.h" - -#include "mirall/credentialstore.h" -#include "mirall/creds/httpconfigfile.h" -#include "mirall/theme.h" - -#ifdef WITH_QTKEYCHAIN -#include -using namespace QKeychain; -#endif - -#define MAX_LOGIN_ATTEMPTS 3 - -namespace Mirall { - -CredentialStore *CredentialStore::_instance=0; -CredentialStore::CredState CredentialStore::_state = NotFetched; -QString CredentialStore::_passwd = QString::null; -QString CredentialStore::_user = QString::null; -QString CredentialStore::_url = QString::null; -QString CredentialStore::_errorMsg = QString::null; -#ifdef WITH_QTKEYCHAIN -CredentialStore::CredentialType CredentialStore::_type = KeyChain; -#else -CredentialStore::CredentialType CredentialStore::_type = Settings; -#endif - -CredentialStore::CredentialStore(QObject *parent) : - QObject(parent) -{ -} - -CredentialStore *CredentialStore::instance() -{ - if( !CredentialStore::_instance ) CredentialStore::_instance = new CredentialStore; - return CredentialStore::_instance; -} - -QString CredentialStore::password() const -{ - return _passwd; -} -QString CredentialStore::user() const -{ - return _user; -} - -CredentialStore::CredState CredentialStore::state() -{ - return _state; -} - -void CredentialStore::fetchCredentials() -{ - HttpConfigFile cfgFile; - - bool ok = false; - QString pwd; - _user = cfgFile.user(); - _url = cfgFile.ownCloudUrl(); - - QString key = keyChainKey(_url); - - if( key.isNull() ) { - qDebug() << "Can not fetch credentials, url is zero!"; - _state = Error; - emit( fetchCredentialsFinished(false) ); - return; - } - - switch( _type ) { - case CredentialStore::Settings: { - /* Read from config file. */ - _state = Fetching; - cfgFile.fixupOldPassword(); - if( cfgFile.passwordExists() ) { - pwd = cfgFile.password(); - ok = true; - } else { - ok = false; - _state = EntryNotFound; - } - break; - } - case CredentialStore::KeyChain: { - // If the credentials are here already, return. - if( _state == Ok || _state == AsyncWriting ) { - emit(fetchCredentialsFinished(true)); - return; - } - // otherwise fetch asynchronious. -#ifdef WITH_QTKEYCHAIN - _state = AsyncFetching; - if( !_user.isEmpty() ) { - ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName()); - job->setKey( key ); - - connect( job, SIGNAL(finished(QKeychain::Job*)), this, - SLOT(slotKeyChainReadFinished(QKeychain::Job*))); - job->start(); - } -#else - qDebug() << "QtKeyChain: Not yet implemented!"; - _state = Error; -#endif - break; - } - default: { - break; - } - } - - if( _state == Fetching ) { // ...but not AsyncFetching - if( ok ) { - _passwd = pwd; - _state = Ok; - } - if( !ok && _state == Fetching ) { - _state = Error; - } - - emit( fetchCredentialsFinished(ok) ); - } else { - // in case of AsyncFetching nothing happens here. The finished-Slot - // will emit the finish signal. - } -} - -void CredentialStore::reset() -{ - _state = NotFetched; - _user = QString::null; - _passwd = QString::null; -} - -QString CredentialStore::keyChainKey( const QString& url ) const -{ - QString u(url); - if( u.isEmpty() ) { - qDebug() << "Empty url in keyChain, error!"; - return QString::null; - } - if( _user.isEmpty() ) { - qDebug() << "Error: User is emty!"; - return QString::null; - } - - if( !u.endsWith(QChar('/')) ) { - u.append(QChar('/')); - } - - QString key = _user+QLatin1Char(':')+u; - return key; -} - -void CredentialStore::slotKeyChainReadFinished(QKeychain::Job* job) -{ -#ifdef WITH_QTKEYCHAIN - ReadPasswordJob *pwdJob = static_cast(job); - if( pwdJob ) { - switch( pwdJob->error() ) { - case QKeychain::NoError: - _passwd = pwdJob->textData(); -#ifdef Q_OS_LINUX - // Currently there is a bug in the keychain on linux that if no - // entry is there, an empty password comes back, but no error. - if( _passwd.isEmpty() ) { - _state = EntryNotFound; - _errorMsg = tr("No password entry found in keychain. Please reconfigure."); - } else -#endif - _state = Ok; - break; - case QKeychain::EntryNotFound: - _state = EntryNotFound; - break; - case QKeychain::CouldNotDeleteEntry: - _state = Error; - break; - case QKeychain::AccessDenied: - _state = AccessDenied; - break; - case QKeychain::NoBackendAvailable: - _state = NoKeychainBackend; - break; - case QKeychain::NotImplemented: - _state = NoKeychainBackend; - break; - case QKeychain::OtherError: - default: - _state = Error; - - } - /* In case there is no backend, tranparentely switch to Settings file. */ - if( _state == NoKeychainBackend ) { - qDebug() << "No Storage Backend, falling back to Settings mode."; - _type = CredentialStore::Settings; - fetchCredentials(_user); - return; - } - - if( _state == EntryNotFound ) { - // try to migrate. - } - - if( _state != Ok ) { - qDebug() << "Error with keychain: " << pwdJob->errorString(); - if(_errorMsg.isEmpty()) _errorMsg = pwdJob->errorString(); - } else { - _errorMsg = QString::null; - } - } else { - _state = Error; - qDebug() << "Error: KeyChain Read Password Job failed!"; - } - emit(fetchCredentialsFinished(_state == Ok)); -#else - (void) job; -#endif -} - -QString CredentialStore::errorMessage() -{ - return _errorMsg; -} - -void CredentialStore::setCredentials( const QString& url, const QString& user, - const QString& pwd ) -{ - _passwd = pwd; - _user = user; -#ifdef WITH_QTKEYCHAIN - _type = KeyChain; -#else - _type = Settings; -#endif - _url = url; - _state = Ok; -} - -void CredentialStore::saveCredentials( ) -{ - HttpConfigFile cfgFile; - QString key = keyChainKey(_url); - if( key.isNull() ) { - qDebug() << "Error: Can not save credentials, URL is zero!"; - return; - } -#ifdef WITH_QTKEYCHAIN -#endif - - cfgFile.setUser(_user); - switch( _type ) { - case CredentialStore::KeyChain: { -#ifdef WITH_QTKEYCHAIN - WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName()); - // Set password in KeyChain - job->setKey( key ); - job->setTextData(_passwd); - - connect( job, SIGNAL(finished(QKeychain::Job*)), this, - SLOT(slotKeyChainWriteFinished(QKeychain::Job*))); - _state = AsyncWriting; - job->start(); -#endif - } - break; - case CredentialStore::Settings: - cfgFile.setPassword( _passwd ); - reset(); - break; - default: - // unsupported. - break; - } -} - -void CredentialStore::slotKeyChainWriteFinished( QKeychain::Job *job ) -{ -#ifdef WITH_QTKEYCHAIN - WritePasswordJob *pwdJob = static_cast(job); - if( pwdJob ) { - QKeychain::Error err = pwdJob->error(); - - if( err != QKeychain::NoError ) { - qDebug() << "Error with keychain: " << pwdJob->errorString(); - if( err == NoBackendAvailable || err == NotImplemented || - pwdJob->errorString().contains(QLatin1String("Could not open wallet"))) { - _state = NoKeychainBackend; - _type = Settings; - saveCredentials(); - } else { - _state = Error; - } - } else { - qDebug() << "Successfully stored password for user " << _user; - // Try to remove password formerly stored in the config file. - HttpConfigFile cfgFile; - cfgFile.removePassword(); - _state = NotFetched; - } - } else { - qDebug() << "Error: KeyChain Write Password Job failed!"; - _state = Error; - } -#else - (void) job; -#endif -} - -// Called if a user chooses to not store the password locally. -void CredentialStore::deleteKeyChainCredential( const QString& key ) -{ -#ifdef WITH_QTKEYCHAIN - // Start the remove job, do not care so much about the result. - DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName()); - job->setKey( key ); - job->start(); -#endif -} - -} diff --git a/src/mirall/credentialstore.h b/src/mirall/credentialstore.h deleted file mode 100644 index 2732e603c..000000000 --- a/src/mirall/credentialstore.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) by Klaas Freitag - * - * 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 CREDENTIALSTORE_H -#define CREDENTIALSTORE_H - -#include -#include - -namespace QKeychain { - class Job; -} - -namespace Mirall { - -/* - * This object holds the credential information of the ownCloud connection. It - * is implemented as a singleton. - * At startup of the client, at first the fetchCredentials() method must be called - * which tries to get credentials from one of the supported backends. To determine - * which backend should be used, MirallConfigFile::credentialType() is called as - * the backend is configured in the config file. - * - * The fetchCredentials() call changes the internal state of the credential store - * to one of - * Ok: There are credentials. Note that it's unknown if they are correct!! - * Fetching: The fetching is not yet finished. - * EntryNotFound: No password entry found in the storage. - * Error: A general error happened. - * After fetching has finished, signal fetchCredentialsFinished(bool) is emitted. - * The result can be retrieved with state() and password() and user() methods. - */ - -class CredentialStore : public QObject -{ - Q_OBJECT -public: - enum CredState { NotFetched = 0, - Ok, - Fetching, - AsyncFetching, - EntryNotFound, - AccessDenied, - NoKeychainBackend, - Error, - AsyncWriting }; - - enum CredentialType { - Settings = 0, - KeyChain - }; - - QString password( ) const; - QString user( ) const; - - /** - * @brief state - * @return the state of the Credentialstore. - */ - CredState state(); - - /** - * @brief fetchCredentials - start to retrieve user credentials. - * - * This method must be called first to retrieve the credentials. - * At the end, this method emits the fetchKeyChainFinished() signal. - */ - void fetchCredentials(); - - /** - * @brief instance - singleton pointer. - * @return the singleton pointer to access the object. - */ - static CredentialStore *instance(); - - /** - * @brief setCredentials - sets the user credentials. - * - * This function is called from the setup wizard to set the credentials - * int this store. Note that it does not store the password. - * The function also sets the state to ok. - * @param url - the connection url - * @param user - the user name - */ - void setCredentials( const QString& url, const QString& user, const QString& pwd); - - void saveCredentials( ); - - QString errorMessage(); - - void reset(); -signals: - /** - * @brief fetchCredentialsFinished - * - * emitted as soon as the fetching of the credentials has finished. - * If the parameter is true, there is a password and user. This does - * however, not say if the credentials are valid log in data. - * If false, the user pressed cancel. - */ - void fetchCredentialsFinished(bool); - -protected slots: - void slotKeyChainReadFinished( QKeychain::Job* ); - void slotKeyChainWriteFinished( QKeychain::Job* ); - -private: - explicit CredentialStore(QObject *parent = 0); - void deleteKeyChainCredential( const QString& ); - QString keyChainKey( const QString& ) const; - - static CredentialStore *_instance; - static CredState _state; - static QString _passwd; - static QString _user; - static QString _url; - static QString _errorMsg; - static CredentialType _type; -}; -} - -#endif // CREDENTIALSTORE_H diff --git a/src/mirall/creds/http/credentialstore.cpp b/src/mirall/creds/http/credentialstore.cpp new file mode 100644 index 000000000..e8387ab3d --- /dev/null +++ b/src/mirall/creds/http/credentialstore.cpp @@ -0,0 +1,338 @@ +/* + * Copyright (C) by Klaas Freitag + * + * 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 +#include + +#include "config.h" + +#include "mirall/creds/http/credentialstore.h" +#include "mirall/creds/http/httpconfigfile.h" +#include "mirall/theme.h" + +#ifdef WITH_QTKEYCHAIN +#include +using namespace QKeychain; +#endif + +#define MAX_LOGIN_ATTEMPTS 3 + +namespace Mirall { + +CredentialStore *CredentialStore::_instance=0; +CredentialStore::CredState CredentialStore::_state = NotFetched; +QString CredentialStore::_passwd = QString::null; +QString CredentialStore::_user = QString::null; +QString CredentialStore::_url = QString::null; +QString CredentialStore::_errorMsg = QString::null; +#ifdef WITH_QTKEYCHAIN +CredentialStore::CredentialType CredentialStore::_type = KeyChain; +#else +CredentialStore::CredentialType CredentialStore::_type = Settings; +#endif + +CredentialStore::CredentialStore(QObject *parent) : + QObject(parent) +{ +} + +CredentialStore *CredentialStore::instance() +{ + if( !CredentialStore::_instance ) CredentialStore::_instance = new CredentialStore; + return CredentialStore::_instance; +} + +QString CredentialStore::password() const +{ + return _passwd; +} +QString CredentialStore::user() const +{ + return _user; +} + +CredentialStore::CredState CredentialStore::state() +{ + return _state; +} + +void CredentialStore::fetchCredentials() +{ + HttpConfigFile cfgFile; + + bool ok = false; + QString pwd; + _user = cfgFile.user(); + _url = cfgFile.ownCloudUrl(); + + QString key = keyChainKey(_url); + + if( key.isNull() ) { + qDebug() << "Can not fetch credentials, url is zero!"; + _state = Error; + emit( fetchCredentialsFinished(false) ); + return; + } + + switch( _type ) { + case CredentialStore::Settings: { + /* Read from config file. */ + _state = Fetching; + cfgFile.fixupOldPassword(); + if( cfgFile.passwordExists() ) { + pwd = cfgFile.password(); + ok = true; + } else { + ok = false; + _state = EntryNotFound; + } + break; + } + case CredentialStore::KeyChain: { + // If the credentials are here already, return. + if( _state == Ok || _state == AsyncWriting ) { + emit(fetchCredentialsFinished(true)); + return; + } + // otherwise fetch asynchronious. +#ifdef WITH_QTKEYCHAIN + _state = AsyncFetching; + if( !_user.isEmpty() ) { + ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName()); + job->setKey( key ); + + connect( job, SIGNAL(finished(QKeychain::Job*)), this, + SLOT(slotKeyChainReadFinished(QKeychain::Job*))); + job->start(); + } +#else + qDebug() << "QtKeyChain: Not yet implemented!"; + _state = Error; +#endif + break; + } + default: { + break; + } + } + + if( _state == Fetching ) { // ...but not AsyncFetching + if( ok ) { + _passwd = pwd; + _state = Ok; + } + if( !ok && _state == Fetching ) { + _state = Error; + } + + emit( fetchCredentialsFinished(ok) ); + } else { + // in case of AsyncFetching nothing happens here. The finished-Slot + // will emit the finish signal. + } +} + +void CredentialStore::reset() +{ + _state = NotFetched; + _user = QString::null; + _passwd = QString::null; +} + +QString CredentialStore::keyChainKey( const QString& url ) const +{ + QString u(url); + if( u.isEmpty() ) { + qDebug() << "Empty url in keyChain, error!"; + return QString::null; + } + if( _user.isEmpty() ) { + qDebug() << "Error: User is emty!"; + return QString::null; + } + + if( !u.endsWith(QChar('/')) ) { + u.append(QChar('/')); + } + + QString key = _user+QLatin1Char(':')+u; + return key; +} + +void CredentialStore::slotKeyChainReadFinished(QKeychain::Job* job) +{ +#ifdef WITH_QTKEYCHAIN + ReadPasswordJob *pwdJob = static_cast(job); + if( pwdJob ) { + switch( pwdJob->error() ) { + case QKeychain::NoError: + _passwd = pwdJob->textData(); +#ifdef Q_OS_LINUX + // Currently there is a bug in the keychain on linux that if no + // entry is there, an empty password comes back, but no error. + if( _passwd.isEmpty() ) { + _state = EntryNotFound; + _errorMsg = tr("No password entry found in keychain. Please reconfigure."); + } else +#endif + _state = Ok; + break; + case QKeychain::EntryNotFound: + _state = EntryNotFound; + break; + case QKeychain::CouldNotDeleteEntry: + _state = Error; + break; + case QKeychain::AccessDenied: + _state = AccessDenied; + break; + case QKeychain::NoBackendAvailable: + _state = NoKeychainBackend; + break; + case QKeychain::NotImplemented: + _state = NoKeychainBackend; + break; + case QKeychain::OtherError: + default: + _state = Error; + + } + /* In case there is no backend, tranparentely switch to Settings file. */ + if( _state == NoKeychainBackend ) { + qDebug() << "No Storage Backend, falling back to Settings mode."; + _type = CredentialStore::Settings; + fetchCredentials(_user); + return; + } + + if( _state == EntryNotFound ) { + // try to migrate. + } + + if( _state != Ok ) { + qDebug() << "Error with keychain: " << pwdJob->errorString(); + if(_errorMsg.isEmpty()) _errorMsg = pwdJob->errorString(); + } else { + _errorMsg = QString::null; + } + } else { + _state = Error; + qDebug() << "Error: KeyChain Read Password Job failed!"; + } + emit(fetchCredentialsFinished(_state == Ok)); +#else + (void) job; +#endif +} + +QString CredentialStore::errorMessage() +{ + return _errorMsg; +} + +void CredentialStore::setCredentials( const QString& url, const QString& user, + const QString& pwd ) +{ + _passwd = pwd; + _user = user; +#ifdef WITH_QTKEYCHAIN + _type = KeyChain; +#else + _type = Settings; +#endif + _url = url; + _state = Ok; +} + +void CredentialStore::saveCredentials( ) +{ + HttpConfigFile cfgFile; + QString key = keyChainKey(_url); + if( key.isNull() ) { + qDebug() << "Error: Can not save credentials, URL is zero!"; + return; + } +#ifdef WITH_QTKEYCHAIN +#endif + + cfgFile.setUser(_user); + switch( _type ) { + case CredentialStore::KeyChain: { +#ifdef WITH_QTKEYCHAIN + WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName()); + // Set password in KeyChain + job->setKey( key ); + job->setTextData(_passwd); + + connect( job, SIGNAL(finished(QKeychain::Job*)), this, + SLOT(slotKeyChainWriteFinished(QKeychain::Job*))); + _state = AsyncWriting; + job->start(); +#endif + } + break; + case CredentialStore::Settings: + cfgFile.setPassword( _passwd ); + reset(); + break; + default: + // unsupported. + break; + } +} + +void CredentialStore::slotKeyChainWriteFinished( QKeychain::Job *job ) +{ +#ifdef WITH_QTKEYCHAIN + WritePasswordJob *pwdJob = static_cast(job); + if( pwdJob ) { + QKeychain::Error err = pwdJob->error(); + + if( err != QKeychain::NoError ) { + qDebug() << "Error with keychain: " << pwdJob->errorString(); + if( err == NoBackendAvailable || err == NotImplemented || + pwdJob->errorString().contains(QLatin1String("Could not open wallet"))) { + _state = NoKeychainBackend; + _type = Settings; + saveCredentials(); + } else { + _state = Error; + } + } else { + qDebug() << "Successfully stored password for user " << _user; + // Try to remove password formerly stored in the config file. + HttpConfigFile cfgFile; + cfgFile.removePassword(); + _state = NotFetched; + } + } else { + qDebug() << "Error: KeyChain Write Password Job failed!"; + _state = Error; + } +#else + (void) job; +#endif +} + +// Called if a user chooses to not store the password locally. +void CredentialStore::deleteKeyChainCredential( const QString& key ) +{ +#ifdef WITH_QTKEYCHAIN + // Start the remove job, do not care so much about the result. + DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName()); + job->setKey( key ); + job->start(); +#endif +} + +} diff --git a/src/mirall/creds/http/credentialstore.h b/src/mirall/creds/http/credentialstore.h new file mode 100644 index 000000000..2732e603c --- /dev/null +++ b/src/mirall/creds/http/credentialstore.h @@ -0,0 +1,132 @@ +/* + * Copyright (C) by Klaas Freitag + * + * 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 CREDENTIALSTORE_H +#define CREDENTIALSTORE_H + +#include +#include + +namespace QKeychain { + class Job; +} + +namespace Mirall { + +/* + * This object holds the credential information of the ownCloud connection. It + * is implemented as a singleton. + * At startup of the client, at first the fetchCredentials() method must be called + * which tries to get credentials from one of the supported backends. To determine + * which backend should be used, MirallConfigFile::credentialType() is called as + * the backend is configured in the config file. + * + * The fetchCredentials() call changes the internal state of the credential store + * to one of + * Ok: There are credentials. Note that it's unknown if they are correct!! + * Fetching: The fetching is not yet finished. + * EntryNotFound: No password entry found in the storage. + * Error: A general error happened. + * After fetching has finished, signal fetchCredentialsFinished(bool) is emitted. + * The result can be retrieved with state() and password() and user() methods. + */ + +class CredentialStore : public QObject +{ + Q_OBJECT +public: + enum CredState { NotFetched = 0, + Ok, + Fetching, + AsyncFetching, + EntryNotFound, + AccessDenied, + NoKeychainBackend, + Error, + AsyncWriting }; + + enum CredentialType { + Settings = 0, + KeyChain + }; + + QString password( ) const; + QString user( ) const; + + /** + * @brief state + * @return the state of the Credentialstore. + */ + CredState state(); + + /** + * @brief fetchCredentials - start to retrieve user credentials. + * + * This method must be called first to retrieve the credentials. + * At the end, this method emits the fetchKeyChainFinished() signal. + */ + void fetchCredentials(); + + /** + * @brief instance - singleton pointer. + * @return the singleton pointer to access the object. + */ + static CredentialStore *instance(); + + /** + * @brief setCredentials - sets the user credentials. + * + * This function is called from the setup wizard to set the credentials + * int this store. Note that it does not store the password. + * The function also sets the state to ok. + * @param url - the connection url + * @param user - the user name + */ + void setCredentials( const QString& url, const QString& user, const QString& pwd); + + void saveCredentials( ); + + QString errorMessage(); + + void reset(); +signals: + /** + * @brief fetchCredentialsFinished + * + * emitted as soon as the fetching of the credentials has finished. + * If the parameter is true, there is a password and user. This does + * however, not say if the credentials are valid log in data. + * If false, the user pressed cancel. + */ + void fetchCredentialsFinished(bool); + +protected slots: + void slotKeyChainReadFinished( QKeychain::Job* ); + void slotKeyChainWriteFinished( QKeychain::Job* ); + +private: + explicit CredentialStore(QObject *parent = 0); + void deleteKeyChainCredential( const QString& ); + QString keyChainKey( const QString& ) const; + + static CredentialStore *_instance; + static CredState _state; + static QString _passwd; + static QString _user; + static QString _url; + static QString _errorMsg; + static CredentialType _type; +}; +} + +#endif // CREDENTIALSTORE_H diff --git a/src/mirall/creds/http/httpconfigfile.cpp b/src/mirall/creds/http/httpconfigfile.cpp new file mode 100644 index 000000000..c65528d8a --- /dev/null +++ b/src/mirall/creds/http/httpconfigfile.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/creds/http/httpconfigfile.h" + +namespace Mirall +{ + +namespace +{ + +const char userC[] = "user"; +const char passwdC[] = "passwd"; +const char oldPasswdC[] = "password"; + +} // ns + +QString HttpConfigFile::user() const +{ + return retrieveData(QString(), QLatin1String(userC)).toString(); +} + +void HttpConfigFile::setUser(const QString& user) +{ + storeData(QString(), QLatin1String(userC), QVariant(user)); +} + +QString HttpConfigFile::password() const +{ + const QVariant passwd(retrieveData(QString(), QLatin1String(passwdC))); + + if (passwd.isValid()) { + return QString::fromUtf8(QByteArray::fromBase64(passwd.toByteArray())); + } + + return QString(); +} + +void HttpConfigFile::setPassword(const QString& password) +{ + QByteArray pwdba = password.toUtf8(); + storeData( QString(), QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); + removeOldPassword(); +} + +bool HttpConfigFile::passwordExists() const +{ + dataExists(QString(), QLatin1String(passwdC)); +} + +void HttpConfigFile::removePassword() +{ + removeOldPassword(); + removeData(QString(), QLatin1String(passwdC)); +} + +void HttpConfigFile::fixupOldPassword() +{ + const QString old(QString::fromLatin1(oldPasswdC)); + + if (dataExists(QString(), old)) { + setPassword(retrieveData(QString(), old).toString()); + } +}; + +void HttpConfigFile::removeOldPassword() +{ + removeData(QString(), QLatin1String(oldPasswdC)); +} + +} // ns Mirall diff --git a/src/mirall/creds/http/httpconfigfile.h b/src/mirall/creds/http/httpconfigfile.h new file mode 100644 index 000000000..ae69329a9 --- /dev/null +++ b/src/mirall/creds/http/httpconfigfile.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_HTTP_CONFIG_FILE_H +#define MIRALL_CREDS_HTTP_CONFIG_FILE_H + +#include "mirall/mirallconfigfile.h" + +namespace Mirall +{ + +class HttpConfigFile : public MirallConfigFile +{ +public: + QString user() const; + void setUser(const QString& user); + + QString password() const; + void setPassword(const QString& password); + bool passwordExists() const; + void removePassword(); + void fixupOldPassword(); + +private: + void removeOldPassword(); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/httpconfigfile.cpp b/src/mirall/creds/httpconfigfile.cpp deleted file mode 100644 index f979ef693..000000000 --- a/src/mirall/creds/httpconfigfile.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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/creds/httpconfigfile.h" - -namespace Mirall -{ - -namespace -{ - -const char userC[] = "user"; -const char passwdC[] = "passwd"; -const char oldPasswdC[] = "password"; - -} // ns - -QString HttpConfigFile::user() const -{ - return retrieveData(QString(), QLatin1String(userC)).toString(); -} - -void HttpConfigFile::setUser(const QString& user) -{ - storeData(QString(), QLatin1String(userC), QVariant(user)); -} - -QString HttpConfigFile::password() const -{ - const QVariant passwd(retrieveData(QString(), QLatin1String(passwdC))); - - if (passwd.isValid()) { - return QString::fromUtf8(QByteArray::fromBase64(passwd.toByteArray())); - } - - return QString(); -} - -void HttpConfigFile::setPassword(const QString& password) -{ - QByteArray pwdba = password.toUtf8(); - storeData( QString(), QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); - removeOldPassword(); -} - -bool HttpConfigFile::passwordExists() const -{ - dataExists(QString(), QLatin1String(passwdC)); -} - -void HttpConfigFile::removePassword() -{ - removeOldPassword(); - removeData(QString(), QLatin1String(passwdC)); -} - -void HttpConfigFile::fixupOldPassword() -{ - const QString old(QString::fromLatin1(oldPasswdC)); - - if (dataExists(QString(), old)) { - setPassword(retrieveData(QString(), old).toString()); - } -}; - -void HttpConfigFile::removeOldPassword() -{ - removeData(QString(), QLatin1String(oldPasswdC)); -} - -} // ns Mirall diff --git a/src/mirall/creds/httpconfigfile.h b/src/mirall/creds/httpconfigfile.h deleted file mode 100644 index ae69329a9..000000000 --- a/src/mirall/creds/httpconfigfile.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_CREDS_HTTP_CONFIG_FILE_H -#define MIRALL_CREDS_HTTP_CONFIG_FILE_H - -#include "mirall/mirallconfigfile.h" - -namespace Mirall -{ - -class HttpConfigFile : public MirallConfigFile -{ -public: - QString user() const; - void setUser(const QString& user); - - QString password() const; - void setPassword(const QString& password); - bool passwordExists() const; - void removePassword(); - void fixupOldPassword(); - -private: - void removeOldPassword(); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/httpcredentials.cpp b/src/mirall/creds/httpcredentials.cpp index 308042c9d..1db14c153 100644 --- a/src/mirall/creds/httpcredentials.cpp +++ b/src/mirall/creds/httpcredentials.cpp @@ -20,7 +20,7 @@ #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" #include "mirall/utility.h" -#include "mirall/credentialstore.h" +#include "mirall/creds/http/credentialstore.h" namespace Mirall { diff --git a/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp b/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp new file mode 100644 index 000000000..b01c23f83 --- /dev/null +++ b/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +#include "mirall/creds/shibboleth/shibbolethaccessmanager.h" + +namespace Mirall +{ + +ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent) + : QNetworkAccessManager (parent), + _cookie(cookie) +{} + +QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) +{ + QNetworkRequest newRequest(request); + QList cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >()); + + cookies << _cookie; + newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies)); + + return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); +} + +} // ns Mirall diff --git a/src/mirall/creds/shibboleth/shibbolethaccessmanager.h b/src/mirall/creds/shibboleth/shibbolethaccessmanager.h new file mode 100644 index 000000000..3300dae21 --- /dev/null +++ b/src/mirall/creds/shibboleth/shibbolethaccessmanager.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H +#define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H + +#include +#include + +namespace Mirall +{ + +class ShibbolethAccessManager : public QNetworkAccessManager +{ + Q_OBJECT + +public: + ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0); + +protected: + QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); + +private: + QNetworkCookie _cookie; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp b/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp new file mode 100644 index 000000000..5baa328e6 --- /dev/null +++ b/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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/creds/shibboleth/shibbolethcookiejar.h" + +namespace Mirall +{ + +ShibbolethCookieJar::ShibbolethCookieJar (QObject* parent) + : QNetworkCookieJar (parent) +{} + +bool ShibbolethCookieJar::setCookiesFromUrl (const QList& cookieList, const QUrl& url) +{ + if (QNetworkCookieJar::setCookiesFromUrl (cookieList, url)) { + Q_EMIT newCookiesForUrl (cookieList, url); + + return true; + } + + return false; +} + +} // ns Mirall diff --git a/src/mirall/creds/shibboleth/shibbolethcookiejar.h b/src/mirall/creds/shibboleth/shibbolethcookiejar.h new file mode 100644 index 000000000..9d263571b --- /dev/null +++ b/src/mirall/creds/shibboleth/shibbolethcookiejar.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H +#define MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H + +#include +#include + +class QUrl; +class QNetworkCookie; + +namespace Mirall +{ + +class ShibbolethCookieJar : public QNetworkCookieJar +{ + Q_OBJECT + +public: + ShibbolethCookieJar (QObject* parent = 0); + + virtual bool setCookiesFromUrl (const QList& cookieList, const QUrl& url); + +Q_SIGNALS: + void newCookiesForUrl (const QList& cookieList, const QUrl& url); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/shibboleth/shibbolethwebview.cpp b/src/mirall/creds/shibboleth/shibbolethwebview.cpp new file mode 100644 index 000000000..a3c144294 --- /dev/null +++ b/src/mirall/creds/shibboleth/shibbolethwebview.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "mirall/creds/shibboleth/shibbolethcookiejar.h" +#include "mirall/creds/shibboleth/shibbolethwebview.h" + +namespace Mirall +{ + +ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) + : QWebView(parent) +{ + ShibbolethCookieJar* jar = new ShibbolethCookieJar(this); + QWebPage* page = new QWebPage(this); + + connect (jar, SIGNAL (newCookiesForUrl (QList, QUrl)), + this, SLOT (onNewCookiesForUrl (QList, QUrl))); + + page->networkAccessManager()->setCookieJar(jar); + page->mainFrame ()->load (url); + this->setPage (page); +} + +void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& url) +{ + Q_FOREACH (const QNetworkCookie& cookie, cookieList) { + if (cookie.name().startsWith ("_shibsession_")) { + Q_EMIT shibbolethCookieReceived (cookie); + + return; + } + } +} + +} // ns Mirall diff --git a/src/mirall/creds/shibboleth/shibbolethwebview.h b/src/mirall/creds/shibboleth/shibbolethwebview.h new file mode 100644 index 000000000..e36f0981d --- /dev/null +++ b/src/mirall/creds/shibboleth/shibbolethwebview.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H +#define MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H + +#include +#include + +class QNetworkCookie; +class QUrl; + +namespace Mirall +{ + +class ShibbolethWebView : public QWebView +{ + Q_OBJECT + +public: + ShibbolethWebView(const QUrl& url, QWidget* parent = 0); + +Q_SIGNALS: + void shibbolethCookieReceived (const QNetworkCookie& cookie); + +private Q_SLOTS: + void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/creds/shibbolethaccessmanager.cpp b/src/mirall/creds/shibbolethaccessmanager.cpp deleted file mode 100644 index 17cbce97c..000000000 --- a/src/mirall/creds/shibbolethaccessmanager.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - -#include "mirall/creds/shibbolethaccessmanager.h" - -namespace Mirall -{ - -ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent) - : QNetworkAccessManager (parent), - _cookie(cookie) -{} - -QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) -{ - QNetworkRequest newRequest(request); - QList cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >()); - - cookies << _cookie; - newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies)); - - return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); -} - -} // ns Mirall diff --git a/src/mirall/creds/shibbolethaccessmanager.h b/src/mirall/creds/shibbolethaccessmanager.h deleted file mode 100644 index 3300dae21..000000000 --- a/src/mirall/creds/shibbolethaccessmanager.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H -#define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H - -#include -#include - -namespace Mirall -{ - -class ShibbolethAccessManager : public QNetworkAccessManager -{ - Q_OBJECT - -public: - ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0); - -protected: - QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); - -private: - QNetworkCookie _cookie; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/shibbolethcookiejar.cpp b/src/mirall/creds/shibbolethcookiejar.cpp deleted file mode 100644 index 97f4c92c2..000000000 --- a/src/mirall/creds/shibbolethcookiejar.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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/creds/shibbolethcookiejar.h" - -namespace Mirall -{ - -ShibbolethCookieJar::ShibbolethCookieJar (QObject* parent) - : QNetworkCookieJar (parent) -{} - -bool ShibbolethCookieJar::setCookiesFromUrl (const QList& cookieList, const QUrl& url) -{ - if (QNetworkCookieJar::setCookiesFromUrl (cookieList, url)) { - Q_EMIT newCookiesForUrl (cookieList, url); - - return true; - } - - return false; -} - -} // ns Mirall diff --git a/src/mirall/creds/shibbolethcookiejar.h b/src/mirall/creds/shibbolethcookiejar.h deleted file mode 100644 index 9d263571b..000000000 --- a/src/mirall/creds/shibbolethcookiejar.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H -#define MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H - -#include -#include - -class QUrl; -class QNetworkCookie; - -namespace Mirall -{ - -class ShibbolethCookieJar : public QNetworkCookieJar -{ - Q_OBJECT - -public: - ShibbolethCookieJar (QObject* parent = 0); - - virtual bool setCookiesFromUrl (const QList& cookieList, const QUrl& url); - -Q_SIGNALS: - void newCookiesForUrl (const QList& cookieList, const QUrl& url); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/shibbolethcredentials.cpp b/src/mirall/creds/shibbolethcredentials.cpp index f32e9cb1e..c77b3f9e8 100644 --- a/src/mirall/creds/shibbolethcredentials.cpp +++ b/src/mirall/creds/shibbolethcredentials.cpp @@ -15,8 +15,8 @@ */ #include "mirall/creds/shibbolethcredentials.h" -#include "mirall/creds/shibbolethaccessmanager.h" -#include "mirall/creds/shibbolethwebview.h" +#include "mirall/creds/shibboleth/shibbolethaccessmanager.h" +#include "mirall/creds/shibboleth/shibbolethwebview.h" #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" diff --git a/src/mirall/creds/shibbolethwebview.cpp b/src/mirall/creds/shibbolethwebview.cpp deleted file mode 100644 index 70380aa9e..000000000 --- a/src/mirall/creds/shibbolethwebview.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 -#include -#include - -#include "mirall/creds/shibbolethcookiejar.h" -#include "mirall/creds/shibbolethwebview.h" - -namespace Mirall -{ - -ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) - : QWebView(parent) -{ - ShibbolethCookieJar* jar = new ShibbolethCookieJar(this); - QWebPage* page = new QWebPage(this); - - connect (jar, SIGNAL (newCookiesForUrl (QList, QUrl)), - this, SLOT (onNewCookiesForUrl (QList, QUrl))); - - page->networkAccessManager()->setCookieJar(jar); - page->mainFrame ()->load (url); - this->setPage (page); -} - -void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& url) -{ - Q_FOREACH (const QNetworkCookie& cookie, cookieList) { - if (cookie.name().startsWith ("_shibsession_")) { - Q_EMIT shibbolethCookieReceived (cookie); - - return; - } - } -} - -} // ns Mirall diff --git a/src/mirall/creds/shibbolethwebview.h b/src/mirall/creds/shibbolethwebview.h deleted file mode 100644 index e36f0981d..000000000 --- a/src/mirall/creds/shibbolethwebview.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H -#define MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H - -#include -#include - -class QNetworkCookie; -class QUrl; - -namespace Mirall -{ - -class ShibbolethWebView : public QWebView -{ - Q_OBJECT - -public: - ShibbolethWebView(const QUrl& url, QWidget* parent = 0); - -Q_SIGNALS: - void shibbolethCookieReceived (const QNetworkCookie& cookie); - -private Q_SLOTS: - void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index 3617ff744..4b4c75391 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -18,7 +18,6 @@ #include "mirall/owncloudinfo.h" #include "mirall/owncloudtheme.h" #include "mirall/theme.h" -#include "mirall/credentialstore.h" #include "mirall/creds/abstractcredentials.h" #include "mirall/creds/credentialsfactory.h" #include diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index 69b43a1b1..5d89edec5 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -24,7 +24,6 @@ #include "mirall/mirallconfigfile.h" #include "mirall/owncloudinfo.h" #include "mirall/folderman.h" -#include "mirall/credentialstore.h" #include "mirall/utility.h" #include "mirall/creds/abstractcredentials.h" #include "mirall/creds/dummycredentials.h" diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.cpp b/src/mirall/wizard/owncloudshibbolethcredspage.cpp index f519fda15..6bb810773 100644 --- a/src/mirall/wizard/owncloudshibbolethcredspage.cpp +++ b/src/mirall/wizard/owncloudshibbolethcredspage.cpp @@ -18,7 +18,7 @@ #include "mirall/theme.h" #include "mirall/wizard/owncloudwizardcommon.h" #include "mirall/creds/shibbolethcredentials.h" -#include "mirall/creds/shibbolethwebview.h" +#include "mirall/creds/shibboleth/shibbolethwebview.h" namespace Mirall { -- cgit v1.2.3 From 306a9421fb0acc67a51f76f5ef8877cebc74a7f7 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 10:23:20 +0200 Subject: Avoid a crash when disposing Shibboleth browser. --- src/mirall/wizard/owncloudshibbolethcredspage.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.cpp b/src/mirall/wizard/owncloudshibbolethcredspage.cpp index 6bb810773..80b450d3a 100644 --- a/src/mirall/wizard/owncloudshibbolethcredspage.cpp +++ b/src/mirall/wizard/owncloudshibbolethcredspage.cpp @@ -73,15 +73,17 @@ void OwncloudShibbolethCredsPage::initializePage() void OwncloudShibbolethCredsPage::disposeBrowser(bool later) { - _browser->hide(); - disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), - this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - if (later) { - _browser->deleteLater(); - } else { - delete _browser; + if (_browser) { + _browser->hide(); + disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + if (later) { + _browser->deleteLater(); + } else { + delete _browser; + } + _browser = 0; } - _browser = 0; } void OwncloudShibbolethCredsPage::cleanupPage() -- cgit v1.2.3 From a6bf33c5018a788405840760d5ddf6aaaa4e6dfc Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 10:23:44 +0200 Subject: Make "Connect" button inactive until we get a Shibboleth cookie. --- src/mirall/wizard/owncloudshibbolethcredspage.cpp | 7 +++++++ src/mirall/wizard/owncloudshibbolethcredspage.h | 1 + src/mirall/wizard/owncloudwizard.cpp | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.cpp b/src/mirall/wizard/owncloudshibbolethcredspage.cpp index 80b450d3a..b11348280 100644 --- a/src/mirall/wizard/owncloudshibbolethcredspage.cpp +++ b/src/mirall/wizard/owncloudshibbolethcredspage.cpp @@ -54,6 +54,11 @@ void OwncloudShibbolethCredsPage::setupCustomization() WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); } +bool OwncloudShibbolethCredsPage::isComplete() const +{ + return _stage == GOT_COOKIE; +} + void OwncloudShibbolethCredsPage::initializePage() { WizardCommon::initErrorLabel(_ui.errorLabel); @@ -126,6 +131,7 @@ void OwncloudShibbolethCredsPage::setConnected( bool comp ) // sets stage to INITIAL initializePage(); } + emit completeChanged(); } void OwncloudShibbolethCredsPage::setErrorString(const QString& err) @@ -151,6 +157,7 @@ void OwncloudShibbolethCredsPage::onShibbolethCookieReceived(const QNetworkCooki _stage = GOT_COOKIE; _cookie = cookie; _ui.infoLabel->setText("Please click \"Connect\" to check received Shibboleth session."); + emit completeChanged(); } } // ns Mirall diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.h b/src/mirall/wizard/owncloudshibbolethcredspage.h index 7f7aaff5b..d5ccef452 100644 --- a/src/mirall/wizard/owncloudshibbolethcredspage.h +++ b/src/mirall/wizard/owncloudshibbolethcredspage.h @@ -35,6 +35,7 @@ public: AbstractCredentials* getCredentials() const; + bool isComplete() const; void initializePage(); void cleanupPage(); bool validatePage(); diff --git a/src/mirall/wizard/owncloudwizard.cpp b/src/mirall/wizard/owncloudwizard.cpp index 883d7728d..4edd8ac73 100644 --- a/src/mirall/wizard/owncloudwizard.cpp +++ b/src/mirall/wizard/owncloudwizard.cpp @@ -111,7 +111,22 @@ void OwncloudWizard::showConnectInfo( const QString& msg ) void OwncloudWizard::successfullyConnected(bool enable) { - _httpCredsPage->setConnected( enable ); + const int id(currentId()); + + switch (id) { + case WizardCommon::Page_HttpCreds: + _httpCredsPage->setConnected( enable ); + break; + + case WizardCommon::Page_ShibbolethCreds: + _shibbolethCredsPage->setConnected( enable ); + break; + + case WizardCommon::Page_oCSetup: + case WizardCommon::Page_Result: + qWarning("Should not happen at this stage."); + break; + } if( enable ) { next(); -- cgit v1.2.3 From 224fd216124881418246c49a2fdbdd6c51f64428 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 10:30:55 +0200 Subject: Fix displaying URL in account settings. I deleted too much code there last time. --- src/mirall/accountsettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index 29f4fbc73..797e3bf36 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -415,7 +415,7 @@ void AccountSettings::slotOCInfo( const QString& url, const QString& versionStr, qDebug() << "#-------# oC found on " << url; /* enable the open button */ ui->connectLabel->setOpenExternalLinks(true); - ui->connectLabel->setText( tr("Connected to %1.") ); + ui->connectLabel->setText( tr("Connected to %1.").arg(url) ); ui->connectLabel->setToolTip( tr("Version: %1 (%2)").arg(versionStr).arg(version)); ui->_ButtonAdd->setEnabled(true); -- cgit v1.2.3 From b7e88aa2efbd004d58c98868abe64d7d6a8c6fa5 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 10:48:26 +0200 Subject: Fix copyright headers. --- src/mirall/creds/abstractcredentials.h | 5 +---- src/mirall/creds/credentialsfactory.cpp | 5 +---- src/mirall/creds/credentialsfactory.h | 5 +---- src/mirall/creds/dummycredentials.cpp | 5 +---- src/mirall/creds/dummycredentials.h | 5 +---- src/mirall/creds/http/httpconfigfile.cpp | 5 +---- src/mirall/creds/http/httpconfigfile.h | 5 +---- src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp | 3 +-- src/mirall/creds/shibboleth/shibbolethaccessmanager.h | 3 +-- src/mirall/creds/shibboleth/shibbolethcookiejar.cpp | 3 +-- src/mirall/creds/shibboleth/shibbolethcookiejar.h | 3 +-- src/mirall/creds/shibboleth/shibbolethwebview.cpp | 3 +-- src/mirall/creds/shibboleth/shibbolethwebview.h | 3 +-- src/mirall/creds/shibbolethcredentials.cpp | 6 ++---- src/mirall/creds/shibbolethcredentials.h | 5 +---- src/mirall/owncloudsetupwizard.cpp | 2 +- src/mirall/wizard/abstractcredswizardpage.h | 5 +---- src/mirall/wizard/owncloudhttpcredspage.cpp | 2 +- src/mirall/wizard/owncloudhttpcredspage.h | 2 +- src/mirall/wizard/owncloudsetuppage.cpp | 2 +- src/mirall/wizard/owncloudsetuppage.h | 2 +- src/mirall/wizard/owncloudshibbolethcredspage.cpp | 5 +---- src/mirall/wizard/owncloudshibbolethcredspage.h | 5 +---- src/mirall/wizard/owncloudwizard.cpp | 2 +- src/mirall/wizard/owncloudwizard.h | 2 +- src/mirall/wizard/owncloudwizardcommon.cpp | 2 +- src/mirall/wizard/owncloudwizardcommon.h | 2 +- src/mirall/wizard/owncloudwizardresultpage.cpp | 2 +- src/mirall/wizard/owncloudwizardresultpage.h | 2 +- 29 files changed, 30 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/mirall/creds/abstractcredentials.h b/src/mirall/creds/abstractcredentials.h index 0c04adc92..1e589ddae 100644 --- a/src/mirall/creds/abstractcredentials.h +++ b/src/mirall/creds/abstractcredentials.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/credentialsfactory.cpp b/src/mirall/creds/credentialsfactory.cpp index ebade2466..2cb8eaa24 100644 --- a/src/mirall/creds/credentialsfactory.cpp +++ b/src/mirall/creds/credentialsfactory.cpp @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/credentialsfactory.h b/src/mirall/creds/credentialsfactory.h index 170610e5e..a34f94b77 100644 --- a/src/mirall/creds/credentialsfactory.h +++ b/src/mirall/creds/credentialsfactory.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/dummycredentials.cpp b/src/mirall/creds/dummycredentials.cpp index 58ff429d0..2318af9d8 100644 --- a/src/mirall/creds/dummycredentials.cpp +++ b/src/mirall/creds/dummycredentials.cpp @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/dummycredentials.h b/src/mirall/creds/dummycredentials.h index af178922f..026fab791 100644 --- a/src/mirall/creds/dummycredentials.h +++ b/src/mirall/creds/dummycredentials.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/http/httpconfigfile.cpp b/src/mirall/creds/http/httpconfigfile.cpp index c65528d8a..7be998495 100644 --- a/src/mirall/creds/http/httpconfigfile.cpp +++ b/src/mirall/creds/http/httpconfigfile.cpp @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/http/httpconfigfile.h b/src/mirall/creds/http/httpconfigfile.h index ae69329a9..2e690054f 100644 --- a/src/mirall/creds/http/httpconfigfile.h +++ b/src/mirall/creds/http/httpconfigfile.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp b/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp index b01c23f83..c70f6d872 100644 --- a/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp +++ b/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp @@ -3,8 +3,7 @@ * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibboleth/shibbolethaccessmanager.h b/src/mirall/creds/shibboleth/shibbolethaccessmanager.h index 3300dae21..9f0571d21 100644 --- a/src/mirall/creds/shibboleth/shibbolethaccessmanager.h +++ b/src/mirall/creds/shibboleth/shibbolethaccessmanager.h @@ -3,8 +3,7 @@ * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp b/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp index 5baa328e6..e683fb53e 100644 --- a/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp +++ b/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp @@ -3,8 +3,7 @@ * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibboleth/shibbolethcookiejar.h b/src/mirall/creds/shibboleth/shibbolethcookiejar.h index 9d263571b..4e4459ba5 100644 --- a/src/mirall/creds/shibboleth/shibbolethcookiejar.h +++ b/src/mirall/creds/shibboleth/shibbolethcookiejar.h @@ -3,8 +3,7 @@ * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibboleth/shibbolethwebview.cpp b/src/mirall/creds/shibboleth/shibbolethwebview.cpp index a3c144294..8ad80a2af 100644 --- a/src/mirall/creds/shibboleth/shibbolethwebview.cpp +++ b/src/mirall/creds/shibboleth/shibbolethwebview.cpp @@ -3,8 +3,7 @@ * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibboleth/shibbolethwebview.h b/src/mirall/creds/shibboleth/shibbolethwebview.h index e36f0981d..9fc1179b9 100644 --- a/src/mirall/creds/shibboleth/shibbolethwebview.h +++ b/src/mirall/creds/shibboleth/shibbolethwebview.h @@ -3,8 +3,7 @@ * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibbolethcredentials.cpp b/src/mirall/creds/shibbolethcredentials.cpp index c77b3f9e8..7c42b5bf6 100644 --- a/src/mirall/creds/shibbolethcredentials.cpp +++ b/src/mirall/creds/shibbolethcredentials.cpp @@ -1,12 +1,10 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak + * Copyright (C) by Klaas Freitag * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/creds/shibbolethcredentials.h b/src/mirall/creds/shibbolethcredentials.h index 79baa3aac..a70a16960 100644 --- a/src/mirall/creds/shibbolethcredentials.h +++ b/src/mirall/creds/shibbolethcredentials.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index 5d89edec5..eaf3d28d2 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/abstractcredswizardpage.h b/src/mirall/wizard/abstractcredswizardpage.h index 563d81d5e..0579f0c05 100644 --- a/src/mirall/wizard/abstractcredswizardpage.h +++ b/src/mirall/wizard/abstractcredswizardpage.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/wizard/owncloudhttpcredspage.cpp b/src/mirall/wizard/owncloudhttpcredspage.cpp index 9df58c5a2..72dc21d3f 100644 --- a/src/mirall/wizard/owncloudhttpcredspage.cpp +++ b/src/mirall/wizard/owncloudhttpcredspage.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudhttpcredspage.h b/src/mirall/wizard/owncloudhttpcredspage.h index 40cd7e8fa..2cb28ad81 100644 --- a/src/mirall/wizard/owncloudhttpcredspage.h +++ b/src/mirall/wizard/owncloudhttpcredspage.h @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudsetuppage.cpp b/src/mirall/wizard/owncloudsetuppage.cpp index 41b7d9584..2aec63556 100644 --- a/src/mirall/wizard/owncloudsetuppage.cpp +++ b/src/mirall/wizard/owncloudsetuppage.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudsetuppage.h b/src/mirall/wizard/owncloudsetuppage.h index c56dd1550..36f84c9a4 100644 --- a/src/mirall/wizard/owncloudsetuppage.h +++ b/src/mirall/wizard/owncloudsetuppage.h @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.cpp b/src/mirall/wizard/owncloudshibbolethcredspage.cpp index b11348280..5384f4128 100644 --- a/src/mirall/wizard/owncloudshibbolethcredspage.cpp +++ b/src/mirall/wizard/owncloudshibbolethcredspage.cpp @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.h b/src/mirall/wizard/owncloudshibbolethcredspage.h index d5ccef452..0e4fe6277 100644 --- a/src/mirall/wizard/owncloudshibbolethcredspage.h +++ b/src/mirall/wizard/owncloudshibbolethcredspage.h @@ -1,12 +1,9 @@ /* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * 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; either version 2 of the License, or - * (at your option) any later version. + * 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 diff --git a/src/mirall/wizard/owncloudwizard.cpp b/src/mirall/wizard/owncloudwizard.cpp index 4edd8ac73..865939342 100644 --- a/src/mirall/wizard/owncloudwizard.cpp +++ b/src/mirall/wizard/owncloudwizard.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudwizard.h b/src/mirall/wizard/owncloudwizard.h index 03f20d62f..60e9952c1 100644 --- a/src/mirall/wizard/owncloudwizard.h +++ b/src/mirall/wizard/owncloudwizard.h @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudwizardcommon.cpp b/src/mirall/wizard/owncloudwizardcommon.cpp index e2aabef0e..6429b02ef 100644 --- a/src/mirall/wizard/owncloudwizardcommon.cpp +++ b/src/mirall/wizard/owncloudwizardcommon.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudwizardcommon.h b/src/mirall/wizard/owncloudwizardcommon.h index 8e4ca7fa1..38ac86278 100644 --- a/src/mirall/wizard/owncloudwizardcommon.h +++ b/src/mirall/wizard/owncloudwizardcommon.h @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudwizardresultpage.cpp b/src/mirall/wizard/owncloudwizardresultpage.cpp index a4ece4236..9c0ae0221 100644 --- a/src/mirall/wizard/owncloudwizardresultpage.cpp +++ b/src/mirall/wizard/owncloudwizardresultpage.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify diff --git a/src/mirall/wizard/owncloudwizardresultpage.h b/src/mirall/wizard/owncloudwizardresultpage.h index 64158e130..0ae7a6679 100644 --- a/src/mirall/wizard/owncloudwizardresultpage.h +++ b/src/mirall/wizard/owncloudwizardresultpage.h @@ -1,6 +1,6 @@ /* * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag + * Copyright (C) by Klaas Freitag * Copyright (C) by Krzesimir Nowak * * This program is free software; you can redistribute it and/or modify -- cgit v1.2.3 From 78b6f4df01bd7fb5620fe5af7d4619896c17249f Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 11:19:22 +0200 Subject: Move the creds/ and wizard/ directories one level higher. --- src/CMakeLists.txt | 70 ++-- src/creds/abstractcredentials.h | 47 +++ src/creds/credentialsfactory.cpp | 43 +++ src/creds/credentialsfactory.h | 32 ++ src/creds/dummycredentials.cpp | 57 +++ src/creds/dummycredentials.h | 39 ++ src/creds/http/credentialstore.cpp | 338 +++++++++++++++++ src/creds/http/credentialstore.h | 132 +++++++ src/creds/http/httpconfigfile.cpp | 81 ++++ src/creds/http/httpconfigfile.h | 40 ++ src/creds/httpcredentials.cpp | 251 +++++++++++++ src/creds/httpcredentials.h | 64 ++++ src/creds/shibboleth/shibbolethaccessmanager.cpp | 37 ++ src/creds/shibboleth/shibbolethaccessmanager.h | 39 ++ src/creds/shibboleth/shibbolethcookiejar.cpp | 34 ++ src/creds/shibboleth/shibbolethcookiejar.h | 41 ++ src/creds/shibboleth/shibbolethwebview.cpp | 49 +++ src/creds/shibboleth/shibbolethwebview.h | 42 +++ src/creds/shibbolethcredentials.cpp | 123 ++++++ src/creds/shibbolethcredentials.h | 56 +++ src/mirall/application.cpp | 2 +- src/mirall/creds/abstractcredentials.h | 47 --- src/mirall/creds/credentialsfactory.cpp | 43 --- src/mirall/creds/credentialsfactory.h | 32 -- src/mirall/creds/dummycredentials.cpp | 57 --- src/mirall/creds/dummycredentials.h | 39 -- src/mirall/creds/http/credentialstore.cpp | 338 ----------------- src/mirall/creds/http/credentialstore.h | 132 ------- src/mirall/creds/http/httpconfigfile.cpp | 81 ---- src/mirall/creds/http/httpconfigfile.h | 40 -- src/mirall/creds/httpcredentials.cpp | 251 ------------- src/mirall/creds/httpcredentials.h | 64 ---- .../creds/shibboleth/shibbolethaccessmanager.cpp | 37 -- .../creds/shibboleth/shibbolethaccessmanager.h | 39 -- .../creds/shibboleth/shibbolethcookiejar.cpp | 34 -- src/mirall/creds/shibboleth/shibbolethcookiejar.h | 41 -- src/mirall/creds/shibboleth/shibbolethwebview.cpp | 49 --- src/mirall/creds/shibboleth/shibbolethwebview.h | 42 --- src/mirall/creds/shibbolethcredentials.cpp | 123 ------ src/mirall/creds/shibbolethcredentials.h | 56 --- src/mirall/csyncthread.cpp | 2 +- src/mirall/folder.cpp | 2 +- src/mirall/mirallconfigfile.cpp | 4 +- src/mirall/owncloudhttpcredspage.ui | 130 ------- src/mirall/owncloudinfo.cpp | 2 +- src/mirall/owncloudsetupnocredspage.ui | 417 --------------------- src/mirall/owncloudsetupwizard.cpp | 7 +- src/mirall/owncloudsetupwizard.h | 2 +- src/mirall/owncloudshibbolethcredspage.ui | 121 ------ src/mirall/owncloudwizardresultpage.ui | 162 -------- src/mirall/wizard/abstractcredswizardpage.h | 32 -- src/mirall/wizard/owncloudhttpcredspage.cpp | 143 ------- src/mirall/wizard/owncloudhttpcredspage.h | 60 --- src/mirall/wizard/owncloudsetuppage.cpp | 352 ----------------- src/mirall/wizard/owncloudsetuppage.h | 92 ----- src/mirall/wizard/owncloudshibbolethcredspage.cpp | 160 -------- src/mirall/wizard/owncloudshibbolethcredspage.h | 68 ---- src/mirall/wizard/owncloudwizard.cpp | 214 ----------- src/mirall/wizard/owncloudwizard.h | 90 ----- src/mirall/wizard/owncloudwizardcommon.cpp | 72 ---- src/mirall/wizard/owncloudwizardcommon.h | 55 --- src/mirall/wizard/owncloudwizardresultpage.cpp | 116 ------ src/mirall/wizard/owncloudwizardresultpage.h | 57 --- src/wizard/abstractcredswizardpage.h | 32 ++ src/wizard/owncloudhttpcredspage.cpp | 143 +++++++ src/wizard/owncloudhttpcredspage.h | 60 +++ src/wizard/owncloudhttpcredspage.ui | 130 +++++++ src/wizard/owncloudsetupnocredspage.ui | 417 +++++++++++++++++++++ src/wizard/owncloudsetuppage.cpp | 352 +++++++++++++++++ src/wizard/owncloudsetuppage.h | 92 +++++ src/wizard/owncloudshibbolethcredspage.cpp | 160 ++++++++ src/wizard/owncloudshibbolethcredspage.h | 68 ++++ src/wizard/owncloudshibbolethcredspage.ui | 121 ++++++ src/wizard/owncloudwizard.cpp | 214 +++++++++++ src/wizard/owncloudwizard.h | 90 +++++ src/wizard/owncloudwizardcommon.cpp | 72 ++++ src/wizard/owncloudwizardcommon.h | 55 +++ src/wizard/owncloudwizardresultpage.cpp | 116 ++++++ src/wizard/owncloudwizardresultpage.h | 57 +++ src/wizard/owncloudwizardresultpage.ui | 162 ++++++++ 80 files changed, 3932 insertions(+), 3931 deletions(-) create mode 100644 src/creds/abstractcredentials.h create mode 100644 src/creds/credentialsfactory.cpp create mode 100644 src/creds/credentialsfactory.h create mode 100644 src/creds/dummycredentials.cpp create mode 100644 src/creds/dummycredentials.h create mode 100644 src/creds/http/credentialstore.cpp create mode 100644 src/creds/http/credentialstore.h create mode 100644 src/creds/http/httpconfigfile.cpp create mode 100644 src/creds/http/httpconfigfile.h create mode 100644 src/creds/httpcredentials.cpp create mode 100644 src/creds/httpcredentials.h create mode 100644 src/creds/shibboleth/shibbolethaccessmanager.cpp create mode 100644 src/creds/shibboleth/shibbolethaccessmanager.h create mode 100644 src/creds/shibboleth/shibbolethcookiejar.cpp create mode 100644 src/creds/shibboleth/shibbolethcookiejar.h create mode 100644 src/creds/shibboleth/shibbolethwebview.cpp create mode 100644 src/creds/shibboleth/shibbolethwebview.h create mode 100644 src/creds/shibbolethcredentials.cpp create mode 100644 src/creds/shibbolethcredentials.h delete mode 100644 src/mirall/creds/abstractcredentials.h delete mode 100644 src/mirall/creds/credentialsfactory.cpp delete mode 100644 src/mirall/creds/credentialsfactory.h delete mode 100644 src/mirall/creds/dummycredentials.cpp delete mode 100644 src/mirall/creds/dummycredentials.h delete mode 100644 src/mirall/creds/http/credentialstore.cpp delete mode 100644 src/mirall/creds/http/credentialstore.h delete mode 100644 src/mirall/creds/http/httpconfigfile.cpp delete mode 100644 src/mirall/creds/http/httpconfigfile.h delete mode 100644 src/mirall/creds/httpcredentials.cpp delete mode 100644 src/mirall/creds/httpcredentials.h delete mode 100644 src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp delete mode 100644 src/mirall/creds/shibboleth/shibbolethaccessmanager.h delete mode 100644 src/mirall/creds/shibboleth/shibbolethcookiejar.cpp delete mode 100644 src/mirall/creds/shibboleth/shibbolethcookiejar.h delete mode 100644 src/mirall/creds/shibboleth/shibbolethwebview.cpp delete mode 100644 src/mirall/creds/shibboleth/shibbolethwebview.h delete mode 100644 src/mirall/creds/shibbolethcredentials.cpp delete mode 100644 src/mirall/creds/shibbolethcredentials.h delete mode 100644 src/mirall/owncloudhttpcredspage.ui delete mode 100644 src/mirall/owncloudsetupnocredspage.ui delete mode 100644 src/mirall/owncloudshibbolethcredspage.ui delete mode 100644 src/mirall/owncloudwizardresultpage.ui delete mode 100644 src/mirall/wizard/abstractcredswizardpage.h delete mode 100644 src/mirall/wizard/owncloudhttpcredspage.cpp delete mode 100644 src/mirall/wizard/owncloudhttpcredspage.h delete mode 100644 src/mirall/wizard/owncloudsetuppage.cpp delete mode 100644 src/mirall/wizard/owncloudsetuppage.h delete mode 100644 src/mirall/wizard/owncloudshibbolethcredspage.cpp delete mode 100644 src/mirall/wizard/owncloudshibbolethcredspage.h delete mode 100644 src/mirall/wizard/owncloudwizard.cpp delete mode 100644 src/mirall/wizard/owncloudwizard.h delete mode 100644 src/mirall/wizard/owncloudwizardcommon.cpp delete mode 100644 src/mirall/wizard/owncloudwizardcommon.h delete mode 100644 src/mirall/wizard/owncloudwizardresultpage.cpp delete mode 100644 src/mirall/wizard/owncloudwizardresultpage.h create mode 100644 src/wizard/abstractcredswizardpage.h create mode 100644 src/wizard/owncloudhttpcredspage.cpp create mode 100644 src/wizard/owncloudhttpcredspage.h create mode 100644 src/wizard/owncloudhttpcredspage.ui create mode 100644 src/wizard/owncloudsetupnocredspage.ui create mode 100644 src/wizard/owncloudsetuppage.cpp create mode 100644 src/wizard/owncloudsetuppage.h create mode 100644 src/wizard/owncloudshibbolethcredspage.cpp create mode 100644 src/wizard/owncloudshibbolethcredspage.h create mode 100644 src/wizard/owncloudshibbolethcredspage.ui create mode 100644 src/wizard/owncloudwizard.cpp create mode 100644 src/wizard/owncloudwizard.h create mode 100644 src/wizard/owncloudwizardcommon.cpp create mode 100644 src/wizard/owncloudwizardcommon.h create mode 100644 src/wizard/owncloudwizardresultpage.cpp create mode 100644 src/wizard/owncloudwizardresultpage.h create mode 100644 src/wizard/owncloudwizardresultpage.ui (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc0d8ae52..dd7003c1d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,10 +23,10 @@ mirall/networksettings.ui mirall/accountsettings.ui mirall/ignorelisteditor.ui mirall/fileitemdialog.ui -mirall/owncloudsetupnocredspage.ui -mirall/owncloudhttpcredspage.ui -mirall/owncloudwizardresultpage.ui -mirall/owncloudshibbolethcredspage.ui +wizard/owncloudsetupnocredspage.ui +wizard/owncloudhttpcredspage.ui +wizard/owncloudwizardresultpage.ui +wizard/owncloudshibbolethcredspage.ui ) set(3rdparty_SRC @@ -78,15 +78,15 @@ set(libsync_SRCS mirall/utility.cpp mirall/connectionvalidator.cpp mirall/progressdispatcher.cpp - mirall/creds/dummycredentials.cpp - mirall/creds/httpcredentials.cpp - mirall/creds/credentialsfactory.cpp - mirall/creds/http/credentialstore.cpp - mirall/creds/http/httpconfigfile.cpp - mirall/creds/shibbolethcredentials.cpp - mirall/creds/shibboleth/shibbolethaccessmanager.cpp - mirall/creds/shibboleth/shibbolethcookiejar.cpp - mirall/creds/shibboleth/shibbolethwebview.cpp + creds/dummycredentials.cpp + creds/httpcredentials.cpp + creds/credentialsfactory.cpp + creds/http/credentialstore.cpp + creds/http/httpconfigfile.cpp + creds/shibbolethcredentials.cpp + creds/shibboleth/shibbolethaccessmanager.cpp + creds/shibboleth/shibbolethcookiejar.cpp + creds/shibboleth/shibbolethwebview.cpp ) set(libsync_HEADERS @@ -100,16 +100,16 @@ set(libsync_HEADERS mirall/logger.h mirall/connectionvalidator.h mirall/progressdispatcher.h - mirall/creds/abstractcredentials.h - mirall/creds/dummycredentials.h - mirall/creds/httpcredentials.h - mirall/creds/credentialsfactory.h - mirall/creds/http/credentialstore.h - mirall/creds/http/httpconfigfile.h - mirall/creds/shibbolethcredentials.h - mirall/creds/shibboleth/shibbolethaccessmanager.h - mirall/creds/shibboleth/shibbolethcookiejar.h - mirall/creds/shibboleth/shibbolethwebview.h + creds/abstractcredentials.h + creds/dummycredentials.h + creds/httpcredentials.h + creds/credentialsfactory.h + creds/http/credentialstore.h + creds/http/httpconfigfile.h + creds/shibbolethcredentials.h + creds/shibboleth/shibbolethaccessmanager.h + creds/shibboleth/shibbolethcookiejar.h + creds/shibboleth/shibbolethwebview.h ) IF( INOTIFY_FOUND ) @@ -172,12 +172,12 @@ set(mirall_SRCS mirall/systray.cpp mirall/folderwizard.cpp mirall/folderstatusmodel.cpp - mirall/wizard/owncloudwizard.cpp - mirall/wizard/owncloudsetuppage.cpp - mirall/wizard/owncloudhttpcredspage.cpp - mirall/wizard/owncloudwizardresultpage.cpp - mirall/wizard/owncloudwizardcommon.cpp - mirall/wizard/owncloudshibbolethcredspage.cpp + wizard/owncloudwizard.cpp + wizard/owncloudsetuppage.cpp + wizard/owncloudhttpcredspage.cpp + wizard/owncloudwizardresultpage.cpp + wizard/owncloudwizardcommon.cpp + wizard/owncloudshibbolethcredspage.cpp mirall/owncloudsetupwizard.cpp mirall/updatedetector.cpp mirall/occinfo.cpp @@ -196,12 +196,12 @@ set(mirall_HEADERS mirall/systray.h mirall/folderwizard.h mirall/owncloudsetupwizard.h - mirall/wizard/owncloudwizard.h - mirall/wizard/owncloudsetuppage.h - mirall/wizard/owncloudhttpcredspage.h - mirall/wizard/owncloudwizardresultpage.h - mirall/wizard/owncloudwizardcommon.h - mirall/wizard/owncloudshibbolethcredspage.h + wizard/owncloudwizard.h + wizard/owncloudsetuppage.h + wizard/owncloudhttpcredspage.h + wizard/owncloudwizardresultpage.h + wizard/owncloudwizardcommon.h + wizard/owncloudshibbolethcredspage.h mirall/folderstatusmodel.h mirall/updatedetector.h mirall/sslerrordialog.h diff --git a/src/creds/abstractcredentials.h b/src/creds/abstractcredentials.h new file mode 100644 index 000000000..1e589ddae --- /dev/null +++ b/src/creds/abstractcredentials.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_CREDS_ABSTRACT_CREDENTIALS_H +#define MIRALL_CREDS_ABSTRACT_CREDENTIALS_H + +#include + +#include + +class QNetworkAccessManager; + +namespace Mirall +{ + +class AbstractCredentials : public QObject +{ + Q_OBJECT + +public: + // No need for virtual destructor - QObject already has one. + virtual void syncContextPreInit(CSYNC* ctx) = 0; + virtual void syncContextPreStart(CSYNC* ctx) = 0; + virtual bool changed(AbstractCredentials* credentials) const = 0; + virtual QString authType() const = 0; + virtual QNetworkAccessManager* getQNAM() const = 0; + virtual bool ready() const = 0; + virtual void fetch() = 0; + virtual void persistForUrl(const QString& url) = 0; + +Q_SIGNALS: + void fetched(); +}; + +} // ns Mirall + +#endif diff --git a/src/creds/credentialsfactory.cpp b/src/creds/credentialsfactory.cpp new file mode 100644 index 000000000..0106f3f73 --- /dev/null +++ b/src/creds/credentialsfactory.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 + +#include "creds/httpcredentials.h" +#include "creds/dummycredentials.h" +#include "creds/shibbolethcredentials.h" + +namespace Mirall +{ + +namespace CredentialsFactory +{ + +AbstractCredentials* create(const QString& type) +{ + // empty string might happen for old version of configuration + if (type == "http" || type == "") { + return new HttpCredentials; + } else if (type == "dummy") { + return new DummyCredentials; + } else if (type == "shibboleth") { + return new ShibbolethCredentials; + } else { + qWarning("Unknown credentials type: %d", qPrintable(type)); + return new DummyCredentials; + } +} + +} // ns CredentialsFactory + +} // ns Mirall diff --git a/src/creds/credentialsfactory.h b/src/creds/credentialsfactory.h new file mode 100644 index 000000000..a34f94b77 --- /dev/null +++ b/src/creds/credentialsfactory.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_CREDS_CREDENTIALS_FACTORY_H +#define MIRALL_CREDS_CREDENTIALS_FACTORY_H + +class AbstractCredentials; +class QString; + +namespace Mirall +{ + +namespace CredentialsFactory +{ + +AbstractCredentials* create(const QString& type); + +} // ns CredentialsFactory + +} // ns Mirall + +#endif diff --git a/src/creds/dummycredentials.cpp b/src/creds/dummycredentials.cpp new file mode 100644 index 000000000..ca5e34a3f --- /dev/null +++ b/src/creds/dummycredentials.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 + +#include "creds/dummycredentials.h" + +namespace Mirall +{ + +void DummyCredentials::syncContextPreInit(CSYNC*) +{} + +void DummyCredentials::syncContextPreStart(CSYNC*) +{} + +bool DummyCredentials::changed(AbstractCredentials* credentials) const +{ + DummyCredentials* dummy(dynamic_cast< DummyCredentials* >(credentials)); + + return dummy == 0; +} + +QString DummyCredentials::authType() const +{ + return QString::fromLatin1("dummy"); +} + +QNetworkAccessManager* DummyCredentials::getQNAM() const +{ + return new QNetworkAccessManager; +} + +bool DummyCredentials::ready() const +{ + return true; +} + +void DummyCredentials::fetch() +{ + Q_EMIT(fetched()); +} + +void DummyCredentials::persistForUrl(const QString&) +{} + +} // ns Mirall diff --git a/src/creds/dummycredentials.h b/src/creds/dummycredentials.h new file mode 100644 index 000000000..bd234699b --- /dev/null +++ b/src/creds/dummycredentials.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_CREDS_DUMMY_CREDENTIALS_H +#define MIRALL_CREDS_DUMMY_CREDENTIALS_H + +#include "creds/abstractcredentials.h" + +namespace Mirall +{ + +class DummyCredentials : public AbstractCredentials +{ + Q_OBJECT + +public: + void syncContextPreInit(CSYNC* ctx); + void syncContextPreStart(CSYNC* ctx); + bool changed(AbstractCredentials* credentials) const; + QString authType() const; + QNetworkAccessManager* getQNAM() const; + bool ready() const; + void fetch(); + void persistForUrl(const QString& url); +}; + +} // ns Mirall + +#endif diff --git a/src/creds/http/credentialstore.cpp b/src/creds/http/credentialstore.cpp new file mode 100644 index 000000000..6f4533531 --- /dev/null +++ b/src/creds/http/credentialstore.cpp @@ -0,0 +1,338 @@ +/* + * Copyright (C) by Klaas Freitag + * + * 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 +#include + +#include "config.h" + +#include "creds/http/credentialstore.h" +#include "creds/http/httpconfigfile.h" +#include "mirall/theme.h" + +#ifdef WITH_QTKEYCHAIN +#include +using namespace QKeychain; +#endif + +#define MAX_LOGIN_ATTEMPTS 3 + +namespace Mirall { + +CredentialStore *CredentialStore::_instance=0; +CredentialStore::CredState CredentialStore::_state = NotFetched; +QString CredentialStore::_passwd = QString::null; +QString CredentialStore::_user = QString::null; +QString CredentialStore::_url = QString::null; +QString CredentialStore::_errorMsg = QString::null; +#ifdef WITH_QTKEYCHAIN +CredentialStore::CredentialType CredentialStore::_type = KeyChain; +#else +CredentialStore::CredentialType CredentialStore::_type = Settings; +#endif + +CredentialStore::CredentialStore(QObject *parent) : + QObject(parent) +{ +} + +CredentialStore *CredentialStore::instance() +{ + if( !CredentialStore::_instance ) CredentialStore::_instance = new CredentialStore; + return CredentialStore::_instance; +} + +QString CredentialStore::password() const +{ + return _passwd; +} +QString CredentialStore::user() const +{ + return _user; +} + +CredentialStore::CredState CredentialStore::state() +{ + return _state; +} + +void CredentialStore::fetchCredentials() +{ + HttpConfigFile cfgFile; + + bool ok = false; + QString pwd; + _user = cfgFile.user(); + _url = cfgFile.ownCloudUrl(); + + QString key = keyChainKey(_url); + + if( key.isNull() ) { + qDebug() << "Can not fetch credentials, url is zero!"; + _state = Error; + emit( fetchCredentialsFinished(false) ); + return; + } + + switch( _type ) { + case CredentialStore::Settings: { + /* Read from config file. */ + _state = Fetching; + cfgFile.fixupOldPassword(); + if( cfgFile.passwordExists() ) { + pwd = cfgFile.password(); + ok = true; + } else { + ok = false; + _state = EntryNotFound; + } + break; + } + case CredentialStore::KeyChain: { + // If the credentials are here already, return. + if( _state == Ok || _state == AsyncWriting ) { + emit(fetchCredentialsFinished(true)); + return; + } + // otherwise fetch asynchronious. +#ifdef WITH_QTKEYCHAIN + _state = AsyncFetching; + if( !_user.isEmpty() ) { + ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName()); + job->setKey( key ); + + connect( job, SIGNAL(finished(QKeychain::Job*)), this, + SLOT(slotKeyChainReadFinished(QKeychain::Job*))); + job->start(); + } +#else + qDebug() << "QtKeyChain: Not yet implemented!"; + _state = Error; +#endif + break; + } + default: { + break; + } + } + + if( _state == Fetching ) { // ...but not AsyncFetching + if( ok ) { + _passwd = pwd; + _state = Ok; + } + if( !ok && _state == Fetching ) { + _state = Error; + } + + emit( fetchCredentialsFinished(ok) ); + } else { + // in case of AsyncFetching nothing happens here. The finished-Slot + // will emit the finish signal. + } +} + +void CredentialStore::reset() +{ + _state = NotFetched; + _user = QString::null; + _passwd = QString::null; +} + +QString CredentialStore::keyChainKey( const QString& url ) const +{ + QString u(url); + if( u.isEmpty() ) { + qDebug() << "Empty url in keyChain, error!"; + return QString::null; + } + if( _user.isEmpty() ) { + qDebug() << "Error: User is emty!"; + return QString::null; + } + + if( !u.endsWith(QChar('/')) ) { + u.append(QChar('/')); + } + + QString key = _user+QLatin1Char(':')+u; + return key; +} + +void CredentialStore::slotKeyChainReadFinished(QKeychain::Job* job) +{ +#ifdef WITH_QTKEYCHAIN + ReadPasswordJob *pwdJob = static_cast(job); + if( pwdJob ) { + switch( pwdJob->error() ) { + case QKeychain::NoError: + _passwd = pwdJob->textData(); +#ifdef Q_OS_LINUX + // Currently there is a bug in the keychain on linux that if no + // entry is there, an empty password comes back, but no error. + if( _passwd.isEmpty() ) { + _state = EntryNotFound; + _errorMsg = tr("No password entry found in keychain. Please reconfigure."); + } else +#endif + _state = Ok; + break; + case QKeychain::EntryNotFound: + _state = EntryNotFound; + break; + case QKeychain::CouldNotDeleteEntry: + _state = Error; + break; + case QKeychain::AccessDenied: + _state = AccessDenied; + break; + case QKeychain::NoBackendAvailable: + _state = NoKeychainBackend; + break; + case QKeychain::NotImplemented: + _state = NoKeychainBackend; + break; + case QKeychain::OtherError: + default: + _state = Error; + + } + /* In case there is no backend, tranparentely switch to Settings file. */ + if( _state == NoKeychainBackend ) { + qDebug() << "No Storage Backend, falling back to Settings mode."; + _type = CredentialStore::Settings; + fetchCredentials(_user); + return; + } + + if( _state == EntryNotFound ) { + // try to migrate. + } + + if( _state != Ok ) { + qDebug() << "Error with keychain: " << pwdJob->errorString(); + if(_errorMsg.isEmpty()) _errorMsg = pwdJob->errorString(); + } else { + _errorMsg = QString::null; + } + } else { + _state = Error; + qDebug() << "Error: KeyChain Read Password Job failed!"; + } + emit(fetchCredentialsFinished(_state == Ok)); +#else + (void) job; +#endif +} + +QString CredentialStore::errorMessage() +{ + return _errorMsg; +} + +void CredentialStore::setCredentials( const QString& url, const QString& user, + const QString& pwd ) +{ + _passwd = pwd; + _user = user; +#ifdef WITH_QTKEYCHAIN + _type = KeyChain; +#else + _type = Settings; +#endif + _url = url; + _state = Ok; +} + +void CredentialStore::saveCredentials( ) +{ + HttpConfigFile cfgFile; + QString key = keyChainKey(_url); + if( key.isNull() ) { + qDebug() << "Error: Can not save credentials, URL is zero!"; + return; + } +#ifdef WITH_QTKEYCHAIN +#endif + + cfgFile.setUser(_user); + switch( _type ) { + case CredentialStore::KeyChain: { +#ifdef WITH_QTKEYCHAIN + WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName()); + // Set password in KeyChain + job->setKey( key ); + job->setTextData(_passwd); + + connect( job, SIGNAL(finished(QKeychain::Job*)), this, + SLOT(slotKeyChainWriteFinished(QKeychain::Job*))); + _state = AsyncWriting; + job->start(); +#endif + } + break; + case CredentialStore::Settings: + cfgFile.setPassword( _passwd ); + reset(); + break; + default: + // unsupported. + break; + } +} + +void CredentialStore::slotKeyChainWriteFinished( QKeychain::Job *job ) +{ +#ifdef WITH_QTKEYCHAIN + WritePasswordJob *pwdJob = static_cast(job); + if( pwdJob ) { + QKeychain::Error err = pwdJob->error(); + + if( err != QKeychain::NoError ) { + qDebug() << "Error with keychain: " << pwdJob->errorString(); + if( err == NoBackendAvailable || err == NotImplemented || + pwdJob->errorString().contains(QLatin1String("Could not open wallet"))) { + _state = NoKeychainBackend; + _type = Settings; + saveCredentials(); + } else { + _state = Error; + } + } else { + qDebug() << "Successfully stored password for user " << _user; + // Try to remove password formerly stored in the config file. + HttpConfigFile cfgFile; + cfgFile.removePassword(); + _state = NotFetched; + } + } else { + qDebug() << "Error: KeyChain Write Password Job failed!"; + _state = Error; + } +#else + (void) job; +#endif +} + +// Called if a user chooses to not store the password locally. +void CredentialStore::deleteKeyChainCredential( const QString& key ) +{ +#ifdef WITH_QTKEYCHAIN + // Start the remove job, do not care so much about the result. + DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName()); + job->setKey( key ); + job->start(); +#endif +} + +} diff --git a/src/creds/http/credentialstore.h b/src/creds/http/credentialstore.h new file mode 100644 index 000000000..2732e603c --- /dev/null +++ b/src/creds/http/credentialstore.h @@ -0,0 +1,132 @@ +/* + * Copyright (C) by Klaas Freitag + * + * 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 CREDENTIALSTORE_H +#define CREDENTIALSTORE_H + +#include +#include + +namespace QKeychain { + class Job; +} + +namespace Mirall { + +/* + * This object holds the credential information of the ownCloud connection. It + * is implemented as a singleton. + * At startup of the client, at first the fetchCredentials() method must be called + * which tries to get credentials from one of the supported backends. To determine + * which backend should be used, MirallConfigFile::credentialType() is called as + * the backend is configured in the config file. + * + * The fetchCredentials() call changes the internal state of the credential store + * to one of + * Ok: There are credentials. Note that it's unknown if they are correct!! + * Fetching: The fetching is not yet finished. + * EntryNotFound: No password entry found in the storage. + * Error: A general error happened. + * After fetching has finished, signal fetchCredentialsFinished(bool) is emitted. + * The result can be retrieved with state() and password() and user() methods. + */ + +class CredentialStore : public QObject +{ + Q_OBJECT +public: + enum CredState { NotFetched = 0, + Ok, + Fetching, + AsyncFetching, + EntryNotFound, + AccessDenied, + NoKeychainBackend, + Error, + AsyncWriting }; + + enum CredentialType { + Settings = 0, + KeyChain + }; + + QString password( ) const; + QString user( ) const; + + /** + * @brief state + * @return the state of the Credentialstore. + */ + CredState state(); + + /** + * @brief fetchCredentials - start to retrieve user credentials. + * + * This method must be called first to retrieve the credentials. + * At the end, this method emits the fetchKeyChainFinished() signal. + */ + void fetchCredentials(); + + /** + * @brief instance - singleton pointer. + * @return the singleton pointer to access the object. + */ + static CredentialStore *instance(); + + /** + * @brief setCredentials - sets the user credentials. + * + * This function is called from the setup wizard to set the credentials + * int this store. Note that it does not store the password. + * The function also sets the state to ok. + * @param url - the connection url + * @param user - the user name + */ + void setCredentials( const QString& url, const QString& user, const QString& pwd); + + void saveCredentials( ); + + QString errorMessage(); + + void reset(); +signals: + /** + * @brief fetchCredentialsFinished + * + * emitted as soon as the fetching of the credentials has finished. + * If the parameter is true, there is a password and user. This does + * however, not say if the credentials are valid log in data. + * If false, the user pressed cancel. + */ + void fetchCredentialsFinished(bool); + +protected slots: + void slotKeyChainReadFinished( QKeychain::Job* ); + void slotKeyChainWriteFinished( QKeychain::Job* ); + +private: + explicit CredentialStore(QObject *parent = 0); + void deleteKeyChainCredential( const QString& ); + QString keyChainKey( const QString& ) const; + + static CredentialStore *_instance; + static CredState _state; + static QString _passwd; + static QString _user; + static QString _url; + static QString _errorMsg; + static CredentialType _type; +}; +} + +#endif // CREDENTIALSTORE_H diff --git a/src/creds/http/httpconfigfile.cpp b/src/creds/http/httpconfigfile.cpp new file mode 100644 index 000000000..366b6c1ee --- /dev/null +++ b/src/creds/http/httpconfigfile.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 "creds/http/httpconfigfile.h" + +namespace Mirall +{ + +namespace +{ + +const char userC[] = "user"; +const char passwdC[] = "passwd"; +const char oldPasswdC[] = "password"; + +} // ns + +QString HttpConfigFile::user() const +{ + return retrieveData(QString(), QLatin1String(userC)).toString(); +} + +void HttpConfigFile::setUser(const QString& user) +{ + storeData(QString(), QLatin1String(userC), QVariant(user)); +} + +QString HttpConfigFile::password() const +{ + const QVariant passwd(retrieveData(QString(), QLatin1String(passwdC))); + + if (passwd.isValid()) { + return QString::fromUtf8(QByteArray::fromBase64(passwd.toByteArray())); + } + + return QString(); +} + +void HttpConfigFile::setPassword(const QString& password) +{ + QByteArray pwdba = password.toUtf8(); + storeData( QString(), QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); + removeOldPassword(); +} + +bool HttpConfigFile::passwordExists() const +{ + dataExists(QString(), QLatin1String(passwdC)); +} + +void HttpConfigFile::removePassword() +{ + removeOldPassword(); + removeData(QString(), QLatin1String(passwdC)); +} + +void HttpConfigFile::fixupOldPassword() +{ + const QString old(QString::fromLatin1(oldPasswdC)); + + if (dataExists(QString(), old)) { + setPassword(retrieveData(QString(), old).toString()); + } +}; + +void HttpConfigFile::removeOldPassword() +{ + removeData(QString(), QLatin1String(oldPasswdC)); +} + +} // ns Mirall diff --git a/src/creds/http/httpconfigfile.h b/src/creds/http/httpconfigfile.h new file mode 100644 index 000000000..2e690054f --- /dev/null +++ b/src/creds/http/httpconfigfile.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_CREDS_HTTP_CONFIG_FILE_H +#define MIRALL_CREDS_HTTP_CONFIG_FILE_H + +#include "mirall/mirallconfigfile.h" + +namespace Mirall +{ + +class HttpConfigFile : public MirallConfigFile +{ +public: + QString user() const; + void setUser(const QString& user); + + QString password() const; + void setPassword(const QString& password); + bool passwordExists() const; + void removePassword(); + void fixupOldPassword(); + +private: + void removeOldPassword(); +}; + +} // ns Mirall + +#endif diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp new file mode 100644 index 000000000..2e4fa272e --- /dev/null +++ b/src/creds/httpcredentials.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +#include "creds/httpcredentials.h" +#include "mirall/owncloudinfo.h" +#include "mirall/mirallconfigfile.h" +#include "mirall/utility.h" +#include "creds/http/credentialstore.h" + +namespace Mirall +{ + +namespace +{ + +int getauth(const char *prompt, + char *buf, + size_t len, + int echo, + int verify, + void *userdata) +{ + int re = 0; + QMutex mutex; + MirallConfigFile cfg; + HttpCredentials* http_credentials = dynamic_cast< HttpCredentials* > (cfg.getCredentials()); + + if (!http_credentials) { + qDebug() << "Not a HTTP creds instance!"; + return -1; + } + + QString qPrompt = QString::fromLatin1( prompt ).trimmed(); + QString user = http_credentials->user(); + QString pwd = http_credentials->password(); + + if( qPrompt == QLatin1String("Enter your username:") ) { + // qDebug() << "OOO Username requested!"; + QMutexLocker locker( &mutex ); + qstrncpy( buf, user.toUtf8().constData(), len ); + } else if( qPrompt == QLatin1String("Enter your password:") ) { + QMutexLocker locker( &mutex ); + // qDebug() << "OOO Password requested!"; + qstrncpy( buf, pwd.toUtf8().constData(), len ); + } else { + if( qPrompt.startsWith( QLatin1String("There are problems with the SSL certificate:"))) { + // SSL is requested. If the program came here, the SSL check was done by mirall + // It needs to be checked if the chain is still equal to the one which + // was verified by the user. + QRegExp regexp("fingerprint: ([\\w\\d:]+)"); + bool certOk = false; + + int pos = 0; + + // This is the set of certificates which QNAM accepted, so we should accept + // them as well + QList certs = ownCloudInfo::instance()->certificateChain(); + + while (!certOk && (pos = regexp.indexIn(qPrompt, 1+pos)) != -1) { + QString neon_fingerprint = regexp.cap(1); + + foreach( const QSslCertificate& c, certs ) { + QString verified_shasum = Utility::formatFingerprint(c.digest(QCryptographicHash::Sha1).toHex()); + qDebug() << "SSL Fingerprint from neon: " << neon_fingerprint << " compared to verified: " << verified_shasum; + if( verified_shasum == neon_fingerprint ) { + certOk = true; + break; + } + } + } + // certOk = false; DEBUG setting, keep disabled! + if( !certOk ) { // Problem! + qstrcpy( buf, "no" ); + re = -1; + } else { + qstrcpy( buf, "yes" ); // Certificate is fine! + } + } else { + qDebug() << "Unknown prompt: <" << prompt << ">"; + re = -1; + } + } + return re; +} + +} // ns + +HttpCredentials::HttpCredentials() + : _user(), + _password(), + _ready(false), + _attempts() +{} + +HttpCredentials::HttpCredentials(const QString& user, const QString& password) + : _user(user), + _password(password), + _ready(true) +{} + +void HttpCredentials::syncContextPreInit (CSYNC* ctx) +{ + csync_set_auth_callback (ctx, getauth); +} + +void HttpCredentials::syncContextPreStart (CSYNC* ctx) +{ + // TODO: This should not be a part of this method, but we don't have + // 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 cookies(ownCloudInfo::instance()->getLastAuthCookies()); + QString cookiesAsString; + + // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply + // when https://github.com/owncloud/core/pull/4042 is merged. + foreach(QNetworkCookie c, cookies) { + cookiesAsString += c.name(); + cookiesAsString += '='; + cookiesAsString += c.value(); + cookiesAsString += "; "; + } + + csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); +} + +bool HttpCredentials::changed(AbstractCredentials* credentials) const +{ + HttpCredentials* other(dynamic_cast< HttpCredentials* >(credentials)); + + if (!other || other->user() != this->user()) { + return true; + } + + return false; +} + +QString HttpCredentials::authType() const +{ + return QString::fromLatin1("http"); +} + +QString HttpCredentials::user() const +{ + return _user; +} + +QString HttpCredentials::password() const +{ + return _password; +} + +QNetworkAccessManager* HttpCredentials::getQNAM() const +{ + QNetworkAccessManager* qnam = new QNetworkAccessManager; + + connect( qnam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), + this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*))); + + return qnam; +} + +bool HttpCredentials::ready() const +{ + return _ready; +} + +void HttpCredentials::fetch() +{ + if (_ready) { + Q_EMIT fetched(); + } else { + // TODO: merge CredentialStore into HttpCredentials? + CredentialStore* store(CredentialStore::instance()); + connect(store, SIGNAL(fetchCredentialsFinished(bool)), + this, SLOT(slotCredentialsFetched(bool))); + store->fetchCredentials(); + } +} + +void HttpCredentials::persistForUrl(const QString& url) +{ + CredentialStore* store(CredentialStore::instance()); + store->setCredentials(url, _user, _password); + store->saveCredentials(); +} + +void HttpCredentials::slotCredentialsFetched(bool ok) +{ + _ready = ok; + if (_ready) { + CredentialStore* store(CredentialStore::instance()); + _user = store->user(); + _password = store->password(); + } + Q_EMIT fetched(); +} + +void HttpCredentials::slotAuthentication(QNetworkReply* reply, QAuthenticator* authenticator) +{ + if( !(authenticator && reply) ) return; + + qDebug() << "Authenticating request for " << reply->url(); + + if (_attempts.contains(reply)) { + ++_attempts[reply]; + } else { + connect(reply, SIGNAL(finished()), + this, SLOT(slotReplyFinished())); + _attempts[reply] = 1; + } + // TODO: Replace it with something meaningful... + //if( reply->url().toString().startsWith( webdavUrl( _connection ) ) ) { + if (_attempts[reply] > 1) { + qDebug() << "Too many attempts to authenticate. Stop request."; + reply->close(); + } else { + authenticator->setUser( _user ); + authenticator->setPassword( _password ); + } + //} else { + // qDebug() << "WRN: attempt to authenticate to different url - closing."; + // reply->close(); + //} +} + +void HttpCredentials::slotReplyFinished() +{ + QNetworkReply* reply = qobject_cast< QNetworkReply* >(sender()); + + disconnect(reply, SIGNAL(finished()), + this, SLOT(slotReplyFinished())); + _attempts.remove (reply); +} + +} // ns Mirall diff --git a/src/creds/httpcredentials.h b/src/creds/httpcredentials.h new file mode 100644 index 000000000..07d52640e --- /dev/null +++ b/src/creds/httpcredentials.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_CREDS_HTTP_CREDENTIALS_H +#define MIRALL_CREDS_HTTP_CREDENTIALS_H + +#include + +#include "creds/abstractcredentials.h" + +class QNetworkReply; +class QAuthenticator; + +namespace Mirall +{ + +class HttpCredentials : public AbstractCredentials +{ + Q_OBJECT + +public: + HttpCredentials(); + HttpCredentials(const QString& user, const QString& password); + + void syncContextPreInit(CSYNC* ctx); + void syncContextPreStart(CSYNC* ctx); + bool changed(AbstractCredentials* credentials) const; + QString authType() const; + QNetworkAccessManager* getQNAM() const; + bool ready() const; + void fetch(); + void persistForUrl(const QString& url); + + QString user() const; + QString password() const; + +private Q_SLOTS: + void slotCredentialsFetched(bool); + void slotAuthentication(QNetworkReply*, QAuthenticator*); + void slotReplyFinished(); + +private: + QString _user; + QString _password; + bool _ready; + QMap _attempts; +}; + +} // ns Mirall + +#endif diff --git a/src/creds/shibboleth/shibbolethaccessmanager.cpp b/src/creds/shibboleth/shibbolethaccessmanager.cpp new file mode 100644 index 000000000..2a5461307 --- /dev/null +++ b/src/creds/shibboleth/shibbolethaccessmanager.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 + +#include "creds/shibboleth/shibbolethaccessmanager.h" + +namespace Mirall +{ + +ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent) + : QNetworkAccessManager (parent), + _cookie(cookie) +{} + +QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) +{ + QNetworkRequest newRequest(request); + QList cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >()); + + cookies << _cookie; + newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies)); + + return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); +} + +} // ns Mirall diff --git a/src/creds/shibboleth/shibbolethaccessmanager.h b/src/creds/shibboleth/shibbolethaccessmanager.h new file mode 100644 index 000000000..9f0571d21 --- /dev/null +++ b/src/creds/shibboleth/shibbolethaccessmanager.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H +#define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H + +#include +#include + +namespace Mirall +{ + +class ShibbolethAccessManager : public QNetworkAccessManager +{ + Q_OBJECT + +public: + ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0); + +protected: + QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); + +private: + QNetworkCookie _cookie; +}; + +} // ns Mirall + +#endif diff --git a/src/creds/shibboleth/shibbolethcookiejar.cpp b/src/creds/shibboleth/shibbolethcookiejar.cpp new file mode 100644 index 000000000..ad86d6ca6 --- /dev/null +++ b/src/creds/shibboleth/shibbolethcookiejar.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 "creds/shibboleth/shibbolethcookiejar.h" + +namespace Mirall +{ + +ShibbolethCookieJar::ShibbolethCookieJar (QObject* parent) + : QNetworkCookieJar (parent) +{} + +bool ShibbolethCookieJar::setCookiesFromUrl (const QList& cookieList, const QUrl& url) +{ + if (QNetworkCookieJar::setCookiesFromUrl (cookieList, url)) { + Q_EMIT newCookiesForUrl (cookieList, url); + + return true; + } + + return false; +} + +} // ns Mirall diff --git a/src/creds/shibboleth/shibbolethcookiejar.h b/src/creds/shibboleth/shibbolethcookiejar.h new file mode 100644 index 000000000..4e4459ba5 --- /dev/null +++ b/src/creds/shibboleth/shibbolethcookiejar.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H +#define MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H + +#include +#include + +class QUrl; +class QNetworkCookie; + +namespace Mirall +{ + +class ShibbolethCookieJar : public QNetworkCookieJar +{ + Q_OBJECT + +public: + ShibbolethCookieJar (QObject* parent = 0); + + virtual bool setCookiesFromUrl (const QList& cookieList, const QUrl& url); + +Q_SIGNALS: + void newCookiesForUrl (const QList& cookieList, const QUrl& url); +}; + +} // ns Mirall + +#endif diff --git a/src/creds/shibboleth/shibbolethwebview.cpp b/src/creds/shibboleth/shibbolethwebview.cpp new file mode 100644 index 000000000..b1ebc5f97 --- /dev/null +++ b/src/creds/shibboleth/shibbolethwebview.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 +#include +#include + +#include "creds/shibboleth/shibbolethcookiejar.h" +#include "creds/shibboleth/shibbolethwebview.h" + +namespace Mirall +{ + +ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) + : QWebView(parent) +{ + ShibbolethCookieJar* jar = new ShibbolethCookieJar(this); + QWebPage* page = new QWebPage(this); + + connect (jar, SIGNAL (newCookiesForUrl (QList, QUrl)), + this, SLOT (onNewCookiesForUrl (QList, QUrl))); + + page->networkAccessManager()->setCookieJar(jar); + page->mainFrame ()->load (url); + this->setPage (page); +} + +void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& url) +{ + Q_FOREACH (const QNetworkCookie& cookie, cookieList) { + if (cookie.name().startsWith ("_shibsession_")) { + Q_EMIT shibbolethCookieReceived (cookie); + + return; + } + } +} + +} // ns Mirall diff --git a/src/creds/shibboleth/shibbolethwebview.h b/src/creds/shibboleth/shibbolethwebview.h new file mode 100644 index 000000000..9fc1179b9 --- /dev/null +++ b/src/creds/shibboleth/shibbolethwebview.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H +#define MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H + +#include +#include + +class QNetworkCookie; +class QUrl; + +namespace Mirall +{ + +class ShibbolethWebView : public QWebView +{ + Q_OBJECT + +public: + ShibbolethWebView(const QUrl& url, QWidget* parent = 0); + +Q_SIGNALS: + void shibbolethCookieReceived (const QNetworkCookie& cookie); + +private Q_SLOTS: + void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); +}; + +} // ns Mirall + +#endif diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp new file mode 100644 index 000000000..056f2c821 --- /dev/null +++ b/src/creds/shibbolethcredentials.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) by Krzesimir Nowak + * Copyright (C) by Klaas Freitag + * + * 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 "creds/shibbolethcredentials.h" +#include "creds/shibboleth/shibbolethaccessmanager.h" +#include "creds/shibboleth/shibbolethwebview.h" +#include "mirall/owncloudinfo.h" +#include "mirall/mirallconfigfile.h" + +namespace Mirall +{ + +ShibbolethCredentials::ShibbolethCredentials() + : _shibCookie(), + _ready(false), + _browser(0) +{} + +ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie) + : _shibCookie(cookie), + _ready(true), + _browser(0) +{} + +void ShibbolethCredentials::syncContextPreInit (CSYNC*) +{} + +void ShibbolethCredentials::syncContextPreStart (CSYNC* ctx) +{ + QString cookiesAsString; + // TODO: This should not be a part of this method, but we don't + // have any way to get "session_key" module property from + // csync. Had we have it, then we could just append shibboleth + // cookies to the "session_key" value and set it in csync module. + QList cookies(ownCloudInfo::instance()->getLastAuthCookies()); + + cookies << _shibCookie; + // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply + // when https://github.com/owncloud/core/pull/4042 is merged. + foreach(QNetworkCookie c, cookies) { + cookiesAsString += c.name(); + cookiesAsString += '='; + cookiesAsString += c.value(); + cookiesAsString += "; "; + } + + csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); +} + +bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const +{ + ShibbolethCredentials* other(dynamic_cast< ShibbolethCredentials* >(credentials)); + + if (!other || other->cookie() != this->cookie()) { + return true; + } + + return false; +} + +QString ShibbolethCredentials::authType() const +{ + return QString::fromLatin1("shibboleth"); +} + +QNetworkCookie ShibbolethCredentials::cookie() const +{ + return _shibCookie; +} + +QNetworkAccessManager* ShibbolethCredentials::getQNAM() const +{ + return new ShibbolethAccessManager(_shibCookie); +} + +bool ShibbolethCredentials::ready() const +{ + return _ready; +} + +void ShibbolethCredentials::fetch() +{ + if (_ready) { + Q_EMIT fetched(); + } else { + MirallConfigFile cfg; + + _browser = new ShibbolethWebView(QUrl(cfg.ownCloudUrl())); + connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + _browser->show (); + } +} + +void ShibbolethCredentials::persistForUrl(const QString& url) +{ + // nothing to do here, we don't store session cookies. +} + +void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& cookie) +{ + _browser->hide(); + disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + _browser->deleteLater(); + _browser = 0; + _ready = true; + _shibCookie = cookie; + Q_EMIT fetched(); +} + +} // ns Mirall diff --git a/src/creds/shibbolethcredentials.h b/src/creds/shibbolethcredentials.h new file mode 100644 index 000000000..a2ed78084 --- /dev/null +++ b/src/creds/shibbolethcredentials.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H +#define MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H + +#include + +#include "creds/abstractcredentials.h" + +namespace Mirall +{ + +class ShibbolethWebView; + +class ShibbolethCredentials : public AbstractCredentials +{ +Q_OBJECT + +public: + ShibbolethCredentials(); + ShibbolethCredentials(const QNetworkCookie& cookie); + + void syncContextPreInit(CSYNC* ctx); + void syncContextPreStart(CSYNC* ctx); + bool changed(AbstractCredentials* credentials) const; + QString authType() const; + QNetworkAccessManager* getQNAM() const; + bool ready() const; + void fetch(); + void persistForUrl(const QString& url); + + QNetworkCookie cookie() const; + +private Q_SLOTS: + void onShibbolethCookieReceived(const QNetworkCookie& cookie); + +private: + QNetworkCookie _shibCookie; + bool _ready; + ShibbolethWebView* _browser; +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 11e487403..09ca5927f 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -36,7 +36,7 @@ #include "mirall/inotify.h" #include "mirall/connectionvalidator.h" -#include "mirall/creds/abstractcredentials.h" +#include "creds/abstractcredentials.h" #if defined(Q_OS_WIN) #include diff --git a/src/mirall/creds/abstractcredentials.h b/src/mirall/creds/abstractcredentials.h deleted file mode 100644 index 1e589ddae..000000000 --- a/src/mirall/creds/abstractcredentials.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_CREDS_ABSTRACT_CREDENTIALS_H -#define MIRALL_CREDS_ABSTRACT_CREDENTIALS_H - -#include - -#include - -class QNetworkAccessManager; - -namespace Mirall -{ - -class AbstractCredentials : public QObject -{ - Q_OBJECT - -public: - // No need for virtual destructor - QObject already has one. - virtual void syncContextPreInit(CSYNC* ctx) = 0; - virtual void syncContextPreStart(CSYNC* ctx) = 0; - virtual bool changed(AbstractCredentials* credentials) const = 0; - virtual QString authType() const = 0; - virtual QNetworkAccessManager* getQNAM() const = 0; - virtual bool ready() const = 0; - virtual void fetch() = 0; - virtual void persistForUrl(const QString& url) = 0; - -Q_SIGNALS: - void fetched(); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/credentialsfactory.cpp b/src/mirall/creds/credentialsfactory.cpp deleted file mode 100644 index 2cb8eaa24..000000000 --- a/src/mirall/creds/credentialsfactory.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 - -#include "mirall/creds/httpcredentials.h" -#include "mirall/creds/dummycredentials.h" -#include "mirall/creds/shibbolethcredentials.h" - -namespace Mirall -{ - -namespace CredentialsFactory -{ - -AbstractCredentials* create(const QString& type) -{ - // empty string might happen for old version of configuration - if (type == "http" || type == "") { - return new HttpCredentials; - } else if (type == "dummy") { - return new DummyCredentials; - } else if (type == "shibboleth") { - return new ShibbolethCredentials; - } else { - qWarning("Unknown credentials type: %d", qPrintable(type)); - return new DummyCredentials; - } -} - -} // ns CredentialsFactory - -} // ns Mirall diff --git a/src/mirall/creds/credentialsfactory.h b/src/mirall/creds/credentialsfactory.h deleted file mode 100644 index a34f94b77..000000000 --- a/src/mirall/creds/credentialsfactory.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_CREDS_CREDENTIALS_FACTORY_H -#define MIRALL_CREDS_CREDENTIALS_FACTORY_H - -class AbstractCredentials; -class QString; - -namespace Mirall -{ - -namespace CredentialsFactory -{ - -AbstractCredentials* create(const QString& type); - -} // ns CredentialsFactory - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/dummycredentials.cpp b/src/mirall/creds/dummycredentials.cpp deleted file mode 100644 index 2318af9d8..000000000 --- a/src/mirall/creds/dummycredentials.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 - -#include "dummycredentials.h" - -namespace Mirall -{ - -void DummyCredentials::syncContextPreInit(CSYNC*) -{} - -void DummyCredentials::syncContextPreStart(CSYNC*) -{} - -bool DummyCredentials::changed(AbstractCredentials* credentials) const -{ - DummyCredentials* dummy(dynamic_cast< DummyCredentials* >(credentials)); - - return dummy == 0; -} - -QString DummyCredentials::authType() const -{ - return QString::fromLatin1("dummy"); -} - -QNetworkAccessManager* DummyCredentials::getQNAM() const -{ - return new QNetworkAccessManager; -} - -bool DummyCredentials::ready() const -{ - return true; -} - -void DummyCredentials::fetch() -{ - Q_EMIT(fetched()); -} - -void DummyCredentials::persistForUrl(const QString&) -{} - -} // ns Mirall diff --git a/src/mirall/creds/dummycredentials.h b/src/mirall/creds/dummycredentials.h deleted file mode 100644 index 026fab791..000000000 --- a/src/mirall/creds/dummycredentials.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_CREDS_DUMMY_CREDENTIALS_H -#define MIRALL_CREDS_DUMMY_CREDENTIALS_H - -#include "mirall/creds/abstractcredentials.h" - -namespace Mirall -{ - -class DummyCredentials : public AbstractCredentials -{ - Q_OBJECT - -public: - void syncContextPreInit(CSYNC* ctx); - void syncContextPreStart(CSYNC* ctx); - bool changed(AbstractCredentials* credentials) const; - QString authType() const; - QNetworkAccessManager* getQNAM() const; - bool ready() const; - void fetch(); - void persistForUrl(const QString& url); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/http/credentialstore.cpp b/src/mirall/creds/http/credentialstore.cpp deleted file mode 100644 index e8387ab3d..000000000 --- a/src/mirall/creds/http/credentialstore.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (C) by Klaas Freitag - * - * 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 -#include - -#include "config.h" - -#include "mirall/creds/http/credentialstore.h" -#include "mirall/creds/http/httpconfigfile.h" -#include "mirall/theme.h" - -#ifdef WITH_QTKEYCHAIN -#include -using namespace QKeychain; -#endif - -#define MAX_LOGIN_ATTEMPTS 3 - -namespace Mirall { - -CredentialStore *CredentialStore::_instance=0; -CredentialStore::CredState CredentialStore::_state = NotFetched; -QString CredentialStore::_passwd = QString::null; -QString CredentialStore::_user = QString::null; -QString CredentialStore::_url = QString::null; -QString CredentialStore::_errorMsg = QString::null; -#ifdef WITH_QTKEYCHAIN -CredentialStore::CredentialType CredentialStore::_type = KeyChain; -#else -CredentialStore::CredentialType CredentialStore::_type = Settings; -#endif - -CredentialStore::CredentialStore(QObject *parent) : - QObject(parent) -{ -} - -CredentialStore *CredentialStore::instance() -{ - if( !CredentialStore::_instance ) CredentialStore::_instance = new CredentialStore; - return CredentialStore::_instance; -} - -QString CredentialStore::password() const -{ - return _passwd; -} -QString CredentialStore::user() const -{ - return _user; -} - -CredentialStore::CredState CredentialStore::state() -{ - return _state; -} - -void CredentialStore::fetchCredentials() -{ - HttpConfigFile cfgFile; - - bool ok = false; - QString pwd; - _user = cfgFile.user(); - _url = cfgFile.ownCloudUrl(); - - QString key = keyChainKey(_url); - - if( key.isNull() ) { - qDebug() << "Can not fetch credentials, url is zero!"; - _state = Error; - emit( fetchCredentialsFinished(false) ); - return; - } - - switch( _type ) { - case CredentialStore::Settings: { - /* Read from config file. */ - _state = Fetching; - cfgFile.fixupOldPassword(); - if( cfgFile.passwordExists() ) { - pwd = cfgFile.password(); - ok = true; - } else { - ok = false; - _state = EntryNotFound; - } - break; - } - case CredentialStore::KeyChain: { - // If the credentials are here already, return. - if( _state == Ok || _state == AsyncWriting ) { - emit(fetchCredentialsFinished(true)); - return; - } - // otherwise fetch asynchronious. -#ifdef WITH_QTKEYCHAIN - _state = AsyncFetching; - if( !_user.isEmpty() ) { - ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName()); - job->setKey( key ); - - connect( job, SIGNAL(finished(QKeychain::Job*)), this, - SLOT(slotKeyChainReadFinished(QKeychain::Job*))); - job->start(); - } -#else - qDebug() << "QtKeyChain: Not yet implemented!"; - _state = Error; -#endif - break; - } - default: { - break; - } - } - - if( _state == Fetching ) { // ...but not AsyncFetching - if( ok ) { - _passwd = pwd; - _state = Ok; - } - if( !ok && _state == Fetching ) { - _state = Error; - } - - emit( fetchCredentialsFinished(ok) ); - } else { - // in case of AsyncFetching nothing happens here. The finished-Slot - // will emit the finish signal. - } -} - -void CredentialStore::reset() -{ - _state = NotFetched; - _user = QString::null; - _passwd = QString::null; -} - -QString CredentialStore::keyChainKey( const QString& url ) const -{ - QString u(url); - if( u.isEmpty() ) { - qDebug() << "Empty url in keyChain, error!"; - return QString::null; - } - if( _user.isEmpty() ) { - qDebug() << "Error: User is emty!"; - return QString::null; - } - - if( !u.endsWith(QChar('/')) ) { - u.append(QChar('/')); - } - - QString key = _user+QLatin1Char(':')+u; - return key; -} - -void CredentialStore::slotKeyChainReadFinished(QKeychain::Job* job) -{ -#ifdef WITH_QTKEYCHAIN - ReadPasswordJob *pwdJob = static_cast(job); - if( pwdJob ) { - switch( pwdJob->error() ) { - case QKeychain::NoError: - _passwd = pwdJob->textData(); -#ifdef Q_OS_LINUX - // Currently there is a bug in the keychain on linux that if no - // entry is there, an empty password comes back, but no error. - if( _passwd.isEmpty() ) { - _state = EntryNotFound; - _errorMsg = tr("No password entry found in keychain. Please reconfigure."); - } else -#endif - _state = Ok; - break; - case QKeychain::EntryNotFound: - _state = EntryNotFound; - break; - case QKeychain::CouldNotDeleteEntry: - _state = Error; - break; - case QKeychain::AccessDenied: - _state = AccessDenied; - break; - case QKeychain::NoBackendAvailable: - _state = NoKeychainBackend; - break; - case QKeychain::NotImplemented: - _state = NoKeychainBackend; - break; - case QKeychain::OtherError: - default: - _state = Error; - - } - /* In case there is no backend, tranparentely switch to Settings file. */ - if( _state == NoKeychainBackend ) { - qDebug() << "No Storage Backend, falling back to Settings mode."; - _type = CredentialStore::Settings; - fetchCredentials(_user); - return; - } - - if( _state == EntryNotFound ) { - // try to migrate. - } - - if( _state != Ok ) { - qDebug() << "Error with keychain: " << pwdJob->errorString(); - if(_errorMsg.isEmpty()) _errorMsg = pwdJob->errorString(); - } else { - _errorMsg = QString::null; - } - } else { - _state = Error; - qDebug() << "Error: KeyChain Read Password Job failed!"; - } - emit(fetchCredentialsFinished(_state == Ok)); -#else - (void) job; -#endif -} - -QString CredentialStore::errorMessage() -{ - return _errorMsg; -} - -void CredentialStore::setCredentials( const QString& url, const QString& user, - const QString& pwd ) -{ - _passwd = pwd; - _user = user; -#ifdef WITH_QTKEYCHAIN - _type = KeyChain; -#else - _type = Settings; -#endif - _url = url; - _state = Ok; -} - -void CredentialStore::saveCredentials( ) -{ - HttpConfigFile cfgFile; - QString key = keyChainKey(_url); - if( key.isNull() ) { - qDebug() << "Error: Can not save credentials, URL is zero!"; - return; - } -#ifdef WITH_QTKEYCHAIN -#endif - - cfgFile.setUser(_user); - switch( _type ) { - case CredentialStore::KeyChain: { -#ifdef WITH_QTKEYCHAIN - WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName()); - // Set password in KeyChain - job->setKey( key ); - job->setTextData(_passwd); - - connect( job, SIGNAL(finished(QKeychain::Job*)), this, - SLOT(slotKeyChainWriteFinished(QKeychain::Job*))); - _state = AsyncWriting; - job->start(); -#endif - } - break; - case CredentialStore::Settings: - cfgFile.setPassword( _passwd ); - reset(); - break; - default: - // unsupported. - break; - } -} - -void CredentialStore::slotKeyChainWriteFinished( QKeychain::Job *job ) -{ -#ifdef WITH_QTKEYCHAIN - WritePasswordJob *pwdJob = static_cast(job); - if( pwdJob ) { - QKeychain::Error err = pwdJob->error(); - - if( err != QKeychain::NoError ) { - qDebug() << "Error with keychain: " << pwdJob->errorString(); - if( err == NoBackendAvailable || err == NotImplemented || - pwdJob->errorString().contains(QLatin1String("Could not open wallet"))) { - _state = NoKeychainBackend; - _type = Settings; - saveCredentials(); - } else { - _state = Error; - } - } else { - qDebug() << "Successfully stored password for user " << _user; - // Try to remove password formerly stored in the config file. - HttpConfigFile cfgFile; - cfgFile.removePassword(); - _state = NotFetched; - } - } else { - qDebug() << "Error: KeyChain Write Password Job failed!"; - _state = Error; - } -#else - (void) job; -#endif -} - -// Called if a user chooses to not store the password locally. -void CredentialStore::deleteKeyChainCredential( const QString& key ) -{ -#ifdef WITH_QTKEYCHAIN - // Start the remove job, do not care so much about the result. - DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName()); - job->setKey( key ); - job->start(); -#endif -} - -} diff --git a/src/mirall/creds/http/credentialstore.h b/src/mirall/creds/http/credentialstore.h deleted file mode 100644 index 2732e603c..000000000 --- a/src/mirall/creds/http/credentialstore.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) by Klaas Freitag - * - * 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 CREDENTIALSTORE_H -#define CREDENTIALSTORE_H - -#include -#include - -namespace QKeychain { - class Job; -} - -namespace Mirall { - -/* - * This object holds the credential information of the ownCloud connection. It - * is implemented as a singleton. - * At startup of the client, at first the fetchCredentials() method must be called - * which tries to get credentials from one of the supported backends. To determine - * which backend should be used, MirallConfigFile::credentialType() is called as - * the backend is configured in the config file. - * - * The fetchCredentials() call changes the internal state of the credential store - * to one of - * Ok: There are credentials. Note that it's unknown if they are correct!! - * Fetching: The fetching is not yet finished. - * EntryNotFound: No password entry found in the storage. - * Error: A general error happened. - * After fetching has finished, signal fetchCredentialsFinished(bool) is emitted. - * The result can be retrieved with state() and password() and user() methods. - */ - -class CredentialStore : public QObject -{ - Q_OBJECT -public: - enum CredState { NotFetched = 0, - Ok, - Fetching, - AsyncFetching, - EntryNotFound, - AccessDenied, - NoKeychainBackend, - Error, - AsyncWriting }; - - enum CredentialType { - Settings = 0, - KeyChain - }; - - QString password( ) const; - QString user( ) const; - - /** - * @brief state - * @return the state of the Credentialstore. - */ - CredState state(); - - /** - * @brief fetchCredentials - start to retrieve user credentials. - * - * This method must be called first to retrieve the credentials. - * At the end, this method emits the fetchKeyChainFinished() signal. - */ - void fetchCredentials(); - - /** - * @brief instance - singleton pointer. - * @return the singleton pointer to access the object. - */ - static CredentialStore *instance(); - - /** - * @brief setCredentials - sets the user credentials. - * - * This function is called from the setup wizard to set the credentials - * int this store. Note that it does not store the password. - * The function also sets the state to ok. - * @param url - the connection url - * @param user - the user name - */ - void setCredentials( const QString& url, const QString& user, const QString& pwd); - - void saveCredentials( ); - - QString errorMessage(); - - void reset(); -signals: - /** - * @brief fetchCredentialsFinished - * - * emitted as soon as the fetching of the credentials has finished. - * If the parameter is true, there is a password and user. This does - * however, not say if the credentials are valid log in data. - * If false, the user pressed cancel. - */ - void fetchCredentialsFinished(bool); - -protected slots: - void slotKeyChainReadFinished( QKeychain::Job* ); - void slotKeyChainWriteFinished( QKeychain::Job* ); - -private: - explicit CredentialStore(QObject *parent = 0); - void deleteKeyChainCredential( const QString& ); - QString keyChainKey( const QString& ) const; - - static CredentialStore *_instance; - static CredState _state; - static QString _passwd; - static QString _user; - static QString _url; - static QString _errorMsg; - static CredentialType _type; -}; -} - -#endif // CREDENTIALSTORE_H diff --git a/src/mirall/creds/http/httpconfigfile.cpp b/src/mirall/creds/http/httpconfigfile.cpp deleted file mode 100644 index 7be998495..000000000 --- a/src/mirall/creds/http/httpconfigfile.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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/creds/http/httpconfigfile.h" - -namespace Mirall -{ - -namespace -{ - -const char userC[] = "user"; -const char passwdC[] = "passwd"; -const char oldPasswdC[] = "password"; - -} // ns - -QString HttpConfigFile::user() const -{ - return retrieveData(QString(), QLatin1String(userC)).toString(); -} - -void HttpConfigFile::setUser(const QString& user) -{ - storeData(QString(), QLatin1String(userC), QVariant(user)); -} - -QString HttpConfigFile::password() const -{ - const QVariant passwd(retrieveData(QString(), QLatin1String(passwdC))); - - if (passwd.isValid()) { - return QString::fromUtf8(QByteArray::fromBase64(passwd.toByteArray())); - } - - return QString(); -} - -void HttpConfigFile::setPassword(const QString& password) -{ - QByteArray pwdba = password.toUtf8(); - storeData( QString(), QLatin1String(passwdC), QVariant(pwdba.toBase64()) ); - removeOldPassword(); -} - -bool HttpConfigFile::passwordExists() const -{ - dataExists(QString(), QLatin1String(passwdC)); -} - -void HttpConfigFile::removePassword() -{ - removeOldPassword(); - removeData(QString(), QLatin1String(passwdC)); -} - -void HttpConfigFile::fixupOldPassword() -{ - const QString old(QString::fromLatin1(oldPasswdC)); - - if (dataExists(QString(), old)) { - setPassword(retrieveData(QString(), old).toString()); - } -}; - -void HttpConfigFile::removeOldPassword() -{ - removeData(QString(), QLatin1String(oldPasswdC)); -} - -} // ns Mirall diff --git a/src/mirall/creds/http/httpconfigfile.h b/src/mirall/creds/http/httpconfigfile.h deleted file mode 100644 index 2e690054f..000000000 --- a/src/mirall/creds/http/httpconfigfile.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_CREDS_HTTP_CONFIG_FILE_H -#define MIRALL_CREDS_HTTP_CONFIG_FILE_H - -#include "mirall/mirallconfigfile.h" - -namespace Mirall -{ - -class HttpConfigFile : public MirallConfigFile -{ -public: - QString user() const; - void setUser(const QString& user); - - QString password() const; - void setPassword(const QString& password); - bool passwordExists() const; - void removePassword(); - void fixupOldPassword(); - -private: - void removeOldPassword(); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/httpcredentials.cpp b/src/mirall/creds/httpcredentials.cpp deleted file mode 100644 index 1db14c153..000000000 --- a/src/mirall/creds/httpcredentials.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - -#include "mirall/creds/httpcredentials.h" -#include "mirall/owncloudinfo.h" -#include "mirall/mirallconfigfile.h" -#include "mirall/utility.h" -#include "mirall/creds/http/credentialstore.h" - -namespace Mirall -{ - -namespace -{ - -int getauth(const char *prompt, - char *buf, - size_t len, - int echo, - int verify, - void *userdata) -{ - int re = 0; - QMutex mutex; - MirallConfigFile cfg; - HttpCredentials* http_credentials = dynamic_cast< HttpCredentials* > (cfg.getCredentials()); - - if (!http_credentials) { - qDebug() << "Not a HTTP creds instance!"; - return -1; - } - - QString qPrompt = QString::fromLatin1( prompt ).trimmed(); - QString user = http_credentials->user(); - QString pwd = http_credentials->password(); - - if( qPrompt == QLatin1String("Enter your username:") ) { - // qDebug() << "OOO Username requested!"; - QMutexLocker locker( &mutex ); - qstrncpy( buf, user.toUtf8().constData(), len ); - } else if( qPrompt == QLatin1String("Enter your password:") ) { - QMutexLocker locker( &mutex ); - // qDebug() << "OOO Password requested!"; - qstrncpy( buf, pwd.toUtf8().constData(), len ); - } else { - if( qPrompt.startsWith( QLatin1String("There are problems with the SSL certificate:"))) { - // SSL is requested. If the program came here, the SSL check was done by mirall - // It needs to be checked if the chain is still equal to the one which - // was verified by the user. - QRegExp regexp("fingerprint: ([\\w\\d:]+)"); - bool certOk = false; - - int pos = 0; - - // This is the set of certificates which QNAM accepted, so we should accept - // them as well - QList certs = ownCloudInfo::instance()->certificateChain(); - - while (!certOk && (pos = regexp.indexIn(qPrompt, 1+pos)) != -1) { - QString neon_fingerprint = regexp.cap(1); - - foreach( const QSslCertificate& c, certs ) { - QString verified_shasum = Utility::formatFingerprint(c.digest(QCryptographicHash::Sha1).toHex()); - qDebug() << "SSL Fingerprint from neon: " << neon_fingerprint << " compared to verified: " << verified_shasum; - if( verified_shasum == neon_fingerprint ) { - certOk = true; - break; - } - } - } - // certOk = false; DEBUG setting, keep disabled! - if( !certOk ) { // Problem! - qstrcpy( buf, "no" ); - re = -1; - } else { - qstrcpy( buf, "yes" ); // Certificate is fine! - } - } else { - qDebug() << "Unknown prompt: <" << prompt << ">"; - re = -1; - } - } - return re; -} - -} // ns - -HttpCredentials::HttpCredentials() - : _user(), - _password(), - _ready(false), - _attempts() -{} - -HttpCredentials::HttpCredentials(const QString& user, const QString& password) - : _user(user), - _password(password), - _ready(true) -{} - -void HttpCredentials::syncContextPreInit (CSYNC* ctx) -{ - csync_set_auth_callback (ctx, getauth); -} - -void HttpCredentials::syncContextPreStart (CSYNC* ctx) -{ - // TODO: This should not be a part of this method, but we don't have - // 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 cookies(ownCloudInfo::instance()->getLastAuthCookies()); - QString cookiesAsString; - - // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply - // when https://github.com/owncloud/core/pull/4042 is merged. - foreach(QNetworkCookie c, cookies) { - cookiesAsString += c.name(); - cookiesAsString += '='; - cookiesAsString += c.value(); - cookiesAsString += "; "; - } - - csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); -} - -bool HttpCredentials::changed(AbstractCredentials* credentials) const -{ - HttpCredentials* other(dynamic_cast< HttpCredentials* >(credentials)); - - if (!other || other->user() != this->user()) { - return true; - } - - return false; -} - -QString HttpCredentials::authType() const -{ - return QString::fromLatin1("http"); -} - -QString HttpCredentials::user() const -{ - return _user; -} - -QString HttpCredentials::password() const -{ - return _password; -} - -QNetworkAccessManager* HttpCredentials::getQNAM() const -{ - QNetworkAccessManager* qnam = new QNetworkAccessManager; - - connect( qnam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), - this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*))); - - return qnam; -} - -bool HttpCredentials::ready() const -{ - return _ready; -} - -void HttpCredentials::fetch() -{ - if (_ready) { - Q_EMIT fetched(); - } else { - // TODO: merge CredentialStore into HttpCredentials? - CredentialStore* store(CredentialStore::instance()); - connect(store, SIGNAL(fetchCredentialsFinished(bool)), - this, SLOT(slotCredentialsFetched(bool))); - store->fetchCredentials(); - } -} - -void HttpCredentials::persistForUrl(const QString& url) -{ - CredentialStore* store(CredentialStore::instance()); - store->setCredentials(url, _user, _password); - store->saveCredentials(); -} - -void HttpCredentials::slotCredentialsFetched(bool ok) -{ - _ready = ok; - if (_ready) { - CredentialStore* store(CredentialStore::instance()); - _user = store->user(); - _password = store->password(); - } - Q_EMIT fetched(); -} - -void HttpCredentials::slotAuthentication(QNetworkReply* reply, QAuthenticator* authenticator) -{ - if( !(authenticator && reply) ) return; - - qDebug() << "Authenticating request for " << reply->url(); - - if (_attempts.contains(reply)) { - ++_attempts[reply]; - } else { - connect(reply, SIGNAL(finished()), - this, SLOT(slotReplyFinished())); - _attempts[reply] = 1; - } - // TODO: Replace it with something meaningful... - //if( reply->url().toString().startsWith( webdavUrl( _connection ) ) ) { - if (_attempts[reply] > 1) { - qDebug() << "Too many attempts to authenticate. Stop request."; - reply->close(); - } else { - authenticator->setUser( _user ); - authenticator->setPassword( _password ); - } - //} else { - // qDebug() << "WRN: attempt to authenticate to different url - closing."; - // reply->close(); - //} -} - -void HttpCredentials::slotReplyFinished() -{ - QNetworkReply* reply = qobject_cast< QNetworkReply* >(sender()); - - disconnect(reply, SIGNAL(finished()), - this, SLOT(slotReplyFinished())); - _attempts.remove (reply); -} - -} // ns Mirall diff --git a/src/mirall/creds/httpcredentials.h b/src/mirall/creds/httpcredentials.h deleted file mode 100644 index f1c74e02b..000000000 --- a/src/mirall/creds/httpcredentials.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_CREDS_HTTP_CREDENTIALS_H -#define MIRALL_CREDS_HTTP_CREDENTIALS_H - -#include - -#include "mirall/creds/abstractcredentials.h" - -class QNetworkReply; -class QAuthenticator; - -namespace Mirall -{ - -class HttpCredentials : public AbstractCredentials -{ - Q_OBJECT - -public: - HttpCredentials(); - HttpCredentials(const QString& user, const QString& password); - - void syncContextPreInit(CSYNC* ctx); - void syncContextPreStart(CSYNC* ctx); - bool changed(AbstractCredentials* credentials) const; - QString authType() const; - QNetworkAccessManager* getQNAM() const; - bool ready() const; - void fetch(); - void persistForUrl(const QString& url); - - QString user() const; - QString password() const; - -private Q_SLOTS: - void slotCredentialsFetched(bool); - void slotAuthentication(QNetworkReply*, QAuthenticator*); - void slotReplyFinished(); - -private: - QString _user; - QString _password; - bool _ready; - QMap _attempts; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp b/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp deleted file mode 100644 index c70f6d872..000000000 --- a/src/mirall/creds/shibboleth/shibbolethaccessmanager.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 - -#include "mirall/creds/shibboleth/shibbolethaccessmanager.h" - -namespace Mirall -{ - -ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent) - : QNetworkAccessManager (parent), - _cookie(cookie) -{} - -QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) -{ - QNetworkRequest newRequest(request); - QList cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >()); - - cookies << _cookie; - newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies)); - - return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); -} - -} // ns Mirall diff --git a/src/mirall/creds/shibboleth/shibbolethaccessmanager.h b/src/mirall/creds/shibboleth/shibbolethaccessmanager.h deleted file mode 100644 index 9f0571d21..000000000 --- a/src/mirall/creds/shibboleth/shibbolethaccessmanager.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H -#define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H - -#include -#include - -namespace Mirall -{ - -class ShibbolethAccessManager : public QNetworkAccessManager -{ - Q_OBJECT - -public: - ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0); - -protected: - QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); - -private: - QNetworkCookie _cookie; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp b/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp deleted file mode 100644 index e683fb53e..000000000 --- a/src/mirall/creds/shibboleth/shibbolethcookiejar.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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/creds/shibboleth/shibbolethcookiejar.h" - -namespace Mirall -{ - -ShibbolethCookieJar::ShibbolethCookieJar (QObject* parent) - : QNetworkCookieJar (parent) -{} - -bool ShibbolethCookieJar::setCookiesFromUrl (const QList& cookieList, const QUrl& url) -{ - if (QNetworkCookieJar::setCookiesFromUrl (cookieList, url)) { - Q_EMIT newCookiesForUrl (cookieList, url); - - return true; - } - - return false; -} - -} // ns Mirall diff --git a/src/mirall/creds/shibboleth/shibbolethcookiejar.h b/src/mirall/creds/shibboleth/shibbolethcookiejar.h deleted file mode 100644 index 4e4459ba5..000000000 --- a/src/mirall/creds/shibboleth/shibbolethcookiejar.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H -#define MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H - -#include -#include - -class QUrl; -class QNetworkCookie; - -namespace Mirall -{ - -class ShibbolethCookieJar : public QNetworkCookieJar -{ - Q_OBJECT - -public: - ShibbolethCookieJar (QObject* parent = 0); - - virtual bool setCookiesFromUrl (const QList& cookieList, const QUrl& url); - -Q_SIGNALS: - void newCookiesForUrl (const QList& cookieList, const QUrl& url); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/shibboleth/shibbolethwebview.cpp b/src/mirall/creds/shibboleth/shibbolethwebview.cpp deleted file mode 100644 index 8ad80a2af..000000000 --- a/src/mirall/creds/shibboleth/shibbolethwebview.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 -#include -#include - -#include "mirall/creds/shibboleth/shibbolethcookiejar.h" -#include "mirall/creds/shibboleth/shibbolethwebview.h" - -namespace Mirall -{ - -ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) - : QWebView(parent) -{ - ShibbolethCookieJar* jar = new ShibbolethCookieJar(this); - QWebPage* page = new QWebPage(this); - - connect (jar, SIGNAL (newCookiesForUrl (QList, QUrl)), - this, SLOT (onNewCookiesForUrl (QList, QUrl))); - - page->networkAccessManager()->setCookieJar(jar); - page->mainFrame ()->load (url); - this->setPage (page); -} - -void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& url) -{ - Q_FOREACH (const QNetworkCookie& cookie, cookieList) { - if (cookie.name().startsWith ("_shibsession_")) { - Q_EMIT shibbolethCookieReceived (cookie); - - return; - } - } -} - -} // ns Mirall diff --git a/src/mirall/creds/shibboleth/shibbolethwebview.h b/src/mirall/creds/shibboleth/shibbolethwebview.h deleted file mode 100644 index 9fc1179b9..000000000 --- a/src/mirall/creds/shibboleth/shibbolethwebview.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H -#define MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H - -#include -#include - -class QNetworkCookie; -class QUrl; - -namespace Mirall -{ - -class ShibbolethWebView : public QWebView -{ - Q_OBJECT - -public: - ShibbolethWebView(const QUrl& url, QWidget* parent = 0); - -Q_SIGNALS: - void shibbolethCookieReceived (const QNetworkCookie& cookie); - -private Q_SLOTS: - void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/creds/shibbolethcredentials.cpp b/src/mirall/creds/shibbolethcredentials.cpp deleted file mode 100644 index 7c42b5bf6..000000000 --- a/src/mirall/creds/shibbolethcredentials.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * Copyright (C) by Klaas Freitag - * - * 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/creds/shibbolethcredentials.h" -#include "mirall/creds/shibboleth/shibbolethaccessmanager.h" -#include "mirall/creds/shibboleth/shibbolethwebview.h" -#include "mirall/owncloudinfo.h" -#include "mirall/mirallconfigfile.h" - -namespace Mirall -{ - -ShibbolethCredentials::ShibbolethCredentials() - : _shibCookie(), - _ready(false), - _browser(0) -{} - -ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie) - : _shibCookie(cookie), - _ready(true), - _browser(0) -{} - -void ShibbolethCredentials::syncContextPreInit (CSYNC*) -{} - -void ShibbolethCredentials::syncContextPreStart (CSYNC* ctx) -{ - QString cookiesAsString; - // TODO: This should not be a part of this method, but we don't - // have any way to get "session_key" module property from - // csync. Had we have it, then we could just append shibboleth - // cookies to the "session_key" value and set it in csync module. - QList cookies(ownCloudInfo::instance()->getLastAuthCookies()); - - cookies << _shibCookie; - // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply - // when https://github.com/owncloud/core/pull/4042 is merged. - foreach(QNetworkCookie c, cookies) { - cookiesAsString += c.name(); - cookiesAsString += '='; - cookiesAsString += c.value(); - cookiesAsString += "; "; - } - - csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); -} - -bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const -{ - ShibbolethCredentials* other(dynamic_cast< ShibbolethCredentials* >(credentials)); - - if (!other || other->cookie() != this->cookie()) { - return true; - } - - return false; -} - -QString ShibbolethCredentials::authType() const -{ - return QString::fromLatin1("shibboleth"); -} - -QNetworkCookie ShibbolethCredentials::cookie() const -{ - return _shibCookie; -} - -QNetworkAccessManager* ShibbolethCredentials::getQNAM() const -{ - return new ShibbolethAccessManager(_shibCookie); -} - -bool ShibbolethCredentials::ready() const -{ - return _ready; -} - -void ShibbolethCredentials::fetch() -{ - if (_ready) { - Q_EMIT fetched(); - } else { - MirallConfigFile cfg; - - _browser = new ShibbolethWebView(QUrl(cfg.ownCloudUrl())); - connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), - this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - _browser->show (); - } -} - -void ShibbolethCredentials::persistForUrl(const QString& url) -{ - // nothing to do here, we don't store session cookies. -} - -void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& cookie) -{ - _browser->hide(); - disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), - this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - _browser->deleteLater(); - _browser = 0; - _ready = true; - _shibCookie = cookie; - Q_EMIT fetched(); -} - -} // ns Mirall diff --git a/src/mirall/creds/shibbolethcredentials.h b/src/mirall/creds/shibbolethcredentials.h deleted file mode 100644 index a70a16960..000000000 --- a/src/mirall/creds/shibbolethcredentials.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H -#define MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H - -#include - -#include "mirall/creds/abstractcredentials.h" - -namespace Mirall -{ - -class ShibbolethWebView; - -class ShibbolethCredentials : public AbstractCredentials -{ -Q_OBJECT - -public: - ShibbolethCredentials(); - ShibbolethCredentials(const QNetworkCookie& cookie); - - void syncContextPreInit(CSYNC* ctx); - void syncContextPreStart(CSYNC* ctx); - bool changed(AbstractCredentials* credentials) const; - QString authType() const; - QNetworkAccessManager* getQNAM() const; - bool ready() const; - void fetch(); - void persistForUrl(const QString& url); - - QNetworkCookie cookie() const; - -private Q_SLOTS: - void onShibbolethCookieReceived(const QNetworkCookie& cookie); - -private: - QNetworkCookie _shibCookie; - bool _ready; - ShibbolethWebView* _browser; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 2f91f4bb9..ca9cc9045 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -18,7 +18,7 @@ #include "mirall/theme.h" #include "mirall/logger.h" #include "mirall/owncloudinfo.h" -#include "mirall/creds/abstractcredentials.h" +#include "creds/abstractcredentials.h" #ifdef Q_OS_WIN #include diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index b8baaad81..a11a410af 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -21,7 +21,7 @@ #include "mirall/syncresult.h" #include "mirall/logger.h" #include "mirall/owncloudinfo.h" -#include "mirall/creds/abstractcredentials.h" +#include "creds/abstractcredentials.h" #include #include diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index 4b4c75391..81a7c5671 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -18,8 +18,8 @@ #include "mirall/owncloudinfo.h" #include "mirall/owncloudtheme.h" #include "mirall/theme.h" -#include "mirall/creds/abstractcredentials.h" -#include "mirall/creds/credentialsfactory.h" +#include "creds/abstractcredentials.h" +#include "creds/credentialsfactory.h" #include #include diff --git a/src/mirall/owncloudhttpcredspage.ui b/src/mirall/owncloudhttpcredspage.ui deleted file mode 100644 index 35f539a25..000000000 --- a/src/mirall/owncloudhttpcredspage.ui +++ /dev/null @@ -1,130 +0,0 @@ - - - OwncloudHttpCredsPage - - - - 0 - 0 - 350 - 196 - - - - Form - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 20 - - - - - - - - - - &Username - - - leUsername - - - - - - - &Password - - - lePassword - - - - - - - Error Label - - - - - - - - - - QLineEdit::Password - - - - - - - - - Qt::Vertical - - - - 20 - 68 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 20 - - - - - - - - - - - TextLabel - - - - - - - TextLabel - - - - - horizontalSpacer - verticalSpacer - horizontalSpacer_2 - horizontalLayoutWidget - topLabel - bottomLabel - - - - diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index 5d6aaac5e..7f0b85269 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -17,7 +17,7 @@ #include "mirall/theme.h" #include "mirall/utility.h" #include "mirall/logger.h" -#include "mirall/creds/abstractcredentials.h" +#include "creds/abstractcredentials.h" #include #include diff --git a/src/mirall/owncloudsetupnocredspage.ui b/src/mirall/owncloudsetupnocredspage.ui deleted file mode 100644 index 5e08a64b1..000000000 --- a/src/mirall/owncloudsetupnocredspage.ui +++ /dev/null @@ -1,417 +0,0 @@ - - - OwncloudSetupPage - - - - 0 - 0 - 583 - 498 - - - - - 0 - 0 - - - - Form - - - - QLayout::SetMinimumSize - - - - - - 0 - 0 - - - - TextLabel - - - Qt::AlignCenter - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 68 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 13 - - - - - - - - 0 - - - - - - - true - - - - 0 - - - 0 - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - - 0 - 0 - - - - &Local Folder - - - pbSelectLocalFolder - - - - - - - - 0 - 0 - - - - pbSelectLocalFolder - - - - - - - - QLayout::SetMinimumSize - - - QFormLayout::ExpandingFieldsGrow - - - - - &Keep local data - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - <small>Syncs your existing data to new location.</small> - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - 0 - - - - - - - <html><head/><body><p>If this box is checked, existing content in the local directory will be erased to start a clean sync from the server.</p><p>Do not check this if the local content should be uploaded to the servers directory.</p></body></html> - - - &Start a clean sync - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - <small>Erases the contents of the local folder before syncing using the new settings.</small> - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - 0 - - - - - - - - - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Server &Address - - - leUrl - - - - - - - - 0 - 0 - - - - Enter the url of the ownCloud you want to connect to (without http or https). - - - https://... - - - - - - - - 0 - 0 - - - - Error Label - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 13 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Advanced &Settings - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Status message - - - Qt::AlignCenter - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 58 - - - - - - - - TextLabel - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - - - - - - Utils::FancyLineEdit - QLineEdit -
fancylineedit.h
-
-
- - -
diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index eaf3d28d2..faffeb8f6 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -19,14 +19,15 @@ #include #include -#include "mirall/wizard/owncloudwizardcommon.h" +#include "wizard/owncloudwizardcommon.h" +#include "wizard/owncloudwizard.h" #include "mirall/owncloudsetupwizard.h" #include "mirall/mirallconfigfile.h" #include "mirall/owncloudinfo.h" #include "mirall/folderman.h" #include "mirall/utility.h" -#include "mirall/creds/abstractcredentials.h" -#include "mirall/creds/dummycredentials.h" +#include "creds/abstractcredentials.h" +#include "creds/dummycredentials.h" namespace Mirall { diff --git a/src/mirall/owncloudsetupwizard.h b/src/mirall/owncloudsetupwizard.h index 540255dce..aeec7f2af 100644 --- a/src/mirall/owncloudsetupwizard.h +++ b/src/mirall/owncloudsetupwizard.h @@ -21,7 +21,6 @@ #include #include -#include "mirall/wizard/owncloudwizard.h" #include "mirall/theme.h" namespace Mirall { @@ -29,6 +28,7 @@ namespace Mirall { class SiteCopyFolder; class SyncResult; class ownCloudInfo; +class OwncloudWizard; class OwncloudSetupWizard : public QObject { diff --git a/src/mirall/owncloudshibbolethcredspage.ui b/src/mirall/owncloudshibbolethcredspage.ui deleted file mode 100644 index 832d7eb44..000000000 --- a/src/mirall/owncloudshibbolethcredspage.ui +++ /dev/null @@ -1,121 +0,0 @@ - - - OwncloudShibbolethCredsPage - - - - 0 - 0 - 640 - 451 - - - - Form - - - - - - QLayout::SetMaximumSize - - - - - TextLabel - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 45 - 17 - - - - - - - - - - - 0 - 0 - - - - Error Label - - - - - - - info label - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 20 - - - - - - - - - - Qt::Vertical - - - - 17 - 38 - - - - - - - - TextLabel - - - - - - - horizontalSpacer - verticalSpacer - horizontalSpacer_2 - topLabel - bottomLabel - errorLabel_2 - - - - diff --git a/src/mirall/owncloudwizardresultpage.ui b/src/mirall/owncloudwizardresultpage.ui deleted file mode 100644 index 917900971..000000000 --- a/src/mirall/owncloudwizardresultpage.ui +++ /dev/null @@ -1,162 +0,0 @@ - - - OwncloudWizardResultPage - - - - 0 - 0 - 469 - 325 - - - - Form - - - - - - TextLabel - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 20 - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 16 - - - - - - - - Your entire account is synced to the local folder - - - true - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 16 - - - - - - - - - - - 160 - 80 - - - - PushButton - - - Qt::ToolButtonTextUnderIcon - - - - - - - - 160 - 80 - - - - PushButton - - - Qt::ToolButtonTextUnderIcon - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 20 - - - - - - - - - - - diff --git a/src/mirall/wizard/abstractcredswizardpage.h b/src/mirall/wizard/abstractcredswizardpage.h deleted file mode 100644 index 0579f0c05..000000000 --- a/src/mirall/wizard/abstractcredswizardpage.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_WIZARD_ABSTRACT_CREDS_WIZARD_PAGE_H -#define MIRALL_WIZARD_ABSTRACT_CREDS_WIZARD_PAGE_H - -#include - -namespace Mirall -{ - -class AbstractCredentials; - -class AbstractCredentialsWizardPage : public QWizardPage -{ -public: - virtual AbstractCredentials* getCredentials() const = 0; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/wizard/owncloudhttpcredspage.cpp b/src/mirall/wizard/owncloudhttpcredspage.cpp deleted file mode 100644 index 72dc21d3f..000000000 --- a/src/mirall/wizard/owncloudhttpcredspage.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 "QProgressIndicator.h" - -#include "mirall/wizard/owncloudhttpcredspage.h" -#include "mirall/theme.h" -#include "mirall/wizard/owncloudwizardcommon.h" -#include "mirall/creds/httpcredentials.h" - -namespace Mirall -{ - -OwncloudHttpCredsPage::OwncloudHttpCredsPage() - : AbstractCredentialsWizardPage(), - _ui(), - _connected(false), - _checking(false), - _progressIndi(new QProgressIndicator (this)) -{ - _ui.setupUi(this); - - registerField( QLatin1String("OCUser*"), _ui.leUsername); - registerField( QLatin1String("OCPasswd*"), _ui.lePassword); - - setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); - setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Enter user credentials"))); - - _ui.resultLayout->addWidget( _progressIndi ); - stopSpinner(); - setupCustomization(); -} - -void OwncloudHttpCredsPage::setupCustomization() -{ - // set defaults for the customize labels. - _ui.topLabel->hide(); - _ui.bottomLabel->hide(); - - Theme *theme = Theme::instance(); - QVariant variant = theme->customMedia( Theme::oCSetupTop ); - if( !variant.isNull() ) { - WizardCommon::setupCustomMedia( variant, _ui.topLabel ); - } - - variant = theme->customMedia( Theme::oCSetupBottom ); - WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); -} - -void OwncloudHttpCredsPage::initializePage() -{ - WizardCommon::initErrorLabel(_ui.errorLabel); - _ui.leUsername->setFocus(); -} - -void OwncloudHttpCredsPage::cleanupPage() -{ - _ui.leUsername->clear(); - _ui.lePassword->clear(); -} - -bool OwncloudHttpCredsPage::validatePage() -{ - if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) { - return false; - } - - if (!_connected) { - _checking = true; - emit completeChanged(); - emit connectToOCUrl(field("OCUrl").toString().simplified()); - - return false; - } else { - _checking = false; - emit completeChanged(); - return true; - } - return true; -} - -int OwncloudHttpCredsPage::nextId() const -{ - return WizardCommon::Page_Result; -} - -void OwncloudHttpCredsPage::setConnected( bool comp ) -{ - _connected = comp; - stopSpinner (); -} - -void OwncloudHttpCredsPage::startSpinner() -{ - _ui.resultLayout->setEnabled(true); - _progressIndi->setVisible(true); - _progressIndi->startAnimation(); -} - -void OwncloudHttpCredsPage::stopSpinner() -{ - _ui.resultLayout->setEnabled(false); - _progressIndi->setVisible(false); - _progressIndi->stopAnimation(); -} - -void OwncloudHttpCredsPage::setOCUser(const QString& user) -{ - _ui.leUsername->setText(user); -} - -void OwncloudHttpCredsPage::setErrorString(const QString& err) -{ - if( err.isEmpty()) { - _ui.errorLabel->setVisible(false); - } else { - _ui.errorLabel->setVisible(true); - _ui.errorLabel->setText(err); - } - _checking = false; - emit completeChanged(); - stopSpinner(); -} - -AbstractCredentials* OwncloudHttpCredsPage::getCredentials() const -{ - return new HttpCredentials(_ui.leUsername->text(), _ui.lePassword->text()); -} - -} // ns Mirall diff --git a/src/mirall/wizard/owncloudhttpcredspage.h b/src/mirall/wizard/owncloudhttpcredspage.h deleted file mode 100644 index 2cb28ad81..000000000 --- a/src/mirall/wizard/owncloudhttpcredspage.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H -#define MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H - -#include "mirall/wizard/abstractcredswizardpage.h" - -#include "ui_owncloudhttpcredspage.h" - -class QProgressIndicator; - -namespace Mirall { - -class OwncloudHttpCredsPage : public AbstractCredentialsWizardPage -{ - Q_OBJECT -public: - OwncloudHttpCredsPage(); - - AbstractCredentials* getCredentials() const; - - void setOCUser(const QString& user); - void initializePage(); - void cleanupPage(); - bool validatePage(); - int nextId() const; - void setConnected(bool connected); - void setErrorString( const QString& err ); - -Q_SIGNALS: - void connectToOCUrl(const QString&); - -private: - void startSpinner(); - void stopSpinner(); - void setupCustomization(); - - Ui_OwncloudHttpCredsPage _ui; - bool _connected; - bool _checking; - QProgressIndicator* _progressIndi; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/wizard/owncloudsetuppage.cpp b/src/mirall/wizard/owncloudsetuppage.cpp deleted file mode 100644 index 2aec63556..000000000 --- a/src/mirall/wizard/owncloudsetuppage.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 -#include -#include - -#include "QProgressIndicator.h" - -#include "mirall/wizard/owncloudwizardcommon.h" -#include "mirall/wizard/owncloudsetuppage.h" -#include "mirall/theme.h" - -namespace Mirall -{ - -OwncloudSetupPage::OwncloudSetupPage() - : QWizardPage(), - _ui(), - _oCUrl(), - _ocUser(), - _authTypeKnown(false), - _checking(false), - _multipleFoldersExist(false), - _authType(WizardCommon::HttpCreds), - _progressIndi(new QProgressIndicator (this)), - _selectiveSyncButtons(0), - _remoteFolder() -{ - _ui.setupUi(this); - - Theme *theme = Theme::instance(); - setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(theme->appNameGUI()))); - setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Setup ownCloud server"))); - - registerField( QLatin1String("OCUrl*"), _ui.leUrl ); - registerField( QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch); - - _ui.advancedBox->setVisible(false); - - _ui.resultLayout->addWidget( _progressIndi ); - stopSpinner(); - - setupCustomization(); - - connect(_ui.leUrl, SIGNAL(textChanged(QString)), SLOT(slotUrlChanged(QString))); - connect( _ui.cbAdvanced, SIGNAL(stateChanged (int)), SLOT(slotToggleAdvanced(int))); - connect( _ui.pbSelectLocalFolder, SIGNAL(clicked()), SLOT(slotSelectFolder())); -} - -void OwncloudSetupPage::slotToggleAdvanced(int state) -{ - _ui.advancedBox->setVisible( state == Qt::Checked ); - slotHandleUserInput(); - QSize size = wizard()->sizeHint(); - // need to substract header for some reason - size -= QSize(0, 63); - - wizard()->setMinimumSize(size); - wizard()->resize(size); -} - -void OwncloudSetupPage::setServerUrl( const QString& newUrl ) -{ - _oCUrl = newUrl; - if( _oCUrl.isEmpty() ) { - _ui.leUrl->clear(); - return; - } - - _ui.leUrl->setText( _oCUrl ); -} - -void OwncloudSetupPage::setupCustomization() -{ - // set defaults for the customize labels. - _ui.topLabel->hide(); - _ui.bottomLabel->hide(); - - Theme *theme = Theme::instance(); - QVariant variant = theme->customMedia( Theme::oCSetupTop ); - if( !variant.isNull() ) { - WizardCommon::setupCustomMedia( variant, _ui.topLabel ); - } - - variant = theme->customMedia( Theme::oCSetupBottom ); - WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); - - QString fixUrl = theme->overrideServerUrl(); - if( !fixUrl.isEmpty() ) { - _ui.label_2->hide(); - setServerUrl( fixUrl ); - _ui.leUrl->setEnabled( false ); - _ui.leUrl->hide(); - } -} - -// slot hit from textChanged of the url entry field. -void OwncloudSetupPage::slotUrlChanged(const QString& ocUrl) -{ - slotHandleUserInput(); - -#if 0 - QString url = ocUrl; - bool visible = false; - - if (url.startsWith(QLatin1String("https://"))) { - _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-high.png")); - _ui.urlLabel->setToolTip(tr("This url is secure. You can use it.")); - visible = true; - } - if (url.startsWith(QLatin1String("http://"))) { - _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-low.png")); - _ui.urlLabel->setToolTip(tr("This url is NOT secure. You should not use it."));W - visible = true; - } -#endif -} - -bool OwncloudSetupPage::isComplete() const -{ - return !_ui.leUrl->text().isEmpty() && !_checking; -} - -void OwncloudSetupPage::initializePage() -{ - WizardCommon::initErrorLabel(_ui.errorLabel); - - _authTypeKnown = false; - _checking = false; - _multipleFoldersExist = false; - - // call to init label - slotHandleUserInput(); - - _ui.leUrl->setFocus(); -} - -bool OwncloudSetupPage::urlHasChanged() -{ - bool change = false; - const QChar slash('/'); - - QUrl currentUrl( url() ); - QUrl initialUrl( _oCUrl ); - - QString currentPath = currentUrl.path(); - QString initialPath = initialUrl.path(); - - // add a trailing slash. - if( ! currentPath.endsWith( slash )) currentPath += slash; - if( ! initialPath.endsWith( slash )) initialPath += slash; - - if( currentUrl.host() != initialUrl.host() || - currentUrl.port() != initialUrl.port() || - currentPath != initialPath ) { - change = true; - } - - return change; -} - -// Called if the user changes the user- or url field. Adjust the texts and -// evtl. warnings on the dialog. -void OwncloudSetupPage::slotHandleUserInput() -{ - // if the url has not changed, return. - if( ! urlHasChanged() ) { - // disable the advanced button as nothing has changed. - _ui.cbAdvanced->setEnabled(false); - _ui.advancedBox->setEnabled(false); - } else { - // Enable advanced stuff for new connection configuration. - _ui.cbAdvanced->setEnabled(true); - _ui.advancedBox->setEnabled(true); - } - - const QString locFolder = localFolder(); - - // check if the local folder exists. If so, and if its not empty, show a warning. - QDir dir( locFolder ); - QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot); - - QString t; - - if( !urlHasChanged() && _configExists ) { - // This is the password change mode: No change to the url and a config - // to an ownCloud exists. - t = tr("Press Next to change the Password for your configured account."); - } else { - // Complete new setup. - _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); - - if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { - t = tr("Your entire account will be synced to the local folder '%1'.") - .arg(QDir::toNativeSeparators(locFolder)); - } else { - t = tr("%1 folder '%2' is synced to local folder '%3'") - .arg(Theme::instance()->appName()).arg(_remoteFolder) - .arg(QDir::toNativeSeparators(locFolder)); - } - - if ( _multipleFoldersExist ) { - t += tr("

Warning: You currently have multiple folders " - "configured. If you continue with the current settings, the folder configurations " - "will be discarded and a single root folder sync will be created!

"); - } - - if( entries.count() > 0) { - // the directory is not empty - if (!_ui.cbAdvanced->isChecked()) { - t += tr("

Warning: The local directory is not empty. " - "Pick a resolution in the advanced settings!

"); - } - _ui.resolutionWidget->setVisible(true); - } else { - // the dir is empty, which means that there is no problem. - _ui.resolutionWidget->setVisible(false); - } - } - - _ui.syncModeLabel->setText(t); - _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); -} - -int OwncloudSetupPage::nextId() const -{ - if (_authType == WizardCommon::HttpCreds) { - return WizardCommon::Page_HttpCreds; - } else { - return WizardCommon::Page_ShibbolethCreds; - } -} - -QString OwncloudSetupPage::url() const -{ - QString url = _ui.leUrl->text().simplified(); - return url; -} - -QString OwncloudSetupPage::localFolder() const -{ - QString folder = wizard()->property("localFolder").toString(); - return folder; -} - -bool OwncloudSetupPage::validatePage() -{ - bool re = false; - - if( ! _authTypeKnown) { - setErrorString(QString::null); - _checking = true; - startSpinner (); - emit completeChanged(); - - emit determineAuthType(url()); - return false; - } else { - // connecting is running - stopSpinner(); - _checking = false; - emit completeChanged(); - return true; - } -} - -void OwncloudSetupPage::setAuthType (WizardCommon::AuthType type) -{ - _authTypeKnown = true; - _authType = type; - stopSpinner(); -} - -void OwncloudSetupPage::setErrorString( const QString& err ) -{ - if( err.isEmpty()) { - _ui.errorLabel->setVisible(false); - } else { - _ui.errorLabel->setVisible(true); - _ui.errorLabel->setText(err); - } - _checking = false; - emit completeChanged(); - stopSpinner(); -} - -void OwncloudSetupPage::startSpinner() -{ - _ui.resultLayout->setEnabled(true); - _progressIndi->setVisible(true); - _progressIndi->startAnimation(); -} - -void OwncloudSetupPage::stopSpinner() -{ - _ui.resultLayout->setEnabled(false); - _progressIndi->setVisible(false); - _progressIndi->stopAnimation(); -} - -WizardCommon::SyncMode OwncloudSetupPage::syncMode() -{ - return WizardCommon::BoxMode; -} - -void OwncloudSetupPage::setRemoteFolder( const QString& remoteFolder ) -{ - if( !remoteFolder.isEmpty() ) { - _remoteFolder = remoteFolder; - } -} - -void OwncloudSetupPage::setMultipleFoldersExist(bool exist) -{ - _multipleFoldersExist = exist; -} - -void OwncloudSetupPage::slotSelectFolder() -{ - QString dir = QFileDialog::getExistingDirectory(0, tr("Local Sync Folder"), QDir::homePath()); - if( !dir.isEmpty() ) { - _ui.pbSelectLocalFolder->setText(dir); - wizard()->setProperty("localFolder", dir); - slotHandleUserInput(); - } -} - -void OwncloudSetupPage::setConfigExists( bool config ) -{ - _configExists = config; - - if (config == true) { - setSubTitle( tr("Change your user credentials") - .arg(Theme::instance()->wizardHeaderTitleColor().name())); - } -} - -} // ns Mirall diff --git a/src/mirall/wizard/owncloudsetuppage.h b/src/mirall/wizard/owncloudsetuppage.h deleted file mode 100644 index 36f84c9a4..000000000 --- a/src/mirall/wizard/owncloudsetuppage.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_OWNCLOUD_SETUP_PAGE_H -#define MIRALL_OWNCLOUD_SETUP_PAGE_H - -#include - -#include "mirall/wizard/owncloudwizardcommon.h" -#include "ui_owncloudsetupnocredspage.h" - -class QLabel; -class QVariant; -class QProgressIndicator; - -namespace Mirall { - -class OwncloudSetupPage: public QWizardPage -{ - Q_OBJECT -public: - OwncloudSetupPage(); - - virtual bool isComplete() const; - virtual void initializePage(); - virtual int nextId() const; - void setServerUrl( const QString& ); - void setAllowPasswordStorage( bool ); - bool validatePage(); - QString url() const; - QString localFolder() const; - void setRemoteFolder( const QString& remoteFolder); - void setMultipleFoldersExist( bool exist ); - - WizardCommon::SyncMode syncMode(); - void setAuthType(WizardCommon::AuthType type); - -public slots: - void setErrorString( const QString& ); - void setConfigExists( bool ); - void startSpinner(); - void stopSpinner(); - -protected slots: - void slotUrlChanged(const QString&); - - void setupCustomization(); - void slotToggleAdvanced(int state); - void slotSelectFolder(); - -signals: - void determineAuthType(const QString&); - -protected: - void updateFoldersInfo(); - -private slots: - void slotHandleUserInput(); - -private: - bool urlHasChanged(); - - Ui_OwncloudSetupPage _ui; - QString _oCUrl; - QString _ocUser; - bool _authTypeKnown; - bool _checking; - bool _configExists; - bool _multipleFoldersExist; - WizardCommon::AuthType _authType; - - QProgressIndicator* _progressIndi; - QButtonGroup* _selectiveSyncButtons; - QString _remoteFolder; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.cpp b/src/mirall/wizard/owncloudshibbolethcredspage.cpp deleted file mode 100644 index 5384f4128..000000000 --- a/src/mirall/wizard/owncloudshibbolethcredspage.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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/wizard/owncloudshibbolethcredspage.h" -#include "mirall/theme.h" -#include "mirall/wizard/owncloudwizardcommon.h" -#include "mirall/creds/shibbolethcredentials.h" -#include "mirall/creds/shibboleth/shibbolethwebview.h" - -namespace Mirall -{ - -OwncloudShibbolethCredsPage::OwncloudShibbolethCredsPage() - : AbstractCredentialsWizardPage(), - _ui(), - _stage(INITIAL_STEP), - _browser(0), - _cookie() -{ - _ui.setupUi(this); - - setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); - setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Process through Shibboleth form"))); - - setupCustomization(); -} - -void OwncloudShibbolethCredsPage::setupCustomization() -{ - // set defaults for the customize labels. - _ui.topLabel->hide(); - _ui.bottomLabel->hide(); - - Theme *theme = Theme::instance(); - QVariant variant = theme->customMedia( Theme::oCSetupTop ); - if( !variant.isNull() ) { - WizardCommon::setupCustomMedia( variant, _ui.topLabel ); - } - - variant = theme->customMedia( Theme::oCSetupBottom ); - WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); -} - -bool OwncloudShibbolethCredsPage::isComplete() const -{ - return _stage == GOT_COOKIE; -} - -void OwncloudShibbolethCredsPage::initializePage() -{ - WizardCommon::initErrorLabel(_ui.errorLabel); - _browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified()), this); - - connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), - this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - - _ui.contentLayout->insertWidget(0, _browser); - _browser->show(); - _browser->setFocus(); - _ui.infoLabel->show(); - _ui.infoLabel->setText(tr("Please follow the steps on displayed page above")); - _stage = INITIAL_STEP; - _cookie = QNetworkCookie(); -} - -void OwncloudShibbolethCredsPage::disposeBrowser(bool later) -{ - if (_browser) { - _browser->hide(); - disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), - this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - if (later) { - _browser->deleteLater(); - } else { - delete _browser; - } - _browser = 0; - } -} - -void OwncloudShibbolethCredsPage::cleanupPage() -{ - disposeBrowser(false); -} - -bool OwncloudShibbolethCredsPage::validatePage() -{ - switch (_stage) { - case INITIAL_STEP: - return false; - - case GOT_COOKIE: - _stage = CHECKING; - emit completeChanged(); - emit connectToOCUrl(field("OCUrl").toString().simplified()); - return false; - - case CHECKING: - return false; - - case CONNECTED: - return true; - } - - return false; -} - -int OwncloudShibbolethCredsPage::nextId() const -{ - return WizardCommon::Page_Result; -} - -void OwncloudShibbolethCredsPage::setConnected( bool comp ) -{ - if (comp) { - _stage = CONNECTED; - } else { - // sets stage to INITIAL - initializePage(); - } - emit completeChanged(); -} - -void OwncloudShibbolethCredsPage::setErrorString(const QString& err) -{ - if( err.isEmpty()) { - _ui.errorLabel->setVisible(false); - } else { - initializePage(); - _ui.errorLabel->setVisible(true); - _ui.errorLabel->setText(err); - } - emit completeChanged(); -} - -AbstractCredentials* OwncloudShibbolethCredsPage::getCredentials() const -{ - return new ShibbolethCredentials(_cookie); -} - -void OwncloudShibbolethCredsPage::onShibbolethCookieReceived(const QNetworkCookie& cookie) -{ - disposeBrowser(true); - _stage = GOT_COOKIE; - _cookie = cookie; - _ui.infoLabel->setText("Please click \"Connect\" to check received Shibboleth session."); - emit completeChanged(); -} - -} // ns Mirall diff --git a/src/mirall/wizard/owncloudshibbolethcredspage.h b/src/mirall/wizard/owncloudshibbolethcredspage.h deleted file mode 100644 index 0e4fe6277..000000000 --- a/src/mirall/wizard/owncloudshibbolethcredspage.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H -#define MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H - -#include - -#include "mirall/wizard/abstractcredswizardpage.h" - -#include "ui_owncloudshibbolethcredspage.h" - -namespace Mirall { - -class ShibbolethWebView; - -class OwncloudShibbolethCredsPage : public AbstractCredentialsWizardPage -{ - Q_OBJECT -public: - OwncloudShibbolethCredsPage(); - - AbstractCredentials* getCredentials() const; - - bool isComplete() const; - void initializePage(); - void cleanupPage(); - bool validatePage(); - int nextId() const; - void setConnected(bool connected); - void setErrorString(const QString& err); - -Q_SIGNALS: - void connectToOCUrl(const QString&); - -private Q_SLOTS: - void onShibbolethCookieReceived(const QNetworkCookie& cookie); - -private: - enum Stage { - INITIAL_STEP, - GOT_COOKIE, - CHECKING, - CONNECTED - }; - - void setupCustomization(); - void disposeBrowser(bool later); - - Ui_OwncloudShibbolethCredsPage _ui; - Stage _stage; - ShibbolethWebView* _browser; - QNetworkCookie _cookie; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/wizard/owncloudwizard.cpp b/src/mirall/wizard/owncloudwizard.cpp deleted file mode 100644 index 865939342..000000000 --- a/src/mirall/wizard/owncloudwizard.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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/wizard/owncloudwizard.h" -#include "mirall/mirallconfigfile.h" -#include "mirall/theme.h" -#include "mirall/wizard/owncloudsetuppage.h" -#include "mirall/wizard/owncloudhttpcredspage.h" -#include "mirall/wizard/owncloudshibbolethcredspage.h" -#include "mirall/wizard/owncloudwizardresultpage.h" - -#include "QProgressIndicator.h" - -#include -#include - -#include - -namespace Mirall -{ - -OwncloudWizard::OwncloudWizard(QWidget *parent) - : QWizard(parent), - _setupPage(new OwncloudSetupPage), - _httpCredsPage(new OwncloudHttpCredsPage), - _shibbolethCredsPage(new OwncloudShibbolethCredsPage), - _resultPage(new OwncloudWizardResultPage), - _credentialsPage(0), - _configFile(), - _oCUser(), - _setupLog(), - _configExists(false) -{ - setPage(WizardCommon::Page_oCSetup, _setupPage ); - setPage(WizardCommon::Page_HttpCreds, _httpCredsPage); - setPage(WizardCommon::Page_ShibbolethCreds, _shibbolethCredsPage); - setPage(WizardCommon::Page_Result, _resultPage ); - - // note: start Id is set by the calling class depending on if the - // welcome text is to be shown or not. - setWizardStyle( QWizard::ModernStyle ); - - connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int))); - connect( _setupPage, SIGNAL(determineAuthType(QString)), SIGNAL(determineAuthType(QString))); - connect( _httpCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); - connect( _shibbolethCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); - - Theme *theme = Theme::instance(); - setWizardStyle(QWizard::ModernStyle); - setPixmap( QWizard::BannerPixmap, theme->wizardHeaderBanner() ); - setPixmap( QWizard::LogoPixmap, theme->wizardHeaderLogo() ); - setOption( QWizard::NoBackButtonOnStartPage ); - setOption( QWizard::NoBackButtonOnLastPage ); - setOption( QWizard::NoCancelButton ); - setTitleFormat(Qt::RichText); - setSubTitleFormat(Qt::RichText); -} - -WizardCommon::SyncMode OwncloudWizard::syncMode() -{ - return _setupPage->syncMode(); - return WizardCommon::BoxMode; -} - -void OwncloudWizard::setMultipleFoldersExist(bool exist) -{ - _setupPage->setMultipleFoldersExist(exist); -} - -QString OwncloudWizard::localFolder() const -{ - return(_setupPage->localFolder()); -} - -QString OwncloudWizard::ocUrl() const -{ - QString url = field("OCUrl").toString().simplified(); - return url; -} - -void OwncloudWizard::enableFinishOnResultWidget(bool enable) -{ - _resultPage->setComplete(enable); -} - -void OwncloudWizard::setRemoteFolder( const QString& remoteFolder ) -{ - _setupPage->setRemoteFolder( remoteFolder ); - _resultPage->setRemoteFolder( remoteFolder ); -} - -void OwncloudWizard::showConnectInfo( const QString& msg ) -{ - if( _setupPage ) { - _setupPage->setErrorString( msg ); - } -} - -void OwncloudWizard::successfullyConnected(bool enable) -{ - const int id(currentId()); - - switch (id) { - case WizardCommon::Page_HttpCreds: - _httpCredsPage->setConnected( enable ); - break; - - case WizardCommon::Page_ShibbolethCreds: - _shibbolethCredsPage->setConnected( enable ); - break; - - case WizardCommon::Page_oCSetup: - case WizardCommon::Page_Result: - qWarning("Should not happen at this stage."); - break; - } - - if( enable ) { - next(); - } -} - -void OwncloudWizard::setAuthType(WizardCommon::AuthType type) -{ - _setupPage->setAuthType(type); - if (type == WizardCommon::Shibboleth) { - _credentialsPage = _shibbolethCredsPage; - } else { - _credentialsPage = _httpCredsPage; - } - next(); -} - -void OwncloudWizard::slotCurrentPageChanged( int id ) -{ - qDebug() << "Current Wizard page changed to " << id; - - if( id == WizardCommon::Page_oCSetup ) { - setButtonText( QWizard::NextButton, tr("Connect...") ); - emit clearPendingRequests(); - _setupPage->initializePage(); - - } - - if( id == WizardCommon::Page_Result ) { - appendToConfigurationLog( QString::null ); - } -} - -void OwncloudWizard::displayError( const QString& msg ) -{ - int id(currentId()); - - if (id == WizardCommon::Page_oCSetup) { - _setupPage->setErrorString( msg ); - } else if (id == WizardCommon::Page_HttpCreds) { - _httpCredsPage->setErrorString(msg); - } else if (id == WizardCommon::Page_ShibbolethCreds) { - _shibbolethCredsPage->setErrorString(msg); - } -} - -void OwncloudWizard::appendToConfigurationLog( const QString& msg, LogType type ) -{ - _setupLog << msg; - qDebug() << "Setup-Log: " << msg; -} - -void OwncloudWizard::setOCUrl( const QString& url ) -{ - _setupPage->setServerUrl( url ); -} - -void OwncloudWizard::setOCUser( const QString& user ) -{ - _oCUser = user; - _httpCredsPage->setOCUser( user ); -} - -void OwncloudWizard::setConfigExists( bool config ) -{ - _configExists = config; - _setupPage->setConfigExists( config ); -} - -bool OwncloudWizard::configExists() -{ - return _configExists; -} - -AbstractCredentials* OwncloudWizard::getCredentials() const -{ - if (_credentialsPage) { - return _credentialsPage->getCredentials(); - } - - return 0; -} - - -} // end namespace diff --git a/src/mirall/wizard/owncloudwizard.h b/src/mirall/wizard/owncloudwizard.h deleted file mode 100644 index 60e9952c1..000000000 --- a/src/mirall/wizard/owncloudwizard.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_OWNCLOUD_WIZARD_H -#define MIRALL_OWNCLOUD_WIZARD_H - -#include - -#include "owncloudwizardcommon.h" - -namespace Mirall { - -class OwncloudSetupPage; -class OwncloudHttpCredsPage; -class OwncloudShibbolethCredsPage; -class OwncloudWizardResultPage; -class AbstractCredentials; -class AbstractCredentialsWizardPage; - -class OwncloudWizard: public QWizard -{ - Q_OBJECT -public: - - enum LogType { - LogPlain, - LogParagraph - }; - - OwncloudWizard(QWidget *parent = 0); - - void setOCUrl( const QString& ); - void setOCUser( const QString& ); - - void setupCustomMedia( QVariant, QLabel* ); - QString ocUrl() const; - QString localFolder() const; - - void enableFinishOnResultWidget(bool enable); - - void displayError( const QString& ); - WizardCommon::SyncMode syncMode(); - void setMultipleFoldersExist( bool ); - void setConfigExists( bool ); - bool configExists(); - void successfullyConnected(bool); - void setAuthType(WizardCommon::AuthType type); - AbstractCredentials* getCredentials() const; - -public slots: - void setRemoteFolder( const QString& ); - void appendToConfigurationLog( const QString& msg, LogType type = LogParagraph ); - void slotCurrentPageChanged( int ); - - void showConnectInfo( const QString& ); - -signals: - void clearPendingRequests(); - void connectToOCUrl( const QString& ); - void determineAuthType(const QString&); - -private: - OwncloudSetupPage* _setupPage; - OwncloudHttpCredsPage* _httpCredsPage; - OwncloudShibbolethCredsPage* _shibbolethCredsPage; - OwncloudWizardResultPage* _resultPage; - AbstractCredentialsWizardPage* _credentialsPage; - - QString _configFile; - QString _oCUser; - QStringList _setupLog; - bool _configExists; -}; - -} // ns Mirall - -#endif diff --git a/src/mirall/wizard/owncloudwizardcommon.cpp b/src/mirall/wizard/owncloudwizardcommon.cpp deleted file mode 100644 index 6429b02ef..000000000 --- a/src/mirall/wizard/owncloudwizardcommon.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 -#include -#include - -#include "mirall/wizard/owncloudwizardcommon.h" -#include "mirall/theme.h" - -namespace Mirall -{ - -namespace WizardCommon -{ - -void setupCustomMedia( const QVariant& variant, QLabel *label ) -{ - if( !label ) return; - - QPixmap pix = variant.value(); - if( !pix.isNull() ) { - label->setPixmap(pix); - label->setAlignment( Qt::AlignTop | Qt::AlignRight ); - label->setVisible(true); - } else { - QString str = variant.toString(); - if( !str.isEmpty() ) { - label->setText( str ); - label->setTextFormat( Qt::RichText ); - label->setVisible(true); - label->setOpenExternalLinks(true); - } - } -} - -QString titleTemplate() -{ - return QString::fromLatin1("").arg(Theme::instance()->wizardHeaderTitleColor().name()) + QString::fromLatin1("%1"); -} - -QString subTitleTemplate() -{ - return QString::fromLatin1("").arg(Theme::instance()->wizardHeaderTitleColor().name()) + QString::fromLatin1("%1"); -} - -void initErrorLabel(QLabel* errorLabel) -{ - QString style = QLatin1String("border: 1px solid #eed3d7; border-radius: 5px; padding: 3px;" - "background-color: #f2dede; color: #b94a48;"); - - errorLabel->setStyleSheet(style); - errorLabel->setWordWrap(true); - errorLabel->setVisible(false); -} - -} // ns WizardCommon - -} // ns Mirall diff --git a/src/mirall/wizard/owncloudwizardcommon.h b/src/mirall/wizard/owncloudwizardcommon.h deleted file mode 100644 index 38ac86278..000000000 --- a/src/mirall/wizard/owncloudwizardcommon.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_OWNCLOUD_WIZARD_COMMON_H -#define MIRALL_OWNCLOUD_WIZARD_COMMON_H - -class QVariant; -class QLabel; - -namespace Mirall -{ - -namespace WizardCommon -{ - -void setupCustomMedia( const QVariant& variant, QLabel *label ); -QString titleTemplate(); -QString subTitleTemplate(); -void initErrorLabel(QLabel* errorLabel); - -enum AuthType { - HttpCreds, - Shibboleth -}; - -enum SyncMode { - SelectiveMode, - BoxMode -}; - -enum Pages { - Page_oCSetup, - Page_HttpCreds, - Page_ShibbolethCreds, - Page_Result -}; - -} // ns WizardCommon - -} // ns Mirall - -#endif // MIRALL_OWNCLOUD_WIZARD_COMMON_H diff --git a/src/mirall/wizard/owncloudwizardresultpage.cpp b/src/mirall/wizard/owncloudwizardresultpage.cpp deleted file mode 100644 index 9c0ae0221..000000000 --- a/src/mirall/wizard/owncloudwizardresultpage.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 -#include -#include -#include - -#include "mirall/wizard/owncloudwizardresultpage.h" -#include "mirall/wizard/owncloudwizardcommon.h" -#include "mirall/theme.h" - -namespace Mirall -{ - -OwncloudWizardResultPage::OwncloudWizardResultPage() - : QWizardPage(), - _localFolder(), - _remoteFolder(), - _complete(false), - _ui() -{ - _ui.setupUi(this); - // no fields to register. - - setTitle(WizardCommon::subTitleTemplate().arg(tr("Everything set up!"))); - // required to show header in QWizard's modern style - setSubTitle( QLatin1String(" ") ); - - _ui.pbOpenLocal->setText(tr("Open Local Folder")); - _ui.pbOpenLocal->setIcon(QIcon(":/mirall/resources/folder-sync.png")); - _ui.pbOpenLocal->setIconSize(QSize(48, 48)); - _ui.pbOpenLocal->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - connect(_ui.pbOpenLocal, SIGNAL(clicked()), SLOT(slotOpenLocal())); - - Theme* theme = Theme::instance(); - QIcon appIcon = theme->applicationIcon(); - _ui.pbOpenServer->setText(tr("Open %1").arg(theme->appNameGUI())); - _ui.pbOpenServer->setIcon(appIcon.pixmap(48)); - _ui.pbOpenServer->setIconSize(QSize(48, 48)); - _ui.pbOpenServer->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - connect(_ui.pbOpenServer, SIGNAL(clicked()), SLOT(slotOpenServer())); - setupCustomization(); -} - -OwncloudWizardResultPage::~OwncloudWizardResultPage() -{} - -void OwncloudWizardResultPage::setComplete(bool complete) -{ - _complete = complete; - emit completeChanged(); -} - -bool OwncloudWizardResultPage::isComplete() const -{ - return _complete; -} - -void OwncloudWizardResultPage::initializePage() -{ - const QString localFolder = wizard()->property("localFolder").toString(); - QString text; - if( _remoteFolder == QLatin1String("/") || _remoteFolder.isEmpty() ) { - text = tr("Your entire account is synced to the local folder %1") - .arg(QDir::toNativeSeparators(localFolder)); - } else { - text = tr("ownCloud folder %1 is synced to local folder %2") - .arg(_remoteFolder).arg(QDir::toNativeSeparators(localFolder)); - } - _ui.localFolderLabel->setText( text ); - -} - -void OwncloudWizardResultPage::setRemoteFolder(const QString &remoteFolder) -{ - _remoteFolder = remoteFolder; -} - -void OwncloudWizardResultPage::setupCustomization() -{ - // set defaults for the customize labels. - _ui.topLabel->setText( QString::null ); - _ui.topLabel->hide(); - - QVariant variant = Theme::instance()->customMedia( Theme::oCSetupResultTop ); - WizardCommon::setupCustomMedia( variant, _ui.topLabel ); -} - -void OwncloudWizardResultPage::slotOpenLocal() -{ - const QString localFolder = wizard()->property("localFolder").toString(); - QDesktopServices::openUrl(QUrl::fromLocalFile(localFolder)); -} - -void OwncloudWizardResultPage::slotOpenServer() -{ - QUrl url = field("OCUrl").toUrl(); - qDebug() << Q_FUNC_INFO << url; - QDesktopServices::openUrl(url); -} - -} // ns Mirall diff --git a/src/mirall/wizard/owncloudwizardresultpage.h b/src/mirall/wizard/owncloudwizardresultpage.h deleted file mode 100644 index 0ae7a6679..000000000 --- a/src/mirall/wizard/owncloudwizardresultpage.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * Copyright (C) by Klaas Freitag - * Copyright (C) by Krzesimir Nowak - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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 MIRALL_OWNCLOUD_WIZARD_RESULT_PAGE_H -#define MIRALL_OWNCLOUD_WIZARD_RESULT_PAGE_H - -#include - -#include "ui_owncloudwizardresultpage.h" - -namespace Mirall { - -class OwncloudWizardResultPage : public QWizardPage -{ - Q_OBJECT -public: - OwncloudWizardResultPage(); - ~OwncloudWizardResultPage(); - - bool isComplete() const; - void initializePage(); - void setRemoteFolder( const QString& remoteFolder); - -public slots: - void setComplete(bool complete); - -protected slots: - void slotOpenLocal(); - void slotOpenServer(); - -protected: - void setupCustomization(); - -private: - QString _localFolder; - QString _remoteFolder; - bool _complete; - - Ui_OwncloudWizardResultPage _ui; -}; - -} // ns Mirall - -#endif diff --git a/src/wizard/abstractcredswizardpage.h b/src/wizard/abstractcredswizardpage.h new file mode 100644 index 000000000..0579f0c05 --- /dev/null +++ b/src/wizard/abstractcredswizardpage.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_WIZARD_ABSTRACT_CREDS_WIZARD_PAGE_H +#define MIRALL_WIZARD_ABSTRACT_CREDS_WIZARD_PAGE_H + +#include + +namespace Mirall +{ + +class AbstractCredentials; + +class AbstractCredentialsWizardPage : public QWizardPage +{ +public: + virtual AbstractCredentials* getCredentials() const = 0; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudhttpcredspage.cpp b/src/wizard/owncloudhttpcredspage.cpp new file mode 100644 index 000000000..5bd550d89 --- /dev/null +++ b/src/wizard/owncloudhttpcredspage.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 "QProgressIndicator.h" + +#include "wizard/owncloudhttpcredspage.h" +#include "mirall/theme.h" +#include "wizard/owncloudwizardcommon.h" +#include "creds/httpcredentials.h" + +namespace Mirall +{ + +OwncloudHttpCredsPage::OwncloudHttpCredsPage() + : AbstractCredentialsWizardPage(), + _ui(), + _connected(false), + _checking(false), + _progressIndi(new QProgressIndicator (this)) +{ + _ui.setupUi(this); + + registerField( QLatin1String("OCUser*"), _ui.leUsername); + registerField( QLatin1String("OCPasswd*"), _ui.lePassword); + + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Enter user credentials"))); + + _ui.resultLayout->addWidget( _progressIndi ); + stopSpinner(); + setupCustomization(); +} + +void OwncloudHttpCredsPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); +} + +void OwncloudHttpCredsPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + _ui.leUsername->setFocus(); +} + +void OwncloudHttpCredsPage::cleanupPage() +{ + _ui.leUsername->clear(); + _ui.lePassword->clear(); +} + +bool OwncloudHttpCredsPage::validatePage() +{ + if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) { + return false; + } + + if (!_connected) { + _checking = true; + emit completeChanged(); + emit connectToOCUrl(field("OCUrl").toString().simplified()); + + return false; + } else { + _checking = false; + emit completeChanged(); + return true; + } + return true; +} + +int OwncloudHttpCredsPage::nextId() const +{ + return WizardCommon::Page_Result; +} + +void OwncloudHttpCredsPage::setConnected( bool comp ) +{ + _connected = comp; + stopSpinner (); +} + +void OwncloudHttpCredsPage::startSpinner() +{ + _ui.resultLayout->setEnabled(true); + _progressIndi->setVisible(true); + _progressIndi->startAnimation(); +} + +void OwncloudHttpCredsPage::stopSpinner() +{ + _ui.resultLayout->setEnabled(false); + _progressIndi->setVisible(false); + _progressIndi->stopAnimation(); +} + +void OwncloudHttpCredsPage::setOCUser(const QString& user) +{ + _ui.leUsername->setText(user); +} + +void OwncloudHttpCredsPage::setErrorString(const QString& err) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + _checking = false; + emit completeChanged(); + stopSpinner(); +} + +AbstractCredentials* OwncloudHttpCredsPage::getCredentials() const +{ + return new HttpCredentials(_ui.leUsername->text(), _ui.lePassword->text()); +} + +} // ns Mirall diff --git a/src/wizard/owncloudhttpcredspage.h b/src/wizard/owncloudhttpcredspage.h new file mode 100644 index 000000000..29412b002 --- /dev/null +++ b/src/wizard/owncloudhttpcredspage.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H +#define MIRALL_OWNCLOUD_HTTP_CREDS_PAGE_H + +#include "wizard/abstractcredswizardpage.h" + +#include "ui_owncloudhttpcredspage.h" + +class QProgressIndicator; + +namespace Mirall { + +class OwncloudHttpCredsPage : public AbstractCredentialsWizardPage +{ + Q_OBJECT +public: + OwncloudHttpCredsPage(); + + AbstractCredentials* getCredentials() const; + + void setOCUser(const QString& user); + void initializePage(); + void cleanupPage(); + bool validatePage(); + int nextId() const; + void setConnected(bool connected); + void setErrorString( const QString& err ); + +Q_SIGNALS: + void connectToOCUrl(const QString&); + +private: + void startSpinner(); + void stopSpinner(); + void setupCustomization(); + + Ui_OwncloudHttpCredsPage _ui; + bool _connected; + bool _checking; + QProgressIndicator* _progressIndi; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudhttpcredspage.ui b/src/wizard/owncloudhttpcredspage.ui new file mode 100644 index 000000000..35f539a25 --- /dev/null +++ b/src/wizard/owncloudhttpcredspage.ui @@ -0,0 +1,130 @@ + + + OwncloudHttpCredsPage + + + + 0 + 0 + 350 + 196 + + + + Form + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + &Username + + + leUsername + + + + + + + &Password + + + lePassword + + + + + + + Error Label + + + + + + + + + + QLineEdit::Password + + + + + + + + + Qt::Vertical + + + + 20 + 68 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + + TextLabel + + + + + + + TextLabel + + + + + horizontalSpacer + verticalSpacer + horizontalSpacer_2 + horizontalLayoutWidget + topLabel + bottomLabel + + + + diff --git a/src/wizard/owncloudsetupnocredspage.ui b/src/wizard/owncloudsetupnocredspage.ui new file mode 100644 index 000000000..5e08a64b1 --- /dev/null +++ b/src/wizard/owncloudsetupnocredspage.ui @@ -0,0 +1,417 @@ + + + OwncloudSetupPage + + + + 0 + 0 + 583 + 498 + + + + + 0 + 0 + + + + Form + + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 68 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + 0 + + + + + + + true + + + + 0 + + + 0 + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + 0 + 0 + + + + &Local Folder + + + pbSelectLocalFolder + + + + + + + + 0 + 0 + + + + pbSelectLocalFolder + + + + + + + + QLayout::SetMinimumSize + + + QFormLayout::ExpandingFieldsGrow + + + + + &Keep local data + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + <small>Syncs your existing data to new location.</small> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 0 + + + + + + + <html><head/><body><p>If this box is checked, existing content in the local directory will be erased to start a clean sync from the server.</p><p>Do not check this if the local content should be uploaded to the servers directory.</p></body></html> + + + &Start a clean sync + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + <small>Erases the contents of the local folder before syncing using the new settings.</small> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 0 + + + + + + + + + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Server &Address + + + leUrl + + + + + + + + 0 + 0 + + + + Enter the url of the ownCloud you want to connect to (without http or https). + + + https://... + + + + + + + + 0 + 0 + + + + Error Label + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Advanced &Settings + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Status message + + + Qt::AlignCenter + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 58 + + + + + + + + TextLabel + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + + Utils::FancyLineEdit + QLineEdit +
fancylineedit.h
+
+
+ + +
diff --git a/src/wizard/owncloudsetuppage.cpp b/src/wizard/owncloudsetuppage.cpp new file mode 100644 index 000000000..df21570d2 --- /dev/null +++ b/src/wizard/owncloudsetuppage.cpp @@ -0,0 +1,352 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "QProgressIndicator.h" + +#include "wizard/owncloudwizardcommon.h" +#include "wizard/owncloudsetuppage.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +OwncloudSetupPage::OwncloudSetupPage() + : QWizardPage(), + _ui(), + _oCUrl(), + _ocUser(), + _authTypeKnown(false), + _checking(false), + _multipleFoldersExist(false), + _authType(WizardCommon::HttpCreds), + _progressIndi(new QProgressIndicator (this)), + _selectiveSyncButtons(0), + _remoteFolder() +{ + _ui.setupUi(this); + + Theme *theme = Theme::instance(); + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(theme->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Setup ownCloud server"))); + + registerField( QLatin1String("OCUrl*"), _ui.leUrl ); + registerField( QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch); + + _ui.advancedBox->setVisible(false); + + _ui.resultLayout->addWidget( _progressIndi ); + stopSpinner(); + + setupCustomization(); + + connect(_ui.leUrl, SIGNAL(textChanged(QString)), SLOT(slotUrlChanged(QString))); + connect( _ui.cbAdvanced, SIGNAL(stateChanged (int)), SLOT(slotToggleAdvanced(int))); + connect( _ui.pbSelectLocalFolder, SIGNAL(clicked()), SLOT(slotSelectFolder())); +} + +void OwncloudSetupPage::slotToggleAdvanced(int state) +{ + _ui.advancedBox->setVisible( state == Qt::Checked ); + slotHandleUserInput(); + QSize size = wizard()->sizeHint(); + // need to substract header for some reason + size -= QSize(0, 63); + + wizard()->setMinimumSize(size); + wizard()->resize(size); +} + +void OwncloudSetupPage::setServerUrl( const QString& newUrl ) +{ + _oCUrl = newUrl; + if( _oCUrl.isEmpty() ) { + _ui.leUrl->clear(); + return; + } + + _ui.leUrl->setText( _oCUrl ); +} + +void OwncloudSetupPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); + + QString fixUrl = theme->overrideServerUrl(); + if( !fixUrl.isEmpty() ) { + _ui.label_2->hide(); + setServerUrl( fixUrl ); + _ui.leUrl->setEnabled( false ); + _ui.leUrl->hide(); + } +} + +// slot hit from textChanged of the url entry field. +void OwncloudSetupPage::slotUrlChanged(const QString& ocUrl) +{ + slotHandleUserInput(); + +#if 0 + QString url = ocUrl; + bool visible = false; + + if (url.startsWith(QLatin1String("https://"))) { + _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-high.png")); + _ui.urlLabel->setToolTip(tr("This url is secure. You can use it.")); + visible = true; + } + if (url.startsWith(QLatin1String("http://"))) { + _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-low.png")); + _ui.urlLabel->setToolTip(tr("This url is NOT secure. You should not use it."));W + visible = true; + } +#endif +} + +bool OwncloudSetupPage::isComplete() const +{ + return !_ui.leUrl->text().isEmpty() && !_checking; +} + +void OwncloudSetupPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + + _authTypeKnown = false; + _checking = false; + _multipleFoldersExist = false; + + // call to init label + slotHandleUserInput(); + + _ui.leUrl->setFocus(); +} + +bool OwncloudSetupPage::urlHasChanged() +{ + bool change = false; + const QChar slash('/'); + + QUrl currentUrl( url() ); + QUrl initialUrl( _oCUrl ); + + QString currentPath = currentUrl.path(); + QString initialPath = initialUrl.path(); + + // add a trailing slash. + if( ! currentPath.endsWith( slash )) currentPath += slash; + if( ! initialPath.endsWith( slash )) initialPath += slash; + + if( currentUrl.host() != initialUrl.host() || + currentUrl.port() != initialUrl.port() || + currentPath != initialPath ) { + change = true; + } + + return change; +} + +// Called if the user changes the user- or url field. Adjust the texts and +// evtl. warnings on the dialog. +void OwncloudSetupPage::slotHandleUserInput() +{ + // if the url has not changed, return. + if( ! urlHasChanged() ) { + // disable the advanced button as nothing has changed. + _ui.cbAdvanced->setEnabled(false); + _ui.advancedBox->setEnabled(false); + } else { + // Enable advanced stuff for new connection configuration. + _ui.cbAdvanced->setEnabled(true); + _ui.advancedBox->setEnabled(true); + } + + const QString locFolder = localFolder(); + + // check if the local folder exists. If so, and if its not empty, show a warning. + QDir dir( locFolder ); + QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot); + + QString t; + + if( !urlHasChanged() && _configExists ) { + // This is the password change mode: No change to the url and a config + // to an ownCloud exists. + t = tr("Press Next to change the Password for your configured account."); + } else { + // Complete new setup. + _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); + + if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { + t = tr("Your entire account will be synced to the local folder '%1'.") + .arg(QDir::toNativeSeparators(locFolder)); + } else { + t = tr("%1 folder '%2' is synced to local folder '%3'") + .arg(Theme::instance()->appName()).arg(_remoteFolder) + .arg(QDir::toNativeSeparators(locFolder)); + } + + if ( _multipleFoldersExist ) { + t += tr("

Warning: You currently have multiple folders " + "configured. If you continue with the current settings, the folder configurations " + "will be discarded and a single root folder sync will be created!

"); + } + + if( entries.count() > 0) { + // the directory is not empty + if (!_ui.cbAdvanced->isChecked()) { + t += tr("

Warning: The local directory is not empty. " + "Pick a resolution in the advanced settings!

"); + } + _ui.resolutionWidget->setVisible(true); + } else { + // the dir is empty, which means that there is no problem. + _ui.resolutionWidget->setVisible(false); + } + } + + _ui.syncModeLabel->setText(t); + _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); +} + +int OwncloudSetupPage::nextId() const +{ + if (_authType == WizardCommon::HttpCreds) { + return WizardCommon::Page_HttpCreds; + } else { + return WizardCommon::Page_ShibbolethCreds; + } +} + +QString OwncloudSetupPage::url() const +{ + QString url = _ui.leUrl->text().simplified(); + return url; +} + +QString OwncloudSetupPage::localFolder() const +{ + QString folder = wizard()->property("localFolder").toString(); + return folder; +} + +bool OwncloudSetupPage::validatePage() +{ + bool re = false; + + if( ! _authTypeKnown) { + setErrorString(QString::null); + _checking = true; + startSpinner (); + emit completeChanged(); + + emit determineAuthType(url()); + return false; + } else { + // connecting is running + stopSpinner(); + _checking = false; + emit completeChanged(); + return true; + } +} + +void OwncloudSetupPage::setAuthType (WizardCommon::AuthType type) +{ + _authTypeKnown = true; + _authType = type; + stopSpinner(); +} + +void OwncloudSetupPage::setErrorString( const QString& err ) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + _checking = false; + emit completeChanged(); + stopSpinner(); +} + +void OwncloudSetupPage::startSpinner() +{ + _ui.resultLayout->setEnabled(true); + _progressIndi->setVisible(true); + _progressIndi->startAnimation(); +} + +void OwncloudSetupPage::stopSpinner() +{ + _ui.resultLayout->setEnabled(false); + _progressIndi->setVisible(false); + _progressIndi->stopAnimation(); +} + +WizardCommon::SyncMode OwncloudSetupPage::syncMode() +{ + return WizardCommon::BoxMode; +} + +void OwncloudSetupPage::setRemoteFolder( const QString& remoteFolder ) +{ + if( !remoteFolder.isEmpty() ) { + _remoteFolder = remoteFolder; + } +} + +void OwncloudSetupPage::setMultipleFoldersExist(bool exist) +{ + _multipleFoldersExist = exist; +} + +void OwncloudSetupPage::slotSelectFolder() +{ + QString dir = QFileDialog::getExistingDirectory(0, tr("Local Sync Folder"), QDir::homePath()); + if( !dir.isEmpty() ) { + _ui.pbSelectLocalFolder->setText(dir); + wizard()->setProperty("localFolder", dir); + slotHandleUserInput(); + } +} + +void OwncloudSetupPage::setConfigExists( bool config ) +{ + _configExists = config; + + if (config == true) { + setSubTitle( tr("Change your user credentials") + .arg(Theme::instance()->wizardHeaderTitleColor().name())); + } +} + +} // ns Mirall diff --git a/src/wizard/owncloudsetuppage.h b/src/wizard/owncloudsetuppage.h new file mode 100644 index 000000000..f8369deaf --- /dev/null +++ b/src/wizard/owncloudsetuppage.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_SETUP_PAGE_H +#define MIRALL_OWNCLOUD_SETUP_PAGE_H + +#include + +#include "wizard/owncloudwizardcommon.h" +#include "ui_owncloudsetupnocredspage.h" + +class QLabel; +class QVariant; +class QProgressIndicator; + +namespace Mirall { + +class OwncloudSetupPage: public QWizardPage +{ + Q_OBJECT +public: + OwncloudSetupPage(); + + virtual bool isComplete() const; + virtual void initializePage(); + virtual int nextId() const; + void setServerUrl( const QString& ); + void setAllowPasswordStorage( bool ); + bool validatePage(); + QString url() const; + QString localFolder() const; + void setRemoteFolder( const QString& remoteFolder); + void setMultipleFoldersExist( bool exist ); + + WizardCommon::SyncMode syncMode(); + void setAuthType(WizardCommon::AuthType type); + +public slots: + void setErrorString( const QString& ); + void setConfigExists( bool ); + void startSpinner(); + void stopSpinner(); + +protected slots: + void slotUrlChanged(const QString&); + + void setupCustomization(); + void slotToggleAdvanced(int state); + void slotSelectFolder(); + +signals: + void determineAuthType(const QString&); + +protected: + void updateFoldersInfo(); + +private slots: + void slotHandleUserInput(); + +private: + bool urlHasChanged(); + + Ui_OwncloudSetupPage _ui; + QString _oCUrl; + QString _ocUser; + bool _authTypeKnown; + bool _checking; + bool _configExists; + bool _multipleFoldersExist; + WizardCommon::AuthType _authType; + + QProgressIndicator* _progressIndi; + QButtonGroup* _selectiveSyncButtons; + QString _remoteFolder; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudshibbolethcredspage.cpp b/src/wizard/owncloudshibbolethcredspage.cpp new file mode 100644 index 000000000..8013f3c7c --- /dev/null +++ b/src/wizard/owncloudshibbolethcredspage.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 "wizard/owncloudshibbolethcredspage.h" +#include "mirall/theme.h" +#include "wizard/owncloudwizardcommon.h" +#include "creds/shibbolethcredentials.h" +#include "creds/shibboleth/shibbolethwebview.h" + +namespace Mirall +{ + +OwncloudShibbolethCredsPage::OwncloudShibbolethCredsPage() + : AbstractCredentialsWizardPage(), + _ui(), + _stage(INITIAL_STEP), + _browser(0), + _cookie() +{ + _ui.setupUi(this); + + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Process through Shibboleth form"))); + + setupCustomization(); +} + +void OwncloudShibbolethCredsPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); +} + +bool OwncloudShibbolethCredsPage::isComplete() const +{ + return _stage == GOT_COOKIE; +} + +void OwncloudShibbolethCredsPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + _browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified()), this); + + connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + + _ui.contentLayout->insertWidget(0, _browser); + _browser->show(); + _browser->setFocus(); + _ui.infoLabel->show(); + _ui.infoLabel->setText(tr("Please follow the steps on displayed page above")); + _stage = INITIAL_STEP; + _cookie = QNetworkCookie(); +} + +void OwncloudShibbolethCredsPage::disposeBrowser(bool later) +{ + if (_browser) { + _browser->hide(); + disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), + this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + if (later) { + _browser->deleteLater(); + } else { + delete _browser; + } + _browser = 0; + } +} + +void OwncloudShibbolethCredsPage::cleanupPage() +{ + disposeBrowser(false); +} + +bool OwncloudShibbolethCredsPage::validatePage() +{ + switch (_stage) { + case INITIAL_STEP: + return false; + + case GOT_COOKIE: + _stage = CHECKING; + emit completeChanged(); + emit connectToOCUrl(field("OCUrl").toString().simplified()); + return false; + + case CHECKING: + return false; + + case CONNECTED: + return true; + } + + return false; +} + +int OwncloudShibbolethCredsPage::nextId() const +{ + return WizardCommon::Page_Result; +} + +void OwncloudShibbolethCredsPage::setConnected( bool comp ) +{ + if (comp) { + _stage = CONNECTED; + } else { + // sets stage to INITIAL + initializePage(); + } + emit completeChanged(); +} + +void OwncloudShibbolethCredsPage::setErrorString(const QString& err) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + initializePage(); + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + emit completeChanged(); +} + +AbstractCredentials* OwncloudShibbolethCredsPage::getCredentials() const +{ + return new ShibbolethCredentials(_cookie); +} + +void OwncloudShibbolethCredsPage::onShibbolethCookieReceived(const QNetworkCookie& cookie) +{ + disposeBrowser(true); + _stage = GOT_COOKIE; + _cookie = cookie; + _ui.infoLabel->setText("Please click \"Connect\" to check received Shibboleth session."); + emit completeChanged(); +} + +} // ns Mirall diff --git a/src/wizard/owncloudshibbolethcredspage.h b/src/wizard/owncloudshibbolethcredspage.h new file mode 100644 index 000000000..d7d2bca79 --- /dev/null +++ b/src/wizard/owncloudshibbolethcredspage.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H +#define MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H + +#include + +#include "wizard/abstractcredswizardpage.h" + +#include "ui_owncloudshibbolethcredspage.h" + +namespace Mirall { + +class ShibbolethWebView; + +class OwncloudShibbolethCredsPage : public AbstractCredentialsWizardPage +{ + Q_OBJECT +public: + OwncloudShibbolethCredsPage(); + + AbstractCredentials* getCredentials() const; + + bool isComplete() const; + void initializePage(); + void cleanupPage(); + bool validatePage(); + int nextId() const; + void setConnected(bool connected); + void setErrorString(const QString& err); + +Q_SIGNALS: + void connectToOCUrl(const QString&); + +private Q_SLOTS: + void onShibbolethCookieReceived(const QNetworkCookie& cookie); + +private: + enum Stage { + INITIAL_STEP, + GOT_COOKIE, + CHECKING, + CONNECTED + }; + + void setupCustomization(); + void disposeBrowser(bool later); + + Ui_OwncloudShibbolethCredsPage _ui; + Stage _stage; + ShibbolethWebView* _browser; + QNetworkCookie _cookie; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudshibbolethcredspage.ui b/src/wizard/owncloudshibbolethcredspage.ui new file mode 100644 index 000000000..832d7eb44 --- /dev/null +++ b/src/wizard/owncloudshibbolethcredspage.ui @@ -0,0 +1,121 @@ + + + OwncloudShibbolethCredsPage + + + + 0 + 0 + 640 + 451 + + + + Form + + + + + + QLayout::SetMaximumSize + + + + + TextLabel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 45 + 17 + + + + + + + + + + + 0 + 0 + + + + Error Label + + + + + + + info label + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + Qt::Vertical + + + + 17 + 38 + + + + + + + + TextLabel + + + + + + + horizontalSpacer + verticalSpacer + horizontalSpacer_2 + topLabel + bottomLabel + errorLabel_2 + + + + diff --git a/src/wizard/owncloudwizard.cpp b/src/wizard/owncloudwizard.cpp new file mode 100644 index 000000000..713114b0e --- /dev/null +++ b/src/wizard/owncloudwizard.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 "wizard/owncloudwizard.h" +#include "mirall/mirallconfigfile.h" +#include "mirall/theme.h" +#include "wizard/owncloudsetuppage.h" +#include "wizard/owncloudhttpcredspage.h" +#include "wizard/owncloudshibbolethcredspage.h" +#include "wizard/owncloudwizardresultpage.h" + +#include "QProgressIndicator.h" + +#include +#include + +#include + +namespace Mirall +{ + +OwncloudWizard::OwncloudWizard(QWidget *parent) + : QWizard(parent), + _setupPage(new OwncloudSetupPage), + _httpCredsPage(new OwncloudHttpCredsPage), + _shibbolethCredsPage(new OwncloudShibbolethCredsPage), + _resultPage(new OwncloudWizardResultPage), + _credentialsPage(0), + _configFile(), + _oCUser(), + _setupLog(), + _configExists(false) +{ + setPage(WizardCommon::Page_oCSetup, _setupPage ); + setPage(WizardCommon::Page_HttpCreds, _httpCredsPage); + setPage(WizardCommon::Page_ShibbolethCreds, _shibbolethCredsPage); + setPage(WizardCommon::Page_Result, _resultPage ); + + // note: start Id is set by the calling class depending on if the + // welcome text is to be shown or not. + setWizardStyle( QWizard::ModernStyle ); + + connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int))); + connect( _setupPage, SIGNAL(determineAuthType(QString)), SIGNAL(determineAuthType(QString))); + connect( _httpCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); + connect( _shibbolethCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); + + Theme *theme = Theme::instance(); + setWizardStyle(QWizard::ModernStyle); + setPixmap( QWizard::BannerPixmap, theme->wizardHeaderBanner() ); + setPixmap( QWizard::LogoPixmap, theme->wizardHeaderLogo() ); + setOption( QWizard::NoBackButtonOnStartPage ); + setOption( QWizard::NoBackButtonOnLastPage ); + setOption( QWizard::NoCancelButton ); + setTitleFormat(Qt::RichText); + setSubTitleFormat(Qt::RichText); +} + +WizardCommon::SyncMode OwncloudWizard::syncMode() +{ + return _setupPage->syncMode(); + return WizardCommon::BoxMode; +} + +void OwncloudWizard::setMultipleFoldersExist(bool exist) +{ + _setupPage->setMultipleFoldersExist(exist); +} + +QString OwncloudWizard::localFolder() const +{ + return(_setupPage->localFolder()); +} + +QString OwncloudWizard::ocUrl() const +{ + QString url = field("OCUrl").toString().simplified(); + return url; +} + +void OwncloudWizard::enableFinishOnResultWidget(bool enable) +{ + _resultPage->setComplete(enable); +} + +void OwncloudWizard::setRemoteFolder( const QString& remoteFolder ) +{ + _setupPage->setRemoteFolder( remoteFolder ); + _resultPage->setRemoteFolder( remoteFolder ); +} + +void OwncloudWizard::showConnectInfo( const QString& msg ) +{ + if( _setupPage ) { + _setupPage->setErrorString( msg ); + } +} + +void OwncloudWizard::successfullyConnected(bool enable) +{ + const int id(currentId()); + + switch (id) { + case WizardCommon::Page_HttpCreds: + _httpCredsPage->setConnected( enable ); + break; + + case WizardCommon::Page_ShibbolethCreds: + _shibbolethCredsPage->setConnected( enable ); + break; + + case WizardCommon::Page_oCSetup: + case WizardCommon::Page_Result: + qWarning("Should not happen at this stage."); + break; + } + + if( enable ) { + next(); + } +} + +void OwncloudWizard::setAuthType(WizardCommon::AuthType type) +{ + _setupPage->setAuthType(type); + if (type == WizardCommon::Shibboleth) { + _credentialsPage = _shibbolethCredsPage; + } else { + _credentialsPage = _httpCredsPage; + } + next(); +} + +void OwncloudWizard::slotCurrentPageChanged( int id ) +{ + qDebug() << "Current Wizard page changed to " << id; + + if( id == WizardCommon::Page_oCSetup ) { + setButtonText( QWizard::NextButton, tr("Connect...") ); + emit clearPendingRequests(); + _setupPage->initializePage(); + + } + + if( id == WizardCommon::Page_Result ) { + appendToConfigurationLog( QString::null ); + } +} + +void OwncloudWizard::displayError( const QString& msg ) +{ + int id(currentId()); + + if (id == WizardCommon::Page_oCSetup) { + _setupPage->setErrorString( msg ); + } else if (id == WizardCommon::Page_HttpCreds) { + _httpCredsPage->setErrorString(msg); + } else if (id == WizardCommon::Page_ShibbolethCreds) { + _shibbolethCredsPage->setErrorString(msg); + } +} + +void OwncloudWizard::appendToConfigurationLog( const QString& msg, LogType type ) +{ + _setupLog << msg; + qDebug() << "Setup-Log: " << msg; +} + +void OwncloudWizard::setOCUrl( const QString& url ) +{ + _setupPage->setServerUrl( url ); +} + +void OwncloudWizard::setOCUser( const QString& user ) +{ + _oCUser = user; + _httpCredsPage->setOCUser( user ); +} + +void OwncloudWizard::setConfigExists( bool config ) +{ + _configExists = config; + _setupPage->setConfigExists( config ); +} + +bool OwncloudWizard::configExists() +{ + return _configExists; +} + +AbstractCredentials* OwncloudWizard::getCredentials() const +{ + if (_credentialsPage) { + return _credentialsPage->getCredentials(); + } + + return 0; +} + + +} // end namespace diff --git a/src/wizard/owncloudwizard.h b/src/wizard/owncloudwizard.h new file mode 100644 index 000000000..a6b88af51 --- /dev/null +++ b/src/wizard/owncloudwizard.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_WIZARD_H +#define MIRALL_OWNCLOUD_WIZARD_H + +#include + +#include "wizard/owncloudwizardcommon.h" + +namespace Mirall { + +class OwncloudSetupPage; +class OwncloudHttpCredsPage; +class OwncloudShibbolethCredsPage; +class OwncloudWizardResultPage; +class AbstractCredentials; +class AbstractCredentialsWizardPage; + +class OwncloudWizard: public QWizard +{ + Q_OBJECT +public: + + enum LogType { + LogPlain, + LogParagraph + }; + + OwncloudWizard(QWidget *parent = 0); + + void setOCUrl( const QString& ); + void setOCUser( const QString& ); + + void setupCustomMedia( QVariant, QLabel* ); + QString ocUrl() const; + QString localFolder() const; + + void enableFinishOnResultWidget(bool enable); + + void displayError( const QString& ); + WizardCommon::SyncMode syncMode(); + void setMultipleFoldersExist( bool ); + void setConfigExists( bool ); + bool configExists(); + void successfullyConnected(bool); + void setAuthType(WizardCommon::AuthType type); + AbstractCredentials* getCredentials() const; + +public slots: + void setRemoteFolder( const QString& ); + void appendToConfigurationLog( const QString& msg, LogType type = LogParagraph ); + void slotCurrentPageChanged( int ); + + void showConnectInfo( const QString& ); + +signals: + void clearPendingRequests(); + void connectToOCUrl( const QString& ); + void determineAuthType(const QString&); + +private: + OwncloudSetupPage* _setupPage; + OwncloudHttpCredsPage* _httpCredsPage; + OwncloudShibbolethCredsPage* _shibbolethCredsPage; + OwncloudWizardResultPage* _resultPage; + AbstractCredentialsWizardPage* _credentialsPage; + + QString _configFile; + QString _oCUser; + QStringList _setupLog; + bool _configExists; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudwizardcommon.cpp b/src/wizard/owncloudwizardcommon.cpp new file mode 100644 index 000000000..dfe454411 --- /dev/null +++ b/src/wizard/owncloudwizardcommon.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "wizard/owncloudwizardcommon.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +namespace WizardCommon +{ + +void setupCustomMedia( const QVariant& variant, QLabel *label ) +{ + if( !label ) return; + + QPixmap pix = variant.value(); + if( !pix.isNull() ) { + label->setPixmap(pix); + label->setAlignment( Qt::AlignTop | Qt::AlignRight ); + label->setVisible(true); + } else { + QString str = variant.toString(); + if( !str.isEmpty() ) { + label->setText( str ); + label->setTextFormat( Qt::RichText ); + label->setVisible(true); + label->setOpenExternalLinks(true); + } + } +} + +QString titleTemplate() +{ + return QString::fromLatin1("").arg(Theme::instance()->wizardHeaderTitleColor().name()) + QString::fromLatin1("%1"); +} + +QString subTitleTemplate() +{ + return QString::fromLatin1("").arg(Theme::instance()->wizardHeaderTitleColor().name()) + QString::fromLatin1("%1"); +} + +void initErrorLabel(QLabel* errorLabel) +{ + QString style = QLatin1String("border: 1px solid #eed3d7; border-radius: 5px; padding: 3px;" + "background-color: #f2dede; color: #b94a48;"); + + errorLabel->setStyleSheet(style); + errorLabel->setWordWrap(true); + errorLabel->setVisible(false); +} + +} // ns WizardCommon + +} // ns Mirall diff --git a/src/wizard/owncloudwizardcommon.h b/src/wizard/owncloudwizardcommon.h new file mode 100644 index 000000000..38ac86278 --- /dev/null +++ b/src/wizard/owncloudwizardcommon.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_WIZARD_COMMON_H +#define MIRALL_OWNCLOUD_WIZARD_COMMON_H + +class QVariant; +class QLabel; + +namespace Mirall +{ + +namespace WizardCommon +{ + +void setupCustomMedia( const QVariant& variant, QLabel *label ); +QString titleTemplate(); +QString subTitleTemplate(); +void initErrorLabel(QLabel* errorLabel); + +enum AuthType { + HttpCreds, + Shibboleth +}; + +enum SyncMode { + SelectiveMode, + BoxMode +}; + +enum Pages { + Page_oCSetup, + Page_HttpCreds, + Page_ShibbolethCreds, + Page_Result +}; + +} // ns WizardCommon + +} // ns Mirall + +#endif // MIRALL_OWNCLOUD_WIZARD_COMMON_H diff --git a/src/wizard/owncloudwizardresultpage.cpp b/src/wizard/owncloudwizardresultpage.cpp new file mode 100644 index 000000000..62f6faf62 --- /dev/null +++ b/src/wizard/owncloudwizardresultpage.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include +#include + +#include "wizard/owncloudwizardresultpage.h" +#include "wizard/owncloudwizardcommon.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +OwncloudWizardResultPage::OwncloudWizardResultPage() + : QWizardPage(), + _localFolder(), + _remoteFolder(), + _complete(false), + _ui() +{ + _ui.setupUi(this); + // no fields to register. + + setTitle(WizardCommon::subTitleTemplate().arg(tr("Everything set up!"))); + // required to show header in QWizard's modern style + setSubTitle( QLatin1String(" ") ); + + _ui.pbOpenLocal->setText(tr("Open Local Folder")); + _ui.pbOpenLocal->setIcon(QIcon(":/mirall/resources/folder-sync.png")); + _ui.pbOpenLocal->setIconSize(QSize(48, 48)); + _ui.pbOpenLocal->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + connect(_ui.pbOpenLocal, SIGNAL(clicked()), SLOT(slotOpenLocal())); + + Theme* theme = Theme::instance(); + QIcon appIcon = theme->applicationIcon(); + _ui.pbOpenServer->setText(tr("Open %1").arg(theme->appNameGUI())); + _ui.pbOpenServer->setIcon(appIcon.pixmap(48)); + _ui.pbOpenServer->setIconSize(QSize(48, 48)); + _ui.pbOpenServer->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + connect(_ui.pbOpenServer, SIGNAL(clicked()), SLOT(slotOpenServer())); + setupCustomization(); +} + +OwncloudWizardResultPage::~OwncloudWizardResultPage() +{} + +void OwncloudWizardResultPage::setComplete(bool complete) +{ + _complete = complete; + emit completeChanged(); +} + +bool OwncloudWizardResultPage::isComplete() const +{ + return _complete; +} + +void OwncloudWizardResultPage::initializePage() +{ + const QString localFolder = wizard()->property("localFolder").toString(); + QString text; + if( _remoteFolder == QLatin1String("/") || _remoteFolder.isEmpty() ) { + text = tr("Your entire account is synced to the local folder %1") + .arg(QDir::toNativeSeparators(localFolder)); + } else { + text = tr("ownCloud folder %1 is synced to local folder %2") + .arg(_remoteFolder).arg(QDir::toNativeSeparators(localFolder)); + } + _ui.localFolderLabel->setText( text ); + +} + +void OwncloudWizardResultPage::setRemoteFolder(const QString &remoteFolder) +{ + _remoteFolder = remoteFolder; +} + +void OwncloudWizardResultPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->setText( QString::null ); + _ui.topLabel->hide(); + + QVariant variant = Theme::instance()->customMedia( Theme::oCSetupResultTop ); + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); +} + +void OwncloudWizardResultPage::slotOpenLocal() +{ + const QString localFolder = wizard()->property("localFolder").toString(); + QDesktopServices::openUrl(QUrl::fromLocalFile(localFolder)); +} + +void OwncloudWizardResultPage::slotOpenServer() +{ + QUrl url = field("OCUrl").toUrl(); + qDebug() << Q_FUNC_INFO << url; + QDesktopServices::openUrl(url); +} + +} // ns Mirall diff --git a/src/wizard/owncloudwizardresultpage.h b/src/wizard/owncloudwizardresultpage.h new file mode 100644 index 000000000..0ae7a6679 --- /dev/null +++ b/src/wizard/owncloudwizardresultpage.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_WIZARD_RESULT_PAGE_H +#define MIRALL_OWNCLOUD_WIZARD_RESULT_PAGE_H + +#include + +#include "ui_owncloudwizardresultpage.h" + +namespace Mirall { + +class OwncloudWizardResultPage : public QWizardPage +{ + Q_OBJECT +public: + OwncloudWizardResultPage(); + ~OwncloudWizardResultPage(); + + bool isComplete() const; + void initializePage(); + void setRemoteFolder( const QString& remoteFolder); + +public slots: + void setComplete(bool complete); + +protected slots: + void slotOpenLocal(); + void slotOpenServer(); + +protected: + void setupCustomization(); + +private: + QString _localFolder; + QString _remoteFolder; + bool _complete; + + Ui_OwncloudWizardResultPage _ui; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudwizardresultpage.ui b/src/wizard/owncloudwizardresultpage.ui new file mode 100644 index 000000000..917900971 --- /dev/null +++ b/src/wizard/owncloudwizardresultpage.ui @@ -0,0 +1,162 @@ + + + OwncloudWizardResultPage + + + + 0 + 0 + 469 + 325 + + + + Form + + + + + + TextLabel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 16 + + + + + + + + Your entire account is synced to the local folder + + + true + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 16 + + + + + + + + + + + 160 + 80 + + + + PushButton + + + Qt::ToolButtonTextUnderIcon + + + + + + + + 160 + 80 + + + + PushButton + + + Qt::ToolButtonTextUnderIcon + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + + -- cgit v1.2.3 From 6a9a2559d2b3e2075cff44efd96abcffd702fe67 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 12:56:27 +0200 Subject: Fix shibboleth syncing after client restart. We needed to notify shibboleth-specific QNAM about new cookie and then stop cramming that cookie into request via setHeader, but rather put it to cookie jar and let Qt handle the cookie insertion into requests. --- src/creds/shibboleth/shibbolethaccessmanager.cpp | 32 ++++++++++++++++++------ src/creds/shibboleth/shibbolethaccessmanager.h | 7 ++++-- src/creds/shibbolethcredentials.cpp | 7 +++++- src/creds/shibbolethcredentials.h | 3 +++ 4 files changed, 39 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/creds/shibboleth/shibbolethaccessmanager.cpp b/src/creds/shibboleth/shibbolethaccessmanager.cpp index 2a5461307..6b728c45c 100644 --- a/src/creds/shibboleth/shibbolethaccessmanager.cpp +++ b/src/creds/shibboleth/shibbolethaccessmanager.cpp @@ -11,6 +11,7 @@ * for more details. */ +#include #include #include "creds/shibboleth/shibbolethaccessmanager.h" @@ -18,20 +19,37 @@ namespace Mirall { -ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent) +ShibbolethAccessManager::ShibbolethAccessManager(const QNetworkCookie& cookie, QObject* parent) : QNetworkAccessManager (parent), _cookie(cookie) {} -QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) +QNetworkReply* ShibbolethAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) { - QNetworkRequest newRequest(request); - QList cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >()); + if (!_cookie.name().isEmpty()) { + QNetworkCookieJar* jar(cookieJar()); + QUrl url(request.url()); + QList cookies; - cookies << _cookie; - newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies)); + Q_FOREACH(const QNetworkCookie& cookie, jar->cookiesForUrl(url)) { + if (!cookie.name().startsWith("_shibsession_")) { + cookies << cookie; + } + } - return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); + cookies << _cookie; + jar->setCookiesFromUrl(cookies, url); + } + + qDebug() << "Creating a request to " << request.url().toString() << " with shibboleth cookie:" << _cookie.name(); + + return QNetworkAccessManager::createRequest (op, request, outgoingData); +} + +void ShibbolethAccessManager::setCookie(const QNetworkCookie& cookie) +{ + qDebug() << "Got new shibboleth cookie:" << cookie.name(); + _cookie = cookie; } } // ns Mirall diff --git a/src/creds/shibboleth/shibbolethaccessmanager.h b/src/creds/shibboleth/shibbolethaccessmanager.h index 9f0571d21..b0e3fd2b2 100644 --- a/src/creds/shibboleth/shibbolethaccessmanager.h +++ b/src/creds/shibboleth/shibbolethaccessmanager.h @@ -25,10 +25,13 @@ class ShibbolethAccessManager : public QNetworkAccessManager Q_OBJECT public: - ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0); + ShibbolethAccessManager(const QNetworkCookie& cookie, QObject* parent = 0); + +public Q_SLOTS: + void setCookie(const QNetworkCookie& cookie); protected: - QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); + QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); private: QNetworkCookie _cookie; diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp index 056f2c821..065df3ece 100644 --- a/src/creds/shibbolethcredentials.cpp +++ b/src/creds/shibbolethcredentials.cpp @@ -81,7 +81,11 @@ QNetworkCookie ShibbolethCredentials::cookie() const QNetworkAccessManager* ShibbolethCredentials::getQNAM() const { - return new ShibbolethAccessManager(_shibCookie); + ShibbolethAccessManager* qnam(new ShibbolethAccessManager(_shibCookie)); + + connect(this, SIGNAL(newCookie(QNetworkCookie)), + qnam, SLOT(setCookie(QNetworkCookie))); + return qnam; } bool ShibbolethCredentials::ready() const @@ -117,6 +121,7 @@ void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& coo _browser = 0; _ready = true; _shibCookie = cookie; + Q_EMIT newCookie(_shibCookie); Q_EMIT fetched(); } diff --git a/src/creds/shibbolethcredentials.h b/src/creds/shibbolethcredentials.h index a2ed78084..a238e294b 100644 --- a/src/creds/shibbolethcredentials.h +++ b/src/creds/shibbolethcredentials.h @@ -45,6 +45,9 @@ public: private Q_SLOTS: void onShibbolethCookieReceived(const QNetworkCookie& cookie); +Q_SIGNALS: + void newCookie(const QNetworkCookie& cookie); + private: QNetworkCookie _shibCookie; bool _ready; -- cgit v1.2.3 From 9413a30a08dea2d379a5dce53d3962c48d009abd Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 13:11:19 +0200 Subject: Fix build when using QtKeyChain. --- src/creds/http/credentialstore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/creds/http/credentialstore.cpp b/src/creds/http/credentialstore.cpp index 6f4533531..19229514b 100644 --- a/src/creds/http/credentialstore.cpp +++ b/src/creds/http/credentialstore.cpp @@ -211,7 +211,7 @@ void CredentialStore::slotKeyChainReadFinished(QKeychain::Job* job) if( _state == NoKeychainBackend ) { qDebug() << "No Storage Backend, falling back to Settings mode."; _type = CredentialStore::Settings; - fetchCredentials(_user); + fetchCredentials(); return; } -- cgit v1.2.3 From 9724e52f1b533042579e686cc8e58426c924c626 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 14:37:46 +0200 Subject: Fix warnings. Should be now compilable when run with -Wall -Wextra -Wpedantic -Werror. --- src/creds/credentialsfactory.cpp | 2 +- src/creds/http/httpconfigfile.cpp | 4 ++-- src/creds/httpcredentials.cpp | 6 +++--- src/creds/shibboleth/shibbolethwebview.cpp | 2 +- src/creds/shibbolethcredentials.cpp | 2 +- src/mirall/accountsettings.cpp | 5 +++++ src/mirall/application.cpp | 2 +- src/mirall/connectionvalidator.cpp | 8 +++----- src/mirall/fileutils.h | 2 +- src/mirall/folder.cpp | 12 ++++++------ src/mirall/folderstatusmodel.cpp | 2 +- src/mirall/folderwatcher_inotify.cpp | 2 +- src/mirall/inotify.cpp | 4 ++-- src/mirall/logbrowser.cpp | 4 ++-- src/mirall/owncloudinfo.cpp | 4 ++-- src/mirall/owncloudinfo.h | 2 +- src/wizard/owncloudsetuppage.cpp | 4 +--- src/wizard/owncloudwizard.cpp | 2 +- 18 files changed, 35 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/creds/credentialsfactory.cpp b/src/creds/credentialsfactory.cpp index 0106f3f73..72cc252a6 100644 --- a/src/creds/credentialsfactory.cpp +++ b/src/creds/credentialsfactory.cpp @@ -33,7 +33,7 @@ AbstractCredentials* create(const QString& type) } else if (type == "shibboleth") { return new ShibbolethCredentials; } else { - qWarning("Unknown credentials type: %d", qPrintable(type)); + qWarning("Unknown credentials type: %s", qPrintable(type)); return new DummyCredentials; } } diff --git a/src/creds/http/httpconfigfile.cpp b/src/creds/http/httpconfigfile.cpp index 366b6c1ee..e1e7a734b 100644 --- a/src/creds/http/httpconfigfile.cpp +++ b/src/creds/http/httpconfigfile.cpp @@ -55,7 +55,7 @@ void HttpConfigFile::setPassword(const QString& password) bool HttpConfigFile::passwordExists() const { - dataExists(QString(), QLatin1String(passwdC)); + return dataExists(QString(), QLatin1String(passwdC)); } void HttpConfigFile::removePassword() @@ -71,7 +71,7 @@ void HttpConfigFile::fixupOldPassword() if (dataExists(QString(), old)) { setPassword(retrieveData(QString(), old).toString()); } -}; +} void HttpConfigFile::removeOldPassword() { diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp index 2e4fa272e..82d3d63fa 100644 --- a/src/creds/httpcredentials.cpp +++ b/src/creds/httpcredentials.cpp @@ -31,9 +31,9 @@ namespace int getauth(const char *prompt, char *buf, size_t len, - int echo, - int verify, - void *userdata) + int /*echo*/, + int /*verify*/, + void */*userdata*/) { int re = 0; QMutex mutex; diff --git a/src/creds/shibboleth/shibbolethwebview.cpp b/src/creds/shibboleth/shibbolethwebview.cpp index b1ebc5f97..21ff4053f 100644 --- a/src/creds/shibboleth/shibbolethwebview.cpp +++ b/src/creds/shibboleth/shibbolethwebview.cpp @@ -35,7 +35,7 @@ ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) this->setPage (page); } -void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& url) +void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieList, const QUrl& /*url*/) { Q_FOREACH (const QNetworkCookie& cookie, cookieList) { if (cookie.name().startsWith ("_shibsession_")) { diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp index 065df3ece..6c61940ac 100644 --- a/src/creds/shibbolethcredentials.cpp +++ b/src/creds/shibbolethcredentials.cpp @@ -107,7 +107,7 @@ void ShibbolethCredentials::fetch() } } -void ShibbolethCredentials::persistForUrl(const QString& url) +void ShibbolethCredentials::persistForUrl(const QString& /*url*/) { // nothing to do here, we don't store session cookies. } diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index 797e3bf36..89916a258 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -552,6 +552,11 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf } timer->start(5000); break; + case Progress::Invalid: + case Progress::Download: + case Progress::Upload: + case Progress::Inactive: + break; } QString fileProgressString; diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 09ca5927f..44bd5a49d 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -160,7 +160,7 @@ Application::Application(int &argc, char **argv) : setupSystemTray(); slotSetupProxy(); - int cnt = folderMan->setupFolders(); + folderMan->setupFolders(); // startup procedure. QTimer::singleShot( 0, this, SLOT( slotCheckConnection() )); diff --git a/src/mirall/connectionvalidator.cpp b/src/mirall/connectionvalidator.cpp index e89c4b495..3c49efac1 100644 --- a/src/mirall/connectionvalidator.cpp +++ b/src/mirall/connectionvalidator.cpp @@ -27,7 +27,8 @@ ConnectionValidator::ConnectionValidator(QObject *parent) : } ConnectionValidator::ConnectionValidator(const QString& connection, QObject *parent) - :_connection(connection) + : QObject(parent), + _connection(connection) { ownCloudInfo::instance()->setCustomConfigHandle(_connection); } @@ -92,7 +93,7 @@ void ConnectionValidator::checkConnection() } } -void ConnectionValidator::slotStatusFound( const QString& url, const QString& versionStr, const QString& version, const QString& edition) +void ConnectionValidator::slotStatusFound( const QString& url, const QString& versionStr, const QString& version, const QString& /*edition*/) { // status.php was found. qDebug() << "** Application: ownCloud found: " << url << " with version " << versionStr << "(" << version << ")"; @@ -145,7 +146,6 @@ void ConnectionValidator::slotCheckAuthentication() void ConnectionValidator::slotAuthCheck( const QString& ,QNetworkReply *reply ) { - bool ok = true; Status stat = Connected; if( reply->error() == QNetworkReply::AuthenticationRequiredError || @@ -153,7 +153,6 @@ void ConnectionValidator::slotAuthCheck( const QString& ,QNetworkReply *reply ) qDebug() << "******** Password is wrong!"; _errors << "The provided credentials are wrong."; stat = CredentialsWrong; - ok = false; } // disconnect from ownCloud Info signals @@ -161,7 +160,6 @@ void ConnectionValidator::slotAuthCheck( const QString& ,QNetworkReply *reply ) this,SLOT(slotAuthCheck(QString,QNetworkReply*))); emit connectionResult( stat ); - } diff --git a/src/mirall/fileutils.h b/src/mirall/fileutils.h index e074585ad..117cf6c05 100644 --- a/src/mirall/fileutils.h +++ b/src/mirall/fileutils.h @@ -25,7 +25,7 @@ class FileUtils public: enum SubFolderListOption { SubFolderNoOptions = 0x0, - SubFolderRecursive = 0x1, + SubFolderRecursive = 0x1 }; Q_DECLARE_FLAGS(SubFolderListOptions, SubFolderListOption) diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index a11a410af..1e395e192 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -33,11 +33,11 @@ namespace Mirall { -void csyncLogCatcher(CSYNC *ctx, - int verbosity, - const char *function, +void csyncLogCatcher(CSYNC */*ctx*/, + int /*verbosity*/, + const char */*function*/, const char *buffer, - void *userdata) + void */*userdata*/) { Logger::instance()->csyncLog( QString::fromUtf8(buffer) ); } @@ -57,9 +57,9 @@ static QString replaceScheme(const QString &urlStr) Folder::Folder(const QString &alias, const QString &path, const QString& secondPath, QObject *parent) : QObject(parent) + , _pollTimer(new QTimer(this)) , _path(path) , _secondPath(secondPath) - , _pollTimer(new QTimer(this)) , _alias(alias) , _enabled(true) , _thread(0) @@ -252,7 +252,7 @@ SyncResult Folder::syncResult() const return _syncResult; } -void Folder::evaluateSync(const QStringList &pathList) +void Folder::evaluateSync(const QStringList &/*pathList*/) { if( !_enabled ) { qDebug() << "*" << alias() << "sync skipped, disabled!"; diff --git a/src/mirall/folderstatusmodel.cpp b/src/mirall/folderstatusmodel.cpp index c54a864b7..f10e8b0d1 100644 --- a/src/mirall/folderstatusmodel.cpp +++ b/src/mirall/folderstatusmodel.cpp @@ -281,7 +281,7 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem & painter->restore(); } -bool FolderStatusDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) +bool FolderStatusDelegate::editorEvent ( QEvent * /*event*/, QAbstractItemModel * /*model*/, const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/ ) { return false; } diff --git a/src/mirall/folderwatcher_inotify.cpp b/src/mirall/folderwatcher_inotify.cpp index 7ed79d969..4257efb36 100644 --- a/src/mirall/folderwatcher_inotify.cpp +++ b/src/mirall/folderwatcher_inotify.cpp @@ -78,7 +78,7 @@ void FolderWatcherPrivate::slotAddFolderRecursive(const QString &path) qDebug() << " `-> and" << subdirs << "subdirectories"; } -void FolderWatcherPrivate::slotINotifyEvent(int mask, int cookie, const QString &path) +void FolderWatcherPrivate::slotINotifyEvent(int mask, int /*cookie*/, const QString &path) { int lastMask = _lastMask; QString lastPath = _lastPath; diff --git a/src/mirall/inotify.cpp b/src/mirall/inotify.cpp index 8395f7462..126a1d57e 100644 --- a/src/mirall/inotify.cpp +++ b/src/mirall/inotify.cpp @@ -47,7 +47,7 @@ INotify::INotify(QObject *parent, int mask) _buffer = (char *) malloc(_buffer_size); } -void INotify::slotActivated(int fd) +void INotify::slotActivated(int /*fd*/) { int len; struct inotify_event* event; @@ -82,7 +82,7 @@ void INotify::slotActivated(int fd) // reset counter i = 0; // while there are enough events in the buffer - while(i + sizeof(struct inotify_event) < len) { + while(i + sizeof(struct inotify_event) < static_cast(len)) { // cast an inotify_event event = (struct inotify_event*)&_buffer[i]; // with the help of watch descriptor, retrieve, corresponding INotify diff --git a/src/mirall/logbrowser.cpp b/src/mirall/logbrowser.cpp index fbdcebada..2ddf41710 100644 --- a/src/mirall/logbrowser.cpp +++ b/src/mirall/logbrowser.cpp @@ -57,8 +57,8 @@ LogWidget::LogWidget(QWidget *parent) LogBrowser::LogBrowser(QWidget *parent) : QDialog(parent), _logWidget( new LogWidget(parent) ), - _logstream(0), - _doFileFlush(false) + _doFileFlush(false), + _logstream(0) { setObjectName("LogBrowser"); // for save/restoreGeometry() setWindowTitle(tr("Log Output")); diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index 7f0b85269..2cb267a9f 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -51,8 +51,8 @@ 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)), diff --git a/src/mirall/owncloudinfo.h b/src/mirall/owncloudinfo.h index a9d467e70..6fde51042 100644 --- a/src/mirall/owncloudinfo.h +++ b/src/mirall/owncloudinfo.h @@ -156,6 +156,6 @@ private: qint64 _lastQuotaTotalBytes; }; -}; +} // ns Mirall #endif // OWNCLOUDINFO_H diff --git a/src/wizard/owncloudsetuppage.cpp b/src/wizard/owncloudsetuppage.cpp index df21570d2..859fcfdf0 100644 --- a/src/wizard/owncloudsetuppage.cpp +++ b/src/wizard/owncloudsetuppage.cpp @@ -109,7 +109,7 @@ void OwncloudSetupPage::setupCustomization() } // slot hit from textChanged of the url entry field. -void OwncloudSetupPage::slotUrlChanged(const QString& ocUrl) +void OwncloudSetupPage::slotUrlChanged(const QString& /*ocUrl*/) { slotHandleUserInput(); @@ -259,8 +259,6 @@ QString OwncloudSetupPage::localFolder() const bool OwncloudSetupPage::validatePage() { - bool re = false; - if( ! _authTypeKnown) { setErrorString(QString::null); _checking = true; diff --git a/src/wizard/owncloudwizard.cpp b/src/wizard/owncloudwizard.cpp index 713114b0e..c6f0f9e54 100644 --- a/src/wizard/owncloudwizard.cpp +++ b/src/wizard/owncloudwizard.cpp @@ -173,7 +173,7 @@ void OwncloudWizard::displayError( const QString& msg ) } } -void OwncloudWizard::appendToConfigurationLog( const QString& msg, LogType type ) +void OwncloudWizard::appendToConfigurationLog( const QString& msg, LogType /*type*/ ) { _setupLog << msg; qDebug() << "Setup-Log: " << msg; -- cgit v1.2.3 From 6543a01418e5dd35e6bf6786c4654944f85fe2fc Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 14:53:42 +0200 Subject: Fix warnings emitted by clang. --- src/mirall/csyncthread.h | 2 +- src/mirall/folderstatusmodel.cpp | 2 +- src/mirall/folderstatusmodel.h | 2 +- src/mirall/systray.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index c737908ee..14d8e0dd3 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -85,7 +85,7 @@ private: bool _hasFiles; // true if there is at least one file that is not ignored or removed - friend class CSyncRunScopeHelper; + friend struct CSyncRunScopeHelper; }; } diff --git a/src/mirall/folderstatusmodel.cpp b/src/mirall/folderstatusmodel.cpp index f10e8b0d1..80ef75ac5 100644 --- a/src/mirall/folderstatusmodel.cpp +++ b/src/mirall/folderstatusmodel.cpp @@ -26,7 +26,7 @@ FolderStatusModel::FolderStatusModel() } -Qt::ItemFlags FolderStatusModel::flags ( const QModelIndex& ) +Qt::ItemFlags FolderStatusModel::flags ( const QModelIndex& ) const { return Qt::ItemIsSelectable; } diff --git a/src/mirall/folderstatusmodel.h b/src/mirall/folderstatusmodel.h index de4923699..ec8537db2 100644 --- a/src/mirall/folderstatusmodel.h +++ b/src/mirall/folderstatusmodel.h @@ -24,7 +24,7 @@ class FolderStatusModel : public QStandardItemModel { public: FolderStatusModel(); - virtual Qt::ItemFlags flags( const QModelIndex& ); + virtual Qt::ItemFlags flags( const QModelIndex& ) const; QVariant data(const QModelIndex &index, int role) const; }; diff --git a/src/mirall/systray.h b/src/mirall/systray.h index a3aaefa03..85e2a86cb 100644 --- a/src/mirall/systray.h +++ b/src/mirall/systray.h @@ -26,4 +26,4 @@ public: void showMessage(const QString & title, const QString & message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000); }; -#endif //SYSTRAY_H \ No newline at end of file +#endif //SYSTRAY_H -- cgit v1.2.3 From 3b6aeb1fc8a084dea3f7a2ccab9780b87f922be6 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 15:07:33 +0200 Subject: Make browser inside Shibboleth wizard page a bit larger. --- src/wizard/owncloudshibbolethcredspage.cpp | 1 + src/wizard/owncloudshibbolethcredspage.ui | 38 ------------------------------ 2 files changed, 1 insertion(+), 38 deletions(-) (limited to 'src') diff --git a/src/wizard/owncloudshibbolethcredspage.cpp b/src/wizard/owncloudshibbolethcredspage.cpp index 8013f3c7c..6d0f0ff90 100644 --- a/src/wizard/owncloudshibbolethcredspage.cpp +++ b/src/wizard/owncloudshibbolethcredspage.cpp @@ -61,6 +61,7 @@ void OwncloudShibbolethCredsPage::initializePage() WizardCommon::initErrorLabel(_ui.errorLabel); _browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified()), this); + _browser->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); diff --git a/src/wizard/owncloudshibbolethcredspage.ui b/src/wizard/owncloudshibbolethcredspage.ui index 832d7eb44..6c86c32b5 100644 --- a/src/wizard/owncloudshibbolethcredspage.ui +++ b/src/wizard/owncloudshibbolethcredspage.ui @@ -28,22 +28,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 45 - 17 - - - - @@ -68,22 +52,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 20 - - - - @@ -109,12 +77,6 @@ - horizontalSpacer - verticalSpacer - horizontalSpacer_2 - topLabel - bottomLabel - errorLabel_2 -- cgit v1.2.3 From fa95a638af313f42187879545bd645402a49c13a Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 15:17:10 +0200 Subject: Fill username in HTTP credentials setup page. --- src/mirall/owncloudsetupwizard.cpp | 4 ---- src/wizard/owncloudhttpcredspage.cpp | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index faffeb8f6..9d4743e78 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -79,10 +79,6 @@ void OwncloudSetupWizard::startWizard() bool configExists = !( url.isEmpty()/* || user.isEmpty()*/ ); _ocWizard->setConfigExists( configExists ); - //if( !user.isEmpty() ) { - // _ocWizard->setOCUser( user ); - //} - if( !url.isEmpty() ) { _ocWizard->setOCUrl( url ); } diff --git a/src/wizard/owncloudhttpcredspage.cpp b/src/wizard/owncloudhttpcredspage.cpp index 5bd550d89..573423e46 100644 --- a/src/wizard/owncloudhttpcredspage.cpp +++ b/src/wizard/owncloudhttpcredspage.cpp @@ -20,6 +20,7 @@ #include "mirall/theme.h" #include "wizard/owncloudwizardcommon.h" #include "creds/httpcredentials.h" +#include "mirall/mirallconfigfile.h" namespace Mirall { @@ -62,8 +63,18 @@ void OwncloudHttpCredsPage::setupCustomization() void OwncloudHttpCredsPage::initializePage() { - WizardCommon::initErrorLabel(_ui.errorLabel); - _ui.leUsername->setFocus(); + WizardCommon::initErrorLabel(_ui.errorLabel); + MirallConfigFile cfgFile; + HttpCredentials* httpCreds(dynamic_cast< HttpCredentials* >(cfgFile.getCredentials())); + + if (httpCreds) { + const QString user = httpCreds->user(); + + if (!user.isEmpty()) { + _ui.leUsername->setText(user); + } + } + _ui.leUsername->setFocus(); } void OwncloudHttpCredsPage::cleanupPage() -- cgit v1.2.3 From 945951cda5645103af1e51804702b839c40d5292 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Jul 2013 15:26:45 +0200 Subject: Fix indentation. --- src/wizard/owncloudhttpcredspage.cpp | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/wizard/owncloudhttpcredspage.cpp b/src/wizard/owncloudhttpcredspage.cpp index 573423e46..713ea508d 100644 --- a/src/wizard/owncloudhttpcredspage.cpp +++ b/src/wizard/owncloudhttpcredspage.cpp @@ -32,17 +32,17 @@ OwncloudHttpCredsPage::OwncloudHttpCredsPage() _checking(false), _progressIndi(new QProgressIndicator (this)) { - _ui.setupUi(this); + _ui.setupUi(this); - registerField( QLatin1String("OCUser*"), _ui.leUsername); - registerField( QLatin1String("OCPasswd*"), _ui.lePassword); + registerField( QLatin1String("OCUser*"), _ui.leUsername); + registerField( QLatin1String("OCPasswd*"), _ui.lePassword); - setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); - setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Enter user credentials"))); + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Enter user credentials"))); - _ui.resultLayout->addWidget( _progressIndi ); - stopSpinner(); - setupCustomization(); + _ui.resultLayout->addWidget( _progressIndi ); + stopSpinner(); + setupCustomization(); } void OwncloudHttpCredsPage::setupCustomization() @@ -79,33 +79,33 @@ void OwncloudHttpCredsPage::initializePage() void OwncloudHttpCredsPage::cleanupPage() { - _ui.leUsername->clear(); - _ui.lePassword->clear(); + _ui.leUsername->clear(); + _ui.lePassword->clear(); } bool OwncloudHttpCredsPage::validatePage() { - if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) { - return false; - } + if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) { + return false; + } - if (!_connected) { - _checking = true; - emit completeChanged(); - emit connectToOCUrl(field("OCUrl").toString().simplified()); + if (!_connected) { + _checking = true; + emit completeChanged(); + emit connectToOCUrl(field("OCUrl").toString().simplified()); - return false; - } else { - _checking = false; - emit completeChanged(); + return false; + } else { + _checking = false; + emit completeChanged(); + return true; + } return true; - } - return true; } int OwncloudHttpCredsPage::nextId() const { - return WizardCommon::Page_Result; + return WizardCommon::Page_Result; } void OwncloudHttpCredsPage::setConnected( bool comp ) -- cgit v1.2.3 From 50edac8ee8d4472362470e82ee1f4985c4ce0d14 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Wed, 31 Jul 2013 15:46:41 +0200 Subject: Split setup page into server and advanced parts. --- src/CMakeLists.txt | 3 + src/mirall/owncloudsetupwizard.cpp | 489 +++++++++++++++-------------- src/mirall/owncloudsetupwizard.h | 70 ++--- src/wizard/owncloudadvancedsetuppage.cpp | 220 +++++++++++++ src/wizard/owncloudadvancedsetuppage.h | 72 +++++ src/wizard/owncloudadvancedsetuppage.ui | 267 ++++++++++++++++ src/wizard/owncloudhttpcredspage.cpp | 5 +- src/wizard/owncloudsetupnocredspage.ui | 351 ++------------------- src/wizard/owncloudsetuppage.cpp | 129 +------- src/wizard/owncloudsetuppage.h | 10 - src/wizard/owncloudshibbolethcredspage.cpp | 2 +- src/wizard/owncloudwizard.cpp | 65 ++-- src/wizard/owncloudwizard.h | 10 +- src/wizard/owncloudwizardcommon.h | 3 +- 14 files changed, 905 insertions(+), 791 deletions(-) create mode 100644 src/wizard/owncloudadvancedsetuppage.cpp create mode 100644 src/wizard/owncloudadvancedsetuppage.h create mode 100644 src/wizard/owncloudadvancedsetuppage.ui (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd7003c1d..b1574a535 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ wizard/owncloudsetupnocredspage.ui wizard/owncloudhttpcredspage.ui wizard/owncloudwizardresultpage.ui wizard/owncloudshibbolethcredspage.ui +wizard/owncloudadvancedsetuppage.ui ) set(3rdparty_SRC @@ -178,6 +179,7 @@ set(mirall_SRCS wizard/owncloudwizardresultpage.cpp wizard/owncloudwizardcommon.cpp wizard/owncloudshibbolethcredspage.cpp + wizard/owncloudadvancedsetuppage.cpp mirall/owncloudsetupwizard.cpp mirall/updatedetector.cpp mirall/occinfo.cpp @@ -202,6 +204,7 @@ set(mirall_HEADERS wizard/owncloudwizardresultpage.h wizard/owncloudwizardcommon.h wizard/owncloudshibbolethcredspage.h + wizard/owncloudadvancedsetuppage.h mirall/folderstatusmodel.h mirall/updatedetector.h mirall/sslerrordialog.h diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index 9d4743e78..f0d2beee8 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -31,25 +31,25 @@ namespace Mirall { -OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent ) : +OwncloudSetupWizard::OwncloudSetupWizard(QObject* parent) : QObject( parent ), - _mkdirRequestReply(0), - _checkInstallationRequest(0) + _ocWizard(new OwncloudWizard), + _mkdirRequestReply(), + _checkInstallationRequest(), + _checkRemoteFolderRequest(), + _configHandle(), + _remoteFolder() { - _ocWizard = new OwncloudWizard(); - - connect( _ocWizard, SIGNAL(connectToOCUrl( const QString& ) ), - this, SLOT(slotConnectToOCUrl( const QString& ))); - connect( _ocWizard, SIGNAL(determineAuthType(const QString&)), this, SLOT(slotDetermineAuthType(const QString&))); - + connect( _ocWizard, SIGNAL(connectToOCUrl( const QString& ) ), + this, SLOT(slotConnectToOCUrl( const QString& ))); + connect( _ocWizard, SIGNAL(createLocalAndRemoteFolders(QString, QString)), + this, SLOT(slotCreateLocalAndRemoteFolders(QString, QString))); connect( _ocWizard, SIGNAL(finished(int)),this,SLOT(slotAssistantFinished(int))); connect( _ocWizard, SIGNAL(clearPendingRequests()), this, SLOT(slotClearPendingRequests())); - - _ocWizard->setWindowTitle( tr("%1 Connection Wizard").arg( Theme::instance()->appNameGUI() ) ); } OwncloudSetupWizard::~OwncloudSetupWizard() @@ -57,10 +57,6 @@ OwncloudSetupWizard::~OwncloudSetupWizard() _ocWizard->deleteLater(); } -OwncloudWizard *OwncloudSetupWizard::wizard() { - return _ocWizard; -} - void OwncloudSetupWizard::runWizard(QObject* obj, const char* amember, QWidget *parent) { OwncloudSetupWizard *wiz = new OwncloudSetupWizard(parent); @@ -89,13 +85,13 @@ void OwncloudSetupWizard::startWizard() QString localFolder = Theme::instance()->defaultClientFolder(); // if its a relative path, prepend with users home dir, otherwise use as absolute path - if( !localFolder.startsWith(QLatin1Char('/')) ) { - localFolder = QDir::homePath() + QDir::separator() + Theme::instance()->defaultClientFolder(); + if( !QDir(localFolder).isAbsolute() ) { + localFolder = QDir::homePath() + QDir::separator() + localFolder; } _ocWizard->setProperty("localFolder", localFolder); _ocWizard->setRemoteFolder(_remoteFolder); - _ocWizard->setStartId(WizardCommon::Page_oCSetup); + _ocWizard->setStartId(WizardCommon::Page_ServerSetup); _ocWizard->restart(); @@ -106,94 +102,135 @@ void OwncloudSetupWizard::startWizard() _ocWizard->raise(); } - -// Method executed when the user ends the wizard, either with 'accept' or 'reject'. -// accept the custom config to be the main one if Accepted. -void OwncloudSetupWizard::slotAssistantFinished( int result ) +void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) { - MirallConfigFile cfg( _configHandle ); - FolderMan *folderMan = FolderMan::instance(); + QString url(serverUrl); + qDebug() << "Connect to url: " << url; + _ocWizard->setField(QLatin1String("OCUrl"), url ); + _ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 to determine authentication type...") + .arg( Theme::instance()->appNameGUI() ).arg(url) ); + // write a temporary config. + QDateTime now = QDateTime::currentDateTime(); - if( result == QDialog::Rejected ) { - // the old config remains valid. Remove the temporary one. - cfg.cleanupCustomConfig(); - qDebug() << "Rejected the new config, use the old!"; - } else if( result == QDialog::Accepted ) { - AbstractCredentials* credentials(_ocWizard->getCredentials()); + // remove a possibly existing custom config. + if( ! _configHandle.isEmpty() ) { + // remove the old config file. + MirallConfigFile oldConfig( _configHandle ); + oldConfig.cleanupCustomConfig(); + } - qDebug() << "Config Changes were accepted!"; + _configHandle = now.toString(QLatin1String("MMddyyhhmmss")); - // go through all folders and remove the journals if the server changed. + MirallConfigFile cfgFile( _configHandle ); + if( url.isEmpty() ) return; + if( !( url.startsWith(QLatin1String("https://")) || url.startsWith(QLatin1String("http://"))) ) { + qDebug() << "url does not start with a valid protocol, assuming https."; + url.prepend(QLatin1String("https://")); + // FIXME: give a hint about the auto completion + _ocWizard->setOCUrl(url); + } + cfgFile.writeOwncloudConfig( Theme::instance()->appName(), + url, + new DummyCredentials); + + ownCloudInfo* info(ownCloudInfo::instance()); + // If there is already a config, take its proxy config. + if( info->isConfigured() ) { MirallConfigFile prevCfg; - QUrl prevUrl( prevCfg.ownCloudUrl() ); - QUrl newUrl( cfg.ownCloudUrl() ); - AbstractCredentials* oldCredentials(prevCfg.getCredentials()); + cfgFile.setProxyType( prevCfg.proxyType(), prevCfg.proxyHostName(), prevCfg.proxyPort(), + prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); + } - bool urlHasChanged = (prevUrl.host() != newUrl.host() || - prevUrl.port() != newUrl.port() || - prevUrl.path() != newUrl.path()); + info->setCustomConfigHandle( _configHandle ); + if( info->isConfigured() ) { + // reset the SSL Untrust flag to let the SSL dialog appear again. + info->resetSSLUntrust(); + connect(info, SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), + SLOT(slotOwnCloudFoundAuth(QString,QString,QString,QString))); + connect(info, SIGNAL(noOwncloudFound(QNetworkReply*)), + SLOT(slotNoOwnCloudFoundAuth(QNetworkReply*))); + _checkInstallationRequest = info->checkInstallation(); + } else { + qDebug() << " ownCloud seems not to be configured, can not start test connect."; + } +} - // if the user changed, its also a changed url. - if(credentials->changed(oldCredentials)) { - urlHasChanged = true; - qDebug() << "The User has changed, same as url change."; - } +void OwncloudSetupWizard::slotOwnCloudFoundAuth( const QString& url, const QString& infoString, const QString& version, const QString& ) +{ + disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), + this, SLOT(slotOwnCloudFoundAuth(QString,QString,QString,QString))); + disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), + this, SLOT(slotNoOwnCloudFoundAuth(QNetworkReply*))); - const QString localFolder = _ocWizard->localFolder(); - bool acceptCfg = true; + _ocWizard->appendToConfigurationLog(tr("Successfully connected to %1: %2 version %3 (%4)

") + .arg( url ).arg(Theme::instance()->appNameGUI()).arg(infoString).arg(version)); - if( urlHasChanged ) { - // first terminate sync jobs. - folderMan->terminateSyncProcess(); + QNetworkAccessManager* nm = new QNetworkAccessManager(this); + // TODO: We should get this path from owncloud info. + QNetworkReply* reply = nm->get (QNetworkRequest (url + "/remote.php/webdav/")); - folderMan->unloadAllFolders(); + connect (reply, SIGNAL(finished()), + this, SLOT(slotAuthCheckReplyFinished())); - bool startFromScratch = _ocWizard->field( "OCSyncFromScratch" ).toBool(); - if( startFromScratch ) { - // first try to rename (backup) the current local dir. - bool renameOk = false; - while( !renameOk ) { - renameOk = folderMan->startFromScratch(localFolder); - if( ! renameOk ) { - QMessageBox::StandardButton but; - but = QMessageBox::question( 0, tr("Folder rename failed"), - tr("Can't remove and back up the folder because the folder or a file in it is open in another program." - "Please close the folder or file and hit retry or cancel the setup."), QMessageBox::Retry | QMessageBox::Abort, QMessageBox::Retry); - if( but == QMessageBox::Abort ) { - renameOk = true; - acceptCfg = false; - } - } - } - } - } - // save the user credentials and afterwards clear the cred store. - if( acceptCfg ) { - cfg.acceptCustomConfig(); - } + nm->setProperty ("mirallRedirs", QVariant (0)); +} - // Now write the resulting folder definition if folder names are set. - if( acceptCfg && urlHasChanged ) { - folderMan->removeAllFolderDefinitions(); - folderMan->addFolderDefinition(Theme::instance()->appName(), - localFolder, _remoteFolder ); - _ocWizard->appendToConfigurationLog(tr("Local sync folder %1 successfully created!").arg(localFolder)); +void OwncloudSetupWizard::slotAuthCheckReplyFinished() +{ + QNetworkReply* reply = qobject_cast< QNetworkReply* > (sender ()); + QUrl redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); + QNetworkAccessManager* nm = reply->manager (); + const int redirCount = nm->property ("mirallRedirs").toInt(); + + if (redirCount > 10) { + redirection.clear (); + } + + disconnect (reply, SIGNAL(finished()), + this, SLOT(slotAuthCheckReplyFinished())); + if ((reply->error () == QNetworkReply::AuthenticationRequiredError) || redirection.isEmpty()) { + reply->deleteLater(); + nm->deleteLater(); + _ocWizard->setAuthType (WizardCommon::HttpCreds); + } else if (redirection.toString().endsWith ("/remote.php/webdav/")) { + QNetworkReply* newReply = nm->get (QNetworkRequest(redirection)); + + connect (newReply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(slotAuthCheckReplyError(QNetworkReply::NetworkError))); + connect (newReply, SIGNAL(finished()), + this, SLOT(slotAuthCheckReplyFinished(QNetworkReply::NetworkError))); + reply->deleteLater(); + + nm->setProperty ("mirallRedirs", QVariant(redirCount + 1)); + } else { + QRegExp shibbolethyWords ("SAML|wayf"); + + shibbolethyWords.setCaseSensitivity (Qt::CaseInsensitive); + if (redirection.toString ().contains (shibbolethyWords)) { + _ocWizard->setAuthType(WizardCommon::Shibboleth); } else { - // url is unchanged. Only the password was changed. - if( acceptCfg ) { - qDebug() << "Only password was changed, no changes to folder configuration."; - } else { - qDebug() << "User interrupted change of configuration."; - } + // TODO: Send an error. + // eh? + _ocWizard->setAuthType (WizardCommon::HttpCreds); } + reply->deleteLater(); + nm->deleteLater(); } +} - // clear the custom config handle - _configHandle.clear(); - ownCloudInfo::instance()->setCustomConfigHandle( QString::null ); +void OwncloudSetupWizard::slotNoOwnCloudFoundAuth( QNetworkReply *err ) +{ + disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), + this, SLOT(slotOwnCloudFound(QString,QString,QString,QString))); + disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), + this, SLOT(slotNoOwnCloudFound(QNetworkReply*))); - // notify others. - emit ownCloudWizardDone( result ); + _ocWizard->displayError(tr("Failed to connect to %1:
%2"). + arg(Theme::instance()->appNameGUI()).arg(err->errorString())); + + // remove the config file again + MirallConfigFile cfgFile( _configHandle ); + cfgFile.cleanupCustomConfig(); } void OwncloudSetupWizard::slotConnectToOCUrl( const QString& url ) @@ -205,23 +242,6 @@ void OwncloudSetupWizard::slotConnectToOCUrl( const QString& url ) testOwnCloudConnect(); } -void OwncloudSetupWizard::slotClearPendingRequests() -{ - qDebug() << "Pending request: " << _mkdirRequestReply; - if( _mkdirRequestReply && _mkdirRequestReply->isRunning() ) { - qDebug() << "ABORTing pending mkdir request."; - _mkdirRequestReply->abort(); - } - if( _checkInstallationRequest && _checkInstallationRequest->isRunning() ) { - qDebug() << "ABORTing pending check installation request."; - _checkInstallationRequest->abort(); - } - if( _checkRemoteFolderRequest && _checkRemoteFolderRequest->isRunning() ) { - qDebug() << "ABORTing pending remote folder check request."; - _checkRemoteFolderRequest->abort(); - } -} - void OwncloudSetupWizard::testOwnCloudConnect() { // write a temporary config. @@ -258,21 +278,39 @@ void OwncloudSetupWizard::testOwnCloudConnect() prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); } - // enable the finish button. - _ocWizard->button( QWizard::FinishButton )->setEnabled( true ); + connect( info,SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), + this,SLOT(slotConnectionCheck(QString,QNetworkReply*))); - // start the local folder creation - setupLocalSyncFolder(); + qDebug() << "# checking for authentication settings."; + _checkRemoteFolderRequest = info->getWebDAVPath(_remoteFolder ); // this call needs to be authenticated. + // continue in slotConnectionCheck } -void OwncloudSetupWizard::setupLocalSyncFolder() +void OwncloudSetupWizard::slotConnectionCheck(const QString&, QNetworkReply* reply) +{ + // disconnect from ownCloud Info signals + disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), + this, SLOT(slotConnectionCheck(QString,QNetworkReply*))); + + switch (reply->error()) { + case QNetworkReply::NoError: + case QNetworkReply::ContentNotFoundError: + _ocWizard->successfulStep(); + break; + + default: + _ocWizard->displayError(tr("Error: Wrong credentials.")); + break; + } +} + +void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFolder, const QString& remoteFolder) { - const QString localFolder = _ocWizard->property("localFolder").toString(); qDebug() << "Setup local sync folder for new oC connection " << localFolder; - QDir fi( localFolder ); + const QDir fi( localFolder ); // FIXME: Show problems with local folder properly. - bool localFolderOk = true; + if( fi.exists() ) { // there is an existing local folder. If its non empty, it can only be synced if the // ownCloud is newly created. @@ -303,7 +341,7 @@ void OwncloudSetupWizard::checkRemoteFolder() connect( info,SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), this,SLOT(slotAuthCheckReply(QString,QNetworkReply*))); - qDebug() << "# checking for authentication settings."; + qDebug() << "# checking for existence of remote folder."; info->setCustomConfigHandle(_configHandle); _checkRemoteFolderRequest = info->getWebDAVPath(_remoteFolder ); // this call needs to be authenticated. // continue in slotAuthCheckReply @@ -321,22 +359,12 @@ void OwncloudSetupWizard::slotAuthCheckReply( const QString&, QNetworkReply *rep if( errId == QNetworkReply::NoError ) { qDebug() << "******** Remote folder found, all cool!"; - } else if( errId == QNetworkReply::AuthenticationRequiredError ) { // returned if the user is wrong. - qDebug() << "******** Password is wrong!"; - error = tr("The given credentials do not authenticate."); - ok = false; - } else if( errId == QNetworkReply::OperationCanceledError ) { - // the username was wrong and ownCloudInfo was closing the request after a couple of auth tries. - qDebug() << "******** Username or password is wrong!"; - error = tr("Username or password is wrong!"); - ok = false; } else if( errId == QNetworkReply::ContentNotFoundError ) { - // FIXME try to create the remote folder! - if( !createRemoteFolder() ) { + if( createRemoteFolder() ) { + return; // Finish here, the mkdir request will go on. + } else { error = tr("The remote folder could not be accessed!"); ok = false; - } else { - return; // Finish here, the mkdir request will go on. } } else { error = tr("Error: %1").arg(reply->errorString()); @@ -345,8 +373,6 @@ void OwncloudSetupWizard::slotAuthCheckReply( const QString&, QNetworkReply *rep if( !ok ) { _ocWizard->displayError(error); - } else { - _ocWizard->setRemoteFolder( _remoteFolder ); } finalizeSetup( ok ); @@ -416,142 +442,119 @@ void OwncloudSetupWizard::finalizeSetup( bool success ) + tr("Successfully connected to %1!") .arg(Theme::instance()->appNameGUI()) + QLatin1String("

")); + _ocWizard->successfulStep(); } else { _ocWizard->appendToConfigurationLog(QLatin1String("

") + tr("Connection to %1 could not be established. Please check again.") .arg(Theme::instance()->appNameGUI()) + QLatin1String("

")); } - _ocWizard->successfullyConnected(success); } -void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl) +// Method executed when the user ends the wizard, either with 'accept' or 'reject'. +// accept the custom config to be the main one if Accepted. +void OwncloudSetupWizard::slotAssistantFinished( int result ) { - QString url(serverUrl); - qDebug() << "Connect to url: " << url; - _ocWizard->setField(QLatin1String("OCUrl"), url ); - _ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 to determine authentication type...") - .arg( Theme::instance()->appNameGUI() ).arg(url) ); - // write a temporary config. - QDateTime now = QDateTime::currentDateTime(); - - // remove a possibly existing custom config. - if( ! _configHandle.isEmpty() ) { - // remove the old config file. - MirallConfigFile oldConfig( _configHandle ); - oldConfig.cleanupCustomConfig(); - } + MirallConfigFile cfg( _configHandle ); + FolderMan *folderMan = FolderMan::instance(); - _configHandle = now.toString(QLatin1String("MMddyyhhmmss")); + if( result == QDialog::Rejected ) { + // the old config remains valid. Remove the temporary one. + cfg.cleanupCustomConfig(); + qDebug() << "Rejected the new config, use the old!"; + } else if( result == QDialog::Accepted ) { + AbstractCredentials* credentials(_ocWizard->getCredentials()); - MirallConfigFile cfgFile( _configHandle ); - if( url.isEmpty() ) return; - if( !( url.startsWith(QLatin1String("https://")) || url.startsWith(QLatin1String("http://"))) ) { - qDebug() << "url does not start with a valid protocol, assuming https."; - url.prepend(QLatin1String("https://")); - // FIXME: give a hint about the auto completion - _ocWizard->setOCUrl(url); - } - cfgFile.writeOwncloudConfig( Theme::instance()->appName(), - url, - new DummyCredentials); + qDebug() << "Config Changes were accepted!"; - ownCloudInfo* info(ownCloudInfo::instance()); - // If there is already a config, take its proxy config. - if( info->isConfigured() ) { + // go through all folders and remove the journals if the server changed. MirallConfigFile prevCfg; - cfgFile.setProxyType( prevCfg.proxyType(), prevCfg.proxyHostName(), prevCfg.proxyPort(), - prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() ); - } + QUrl prevUrl( prevCfg.ownCloudUrl() ); + QUrl newUrl( cfg.ownCloudUrl() ); + AbstractCredentials* oldCredentials(prevCfg.getCredentials()); - info->setCustomConfigHandle( _configHandle ); - if( info->isConfigured() ) { - // reset the SSL Untrust flag to let the SSL dialog appear again. - info->resetSSLUntrust(); - connect(info, SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), - SLOT(slotOwnCloudFoundAuth(QString,QString,QString,QString))); - connect(info, SIGNAL(noOwncloudFound(QNetworkReply*)), - SLOT(slotNoOwnCloudFoundAuth(QNetworkReply*))); - _checkInstallationRequest = info->checkInstallation(); - } else { - qDebug() << " ownCloud seems not to be configured, can not start test connect."; - } -} + bool urlHasChanged = (prevUrl.host() != newUrl.host() || + prevUrl.port() != newUrl.port() || + prevUrl.path() != newUrl.path()); -void OwncloudSetupWizard::slotOwnCloudFoundAuth( const QString& url, const QString& infoString, const QString& version, const QString& ) -{ - disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), - this, SLOT(slotOwnCloudFoundAuth(QString,QString,QString,QString))); - disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), - this, SLOT(slotNoOwnCloudFoundAuth(QNetworkReply*))); + // if the user changed, its also a changed url. + if(credentials->changed(oldCredentials)) { + urlHasChanged = true; + qDebug() << "The User has changed, same as url change."; + } - _ocWizard->appendToConfigurationLog(tr("Successfully connected to %1: %2 version %3 (%4)

") - .arg( url ).arg(Theme::instance()->appNameGUI()).arg(infoString).arg(version)); + const QString localFolder = _ocWizard->localFolder(); + bool acceptCfg = true; - QNetworkAccessManager* nm = new QNetworkAccessManager(this); - QNetworkReply* reply = nm->get (QNetworkRequest (url + "/remote.php/webdav/")); + if( urlHasChanged ) { + // first terminate sync jobs. + folderMan->terminateSyncProcess(); - connect (reply, SIGNAL(finished()), - this, SLOT(slotAuthCheckReplyFinished())); + folderMan->unloadAllFolders(); - nm->setProperty ("mirallRedirs", QVariant (0)); -} + bool startFromScratch = _ocWizard->field( "OCSyncFromScratch" ).toBool(); + if( startFromScratch ) { + // first try to rename (backup) the current local dir. + bool renameOk = false; + while( !renameOk ) { + renameOk = folderMan->startFromScratch(localFolder); + if( ! renameOk ) { + QMessageBox::StandardButton but; + but = QMessageBox::question( 0, tr("Folder rename failed"), + tr("Can't remove and back up the folder because the folder or a file in it is open in another program." + "Please close the folder or file and hit retry or cancel the setup."), QMessageBox::Retry | QMessageBox::Abort, QMessageBox::Retry); + if( but == QMessageBox::Abort ) { + renameOk = true; + acceptCfg = false; + } + } + } + } + } + // save the user credentials and afterwards clear the cred store. + if( acceptCfg ) { + cfg.acceptCustomConfig(); + } -void OwncloudSetupWizard::slotAuthCheckReplyFinished() -{ - QNetworkReply* reply = qobject_cast< QNetworkReply* > (sender ()); - QUrl redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); - QNetworkAccessManager* nm = reply->manager (); - const int redirCount = nm->property ("mirallRedirs").toInt(); - - if (redirCount > 10) { - redirection.clear (); - } - - disconnect (reply, SIGNAL(finished()), - this, SLOT(slotAuthCheckReplyFinished())); - if ((reply->error () == QNetworkReply::AuthenticationRequiredError) || redirection.isEmpty()) { - reply->deleteLater(); - nm->deleteLater(); - _ocWizard->setAuthType (WizardCommon::HttpCreds); - } else if (redirection.toString().endsWith ("remote.php/webdav/")) { - QNetworkReply* newReply = nm->get (QNetworkRequest(redirection)); - - connect (newReply, SIGNAL(error(QNetworkReply::NetworkError)), - this, SLOT(slotAuthCheckReplyError(QNetworkReply::NetworkError))); - connect (newReply, SIGNAL(finished()), - this, SLOT(slotAuthCheckReplyFinished(QNetworkReply::NetworkError))); - reply->deleteLater(); - - nm->setProperty ("mirallRedirs", QVariant(redirCount + 1)); - } else { - QRegExp shibbolethyWords ("SAML|wayf"); - - shibbolethyWords.setCaseSensitivity (Qt::CaseInsensitive); - if (redirection.toString ().contains (shibbolethyWords)) { - _ocWizard->setAuthType(WizardCommon::Shibboleth); - } else { - // eh? - _ocWizard->setAuthType (WizardCommon::HttpCreds); + // Now write the resulting folder definition if folder names are set. + if( acceptCfg && urlHasChanged ) { + folderMan->removeAllFolderDefinitions(); + folderMan->addFolderDefinition(Theme::instance()->appName(), + localFolder, _remoteFolder ); + _ocWizard->appendToConfigurationLog(tr("Local sync folder %1 successfully created!").arg(localFolder)); + } else { + // url is unchanged. Only the password was changed. + if( acceptCfg ) { + qDebug() << "Only password was changed, no changes to folder configuration."; + } else { + qDebug() << "User interrupted change of configuration."; + } + } } - reply->deleteLater(); - nm->deleteLater(); - } -} -void OwncloudSetupWizard::slotNoOwnCloudFoundAuth( QNetworkReply *err ) -{ - disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)), - this, SLOT(slotOwnCloudFound(QString,QString,QString,QString))); - disconnect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)), - this, SLOT(slotNoOwnCloudFound(QNetworkReply*))); - - _ocWizard->displayError(tr("Failed to connect to %1:
%2"). - arg(Theme::instance()->appNameGUI()).arg(err->errorString())); + // clear the custom config handle + _configHandle.clear(); + ownCloudInfo::instance()->setCustomConfigHandle( QString::null ); - // remove the config file again - MirallConfigFile cfgFile( _configHandle ); - cfgFile.cleanupCustomConfig(); + // notify others. + emit ownCloudWizardDone( result ); } +void OwncloudSetupWizard::slotClearPendingRequests() +{ + qDebug() << "Pending request: " << _mkdirRequestReply; + if( _mkdirRequestReply && _mkdirRequestReply->isRunning() ) { + qDebug() << "ABORTing pending mkdir request."; + _mkdirRequestReply->abort(); + } + if( _checkInstallationRequest && _checkInstallationRequest->isRunning() ) { + qDebug() << "ABORTing pending check installation request."; + _checkInstallationRequest->abort(); + } + if( _checkRemoteFolderRequest && _checkRemoteFolderRequest->isRunning() ) { + qDebug() << "ABORTing pending remote folder check request."; + _checkRemoteFolderRequest->abort(); + } } + +} // ns Mirall diff --git a/src/mirall/owncloudsetupwizard.h b/src/mirall/owncloudsetupwizard.h index aeec7f2af..66284a2b8 100644 --- a/src/mirall/owncloudsetupwizard.h +++ b/src/mirall/owncloudsetupwizard.h @@ -25,80 +25,50 @@ namespace Mirall { -class SiteCopyFolder; -class SyncResult; -class ownCloudInfo; class OwncloudWizard; class OwncloudSetupWizard : public QObject { Q_OBJECT public: - explicit OwncloudSetupWizard(QObject *parent = 0 ); - - ~OwncloudSetupWizard(); - - /** - * @intro wether or not to show the intro wizard page - */ - void startWizard(); - - void installServer(); - - bool isBusy(); - - void writeOwncloudConfig(); - - /** - * returns the configured owncloud url if its already configured, otherwise an empty - * string. - */ - - void setupLocalSyncFolder(); - - OwncloudWizard *wizard(); - /** Run the wizard */ static void runWizard(QObject *obj, const char* amember, QWidget *parent = 0 ); signals: - // issued if the oC Setup process (owncloud-admin) is finished. - void ownCloudSetupFinished( bool ); // overall dialog close signal. - void ownCloudWizardDone( int ); + void ownCloudWizardDone( int ); -public slots: - -protected slots: - // wizard dialog signals - void slotConnectToOCUrl( const QString& ); +private slots: void slotDetermineAuthType(const QString&); + void slotOwnCloudFoundAuth(const QString&, const QString&, const QString&, const QString&); + void slotAuthCheckReplyFinished(); + void slotNoOwnCloudFoundAuth(QNetworkReply*); -private slots: - void slotCreateRemoteFolderFinished( QNetworkReply::NetworkError ); + void slotConnectToOCUrl(const QString&); + void slotConnectionCheck(const QString&, QNetworkReply*); + + void slotCreateLocalAndRemoteFolders(const QString&, const QString&); + void slotAuthCheckReply(const QString&, QNetworkReply*); + void slotCreateRemoteFolderFinished(QNetworkReply::NetworkError); void slotAssistantFinished( int ); void slotClearPendingRequests(); - void slotAuthCheckReply( const QString&, QNetworkReply * ); - void slotOwnCloudFoundAuth( const QString&, const QString&, const QString&, const QString& ); - void slotNoOwnCloudFoundAuth( QNetworkReply* ); - void slotAuthCheckReplyFinished(); private: - bool createRemoteFolder(); - void checkRemoteFolder(); - - void finalizeSetup( bool ); + explicit OwncloudSetupWizard(QObject *parent = 0 ); + ~OwncloudSetupWizard(); - /* Start a request to the newly installed ownCloud to check the connection */ + void startWizard(); void testOwnCloudConnect(); + void checkRemoteFolder(); + bool createRemoteFolder(); + void finalizeSetup( bool ); - OwncloudWizard *_ocWizard; + OwncloudWizard* _ocWizard; QPointer _mkdirRequestReply; QPointer _checkInstallationRequest; QPointer _checkRemoteFolderRequest; - - QString _configHandle; - QString _remoteFolder; + QString _configHandle; + QString _remoteFolder; }; } diff --git a/src/wizard/owncloudadvancedsetuppage.cpp b/src/wizard/owncloudadvancedsetuppage.cpp new file mode 100644 index 000000000..dbe27a8ca --- /dev/null +++ b/src/wizard/owncloudadvancedsetuppage.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 +#include +#include + +#include "QProgressIndicator.h" + +#include "wizard/owncloudwizardcommon.h" +#include "wizard/owncloudadvancedsetuppage.h" +#include "mirall/theme.h" + +namespace Mirall +{ + +OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage() + : QWizardPage(), + _ui(), + _checking(false), + _created(false), + _configExists(false), + _multipleFoldersExist(false), + _remoteFolder(), + _progressIndi(new QProgressIndicator (this)) +{ + _ui.setupUi(this); + + Theme *theme = Theme::instance(); + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(theme->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Setup local folder options"))); + + registerField( QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch); + + _ui.resultLayout->addWidget( _progressIndi ); + stopSpinner(); + setupCustomization(); + + connect( _ui.pbSelectLocalFolder, SIGNAL(clicked()), SLOT(slotSelectFolder())); +} + +void OwncloudAdvancedSetupPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + Theme *theme = Theme::instance(); + QVariant variant = theme->customMedia( Theme::oCSetupTop ); + if( !variant.isNull() ) { + WizardCommon::setupCustomMedia( variant, _ui.topLabel ); + } + + variant = theme->customMedia( Theme::oCSetupBottom ); + WizardCommon::setupCustomMedia( variant, _ui.bottomLabel ); +} + +bool OwncloudAdvancedSetupPage::isComplete() const +{ + return !_checking; +} + +void OwncloudAdvancedSetupPage::initializePage() +{ + WizardCommon::initErrorLabel(_ui.errorLabel); + + _checking = false; + _multipleFoldersExist = false; + + // call to init label + updateStatus(); + + // TODO: focus + _ui.pbSelectLocalFolder->setFocus(); +} + +// Called if the user changes the user- or url field. Adjust the texts and +// evtl. warnings on the dialog. +void OwncloudAdvancedSetupPage::updateStatus() +{ + const QString locFolder = localFolder(); + // check if the local folder exists. If so, and if its not empty, show a warning. + QString t; + + // TODO: Maybe handle "modify" mode differently. + _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); + + if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { + t = tr("Your entire account will be synced to the local folder '%1'.") + .arg(QDir::toNativeSeparators(locFolder)); + } else { + t = tr("%1 folder '%2' is synced to local folder '%3'") + .arg(Theme::instance()->appName()).arg(_remoteFolder) + .arg(QDir::toNativeSeparators(locFolder)); + } + + if ( _multipleFoldersExist ) { + t += tr("

Warning: You currently have multiple folders " + "configured. If you continue with the current settings, the folder configurations " + "will be discarded and a single root folder sync will be created!

"); + } + + if(QDir(locFolder).entryList(QDir::AllEntries | QDir::NoDotAndDotDot).count() > 0) { + t += tr("

Warning: The local directory is not empty.

"); + } + + _ui.syncModeLabel->setText(t); + _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); +} + +void OwncloudAdvancedSetupPage::startSpinner() +{ + _ui.resultLayout->setEnabled(true); + _progressIndi->setVisible(true); + _progressIndi->startAnimation(); +} + +void OwncloudAdvancedSetupPage::stopSpinner() +{ + _ui.resultLayout->setEnabled(false); + _progressIndi->setVisible(false); + _progressIndi->stopAnimation(); +} + +int OwncloudAdvancedSetupPage::nextId() const +{ + return WizardCommon::Page_Result; +} + +QString OwncloudAdvancedSetupPage::localFolder() const +{ + QString folder = wizard()->property("localFolder").toString(); + return folder; +} + +bool OwncloudAdvancedSetupPage::validatePage() +{ + if(!_created) { + setErrorString(QString::null); + _checking = true; + startSpinner(); + emit completeChanged(); + + emit createLocalAndRemoteFolders(localFolder(), _remoteFolder); + return false; + } else { + // connecting is running + _checking = false; + emit completeChanged(); + stopSpinner(); + return true; + } +} + +void OwncloudAdvancedSetupPage::setErrorString( const QString& err ) +{ + if( err.isEmpty()) { + _ui.errorLabel->setVisible(false); + } else { + _ui.errorLabel->setVisible(true); + _ui.errorLabel->setText(err); + } + _checking = false; + emit completeChanged(); +} + +void OwncloudAdvancedSetupPage::directoriesCreated() +{ + _checking = false; + _created = true; + stopSpinner(); + emit completeChanged(); +} + +void OwncloudAdvancedSetupPage::setRemoteFolder( const QString& remoteFolder ) +{ + if( !remoteFolder.isEmpty() ) { + _remoteFolder = remoteFolder; + } +} + +void OwncloudAdvancedSetupPage::setMultipleFoldersExist(bool exist) +{ + _multipleFoldersExist = exist; +} + +void OwncloudAdvancedSetupPage::slotSelectFolder() +{ + QString dir = QFileDialog::getExistingDirectory(0, tr("Local Sync Folder"), QDir::homePath()); + if( !dir.isEmpty() ) { + _ui.pbSelectLocalFolder->setText(dir); + wizard()->setProperty("localFolder", dir); + updateStatus(); + } +} + +void OwncloudAdvancedSetupPage::setConfigExists( bool config ) +{ + _configExists = config; + + if (config == true) { + setSubTitle( tr("Change your user credentials") + .arg(Theme::instance()->wizardHeaderTitleColor().name())); + } +} + +} // ns Mirall diff --git a/src/wizard/owncloudadvancedsetuppage.h b/src/wizard/owncloudadvancedsetuppage.h new file mode 100644 index 000000000..919ad47df --- /dev/null +++ b/src/wizard/owncloudadvancedsetuppage.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) by Duncan Mac-Vicar P. + * Copyright (C) by Klaas Freitag + * Copyright (C) by Krzesimir Nowak + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 MIRALL_OWNCLOUD_ADVANCED_SETUP_PAGE_H +#define MIRALL_OWNCLOUD_ADVANCED_SETUP_PAGE_H + +#include + +#include "wizard/owncloudwizardcommon.h" +#include "ui_owncloudadvancedsetuppage.h" + +class QProgressIndicator; + +namespace Mirall { + +class OwncloudAdvancedSetupPage: public QWizardPage +{ + Q_OBJECT +public: + OwncloudAdvancedSetupPage(); + + virtual bool isComplete() const; + virtual void initializePage(); + virtual int nextId() const; + bool validatePage(); + QString localFolder() const; + void setRemoteFolder( const QString& remoteFolder); + void setMultipleFoldersExist( bool exist ); + void directoriesCreated(); + +signals: + void createLocalAndRemoteFolders(const QString&, const QString&); + +public slots: + void setErrorString( const QString& ); + void setConfigExists( bool ); + +private slots: + void slotSelectFolder(); + +private: + void setupCustomization(); + void updateStatus(); + void startSpinner(); + void stopSpinner(); + + Ui_OwncloudAdvancedSetupPage _ui; + bool _checking; + bool _created; + bool _configExists; + bool _multipleFoldersExist; + QProgressIndicator* _progressIndi; + + QString _remoteFolder; +}; + +} // ns Mirall + +#endif diff --git a/src/wizard/owncloudadvancedsetuppage.ui b/src/wizard/owncloudadvancedsetuppage.ui new file mode 100644 index 000000000..9b8cd12cf --- /dev/null +++ b/src/wizard/owncloudadvancedsetuppage.ui @@ -0,0 +1,267 @@ + + + OwncloudAdvancedSetupPage + + + + 0 + 0 + 821 + 647 + + + + + 0 + 0 + + + + Form + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + QLayout::SetMinimumSize + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + 0 + 0 + + + + &Local Folder + + + pbSelectLocalFolder + + + + + + + + 0 + 0 + + + + pbSelectLocalFolder + + + + + + + + 0 + 0 + + + + + QLayout::SetMinimumSize + + + QFormLayout::ExpandingFieldsGrow + + + + + &Keep local data + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + <small>Syncs your existing data to new location.</small> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 0 + + + + + + + <html><head/><body><p>If this box is checked, existing content in the local directory will be erased to start a clean sync from the server.</p><p>Do not check this if the local content should be uploaded to the servers directory.</p></body></html> + + + &Start a clean sync + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + <small>Erases the contents of the local folder before syncing using the new settings.</small> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 0 + + + + + + + + + + + + TextLabel + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + Status message + + + Qt::AlignCenter + + + true + + + + + + + + + + TextLabel + + + + + + + + diff --git a/src/wizard/owncloudhttpcredspage.cpp b/src/wizard/owncloudhttpcredspage.cpp index 713ea508d..c3c685873 100644 --- a/src/wizard/owncloudhttpcredspage.cpp +++ b/src/wizard/owncloudhttpcredspage.cpp @@ -90,7 +90,9 @@ bool OwncloudHttpCredsPage::validatePage() } if (!_connected) { + _ui.errorLabel->setVisible(false); _checking = true; + startSpinner(); emit completeChanged(); emit connectToOCUrl(field("OCUrl").toString().simplified()); @@ -98,6 +100,7 @@ bool OwncloudHttpCredsPage::validatePage() } else { _checking = false; emit completeChanged(); + stopSpinner(); return true; } return true; @@ -105,7 +108,7 @@ bool OwncloudHttpCredsPage::validatePage() int OwncloudHttpCredsPage::nextId() const { - return WizardCommon::Page_Result; + return WizardCommon::Page_AdvancedSetup; } void OwncloudHttpCredsPage::setConnected( bool comp ) diff --git a/src/wizard/owncloudsetupnocredspage.ui b/src/wizard/owncloudsetupnocredspage.ui index 5e08a64b1..76008d744 100644 --- a/src/wizard/owncloudsetupnocredspage.ui +++ b/src/wizard/owncloudsetupnocredspage.ui @@ -6,8 +6,8 @@ 0 0 - 583 - 498 + 478 + 461 @@ -19,11 +19,8 @@ Form - - - QLayout::SetMinimumSize - - + + @@ -39,218 +36,8 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 48 - 68 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 13 - - - - - - - - 0 - - - - - - - true - - - - 0 - - - 0 - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - - 0 - 0 - - - - &Local Folder - - - pbSelectLocalFolder - - - - - - - - 0 - 0 - - - - pbSelectLocalFolder - - - - - - - - QLayout::SetMinimumSize - - - QFormLayout::ExpandingFieldsGrow - - - - - &Keep local data - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - <small>Syncs your existing data to new location.</small> - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - 0 - - - - - - - <html><head/><body><p>If this box is checked, existing content in the local directory will be erased to start a clean sync from the server.</p><p>Do not check this if the local content should be uploaded to the servers directory.</p></body></html> - - - &Start a clean sync - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - <small>Erases the contents of the local folder before syncing using the new settings.</small> - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - 0 - - - - - - - - - - - - + - - QFormLayout::AllNonFixedFieldsGrow - @@ -264,7 +51,7 @@ - + 0 0 @@ -277,132 +64,48 @@ - - - - - 0 - 0 - - - - Error Label - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 13 - + + + + + 0 + 0 + - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Advanced &Settings - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Status message - - - Qt::AlignCenter - - - true + Error Label - - + + - Qt::Horizontal - - - QSizePolicy::Fixed + Qt::Vertical - 48 - 58 + 20 + 40 - + + + + 0 + + + + TextLabel - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - diff --git a/src/wizard/owncloudsetuppage.cpp b/src/wizard/owncloudsetuppage.cpp index 859fcfdf0..6e8933925 100644 --- a/src/wizard/owncloudsetuppage.cpp +++ b/src/wizard/owncloudsetuppage.cpp @@ -34,11 +34,8 @@ OwncloudSetupPage::OwncloudSetupPage() _ocUser(), _authTypeKnown(false), _checking(false), - _multipleFoldersExist(false), _authType(WizardCommon::HttpCreds), - _progressIndi(new QProgressIndicator (this)), - _selectiveSyncButtons(0), - _remoteFolder() + _progressIndi(new QProgressIndicator (this)) { _ui.setupUi(this); @@ -47,9 +44,6 @@ OwncloudSetupPage::OwncloudSetupPage() setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Setup ownCloud server"))); registerField( QLatin1String("OCUrl*"), _ui.leUrl ); - registerField( QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch); - - _ui.advancedBox->setVisible(false); _ui.resultLayout->addWidget( _progressIndi ); stopSpinner(); @@ -57,20 +51,6 @@ OwncloudSetupPage::OwncloudSetupPage() setupCustomization(); connect(_ui.leUrl, SIGNAL(textChanged(QString)), SLOT(slotUrlChanged(QString))); - connect( _ui.cbAdvanced, SIGNAL(stateChanged (int)), SLOT(slotToggleAdvanced(int))); - connect( _ui.pbSelectLocalFolder, SIGNAL(clicked()), SLOT(slotSelectFolder())); -} - -void OwncloudSetupPage::slotToggleAdvanced(int state) -{ - _ui.advancedBox->setVisible( state == Qt::Checked ); - slotHandleUserInput(); - QSize size = wizard()->sizeHint(); - // need to substract header for some reason - size -= QSize(0, 63); - - wizard()->setMinimumSize(size); - wizard()->resize(size); } void OwncloudSetupPage::setServerUrl( const QString& newUrl ) @@ -111,8 +91,6 @@ void OwncloudSetupPage::setupCustomization() // slot hit from textChanged of the url entry field. void OwncloudSetupPage::slotUrlChanged(const QString& /*ocUrl*/) { - slotHandleUserInput(); - #if 0 QString url = ocUrl; bool visible = false; @@ -124,7 +102,7 @@ void OwncloudSetupPage::slotUrlChanged(const QString& /*ocUrl*/) } if (url.startsWith(QLatin1String("http://"))) { _ui.urlLabel->setPixmap( QPixmap(":/mirall/resources/security-low.png")); - _ui.urlLabel->setToolTip(tr("This url is NOT secure. You should not use it."));W + _ui.urlLabel->setToolTip(tr("This url is NOT secure. You should not use it.")); visible = true; } #endif @@ -141,10 +119,6 @@ void OwncloudSetupPage::initializePage() _authTypeKnown = false; _checking = false; - _multipleFoldersExist = false; - - // call to init label - slotHandleUserInput(); _ui.leUrl->setFocus(); } @@ -173,69 +147,6 @@ bool OwncloudSetupPage::urlHasChanged() return change; } -// Called if the user changes the user- or url field. Adjust the texts and -// evtl. warnings on the dialog. -void OwncloudSetupPage::slotHandleUserInput() -{ - // if the url has not changed, return. - if( ! urlHasChanged() ) { - // disable the advanced button as nothing has changed. - _ui.cbAdvanced->setEnabled(false); - _ui.advancedBox->setEnabled(false); - } else { - // Enable advanced stuff for new connection configuration. - _ui.cbAdvanced->setEnabled(true); - _ui.advancedBox->setEnabled(true); - } - - const QString locFolder = localFolder(); - - // check if the local folder exists. If so, and if its not empty, show a warning. - QDir dir( locFolder ); - QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot); - - QString t; - - if( !urlHasChanged() && _configExists ) { - // This is the password change mode: No change to the url and a config - // to an ownCloud exists. - t = tr("Press Next to change the Password for your configured account."); - } else { - // Complete new setup. - _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); - - if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { - t = tr("Your entire account will be synced to the local folder '%1'.") - .arg(QDir::toNativeSeparators(locFolder)); - } else { - t = tr("%1 folder '%2' is synced to local folder '%3'") - .arg(Theme::instance()->appName()).arg(_remoteFolder) - .arg(QDir::toNativeSeparators(locFolder)); - } - - if ( _multipleFoldersExist ) { - t += tr("

Warning: You currently have multiple folders " - "configured. If you continue with the current settings, the folder configurations " - "will be discarded and a single root folder sync will be created!

"); - } - - if( entries.count() > 0) { - // the directory is not empty - if (!_ui.cbAdvanced->isChecked()) { - t += tr("

Warning: The local directory is not empty. " - "Pick a resolution in the advanced settings!

"); - } - _ui.resolutionWidget->setVisible(true); - } else { - // the dir is empty, which means that there is no problem. - _ui.resolutionWidget->setVisible(false); - } - } - - _ui.syncModeLabel->setText(t); - _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); -} - int OwncloudSetupPage::nextId() const { if (_authType == WizardCommon::HttpCreds) { @@ -251,12 +162,6 @@ QString OwncloudSetupPage::url() const return url; } -QString OwncloudSetupPage::localFolder() const -{ - QString folder = wizard()->property("localFolder").toString(); - return folder; -} - bool OwncloudSetupPage::validatePage() { if( ! _authTypeKnown) { @@ -310,40 +215,12 @@ void OwncloudSetupPage::stopSpinner() _progressIndi->stopAnimation(); } -WizardCommon::SyncMode OwncloudSetupPage::syncMode() -{ - return WizardCommon::BoxMode; -} - -void OwncloudSetupPage::setRemoteFolder( const QString& remoteFolder ) -{ - if( !remoteFolder.isEmpty() ) { - _remoteFolder = remoteFolder; - } -} - -void OwncloudSetupPage::setMultipleFoldersExist(bool exist) -{ - _multipleFoldersExist = exist; -} - -void OwncloudSetupPage::slotSelectFolder() -{ - QString dir = QFileDialog::getExistingDirectory(0, tr("Local Sync Folder"), QDir::homePath()); - if( !dir.isEmpty() ) { - _ui.pbSelectLocalFolder->setText(dir); - wizard()->setProperty("localFolder", dir); - slotHandleUserInput(); - } -} - void OwncloudSetupPage::setConfigExists( bool config ) { _configExists = config; if (config == true) { - setSubTitle( tr("Change your user credentials") - .arg(Theme::instance()->wizardHeaderTitleColor().name())); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Update ownCloud server"))); } } diff --git a/src/wizard/owncloudsetuppage.h b/src/wizard/owncloudsetuppage.h index f8369deaf..8d343cd60 100644 --- a/src/wizard/owncloudsetuppage.h +++ b/src/wizard/owncloudsetuppage.h @@ -44,8 +44,6 @@ public: QString localFolder() const; void setRemoteFolder( const QString& remoteFolder); void setMultipleFoldersExist( bool exist ); - - WizardCommon::SyncMode syncMode(); void setAuthType(WizardCommon::AuthType type); public slots: @@ -58,18 +56,10 @@ protected slots: void slotUrlChanged(const QString&); void setupCustomization(); - void slotToggleAdvanced(int state); - void slotSelectFolder(); signals: void determineAuthType(const QString&); -protected: - void updateFoldersInfo(); - -private slots: - void slotHandleUserInput(); - private: bool urlHasChanged(); diff --git a/src/wizard/owncloudshibbolethcredspage.cpp b/src/wizard/owncloudshibbolethcredspage.cpp index 6d0f0ff90..968b97747 100644 --- a/src/wizard/owncloudshibbolethcredspage.cpp +++ b/src/wizard/owncloudshibbolethcredspage.cpp @@ -118,7 +118,7 @@ bool OwncloudShibbolethCredsPage::validatePage() int OwncloudShibbolethCredsPage::nextId() const { - return WizardCommon::Page_Result; + return WizardCommon::Page_AdvancedSetup; } void OwncloudShibbolethCredsPage::setConnected( bool comp ) diff --git a/src/wizard/owncloudwizard.cpp b/src/wizard/owncloudwizard.cpp index c6f0f9e54..5409163e7 100644 --- a/src/wizard/owncloudwizard.cpp +++ b/src/wizard/owncloudwizard.cpp @@ -20,6 +20,7 @@ #include "wizard/owncloudsetuppage.h" #include "wizard/owncloudhttpcredspage.h" #include "wizard/owncloudshibbolethcredspage.h" +#include "wizard/owncloudadvancedsetuppage.h" #include "wizard/owncloudwizardresultpage.h" #include "QProgressIndicator.h" @@ -37,6 +38,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) _setupPage(new OwncloudSetupPage), _httpCredsPage(new OwncloudHttpCredsPage), _shibbolethCredsPage(new OwncloudShibbolethCredsPage), + _advancedSetupPage(new OwncloudAdvancedSetupPage), _resultPage(new OwncloudWizardResultPage), _credentialsPage(0), _configFile(), @@ -44,10 +46,11 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) _setupLog(), _configExists(false) { - setPage(WizardCommon::Page_oCSetup, _setupPage ); + setPage(WizardCommon::Page_ServerSetup, _setupPage ); setPage(WizardCommon::Page_HttpCreds, _httpCredsPage); setPage(WizardCommon::Page_ShibbolethCreds, _shibbolethCredsPage); - setPage(WizardCommon::Page_Result, _resultPage ); + setPage(WizardCommon::Page_AdvancedSetup, _advancedSetupPage); + setPage(WizardCommon::Page_Result, _resultPage ); // note: start Id is set by the calling class depending on if the // welcome text is to be shown or not. @@ -57,8 +60,11 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) connect( _setupPage, SIGNAL(determineAuthType(QString)), SIGNAL(determineAuthType(QString))); connect( _httpCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); connect( _shibbolethCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString))); + connect( _advancedSetupPage, SIGNAL(createLocalAndRemoteFolders(QString, QString)), + SIGNAL(createLocalAndRemoteFolders(QString, QString))); Theme *theme = Theme::instance(); + setWindowTitle( tr("%1 Connection Wizard").arg(theme->appNameGUI())); setWizardStyle(QWizard::ModernStyle); setPixmap( QWizard::BannerPixmap, theme->wizardHeaderBanner() ); setPixmap( QWizard::LogoPixmap, theme->wizardHeaderLogo() ); @@ -69,20 +75,14 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) setSubTitleFormat(Qt::RichText); } -WizardCommon::SyncMode OwncloudWizard::syncMode() -{ - return _setupPage->syncMode(); - return WizardCommon::BoxMode; -} - void OwncloudWizard::setMultipleFoldersExist(bool exist) { - _setupPage->setMultipleFoldersExist(exist); + _advancedSetupPage->setMultipleFoldersExist(exist); } QString OwncloudWizard::localFolder() const { - return(_setupPage->localFolder()); + return(_advancedSetupPage->localFolder()); } QString OwncloudWizard::ocUrl() const @@ -98,39 +98,34 @@ void OwncloudWizard::enableFinishOnResultWidget(bool enable) void OwncloudWizard::setRemoteFolder( const QString& remoteFolder ) { - _setupPage->setRemoteFolder( remoteFolder ); + _advancedSetupPage->setRemoteFolder( remoteFolder ); _resultPage->setRemoteFolder( remoteFolder ); } -void OwncloudWizard::showConnectInfo( const QString& msg ) -{ - if( _setupPage ) { - _setupPage->setErrorString( msg ); - } -} - -void OwncloudWizard::successfullyConnected(bool enable) +void OwncloudWizard::successfulStep() { const int id(currentId()); switch (id) { case WizardCommon::Page_HttpCreds: - _httpCredsPage->setConnected( enable ); + _httpCredsPage->setConnected(true); break; case WizardCommon::Page_ShibbolethCreds: - _shibbolethCredsPage->setConnected( enable ); + _shibbolethCredsPage->setConnected(true); break; - case WizardCommon::Page_oCSetup: + case WizardCommon::Page_AdvancedSetup: + _advancedSetupPage->directoriesCreated(); + break; + + case WizardCommon::Page_ServerSetup: case WizardCommon::Page_Result: qWarning("Should not happen at this stage."); break; } - if( enable ) { - next(); - } + next(); } void OwncloudWizard::setAuthType(WizardCommon::AuthType type) @@ -144,15 +139,15 @@ void OwncloudWizard::setAuthType(WizardCommon::AuthType type) next(); } +// TODO: update this function void OwncloudWizard::slotCurrentPageChanged( int id ) { qDebug() << "Current Wizard page changed to " << id; - if( id == WizardCommon::Page_oCSetup ) { + if( id == WizardCommon::Page_ServerSetup ) { setButtonText( QWizard::NextButton, tr("Connect...") ); emit clearPendingRequests(); _setupPage->initializePage(); - } if( id == WizardCommon::Page_Result ) { @@ -164,12 +159,22 @@ void OwncloudWizard::displayError( const QString& msg ) { int id(currentId()); - if (id == WizardCommon::Page_oCSetup) { + switch (currentId()) { + case WizardCommon::Page_ServerSetup: _setupPage->setErrorString( msg ); - } else if (id == WizardCommon::Page_HttpCreds) { + break; + + case WizardCommon::Page_HttpCreds: _httpCredsPage->setErrorString(msg); - } else if (id == WizardCommon::Page_ShibbolethCreds) { + break; + + case WizardCommon::Page_ShibbolethCreds: _shibbolethCredsPage->setErrorString(msg); + break; + + case WizardCommon::Page_AdvancedSetup: + _advancedSetupPage->setErrorString(msg); + break; } } diff --git a/src/wizard/owncloudwizard.h b/src/wizard/owncloudwizard.h index a6b88af51..b5ac2be77 100644 --- a/src/wizard/owncloudwizard.h +++ b/src/wizard/owncloudwizard.h @@ -26,6 +26,7 @@ namespace Mirall { class OwncloudSetupPage; class OwncloudHttpCredsPage; class OwncloudShibbolethCredsPage; +class OwncloudAdvancedSetupPage; class OwncloudWizardResultPage; class AbstractCredentials; class AbstractCredentialsWizardPage; @@ -52,11 +53,10 @@ public: void enableFinishOnResultWidget(bool enable); void displayError( const QString& ); - WizardCommon::SyncMode syncMode(); void setMultipleFoldersExist( bool ); void setConfigExists( bool ); bool configExists(); - void successfullyConnected(bool); + void successfulStep(); void setAuthType(WizardCommon::AuthType type); AbstractCredentials* getCredentials() const; @@ -65,17 +65,17 @@ public slots: void appendToConfigurationLog( const QString& msg, LogType type = LogParagraph ); void slotCurrentPageChanged( int ); - void showConnectInfo( const QString& ); - signals: void clearPendingRequests(); - void connectToOCUrl( const QString& ); void determineAuthType(const QString&); + void connectToOCUrl( const QString& ); + void createLocalAndRemoteFolders(const QString&, const QString&); private: OwncloudSetupPage* _setupPage; OwncloudHttpCredsPage* _httpCredsPage; OwncloudShibbolethCredsPage* _shibbolethCredsPage; + OwncloudAdvancedSetupPage* _advancedSetupPage; OwncloudWizardResultPage* _resultPage; AbstractCredentialsWizardPage* _credentialsPage; diff --git a/src/wizard/owncloudwizardcommon.h b/src/wizard/owncloudwizardcommon.h index 38ac86278..83a548497 100644 --- a/src/wizard/owncloudwizardcommon.h +++ b/src/wizard/owncloudwizardcommon.h @@ -42,9 +42,10 @@ enum SyncMode { }; enum Pages { - Page_oCSetup, + Page_ServerSetup, Page_HttpCreds, Page_ShibbolethCreds, + Page_AdvancedSetup, Page_Result }; -- cgit v1.2.3 From 928eae419f4acb8430dd141bae2291a57d18c1a2 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 14:50:27 +0200 Subject: Hide resolution widget in advanced setup page if nothing has changed. --- src/wizard/owncloudadvancedsetuppage.cpp | 68 +++++++++++++++++++++++--------- src/wizard/owncloudadvancedsetuppage.h | 3 +- 2 files changed, 51 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/wizard/owncloudadvancedsetuppage.cpp b/src/wizard/owncloudadvancedsetuppage.cpp index dbe27a8ca..9102bfa21 100644 --- a/src/wizard/owncloudadvancedsetuppage.cpp +++ b/src/wizard/owncloudadvancedsetuppage.cpp @@ -20,9 +20,12 @@ #include "QProgressIndicator.h" +#include "wizard/owncloudwizard.h" #include "wizard/owncloudwizardcommon.h" #include "wizard/owncloudadvancedsetuppage.h" #include "mirall/theme.h" +#include "mirall/mirallconfigfile.h" +#include "creds/abstractcredentials.h" namespace Mirall { @@ -34,8 +37,9 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage() _created(false), _configExists(false), _multipleFoldersExist(false), - _remoteFolder(), - _progressIndi(new QProgressIndicator (this)) + _progressIndi(new QProgressIndicator (this)), + _oldLocalFolder(), + _remoteFolder() { _ui.setupUi(this); @@ -79,6 +83,7 @@ void OwncloudAdvancedSetupPage::initializePage() _checking = false; _multipleFoldersExist = false; + _oldLocalFolder = localFolder(); // call to init label updateStatus(); @@ -95,30 +100,55 @@ void OwncloudAdvancedSetupPage::updateStatus() // check if the local folder exists. If so, and if its not empty, show a warning. QString t; - // TODO: Maybe handle "modify" mode differently. _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder)); - - if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { - t = tr("Your entire account will be synced to the local folder '%1'.") - .arg(QDir::toNativeSeparators(locFolder)); + if (dataChanged()) { + if( _remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/") ) { + t = tr("Your entire account will be synced to the local folder '%1'.") + .arg(QDir::toNativeSeparators(locFolder)); + } else { + t = tr("%1 folder '%2' is synced to local folder '%3'") + .arg(Theme::instance()->appName()).arg(_remoteFolder) + .arg(QDir::toNativeSeparators(locFolder)); + } + + if ( _multipleFoldersExist ) { + t += tr("

Warning: You currently have multiple folders " + "configured. If you continue with the current settings, the folder configurations " + "will be discarded and a single root folder sync will be created!

"); + } + + const bool dirNotEmpty(QDir(locFolder).entryList(QDir::AllEntries | QDir::NoDotAndDotDot).count() > 0); + if(dirNotEmpty) { + t += tr("

Warning: The local directory is not empty. " + "Pick a resolution!

"); + } + _ui.resolutionWidget->setVisible(dirNotEmpty); } else { - t = tr("%1 folder '%2' is synced to local folder '%3'") - .arg(Theme::instance()->appName()).arg(_remoteFolder) - .arg(QDir::toNativeSeparators(locFolder)); + _ui.resolutionWidget->setVisible(false); } - if ( _multipleFoldersExist ) { - t += tr("

Warning: You currently have multiple folders " - "configured. If you continue with the current settings, the folder configurations " - "will be discarded and a single root folder sync will be created!

"); - } + _ui.syncModeLabel->setText(t); + _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); +} - if(QDir(locFolder).entryList(QDir::AllEntries | QDir::NoDotAndDotDot).count() > 0) { - t += tr("

Warning: The local directory is not empty.

"); +bool OwncloudAdvancedSetupPage::dataChanged() +{ + OwncloudWizard* ocWizard(dynamic_cast< OwncloudWizard* >(wizard())); + + if (!ocWizard) { + return false; } - _ui.syncModeLabel->setText(t); - _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height()); + MirallConfigFile cfgFile; + const QString url(field("OCUrl").toString()); + AbstractCredentials* newCredentials(ocWizard->getCredentials()); + AbstractCredentials* oldCredentials(cfgFile.getCredentials()); + const bool differentCreds(oldCredentials->changed(newCredentials)); + delete newCredentials; + const QString newLocalFolder(QDir::toNativeSeparators(_ui.pbSelectLocalFolder->text())); + const QString oldLocalFolder(QDir::toNativeSeparators(_oldLocalFolder)); + + return ((url != cfgFile.ownCloudUrl()) || differentCreds || (oldLocalFolder != newLocalFolder)); } void OwncloudAdvancedSetupPage::startSpinner() diff --git a/src/wizard/owncloudadvancedsetuppage.h b/src/wizard/owncloudadvancedsetuppage.h index 919ad47df..2e46224c9 100644 --- a/src/wizard/owncloudadvancedsetuppage.h +++ b/src/wizard/owncloudadvancedsetuppage.h @@ -54,6 +54,7 @@ private slots: private: void setupCustomization(); void updateStatus(); + bool dataChanged(); void startSpinner(); void stopSpinner(); @@ -63,7 +64,7 @@ private: bool _configExists; bool _multipleFoldersExist; QProgressIndicator* _progressIndi; - + QString _oldLocalFolder; QString _remoteFolder; }; -- cgit v1.2.3 From 69a4558fe40299be13ba05bc6ebb64a63184d5da Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 14:51:06 +0200 Subject: Actually use the remoteFolder sent by signal. --- src/mirall/owncloudsetupwizard.cpp | 6 +++--- src/mirall/owncloudsetupwizard.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index f0d2beee8..0fcd08eb9 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -331,11 +331,11 @@ void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFo } if( localFolderOk ) { - checkRemoteFolder(); + checkRemoteFolder(remoteFolder); } } -void OwncloudSetupWizard::checkRemoteFolder() +void OwncloudSetupWizard::checkRemoteFolder(const QString& remoteFolder) { ownCloudInfo* info(ownCloudInfo::instance()); connect( info,SIGNAL(ownCloudDirExists(QString,QNetworkReply*)), @@ -343,7 +343,7 @@ void OwncloudSetupWizard::checkRemoteFolder() qDebug() << "# checking for existence of remote folder."; info->setCustomConfigHandle(_configHandle); - _checkRemoteFolderRequest = info->getWebDAVPath(_remoteFolder ); // this call needs to be authenticated. + _checkRemoteFolderRequest = info->getWebDAVPath(remoteFolder); // this call needs to be authenticated. // continue in slotAuthCheckReply } diff --git a/src/mirall/owncloudsetupwizard.h b/src/mirall/owncloudsetupwizard.h index 66284a2b8..2fe1acf4b 100644 --- a/src/mirall/owncloudsetupwizard.h +++ b/src/mirall/owncloudsetupwizard.h @@ -59,7 +59,7 @@ private: void startWizard(); void testOwnCloudConnect(); - void checkRemoteFolder(); + void checkRemoteFolder(const QString& remoteFolder); bool createRemoteFolder(); void finalizeSetup( bool ); -- cgit v1.2.3 From 36cb8274067c1222f539bdae64f8d75903aefda3 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 14:51:42 +0200 Subject: Print correct subtitles when modifying account details. --- src/wizard/owncloudadvancedsetuppage.cpp | 5 ++--- src/wizard/owncloudadvancedsetuppage.h | 2 +- src/wizard/owncloudhttpcredspage.cpp | 10 ++++++++++ src/wizard/owncloudhttpcredspage.h | 2 ++ src/wizard/owncloudwizard.cpp | 8 ++------ 5 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/wizard/owncloudadvancedsetuppage.cpp b/src/wizard/owncloudadvancedsetuppage.cpp index 9102bfa21..36c025cb6 100644 --- a/src/wizard/owncloudadvancedsetuppage.cpp +++ b/src/wizard/owncloudadvancedsetuppage.cpp @@ -237,13 +237,12 @@ void OwncloudAdvancedSetupPage::slotSelectFolder() } } -void OwncloudAdvancedSetupPage::setConfigExists( bool config ) +void OwncloudAdvancedSetupPage::setConfigExists(bool config) { _configExists = config; if (config == true) { - setSubTitle( tr("Change your user credentials") - .arg(Theme::instance()->wizardHeaderTitleColor().name())); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Update advanced setup"))); } } diff --git a/src/wizard/owncloudadvancedsetuppage.h b/src/wizard/owncloudadvancedsetuppage.h index 2e46224c9..66b8de273 100644 --- a/src/wizard/owncloudadvancedsetuppage.h +++ b/src/wizard/owncloudadvancedsetuppage.h @@ -40,13 +40,13 @@ public: void setRemoteFolder( const QString& remoteFolder); void setMultipleFoldersExist( bool exist ); void directoriesCreated(); + void setConfigExists(bool config); signals: void createLocalAndRemoteFolders(const QString&, const QString&); public slots: void setErrorString( const QString& ); - void setConfigExists( bool ); private slots: void slotSelectFolder(); diff --git a/src/wizard/owncloudhttpcredspage.cpp b/src/wizard/owncloudhttpcredspage.cpp index c3c685873..584bbe264 100644 --- a/src/wizard/owncloudhttpcredspage.cpp +++ b/src/wizard/owncloudhttpcredspage.cpp @@ -30,6 +30,7 @@ OwncloudHttpCredsPage::OwncloudHttpCredsPage() _ui(), _connected(false), _checking(false), + _configExists(false), _progressIndi(new QProgressIndicator (this)) { _ui.setupUi(this); @@ -154,4 +155,13 @@ AbstractCredentials* OwncloudHttpCredsPage::getCredentials() const return new HttpCredentials(_ui.leUsername->text(), _ui.lePassword->text()); } +void OwncloudHttpCredsPage::setConfigExists(bool config) +{ + _configExists = config; + + if (config == true) { + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Update user credentials"))); + } +} + } // ns Mirall diff --git a/src/wizard/owncloudhttpcredspage.h b/src/wizard/owncloudhttpcredspage.h index 29412b002..095b7a62f 100644 --- a/src/wizard/owncloudhttpcredspage.h +++ b/src/wizard/owncloudhttpcredspage.h @@ -40,6 +40,7 @@ public: int nextId() const; void setConnected(bool connected); void setErrorString( const QString& err ); + void setConfigExists(bool config); Q_SIGNALS: void connectToOCUrl(const QString&); @@ -52,6 +53,7 @@ private: Ui_OwncloudHttpCredsPage _ui; bool _connected; bool _checking; + bool _configExists; QProgressIndicator* _progressIndi; }; diff --git a/src/wizard/owncloudwizard.cpp b/src/wizard/owncloudwizard.cpp index 5409163e7..bbcc78eb2 100644 --- a/src/wizard/owncloudwizard.cpp +++ b/src/wizard/owncloudwizard.cpp @@ -189,16 +189,12 @@ void OwncloudWizard::setOCUrl( const QString& url ) _setupPage->setServerUrl( url ); } -void OwncloudWizard::setOCUser( const QString& user ) -{ - _oCUser = user; - _httpCredsPage->setOCUser( user ); -} - void OwncloudWizard::setConfigExists( bool config ) { _configExists = config; _setupPage->setConfigExists( config ); + _httpCredsPage->setConfigExists(config); + _advancedSetupPage->setConfigExists(config); } bool OwncloudWizard::configExists() -- cgit v1.2.3 From 4104db65bb95668cb4f0d05a5393796c54a9417e Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 14:52:39 +0200 Subject: Remove unused method. --- src/wizard/owncloudhttpcredspage.cpp | 5 ----- src/wizard/owncloudhttpcredspage.h | 1 - src/wizard/owncloudwizard.h | 1 - 3 files changed, 7 deletions(-) (limited to 'src') diff --git a/src/wizard/owncloudhttpcredspage.cpp b/src/wizard/owncloudhttpcredspage.cpp index 584bbe264..fc832bc37 100644 --- a/src/wizard/owncloudhttpcredspage.cpp +++ b/src/wizard/owncloudhttpcredspage.cpp @@ -132,11 +132,6 @@ void OwncloudHttpCredsPage::stopSpinner() _progressIndi->stopAnimation(); } -void OwncloudHttpCredsPage::setOCUser(const QString& user) -{ - _ui.leUsername->setText(user); -} - void OwncloudHttpCredsPage::setErrorString(const QString& err) { if( err.isEmpty()) { diff --git a/src/wizard/owncloudhttpcredspage.h b/src/wizard/owncloudhttpcredspage.h index 095b7a62f..1e6a71098 100644 --- a/src/wizard/owncloudhttpcredspage.h +++ b/src/wizard/owncloudhttpcredspage.h @@ -33,7 +33,6 @@ public: AbstractCredentials* getCredentials() const; - void setOCUser(const QString& user); void initializePage(); void cleanupPage(); bool validatePage(); diff --git a/src/wizard/owncloudwizard.h b/src/wizard/owncloudwizard.h index b5ac2be77..cac61be9c 100644 --- a/src/wizard/owncloudwizard.h +++ b/src/wizard/owncloudwizard.h @@ -44,7 +44,6 @@ public: OwncloudWizard(QWidget *parent = 0); void setOCUrl( const QString& ); - void setOCUser( const QString& ); void setupCustomMedia( QVariant, QLabel* ); QString ocUrl() const; -- cgit v1.2.3 From c1fdecae2d80ca2a50df7754e2540a3e6924dbe8 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 14:52:51 +0200 Subject: Fix misc warnings. --- src/mirall/accountsettings.cpp | 1 + src/wizard/owncloudwizard.cpp | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index 89916a258..e774b4c89 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -556,6 +556,7 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf case Progress::Download: case Progress::Upload: case Progress::Inactive: + case Progress::Error: break; } diff --git a/src/wizard/owncloudwizard.cpp b/src/wizard/owncloudwizard.cpp index bbcc78eb2..95f4223d5 100644 --- a/src/wizard/owncloudwizard.cpp +++ b/src/wizard/owncloudwizard.cpp @@ -157,8 +157,6 @@ void OwncloudWizard::slotCurrentPageChanged( int id ) void OwncloudWizard::displayError( const QString& msg ) { - int id(currentId()); - switch (currentId()) { case WizardCommon::Page_ServerSetup: _setupPage->setErrorString( msg ); -- cgit v1.2.3 From f6e3838eb2b9dd9d342754973c5e1b17b37eb8b4 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 16:22:54 +0200 Subject: Create a QNetworkAccessManager subclass which sets proper user agent and use it. --- src/CMakeLists.txt | 2 ++ src/creds/dummycredentials.cpp | 5 ++-- src/creds/httpcredentials.cpp | 3 +- src/creds/shibboleth/shibbolethaccessmanager.cpp | 4 +-- src/creds/shibboleth/shibbolethaccessmanager.h | 5 ++-- src/creds/shibboleth/shibbolethwebview.cpp | 5 +++- src/mirall/mirallaccessmanager.cpp | 34 +++++++++++++++++++++++ src/mirall/mirallaccessmanager.h | 35 ++++++++++++++++++++++++ src/mirall/owncloudinfo.cpp | 2 -- src/mirall/owncloudsetupwizard.cpp | 3 +- src/mirall/updatedetector.cpp | 3 +- 11 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 src/mirall/mirallaccessmanager.cpp create mode 100644 src/mirall/mirallaccessmanager.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1574a535..6a35f4453 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,6 +79,7 @@ set(libsync_SRCS mirall/utility.cpp mirall/connectionvalidator.cpp mirall/progressdispatcher.cpp + mirall/mirallaccessmanager.cpp creds/dummycredentials.cpp creds/httpcredentials.cpp creds/credentialsfactory.cpp @@ -101,6 +102,7 @@ set(libsync_HEADERS mirall/logger.h mirall/connectionvalidator.h mirall/progressdispatcher.h + mirall/mirallaccessmanager.h creds/abstractcredentials.h creds/dummycredentials.h creds/httpcredentials.h diff --git a/src/creds/dummycredentials.cpp b/src/creds/dummycredentials.cpp index ca5e34a3f..6857d3218 100644 --- a/src/creds/dummycredentials.cpp +++ b/src/creds/dummycredentials.cpp @@ -11,9 +11,8 @@ * for more details. */ -#include - #include "creds/dummycredentials.h" +#include "mirall/mirallaccessmanager.h" namespace Mirall { @@ -38,7 +37,7 @@ QString DummyCredentials::authType() const QNetworkAccessManager* DummyCredentials::getQNAM() const { - return new QNetworkAccessManager; + return new MirallAccessManager; } bool DummyCredentials::ready() const diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp index 82d3d63fa..5105b2a1e 100644 --- a/src/creds/httpcredentials.cpp +++ b/src/creds/httpcredentials.cpp @@ -19,6 +19,7 @@ #include "creds/httpcredentials.h" #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" +#include "mirall/mirallaccessmanager.h" #include "mirall/utility.h" #include "creds/http/credentialstore.h" @@ -167,7 +168,7 @@ QString HttpCredentials::password() const QNetworkAccessManager* HttpCredentials::getQNAM() const { - QNetworkAccessManager* qnam = new QNetworkAccessManager; + MirallAccessManager* qnam = new MirallAccessManager; connect( qnam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*))); diff --git a/src/creds/shibboleth/shibbolethaccessmanager.cpp b/src/creds/shibboleth/shibbolethaccessmanager.cpp index 6b728c45c..5e9d1cf16 100644 --- a/src/creds/shibboleth/shibbolethaccessmanager.cpp +++ b/src/creds/shibboleth/shibbolethaccessmanager.cpp @@ -20,7 +20,7 @@ namespace Mirall { ShibbolethAccessManager::ShibbolethAccessManager(const QNetworkCookie& cookie, QObject* parent) - : QNetworkAccessManager (parent), + : MirallAccessManager (parent), _cookie(cookie) {} @@ -43,7 +43,7 @@ QNetworkReply* ShibbolethAccessManager::createRequest(QNetworkAccessManager::Ope qDebug() << "Creating a request to " << request.url().toString() << " with shibboleth cookie:" << _cookie.name(); - return QNetworkAccessManager::createRequest (op, request, outgoingData); + return MirallAccessManager::createRequest (op, request, outgoingData); } void ShibbolethAccessManager::setCookie(const QNetworkCookie& cookie) diff --git a/src/creds/shibboleth/shibbolethaccessmanager.h b/src/creds/shibboleth/shibbolethaccessmanager.h index b0e3fd2b2..e6ee4d25e 100644 --- a/src/creds/shibboleth/shibbolethaccessmanager.h +++ b/src/creds/shibboleth/shibbolethaccessmanager.h @@ -14,13 +14,14 @@ #ifndef MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H #define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H -#include #include +#include "mirall/mirallaccessmanager.h" + namespace Mirall { -class ShibbolethAccessManager : public QNetworkAccessManager +class ShibbolethAccessManager : public MirallAccessManager { Q_OBJECT diff --git a/src/creds/shibboleth/shibbolethwebview.cpp b/src/creds/shibboleth/shibbolethwebview.cpp index 21ff4053f..5b39afde7 100644 --- a/src/creds/shibboleth/shibbolethwebview.cpp +++ b/src/creds/shibboleth/shibbolethwebview.cpp @@ -17,6 +17,7 @@ #include "creds/shibboleth/shibbolethcookiejar.h" #include "creds/shibboleth/shibbolethwebview.h" +#include "mirall/mirallaccessmanager.h" namespace Mirall { @@ -24,13 +25,15 @@ namespace Mirall ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent) : QWebView(parent) { + MirallAccessManager* nm = new MirallAccessManager(this); ShibbolethCookieJar* jar = new ShibbolethCookieJar(this); QWebPage* page = new QWebPage(this); connect (jar, SIGNAL (newCookiesForUrl (QList, QUrl)), this, SLOT (onNewCookiesForUrl (QList, QUrl))); - page->networkAccessManager()->setCookieJar(jar); + nm->setCookieJar(jar); + page->setNetworkAccessManager(nm); page->mainFrame ()->load (url); this->setPage (page); } diff --git a/src/mirall/mirallaccessmanager.cpp b/src/mirall/mirallaccessmanager.cpp new file mode 100644 index 000000000..1e627bd10 --- /dev/null +++ b/src/mirall/mirallaccessmanager.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 + +#include "mirall/mirallaccessmanager.h" +#include "mirall/utility.h" + +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); +} + +} // ns Mirall diff --git a/src/mirall/mirallaccessmanager.h b/src/mirall/mirallaccessmanager.h new file mode 100644 index 000000000..a8dcbab30 --- /dev/null +++ b/src/mirall/mirallaccessmanager.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_ACCESS_MANAGER_H +#define MIRALL_ACCESS_MANAGER_H + +#include + +namespace Mirall +{ + +class MirallAccessManager : public QNetworkAccessManager +{ + Q_OBJECT + +public: + MirallAccessManager(QObject* parent = 0); + +protected: + QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); +}; + +} // ns Mirall + +#endif diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index 2cb267a9f..b9016e37a 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -15,7 +15,6 @@ #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" #include "mirall/theme.h" -#include "mirall/utility.h" #include "mirall/logger.h" #include "creds/abstractcredentials.h" @@ -521,7 +520,6 @@ 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); diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp index 0fcd08eb9..a95dbfee0 100644 --- a/src/mirall/owncloudsetupwizard.cpp +++ b/src/mirall/owncloudsetupwizard.cpp @@ -26,6 +26,7 @@ #include "mirall/owncloudinfo.h" #include "mirall/folderman.h" #include "mirall/utility.h" +#include "mirall/mirallaccessmanager.h" #include "creds/abstractcredentials.h" #include "creds/dummycredentials.h" @@ -165,7 +166,7 @@ void OwncloudSetupWizard::slotOwnCloudFoundAuth( const QString& url, const QStri _ocWizard->appendToConfigurationLog(tr("Successfully connected to %1: %2 version %3 (%4)

") .arg( url ).arg(Theme::instance()->appNameGUI()).arg(infoString).arg(version)); - QNetworkAccessManager* nm = new QNetworkAccessManager(this); + MirallAccessManager* nm = new MirallAccessManager(this); // TODO: We should get this path from owncloud info. QNetworkReply* reply = nm->get (QNetworkRequest (url + "/remote.php/webdav/")); diff --git a/src/mirall/updatedetector.cpp b/src/mirall/updatedetector.cpp index 20bde3cdd..628463db3 100644 --- a/src/mirall/updatedetector.cpp +++ b/src/mirall/updatedetector.cpp @@ -18,6 +18,7 @@ #include "mirall/mirallconfigfile.h" #include "mirall/occinfo.h" #include "mirall/utility.h" +#include "mirall/mirallaccessmanager.h" #include #include @@ -28,7 +29,7 @@ namespace Mirall { UpdateDetector::UpdateDetector(QObject *parent) : QObject(parent) - , _accessManager( new QNetworkAccessManager(this)) + , _accessManager(new MirallAccessManager(this)) { } -- cgit v1.2.3 From 72d51e4667f5cec504e5bfcbafea033d32ebcb40 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 16:50:17 +0200 Subject: Show browser as independent window instead of putting it into dialog. When browser is shown, dialog is hidden. It reappears after we are done with logging in. --- src/wizard/owncloudshibbolethcredspage.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wizard/owncloudshibbolethcredspage.cpp b/src/wizard/owncloudshibbolethcredspage.cpp index 968b97747..544eba996 100644 --- a/src/wizard/owncloudshibbolethcredspage.cpp +++ b/src/wizard/owncloudshibbolethcredspage.cpp @@ -59,15 +59,16 @@ bool OwncloudShibbolethCredsPage::isComplete() const void OwncloudShibbolethCredsPage::initializePage() { WizardCommon::initErrorLabel(_ui.errorLabel); - _browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified()), this); + _browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified())); _browser->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - _ui.contentLayout->insertWidget(0, _browser); + //_ui.contentLayout->insertWidget(0, _browser); _browser->show(); _browser->setFocus(); + wizard()->hide(); _ui.infoLabel->show(); _ui.infoLabel->setText(tr("Please follow the steps on displayed page above")); _stage = INITIAL_STEP; @@ -130,6 +131,7 @@ void OwncloudShibbolethCredsPage::setConnected( bool comp ) initializePage(); } emit completeChanged(); + wizard()->show(); } void OwncloudShibbolethCredsPage::setErrorString(const QString& err) @@ -156,6 +158,7 @@ void OwncloudShibbolethCredsPage::onShibbolethCookieReceived(const QNetworkCooki _cookie = cookie; _ui.infoLabel->setText("Please click \"Connect\" to check received Shibboleth session."); emit completeChanged(); + validatePage(); } } // ns Mirall -- cgit v1.2.3 From b0236eaa24c0f6964f9995c0c58affa00c1b0416 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 19:11:05 +0200 Subject: Fix folder item being inactive. --- src/mirall/folderstatusmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mirall/folderstatusmodel.cpp b/src/mirall/folderstatusmodel.cpp index 80ef75ac5..1b75489e1 100644 --- a/src/mirall/folderstatusmodel.cpp +++ b/src/mirall/folderstatusmodel.cpp @@ -28,7 +28,7 @@ FolderStatusModel::FolderStatusModel() Qt::ItemFlags FolderStatusModel::flags ( const QModelIndex& ) const { - return Qt::ItemIsSelectable; + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QVariant FolderStatusModel::data(const QModelIndex &index, int role) const -- cgit v1.2.3 From fb79b8a7f82c3b7a327e2d622a538eb501964038 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 1 Aug 2013 19:17:41 +0200 Subject: Omit the server setup page in wizard if URL is overriden by theme. --- src/wizard/owncloudsetuppage.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/wizard/owncloudsetuppage.cpp b/src/wizard/owncloudsetuppage.cpp index 6e8933925..3dea12f96 100644 --- a/src/wizard/owncloudsetuppage.cpp +++ b/src/wizard/owncloudsetuppage.cpp @@ -120,7 +120,14 @@ void OwncloudSetupPage::initializePage() _authTypeKnown = false; _checking = false; - _ui.leUrl->setFocus(); + // URL entry is disabled when url is overriden by theme. In that + // case we just check the server type and switch to second page + // immediately. + if (_ui.leUrl->isEnabled()) { + _ui.leUrl->setFocus(); + } else { + validatePage(); + } } bool OwncloudSetupPage::urlHasChanged() -- cgit v1.2.3 From 5930ca8ac7dec679029b9b2a82d139e9812df118 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Fri, 2 Aug 2013 14:30:15 +0200 Subject: Temporarily log HTTP traffic done by MirallAccessManager. To be reverted later. --- src/creds/httpcredentials.cpp | 2 + src/mirall/mirallaccessmanager.cpp | 115 ++++++++++++++++++++++++++++++++++++- src/mirall/mirallaccessmanager.h | 6 ++ 3 files changed, 122 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp index 5105b2a1e..ee3e23d5b 100644 --- a/src/creds/httpcredentials.cpp +++ b/src/creds/httpcredentials.cpp @@ -231,6 +231,8 @@ void HttpCredentials::slotAuthentication(QNetworkReply* reply, QAuthenticator* a qDebug() << "Too many attempts to authenticate. Stop request."; reply->close(); } else { + reply->setProperty("mirall-user", _user); + reply->setProperty("mirall-password", _password); authenticator->setUser( _user ); authenticator->setPassword( _password ); } diff --git a/src/mirall/mirallaccessmanager.cpp b/src/mirall/mirallaccessmanager.cpp index 1e627bd10..b0bec901e 100644 --- a/src/mirall/mirallaccessmanager.cpp +++ b/src/mirall/mirallaccessmanager.cpp @@ -11,7 +11,10 @@ * for more details. */ +#include +#include #include +#include #include "mirall/mirallaccessmanager.h" #include "mirall/utility.h" @@ -19,16 +22,126 @@ namespace Mirall { +namespace +{ + +QString +operationToString (QNetworkAccessManager::Operation op) +{ + switch (op) { + case QNetworkAccessManager::HeadOperation: + return QString::fromLatin1 ("HEAD"); + + case QNetworkAccessManager::GetOperation: + return QString::fromLatin1 ("GET"); + + case QNetworkAccessManager::PutOperation: + return QString::fromLatin1 ("PUT"); + + case QNetworkAccessManager::PostOperation: + return QString::fromLatin1 ("POST"); + + case QNetworkAccessManager::DeleteOperation: + return QString::fromLatin1 ("DELETE"); + + case QNetworkAccessManager::CustomOperation: + return QString::fromLatin1 ("CUSTOM"); + + case QNetworkAccessManager::UnknownOperation: + return QString::fromLatin1 ("UNKNOWN"); + } + + return QString::fromLatin1 ("PLAIN WRONG"); +} + +} // ns + MirallAccessManager::MirallAccessManager(QObject* parent) : QNetworkAccessManager (parent) {} QNetworkReply* MirallAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) { + static unsigned int staticRequestNo(0); + + unsigned int requestNo(staticRequestNo++); QNetworkRequest newRequest(request); newRequest.setRawHeader( QByteArray("User-Agent"), Utility::userAgentString()); - return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); + + QNetworkReply* reply(QNetworkAccessManager::createRequest (op, newRequest, outgoingData)); + + logRequest(requestNo, op, newRequest, outgoingData); + connect (reply, SIGNAL(finished()), + this, SLOT(logReply())); + reply->setProperty("mirall-request-no", QVariant(requestNo)); + return reply; +} + +void MirallAccessManager::logRequest(unsigned int requestNo, QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) +{ + QString log; + QTextStream stream (&log); + QVariant variant = request.attribute (QNetworkRequest::CustomVerbAttribute); + + stream << "\nREQUEST NO: " << requestNo + << "\nRequest operation: " << operationToString (op) + << "\nRequest URL: " << request.url ().toString (); + if (variant.isValid ()) { + stream << "Request custom operation: " << variant.toByteArray () << "\n"; + } + stream << "\nRequest headers:\n"; + Q_FOREACH (const QByteArray& header, request.rawHeaderList ()) { + stream << " " << header << ": " << request.rawHeader (header) << "\n"; + } + if (outgoingData) { + stream << "Body:\n" << outgoingData->peek(outgoingData->bytesAvailable()) << "\n"; + } + stream << "----------\n"; + qDebug() << log; +} + +void MirallAccessManager::logReply() +{ + QNetworkReply* reply = qobject_cast< QNetworkReply* > (sender()); + + if (!reply) { + return; + } + + disconnect (reply, SIGNAL(finished()), + this, SLOT(logReply())); + + unsigned int requestNo(reply->property("mirall-request-no").toUInt()); + QString log; + QTextStream stream (&log); + QVariant variant = reply->property ("mirall-user"); + + stream << "\nREPLY TO REQUEST NO: " << requestNo << "\n"; + if (variant.isValid()) { + stream << "Auth user: " << variant.toString() << "\n" + << "Auth password: " << reply->property("mirall-password").toString() << "\n"; + } + variant = reply->attribute (QNetworkRequest::HttpStatusCodeAttribute); + if (variant.isValid ()) { + stream << "Reply status: " << variant.toInt () << "\n"; + } + variant = reply->attribute (QNetworkRequest::HttpReasonPhraseAttribute); + if (variant.isValid ()) { + stream << "Reply reason: " << variant.toByteArray () << "\n"; + } + variant = reply->attribute (QNetworkRequest::RedirectionTargetAttribute); + if (variant.isValid ()) { + stream << "Reply redirection: " << variant.toUrl ().toString () << "\n"; + } + stream << "Reply headers:\n"; + Q_FOREACH (const QByteArray& header, reply->rawHeaderList ()) { + stream << " " << header << ": " << reply->rawHeader (header) << "\n"; + } + stream << "Reply data:\n" + << reply->peek (reply->bytesAvailable ()) + << "\n----------\n"; + qDebug() << log; } } // ns Mirall diff --git a/src/mirall/mirallaccessmanager.h b/src/mirall/mirallaccessmanager.h index a8dcbab30..20080ca6a 100644 --- a/src/mirall/mirallaccessmanager.h +++ b/src/mirall/mirallaccessmanager.h @@ -28,6 +28,12 @@ public: protected: QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); + +private Q_SLOTS: + void logReply(); + +private: + void logRequest(unsigned int requestNo, QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData); }; } // ns Mirall -- cgit v1.2.3 From 2b3b4f9daf667a00b8496b07d0f18d91a2c00068 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 5 Aug 2013 12:19:53 +0200 Subject: Start setup wizard if no config exists on startup. --- src/mirall/application.cpp | 33 ++++++++++++++++++++++----------- src/mirall/application.h | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 44bd5a49d..20648bdb8 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -193,15 +193,20 @@ void Application::slotStartUpdateDetector() void Application::slotCheckConnection() { - MirallConfigFile cfg; - AbstractCredentials* credentials(cfg.getCredentials()); - - if (! credentials->ready()) { - connect( credentials, SIGNAL(fetched()), - this, SLOT(slotCredentialsFetched())); - credentials->fetch(); + if( checkConfigExists(false) ) { + MirallConfigFile cfg; + AbstractCredentials* credentials(cfg.getCredentials()); + + if (! credentials->ready()) { + connect( credentials, SIGNAL(fetched()), + this, SLOT(slotCredentialsFetched())); + credentials->fetch(); + } else { + runValidator(); + } } else { - runValidator(); + // the call to checkConfigExists opens the setup wizard + // if the config does not exist. Nothing to do here. } } @@ -244,6 +249,8 @@ void Application::slotConnectionValidatorResult(ConnectionValidator::Status stat computeOverallSyncStatus(); setupContextMenu(); + } else if( status == ConnectionValidator::NotConfigured ) { + // this can not happen, it should be caught in first step of startup. } else { // What else? } @@ -630,21 +637,25 @@ void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason ) // Linux, not on Mac. They want a menu entry. #if defined Q_WS_WIN || defined Q_WS_X11 if( reason == QSystemTrayIcon::Trigger ) { - slotCheckConfig(); + checkConfigExists(true); // start settings if config is existing. } #endif } -void Application::slotCheckConfig() +bool Application::checkConfigExists(bool openSettings) { // if no config file is there, start the configuration wizard. MirallConfigFile cfgFile; if( cfgFile.exists() ) { - slotSettings(); + if( openSettings ) { + slotSettings(); + } + return true; } else { qDebug() << "No configured folders yet, starting setup wizard"; OwncloudSetupWizard::runWizard(this, SLOT(slotownCloudWizardDone(int))); + return false; } } diff --git a/src/mirall/application.h b/src/mirall/application.h index 3e906d86d..0e964ab8b 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -67,6 +67,7 @@ protected: void setupContextMenu(); void setupLogBrowser(); void enterNextLogFile(); + bool checkConfigExists(bool openSettings); //folders have to be disabled while making config changes void computeOverallSyncStatus(); @@ -82,7 +83,6 @@ signals: protected slots: void slotFoldersChanged(); - void slotCheckConfig(); void slotSettings(); void slotParseOptions( const QString& ); void slotShowTrayMessage(const QString&, const QString&); -- cgit v1.2.3 From da370c8b3623f2da163b6775661d7ed67c5bd62d Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 5 Aug 2013 15:26:31 +0200 Subject: Go back if browser in wizard is destroyed before getting a cookie. --- src/creds/shibboleth/shibbolethwebview.cpp | 7 +++++++ src/creds/shibboleth/shibbolethwebview.h | 4 ++++ src/wizard/owncloudshibbolethcredspage.cpp | 15 +++++++++++++++ src/wizard/owncloudshibbolethcredspage.h | 1 + 4 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/creds/shibboleth/shibbolethwebview.cpp b/src/creds/shibboleth/shibbolethwebview.cpp index 5b39afde7..c8a124daa 100644 --- a/src/creds/shibboleth/shibbolethwebview.cpp +++ b/src/creds/shibboleth/shibbolethwebview.cpp @@ -49,4 +49,11 @@ void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieL } } +void ShibbolethWebView::hideEvent(QHideEvent* event) +{ + QWebView::hideEvent(event); + + Q_EMIT hidden(); +} + } // ns Mirall diff --git a/src/creds/shibboleth/shibbolethwebview.h b/src/creds/shibboleth/shibbolethwebview.h index 9fc1179b9..7d90ae3e3 100644 --- a/src/creds/shibboleth/shibbolethwebview.h +++ b/src/creds/shibboleth/shibbolethwebview.h @@ -30,8 +30,12 @@ class ShibbolethWebView : public QWebView public: ShibbolethWebView(const QUrl& url, QWidget* parent = 0); +protected: + void hideEvent(QHideEvent* event); + Q_SIGNALS: void shibbolethCookieReceived (const QNetworkCookie& cookie); + void hidden(); private Q_SLOTS: void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); diff --git a/src/wizard/owncloudshibbolethcredspage.cpp b/src/wizard/owncloudshibbolethcredspage.cpp index 544eba996..92648107b 100644 --- a/src/wizard/owncloudshibbolethcredspage.cpp +++ b/src/wizard/owncloudshibbolethcredspage.cpp @@ -64,6 +64,8 @@ void OwncloudShibbolethCredsPage::initializePage() _browser->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + connect(_browser, SIGNAL(hidden()), + this, SLOT(browserDestroyed())); //_ui.contentLayout->insertWidget(0, _browser); _browser->show(); @@ -75,10 +77,23 @@ void OwncloudShibbolethCredsPage::initializePage() _cookie = QNetworkCookie(); } +void OwncloudShibbolethCredsPage::browserDestroyed() +{ + _browser = 0; + + QWizard* mainWizard(wizard()); + + mainWizard->show(); + mainWizard->raise(); + mainWizard->back(); +} + void OwncloudShibbolethCredsPage::disposeBrowser(bool later) { if (_browser) { _browser->hide(); + disconnect(_browser, SIGNAL(hidden()), + this, SLOT(browserDestroyed())); disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); if (later) { diff --git a/src/wizard/owncloudshibbolethcredspage.h b/src/wizard/owncloudshibbolethcredspage.h index d7d2bca79..1917fd49a 100644 --- a/src/wizard/owncloudshibbolethcredspage.h +++ b/src/wizard/owncloudshibbolethcredspage.h @@ -45,6 +45,7 @@ Q_SIGNALS: private Q_SLOTS: void onShibbolethCookieReceived(const QNetworkCookie& cookie); + void browserDestroyed(); private: enum Stage { -- cgit v1.2.3 From f0b284eda730e2b32a2342b799a5681d926ea10e Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 5 Aug 2013 17:31:52 +0200 Subject: Refresh Shibboleth cookie if it gets outdated during sync. --- src/CMakeLists.txt | 2 + src/creds/shibboleth/shibbolethrefresher.cpp | 52 ++++++++++++++ src/creds/shibboleth/shibbolethrefresher.h | 47 ++++++++++++ src/creds/shibbolethcredentials.cpp | 104 ++++++++++++++++++++++----- src/creds/shibbolethcredentials.h | 7 ++ 5 files changed, 193 insertions(+), 19 deletions(-) create mode 100644 src/creds/shibboleth/shibbolethrefresher.cpp create mode 100644 src/creds/shibboleth/shibbolethrefresher.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a35f4453..3b13aa416 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,6 +89,7 @@ set(libsync_SRCS creds/shibboleth/shibbolethaccessmanager.cpp creds/shibboleth/shibbolethcookiejar.cpp creds/shibboleth/shibbolethwebview.cpp + creds/shibboleth/shibbolethrefresher.cpp ) set(libsync_HEADERS @@ -113,6 +114,7 @@ set(libsync_HEADERS creds/shibboleth/shibbolethaccessmanager.h creds/shibboleth/shibbolethcookiejar.h creds/shibboleth/shibbolethwebview.h + creds/shibboleth/shibbolethrefresher.h ) IF( INOTIFY_FOUND ) diff --git a/src/creds/shibboleth/shibbolethrefresher.cpp b/src/creds/shibboleth/shibbolethrefresher.cpp new file mode 100644 index 000000000..3f5e00466 --- /dev/null +++ b/src/creds/shibboleth/shibbolethrefresher.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 + +#include "creds/shibboleth/shibbolethrefresher.h" +#include "creds/shibbolethcredentials.h" + +namespace Mirall +{ + +ShibbolethRefresher::ShibbolethRefresher(ShibbolethCredentials* creds, CSYNC* csync_ctx, QObject* parent) + : QObject(parent), + _creds(creds), + _csync_ctx(csync_ctx) +{} + +void ShibbolethRefresher::refresh() +{ + QEventLoop loop; + + connect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)), + this, SLOT(onInvalidatedAndFetched(QByteArray))); + connect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)), + &loop, SLOT(quit())); + QMetaObject::invokeMethod(_creds, "invalidateAndFetch", Qt::QueuedConnection); + loop.exec(); + disconnect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)), + &loop, SLOT(quit())); +} + +void ShibbolethRefresher::onInvalidatedAndFetched(const QByteArray& cookies) +{ + // "cookies" is const and its data() return const void*. We want just void*. + QByteArray myCookies(cookies); + + disconnect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)), + this, SLOT(onInvalidatedAndFetched(QByteArray))); + csync_set_module_property(_csync_ctx, "session_key", myCookies.data()); +} + +} // ns Mirall diff --git a/src/creds/shibboleth/shibbolethrefresher.h b/src/creds/shibboleth/shibbolethrefresher.h new file mode 100644 index 000000000..39d2ef55c --- /dev/null +++ b/src/creds/shibboleth/shibbolethrefresher.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) by Krzesimir Nowak + * + * 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 MIRALL_CREDS_SHIBBOLETH_REFRESHER_H +#define MIRALL_CREDS_SHIBBOLETH_REFRESHER_H + +#include + +#include + +class QByteArray; + +namespace Mirall +{ + +class ShibbolethCredentials; + +class ShibbolethRefresher : public QObject +{ + Q_OBJECT + +public: + ShibbolethRefresher(ShibbolethCredentials* creds, CSYNC* csync_ctx, QObject* parent = 0); + + void refresh(); + +private Q_SLOTS: + void onInvalidatedAndFetched(const QByteArray& cookieData); + +private: + ShibbolethCredentials* _creds; + CSYNC* _csync_ctx; +}; + +} // ns Mirall + +#endif diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp index 6c61940ac..936ea41c4 100644 --- a/src/creds/shibbolethcredentials.cpp +++ b/src/creds/shibbolethcredentials.cpp @@ -15,12 +15,52 @@ #include "creds/shibbolethcredentials.h" #include "creds/shibboleth/shibbolethaccessmanager.h" #include "creds/shibboleth/shibbolethwebview.h" +#include "creds/shibboleth/shibbolethrefresher.h" #include "mirall/owncloudinfo.h" #include "mirall/mirallconfigfile.h" +#include "mirall/csyncthread.h" namespace Mirall { +namespace +{ + +int shibboleth_redirect_callback(CSYNC* csync_ctx, + const char* uri) +{ + if (!csync_ctx || !uri) { + return 1; + } + + const QString qurl(QString::fromLatin1(uri)); + QRegExp shibbolethyWords ("SAML|wayf"); + + shibbolethyWords.setCaseSensitivity (Qt::CaseInsensitive); + if (!qurl.contains(shibbolethyWords)) { + return 1; + } + + QMutex mutex; + QMutexLocker locker(&mutex); + MirallConfigFile cfg; + ShibbolethCredentials* creds = dynamic_cast< ShibbolethCredentials* > (cfg.getCredentials()); + + if (!creds) { + qDebug() << "Not a Shibboleth creds instance!"; + return 1; + } + + ShibbolethRefresher refresher(creds, csync_ctx); + + // blocks + refresher.refresh(); + + return 0; +} + +} // ns + ShibbolethCredentials::ShibbolethCredentials() : _shibCookie(), _ready(false), @@ -33,29 +73,39 @@ ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie) _browser(0) {} -void ShibbolethCredentials::syncContextPreInit (CSYNC*) +void ShibbolethCredentials::syncContextPreInit(CSYNC*) {} +QByteArray ShibbolethCredentials::prepareCookieData() const +{ + QString cookiesAsString; + // TODO: This should not be a part of this method, but we don't + // have any way to get "session_key" module property from + // csync. Had we have it, then we could just append shibboleth + // cookies to the "session_key" value and set it in csync module. + QList cookies(ownCloudInfo::instance()->getLastAuthCookies()); + + cookies << _shibCookie; + // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply + // when https://github.com/owncloud/core/pull/4042 is merged. + foreach(QNetworkCookie c, cookies) { + cookiesAsString += c.name(); + cookiesAsString += '='; + cookiesAsString += c.value(); + cookiesAsString += "; "; + } + + return cookiesAsString.toLatin1(); +} + void ShibbolethCredentials::syncContextPreStart (CSYNC* ctx) { - QString cookiesAsString; - // TODO: This should not be a part of this method, but we don't - // have any way to get "session_key" module property from - // csync. Had we have it, then we could just append shibboleth - // cookies to the "session_key" value and set it in csync module. - QList cookies(ownCloudInfo::instance()->getLastAuthCookies()); - - cookies << _shibCookie; - // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply - // when https://github.com/owncloud/core/pull/4042 is merged. - foreach(QNetworkCookie c, cookies) { - cookiesAsString += c.name(); - cookiesAsString += '='; - cookiesAsString += c.value(); - cookiesAsString += "; "; - } - - csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data()); + typedef int (*csync_owncloud_redirect_callback_t)(CSYNC* ctx, const char* uri); + + csync_owncloud_redirect_callback_t cb = shibboleth_redirect_callback; + + csync_set_module_property(ctx, "session_key", prepareCookieData().data()); + csync_set_module_property(ctx, "redirect_callback", &cb); } bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const @@ -125,4 +175,20 @@ void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& coo Q_EMIT fetched(); } +void ShibbolethCredentials::invalidateAndFetch() +{ + _ready = false; + connect (this, SIGNAL(fetched()), + this, SLOT(onFetched())); + fetch(); +} + +void ShibbolethCredentials::onFetched() +{ + disconnect (this, SIGNAL(fetched()), + this, SLOT(onFetched())); + + Q_EMIT invalidatedAndFetched(prepareCookieData()); +} + } // ns Mirall diff --git a/src/creds/shibbolethcredentials.h b/src/creds/shibbolethcredentials.h index a238e294b..27c4692ba 100644 --- a/src/creds/shibbolethcredentials.h +++ b/src/creds/shibbolethcredentials.h @@ -42,13 +42,20 @@ public: QNetworkCookie cookie() const; +public Q_SLOTS: + void invalidateAndFetch(); + private Q_SLOTS: void onShibbolethCookieReceived(const QNetworkCookie& cookie); + void onFetched(); Q_SIGNALS: void newCookie(const QNetworkCookie& cookie); + void invalidatedAndFetched(const QByteArray& cookieData); private: + QByteArray prepareCookieData() const; + QNetworkCookie _shibCookie; bool _ready; ShibbolethWebView* _browser; -- cgit v1.2.3 From 740d33b378adca8edbb55bd2bde88d5620a02544 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 5 Aug 2013 17:57:32 +0200 Subject: Revert "Go back if browser in wizard is destroyed before getting a cookie." This reverts commit da370c8b3623f2da163b6775661d7ed67c5bd62d. --- src/creds/shibboleth/shibbolethwebview.cpp | 7 ------- src/creds/shibboleth/shibbolethwebview.h | 4 ---- src/wizard/owncloudshibbolethcredspage.cpp | 15 --------------- src/wizard/owncloudshibbolethcredspage.h | 1 - 4 files changed, 27 deletions(-) (limited to 'src') diff --git a/src/creds/shibboleth/shibbolethwebview.cpp b/src/creds/shibboleth/shibbolethwebview.cpp index c8a124daa..5b39afde7 100644 --- a/src/creds/shibboleth/shibbolethwebview.cpp +++ b/src/creds/shibboleth/shibbolethwebview.cpp @@ -49,11 +49,4 @@ void ShibbolethWebView::onNewCookiesForUrl (const QList& cookieL } } -void ShibbolethWebView::hideEvent(QHideEvent* event) -{ - QWebView::hideEvent(event); - - Q_EMIT hidden(); -} - } // ns Mirall diff --git a/src/creds/shibboleth/shibbolethwebview.h b/src/creds/shibboleth/shibbolethwebview.h index 7d90ae3e3..9fc1179b9 100644 --- a/src/creds/shibboleth/shibbolethwebview.h +++ b/src/creds/shibboleth/shibbolethwebview.h @@ -30,12 +30,8 @@ class ShibbolethWebView : public QWebView public: ShibbolethWebView(const QUrl& url, QWidget* parent = 0); -protected: - void hideEvent(QHideEvent* event); - Q_SIGNALS: void shibbolethCookieReceived (const QNetworkCookie& cookie); - void hidden(); private Q_SLOTS: void onNewCookiesForUrl (const QList& cookieList, const QUrl& url); diff --git a/src/wizard/owncloudshibbolethcredspage.cpp b/src/wizard/owncloudshibbolethcredspage.cpp index 92648107b..544eba996 100644 --- a/src/wizard/owncloudshibbolethcredspage.cpp +++ b/src/wizard/owncloudshibbolethcredspage.cpp @@ -64,8 +64,6 @@ void OwncloudShibbolethCredsPage::initializePage() _browser->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); - connect(_browser, SIGNAL(hidden()), - this, SLOT(browserDestroyed())); //_ui.contentLayout->insertWidget(0, _browser); _browser->show(); @@ -77,23 +75,10 @@ void OwncloudShibbolethCredsPage::initializePage() _cookie = QNetworkCookie(); } -void OwncloudShibbolethCredsPage::browserDestroyed() -{ - _browser = 0; - - QWizard* mainWizard(wizard()); - - mainWizard->show(); - mainWizard->raise(); - mainWizard->back(); -} - void OwncloudShibbolethCredsPage::disposeBrowser(bool later) { if (_browser) { _browser->hide(); - disconnect(_browser, SIGNAL(hidden()), - this, SLOT(browserDestroyed())); disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); if (later) { diff --git a/src/wizard/owncloudshibbolethcredspage.h b/src/wizard/owncloudshibbolethcredspage.h index 1917fd49a..d7d2bca79 100644 --- a/src/wizard/owncloudshibbolethcredspage.h +++ b/src/wizard/owncloudshibbolethcredspage.h @@ -45,7 +45,6 @@ Q_SIGNALS: private Q_SLOTS: void onShibbolethCookieReceived(const QNetworkCookie& cookie); - void browserDestroyed(); private: enum Stage { -- cgit v1.2.3 From 00e819bd922350b2e11fce00a72a49d4d566c93a Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 5 Aug 2013 18:39:26 +0200 Subject: Make sure we don't append several copies of cookies for syncing. Also, make sure we don't append old Shibboleth ones as well. --- src/creds/shibbolethcredentials.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp index 936ea41c4..2e2eb01b8 100644 --- a/src/creds/shibbolethcredentials.cpp +++ b/src/creds/shibbolethcredentials.cpp @@ -84,14 +84,25 @@ QByteArray ShibbolethCredentials::prepareCookieData() const // csync. Had we have it, then we could just append shibboleth // cookies to the "session_key" value and set it in csync module. QList cookies(ownCloudInfo::instance()->getLastAuthCookies()); + QMap uniqueCookies; cookies << _shibCookie; // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply // when https://github.com/owncloud/core/pull/4042 is merged. foreach(QNetworkCookie c, cookies) { - cookiesAsString += c.name(); + const QString cookieName(c.name()); + + if (cookieName.startsWith("_shibsession_")) { + continue; + } + uniqueCookies.insert(cookieName, c.value()); + } + + uniqueCookies.insert(_shibCookie.name(), _shibCookie.value()); + foreach(const QString& cookieName, uniqueCookies.keys()) { + cookiesAsString += cookieName; cookiesAsString += '='; - cookiesAsString += c.value(); + cookiesAsString += uniqueCookies[cookieName]; cookiesAsString += "; "; } -- cgit v1.2.3 From ee1b8465a3f08d39e8c71b9aa53401fde17c88ac Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Mon, 5 Aug 2013 19:47:48 +0200 Subject: Revert "Temporarily log HTTP traffic done by MirallAccessManager." This reverts commit 5930ca8ac7dec679029b9b2a82d139e9812df118. --- src/creds/httpcredentials.cpp | 2 - src/mirall/mirallaccessmanager.cpp | 115 +------------------------------------ src/mirall/mirallaccessmanager.h | 6 -- 3 files changed, 1 insertion(+), 122 deletions(-) (limited to 'src') diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp index ee3e23d5b..5105b2a1e 100644 --- a/src/creds/httpcredentials.cpp +++ b/src/creds/httpcredentials.cpp @@ -231,8 +231,6 @@ void HttpCredentials::slotAuthentication(QNetworkReply* reply, QAuthenticator* a qDebug() << "Too many attempts to authenticate. Stop request."; reply->close(); } else { - reply->setProperty("mirall-user", _user); - reply->setProperty("mirall-password", _password); authenticator->setUser( _user ); authenticator->setPassword( _password ); } diff --git a/src/mirall/mirallaccessmanager.cpp b/src/mirall/mirallaccessmanager.cpp index b0bec901e..1e627bd10 100644 --- a/src/mirall/mirallaccessmanager.cpp +++ b/src/mirall/mirallaccessmanager.cpp @@ -11,10 +11,7 @@ * for more details. */ -#include -#include #include -#include #include "mirall/mirallaccessmanager.h" #include "mirall/utility.h" @@ -22,126 +19,16 @@ namespace Mirall { -namespace -{ - -QString -operationToString (QNetworkAccessManager::Operation op) -{ - switch (op) { - case QNetworkAccessManager::HeadOperation: - return QString::fromLatin1 ("HEAD"); - - case QNetworkAccessManager::GetOperation: - return QString::fromLatin1 ("GET"); - - case QNetworkAccessManager::PutOperation: - return QString::fromLatin1 ("PUT"); - - case QNetworkAccessManager::PostOperation: - return QString::fromLatin1 ("POST"); - - case QNetworkAccessManager::DeleteOperation: - return QString::fromLatin1 ("DELETE"); - - case QNetworkAccessManager::CustomOperation: - return QString::fromLatin1 ("CUSTOM"); - - case QNetworkAccessManager::UnknownOperation: - return QString::fromLatin1 ("UNKNOWN"); - } - - return QString::fromLatin1 ("PLAIN WRONG"); -} - -} // ns - MirallAccessManager::MirallAccessManager(QObject* parent) : QNetworkAccessManager (parent) {} QNetworkReply* MirallAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) { - static unsigned int staticRequestNo(0); - - unsigned int requestNo(staticRequestNo++); QNetworkRequest newRequest(request); newRequest.setRawHeader( QByteArray("User-Agent"), Utility::userAgentString()); - - QNetworkReply* reply(QNetworkAccessManager::createRequest (op, newRequest, outgoingData)); - - logRequest(requestNo, op, newRequest, outgoingData); - connect (reply, SIGNAL(finished()), - this, SLOT(logReply())); - reply->setProperty("mirall-request-no", QVariant(requestNo)); - return reply; -} - -void MirallAccessManager::logRequest(unsigned int requestNo, QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData) -{ - QString log; - QTextStream stream (&log); - QVariant variant = request.attribute (QNetworkRequest::CustomVerbAttribute); - - stream << "\nREQUEST NO: " << requestNo - << "\nRequest operation: " << operationToString (op) - << "\nRequest URL: " << request.url ().toString (); - if (variant.isValid ()) { - stream << "Request custom operation: " << variant.toByteArray () << "\n"; - } - stream << "\nRequest headers:\n"; - Q_FOREACH (const QByteArray& header, request.rawHeaderList ()) { - stream << " " << header << ": " << request.rawHeader (header) << "\n"; - } - if (outgoingData) { - stream << "Body:\n" << outgoingData->peek(outgoingData->bytesAvailable()) << "\n"; - } - stream << "----------\n"; - qDebug() << log; -} - -void MirallAccessManager::logReply() -{ - QNetworkReply* reply = qobject_cast< QNetworkReply* > (sender()); - - if (!reply) { - return; - } - - disconnect (reply, SIGNAL(finished()), - this, SLOT(logReply())); - - unsigned int requestNo(reply->property("mirall-request-no").toUInt()); - QString log; - QTextStream stream (&log); - QVariant variant = reply->property ("mirall-user"); - - stream << "\nREPLY TO REQUEST NO: " << requestNo << "\n"; - if (variant.isValid()) { - stream << "Auth user: " << variant.toString() << "\n" - << "Auth password: " << reply->property("mirall-password").toString() << "\n"; - } - variant = reply->attribute (QNetworkRequest::HttpStatusCodeAttribute); - if (variant.isValid ()) { - stream << "Reply status: " << variant.toInt () << "\n"; - } - variant = reply->attribute (QNetworkRequest::HttpReasonPhraseAttribute); - if (variant.isValid ()) { - stream << "Reply reason: " << variant.toByteArray () << "\n"; - } - variant = reply->attribute (QNetworkRequest::RedirectionTargetAttribute); - if (variant.isValid ()) { - stream << "Reply redirection: " << variant.toUrl ().toString () << "\n"; - } - stream << "Reply headers:\n"; - Q_FOREACH (const QByteArray& header, reply->rawHeaderList ()) { - stream << " " << header << ": " << reply->rawHeader (header) << "\n"; - } - stream << "Reply data:\n" - << reply->peek (reply->bytesAvailable ()) - << "\n----------\n"; - qDebug() << log; + return QNetworkAccessManager::createRequest (op, newRequest, outgoingData); } } // ns Mirall diff --git a/src/mirall/mirallaccessmanager.h b/src/mirall/mirallaccessmanager.h index 20080ca6a..a8dcbab30 100644 --- a/src/mirall/mirallaccessmanager.h +++ b/src/mirall/mirallaccessmanager.h @@ -28,12 +28,6 @@ public: protected: QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0); - -private Q_SLOTS: - void logReply(); - -private: - void logRequest(unsigned int requestNo, QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData); }; } // ns Mirall -- cgit v1.2.3