bool ScanFoldersModel::downloadInDefaultFolder(const QString &filePath) const { const int row = findPathData(QFileInfo(filePath).dir().path()); Q_ASSERT(row != -1); const PathData *data = m_pathList.at(row); return (data->downloadType == DEFAULT_LOCATION); }
bool ScanFoldersModel::downloadInWatchFolder(const QString &filePath) const { const int row = findPathData(QFileInfo(filePath).dir().path()); Q_ASSERT(row != -1); const PathData *data = m_pathList.at(row); return (data->downloadType == DOWNLOAD_IN_WATCH_FOLDER); }
ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath, bool addToFSWatcher) { const QDir watchDir(watchPath); if (!watchDir.exists()) return DoesNotExist; if (!watchDir.isReadable()) return CannotRead; const QString canonicalWatchPath = watchDir.canonicalPath(); if (findPathData(canonicalWatchPath) != -1) return AlreadyInList; const QDir downloadDir(downloadPath); const QString canonicalDownloadPath = downloadDir.canonicalPath(); if (!m_fsWatcher) { m_fsWatcher = new FileSystemWatcher(this); connect(m_fsWatcher, &FileSystemWatcher::torrentsAdded, this, &ScanFoldersModel::addTorrentsToSession); } beginInsertRows(QModelIndex(), rowCount(), rowCount()); m_pathList << new PathData(Utils::Fs::toNativePath(canonicalWatchPath), downloadType, Utils::Fs::toNativePath(canonicalDownloadPath)); endInsertRows(); // Start scanning if (addToFSWatcher) m_fsWatcher->addPath(canonicalWatchPath); return Ok; }
bool ScanFoldersModel::removePath(const QString &path, const bool removeFromFSWatcher) { const int row = findPathData(path); if (row == -1) return false; removePath(row, removeFromFSWatcher); return true; }
QString ScanFoldersModel::downloadPathTorrentFolder(const QString &filePath) const { const int row = findPathData(QFileInfo(filePath).dir().path()); Q_ASSERT(row != -1); const PathData *data = m_pathList.at(row); if (data->downloadType == CUSTOM_LOCATION) return data->downloadPath; return {}; }
ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path, bool downloadAtPath, const QString &downloadPath) { QDir dir(path); if (!dir.exists()) return DoesNotExist; if (!dir.isReadable()) return CannotRead; const QString &canonicalPath = dir.canonicalPath(); if (findPathData(canonicalPath) != -1) return AlreadyInList; if (!m_fsWatcher) { m_fsWatcher = new FileSystemWatcher(this); connect(m_fsWatcher, SIGNAL(torrentsAdded(const QStringList &)), this, SLOT(addTorrentsToSession(const QStringList &))); }
ScanFoldersModel::PathStatus ScanFoldersModel::updatePath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath) { const QDir watchDir(watchPath); const QString canonicalWatchPath = watchDir.canonicalPath(); const int row = findPathData(canonicalWatchPath); if (row == -1) return DoesNotExist; const QDir downloadDir(downloadPath); const QString canonicalDownloadPath = downloadDir.canonicalPath(); m_pathList.at(row)->downloadType = downloadType; m_pathList.at(row)->downloadPath = Utils::Fs::toNativePath(canonicalDownloadPath); return Ok; }