From fbb46b64f9f4da1c8c8eabcc7c7a4a737dd37358 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 30 Oct 2012 12:42:17 +0100 Subject: [PATCH] Check if local folder is proper and set error stat accordingly. --- src/mirall/folder.cpp | 37 +++++++++++++++++++++++++++++++++---- src/mirall/folder.h | 2 ++ src/mirall/folderman.cpp | 8 -------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 0e763c6db..d841a5142 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -70,18 +70,47 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP _online = true; #endif - _pathWatcher = new QFileSystemWatcher(this); - _pathWatcher->addPath( _path ); - connect(_pathWatcher, SIGNAL(directoryChanged(QString)),SLOT(slotLocalPathChanged(QString))); - _syncResult.setStatus( SyncResult::NotYetStarted ); + // check if the local path exists + checkLocalPath(); + } Folder::~Folder() { } +void Folder::checkLocalPath() +{ + QFileInfo fi(_path); + + if( fi.isDir() && fi.isReadable() ) { + qDebug() << "Checked local path ok"; + } else { + _syncResult.setStatus( SyncResult::SetupError ); + setSyncEnabled(false); + + if( !fi.exists() ) { + _syncResult.setErrorString(tr("The local folder %1 does not exist.").arg(_path)); + } else { + if( !fi.isDir() ) { + _syncResult.setErrorString(tr("Path %1 should be a directory but is not.").arg(_path)); + } else if( !fi.isReadable() ) { + _syncResult.setErrorString(tr("Path %1 is not readable.").arg(_path)); + } + } + } + + // if all is fine, connect a FileSystemWatcher + if( _syncResult.status() != SyncResult::SetupError ) { + _pathWatcher = new QFileSystemWatcher(this); + _pathWatcher->addPath( _path ); + connect(_pathWatcher, SIGNAL(directoryChanged(QString)), + SLOT(slotLocalPathChanged(QString))); + } +} + QString Folder::alias() const { return _alias; diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 992fc3494..bc17d098f 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -192,6 +192,8 @@ private: */ void evaluateSync(const QStringList &pathList); + virtual void checkLocalPath(); + QString _path; QString _secondPath; QString _alias; diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 5c3d0f635..37b29b661 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -169,14 +169,6 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) { settings.beginGroup( escapedAlias ); // read the group with the same name as the file which is the folder alias QString path = settings.value(QLatin1String("localpath")).toString(); - if ( path.isNull() || !QFileInfo( path ).isDir() ) { - qWarning() << " `->" << path << "does not exist. Skipping folder" << file; - // _tray->showMessage(tr("Unknown folder"), - // tr("Folder %1 does not exist").arg(path.toString()), - // QSystemTrayIcon::Critical); - return folder; - } - QString backend = settings.value(QLatin1String("backend")).toString(); QString targetPath = settings.value( QLatin1String("targetPath") ).toString(); // QString connection = settings.value( QLatin1String("connection") ).toString();