2011-09-30 19:42:28 +04:00
/*
2013-07-30 12:48:26 +04:00
* Copyright ( C ) by Klaas Freitag < freitag @ owncloud . com >
2013-07-22 16:54:14 +04:00
* Copyright ( C ) by Krzesimir Nowak < krzesimir @ endocode . com >
2011-09-30 19:42:28 +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 .
*/
2013-07-22 16:54:14 +04:00
# include <QAbstractButton>
2013-04-28 00:24:32 +04:00
# include <QtCore>
# include <QProcess>
# include <QMessageBox>
# include <QDesktopServices>
2013-07-30 13:19:22 +04:00
# include "wizard/owncloudwizardcommon.h"
# include "wizard/owncloudwizard.h"
2014-07-11 02:31:24 +04:00
# include "owncloudsetupwizard.h"
2014-11-10 01:25:57 +03:00
# include "configfile.h"
2014-07-11 02:31:24 +04:00
# include "folderman.h"
# include "utility.h"
2014-11-10 01:25:57 +03:00
# include "accessmanager.h"
2014-07-11 02:31:24 +04:00
# include "account.h"
# include "networkjobs.h"
# include "sslerrordialog.h"
2013-10-23 16:48:44 +04:00
2013-10-28 23:01:59 +04:00
# include "creds/credentialsfactory.h"
2013-07-30 13:19:22 +04:00
# include "creds/abstractcredentials.h"
# include "creds/dummycredentials.h"
2011-09-28 20:14:48 +04:00
2014-11-10 00:34:07 +03:00
namespace OCC {
2011-09-28 20:14:48 +04:00
2013-07-31 17:46:41 +04:00
OwncloudSetupWizard : : OwncloudSetupWizard ( QObject * parent ) :
2012-02-17 18:54:39 +04:00
QObject ( parent ) ,
2013-07-31 17:46:41 +04:00
_ocWizard ( new OwncloudWizard ) ,
_remoteFolder ( )
2011-09-28 20:14:48 +04:00
{
2013-07-22 16:54:14 +04:00
connect ( _ocWizard , SIGNAL ( determineAuthType ( const QString & ) ) ,
2013-07-29 16:28:19 +04:00
this , SLOT ( slotDetermineAuthType ( const QString & ) ) ) ;
2013-07-31 17:46:41 +04:00
connect ( _ocWizard , SIGNAL ( connectToOCUrl ( const QString & ) ) ,
this , SLOT ( slotConnectToOCUrl ( const QString & ) ) ) ;
connect ( _ocWizard , SIGNAL ( createLocalAndRemoteFolders ( QString , QString ) ) ,
this , SLOT ( slotCreateLocalAndRemoteFolders ( QString , QString ) ) ) ;
2013-08-19 14:43:52 +04:00
/* basicSetupFinished might be called from a reply from the network.
slotAssistantFinished might destroy the temporary QNetworkAccessManager .
Therefore Qt : : QueuedConnection is required */
2013-08-18 17:16:22 +04:00
connect ( _ocWizard , SIGNAL ( basicSetupFinished ( int ) ) ,
2013-08-19 14:43:52 +04:00
this , SLOT ( slotAssistantFinished ( int ) ) , Qt : : QueuedConnection ) ;
2013-12-05 19:00:27 +04:00
connect ( _ocWizard , SIGNAL ( finished ( int ) ) , SLOT ( deleteLater ( ) ) ) ;
2014-12-18 15:18:24 +03:00
connect ( _ocWizard , SIGNAL ( skipFolderConfiguration ( ) ) , SLOT ( slotSkipFolderConfiguration ( ) ) ) ;
2012-04-12 13:37:48 +04:00
}
OwncloudSetupWizard : : ~ OwncloudSetupWizard ( )
{
2013-05-29 03:20:43 +04:00
_ocWizard - > deleteLater ( ) ;
2013-04-28 00:24:32 +04:00
}
2012-07-26 12:16:18 +04:00
2013-07-22 15:59:52 +04:00
void OwncloudSetupWizard : : runWizard ( QObject * obj , const char * amember , QWidget * parent )
2013-07-04 21:59:40 +04:00
{
2013-09-19 13:51:02 +04:00
static QPointer < OwncloudSetupWizard > wiz ;
if ( ! wiz . isNull ( ) ) {
return ;
}
wiz = new OwncloudSetupWizard ( parent ) ;
2013-07-04 21:59:40 +04:00
connect ( wiz , SIGNAL ( ownCloudWizardDone ( int ) ) , obj , amember ) ;
2013-07-22 15:59:52 +04:00
FolderMan : : instance ( ) - > setSyncEnabled ( false ) ;
2013-07-04 21:59:40 +04:00
wiz - > startWizard ( ) ;
}
2013-03-02 00:30:22 +04:00
void OwncloudSetupWizard : : startWizard ( )
{
2013-11-26 03:00:27 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
bool multiFolderSetup = folderMan - > map ( ) . count ( ) > 1 ;
2013-10-30 19:31:47 +04:00
// ###
2014-12-18 14:09:48 +03:00
AccountPtr account = Account : : restore ( ) ;
2013-10-28 23:01:59 +04:00
if ( ! account ) {
2013-11-07 13:14:12 +04:00
_ocWizard - > setConfigExists ( false ) ;
2014-12-18 14:09:48 +03:00
account = Account : : create ( ) ;
2013-10-28 23:01:59 +04:00
account - > setCredentials ( CredentialsFactory : : create ( " dummy " ) ) ;
2013-11-07 13:14:12 +04:00
} else {
_ocWizard - > setConfigExists ( true ) ;
2013-05-26 16:04:11 +04:00
}
2013-11-07 13:14:12 +04:00
account - > setSslErrorHandler ( new SslDialogErrorHandler ) ;
2013-10-28 23:01:59 +04:00
_ocWizard - > setAccount ( account ) ;
2013-11-04 19:36:23 +04:00
_ocWizard - > setOCUrl ( account - > url ( ) . toString ( ) ) ;
2013-05-26 16:04:11 +04:00
2013-04-28 00:24:32 +04:00
_remoteFolder = Theme : : instance ( ) - > defaultServerFolder ( ) ;
// remoteFolder may be empty, which means /
2013-05-23 03:51:05 +04:00
QString localFolder = Theme : : instance ( ) - > defaultClientFolder ( ) ;
2013-04-28 00:24:32 +04:00
// if its a relative path, prepend with users home dir, otherwise use as absolute path
2013-11-26 03:00:27 +04:00
2013-07-31 17:46:41 +04:00
if ( ! QDir ( localFolder ) . isAbsolute ( ) ) {
localFolder = QDir : : homePath ( ) + QDir : : separator ( ) + localFolder ;
2013-04-28 00:24:32 +04:00
}
2013-11-26 03:00:27 +04:00
if ( ! multiFolderSetup ) {
QList < Folder * > folders = folderMan - > map ( ) . values ( ) ;
if ( ! folders . isEmpty ( ) ) {
Folder * folder = folders . first ( ) ;
localFolder = QDir ( folder - > path ( ) ) . absolutePath ( ) ;
}
}
2014-11-05 14:10:41 +03:00
_ocWizard - > setProperty ( " oldLocalFolder " , localFolder ) ;
2013-05-23 03:51:05 +04:00
_ocWizard - > setProperty ( " localFolder " , localFolder ) ;
2014-07-08 20:32:43 +04:00
// remember the local folder to compare later if it changed, but clean first
QString lf = QDir : : fromNativeSeparators ( localFolder ) ;
if ( ! lf . endsWith ( QLatin1Char ( ' / ' ) ) ) {
lf . append ( QLatin1Char ( ' / ' ) ) ;
}
_initLocalFolder = lf ;
2013-05-23 03:51:05 +04:00
_ocWizard - > setRemoteFolder ( _remoteFolder ) ;
2013-03-02 00:30:22 +04:00
2013-07-31 17:46:41 +04:00
_ocWizard - > setStartId ( WizardCommon : : Page_ServerSetup ) ;
2013-03-02 00:30:22 +04:00
_ocWizard - > restart ( ) ;
2013-05-28 22:25:31 +04:00
// settings re-initialized in initPage must be set here after restart
2013-11-26 03:00:27 +04:00
_ocWizard - > setMultipleFoldersExist ( multiFolderSetup ) ;
2013-05-28 22:25:31 +04:00
2013-07-04 21:59:40 +04:00
_ocWizard - > open ( ) ;
2013-06-24 17:15:46 +04:00
_ocWizard - > raise ( ) ;
2013-03-02 00:30:22 +04:00
}
2013-10-28 23:01:59 +04:00
// also checks if an installation is valid and determines auth type in a second step
void OwncloudSetupWizard : : slotDetermineAuthType ( const QString & urlString )
2012-06-12 14:30:05 +04:00
{
2013-10-28 23:01:59 +04:00
QString fixedUrl = urlString ;
QUrl url = QUrl : : fromUserInput ( fixedUrl ) ;
// fromUserInput defaults to http, not http if no scheme is specified
2013-10-30 19:31:47 +04:00
if ( ! fixedUrl . startsWith ( " http:// " ) & & ! fixedUrl . startsWith ( " https:// " ) ) {
2013-10-28 23:01:59 +04:00
url . setScheme ( " https " ) ;
2013-07-31 17:46:41 +04:00
}
2014-12-18 14:09:48 +03:00
AccountPtr account = _ocWizard - > account ( ) ;
2013-10-28 23:01:59 +04:00
account - > setUrl ( url ) ;
2014-12-03 16:59:53 +03:00
// Set fake credentials beforfe we check what credential it actually is.
2014-07-23 16:38:50 +04:00
account - > setCredentials ( CredentialsFactory : : create ( " dummy " ) ) ;
2014-12-16 13:27:02 +03:00
CheckServerJob * job = new CheckServerJob ( _ocWizard - > account ( ) , this ) ;
2013-11-25 18:50:19 +04:00
job - > setIgnoreCredentialFailure ( true ) ;
2013-10-28 23:01:59 +04:00
connect ( job , SIGNAL ( instanceFound ( QUrl , QVariantMap ) ) , SLOT ( slotOwnCloudFoundAuth ( QUrl , QVariantMap ) ) ) ;
2014-04-14 17:10:08 +04:00
connect ( job , SIGNAL ( instanceNotFound ( QNetworkReply * ) ) , SLOT ( slotNoOwnCloudFoundAuth ( QNetworkReply * ) ) ) ;
2013-11-14 20:02:41 +04:00
connect ( job , SIGNAL ( timeout ( const QUrl & ) ) , SLOT ( slotNoOwnCloudFoundAuthTimeout ( const QUrl & ) ) ) ;
job - > setTimeout ( 10 * 1000 ) ;
2013-11-14 22:20:09 +04:00
job - > start ( ) ;
2013-07-31 17:46:41 +04:00
}
2013-05-26 16:04:11 +04:00
2013-10-28 23:01:59 +04:00
void OwncloudSetupWizard : : slotOwnCloudFoundAuth ( const QUrl & url , const QVariantMap & info )
2013-07-31 17:46:41 +04:00
{
_ocWizard - > appendToConfigurationLog ( tr ( " <font color= \" green \" >Successfully connected to %1: %2 version %3 (%4)</font><br/><br/> " )
2013-10-28 23:01:59 +04:00
. arg ( url . toString ( ) )
. arg ( Theme : : instance ( ) - > appNameGUI ( ) )
. arg ( CheckServerJob : : versionString ( info ) )
. arg ( CheckServerJob : : version ( info ) ) ) ;
2013-07-31 17:46:41 +04:00
2014-04-17 12:01:26 +04:00
QString p = url . path ( ) ;
if ( p . endsWith ( " /status.php " ) ) {
2013-11-14 20:54:38 +04:00
// We might be redirected, update the account
QUrl redirectedUrl = url ;
redirectedUrl . setPath ( url . path ( ) . left ( url . path ( ) . length ( ) - 11 ) ) ;
_ocWizard - > account ( ) - > setUrl ( redirectedUrl ) ;
qDebug ( ) < < Q_FUNC_INFO < < " was redirected to " < < redirectedUrl . toString ( ) ;
}
2013-10-28 23:01:59 +04:00
DetermineAuthTypeJob * job = new DetermineAuthTypeJob ( _ocWizard - > account ( ) , this ) ;
2013-11-25 18:50:19 +04:00
job - > setIgnoreCredentialFailure ( true ) ;
2013-10-28 23:01:59 +04:00
connect ( job , SIGNAL ( authType ( WizardCommon : : AuthType ) ) ,
_ocWizard , SLOT ( setAuthType ( WizardCommon : : AuthType ) ) ) ;
2013-11-14 22:20:09 +04:00
job - > start ( ) ;
2013-07-31 17:46:41 +04:00
}
2012-06-12 14:30:05 +04:00
2013-10-28 23:01:59 +04:00
void OwncloudSetupWizard : : slotNoOwnCloudFoundAuth ( QNetworkReply * reply )
2013-07-31 17:46:41 +04:00
{
2013-10-28 23:01:59 +04:00
_ocWizard - > displayError ( tr ( " Failed to connect to %1 at %2:<br/>%3 " )
2014-12-02 12:19:55 +03:00
. arg ( Theme : : instance ( ) - > appNameGUI ( ) ,
reply - > url ( ) . toString ( ) ,
2014-12-17 21:14:42 +03:00
reply - > errorString ( ) ) , checkDowngradeAdvised ( reply ) ) ;
2012-06-12 14:30:05 +04:00
}
2013-11-14 20:02:41 +04:00
void OwncloudSetupWizard : : slotNoOwnCloudFoundAuthTimeout ( const QUrl & url )
{
2014-12-17 21:14:42 +03:00
_ocWizard - > displayError ( tr ( " Timeout while trying to connect to %1 at %2. " )
2014-12-02 12:19:55 +03:00
. arg ( Theme : : instance ( ) - > appNameGUI ( ) ,
2014-12-17 21:14:42 +03:00
url . toString ( ) ) , false ) ;
2013-11-14 20:02:41 +04:00
}
2012-02-17 14:11:18 +04:00
void OwncloudSetupWizard : : slotConnectToOCUrl ( const QString & url )
2011-09-28 20:14:48 +04:00
{
2013-10-30 19:31:47 +04:00
qDebug ( ) < < " Connect to url: " < < url ;
2014-05-15 11:45:26 +04:00
AbstractCredentials * creds = _ocWizard - > getCredentials ( ) ;
_ocWizard - > account ( ) - > setCredentials ( creds ) ;
2013-10-30 19:31:47 +04:00
_ocWizard - > setField ( QLatin1String ( " OCUrl " ) , url ) ;
_ocWizard - > appendToConfigurationLog ( tr ( " Trying to connect to %1 at %2... " )
. arg ( Theme : : instance ( ) - > appNameGUI ( ) ) . arg ( url ) ) ;
2013-10-28 23:01:59 +04:00
2013-10-30 19:31:47 +04:00
testOwnCloudConnect ( ) ;
2012-02-17 18:54:39 +04:00
}
void OwncloudSetupWizard : : testOwnCloudConnect ( )
{
2014-12-18 14:09:48 +03:00
AccountPtr account = _ocWizard - > account ( ) ;
2014-05-15 11:45:26 +04:00
ValidateDavAuthJob * job = new ValidateDavAuthJob ( account , this ) ;
2013-11-25 18:50:19 +04:00
job - > setIgnoreCredentialFailure ( true ) ;
2013-10-28 23:01:59 +04:00
connect ( job , SIGNAL ( authResult ( QNetworkReply * ) ) , SLOT ( slotConnectionCheck ( QNetworkReply * ) ) ) ;
2013-11-14 22:20:09 +04:00
job - > start ( ) ;
2012-02-17 18:54:39 +04:00
}
2014-12-17 21:14:42 +03:00
bool OwncloudSetupWizard : : checkDowngradeAdvised ( QNetworkReply * reply )
{
2015-01-21 17:07:24 +03:00
if ( reply - > url ( ) . scheme ( ) ! = QLatin1String ( " https " ) ) {
2015-01-07 20:22:44 +03:00
return false ;
}
2014-12-17 21:14:42 +03:00
switch ( reply - > error ( ) ) {
case QNetworkReply : : NoError :
case QNetworkReply : : ContentNotFoundError :
2015-01-21 17:07:24 +03:00
case QNetworkReply : : AuthenticationRequiredError :
2014-12-17 21:14:42 +03:00
case QNetworkReply : : HostNotFoundError :
2015-01-07 20:22:44 +03:00
return false ;
2014-12-17 21:14:42 +03:00
default :
2015-01-08 11:42:26 +03:00
break ;
2014-12-17 21:14:42 +03:00
}
2015-01-07 20:22:44 +03:00
// Adhere to HSTS, even though we do not parse it properly
if ( reply - > hasRawHeader ( " Strict-Transport-Security " ) ) {
return false ;
}
return true ;
2014-12-17 21:14:42 +03:00
}
2013-10-28 23:01:59 +04:00
void OwncloudSetupWizard : : slotConnectionCheck ( QNetworkReply * reply )
2013-07-31 17:46:41 +04:00
{
2015-01-28 13:06:02 +03:00
QString msg = reply - > errorString ( ) ;
2013-07-31 17:46:41 +04:00
switch ( reply - > error ( ) ) {
case QNetworkReply : : NoError :
case QNetworkReply : : ContentNotFoundError :
_ocWizard - > successfulStep ( ) ;
break ;
default :
2015-01-28 13:06:02 +03:00
if ( reply - > attribute ( QNetworkRequest : : HttpStatusCodeAttribute ) . toInt ( ) = = 403 ) {
msg = tr ( " Access forbidden by server. To verify that you have proper access, "
" <a href= \" %1 \" >click here</a> to access the service with your browser. " )
. arg ( _ocWizard - > account ( ) - > url ( ) . toString ( ) ) ;
}
2015-01-07 20:22:44 +03:00
_ocWizard - > show ( ) ;
2015-01-21 17:07:24 +03:00
if ( _ocWizard - > currentId ( ) = = WizardCommon : : Page_ShibbolethCreds ) {
_ocWizard - > back ( ) ;
}
2015-01-28 13:06:02 +03:00
_ocWizard - > displayError ( msg , _ocWizard - > currentId ( ) = = WizardCommon : : Page_ServerSetup & & checkDowngradeAdvised ( reply ) ) ;
2013-07-31 17:46:41 +04:00
break ;
}
}
void OwncloudSetupWizard : : slotCreateLocalAndRemoteFolders ( const QString & localFolder , const QString & remoteFolder )
2011-09-30 16:19:26 +04:00
{
2013-05-23 03:51:05 +04:00
qDebug ( ) < < " Setup local sync folder for new oC connection " < < localFolder ;
2013-07-31 17:46:41 +04:00
const QDir fi ( localFolder ) ;
2013-10-30 19:31:47 +04:00
bool nextStep = true ;
2012-03-14 14:26:00 +04:00
if ( fi . exists ( ) ) {
// there is an existing local folder. If its non empty, it can only be synced if the
// ownCloud is newly created.
2013-05-23 03:51:05 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " Local sync folder %1 already exists, setting it up for sync.<br/><br/> " ) . arg ( localFolder ) ) ;
2011-10-05 14:11:10 +04:00
} else {
2015-02-06 00:00:13 +03:00
QString res = tr ( " Creating local sync folder %1... " ) . arg ( localFolder ) ;
2013-05-23 03:51:05 +04:00
if ( fi . mkpath ( localFolder ) ) {
Utility : : setupFavLink ( localFolder ) ;
2012-03-14 14:26:00 +04:00
// FIXME: Create a local sync folder.
res + = tr ( " ok " ) ;
} else {
res + = tr ( " failed. " ) ;
qDebug ( ) < < " Failed to create " < < fi . path ( ) ;
2014-12-17 21:14:42 +03:00
_ocWizard - > displayError ( tr ( " Could not create local folder %1 " ) . arg ( localFolder ) , false ) ;
2013-10-30 19:31:47 +04:00
nextStep = false ;
2012-03-14 14:26:00 +04:00
}
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( res ) ;
2012-03-14 14:26:00 +04:00
}
2013-10-30 19:31:47 +04:00
if ( nextStep ) {
2015-02-05 14:48:23 +03:00
EntityExistsJob * job = new EntityExistsJob ( _ocWizard - > account ( ) , _ocWizard - > account ( ) - > davPath ( ) + remoteFolder , this ) ;
2013-10-30 19:31:47 +04:00
connect ( job , SIGNAL ( exists ( QNetworkReply * ) ) , SLOT ( slotAuthCheckReply ( QNetworkReply * ) ) ) ;
2013-11-14 22:20:09 +04:00
job - > start ( ) ;
2013-10-30 19:31:47 +04:00
} else {
finalizeSetup ( false ) ;
}
2012-12-04 20:27:59 +04:00
}
2012-03-14 14:26:00 +04:00
2013-10-28 23:01:59 +04:00
// ### TODO move into EntityExistsJob once we decide if/how to return gui strings from jobs
void OwncloudSetupWizard : : slotAuthCheckReply ( QNetworkReply * reply )
2013-04-28 00:24:32 +04:00
{
bool ok = true ;
QString error ;
QNetworkReply : : NetworkError errId = reply - > error ( ) ;
if ( errId = = QNetworkReply : : NoError ) {
qDebug ( ) < < " ******** Remote folder found, all cool! " ;
} else if ( errId = = QNetworkReply : : ContentNotFoundError ) {
2013-10-28 23:01:59 +04:00
if ( _remoteFolder . isEmpty ( ) ) {
error = tr ( " No remote folder specified! " ) ;
2013-04-28 00:24:32 +04:00
ok = false ;
2013-10-28 23:01:59 +04:00
} else {
createRemoteFolder ( ) ;
2013-04-28 00:24:32 +04:00
}
} else {
error = tr ( " Error: %1 " ) . arg ( reply - > errorString ( ) ) ;
ok = false ;
2012-12-09 01:56:48 +04:00
}
2013-04-28 00:24:32 +04:00
if ( ! ok ) {
2014-12-17 21:14:42 +03:00
_ocWizard - > displayError ( error , false ) ;
2011-10-05 14:11:10 +04:00
}
2013-04-28 00:24:32 +04:00
finalizeSetup ( ok ) ;
2011-10-05 14:11:10 +04:00
}
2013-10-28 23:01:59 +04:00
void OwncloudSetupWizard : : createRemoteFolder ( )
2011-10-05 14:11:10 +04:00
{
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " creating folder on ownCloud: %1 " ) . arg ( _remoteFolder ) ) ;
2012-04-18 13:59:56 +04:00
2013-10-28 23:01:59 +04:00
MkColJob * job = new MkColJob ( _ocWizard - > account ( ) , _remoteFolder , this ) ;
connect ( job , SIGNAL ( finished ( QNetworkReply : : NetworkError ) ) , SLOT ( slotCreateRemoteFolderFinished ( QNetworkReply : : NetworkError ) ) ) ;
2013-11-14 22:20:09 +04:00
job - > start ( ) ;
2011-10-05 14:11:10 +04:00
}
2012-04-21 01:58:09 +04:00
void OwncloudSetupWizard : : slotCreateRemoteFolderFinished ( QNetworkReply : : NetworkError error )
2012-03-14 14:26:00 +04:00
{
2012-04-21 01:58:09 +04:00
qDebug ( ) < < " ** webdav mkdir request finished " < < error ;
2013-10-30 19:31:47 +04:00
// disconnect(ownCloudInfo::instance(), SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),
// this, SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));
2013-04-28 00:24:32 +04:00
2012-08-06 18:43:24 +04:00
bool success = true ;
2012-03-14 14:26:00 +04:00
2012-04-21 01:58:09 +04:00
if ( error = = QNetworkReply : : NoError ) {
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " Remote folder %1 created successfully. " ) . arg ( _remoteFolder ) ) ;
2012-04-21 01:58:09 +04:00
} else if ( error = = 202 ) {
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " The remote folder %1 already exists. Connecting it for syncing. " ) . arg ( _remoteFolder ) ) ;
2012-08-06 18:43:24 +04:00
} else if ( error > 202 & & error < 300 ) {
2014-12-17 21:14:42 +03:00
_ocWizard - > displayError ( tr ( " The folder creation resulted in HTTP error code %1 " ) . arg ( ( int ) error ) , false ) ;
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " The folder creation resulted in HTTP error code %1 " ) . arg ( ( int ) error ) ) ;
2012-04-21 01:58:09 +04:00
} else if ( error = = QNetworkReply : : OperationCanceledError ) {
2013-04-28 00:24:32 +04:00
_ocWizard - > displayError ( tr ( " The remote folder creation failed because the provided credentials "
" are wrong! "
2014-12-17 21:14:42 +03:00
" <br/>Please go back and check your credentials.</p> " ) , false ) ;
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " <p><font color= \" red \" >Remote folder creation failed probably because the provided credentials are wrong.</font> "
2013-10-30 19:31:47 +04:00
" <br/>Please go back and check your credentials.</p> " ) ) ;
2012-06-12 14:30:05 +04:00
_remoteFolder . clear ( ) ;
2012-08-06 18:43:24 +04:00
success = false ;
2012-03-14 14:26:00 +04:00
} else {
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " Remote folder %1 creation failed with error <tt>%2</tt>. " ) . arg ( _remoteFolder ) . arg ( error ) ) ;
2014-12-17 21:14:42 +03:00
_ocWizard - > displayError ( tr ( " Remote folder %1 creation failed with error <tt>%2</tt>. " ) . arg ( _remoteFolder ) . arg ( error ) , false ) ;
2012-06-12 14:30:05 +04:00
_remoteFolder . clear ( ) ;
2012-08-06 18:43:24 +04:00
success = false ;
2012-06-12 14:30:05 +04:00
}
2012-08-06 18:43:24 +04:00
finalizeSetup ( success ) ;
2012-06-12 14:30:05 +04:00
}
void OwncloudSetupWizard : : finalizeSetup ( bool success )
{
2013-02-06 13:21:50 +04:00
// enable/disable the finish button.
_ocWizard - > enableFinishOnResultWidget ( success ) ;
2013-05-23 03:51:05 +04:00
const QString localFolder = _ocWizard - > property ( " localFolder " ) . toString ( ) ;
2012-06-12 14:30:05 +04:00
if ( success ) {
2013-05-23 03:51:05 +04:00
if ( ! ( localFolder . isEmpty ( ) | | _remoteFolder . isEmpty ( ) ) ) {
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " A sync connection from %1 to remote directory %2 was set up. " )
2013-10-30 19:31:47 +04:00
. arg ( localFolder ) . arg ( _remoteFolder ) ) ;
2012-06-12 14:30:05 +04:00
}
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( QLatin1String ( " " ) ) ;
_ocWizard - > appendToConfigurationLog ( QLatin1String ( " <p><font color= \" green \" ><b> " )
2013-10-30 19:31:47 +04:00
+ tr ( " Successfully connected to %1! " )
. arg ( Theme : : instance ( ) - > appNameGUI ( ) )
+ QLatin1String ( " </b></font></p> " ) ) ;
2013-07-31 17:46:41 +04:00
_ocWizard - > successfulStep ( ) ;
2012-06-12 14:30:05 +04:00
} else {
2013-10-30 19:31:47 +04:00
// ### this is not quite true, pass in the real problem as optional parameter
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( QLatin1String ( " <p><font color= \" red \" > " )
2013-10-30 19:31:47 +04:00
+ tr ( " Connection to %1 could not be established. Please check again. " )
. arg ( Theme : : instance ( ) - > appNameGUI ( ) )
+ QLatin1String ( " </font></p> " ) ) ;
}
}
bool OwncloudSetupWizard : : ensureStartFromScratch ( const QString & localFolder ) {
// first try to rename (backup) the current local dir.
bool renameOk = false ;
while ( ! renameOk ) {
renameOk = FolderMan : : instance ( ) - > startFromScratch ( localFolder ) ;
if ( ! renameOk ) {
QMessageBox : : StandardButton but ;
but = QMessageBox : : question ( 0 , tr ( " Folder rename failed " ) ,
tr ( " Can't remove and back up the folder because the folder or a file in it is open in another program. "
2014-04-20 16:54:40 +04:00
" Please close the folder or file and hit retry or cancel the setup. " ) , QMessageBox : : Retry | QMessageBox : : Abort , QMessageBox : : Retry ) ;
2013-10-30 19:31:47 +04:00
if ( but = = QMessageBox : : Abort ) {
break ;
}
}
}
return renameOk ;
}
2014-12-18 14:09:48 +03:00
void OwncloudSetupWizard : : replaceDefaultAccountWith ( AccountPtr newAccount )
2013-10-30 19:31:47 +04:00
{
// new Account
AccountManager * mgr = AccountManager : : instance ( ) ;
mgr - > setAccount ( newAccount ) ;
2013-11-04 19:36:23 +04:00
newAccount - > save ( ) ;
2012-03-14 14:26:00 +04:00
}
2011-09-30 16:19:26 +04:00
2013-12-05 19:00:27 +04:00
// Method executed when the user ends has finished the basic setup.
2013-07-31 17:46:41 +04:00
void OwncloudSetupWizard : : slotAssistantFinished ( int result )
2013-07-22 16:54:14 +04:00
{
2013-07-31 17:46:41 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
if ( result = = QDialog : : Rejected ) {
qDebug ( ) < < " Rejected the new config, use the old! " ;
2014-12-18 15:18:24 +03:00
2013-07-31 17:46:41 +04:00
} else if ( result = = QDialog : : Accepted ) {
2014-12-18 15:18:24 +03:00
// This may or may not wipe all folder definitions, depending
// on whether a new account is activated or the existing one
// is changed.
applyAccountChanges ( ) ;
// But if the user went through with the folder config wizard,
// we assume they always want to have only that folder configured.
folderMan - > removeAllFolderDefinitions ( ) ;
2014-07-08 20:32:43 +04:00
QString localFolder = QDir : : fromNativeSeparators ( _ocWizard - > localFolder ( ) ) ;
if ( ! localFolder . endsWith ( QLatin1Char ( ' / ' ) ) ) {
localFolder . append ( QLatin1Char ( ' / ' ) ) ;
}
2013-07-22 16:54:14 +04:00
2013-10-30 19:31:47 +04:00
bool startFromScratch = _ocWizard - > field ( " OCSyncFromScratch " ) . toBool ( ) ;
2014-12-18 15:18:24 +03:00
if ( ! startFromScratch | | ensureStartFromScratch ( localFolder ) ) {
qDebug ( ) < < " Adding folder definition for " < < localFolder < < _remoteFolder ;
2013-10-30 19:31:47 +04:00
folderMan - > addFolderDefinition ( Theme : : instance ( ) - > appName ( ) ,
2015-01-16 12:17:19 +03:00
localFolder , _remoteFolder , _ocWizard - > selectiveSyncBlacklist ( ) ) ;
2014-12-18 15:18:24 +03:00
_ocWizard - > appendToConfigurationLog ( tr ( " <font color= \" green \" ><b>Local sync folder %1 successfully created!</b></font> " ) . arg ( localFolder ) ) ;
2013-08-15 18:35:03 +04:00
}
2013-07-22 16:54:14 +04:00
}
2013-07-31 17:46:41 +04:00
// notify others.
emit ownCloudWizardDone ( result ) ;
2013-07-22 16:54:14 +04:00
}
2014-12-18 15:18:24 +03:00
void OwncloudSetupWizard : : slotSkipFolderConfiguration ( )
2014-08-12 19:33:17 +04:00
{
2014-12-18 15:18:24 +03:00
applyAccountChanges ( ) ;
disconnect ( _ocWizard , SIGNAL ( basicSetupFinished ( int ) ) ,
this , SLOT ( slotAssistantFinished ( int ) ) ) ;
2014-08-12 19:33:17 +04:00
_ocWizard - > close ( ) ;
emit ownCloudWizardDone ( QDialog : : Accepted ) ;
}
2014-12-18 15:18:24 +03:00
void OwncloudSetupWizard : : applyAccountChanges ( )
{
AccountPtr newAccount = _ocWizard - > account ( ) ;
AccountPtr origAccount = AccountManager : : instance ( ) - > account ( ) ;
bool isInitialSetup = ( origAccount = = 0 ) ;
// check if either the account changed in a major way
bool reinitRequired =
newAccount - > changed ( origAccount , true /* ignoreProtocol, allows http->https */ ) ;
// If this is a completely new account, replace it entirely
// thereby clearing all folder definitions.
if ( isInitialSetup | | reinitRequired ) {
replaceDefaultAccountWith ( newAccount ) ;
qDebug ( ) < < " Significant changes or first setup: switched to new account " ;
}
// Otherwise, set only URL and credentials
else {
origAccount - > setUrl ( newAccount - > url ( ) ) ;
origAccount - > setCredentials ( _ocWizard - > getCredentials ( ) ) ;
qDebug ( ) < < " Only password or schema was changed, adjusted existing account " ;
}
}
2014-08-12 19:33:17 +04:00
2014-12-18 14:09:48 +03:00
DetermineAuthTypeJob : : DetermineAuthTypeJob ( AccountPtr account , QObject * parent )
2013-10-28 23:01:59 +04:00
: AbstractNetworkJob ( account , QString ( ) , parent )
, _redirects ( 0 )
2013-11-14 22:20:09 +04:00
{
}
void DetermineAuthTypeJob : : start ( )
2013-07-31 17:46:41 +04:00
{
2014-03-22 12:41:32 +04:00
QNetworkReply * reply = getRequest ( account ( ) - > davPath ( ) ) ;
2013-10-28 23:01:59 +04:00
setReply ( reply ) ;
setupConnections ( reply ) ;
2013-11-22 17:01:11 +04:00
AbstractNetworkJob : : start ( ) ;
2013-10-28 23:01:59 +04:00
}
2014-04-14 17:08:43 +04:00
bool DetermineAuthTypeJob : : finished ( )
2013-10-28 23:01:59 +04:00
{
QUrl redirection = reply ( ) - > attribute ( QNetworkRequest : : RedirectionTargetAttribute ) . toUrl ( ) ;
2014-01-28 14:06:40 +04:00
qDebug ( ) < < Q_FUNC_INFO < < redirection . toString ( ) ;
2013-10-28 23:01:59 +04:00
if ( _redirects > = maxRedirects ( ) ) {
redirection . clear ( ) ;
2013-07-31 17:46:41 +04:00
}
2013-10-28 23:01:59 +04:00
if ( ( reply ( ) - > error ( ) = = QNetworkReply : : AuthenticationRequiredError ) | | redirection . isEmpty ( ) ) {
emit authType ( WizardCommon : : HttpCreds ) ;
2014-03-22 12:41:32 +04:00
} else if ( redirection . toString ( ) . endsWith ( account ( ) - > davPath ( ) ) ) {
2013-10-28 23:01:59 +04:00
// do a new run
_redirects + + ;
setReply ( getRequest ( redirection ) ) ;
setupConnections ( reply ( ) ) ;
} else {
QRegExp shibbolethyWords ( " SAML|wayf " ) ;
shibbolethyWords . setCaseSensitivity ( Qt : : CaseInsensitive ) ;
if ( redirection . toString ( ) . contains ( shibbolethyWords ) ) {
emit authType ( WizardCommon : : Shibboleth ) ;
} else {
// TODO: Send an error.
// eh?
emit authType ( WizardCommon : : HttpCreds ) ;
}
2013-07-31 17:46:41 +04:00
}
2014-04-14 17:08:43 +04:00
return true ;
2013-10-28 23:01:59 +04:00
}
2014-12-18 14:09:48 +03:00
ValidateDavAuthJob : : ValidateDavAuthJob ( AccountPtr account , QObject * parent )
2013-10-28 23:01:59 +04:00
: AbstractNetworkJob ( account , QString ( ) , parent )
2013-11-14 22:20:09 +04:00
{
}
void ValidateDavAuthJob : : start ( )
2013-10-28 23:01:59 +04:00
{
2014-05-15 11:45:26 +04:00
QString p = account ( ) - > davPath ( ) ;
QNetworkReply * reply = getRequest ( p ) ;
2013-10-28 23:01:59 +04:00
setReply ( reply ) ;
setupConnections ( reply ) ;
2013-11-22 17:01:11 +04:00
AbstractNetworkJob : : start ( ) ;
2013-10-28 23:01:59 +04:00
}
2014-04-14 17:08:43 +04:00
bool ValidateDavAuthJob : : finished ( )
2013-10-28 23:01:59 +04:00
{
emit authResult ( reply ( ) ) ;
2014-04-14 17:08:43 +04:00
return true ;
2011-09-29 19:17:50 +04:00
}
2013-07-31 17:46:41 +04:00
2014-11-10 00:34:07 +03:00
} // namespace OCC