diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp
index b86198392..25c8fb708 100644
--- a/src/creds/httpcredentials.cpp
+++ b/src/creds/httpcredentials.cpp
@@ -19,7 +19,6 @@
#include
#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(AccountManager::instance()->account()->credentials());
if (!http_credentials) {
qDebug() << "Not a HTTP creds instance!";
diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp
index 936990d95..0ef41b1e2 100644
--- a/src/creds/shibbolethcredentials.cpp
+++ b/src/creds/shibbolethcredentials.cpp
@@ -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(AccountManager::instance()->account()->credentials());
+
if (!creds) {
qDebug() << "Not a Shibboleth creds instance!";
diff --git a/src/mirall/account.cpp b/src/mirall/account.cpp
index 29e47c1f8..592f02655 100644
--- a/src/mirall/account.cpp
+++ b/src/mirall/account.cpp
@@ -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;
diff --git a/src/mirall/account.h b/src/mirall/account.h
index 0e297bfa7..07c6a03bc 100644
--- a/src/mirall/account.h
+++ b/src/mirall/account.h
@@ -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 _caCerts;
QUrl _url;
- QString _user;
AbstractCredentials* _credentials;
QList _approvedCerts;
QList _certificateChain;
diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp
index 632af2e29..7ef10681f 100644
--- a/src/mirall/csyncthread.cpp
+++ b/src/mirall/csyncthread.cpp
@@ -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.
diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp
index 5c9c451d6..e86bae3d8 100644
--- a/src/mirall/folder.cpp
+++ b/src/mirall/folder.cpp
@@ -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);
diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp
index b5761df35..1f66cd93a 100644
--- a/src/mirall/mirallconfigfile.cpp
+++ b/src/mirall/mirallconfigfile.cpp
@@ -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();
-}
-
}
diff --git a/src/mirall/mirallconfigfile.h b/src/mirall/mirallconfigfile.h
index aeccd4f4d..3ceb2cacf 100644
--- a/src/mirall/mirallconfigfile.h
+++ b/src/mirall/mirallconfigfile.h
@@ -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;
};
}
diff --git a/src/mirall/owncloudgui.cpp b/src/mirall/owncloudgui.cpp
index d60fe8c3f..49795262c 100644
--- a/src/mirall/owncloudgui.cpp
+++ b/src/mirall/owncloudgui.cpp
@@ -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()
diff --git a/src/mirall/owncloudsetupwizard.cpp b/src/mirall/owncloudsetupwizard.cpp
index e6fa8f5f1..c3cca6aa2 100644
--- a/src/mirall/owncloudsetupwizard.cpp
+++ b/src/mirall/owncloudsetupwizard.cpp
@@ -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:
%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!"
"
Please go back and check your credentials.
"));
_ocWizard->appendToConfigurationLog( tr("Remote folder creation failed probably because the provided credentials are wrong."
- "
Please go back and check your credentials.
"));
+ "
Please go back and check your credentials."));
_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("")
- + tr("Successfully connected to %1!")
- .arg(Theme::instance()->appNameGUI())
- + QLatin1String("
"));
+ + tr("Successfully connected to %1!")
+ .arg(Theme::instance()->appNameGUI())
+ + QLatin1String(""));
_ocWizard->successfulStep();
} else {
+ // ### this is not quite true, pass in the real problem as optional parameter
_ocWizard->appendToConfigurationLog(QLatin1String("")
- + tr("Connection to %1 could not be established. Please check again.")
- .arg(Theme::instance()->appNameGUI())
- + QLatin1String("
"));
+ + tr("Connection to %1 could not be established. Please check again.")
+ .arg(Theme::instance()->appNameGUI())
+ + QLatin1String(""));
}
}
+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("Local sync folder %1 successfully created!").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("Local sync folder %1 successfully created!").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("Local sync folder %1 successfully created!").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 );
}
diff --git a/src/mirall/owncloudsetupwizard.h b/src/mirall/owncloudsetupwizard.h
index 440f32a79..74941ba02 100644
--- a/src/mirall/owncloudsetupwizard.h
+++ b/src/mirall/owncloudsetupwizard.h
@@ -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;