Create the local sync folder successfully

This commit is contained in:
Klaas Freitag 2011-09-30 14:19:26 +02:00
parent 7452f1956e
commit 35aee0de00
6 changed files with 79 additions and 6 deletions

View file

@ -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 */

View file

@ -4,6 +4,8 @@
#include <QDesktopServices>
#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("<font color=\"red\">Installation of ownCloud failed!</font>") );
emit ownCloudSetupFinished( true );
} else {
// Successful installation. Write the config.
_ocWizard->appendToResultWidget( tr("<font color=\"green\">Installation of ownCloud succeeded!</font>") );
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"

View file

@ -31,8 +31,12 @@ public:
* string.
*/
QString ownCloudUrl() const ;
QString ownCloudUser() const ;
QString ownCloudPasswd() const ;
void setupLocalSyncFolder();
signals:
void ownCloudSetupFinished( bool );
public slots:

View file

@ -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('/')) ) {

View file

@ -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 ) {

View file

@ -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,