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"
2012-02-17 14:11:18 +04:00
# include "mirall/owncloudsetupwizard.h"
# include "mirall/mirallconfigfile.h"
2012-02-17 18:54:39 +04:00
# include "mirall/owncloudinfo.h"
2012-03-14 14:26:00 +04:00
# include "mirall/folderman.h"
2013-03-21 15:01:37 +04:00
# include "mirall/utility.h"
2013-08-01 18:22:54 +04:00
# include "mirall/mirallaccessmanager.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
namespace Mirall {
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 ) ,
_mkdirRequestReply ( ) ,
_checkInstallationRequest ( ) ,
_checkRemoteFolderRequest ( ) ,
_configHandle ( ) ,
_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-02-10 17:03:09 +04:00
connect ( _ocWizard , SIGNAL ( clearPendingRequests ( ) ) ,
this , SLOT ( slotClearPendingRequests ( ) ) ) ;
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-07-22 15:59:52 +04:00
OwncloudSetupWizard * 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 ( )
{
// Set useful default values.
MirallConfigFile cfgFile ;
// Fill the entry fields with existing values.
QString url = cfgFile . ownCloudUrl ( ) ;
2013-07-29 16:28:19 +04:00
//QString user = cfgFile.ownCloudUser();
bool configExists = ! ( url . isEmpty ( ) /* || user.isEmpty()*/ ) ;
2013-05-26 16:04:11 +04:00
_ocWizard - > setConfigExists ( configExists ) ;
if ( ! url . isEmpty ( ) ) {
_ocWizard - > setOCUrl ( url ) ;
}
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-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-05-23 03:51:05 +04:00
_ocWizard - > setProperty ( " localFolder " , localFolder ) ;
_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-07-22 15:59:52 +04:00
_ocWizard - > setMultipleFoldersExist ( FolderMan : : instance ( ) - > map ( ) . count ( ) > 1 ) ;
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-07-31 17:46:41 +04:00
void OwncloudSetupWizard : : slotDetermineAuthType ( const QString & serverUrl )
2012-06-12 14:30:05 +04:00
{
2013-07-31 17:46:41 +04:00
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 ( ) ;
2013-03-02 00:30:22 +04:00
2013-07-31 17:46:41 +04:00
// remove a possibly existing custom config.
if ( ! _configHandle . isEmpty ( ) ) {
// remove the old config file.
MirallConfigFile oldConfig ( _configHandle ) ;
oldConfig . cleanupCustomConfig ( ) ;
}
2013-07-29 16:28:19 +04:00
2013-07-31 17:46:41 +04:00
_configHandle = now . toString ( QLatin1String ( " MMddyyhhmmss " ) ) ;
2013-01-25 14:29:45 +04:00
2013-08-08 15:03:49 +04:00
MirallConfigFile cfgFile ( _configHandle , true ) ;
2013-07-31 17:46:41 +04:00
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 ) ;
}
cfgFile . writeOwncloudConfig ( Theme : : instance ( ) - > appName ( ) ,
url ,
new DummyCredentials ) ;
2013-08-08 15:03:49 +04:00
ownCloudInfo * info = ownCloudInfo : : instance ( ) ;
2013-07-31 17:46:41 +04:00
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. " ;
}
}
2013-05-26 16:04:11 +04:00
2013-07-31 17:46:41 +04:00
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 * ) ) ) ;
2013-02-10 23:04:03 +04:00
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/> " )
. arg ( url ) . arg ( Theme : : instance ( ) - > appNameGUI ( ) ) . arg ( infoString ) . arg ( version ) ) ;
2013-06-03 17:47:39 +04:00
2013-08-01 18:22:54 +04:00
MirallAccessManager * nm = new MirallAccessManager ( this ) ;
2013-07-31 17:46:41 +04:00
// TODO: We should get this path from owncloud info.
QNetworkReply * reply = nm - > get ( QNetworkRequest ( url + " /remote.php/webdav/ " ) ) ;
2013-06-06 13:08:51 +04:00
2013-07-31 17:46:41 +04:00
connect ( reply , SIGNAL ( finished ( ) ) ,
this , SLOT ( slotAuthCheckReplyFinished ( ) ) ) ;
2013-06-03 17:47:39 +04:00
2013-07-31 17:46:41 +04:00
nm - > setProperty ( " mirallRedirs " , QVariant ( 0 ) ) ;
}
2013-06-03 17:47:39 +04:00
2013-07-31 17:46:41 +04:00
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 ) ;
2013-06-03 17:47:39 +04:00
} else {
2013-07-31 17:46:41 +04:00
// TODO: Send an error.
// eh?
_ocWizard - > setAuthType ( WizardCommon : : HttpCreds ) ;
2012-06-12 14:30:05 +04:00
}
2013-07-31 17:46:41 +04:00
reply - > deleteLater ( ) ;
nm - > deleteLater ( ) ;
2012-06-12 14:30:05 +04:00
}
2013-07-31 17:46:41 +04:00
}
2012-06-12 14:30:05 +04:00
2013-07-31 17:46:41 +04:00
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 * ) ) ) ;
2012-06-12 14:30:05 +04:00
2013-07-31 17:46:41 +04:00
_ocWizard - > displayError ( tr ( " Failed to connect to %1:<br/>%2 " ) .
arg ( Theme : : instance ( ) - > appNameGUI ( ) ) . arg ( err - > errorString ( ) ) ) ;
// remove the config file again
MirallConfigFile cfgFile ( _configHandle ) ;
cfgFile . cleanupCustomConfig ( ) ;
2012-06-12 14:30:05 +04:00
}
2012-02-17 14:11:18 +04:00
void OwncloudSetupWizard : : slotConnectToOCUrl ( const QString & url )
2011-09-28 20:14:48 +04:00
{
qDebug ( ) < < " Connect to url: " < < url ;
2012-08-17 19:13:17 +04:00
_ocWizard - > setField ( QLatin1String ( " OCUrl " ) , url ) ;
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " Trying to connect to %1 at %2... " )
2013-02-21 15:21:42 +04:00
. arg ( Theme : : instance ( ) - > appNameGUI ( ) ) . arg ( url ) ) ;
2012-02-17 18:54:39 +04:00
testOwnCloudConnect ( ) ;
}
void OwncloudSetupWizard : : testOwnCloudConnect ( )
{
2012-06-12 14:30:05 +04:00
// write a temporary config.
QDateTime now = QDateTime : : currentDateTime ( ) ;
2013-04-28 00:24:32 +04:00
2013-08-15 17:42:22 +04:00
if ( _configHandle . isEmpty ( ) ) {
_configHandle = now . toString ( QLatin1String ( " MMddyyhhmmss " ) ) ;
2013-04-28 00:24:32 +04:00
}
2013-08-08 15:03:49 +04:00
MirallConfigFile cfgFile ( _configHandle , true ) ;
2013-04-28 00:24:32 +04:00
QString url = _ocWizard - > field ( QLatin1String ( " OCUrl " ) ) . toString ( ) ;
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 ) ;
}
2012-09-24 19:55:10 +04:00
cfgFile . writeOwncloudConfig ( Theme : : instance ( ) - > appName ( ) ,
2013-04-28 00:24:32 +04:00
url ,
2013-07-29 16:28:19 +04:00
_ocWizard - > getCredentials ( ) ) ;
2012-02-17 18:54:39 +04:00
2013-07-29 16:28:19 +04:00
ownCloudInfo * info ( ownCloudInfo : : instance ( ) ) ;
info - > setCustomConfigHandle ( _configHandle ) ;
2013-02-18 19:16:10 +04:00
// If there is already a config, take its proxy config.
2013-07-29 16:28:19 +04:00
if ( info - > isConfigured ( ) ) {
2013-02-18 19:16:10 +04:00
MirallConfigFile prevCfg ;
2013-06-14 14:35:14 +04:00
cfgFile . setProxyType ( prevCfg . proxyType ( ) , prevCfg . proxyHostName ( ) , prevCfg . proxyPort ( ) ,
prevCfg . proxyNeedsAuth ( ) , prevCfg . proxyUser ( ) , prevCfg . proxyPassword ( ) ) ;
2013-02-18 19:16:10 +04:00
}
2013-07-31 17:46:41 +04:00
connect ( info , SIGNAL ( ownCloudDirExists ( QString , QNetworkReply * ) ) ,
this , SLOT ( slotConnectionCheck ( QString , QNetworkReply * ) ) ) ;
2012-04-14 13:19:36 +04:00
2013-07-31 17:46:41 +04:00
qDebug ( ) < < " # checking for authentication settings. " ;
_checkRemoteFolderRequest = info - > getWebDAVPath ( _remoteFolder ) ; // this call needs to be authenticated.
// continue in slotConnectionCheck
2012-02-17 18:54:39 +04:00
}
2013-07-31 17:46:41 +04:00
void OwncloudSetupWizard : : slotConnectionCheck ( const QString & , QNetworkReply * reply )
{
// disconnect from ownCloud Info signals
disconnect ( ownCloudInfo : : instance ( ) , SIGNAL ( ownCloudDirExists ( QString , QNetworkReply * ) ) ,
this , SLOT ( slotConnectionCheck ( QString , QNetworkReply * ) ) ) ;
switch ( reply - > error ( ) ) {
case QNetworkReply : : NoError :
case QNetworkReply : : ContentNotFoundError :
_ocWizard - > successfulStep ( ) ;
break ;
default :
_ocWizard - > displayError ( tr ( " Error: Wrong credentials. " ) ) ;
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-03-02 00:30:22 +04:00
// FIXME: Show problems with local folder properly.
2012-03-14 14:26:00 +04:00
bool localFolderOk = true ;
2013-07-31 17:46:41 +04:00
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 {
2013-05-23 03:51:05 +04:00
QString res = tr ( " Creating local sync folder %1... " ) . arg ( localFolder ) ;
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 ( ) ;
localFolderOk = false ;
2013-05-23 03:51:05 +04:00
_ocWizard - > displayError ( tr ( " Could not create local folder %1 " ) . arg ( localFolder ) ) ;
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
}
if ( localFolderOk ) {
2013-08-01 16:51:06 +04:00
checkRemoteFolder ( remoteFolder ) ;
2012-12-04 20:27:59 +04:00
}
}
2012-03-14 14:26:00 +04:00
2013-08-01 16:51:06 +04:00
void OwncloudSetupWizard : : checkRemoteFolder ( const QString & remoteFolder )
2013-04-28 00:24:32 +04:00
{
2013-07-29 16:28:19 +04:00
ownCloudInfo * info ( ownCloudInfo : : instance ( ) ) ;
connect ( info , SIGNAL ( ownCloudDirExists ( QString , QNetworkReply * ) ) ,
2013-04-28 00:24:32 +04:00
this , SLOT ( slotAuthCheckReply ( QString , QNetworkReply * ) ) ) ;
2013-07-31 17:46:41 +04:00
qDebug ( ) < < " # checking for existence of remote folder. " ;
2013-07-29 16:28:19 +04:00
info - > setCustomConfigHandle ( _configHandle ) ;
2013-08-01 16:51:06 +04:00
_checkRemoteFolderRequest = info - > getWebDAVPath ( remoteFolder ) ; // this call needs to be authenticated.
2013-04-28 00:24:32 +04:00
// continue in slotAuthCheckReply
}
void OwncloudSetupWizard : : slotAuthCheckReply ( const QString & , QNetworkReply * reply )
2012-12-04 20:27:59 +04:00
{
2013-04-28 00:24:32 +04:00
// disconnect from ownCloud Info signals
disconnect ( ownCloudInfo : : instance ( ) , SIGNAL ( ownCloudDirExists ( QString , QNetworkReply * ) ) ,
this , SLOT ( slotAuthCheckReply ( QString , QNetworkReply * ) ) ) ;
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-07-31 17:46:41 +04:00
if ( createRemoteFolder ( ) ) {
return ; // Finish here, the mkdir request will go on.
} else {
2013-04-28 00:24:32 +04:00
error = tr ( " The remote folder could not be accessed! " ) ;
ok = false ;
}
} 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 ) {
_ocWizard - > displayError ( error ) ;
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-04-28 00:24:32 +04:00
bool OwncloudSetupWizard : : createRemoteFolder ( )
2011-10-05 14:11:10 +04:00
{
2013-04-28 00:24:32 +04:00
if ( _remoteFolder . isEmpty ( ) ) return false ;
2012-03-14 14:26:00 +04:00
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( tr ( " creating folder on ownCloud: %1 " ) . arg ( _remoteFolder ) ) ;
2013-07-29 16:28:19 +04:00
ownCloudInfo * info ( ownCloudInfo : : instance ( ) ) ;
connect ( info , SIGNAL ( webdavColCreated ( QNetworkReply : : NetworkError ) ) ,
2013-04-28 00:24:32 +04:00
this , SLOT ( slotCreateRemoteFolderFinished ( QNetworkReply : : NetworkError ) ) ) ;
2012-03-14 14:26:00 +04:00
2013-07-29 16:28:19 +04:00
_mkdirRequestReply = info - > mkdirRequest ( _remoteFolder ) ;
2012-04-18 13:59:56 +04:00
2013-04-28 00:24:32 +04:00
return ( _mkdirRequestReply ! = NULL ) ;
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-04-28 00:24:32 +04:00
disconnect ( ownCloudInfo : : instance ( ) , SIGNAL ( webdavColCreated ( QNetworkReply : : NetworkError ) ) ,
this , SLOT ( slotCreateRemoteFolderFinished ( QNetworkReply : : NetworkError ) ) ) ;
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 ) {
2013-04-28 00:24:32 +04:00
_ocWizard - > displayError ( tr ( " The folder creation resulted in HTTP error code %1 " ) . arg ( ( int ) error ) ) ;
_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! "
" <br/>Please go back and check your credentials.</p> " ) ) ;
_ocWizard - > appendToConfigurationLog ( tr ( " <p><font color= \" red \" >Remote folder creation failed probably because the provided credentials are wrong.</font> "
2012-04-18 13:59:56 +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 ) ) ;
_ocWizard - > displayError ( tr ( " Remote folder %1 creation failed with error <tt>%2</tt>. " ) . arg ( _remoteFolder ) . arg ( error ) ) ;
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-05-23 03:51:05 +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-02-09 15:46:08 +04:00
+ tr ( " Successfully connected to %1! " )
2013-02-21 15:21:42 +04:00
. arg ( Theme : : instance ( ) - > appNameGUI ( ) )
2012-12-04 20:27:59 +04:00
+ QLatin1String ( " </b></font></p> " ) ) ;
2013-07-31 17:46:41 +04:00
_ocWizard - > successfulStep ( ) ;
2012-06-12 14:30:05 +04:00
} else {
2013-04-28 00:24:32 +04:00
_ocWizard - > appendToConfigurationLog ( QLatin1String ( " <p><font color= \" red \" > " )
2012-09-24 21:21:55 +04:00
+ tr ( " Connection to %1 could not be established. Please check again. " )
2013-02-21 15:21:42 +04:00
. arg ( Theme : : instance ( ) - > appNameGUI ( ) )
2012-06-12 14:30:05 +04:00
+ QLatin1String ( " </font></p> " ) ) ;
2012-03-14 14:26:00 +04:00
}
}
2011-09-30 16:19:26 +04:00
2013-07-31 17:46:41 +04:00
// Method executed when the user ends the wizard, either with 'accept' or 'reject'.
// accept the custom config to be the main one if Accepted.
void OwncloudSetupWizard : : slotAssistantFinished ( int result )
2013-07-22 16:54:14 +04:00
{
2013-07-31 17:46:41 +04:00
MirallConfigFile cfg ( _configHandle ) ;
FolderMan * folderMan = FolderMan : : instance ( ) ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
if ( result = = QDialog : : Rejected ) {
// the old config remains valid. Remove the temporary one.
cfg . cleanupCustomConfig ( ) ;
qDebug ( ) < < " Rejected the new config, use the old! " ;
} else if ( result = = QDialog : : Accepted ) {
AbstractCredentials * credentials ( _ocWizard - > getCredentials ( ) ) ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
qDebug ( ) < < " Config Changes were accepted! " ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
// go through all folders and remove the journals if the server changed.
2013-07-22 16:54:14 +04:00
MirallConfigFile prevCfg ;
2013-07-31 17:46:41 +04:00
QUrl prevUrl ( prevCfg . ownCloudUrl ( ) ) ;
QUrl newUrl ( cfg . ownCloudUrl ( ) ) ;
AbstractCredentials * oldCredentials ( prevCfg . getCredentials ( ) ) ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
bool urlHasChanged = ( prevUrl . host ( ) ! = newUrl . host ( ) | |
prevUrl . port ( ) ! = newUrl . port ( ) | |
prevUrl . path ( ) ! = newUrl . path ( ) ) ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
// if the user changed, its also a changed url.
if ( credentials - > changed ( oldCredentials ) ) {
urlHasChanged = true ;
qDebug ( ) < < " The User has changed, same as url change. " ;
}
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
const QString localFolder = _ocWizard - > localFolder ( ) ;
bool acceptCfg = true ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
if ( urlHasChanged ) {
// first terminate sync jobs.
folderMan - > terminateSyncProcess ( ) ;
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
bool startFromScratch = _ocWizard - > field ( " OCSyncFromScratch " ) . toBool ( ) ;
if ( startFromScratch ) {
// first try to rename (backup) the current local dir.
bool renameOk = false ;
while ( ! renameOk ) {
renameOk = folderMan - > 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. "
" Please close the folder or file and hit retry or cancel the setup. " ) , QMessageBox : : Retry | QMessageBox : : Abort , QMessageBox : : Retry ) ;
if ( but = = QMessageBox : : Abort ) {
renameOk = true ;
acceptCfg = false ;
}
}
}
}
}
2013-07-22 16:54:14 +04:00
2013-07-31 17:46:41 +04:00
// Now write the resulting folder definition if folder names are set.
if ( acceptCfg & & urlHasChanged ) {
folderMan - > removeAllFolderDefinitions ( ) ;
folderMan - > addFolderDefinition ( Theme : : instance ( ) - > appName ( ) ,
localFolder , _remoteFolder ) ;
_ocWizard - > appendToConfigurationLog ( tr ( " <font color= \" green \" ><b>Local sync folder %1 successfully created!</b></font> " ) . arg ( localFolder ) ) ;
} else {
// url is unchanged. Only the password was changed.
if ( acceptCfg ) {
qDebug ( ) < < " Only password was changed, no changes to folder configuration. " ;
} else {
qDebug ( ) < < " User interrupted change of configuration. " ;
}
}
2013-08-15 18:35:03 +04:00
// save the user credentials and afterwards clear the cred store.
if ( acceptCfg ) {
cfg . acceptCustomConfig ( ) ;
}
2013-07-22 16:54:14 +04:00
}
2013-07-31 17:46:41 +04:00
// clear the custom config handle
_configHandle . clear ( ) ;
ownCloudInfo : : instance ( ) - > setCustomConfigHandle ( QString : : null ) ;
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
}
2013-07-31 17:46:41 +04:00
void OwncloudSetupWizard : : slotClearPendingRequests ( )
{
qDebug ( ) < < " Pending request: " < < _mkdirRequestReply ;
if ( _mkdirRequestReply & & _mkdirRequestReply - > isRunning ( ) ) {
qDebug ( ) < < " ABORTing pending mkdir request. " ;
_mkdirRequestReply - > abort ( ) ;
}
if ( _checkInstallationRequest & & _checkInstallationRequest - > isRunning ( ) ) {
qDebug ( ) < < " ABORTing pending check installation request. " ;
_checkInstallationRequest - > abort ( ) ;
}
if ( _checkRemoteFolderRequest & & _checkRemoteFolderRequest - > isRunning ( ) ) {
qDebug ( ) < < " ABORTing pending remote folder check request. " ;
_checkRemoteFolderRequest - > abort ( ) ;
}
2011-09-29 19:17:50 +04:00
}
2013-07-31 17:46:41 +04:00
} // ns Mirall