Added a new setup page in the ownCloud connection wizard. Also added

the ability for custom images and text in  the setup assistant.
This commit is contained in:
Klaas Freitag 2012-07-25 17:51:29 +03:00
parent 37359969e4
commit 64e83cb287
6 changed files with 406 additions and 2 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -17,6 +17,7 @@
#include <QString>
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;

View File

@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OwncloudSetupPage</class>
<widget class="QWidget" name="OwncloudSetupPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>271</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Create the ownCloud Connection</string>
</property>
</widget>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Server &amp;address:</string>
</property>
<property name="buddy">
<cstring>leUrl</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="protocolLabel">
<property name="text">
<string>https://</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leUrl"/>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="cbSecureConnect">
<property name="text">
<string>Use &amp;secure connection</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbConnectOC">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>CheckBox</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Username:</string>
</property>
<property name="buddy">
<cstring>leUsername</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leUsername"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&amp;Password:</string>
</property>
<property name="buddy">
<cstring>lePassword</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lePassword">
<property name="toolTip">
<string>Enter the ownCloud password.</string>
</property>
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbNoPasswordStore">
<property name="text">
<string>&amp;do not store Password on local machine.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="sideLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>344</width>
<height>19</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="topLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="bottomLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -13,6 +13,7 @@
* for more details.
*/
#include "mirall/owncloudwizard.h"
#include "mirall/mirallconfigfile.h"
#include <QDebug>
#include <QDesktopServices>
@ -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<QPixmap>();
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<OwncloudSetupPage*>(page(Page_oCSetup));
#else
OwncloudWizardSelectTypePage *p = static_cast<OwncloudWizardSelectTypePage*>(page( Page_SelectType ));
p->setOCUrl( url );
#endif
if( p )
p->setOCUrl( url );
}
} // end namespace

View File

@ -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,