diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 356d5f886..4d63cdc42 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -187,7 +187,7 @@ void Application::slotAddFolder() SitecopyConfig scConfig; scConfig.writeSiteConfig( _folderWizard->field("sourceFolder").toString(), /* local path */ - alias, /* _folderWizard->field("OCSiteAlias").toString(), site alias */ + alias, _folderWizard->field("OCUrl").toString(), /* site URL */ _folderWizard->field("OCUser").toString(), _folderWizard->field("OCPasswd").toString(), diff --git a/src/mirall/owncloudsetup.cpp b/src/mirall/owncloudsetup.cpp index 2b3d30f30..bc7f22363 100644 --- a/src/mirall/owncloudsetup.cpp +++ b/src/mirall/owncloudsetup.cpp @@ -19,7 +19,7 @@ #include "owncloudsetup.h" #include "mirall/sitecopyconfig.h" - +#include "mirall/sitecopyfolder.h" namespace Mirall { @@ -257,7 +257,7 @@ bool OwncloudSetup::checkOwncloudAdmin( const QString& bin ) void OwncloudSetup::setupLocalSyncFolder() { - QString syncFolder( QDir::homePath() + "/ownCloud" ); + const QString syncFolder( QDir::homePath() + "/ownCloud" ); qDebug() << "Setup local sync folder " << syncFolder; QDir fi( syncFolder ); _ocWizard->appendToResultWidget( tr("creating local sync folder %1").arg(syncFolder) ); @@ -283,16 +283,10 @@ void OwncloudSetup::setupLocalSyncFolder() 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"; + // now there is the sitecopy config. A fetch in to the newly created folder mirrors + // the files from the ownCloud to local + startFetchFromOC( syncFolder ); - 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(); @@ -300,5 +294,43 @@ void OwncloudSetup::setupLocalSyncFolder() } } +void OwncloudSetup::startFetchFromOC( const QString& syncFolder ) +{ + _scf = new SiteCopyFolder( "ownCloud", + syncFolder, + QString(), + this); + connect( _scf, SIGNAL( syncFinished( const SyncResult& )), + SLOT( slotFetchFinished( const SyncResult& ))); + _ocWizard->appendToResultWidget( tr("Starting initial fetch of ownCloud data...")); + _scf->fetchFromOC(); +} + +void OwncloudSetup::slotFetchFinished( const SyncResult& res ) +{ + qDebug() << "Initial fetch finished!"; + if( res.result() == SyncResult::Error ) { + _ocWizard->appendToResultWidget( tr("Initial fetch of data failed: ") + res.errorString() ); + } else { + // fetch of data from ownCloud succeeded. + _ocWizard->appendToResultWidget( tr("Initial fetch of data succeeded.") ); + _ocWizard->appendToResultWidget( tr("Writing mirall folder setting now.") ); + // create a mirall folder entry. + // FIXME: folderConfigPath is a method of application object, copied to here. + const QString folderConfigPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/folders"; + + const QString syncFolder( QDir::homePath() + "/ownCloud" ); + const QString targetPath("/"); + + 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(); + } + _scf->deleteLater(); +} + } #include "owncloudsetup.moc" diff --git a/src/mirall/owncloudsetup.h b/src/mirall/owncloudsetup.h index ad32dc276..f240a2aa9 100644 --- a/src/mirall/owncloudsetup.h +++ b/src/mirall/owncloudsetup.h @@ -23,6 +23,8 @@ namespace Mirall { +class SiteCopyFolder; +class SyncResult; class OwncloudSetup : public QObject { @@ -40,6 +42,8 @@ public: QString mirallConfigFile() const; + void startFetchFromOC( const QString& ); + /** * returns the configured owncloud url if its already configured, otherwise an empty * string. @@ -62,6 +66,7 @@ protected slots: void slotError( QProcess::ProcessError ); void slotStarted(); void slotFinished( int, QProcess::ExitStatus ); + void slotFetchFinished( const SyncResult& ); // wizard dialog signals void slotInstallOCServer(); @@ -74,6 +79,7 @@ private: OwncloudWizard *_ocWizard; QProcess *_process; + SiteCopyFolder *_scf; }; }; diff --git a/src/mirall/sitecopyfolder.cpp b/src/mirall/sitecopyfolder.cpp index 1ee3ede37..e6d16372e 100644 --- a/src/mirall/sitecopyfolder.cpp +++ b/src/mirall/sitecopyfolder.cpp @@ -24,10 +24,10 @@ namespace Mirall { - SiteCopyFolder::SiteCopyFolder(const QString &alias, - const QString &path, - const QString &secondPath, - QObject *parent) + SiteCopyFolder::SiteCopyFolder( const QString &alias, + const QString &path, + const QString &secondPath, + QObject *parent) : Folder(alias, path, parent), _SiteCopy(new QProcess(this)), _syncCount(0) @@ -72,9 +72,16 @@ void SiteCopyFolder::startSync(const QStringList &pathList) emit syncStarted(); qDebug() << "PATHLIST: " << pathList; - startSiteCopy( "--fetch", Status ); + startSiteCopy( "--fetch", FlatList ); } +void SiteCopyFolder::fetchFromOC() +{ + QMutexLocker locker( &_syncMutex ); + qDebug() << "starting to sync from ownCloud"; + + startSiteCopy( "--fetch", Sync ); +} void SiteCopyFolder::startSiteCopy( const QString& command, SiteCopyState nextState ) { @@ -141,8 +148,8 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus) } else if( _NextStep == Status ) { startSiteCopy( "--fetch", FlatList ); } else if( _NextStep == FlatList ) { - startSiteCopy( "--flatlist", DisplayStatus ); - } else if( _NextStep == DisplayStatus ) { + startSiteCopy( "--flatlist", ExecuteStatus ); + } else if( _NextStep == ExecuteStatus ) { if( exitCode == 1 ) { qDebug() << "Exit-Code: Sync Needed!"; analyzeStatus(); diff --git a/src/mirall/sitecopyfolder.h b/src/mirall/sitecopyfolder.h index 989738909..cb7b8bd45 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, FlatList, DisplayStatus }; + enum SiteCopyState { Sync, Update, Finish, Status, FlatList, ExecuteStatus }; SiteCopyFolder(const QString &alias, const QString &path, @@ -38,6 +38,9 @@ public: virtual void startSync(const QStringList &pathList); + // load data from ownCloud to the local directory. + void fetchFromOC(); + virtual bool isBusy() const;