More porting to Account class

- Finish port of owncloud setup wizard to Account
- Deprive MirallConfigFile of the customHandle
This commit is contained in:
Daniel Molkentin 2013-10-30 16:31:47 +01:00
parent a91799a11c
commit 14c2ff44f3
11 changed files with 165 additions and 301 deletions

View file

@ -19,7 +19,6 @@
#include <QNetworkReply>
#include "mirall/account.h"
#include "mirall/mirallconfigfile.h"
#include "mirall/mirallaccessmanager.h"
#include "mirall/utility.h"
#include "creds/credentialscommon.h"
@ -41,8 +40,8 @@ int getauth(const char *prompt,
{
int re = 0;
QMutex mutex;
MirallConfigFile cfg;
HttpCredentials* http_credentials = dynamic_cast< HttpCredentials* > (cfg.getCredentials());
// ### safe?
HttpCredentials* http_credentials = qobject_cast<HttpCredentials*>(AccountManager::instance()->account()->credentials());
if (!http_credentials) {
qDebug() << "Not a HTTP creds instance!";

View file

@ -21,7 +21,6 @@
#include "creds/shibboleth/shibbolethrefresher.h"
#include "creds/shibboleth/shibbolethconfigfile.h"
#include "creds/credentialscommon.h"
#include "mirall/mirallconfigfile.h"
#include "mirall/account.h"
namespace Mirall
@ -47,8 +46,8 @@ int shibboleth_redirect_callback(CSYNC* csync_ctx,
QMutex mutex;
QMutexLocker locker(&mutex);
MirallConfigFile cfg;
ShibbolethCredentials* creds = dynamic_cast< ShibbolethCredentials* > (cfg.getCredentials());
ShibbolethCredentials* creds = qobject_cast<ShibbolethCredentials*>(AccountManager::instance()->account()->credentials());
if (!creds) {
qDebug() << "Not a Shibboleth creds instance!";

View file

@ -26,7 +26,6 @@
namespace Mirall {
static const char urlC[] = "url";
static const char userC[] = "user";
static const char authTypeC[] = "authType";
AccountManager *AccountManager::_instance = 0;
@ -47,6 +46,11 @@ AccountManager *AccountManager::instance()
return _instance;
}
void AccountManager::setAccount(Account *account)
{
_account = account;
}
Account::Account(AbstractSslErrorHandler *sslErrorHandler, QObject *parent)
: QObject(parent)
@ -61,7 +65,6 @@ Account::Account(AbstractSslErrorHandler *sslErrorHandler, QObject *parent)
void Account::save(QSettings &settings)
{
settings.beginGroup(Theme::instance()->appName());
settings.setValue(QLatin1String(userC), _user);
settings.setValue(QLatin1String(urlC), _url);
if (_credentials) {
settings.setValue(QLatin1String(authTypeC), _credentials->authType());
@ -87,8 +90,7 @@ Account* Account::restore(QSettings &settings)
acc->setApprovedCerts(QSslCertificate::fromData(cfg.caCerts()));
settings.beginGroup(groupName);
acc->setUrl(settings.value(QLatin1String(urlC)).toUrl());
acc->setUser(settings.value(QLatin1String(userC)).toString());
acc->setCredentials(cfg.getCredentials());
acc->setCredentials(CredentialsFactory::create(QLatin1String(urlC)));
return acc;
} else {
@ -96,6 +98,31 @@ Account* Account::restore(QSettings &settings)
}
}
static bool isEqualExceptProtocol(const QUrl &url1, const QUrl &url2)
{
return (url1.host() != url2.host() ||
url1.port() != url2.port() ||
url1.path() != url2.path());
}
bool Account::changed(Account *other, bool ignoreUrlProtocol) const
{
if (!other) {
return false;
}
bool changes = false;
if (ignoreUrlProtocol) {
changes = isEqualExceptProtocol(_url, other->_url);
} else {
changes = (_url == other->_url);
}
if (!changes) {
changes = _credentials->changed(other->_credentials);
}
return changes;
}
AbstractCredentials *Account::credentials() const
{
return _credentials;
@ -176,11 +203,6 @@ void Account::setUrl(const QUrl &url)
_url = url;
}
void Account::setUser(const QString &user)
{
_user = user;
}
QUrl Account::concatUrlPath(const QUrl &url, const QString &concatPath)
{
QUrl tmpUrl = url;

View file

@ -37,7 +37,7 @@ public:
static AccountManager *instance();
~AccountManager();
void setAccount(Account *account) { _account = account; }
void setAccount(Account *account);
Account *account() { return _account; }
private:
@ -80,6 +80,13 @@ public:
*/
static Account* create(const QUrl &url);
/**
* @brief Checks the Account instance is different from \param other
*
* @returns true, if credentials or url have changed, false otherwise
*/
bool changed(Account *other, bool ignoreUrlProtocol) const;
/** Holds the accounts credentials */
AbstractCredentials* credentials() const;
void setCredentials(AbstractCredentials *cred);
@ -88,10 +95,6 @@ public:
void setUrl(const QUrl &url);
QUrl url() const { return _url; }
/** User name of the account */
void setUser(const QString &user);
QString user() const { return _user; }
/** Returns webdav entry URL, based on url() */
QUrl davUrl() const;
@ -122,7 +125,6 @@ private:
QNetworkAccessManager *_am;
QList<QSslCertificate> _caCerts;
QUrl _url;
QString _user;
AbstractCredentials* _credentials;
QList<QSslCertificate> _approvedCerts;
QList<QSslCertificate> _certificateChain;

View file

@ -14,6 +14,7 @@
*/
#include "mirall/csyncthread.h"
#include "mirall/account.h"
#include "mirall/mirallconfigfile.h"
#include "mirall/theme.h"
#include "mirall/logger.h"
@ -356,7 +357,11 @@ void CSyncThread::startSync()
// any way to get "session_key" module property from csync. Had we
// have it, then we could keep this code and remove it from
// AbstractCredentials implementations.
cfg.getCredentials()->syncContextPreStart(_csync_ctx);
if (Account *account = AccountManager::instance()->account()) {
account->credentials()->syncContextPreStart(_csync_ctx);
} else {
qDebug() << Q_FUNC_INFO << "No default Account object, huh?";
}
// if (_lastAuthCookies.length() > 0) {
// // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
// // when https://github.com/owncloud/core/pull/4042 is merged.

View file

@ -113,7 +113,11 @@ bool Folder::init()
csync_enable_conflictcopys(_csync_ctx);
setIgnoredFiles();
cfgFile.getCredentials()->syncContextPreInit(_csync_ctx);
if (Account *account = AccountManager::instance()->account()) {
account->credentials()->syncContextPreInit(_csync_ctx);
} else {
qDebug() << Q_FUNC_INFO << "No default Account object, huh?";
}
if( csync_init( _csync_ctx ) < 0 ) {
qDebug() << "Could not initialize csync!" << csync_get_status(_csync_ctx) << csync_get_status_string(_csync_ctx);

View file

@ -36,9 +36,6 @@
namespace Mirall {
static const char urlC[] = "url";
static const char authTypeC[] = "authType";
static const char caCertsKeyC[] = "CaCertificates";
static const char remotePollIntervalC[] = "remotePollInterval";
static const char forceSyncIntervalC[] = "forceSyncInterval";
@ -65,39 +62,17 @@ static const char maxLogLinesC[] = "Logging/maxLogLines";
QString MirallConfigFile::_oCVersion;
QString MirallConfigFile::_confDir = QString::null;
bool MirallConfigFile::_askedUser = false;
QMap< QString, MirallConfigFile::SharedCreds > MirallConfigFile::credentialsPerConfig;
MirallConfigFile::MirallConfigFile( const QString& appendix, bool useOldConfig )
MirallConfigFile::MirallConfigFile()
{
if (useOldConfig && !appendix.isEmpty()) {
QString oldConfigFile = configFile();
_customHandle = appendix;
QString newConfigFile = configFile();
QFile::copy(oldConfigFile, newConfigFile);
} else {
_customHandle = appendix;
}
QSettings::setDefaultFormat(QSettings::IniFormat);
if (! credentialsPerConfig.contains(_customHandle)) {
QString con( _customHandle );
if( _customHandle.isEmpty() ) con = defaultConnection();
const QString config = configFile();
qDebug() << "Loading config: " << config;
const QString config = configFile();
qDebug() << "Loading config: " << config;
QSettings settings(config, QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup( con );
QString type = settings.value( QLatin1String(authTypeC) ).toString();
qDebug() << "Getting credentials of type " << type << " for " << _customHandle;
credentialsPerConfig.insert(_customHandle, SharedCreds(CredentialsFactory::create (type)));
}
QSettings settings(config, QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup( defaultConnection() );
}
void MirallConfigFile::setConfDir(const QString &value)
@ -227,13 +202,7 @@ QString MirallConfigFile::configFile() const
if( qApp->applicationName().isEmpty() ) {
qApp->setApplicationName( Theme::instance()->appNameGUI() );
}
QString file = configPath() + Theme::instance()->configFileName();
if( !_customHandle.isEmpty() ) {
file.append( QLatin1Char('_'));
file.append( _customHandle );
qDebug() << __PRETTY_FUNCTION__ << " OO Custom config file in use: " << file;
}
return file;
return configPath() + Theme::instance()->configFileName();
}
bool MirallConfigFile::exists()
@ -247,42 +216,6 @@ QString MirallConfigFile::defaultConnection() const
return Theme::instance()->appName();
}
bool MirallConfigFile::connectionExists( const QString& conn )
{
QString con = conn;
if( conn.isEmpty() ) con = defaultConnection();
QSettings settings(configFile(), QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup(conn);
return settings.contains( QLatin1String(urlC) );
}
void MirallConfigFile::writeOwncloudConfig( const QString& connection,
const QString& url,
AbstractCredentials* credentials)
{
const QString file = configFile();
qDebug() << "*** writing mirall config to " << file;
QSettings settings(configFile(), QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup( connection );
settings.setValue( QLatin1String(urlC), url );
settings.setValue(QLatin1String(authTypeC), credentials->authType());
credentialsPerConfig.insert(_customHandle, SharedCreds(credentials));
settings.sync();
// check the perms, only read-write for the owner.
QFile::setPermissions( file, QFile::ReadOwner|QFile::WriteOwner );
// Store credentials temporar until the config is finalized.
//ownCloudInfo::instance()->setCredentials( user, passwd, _customHandle );
}
void MirallConfigFile::storeData(const QString& group, const QString& key, const QVariant& value)
{
const QString con(group.isEmpty() ? defaultConnection() : group);
@ -341,45 +274,6 @@ void MirallConfigFile::setCaCerts( const QByteArray & certs )
settings.sync();
}
void MirallConfigFile::removeConnection( const QString& connection )
{
QString con( connection );
if( connection.isEmpty() ) con = defaultConnection();
qDebug() << " removing the config file for connection " << con;
// Currently its just removing the entire config file
// TODO: Eh? Shouldn't it try to load a file under configFile() and set it to INI?
QSettings settings;
settings.setIniCodec( "UTF-8" );
settings.beginGroup( con );
settings.remove(QString::null); // removes all content from the group
settings.sync();
}
/*
* returns the configured owncloud url if its already configured, otherwise an empty
* string.
* The returned url always has a trailing hash.
*/
QString MirallConfigFile::ownCloudUrl( const QString& connection) const
{
QString con( connection );
if( connection.isEmpty() ) con = defaultConnection();
QSettings settings(configFile(), QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup( con );
QString url = settings.value( QLatin1String(urlC) ).toString();
if( ! url.isEmpty() ) {
if( ! url.endsWith(QLatin1Char('/'))) url.append(QLatin1String("/"));
}
return url;
}
int MirallConfigFile::remotePollInterval( const QString& connection ) const
{
QString con( connection );
@ -486,55 +380,6 @@ void MirallConfigFile::setMaxLogLines( int lines )
settings.sync();
}
// remove a custom config file.
void MirallConfigFile::cleanupCustomConfig()
{
if( _customHandle.isEmpty() ) {
qDebug() << "SKipping to erase the main configuration.";
return;
}
QString file = configFile();
if( QFile::exists( file ) ) {
QFile::remove( file );
}
}
// accept a config identified by the customHandle as general config.
void MirallConfigFile::acceptCustomConfig()
{
if( _customHandle.isEmpty() ) {
qDebug() << "WRN: Custom Handle is empty. Can not accept.";
return;
}
QString srcConfig = configFile(); // this considers the custom handle
credentialsPerConfig.insert(QString(), credentialsPerConfig[_customHandle]);
credentialsPerConfig.remove(_customHandle);
_customHandle.clear();
QString targetConfig = configFile();
QString targetBak = targetConfig + QLatin1String(".bak");
bool bakOk = false;
// remove an evtl existing old config backup.
if( QFile::exists( targetBak ) ) {
QFile::remove( targetBak );
}
// create a backup of the current config.
bakOk = QFile::rename( targetConfig, targetBak );
// move the custom config to the master place.
if( ! QFile::rename( srcConfig, targetConfig ) ) {
// if the move from custom to master failed, put old backup back.
if( bakOk ) {
QFile::rename( targetBak, targetConfig );
}
}
QFile::remove( targetBak );
credentialsPerConfig[QString()]->persistForUrl(ownCloudUrl());
}
void MirallConfigFile::setProxyType(int proxyType,
const QString& host,
int port, bool needsAuth,
@ -661,9 +506,4 @@ void MirallConfigFile::setMonoIcons(bool useMonoIcons)
settings.setValue(QLatin1String(monoIconsC), useMonoIcons);
}
AbstractCredentials* MirallConfigFile::getCredentials() const
{
return credentialsPerConfig[_customHandle].data();
}
}

View file

@ -28,7 +28,7 @@ class AbstractCredentials;
class MirallConfigFile
{
public:
MirallConfigFile( const QString& appendix = QString(), bool useOldConfig = false );
MirallConfigFile();
enum Scope { UserScope, SystemScope };
@ -39,19 +39,8 @@ public:
bool exists();
bool connectionExists( const QString& = QString() );
QString defaultConnection() const;
void writeOwncloudConfig( const QString& connection,
const QString& url,
AbstractCredentials* credentials);
AbstractCredentials* getCredentials() const;
void removeConnection( const QString& connection = QString() );
QString ownCloudUrl( const QString& connection = QString() ) const;
// the certs do not depend on a connection.
QByteArray caCerts();
void setCaCerts( const QByteArray& );
@ -76,11 +65,6 @@ public:
/* Force sync interval, in milliseconds */
quint64 forceSyncInterval(const QString &connection = QString()) const;
// Custom Config: accept the custom config to become the main one.
void acceptCustomConfig();
// Custom Config: remove the custom config file.
void cleanupCustomConfig();
bool monoIcons() const;
void setMonoIcons(bool);
@ -137,8 +121,6 @@ private:
static bool _askedUser;
static QString _oCVersion;
static QString _confDir;
static QMap< QString, SharedCreds > credentialsPerConfig;
QString _customHandle;
};
}

View file

@ -81,10 +81,8 @@ ownCloudGui::ownCloudGui(Application *parent) :
// This should rather be in application.... or rather in MirallConfigFile?
bool ownCloudGui::checkConfigExists(bool openSettings)
{
// if no config file is there, start the configuration wizard.
MirallConfigFile cfgFile;
if( cfgFile.exists() && !cfgFile.ownCloudUrl().isEmpty() ) {
// if account is set up, start the configuration wizard.
if( AccountManager::instance()->account() ) {
if( openSettings ) {
this->slotSettings();
}
@ -478,10 +476,10 @@ void ownCloudGui::slotToggleLogBrowser()
void ownCloudGui::slotOpenOwnCloud()
{
MirallConfigFile cfgFile;
QString url = cfgFile.ownCloudUrl();
QDesktopServices::openUrl( url );
if (Account *account = AccountManager::instance()->account()) {
QString url = account->url();
QDesktopServices::openUrl( url );
}
}
void ownCloudGui::slotHelp()

View file

@ -79,7 +79,10 @@ void OwncloudSetupWizard::runWizard(QObject* obj, const char* amember, QWidget *
void OwncloudSetupWizard::startWizard()
{
Account *account = AccountManager::instance()->account();
// ###
MirallConfigFile cfg;
QSettings settings(cfg.configFile(), QSettings::IniFormat);
Account *account = Account::restore(settings);
if (!account) {
account = new Account(new SslDialogErrorHandler);
account->setCredentials(CredentialsFactory::create("dummy"));
@ -114,7 +117,7 @@ void OwncloudSetupWizard::slotDetermineAuthType(const QString &urlString)
QString fixedUrl = urlString;
QUrl url = QUrl::fromUserInput(fixedUrl);
// fromUserInput defaults to http, not http if no scheme is specified
if (!fixedUrl.startsWith("http://") || !fixedUrl.startsWith("https://")) {
if (!fixedUrl.startsWith("http://") && !fixedUrl.startsWith("https://")) {
url.setScheme("https");
}
Account *account = _ocWizard->account();
@ -140,20 +143,20 @@ void OwncloudSetupWizard::slotOwnCloudFoundAuth(const QUrl& url, const QVariantM
void OwncloudSetupWizard::slotNoOwnCloudFoundAuth(QNetworkReply *reply)
{
_ocWizard->displayError(tr("Failed to connect to %1 at %2:<br/>%3")
.arg(Theme::instance()->appNameGUI())
.arg(Theme::instance()->appNameGUI())
.arg(reply->url().toString())
.arg(reply->errorString()));
}
void OwncloudSetupWizard::slotConnectToOCUrl( const QString& url )
{
qDebug() << "Connect to url: " << url;
_ocWizard->account()->setCredentials(_ocWizard->getCredentials());
_ocWizard->setField(QLatin1String("OCUrl"), url );
_ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2...")
.arg( Theme::instance()->appNameGUI() ).arg(url) );
qDebug() << "Connect to url: " << url;
_ocWizard->account()->setCredentials(_ocWizard->getCredentials());
_ocWizard->setField(QLatin1String("OCUrl"), url );
_ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2...")
.arg( Theme::instance()->appNameGUI() ).arg(url) );
testOwnCloudConnect();
testOwnCloudConnect();
}
void OwncloudSetupWizard::testOwnCloudConnect()
@ -181,6 +184,7 @@ void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFo
qDebug() << "Setup local sync folder for new oC connection " << localFolder;
const QDir fi( localFolder );
bool nextStep = true;
if( fi.exists() ) {
// there is an existing local folder. If its non empty, it can only be synced if the
// ownCloud is newly created.
@ -191,15 +195,20 @@ void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFo
Utility::setupFavLink( localFolder );
// FIXME: Create a local sync folder.
res += tr("ok");
EntityExistsJob *job = new EntityExistsJob(_ocWizard->account(), remoteFolder, this);
connect(job, SIGNAL(exists(QNetworkReply*)), SLOT(slotAuthCheckReply(QNetworkReply*)));
} else {
res += tr("failed.");
qDebug() << "Failed to create " << fi.path();
_ocWizard->displayError(tr("Could not create local folder %1").arg(localFolder));
nextStep = false;
}
_ocWizard->appendToConfigurationLog( res );
}
if (nextStep) {
EntityExistsJob *job = new EntityExistsJob(_ocWizard->account(), remoteFolder, this);
connect(job, SIGNAL(exists(QNetworkReply*)), SLOT(slotAuthCheckReply(QNetworkReply*)));
} else {
finalizeSetup( false );
}
}
// ### TODO move into EntityExistsJob once we decide if/how to return gui strings from jobs
@ -241,8 +250,8 @@ void OwncloudSetupWizard::createRemoteFolder()
void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply::NetworkError error )
{
qDebug() << "** webdav mkdir request finished " << error;
// disconnect(ownCloudInfo::instance(), SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),
// this, SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));
// disconnect(ownCloudInfo::instance(), SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),
// this, SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));
bool success = true;
@ -259,7 +268,7 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply::Network
"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>"
"<br/>Please go back and check your credentials.</p>"));
"<br/>Please go back and check your credentials.</p>"));
_remoteFolder.clear();
success = false;
} else {
@ -281,106 +290,108 @@ void OwncloudSetupWizard::finalizeSetup( bool success )
if( success ) {
if( !(localFolder.isEmpty() || _remoteFolder.isEmpty() )) {
_ocWizard->appendToConfigurationLog( tr("A sync connection from %1 to remote directory %2 was set up.")
.arg(localFolder).arg(_remoteFolder));
.arg(localFolder).arg(_remoteFolder));
}
_ocWizard->appendToConfigurationLog( QLatin1String(" "));
_ocWizard->appendToConfigurationLog( QLatin1String("<p><font color=\"green\"><b>")
+ tr("Successfully connected to %1!")
.arg(Theme::instance()->appNameGUI())
+ QLatin1String("</b></font></p>"));
+ tr("Successfully connected to %1!")
.arg(Theme::instance()->appNameGUI())
+ QLatin1String("</b></font></p>"));
_ocWizard->successfulStep();
} else {
// ### this is not quite true, pass in the real problem as optional parameter
_ocWizard->appendToConfigurationLog(QLatin1String("<p><font color=\"red\">")
+ tr("Connection to %1 could not be established. Please check again.")
.arg(Theme::instance()->appNameGUI())
+ QLatin1String("</font></p>"));
+ 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."
"Please close the folder or file and hit retry or cancel the setup."), QMessageBox::Retry | QMessageBox::Abort, QMessageBox::Retry);
if( but == QMessageBox::Abort ) {
break;
}
}
}
return renameOk;
}
void OwncloudSetupWizard::replaceDefaultAccountWith(Account *newAccount)
{
// new Account
AccountManager *mgr = AccountManager::instance();
if (mgr->account()) {
mgr->account()->deleteLater();
}
mgr->setAccount(newAccount);
MirallConfigFile cfg;
QSettings settings(cfg.configFile(), QSettings::IniFormat);
newAccount->save(settings);
}
// 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 )
{
MirallConfigFile cfg;
FolderMan *folderMan = FolderMan::instance();
if( result == QDialog::Rejected ) {
// the old config remains valid. Remove the temporary one.
cfg.cleanupCustomConfig();
_ocWizard->account()->deleteLater();
qDebug() << "Rejected the new config, use the old!";
} else if( result == QDialog::Accepted ) {
AbstractCredentials* credentials(_ocWizard->getCredentials());
qDebug() << "Config Changes were accepted!";
// go through all folders and remove the journals if the server changed.
MirallConfigFile prevCfg;
QUrl prevUrl( prevCfg.ownCloudUrl() );
QUrl newUrl( cfg.ownCloudUrl() );
AbstractCredentials* oldCredentials(prevCfg.getCredentials());
bool urlHasChanged = (prevUrl.host() != newUrl.host() ||
prevUrl.port() != newUrl.port() ||
prevUrl.path() != newUrl.path());
// if the user changed, its also a changed url.
if(credentials->changed(oldCredentials)) {
urlHasChanged = true;
qDebug() << "The User has changed, same as url change.";
}
Account *newAccount = _ocWizard->account();
Account *origAccount = AccountManager::instance()->account();
const QString localFolder = _ocWizard->localFolder();
bool acceptCfg = true;
if( urlHasChanged ) {
// first terminate sync jobs.
folderMan->terminateSyncProcess();
bool isInitialSetup = (origAccount == 0);
bool reinitRequired = newAccount->changed(origAccount, true /* ignoreProtocol, allows http->https */);
bool startFromScratch = _ocWizard->field("OCSyncFromScratch").toBool();
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;
}
}
// This distinguishes three possibilities:
// 1. Initial setup, no prior account exists
if (isInitialSetup) {
folderMan->addFolderDefinition(Theme::instance()->appName(),
localFolder, _remoteFolder );
replaceDefaultAccountWith(newAccount);
}
// 2. Server URL or user changed, requires reinit of folders
else if (reinitRequired) {
// 2.1: startFromScratch: (Re)move local data, clean slate sync
if (startFromScratch) {
if (ensureStartFromScratch(localFolder)) {
folderMan->addFolderDefinition(Theme::instance()->appName(),
localFolder, _remoteFolder );
_ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));
replaceDefaultAccountWith(newAccount);
}
}
}
// 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.";
// 2.2: Reinit: Remove journal and start a sync
else {
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));
replaceDefaultAccountWith(newAccount);
}
}
// save the user credentials and afterwards clear the cred store.
if( acceptCfg ) {
cfg.acceptCustomConfig();
// 3. Existing setup, http -> https or password changed
else {
replaceDefaultAccountWith(newAccount);
qDebug() << "Only password was changed, no changes to folder configuration.";
}
}
// // clear the custom config handle
// _configHandle.clear();
// ownCloudInfo::instance()->setCustomConfigHandle( QString::null );
// notify others.
emit ownCloudWizardDone( result );
}

View file

@ -86,6 +86,8 @@ private:
void testOwnCloudConnect();
void createRemoteFolder();
void finalizeSetup( bool );
bool ensureStartFromScratch(const QString &localFolder);
void replaceDefaultAccountWith(Account *newAccount);
Account* _account;
OwncloudWizard* _ocWizard;