Browse Source

Don't add the watch folder before the user closes the Preferences window.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
990e33a4b1
  1. 17
      src/base/scanfoldersmodel.cpp
  2. 4
      src/base/scanfoldersmodel.h
  3. 3
      src/gui/options_imp.cpp

17
src/base/scanfoldersmodel.cpp

@ -203,7 +203,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
return true; 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); QDir watchDir(watchPath);
if (!watchDir.exists()) return DoesNotExist; if (!watchDir.exists()) return DoesNotExist;
@ -225,10 +225,23 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath,
endInsertRows(); endInsertRows();
// Start scanning // Start scanning
m_fsWatcher->addPath(canonicalWatchPath); if (addToFSWatcher)
m_fsWatcher->addPath(canonicalWatchPath);
return Ok; 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) void ScanFoldersModel::removePath(int row)
{ {
Q_ASSERT((row >= 0) && (row < rowCount())); Q_ASSERT((row >= 0) && (row < rowCount()));

4
src/base/scanfoldersmodel.h

@ -81,7 +81,9 @@ public:
// TODO: removePaths(); singular version becomes private helper functions; // TODO: removePaths(); singular version becomes private helper functions;
// also: remove functions should take modelindexes // 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); void removePath(int row);
bool removePath(const QString &path); bool removePath(const QString &path);

3
src/gui/options_imp.cpp

@ -418,6 +418,7 @@ 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()->addToFSWatcher(addedScanDirs);
ScanFoldersModel::instance()->makePersistent(); ScanFoldersModel::instance()->makePersistent();
addedScanDirs.clear(); addedScanDirs.clear();
pref->setTorrentExportDir(getTorrentExportDir()); pref->setTorrentExportDir(getTorrentExportDir());
@ -1203,7 +1204,7 @@ void options_imp::on_addScanFolderButton_clicked()
const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan"), const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan"),
Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath()))); Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath())));
if (!dir.isEmpty()) { 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; QString error;
switch (status) { switch (status) {
case ScanFoldersModel::AlreadyInList: case ScanFoldersModel::AlreadyInList:

Loading…
Cancel
Save