diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 504b60740d..56f99ef1d1 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 0000000000..35f539a256 --- /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 0000000000..5e08a64b1c --- /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 506a16c296..ffb8abc2f4 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 3fd70766e4..540255dce5 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 68fc05ba22..0000000000 --- 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 ceccf12093..0000000000 --- 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 0000000000..99d06acccf --- /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 0000000000..c9eadbd9f4 --- /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 0000000000..e32381a520 --- /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 0000000000..c56dd15504 --- /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 0000000000..b5d21e0078 --- /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 0000000000..bd6cf6814a --- /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 0000000000..10e66bb1b4 --- /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 0000000000..d4b0ec21c9 --- /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 0000000000..a4ece42365 --- /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 0000000000..64158e130c --- /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