diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 48d855654..972119381 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -281,12 +281,14 @@ void Bittorrent::configureSession() { startTorrentsInPause(Preferences::addTorrentsInPause()); // * Scan dirs const QStringList &scan_dirs = Preferences::getScanDirs(); - foreach (const QString &dir, scan_dirs) { - m_scanFolders->addPath(dir); + QVariantList downloadInDirList = Preferences::getDownloadInScanDirs(); + while(scan_dirs.size() > downloadInDirList.size()) { + downloadInDirList << QVariant(false); } - const QVariantList &downloadInDirList = Preferences::getDownloadInScanDirs(); - for (int i = 0; i < downloadInDirList.count(); ++i) { - m_scanFolders->setDownloadAtPath(i, downloadInDirList.at(i).toBool()); + int i = 0; + foreach (const QString &dir, scan_dirs) { + m_scanFolders->addPath(dir, downloadInDirList.at(i).toBool()); + ++i; } // * Export Dir const bool newTorrentExport = Preferences::isTorrentExportEnabled(); diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index af8054a8d..36d10c57e 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -130,25 +130,29 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool()); if(m.contains("temp_path")) Preferences::setTempPath(m["temp_path"].toString()); - if(m.contains("scan_dirs")) { + if(m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) { + QVariantList download_at_path = m["download_in_scan_dirs"].toList(); QStringList old_folders = Preferences::getScanDirs(); QStringList new_folders = m["scan_dirs"].toStringList(); - foreach(const QString &old_folder, old_folders) { - // Update deleted folders - if(!new_folders.contains(old_folder)) { - BTSession->getScanFoldersModel()->removePath(old_folder); - } - } - foreach(const QString &new_folder, new_folders) { - // Update new folders - if(!old_folders.contains(new_folder)) { - BTSession->getScanFoldersModel()->addPath(new_folder); - } - } Preferences::setScanDirs(new_folders); + Preferences::setDownloadInScanDirs(download_at_path); + if(download_at_path.size() == new_folders.size()) { + foreach(const QString &old_folder, old_folders) { + // Update deleted folders + if(!new_folders.contains(old_folder)) { + BTSession->getScanFoldersModel()->removePath(old_folder); + } + } + int i = 0; + foreach(const QString &new_folder, new_folders) { + // Update new folders + if(!old_folders.contains(new_folder)) { + BTSession->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i).toBool()); + } + ++i; + } + } } - if(m.contains("download_in_scan_dirs")) - Preferences::setDownloadInScanDirs(m["download_in_scan_dirs"].toList()); if(m.contains("export_dir")) Preferences::setExportDir(m["export_dir"].toString()); if(m.contains("preallocate_all")) diff --git a/src/options_imp.cpp b/src/options_imp.cpp index c9c75d095..0b4f6f733 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -1379,7 +1379,7 @@ int options_imp::getActionOnDblClOnTorrentFn() const { void options_imp::on_addScanFolderButton_clicked() { const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan")); if (!dir.isEmpty()) { - const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir); + const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, false); QString error; switch (status) { case ScanFoldersModel::AlreadyInList: diff --git a/src/scannedfoldersmodel.cpp b/src/scannedfoldersmodel.cpp index 0aceb7511..b3a3dc9c4 100644 --- a/src/scannedfoldersmodel.cpp +++ b/src/scannedfoldersmodel.cpp @@ -110,7 +110,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, return true; } -ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path) { +ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path, bool download_at_path) { QDir dir(path); if (!dir.exists()) return DoesNotExist; @@ -126,6 +126,9 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); m_pathList << new PathData(canonicalPath); endInsertRows(); + // Set download at path + setDownloadAtPath(m_pathList.size()-1, download_at_path); + // Start scanning m_fsWatcher->addPath(canonicalPath); return Ok; } diff --git a/src/scannedfoldersmodel.h b/src/scannedfoldersmodel.h index 9352532ac..b49af50fe 100644 --- a/src/scannedfoldersmodel.h +++ b/src/scannedfoldersmodel.h @@ -55,7 +55,7 @@ public: // TODO: removePaths(); singular version becomes private helper functions; // also: remove functions should take modelindexes - PathStatus addPath(const QString &path); + PathStatus addPath(const QString &path, bool download_at_path); void removePath(int row); bool removePath(const QString &path); PathStatus setDownloadAtPath(int row, bool downloadAtPath);