From 06be9edfe1d92140d9ec7c6a689dd0f8801a6239 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 2 Jan 2016 01:23:26 +0200 Subject: [PATCH] Remove watch folders permanently only if the user accepts the Preferences dialog. --- src/base/scanfoldersmodel.cpp | 15 +++++++++++---- src/base/scanfoldersmodel.h | 9 ++++++--- src/gui/options_imp.cpp | 9 ++++++++- src/gui/options_imp.h | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index a001c30b8..5349bb85d 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -268,24 +268,31 @@ void ScanFoldersModel::addToFSWatcher(const QStringList &watchPaths) } } -void ScanFoldersModel::removePath(int row) +void ScanFoldersModel::removePath(int row, bool removeFromFSWatcher) { Q_ASSERT((row >= 0) && (row < rowCount())); beginRemoveRows(QModelIndex(), row, row); - m_fsWatcher->removePath(m_pathList.at(row)->watchPath); + if (removeFromFSWatcher) + m_fsWatcher->removePath(m_pathList.at(row)->watchPath); delete m_pathList.takeAt(row); endRemoveRows(); } -bool ScanFoldersModel::removePath(const QString &path) +bool ScanFoldersModel::removePath(const QString &path, bool removeFromFSWatcher) { const int row = findPathData(path); if (row == -1) return false; - removePath(row); + removePath(row, removeFromFSWatcher); return true; } +void ScanFoldersModel::removeFromFSWatcher(const QStringList &watchPaths) +{ + foreach (const QString &path, watchPaths) + m_fsWatcher->removePath(path); +} + bool ScanFoldersModel::downloadInWatchFolder(const QString &filePath) const { const int row = findPathData(QFileInfo(filePath).dir().path()); diff --git a/src/base/scanfoldersmodel.h b/src/base/scanfoldersmodel.h index 1dc62c5a5..25dfdfd22 100644 --- a/src/base/scanfoldersmodel.h +++ b/src/base/scanfoldersmodel.h @@ -85,13 +85,16 @@ public: PathStatus updatePath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath); // PRECONDITION: The paths must have been added with addPath() first. void addToFSWatcher(const QStringList &watchPaths); - void removePath(int row); - bool removePath(const QString &path); + void removePath(int row, bool removeFromFSWatcher = true); + bool removePath(const QString &path, bool removeFromFSWatcher = true); + void removeFromFSWatcher(const QStringList &watchPaths); void makePersistent(); -private slots: +public slots: void configure(); + +private slots: void addTorrentsToSession(const QStringList &pathList); private: diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index 2c33b7aaa..f1426fcab 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -308,6 +308,7 @@ options_imp::~options_imp() qDebug("-> destructing Options"); foreach (const QString &path, addedScanDirs) ScanFoldersModel::instance()->removePath(path); + ScanFoldersModel::instance()->configure(); // reloads "removed" paths delete scrollArea_advanced->layout(); delete advancedSettings; } @@ -418,8 +419,10 @@ void options_imp::saveOptions() pref->useAdditionDialog(useAdditionDialog()); pref->additionDialogFront(checkAdditionDialogFront->isChecked()); pref->addTorrentsInPause(addTorrentsInPause()); + ScanFoldersModel::instance()->removeFromFSWatcher(removedScanDirs); ScanFoldersModel::instance()->addToFSWatcher(addedScanDirs); ScanFoldersModel::instance()->makePersistent(); + removedScanDirs.clear(); addedScanDirs.clear(); pref->setTorrentExportDir(getTorrentExportDir()); pref->setFinishedTorrentExportDir(getFinishedTorrentExportDir()); @@ -1236,7 +1239,11 @@ void options_imp::on_removeScanFolderButton_clicked() if (selected.isEmpty()) return; Q_ASSERT(selected.count() == ScanFoldersModel::instance()->columnCount()); - ScanFoldersModel::instance()->removePath(selected.first().row()); + foreach (const QModelIndex &index, selected) { + if (index.column() == ScanFoldersModel::WATCH) + removedScanDirs << index.data().toString(); + } + ScanFoldersModel::instance()->removePath(selected.first().row(), false); } void options_imp::handleScanFolderViewSelectionChanged() diff --git a/src/gui/options_imp.h b/src/gui/options_imp.h index 4b7d7ffea..46ec23d67 100644 --- a/src/gui/options_imp.h +++ b/src/gui/options_imp.h @@ -172,6 +172,7 @@ private: QAbstractButton *applyButton; AdvancedSettings *advancedSettings; QList addedScanDirs; + QList removedScanDirs; // SSL Cert / key QByteArray m_sslCert, m_sslKey; };