diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index 310e21eca..c1e0b369b 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -203,7 +203,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, return true; } -ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath) +ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath, bool addToFSWatcher) { QDir watchDir(watchPath); if (!watchDir.exists()) return DoesNotExist; @@ -225,10 +225,23 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath, endInsertRows(); // Start scanning - m_fsWatcher->addPath(canonicalWatchPath); + if (addToFSWatcher) + m_fsWatcher->addPath(canonicalWatchPath); return Ok; } +void ScanFoldersModel::addToFSWatcher(const QStringList &watchPaths) +{ + if (!m_fsWatcher) + return; // addPath() wasn't called before this + + foreach (const QString &path, watchPaths) { + QDir watchDir(path); + const QString &canonicalWatchPath = watchDir.canonicalPath(); + m_fsWatcher->addPath(canonicalWatchPath); + } +} + void ScanFoldersModel::removePath(int row) { Q_ASSERT((row >= 0) && (row < rowCount())); diff --git a/src/base/scanfoldersmodel.h b/src/base/scanfoldersmodel.h index 31959ca75..e1b767c8b 100644 --- a/src/base/scanfoldersmodel.h +++ b/src/base/scanfoldersmodel.h @@ -81,7 +81,9 @@ public: // TODO: removePaths(); singular version becomes private helper functions; // also: remove functions should take modelindexes - PathStatus addPath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath); + PathStatus addPath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath, bool addToFSWatcher = true); + // PRECONDITION: The paths must have been added with addPath() first. + void addToFSWatcher(const QStringList &watchPaths); void removePath(int row); bool removePath(const QString &path); diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index d1fc939e7..9595834fa 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -418,6 +418,7 @@ void options_imp::saveOptions() pref->useAdditionDialog(useAdditionDialog()); pref->additionDialogFront(checkAdditionDialogFront->isChecked()); pref->addTorrentsInPause(addTorrentsInPause()); + ScanFoldersModel::instance()->addToFSWatcher(addedScanDirs); ScanFoldersModel::instance()->makePersistent(); addedScanDirs.clear(); pref->setTorrentExportDir(getTorrentExportDir()); @@ -1203,7 +1204,7 @@ void options_imp::on_addScanFolderButton_clicked() const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan"), Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath()))); if (!dir.isEmpty()) { - const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER, QString()); + const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER, QString(), false); QString error; switch (status) { case ScanFoldersModel::AlreadyInList: