diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index e3a0e04cb..356d5f886 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -72,7 +72,8 @@ Application::Application(int argc, char **argv) : // Look for configuration changes _configFolderWatcher = new FolderWatcher(storageDir.path()); - connect(_configFolderWatcher, SIGNAL(folderChanged(const QStringList &)), this, SLOT(slotReparseConfiguration())); + connect(_configFolderWatcher, SIGNAL(folderChanged(const QStringList &)), + this, SLOT(slotReparseConfiguration())); setupKnownFolders(); setupContextMenu(); @@ -180,13 +181,11 @@ void Application::slotAddFolder() } else if( _folderWizard->field("OC?").toBool()) { settings.setValue("folder/backend", "sitecopy"); settings.setValue("backend:sitecopy/targetPath", _folderWizard->field("targetOCFolder")); - - settings.setValue("backend:sitecopy/url", _folderWizard->field("OCUrl")); - settings.setValue("backend:sitecopy/user", _folderWizard->field("OCUser")); settings.setValue("backend:sitecopy/alias", _folderWizard->field("OCSiteAlias")); qDebug() << "Now writing sitecopy config " << _folderWizard->field("OCSiteAlias").toString(); ; SitecopyConfig scConfig; + scConfig.writeSiteConfig( _folderWizard->field("sourceFolder").toString(), /* local path */ alias, /* _folderWizard->field("OCSiteAlias").toString(), site alias */ _folderWizard->field("OCUrl").toString(), /* site URL */ diff --git a/src/mirall/owncloudsetup.cpp b/src/mirall/owncloudsetup.cpp index f035385d6..b9492f20c 100644 --- a/src/mirall/owncloudsetup.cpp +++ b/src/mirall/owncloudsetup.cpp @@ -4,6 +4,8 @@ #include #include "owncloudsetup.h" +#include "mirall/sitecopyconfig.h" + namespace Mirall { @@ -154,11 +156,15 @@ void OwncloudSetup::slotFinished( int res, QProcess::ExitStatus ) if( res ) { _ocWizard->appendToResultWidget( tr("Installation of ownCloud failed!") ); + emit ownCloudSetupFinished( true ); } else { // Successful installation. Write the config. _ocWizard->appendToResultWidget( tr("Installation of ownCloud succeeded!") ); writeOwncloudConfig(); + + emit ownCloudSetupFinished( true ); + setupLocalSyncFolder(); } } @@ -199,6 +205,23 @@ QString OwncloudSetup::ownCloudUrl() const return url; } +QString OwncloudSetup::ownCloudUser() const +{ + QSettings settings( mirallConfigFile(), QSettings::IniFormat ); + QString user = settings.value( "ownCloud/user" ).toString(); + qDebug() << "Returning configured owncloud user: " << user; + + return user; +} + +QString OwncloudSetup::ownCloudPasswd() const +{ + QSettings settings( mirallConfigFile(), QSettings::IniFormat ); + QString pwd = settings.value( "ownCloud/password" ).toString(); + + return pwd; +} + /* * method to check the if the owncloud admin script is existing */ @@ -214,5 +237,50 @@ bool OwncloudSetup::checkOwncloudAdmin( const QString& bin ) return true; } +void OwncloudSetup::setupLocalSyncFolder() +{ + QString syncFolder( QDir::homePath() + "/ownCloud" ); + qDebug() << "Setup local sync folder " << syncFolder; + QDir fi( syncFolder ); + _ocWizard->appendToResultWidget( tr("creating local sync folder %1").arg(syncFolder) ); + + if( fi.exists() ) { + // there is an existing local folder. If its non empty, it can only be synced if the + // ownCloud is newly created. + _ocWizard->appendToResultWidget( tr("Local sync folder %1 already exists, can " + "not automatically create.").arg(syncFolder)); + } else { + + if( fi.mkpath( syncFolder ) ) { + QString targetPath = "/"; + qDebug() << "Successfully created " << fi.path(); + + // Create a sitecopy config file + SitecopyConfig scConfig; + + scConfig.writeSiteConfig( syncFolder, /* local path */ + "ownCloud", /* _folderWizard->field("OCSiteAlias").toString(), site alias */ + ownCloudUrl(), + ownCloudUser(), + ownCloudPasswd(), + targetPath ); + + // create a mirall folder entry. + // FIXME: folderConfigPath is a method of application object, copied to here. + const QString folderConfigPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/folders"; + + QSettings settings(folderConfigPath + "/ownCloud", QSettings::IniFormat); + settings.setValue("folder/backend", "sitecopy"); + settings.setValue("folder/path", syncFolder ); + settings.setValue("backend:sitecopy/targetPath", targetPath ); + settings.setValue("backend:sitecopy/alias", "ownCloud" ); + settings.sync(); + + } else { + qDebug() << "Failed to create " << fi.path(); + } + } +} + } #include "owncloudsetup.moc" diff --git a/src/mirall/owncloudsetup.h b/src/mirall/owncloudsetup.h index 79b1faeb0..92cf60357 100644 --- a/src/mirall/owncloudsetup.h +++ b/src/mirall/owncloudsetup.h @@ -31,8 +31,12 @@ public: * string. */ QString ownCloudUrl() const ; + QString ownCloudUser() const ; + QString ownCloudPasswd() const ; + void setupLocalSyncFolder(); signals: + void ownCloudSetupFinished( bool ); public slots: diff --git a/src/mirall/sitecopyconfig.cpp b/src/mirall/sitecopyconfig.cpp index b69c27e4e..f088f9639 100644 --- a/src/mirall/sitecopyconfig.cpp +++ b/src/mirall/sitecopyconfig.cpp @@ -49,7 +49,7 @@ void SitecopyConfig::writeSiteConfig( const QString& localPath, ocDefs["protocol"] = "webdav"; ocDefs["local"] = localPath; QString webdavBase = "files/webdav.php"; - if( !remoteFolder.isEmpty() ) { + if( !remoteFolder.isEmpty() && remoteFolder != "/" ) { webdavBase += "/" + remoteFolder; } if( !path.endsWith( QChar('/')) ) { diff --git a/src/mirall/sitecopyfolder.cpp b/src/mirall/sitecopyfolder.cpp index 52b4668be..1ee3ede37 100644 --- a/src/mirall/sitecopyfolder.cpp +++ b/src/mirall/sitecopyfolder.cpp @@ -139,6 +139,8 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus) emit syncFinished( SyncResult(SyncResult::Success) ); // mLocalChangesSeen = false; } else if( _NextStep == Status ) { + startSiteCopy( "--fetch", FlatList ); + } else if( _NextStep == FlatList ) { startSiteCopy( "--flatlist", DisplayStatus ); } else if( _NextStep == DisplayStatus ) { if( exitCode == 1 ) { diff --git a/src/mirall/sitecopyfolder.h b/src/mirall/sitecopyfolder.h index 085d286fc..989738909 100644 --- a/src/mirall/sitecopyfolder.h +++ b/src/mirall/sitecopyfolder.h @@ -29,7 +29,7 @@ class SiteCopyFolder : public Folder { Q_OBJECT public: - enum SiteCopyState { Sync, Update, Finish, Status, DisplayStatus }; + enum SiteCopyState { Sync, Update, Finish, Status, FlatList, DisplayStatus }; SiteCopyFolder(const QString &alias, const QString &path,