Browse Source

Remove watch folders permanently only if the user accepts the Preferences dialog.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
06be9edfe1
  1. 15
      src/base/scanfoldersmodel.cpp
  2. 9
      src/base/scanfoldersmodel.h
  3. 9
      src/gui/options_imp.cpp
  4. 1
      src/gui/options_imp.h

15
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())); Q_ASSERT((row >= 0) && (row < rowCount()));
beginRemoveRows(QModelIndex(), row, row); 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); delete m_pathList.takeAt(row);
endRemoveRows(); endRemoveRows();
} }
bool ScanFoldersModel::removePath(const QString &path) bool ScanFoldersModel::removePath(const QString &path, bool removeFromFSWatcher)
{ {
const int row = findPathData(path); const int row = findPathData(path);
if (row == -1) return false; if (row == -1) return false;
removePath(row); removePath(row, removeFromFSWatcher);
return true; return true;
} }
void ScanFoldersModel::removeFromFSWatcher(const QStringList &watchPaths)
{
foreach (const QString &path, watchPaths)
m_fsWatcher->removePath(path);
}
bool ScanFoldersModel::downloadInWatchFolder(const QString &filePath) const bool ScanFoldersModel::downloadInWatchFolder(const QString &filePath) const
{ {
const int row = findPathData(QFileInfo(filePath).dir().path()); const int row = findPathData(QFileInfo(filePath).dir().path());

9
src/base/scanfoldersmodel.h

@ -85,13 +85,16 @@ public:
PathStatus updatePath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath); PathStatus updatePath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath);
// PRECONDITION: The paths must have been added with addPath() first. // PRECONDITION: The paths must have been added with addPath() first.
void addToFSWatcher(const QStringList &watchPaths); void addToFSWatcher(const QStringList &watchPaths);
void removePath(int row); void removePath(int row, bool removeFromFSWatcher = true);
bool removePath(const QString &path); bool removePath(const QString &path, bool removeFromFSWatcher = true);
void removeFromFSWatcher(const QStringList &watchPaths);
void makePersistent(); void makePersistent();
private slots: public slots:
void configure(); void configure();
private slots:
void addTorrentsToSession(const QStringList &pathList); void addTorrentsToSession(const QStringList &pathList);
private: private:

9
src/gui/options_imp.cpp

@ -308,6 +308,7 @@ options_imp::~options_imp()
qDebug("-> destructing Options"); qDebug("-> destructing Options");
foreach (const QString &path, addedScanDirs) foreach (const QString &path, addedScanDirs)
ScanFoldersModel::instance()->removePath(path); ScanFoldersModel::instance()->removePath(path);
ScanFoldersModel::instance()->configure(); // reloads "removed" paths
delete scrollArea_advanced->layout(); delete scrollArea_advanced->layout();
delete advancedSettings; delete advancedSettings;
} }
@ -418,8 +419,10 @@ void options_imp::saveOptions()
pref->useAdditionDialog(useAdditionDialog()); pref->useAdditionDialog(useAdditionDialog());
pref->additionDialogFront(checkAdditionDialogFront->isChecked()); pref->additionDialogFront(checkAdditionDialogFront->isChecked());
pref->addTorrentsInPause(addTorrentsInPause()); pref->addTorrentsInPause(addTorrentsInPause());
ScanFoldersModel::instance()->removeFromFSWatcher(removedScanDirs);
ScanFoldersModel::instance()->addToFSWatcher(addedScanDirs); ScanFoldersModel::instance()->addToFSWatcher(addedScanDirs);
ScanFoldersModel::instance()->makePersistent(); ScanFoldersModel::instance()->makePersistent();
removedScanDirs.clear();
addedScanDirs.clear(); addedScanDirs.clear();
pref->setTorrentExportDir(getTorrentExportDir()); pref->setTorrentExportDir(getTorrentExportDir());
pref->setFinishedTorrentExportDir(getFinishedTorrentExportDir()); pref->setFinishedTorrentExportDir(getFinishedTorrentExportDir());
@ -1236,7 +1239,11 @@ void options_imp::on_removeScanFolderButton_clicked()
if (selected.isEmpty()) if (selected.isEmpty())
return; return;
Q_ASSERT(selected.count() == ScanFoldersModel::instance()->columnCount()); 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() void options_imp::handleScanFolderViewSelectionChanged()

1
src/gui/options_imp.h

@ -172,6 +172,7 @@ private:
QAbstractButton *applyButton; QAbstractButton *applyButton;
AdvancedSettings *advancedSettings; AdvancedSettings *advancedSettings;
QList<QString> addedScanDirs; QList<QString> addedScanDirs;
QList<QString> removedScanDirs;
// SSL Cert / key // SSL Cert / key
QByteArray m_sslCert, m_sslKey; QByteArray m_sslCert, m_sslKey;
}; };

Loading…
Cancel
Save