Fix possible crash with folder watching

This commit is contained in:
Christophe Dumez 2010-03-22 18:50:04 +00:00
parent 8ccaaae085
commit 38cb4ccbd3
5 changed files with 32 additions and 23 deletions

View file

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

View file

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

View file

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

View file

@ -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;
}

View file

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