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

This commit is contained in:
sledgehammer999 2016-01-02 01:23:26 +02:00
parent 9c88959651
commit 06be9edfe1
4 changed files with 26 additions and 8 deletions

View File

@ -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());

View File

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

View File

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

View File

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