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

30
src/eventmanager.cpp

@ -130,25 +130,29 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { @@ -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);
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);
}
}
}
foreach(const QString &new_folder, new_folders) {
// Update new folders
if(!old_folders.contains(new_folder)) {
BTSession->getScanFoldersModel()->addPath(new_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;
}
}
Preferences::setScanDirs(new_folders);
}
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"))

2
src/options_imp.cpp

@ -1379,7 +1379,7 @@ int options_imp::getActionOnDblClOnTorrentFn() const { @@ -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:

5
src/scannedfoldersmodel.cpp

@ -110,7 +110,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, @@ -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) { @@ -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;
}

2
src/scannedfoldersmodel.h

@ -55,7 +55,7 @@ public: @@ -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);

Loading…
Cancel
Save