From 64e83cb287966427b5a8ecd7ed1752a259fe5bcd Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 25 Jul 2012 17:51:29 +0300 Subject: [PATCH] Added a new setup page in the ownCloud connection wizard. Also added the ability for custom images and text in the setup assistant. --- src/CMakeLists.txt | 1 + src/mirall/mirallconfigfile.cpp | 36 +++++++ src/mirall/mirallconfigfile.h | 10 ++ src/mirall/owncloudsetuppage.ui | 185 ++++++++++++++++++++++++++++++++ src/mirall/owncloudwizard.cpp | 149 ++++++++++++++++++++++++- src/mirall/owncloudwizard.h | 27 +++++ 6 files changed, 406 insertions(+), 2 deletions(-) create mode 100644 src/mirall/owncloudsetuppage.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 545b7163ed..70bb059f37 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ mirall/folderwizardnetworkpage.ui mirall/folderwizardowncloudpage.ui mirall/statusdialog.ui mirall/owncloudwizardselecttypepage.ui +mirall/owncloudsetuppage.ui mirall/createanowncloudpage.ui mirall/owncloudftpaccesspage.ui mirall/owncloudwizardresultpage.ui diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index 1cf5d17fa3..41b110ae9c 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -428,5 +428,41 @@ void MirallConfigFile::acceptCustomConfig() QFile::remove( targetBak ); } +QVariant MirallConfigFile::customMedia( customMediaType type ) +{ + QVariant re; + QString key; + + if( type == oCSetupTop ) { + key = QLatin1String("oCSetupTop"); + } else if( type == oCSetupSide ) { + key = QLatin1String("oCSetupSide"); + } else if( type == oCSetupBottom) { + key = QLatin1String("oCSetupBottom"); + } else if( type == oCSetupFixUrl ) { + key = QLatin1String("oCSetupFixUrl"); + } else { + qDebug() << "Wrong media type."; + } + + if( !key.isEmpty() ) { + QSettings settings( configFile(), QSettings::IniFormat ); + settings.setIniCodec( "UTF-8" ); + settings.beginGroup(QLatin1String("GUICustomize")); + QString val = settings.value( key, QString() ).toString(); + + if( !val.isEmpty() ) { + QPixmap pix( val ); + if( pix.isNull() ) { + // pixmap loading hasn't succeeded. We take the text instead. + re.setValue( val ); + } else { + re.setValue( pix ); + } + } + } + return re; +} + } diff --git a/src/mirall/mirallconfigfile.h b/src/mirall/mirallconfigfile.h index 265dbdab69..c4a572c514 100644 --- a/src/mirall/mirallconfigfile.h +++ b/src/mirall/mirallconfigfile.h @@ -17,6 +17,7 @@ #include +class QVariant; namespace Mirall { @@ -26,6 +27,13 @@ class MirallConfigFile public: MirallConfigFile( const QString& appendix = QString() ); + enum customMediaType { + oCSetupTop, + oCSetupSide, + oCSetupBottom, + oCSetupFixUrl + }; + QString configPath() const; QString configFile() const; QString excludeFile() const; @@ -51,6 +59,8 @@ public: QString ownCloudVersion() const; void setOwnCloudVersion( const QString& ); + QVariant customMedia( customMediaType ); + // max count of lines in the log window int maxLogLines() const; diff --git a/src/mirall/owncloudsetuppage.ui b/src/mirall/owncloudsetuppage.ui new file mode 100644 index 0000000000..5ef856d758 --- /dev/null +++ b/src/mirall/owncloudsetuppage.ui @@ -0,0 +1,185 @@ + + + OwncloudSetupPage + + + + 0 + 0 + 480 + 271 + + + + Form + + + + + + Qt::Horizontal + + + + + 14 + 50 + false + + + + Create the ownCloud Connection + + + + + + + + Server &address: + + + leUrl + + + + + + + + + https:// + + + + + + + + + + + + + + + + Use &secure connection + + + true + + + + + + + true + + + CheckBox + + + true + + + true + + + + + + + + + &Username: + + + leUsername + + + + + + + + + + &Password: + + + lePassword + + + + + + + Enter the ownCloud password. + + + + + + QLineEdit::Password + + + + + + + + + &do not store Password on local machine. + + + + + + + + + TextLabel + + + + + + + + + Qt::Vertical + + + + 344 + 19 + + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + TextLabel + + + + + + + + diff --git a/src/mirall/owncloudwizard.cpp b/src/mirall/owncloudwizard.cpp index f8d3e811b1..5dd766185d 100644 --- a/src/mirall/owncloudwizard.cpp +++ b/src/mirall/owncloudwizard.cpp @@ -13,6 +13,7 @@ * for more details. */ #include "mirall/owncloudwizard.h" +#include "mirall/mirallconfigfile.h" #include #include @@ -29,6 +30,139 @@ namespace Mirall { +// ====================================================================== + + +OwncloudSetupPage::OwncloudSetupPage() +{ + _ui.setupUi(this); + registerField( "OCUrl", _ui.leUrl ); + registerField( "OCUser", _ui.leUsername ); + registerField( "OCPasswd", _ui.lePassword); + registerField( "connectMyOC", _ui.cbConnectOC ); + + registerField( "PwdNoLocalStore", _ui.cbNoPasswordStore ); + + connect( _ui.lePassword, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); + + connect( _ui.cbNoPasswordStore, SIGNAL(stateChanged(int)), this, SLOT(slotPwdStoreChanged(int))); + connect( _ui.cbSecureConnect, SIGNAL(stateChanged(int)), this, SLOT(slotSecureConChanged(int))); + + _ui.cbConnectOC->hide(); + setupCustomization(); +} + +OwncloudSetupPage::~OwncloudSetupPage() +{ +#if QT_VERSION >= 0x040700 + _ui.leUsername->setPlaceholderText(QApplication::translate("OwncloudSetupPage", "john", 0, QApplication::UnicodeUTF8)); + _ui.lePassword->setPlaceholderText(QApplication::translate("OwncloudSetupPage", "secret", 0, QApplication::UnicodeUTF8)); +#endif +} + +void OwncloudSetupPage::setOCUrl( const QString& newUrl ) +{ + QString url( newUrl ); + if( url.isEmpty() ) { + _ui.leUrl->clear(); + return; + } + if( url.startsWith( QLatin1String("https"))) { + _ui.cbSecureConnect->setChecked( true ); + url.remove(0,5); + } else if( url.startsWith( QLatin1String("http"))) { + _ui.cbSecureConnect->setChecked( false ); + url.remove(0,4); + } + if( url.startsWith( QLatin1String("://"))) url.remove(0,3); + + _ui.leUrl->setText( url ); +} + +void OwncloudSetupPage::setupCustomization() +{ + // set defaults for the customize labels. + _ui.sideLabel->setText( QString() ); + _ui.sideLabel->setFixedWidth(160); + + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + + MirallConfigFile cfg; + + QVariant variant = cfg.customMedia( MirallConfigFile::oCSetupTop ); + setupCustomMedia( variant, _ui.topLabel ); + variant = cfg.customMedia( MirallConfigFile::oCSetupSide ); + setupCustomMedia( variant, _ui.sideLabel ); + variant = cfg.customMedia( MirallConfigFile::oCSetupBottom ); + setupCustomMedia( variant, _ui.bottomLabel ); + + QString fixUrl = cfg.customMedia( MirallConfigFile::oCSetupFixUrl ).toString(); + if( !fixUrl.isEmpty() ) { + setOCUrl( fixUrl ); + _ui.leUrl->setEnabled( false ); + _ui.cbSecureConnect->hide(); + } +} + +void OwncloudSetupPage::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); + } + } +} + +void OwncloudSetupPage::slotPwdStoreChanged( int state ) +{ + _ui.lePassword->setEnabled( state == Qt::Unchecked ); + emit completeChanged(); +} + +void OwncloudSetupPage::slotSecureConChanged( int state ) +{ + if( state == Qt::Checked ) { + _ui.protocolLabel->setText(QLatin1String("https://")); + } else { + _ui.protocolLabel->setText(QLatin1String("http://")); + } +} + +bool OwncloudSetupPage::isComplete() const +{ + if( _ui.leUrl->text().isEmpty() ) return false; + + if( _ui.cbNoPasswordStore->checkState() == Qt::Checked ) { + return !(_ui.leUsername->text().isEmpty()); + } + return !(_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty() ); +} + +void OwncloudSetupPage::initializePage() +{ + QString user = qgetenv( "USER" ); + _ui.leUsername->setText( user ); +} + +int OwncloudSetupPage::nextId() const +{ + return OwncloudWizard::Page_Install; +} + +// ====================================================================== + OwncloudWizardSelectTypePage::OwncloudWizardSelectTypePage() { _ui.setupUi(this); @@ -287,15 +421,20 @@ void OwncloudWizardResultPage::showOCUrlLabel( const QString& url, bool show ) OwncloudWizard::OwncloudWizard(QWidget *parent) : QWizard(parent) { +#ifdef OWNCLOUD_CLIENT + setPage(Page_oCSetup, new OwncloudSetupPage() ); +#else setPage(Page_SelectType, new OwncloudWizardSelectTypePage() ); + setPage(Page_OC_Credentials, new OwncloudCredentialsPage() ); +#endif setPage(Page_Create_OC, new CreateAnOwncloudPage() ); setPage(Page_FTP, new OwncloudFTPAccessPage() ); - setPage(Page_OC_Credentials, new OwncloudCredentialsPage() ); setPage(Page_Install, new OwncloudWizardResultPage() ); #ifdef Q_WS_MAC setWizardStyle( QWizard::ModernStyle ); #endif + setField("connectMyOC", true); connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int))); @@ -354,8 +493,14 @@ void OwncloudWizard::appendToResultWidget( const QString& msg, LogType type ) void OwncloudWizard::setOCUrl( const QString& url ) { _oCUrl = url; +#ifdef OWNCLOUD_CLIENT + OwncloudSetupPage *p = static_cast(page(Page_oCSetup)); +#else OwncloudWizardSelectTypePage *p = static_cast(page( Page_SelectType )); - p->setOCUrl( url ); +#endif + if( p ) + p->setOCUrl( url ); + } } // end namespace diff --git a/src/mirall/owncloudwizard.h b/src/mirall/owncloudwizard.h index 81468ed0df..6a122fd550 100644 --- a/src/mirall/owncloudwizard.h +++ b/src/mirall/owncloudwizard.h @@ -23,15 +23,42 @@ #include "ui_owncloudftpaccesspage.h" #include "ui_owncloudwizardresultpage.h" #include "ui_owncloudcredentialspage.h" +#include "ui_owncloudsetuppage.h" + +class QLabel; +class QVariant; namespace Mirall { +class OwncloudSetupPage: public QWizardPage +{ + Q_OBJECT +public: + OwncloudSetupPage(); + ~OwncloudSetupPage(); + + virtual bool isComplete() const; + virtual void initializePage(); + virtual int nextId() const; + void setOCUrl( const QString& ); + +protected slots: + void slotPwdStoreChanged( int ); + void slotSecureConChanged( int ); + void setupCustomization(); + void setupCustomMedia( QVariant, QLabel* ); +private: + Ui_OwncloudSetupPage _ui; + +}; + class OwncloudWizard: public QWizard { Q_OBJECT public: enum { + Page_oCSetup, Page_SelectType, Page_Create_OC, Page_OC_Credentials,