Browse Source

Fix possible crash with folder watching

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
38cb4ccbd3
  1. 12
      src/bittorrent.cpp
  2. 30
      src/eventmanager.cpp
  3. 2
      src/options_imp.cpp
  4. 5
      src/scannedfoldersmodel.cpp
  5. 2
      src/scannedfoldersmodel.h

12
src/bittorrent.cpp

@ -281,12 +281,14 @@ void Bittorrent::configureSession() {
startTorrentsInPause(Preferences::addTorrentsInPause()); startTorrentsInPause(Preferences::addTorrentsInPause());
// * Scan dirs // * Scan dirs
const QStringList &scan_dirs = Preferences::getScanDirs(); const QStringList &scan_dirs = Preferences::getScanDirs();
foreach (const QString &dir, scan_dirs) { QVariantList downloadInDirList = Preferences::getDownloadInScanDirs();
m_scanFolders->addPath(dir); while(scan_dirs.size() > downloadInDirList.size()) {
downloadInDirList << QVariant(false);
} }
const QVariantList &downloadInDirList = Preferences::getDownloadInScanDirs(); int i = 0;
for (int i = 0; i < downloadInDirList.count(); ++i) { foreach (const QString &dir, scan_dirs) {
m_scanFolders->setDownloadAtPath(i, downloadInDirList.at(i).toBool()); m_scanFolders->addPath(dir, downloadInDirList.at(i).toBool());
++i;
} }
// * Export Dir // * Export Dir
const bool newTorrentExport = Preferences::isTorrentExportEnabled(); const bool newTorrentExport = Preferences::isTorrentExportEnabled();

30
src/eventmanager.cpp

@ -130,25 +130,29 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool()); Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool());
if(m.contains("temp_path")) if(m.contains("temp_path"))
Preferences::setTempPath(m["temp_path"].toString()); 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 old_folders = Preferences::getScanDirs();
QStringList new_folders = m["scan_dirs"].toStringList(); QStringList new_folders = m["scan_dirs"].toStringList();
foreach(const QString &old_folder, old_folders) { Preferences::setScanDirs(new_folders);
// Update deleted folders Preferences::setDownloadInScanDirs(download_at_path);
if(!new_folders.contains(old_folder)) { if(download_at_path.size() == new_folders.size()) {
BTSession->getScanFoldersModel()->removePath(old_folder); 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) { foreach(const QString &new_folder, new_folders) {
// Update new folders // Update new folders
if(!old_folders.contains(new_folder)) { if(!old_folders.contains(new_folder)) {
BTSession->getScanFoldersModel()->addPath(new_folder); BTSession->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i).toBool());
}
++i;
} }
} }
Preferences::setScanDirs(new_folders);
} }
if(m.contains("download_in_scan_dirs"))
Preferences::setDownloadInScanDirs(m["download_in_scan_dirs"].toList());
if(m.contains("export_dir")) if(m.contains("export_dir"))
Preferences::setExportDir(m["export_dir"].toString()); Preferences::setExportDir(m["export_dir"].toString());
if(m.contains("preallocate_all")) if(m.contains("preallocate_all"))

2
src/options_imp.cpp

@ -1379,7 +1379,7 @@ int options_imp::getActionOnDblClOnTorrentFn() const {
void options_imp::on_addScanFolderButton_clicked() { 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"));
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir); const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, false);
QString error; QString error;
switch (status) { switch (status) {
case ScanFoldersModel::AlreadyInList: case ScanFoldersModel::AlreadyInList:

5
src/scannedfoldersmodel.cpp

@ -110,7 +110,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
return true; return true;
} }
ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path) { ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path, bool download_at_path) {
QDir dir(path); QDir dir(path);
if (!dir.exists()) if (!dir.exists())
return DoesNotExist; return DoesNotExist;
@ -126,6 +126,9 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path) {
beginInsertRows(QModelIndex(), rowCount(), rowCount()); beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_pathList << new PathData(canonicalPath); m_pathList << new PathData(canonicalPath);
endInsertRows(); endInsertRows();
// Set download at path
setDownloadAtPath(m_pathList.size()-1, download_at_path);
// Start scanning
m_fsWatcher->addPath(canonicalPath); m_fsWatcher->addPath(canonicalPath);
return Ok; return Ok;
} }

2
src/scannedfoldersmodel.h

@ -55,7 +55,7 @@ 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 &path); PathStatus addPath(const QString &path, bool download_at_path);
void removePath(int row); void removePath(int row);
bool removePath(const QString &path); bool removePath(const QString &path);
PathStatus setDownloadAtPath(int row, bool downloadAtPath); PathStatus setDownloadAtPath(int row, bool downloadAtPath);

Loading…
Cancel
Save