2011-09-27 21:10:01 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
2011-09-30 19:42:28 +04:00
|
|
|
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
2011-09-27 21:10:01 +04:00
|
|
|
*
|
|
|
|
* 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 <QDebug>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QValidator>
|
|
|
|
#include <QWizardPage>
|
|
|
|
#include <QDir>
|
2011-11-24 19:25:15 +04:00
|
|
|
#include <QScrollBar>
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "mirall/owncloudwizard.h"
|
|
|
|
|
|
|
|
namespace Mirall
|
|
|
|
{
|
|
|
|
|
|
|
|
OwncloudWizardSelectTypePage::OwncloudWizardSelectTypePage()
|
|
|
|
{
|
|
|
|
_ui.setupUi(this);
|
2011-09-28 20:14:48 +04:00
|
|
|
registerField( "connectMyOC", _ui.connectMyOCRadioBtn );
|
|
|
|
registerField( "createNewOC", _ui.createNewOCRadioBtn );
|
|
|
|
registerField( "OCUrl", _ui.OCUrlLineEdit );
|
2011-09-29 21:05:49 +04:00
|
|
|
|
|
|
|
connect( _ui.connectMyOCRadioBtn, SIGNAL(clicked()), SIGNAL(completeChanged()));
|
|
|
|
connect( _ui.createNewOCRadioBtn, SIGNAL(clicked()), SIGNAL(completeChanged()));
|
|
|
|
connect( _ui.OCUrlLineEdit, SIGNAL(textChanged(QString)), SIGNAL(completeChanged()));
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OwncloudWizardSelectTypePage::~OwncloudWizardSelectTypePage()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudWizardSelectTypePage::initializePage()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
int OwncloudWizardSelectTypePage::nextId() const
|
|
|
|
{
|
|
|
|
if( _ui.connectMyOCRadioBtn->isChecked() ) {
|
2011-09-30 14:51:56 +04:00
|
|
|
return OwncloudWizard::Page_OC_Credentials;
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
return OwncloudWizard::Page_Create_OC;
|
|
|
|
}
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
bool OwncloudWizardSelectTypePage::isComplete() const
|
|
|
|
{
|
2011-09-29 21:05:49 +04:00
|
|
|
if( _ui.connectMyOCRadioBtn->isChecked() ) {
|
|
|
|
// a valid url is needed.
|
|
|
|
QString u = _ui.OCUrlLineEdit->text();
|
|
|
|
QUrl url( u );
|
|
|
|
if( url.isValid() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-30 12:24:01 +04:00
|
|
|
void OwncloudWizardSelectTypePage::setOCUrl( const QString& url )
|
|
|
|
{
|
|
|
|
_ui.OCUrlLineEdit->setText( url );
|
|
|
|
}
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
// ======================================================================
|
|
|
|
|
|
|
|
|
2011-09-30 14:51:56 +04:00
|
|
|
OwncloudCredentialsPage::OwncloudCredentialsPage()
|
|
|
|
{
|
|
|
|
_ui.setupUi(this);
|
|
|
|
registerField( "OCUser", _ui.OCUserEdit );
|
|
|
|
registerField( "OCPasswd", _ui.OCPasswdEdit );
|
2011-11-02 17:44:53 +04:00
|
|
|
|
|
|
|
connect( _ui.OCPasswdEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged()));
|
2011-09-30 14:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OwncloudCredentialsPage::~OwncloudCredentialsPage()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OwncloudCredentialsPage::isComplete() const
|
|
|
|
{
|
2011-11-02 17:44:53 +04:00
|
|
|
return !(_ui.OCPasswdEdit->text().isEmpty() );
|
2011-09-30 14:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudCredentialsPage::initializePage()
|
|
|
|
{
|
|
|
|
QString user = getenv( "USER" );
|
|
|
|
_ui.OCUserEdit->setText( user );
|
|
|
|
}
|
|
|
|
|
|
|
|
int OwncloudCredentialsPage::nextId() const
|
|
|
|
{
|
|
|
|
return OwncloudWizard::Page_Install;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======================================================================
|
|
|
|
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
OwncloudFTPAccessPage::OwncloudFTPAccessPage()
|
|
|
|
{
|
|
|
|
_ui.setupUi(this);
|
2011-09-28 20:14:48 +04:00
|
|
|
registerField( "ftpUrl", _ui.ftpUrlEdit );
|
|
|
|
registerField( "ftpUser", _ui.ftpUserEdit );
|
|
|
|
registerField( "ftpPasswd", _ui.ftpPasswdEdit );
|
2011-09-29 18:36:27 +04:00
|
|
|
// registerField( "ftpDir", _ui.ftpDir );
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OwncloudFTPAccessPage::~OwncloudFTPAccessPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudFTPAccessPage::initializePage()
|
|
|
|
{
|
|
|
|
// _ui.lineEditOCAlias->setText( "Owncloud" );
|
|
|
|
}
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
void OwncloudFTPAccessPage::setFTPUrl( const QString& url )
|
|
|
|
{
|
|
|
|
_ui.ftpUrlEdit->setText( url );
|
|
|
|
}
|
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
int OwncloudFTPAccessPage::nextId() const
|
|
|
|
{
|
2011-10-14 20:13:34 +04:00
|
|
|
return OwncloudWizard::Page_OC_Credentials;
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
bool OwncloudFTPAccessPage::isComplete() const
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======================================================================
|
|
|
|
|
|
|
|
CreateAnOwncloudPage::CreateAnOwncloudPage()
|
|
|
|
{
|
|
|
|
_ui.setupUi(this);
|
2011-09-28 20:14:48 +04:00
|
|
|
registerField("createLocalOC", _ui.createLocalRadioBtn );
|
|
|
|
registerField("createOnDomain", _ui.createPerFTPRadioBtn );
|
|
|
|
registerField("myOCDomain", _ui.myDomainEdit );
|
2011-09-29 18:36:27 +04:00
|
|
|
|
|
|
|
connect( _ui.createLocalRadioBtn, SIGNAL(clicked()), SIGNAL(completeChanged()));
|
|
|
|
connect( _ui.createPerFTPRadioBtn, SIGNAL(clicked()), SIGNAL(completeChanged()));
|
|
|
|
connect( _ui.myDomainEdit, SIGNAL(textChanged(QString)), SIGNAL(completeChanged()));
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateAnOwncloudPage::~CreateAnOwncloudPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateAnOwncloudPage::initializePage()
|
|
|
|
{
|
|
|
|
// _ui.lineEditOCAlias->setText( "Owncloud" );
|
|
|
|
}
|
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
int CreateAnOwncloudPage::nextId() const
|
|
|
|
{
|
|
|
|
if( _ui.createLocalRadioBtn->isChecked() ) {
|
2011-09-30 14:51:56 +04:00
|
|
|
return OwncloudWizard::Page_OC_Credentials;
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
2011-09-29 18:36:27 +04:00
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
return OwncloudWizard::Page_FTP;
|
|
|
|
}
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
bool CreateAnOwncloudPage::isComplete() const
|
|
|
|
{
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
if( _ui.createPerFTPRadioBtn->isChecked() ) {
|
|
|
|
QString dom = _ui.myDomainEdit->text();
|
|
|
|
qDebug() << "check is Complete with " << dom;
|
|
|
|
return (!dom.isEmpty() && dom.contains( QChar('.'))
|
|
|
|
&& dom.lastIndexOf('.') < dom.length()-2 );
|
|
|
|
}
|
|
|
|
return true;
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
QString CreateAnOwncloudPage::domain() const
|
|
|
|
{
|
|
|
|
return _ui.myDomainEdit->text();
|
|
|
|
}
|
2011-09-27 21:10:01 +04:00
|
|
|
// ======================================================================
|
|
|
|
|
|
|
|
OwncloudWizardResultPage::OwncloudWizardResultPage()
|
|
|
|
{
|
|
|
|
_ui.setupUi(this);
|
2011-09-28 20:14:48 +04:00
|
|
|
// no fields to register.
|
2011-09-29 18:36:27 +04:00
|
|
|
_ui.resultTextEdit->setAcceptRichText(true);
|
2011-10-14 18:39:53 +04:00
|
|
|
_ui.ocLinkLabel->setVisible( false );
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OwncloudWizardResultPage::~OwncloudWizardResultPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudWizardResultPage::initializePage()
|
|
|
|
{
|
|
|
|
// _ui.lineEditOCAlias->setText( "Owncloud" );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OwncloudWizardResultPage::isComplete() const
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-24 19:25:15 +04:00
|
|
|
void OwncloudWizardResultPage::appendResultText( const QString& msg, OwncloudWizard::LogType type )
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
if( msg.isEmpty() ) {
|
|
|
|
_ui.resultTextEdit->clear();
|
|
|
|
} else {
|
2011-11-24 19:25:15 +04:00
|
|
|
if( type == OwncloudWizard::LogParagraph ) {
|
|
|
|
_ui.resultTextEdit->append( msg );
|
|
|
|
} else {
|
|
|
|
// _ui.resultTextEdit->append( msg );
|
|
|
|
_ui.resultTextEdit->insertPlainText(msg );
|
|
|
|
}
|
|
|
|
_ui.resultTextEdit->verticalScrollBar()->setValue( _ui.resultTextEdit->verticalScrollBar()->maximum() );
|
2011-09-29 18:36:27 +04:00
|
|
|
}
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-10-14 18:39:53 +04:00
|
|
|
void OwncloudWizardResultPage::showOCUrlLabel( const QString& url, bool show )
|
|
|
|
{
|
2011-11-02 17:44:53 +04:00
|
|
|
_ui.ocLinkLabel->setText( tr("Congratulations! Your <a href=\"%1\" title=\"%1\">new ownCloud</a> is now up and running!").arg(url) );
|
2011-10-14 18:39:53 +04:00
|
|
|
_ui.ocLinkLabel->setOpenExternalLinks( true );
|
|
|
|
|
|
|
|
if( show ) {
|
|
|
|
_ui.ocLinkLabel->setVisible( true );
|
|
|
|
} else {
|
|
|
|
_ui.ocLinkLabel->setVisible( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
// ======================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Folder wizard itself
|
|
|
|
*/
|
|
|
|
|
|
|
|
OwncloudWizard::OwncloudWizard(QWidget *parent)
|
|
|
|
: QWizard(parent)
|
|
|
|
{
|
2011-09-30 14:51:56 +04:00
|
|
|
setPage(Page_SelectType, new OwncloudWizardSelectTypePage() );
|
|
|
|
setPage(Page_Create_OC, new CreateAnOwncloudPage() );
|
|
|
|
setPage(Page_FTP, new OwncloudFTPAccessPage() );
|
|
|
|
setPage(Page_OC_Credentials, new OwncloudCredentialsPage() );
|
|
|
|
setPage(Page_Install, new OwncloudWizardResultPage() );
|
2011-09-28 20:14:48 +04:00
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
setWizardStyle( QWizard::ClassicStyle );
|
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int)));
|
|
|
|
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
void OwncloudWizard::slotCurrentPageChanged( int id )
|
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
qDebug() << "Current Wizard page changed to " << id;
|
|
|
|
qDebug() << "Page_install is " << Page_Install;
|
|
|
|
|
|
|
|
if( id == Page_FTP ) {
|
|
|
|
// preset the ftp url field
|
|
|
|
CreateAnOwncloudPage *p = static_cast<CreateAnOwncloudPage*> (page( Page_Create_OC ));
|
|
|
|
QString domain = p->domain();
|
|
|
|
if( domain.startsWith( "http://" )) {
|
|
|
|
domain = domain.right( domain.length()-7 );
|
|
|
|
}
|
|
|
|
if( domain.startsWith( "https://" )) {
|
|
|
|
domain = domain.right( domain.length()-8 );
|
|
|
|
}
|
2011-10-14 18:39:53 +04:00
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
QString host = "ftp." +domain;
|
|
|
|
OwncloudFTPAccessPage *p1 = static_cast<OwncloudFTPAccessPage*> (page( Page_FTP ));
|
|
|
|
p1->setFTPUrl( host );
|
|
|
|
}
|
2011-09-28 20:14:48 +04:00
|
|
|
if( id == Page_Install ) {
|
2011-09-29 18:36:27 +04:00
|
|
|
appendToResultWidget( QString() );
|
2011-10-14 18:39:53 +04:00
|
|
|
showOCUrlLabel( false );
|
2011-09-28 20:14:48 +04:00
|
|
|
if( field("connectMyOC").toBool() ) {
|
|
|
|
// check the url and connect.
|
2012-02-17 15:16:48 +04:00
|
|
|
_oCUrl = field("OCUrl").toString();
|
|
|
|
emit connectToOCUrl( _oCUrl);
|
2011-09-29 18:36:27 +04:00
|
|
|
} else if( field("createLocalOC").toBool() ) {
|
|
|
|
qDebug() << "Connect to local!";
|
|
|
|
emit installOCLocalhost();
|
2011-09-28 20:14:48 +04:00
|
|
|
} else if( field("createNewOC").toBool() ) {
|
|
|
|
// call in installation mode and install to ftp site.
|
|
|
|
emit installOCServer();
|
2011-09-29 18:36:27 +04:00
|
|
|
} else {
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 18:39:53 +04:00
|
|
|
void OwncloudWizard::showOCUrlLabel( bool show )
|
|
|
|
{
|
|
|
|
OwncloudWizardResultPage *p = static_cast<OwncloudWizardResultPage*> (page( Page_Install ));
|
|
|
|
p->showOCUrlLabel( _oCUrl, show );
|
|
|
|
}
|
|
|
|
|
2011-11-24 19:25:15 +04:00
|
|
|
void OwncloudWizard::appendToResultWidget( const QString& msg, LogType type )
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
|
|
|
OwncloudWizardResultPage *p = static_cast<OwncloudWizardResultPage*> (page( Page_Install ));
|
2011-11-24 19:25:15 +04:00
|
|
|
p->appendResultText( msg, type );
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
2011-09-29 18:36:27 +04:00
|
|
|
|
2011-09-30 12:24:01 +04:00
|
|
|
void OwncloudWizard::setOCUrl( const QString& url )
|
|
|
|
{
|
2011-10-14 18:39:53 +04:00
|
|
|
_oCUrl = url;
|
|
|
|
OwncloudWizardSelectTypePage *p = static_cast<OwncloudWizardSelectTypePage*>(page( Page_SelectType ));
|
|
|
|
p->setOCUrl( url );
|
2011-09-30 12:24:01 +04:00
|
|
|
}
|
2011-09-27 21:10:01 +04:00
|
|
|
|
2011-09-30 12:24:01 +04:00
|
|
|
} // end namespace
|