mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Improve the "Watch folders" UI. Closes #4300.
This commit is contained in:
parent
e9547f7a1c
commit
bc92f156c1
@ -475,46 +475,15 @@ void Preferences::addTorrentsInPause(bool b)
|
|||||||
setValue("Preferences/Downloads/StartInPause", b);
|
setValue("Preferences/Downloads/StartInPause", b);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Preferences::getScanDirs() const
|
QVariantHash Preferences::getScanDirs() const
|
||||||
{
|
{
|
||||||
QStringList originalList = value("Preferences/Downloads/ScanDirs").toStringList();
|
return value("Preferences/Downloads/ScanDirsV2").toHash();
|
||||||
if (originalList.isEmpty())
|
|
||||||
return originalList;
|
|
||||||
|
|
||||||
QStringList newList;
|
|
||||||
foreach (const QString& s, originalList)
|
|
||||||
newList << Utils::Fs::fromNativePath(s);
|
|
||||||
return newList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be called somewhere with data from the model
|
// This must be called somewhere with data from the model
|
||||||
void Preferences::setScanDirs(const QStringList &dirs)
|
void Preferences::setScanDirs(const QVariantHash &dirs)
|
||||||
{
|
{
|
||||||
QStringList newList;
|
setValue("Preferences/Downloads/ScanDirsV2", dirs);
|
||||||
if (!dirs.isEmpty())
|
|
||||||
foreach (const QString& s, dirs)
|
|
||||||
newList << Utils::Fs::fromNativePath(s);
|
|
||||||
setValue("Preferences/Downloads/ScanDirs", newList);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<bool> Preferences::getDownloadInScanDirs() const
|
|
||||||
{
|
|
||||||
return Utils::Misc::boolListfromStringList(value("Preferences/Downloads/DownloadInScanDirs").toStringList());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Preferences::setDownloadInScanDirs(const QList<bool> &list)
|
|
||||||
{
|
|
||||||
setValue("Preferences/Downloads/DownloadInScanDirs", Utils::Misc::toStringList(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Preferences::setScanDirsDownloadPaths(const QStringList &downloadpaths)
|
|
||||||
{
|
|
||||||
setValue("Preferences/Downloads/ScanDirsDownloadPaths", downloadpaths);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList Preferences::getScanDirsDownloadPaths() const
|
|
||||||
{
|
|
||||||
return value("Preferences/Downloads/ScanDirsDownloadPaths").toStringList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Preferences::getScanDirsLastPath() const
|
QString Preferences::getScanDirsLastPath() const
|
||||||
|
@ -176,13 +176,9 @@ public:
|
|||||||
void additionDialogFront(bool b);
|
void additionDialogFront(bool b);
|
||||||
bool addTorrentsInPause() const;
|
bool addTorrentsInPause() const;
|
||||||
void addTorrentsInPause(bool b);
|
void addTorrentsInPause(bool b);
|
||||||
QStringList getScanDirs() const;
|
QVariantHash getScanDirs() const;
|
||||||
void setScanDirs(const QStringList &dirs);
|
void setScanDirs(const QVariantHash &dirs);
|
||||||
QList<bool> getDownloadInScanDirs() const;
|
|
||||||
void setDownloadInScanDirs(const QList<bool> &list);
|
|
||||||
QString getScanDirsLastPath() const;
|
QString getScanDirsLastPath() const;
|
||||||
void setScanDirsDownloadPaths(const QStringList &downloadpaths);
|
|
||||||
QStringList getScanDirsDownloadPaths() const;
|
|
||||||
void setScanDirsLastPath(const QString &path);
|
void setScanDirsLastPath(const QString &path);
|
||||||
bool isTorrentExportEnabled() const;
|
bool isTorrentExportEnabled() const;
|
||||||
QString getTorrentExportDir() const;
|
QString getTorrentExportDir() const;
|
||||||
|
@ -37,37 +37,25 @@
|
|||||||
#include "utils/misc.h"
|
#include "utils/misc.h"
|
||||||
#include "utils/fs.h"
|
#include "utils/fs.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
#include "logger.h"
|
||||||
#include "filesystemwatcher.h"
|
#include "filesystemwatcher.h"
|
||||||
#include "bittorrent/session.h"
|
#include "bittorrent/session.h"
|
||||||
#include "scanfoldersmodel.h"
|
#include "scanfoldersmodel.h"
|
||||||
|
|
||||||
namespace
|
struct ScanFoldersModel::PathData
|
||||||
{
|
{
|
||||||
const int PathColumn = 0;
|
PathData(const QString &watchPath, const PathType &type, const QString &downloadPath)
|
||||||
const int DownloadAtTorrentColumn = 1;
|
: watchPath(watchPath)
|
||||||
const int DownloadPath = 2;
|
, downloadType(type)
|
||||||
}
|
|
||||||
|
|
||||||
class ScanFoldersModel::PathData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PathData(const QString &path)
|
|
||||||
: path(path)
|
|
||||||
, downloadAtPath(false)
|
|
||||||
, downloadPath(path)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PathData(const QString &path, bool downloadAtPath, const QString &downloadPath)
|
|
||||||
: path(path)
|
|
||||||
, downloadAtPath(downloadAtPath)
|
|
||||||
, downloadPath(downloadPath)
|
, downloadPath(downloadPath)
|
||||||
{
|
{
|
||||||
|
if (this->downloadPath.isEmpty() && downloadType == CUSTOM_LOCATION)
|
||||||
|
downloadType = DEFAULT_LOCATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString path; //watching directory
|
QString watchPath;
|
||||||
bool downloadAtPath; //if TRUE save data to watching directory
|
PathType downloadType;
|
||||||
QString downloadPath; //if 'downloadAtPath' FALSE use this path for save data
|
QString downloadPath; // valid for CUSTOM_LOCATION
|
||||||
};
|
};
|
||||||
|
|
||||||
ScanFoldersModel *ScanFoldersModel::m_instance = 0;
|
ScanFoldersModel *ScanFoldersModel::m_instance = 0;
|
||||||
@ -96,7 +84,7 @@ ScanFoldersModel *ScanFoldersModel::instance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScanFoldersModel::ScanFoldersModel(QObject *parent)
|
ScanFoldersModel::ScanFoldersModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_fsWatcher(0)
|
, m_fsWatcher(0)
|
||||||
{
|
{
|
||||||
configure();
|
configure();
|
||||||
@ -116,7 +104,7 @@ int ScanFoldersModel::rowCount(const QModelIndex &parent) const
|
|||||||
int ScanFoldersModel::columnCount(const QModelIndex &parent) const
|
int ScanFoldersModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return 3;
|
return NB_COLUMNS;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
|
QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
|
||||||
@ -128,17 +116,17 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
|
|||||||
QVariant value;
|
QVariant value;
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case PathColumn:
|
case WATCH:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
value = Utils::Fs::toNativePath(pathData->path);
|
value = Utils::Fs::toNativePath(pathData->watchPath);
|
||||||
break;
|
break;
|
||||||
case DownloadAtTorrentColumn:
|
case DOWNLOAD:
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::DisplayRole) {
|
||||||
value = pathData->downloadAtPath ? Qt::Checked : Qt::Unchecked;
|
value = pathData->downloadType;
|
||||||
break;
|
}
|
||||||
case DownloadPath:
|
else if ((role == Qt::UserRole) && (pathData->downloadType == CUSTOM_LOCATION)) {
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::ToolTipRole)
|
value = pathData->downloadPath;
|
||||||
value = Utils::Fs::toNativePath(pathData->downloadPath);
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,14 +141,11 @@ QVariant ScanFoldersModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
QVariant title;
|
QVariant title;
|
||||||
|
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case PathColumn:
|
case WATCH:
|
||||||
title = tr("Watched Folder");
|
title = tr("Watched Folder");
|
||||||
break;
|
break;
|
||||||
case DownloadAtTorrentColumn:
|
case DOWNLOAD:
|
||||||
title = tr("Download here");
|
title = tr("Save Files to");
|
||||||
break;
|
|
||||||
case DownloadPath:
|
|
||||||
title = tr("Download path");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,23 +155,16 @@ QVariant ScanFoldersModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
Qt::ItemFlags ScanFoldersModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags ScanFoldersModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || (index.row() >= rowCount()))
|
if (!index.isValid() || (index.row() >= rowCount()))
|
||||||
return QAbstractTableModel::flags(index);
|
return QAbstractListModel::flags(index);
|
||||||
|
|
||||||
const PathData *pathData = m_pathList.at(index.row());
|
|
||||||
Qt::ItemFlags flags;
|
Qt::ItemFlags flags;
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case PathColumn:
|
case WATCH:
|
||||||
flags = QAbstractTableModel::flags(index);
|
flags = QAbstractListModel::flags(index);
|
||||||
break;
|
break;
|
||||||
case DownloadAtTorrentColumn:
|
case DOWNLOAD:
|
||||||
flags = QAbstractTableModel::flags(index) | Qt::ItemIsUserCheckable;
|
flags = QAbstractListModel::flags(index) | Qt::ItemIsEditable;
|
||||||
break;
|
|
||||||
case DownloadPath:
|
|
||||||
if (pathData->downloadAtPath == false)
|
|
||||||
flags = QAbstractTableModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled;
|
|
||||||
else
|
|
||||||
flags = QAbstractTableModel::flags(index) ^ Qt::ItemIsEnabled; //dont edit DownloadPath if checked 'downloadAtPath'
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,42 +173,46 @@ Qt::ItemFlags ScanFoldersModel::flags(const QModelIndex &index) const
|
|||||||
|
|
||||||
bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!index.isValid() || (index.row() >= rowCount()) || (index.column() > DownloadPath))
|
if (!index.isValid() || (index.row() >= rowCount()) || (index.column() >= columnCount())
|
||||||
|
|| (index.column() != DOWNLOAD))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool success = true;
|
if (role == Qt::DisplayRole) {
|
||||||
|
PathType type = static_cast<PathType>(value.toInt());
|
||||||
|
if (type == CUSTOM_LOCATION)
|
||||||
|
return false;
|
||||||
|
|
||||||
switch (index.column()) {
|
m_pathList[index.row()]->downloadType = type;
|
||||||
case PathColumn:
|
m_pathList[index.row()]->downloadPath.clear();
|
||||||
success = false;
|
|
||||||
break;
|
|
||||||
case DownloadAtTorrentColumn:
|
|
||||||
if (role == Qt::CheckStateRole) {
|
|
||||||
Q_ASSERT(index.column() == DownloadAtTorrentColumn);
|
|
||||||
m_pathList[index.row()]->downloadAtPath = (value.toInt() == Qt::Checked);
|
|
||||||
emit dataChanged(index, index);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DownloadPath:
|
|
||||||
Q_ASSERT(index.column() == DownloadPath);
|
|
||||||
m_pathList[index.row()]->downloadPath = value.toString();
|
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
success = true;
|
}
|
||||||
break;
|
else if (role == Qt::UserRole) {
|
||||||
|
QString path = value.toString();
|
||||||
|
if (path.isEmpty()) // means we didn't pass CUSTOM_LOCATION type
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_pathList[index.row()]->downloadType = CUSTOM_LOCATION;
|
||||||
|
m_pathList[index.row()]->downloadPath = Utils::Fs::toNativePath(path);
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path, bool downloadAtPath, const QString &downloadPath)
|
ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath)
|
||||||
{
|
{
|
||||||
QDir dir(path);
|
QDir watchDir(watchPath);
|
||||||
if (!dir.exists()) return DoesNotExist;
|
if (!watchDir.exists()) return DoesNotExist;
|
||||||
if (!dir.isReadable()) return CannotRead;
|
if (!watchDir.isReadable()) return CannotRead;
|
||||||
|
|
||||||
const QString &canonicalPath = dir.canonicalPath();
|
const QString &canonicalWatchPath = watchDir.canonicalPath();
|
||||||
if (findPathData(canonicalPath) != -1) return AlreadyInList;
|
if (findPathData(canonicalWatchPath) != -1) return AlreadyInList;
|
||||||
|
|
||||||
|
QDir downloadDir(downloadPath);
|
||||||
|
const QString &canonicalDownloadPath = downloadDir.canonicalPath();
|
||||||
|
|
||||||
if (!m_fsWatcher) {
|
if (!m_fsWatcher) {
|
||||||
m_fsWatcher = new FileSystemWatcher(this);
|
m_fsWatcher = new FileSystemWatcher(this);
|
||||||
@ -238,12 +220,11 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
QString downloadToPath = downloadPath.isEmpty() ? path : downloadPath;
|
m_pathList << new PathData(Utils::Fs::toNativePath(canonicalWatchPath), downloadType, Utils::Fs::toNativePath(canonicalDownloadPath));
|
||||||
m_pathList << new PathData(canonicalPath, downloadAtPath, downloadToPath);
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
// Start scanning
|
// Start scanning
|
||||||
m_fsWatcher->addPath(canonicalPath);
|
m_fsWatcher->addPath(canonicalWatchPath);
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,8 +232,8 @@ void ScanFoldersModel::removePath(int row)
|
|||||||
{
|
{
|
||||||
Q_ASSERT((row >= 0) && (row < rowCount()));
|
Q_ASSERT((row >= 0) && (row < rowCount()));
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
m_fsWatcher->removePath(m_pathList.at(row)->path);
|
m_fsWatcher->removePath(m_pathList.at(row)->watchPath);
|
||||||
m_pathList.removeAt(row);
|
delete m_pathList.takeAt(row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,43 +246,37 @@ bool ScanFoldersModel::removePath(const QString &path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanFoldersModel::PathStatus ScanFoldersModel::setDownloadAtPath(int row, bool downloadAtPath)
|
bool ScanFoldersModel::downloadInWatchFolder(const QString &filePath) const
|
||||||
{
|
|
||||||
Q_ASSERT((row >= 0) && (row < rowCount()));
|
|
||||||
|
|
||||||
bool &oldValue = m_pathList[row]->downloadAtPath;
|
|
||||||
if (oldValue != downloadAtPath) {
|
|
||||||
if (downloadAtPath) {
|
|
||||||
QTemporaryFile testFile(m_pathList[row]->path + "/tmpFile");
|
|
||||||
if (!testFile.open()) return CannotWrite;
|
|
||||||
}
|
|
||||||
|
|
||||||
oldValue = downloadAtPath;
|
|
||||||
const QModelIndex changedIndex = index(row, DownloadAtTorrentColumn);
|
|
||||||
emit dataChanged(changedIndex, changedIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScanFoldersModel::downloadInTorrentFolder(const QString &filePath) const
|
|
||||||
{
|
{
|
||||||
const int row = findPathData(QFileInfo(filePath).dir().path());
|
const int row = findPathData(QFileInfo(filePath).dir().path());
|
||||||
Q_ASSERT(row != -1);
|
Q_ASSERT(row != -1);
|
||||||
return m_pathList.at(row)->downloadAtPath;
|
PathData *data = m_pathList.at(row);
|
||||||
|
return (data->downloadType == DOWNLOAD_IN_WATCH_FOLDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScanFoldersModel::downloadInDefaultFolder(const QString &filePath) const
|
||||||
|
{
|
||||||
|
const int row = findPathData(QFileInfo(filePath).dir().path());
|
||||||
|
Q_ASSERT(row != -1);
|
||||||
|
PathData *data = m_pathList.at(row);
|
||||||
|
return (data->downloadType == DEFAULT_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScanFoldersModel::downloadPathTorrentFolder(const QString &filePath) const
|
QString ScanFoldersModel::downloadPathTorrentFolder(const QString &filePath) const
|
||||||
{
|
{
|
||||||
const int row = findPathData(QFileInfo(filePath).dir().path());
|
const int row = findPathData(QFileInfo(filePath).dir().path());
|
||||||
Q_ASSERT(row != -1);
|
Q_ASSERT(row != -1);
|
||||||
return m_pathList.at(row)->downloadPath;
|
PathData *data = m_pathList.at(row);
|
||||||
|
if (data->downloadType == CUSTOM_LOCATION)
|
||||||
|
return data->downloadPath;
|
||||||
|
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScanFoldersModel::findPathData(const QString &path) const
|
int ScanFoldersModel::findPathData(const QString &path) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_pathList.count(); ++i)
|
for (int i = 0; i < m_pathList.count(); ++i)
|
||||||
if (m_pathList.at(i)->path == Utils::Fs::fromNativePath(path))
|
if (m_pathList.at(i)->watchPath == Utils::Fs::toNativePath(path))
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -309,33 +284,27 @@ int ScanFoldersModel::findPathData(const QString &path) const
|
|||||||
|
|
||||||
void ScanFoldersModel::makePersistent()
|
void ScanFoldersModel::makePersistent()
|
||||||
{
|
{
|
||||||
Preferences *const pref = Preferences::instance();
|
QVariantHash dirs;
|
||||||
QStringList paths;
|
|
||||||
QList<bool> downloadInFolderInfo;
|
|
||||||
QStringList downloadPaths;
|
|
||||||
foreach (const PathData *pathData, m_pathList) {
|
foreach (const PathData *pathData, m_pathList) {
|
||||||
paths << pathData->path;
|
if (pathData->downloadType == CUSTOM_LOCATION)
|
||||||
downloadInFolderInfo << pathData->downloadAtPath;
|
dirs.insert(Utils::Fs::fromNativePath(pathData->watchPath), Utils::Fs::fromNativePath(pathData->downloadPath));
|
||||||
downloadPaths << pathData->downloadPath;
|
else
|
||||||
|
dirs.insert(Utils::Fs::fromNativePath(pathData->watchPath), pathData->downloadType);
|
||||||
}
|
}
|
||||||
|
|
||||||
pref->setScanDirs(paths);
|
Preferences::instance()->setScanDirs(dirs);
|
||||||
pref->setDownloadInScanDirs(downloadInFolderInfo);
|
|
||||||
pref->setScanDirsDownloadPaths(downloadPaths);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanFoldersModel::configure()
|
void ScanFoldersModel::configure()
|
||||||
{
|
{
|
||||||
Preferences *const pref = Preferences::instance();
|
QVariantHash dirs = Preferences::instance()->getScanDirs();
|
||||||
|
|
||||||
int i = 0;
|
for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) {
|
||||||
QStringList downloadPaths = pref->getScanDirsDownloadPaths();
|
if (i.value().type() == QVariant::Int)
|
||||||
QList<bool> downloadInDirList = pref->getDownloadInScanDirs();
|
addPath(i.key(), static_cast<PathType>(i.value().toInt()), QString());
|
||||||
foreach (const QString &dir, pref->getScanDirs()) {
|
else
|
||||||
bool downloadInDir = downloadInDirList.value(i, true);
|
addPath(i.key(), CUSTOM_LOCATION, i.value().toString());
|
||||||
QString downloadPath = downloadPaths.value(i); //empty string if out-of-bounds
|
|
||||||
addPath(dir, downloadInDir, downloadPath);
|
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,10 +312,17 @@ void ScanFoldersModel::addTorrentsToSession(const QStringList &pathList)
|
|||||||
{
|
{
|
||||||
foreach (const QString &file, pathList) {
|
foreach (const QString &file, pathList) {
|
||||||
qDebug("File %s added", qPrintable(file));
|
qDebug("File %s added", qPrintable(file));
|
||||||
|
|
||||||
|
BitTorrent::AddTorrentParams params;
|
||||||
|
if (downloadInWatchFolder(file))
|
||||||
|
params.savePath = QFileInfo(file).dir().path();
|
||||||
|
else if (!downloadInDefaultFolder(file))
|
||||||
|
params.savePath = downloadPathTorrentFolder(file);
|
||||||
|
|
||||||
if (file.endsWith(".magnet")) {
|
if (file.endsWith(".magnet")) {
|
||||||
QFile f(file);
|
QFile f(file);
|
||||||
if (f.open(QIODevice::ReadOnly)) {
|
if (f.open(QIODevice::ReadOnly)) {
|
||||||
BitTorrent::Session::instance()->addTorrent(QString::fromLocal8Bit(f.readAll()));
|
BitTorrent::Session::instance()->addTorrent(QString::fromLocal8Bit(f.readAll()), params);
|
||||||
f.remove();
|
f.remove();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -354,12 +330,6 @@ void ScanFoldersModel::addTorrentsToSession(const QStringList &pathList)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BitTorrent::AddTorrentParams params;
|
|
||||||
if (downloadInTorrentFolder(file))
|
|
||||||
params.savePath = QFileInfo(file).dir().path();
|
|
||||||
else
|
|
||||||
params.savePath = downloadPathTorrentFolder(file); //if empty it will use the default savePath
|
|
||||||
|
|
||||||
BitTorrent::TorrentInfo torrentInfo = BitTorrent::TorrentInfo::loadFromFile(file);
|
BitTorrent::TorrentInfo torrentInfo = BitTorrent::TorrentInfo::loadFromFile(file);
|
||||||
if (torrentInfo.isValid()) {
|
if (torrentInfo.isValid()) {
|
||||||
BitTorrent::Session::instance()->addTorrent(torrentInfo, params);
|
BitTorrent::Session::instance()->addTorrent(torrentInfo, params);
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#ifndef SCANFOLDERSMODEL_H
|
#ifndef SCANFOLDERSMODEL_H
|
||||||
#define SCANFOLDERSMODEL_H
|
#define SCANFOLDERSMODEL_H
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -40,7 +40,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
class FileSystemWatcher;
|
class FileSystemWatcher;
|
||||||
|
|
||||||
class ScanFoldersModel : public QAbstractTableModel
|
class ScanFoldersModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DISABLE_COPY(ScanFoldersModel)
|
Q_DISABLE_COPY(ScanFoldersModel)
|
||||||
@ -55,6 +55,20 @@ public:
|
|||||||
AlreadyInList
|
AlreadyInList
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Column
|
||||||
|
{
|
||||||
|
WATCH,
|
||||||
|
DOWNLOAD,
|
||||||
|
NB_COLUMNS
|
||||||
|
};
|
||||||
|
|
||||||
|
enum PathType
|
||||||
|
{
|
||||||
|
DOWNLOAD_IN_WATCH_FOLDER,
|
||||||
|
DEFAULT_LOCATION,
|
||||||
|
CUSTOM_LOCATION
|
||||||
|
};
|
||||||
|
|
||||||
static bool initInstance(QObject *parent = 0);
|
static bool initInstance(QObject *parent = 0);
|
||||||
static void freeInstance();
|
static void freeInstance();
|
||||||
static ScanFoldersModel *instance();
|
static ScanFoldersModel *instance();
|
||||||
@ -67,13 +81,10 @@ 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, bool downloadAtPath, const QString &downloadPath);
|
PathStatus addPath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath);
|
||||||
void removePath(int row);
|
void removePath(int row);
|
||||||
bool removePath(const QString &path);
|
bool removePath(const QString &path);
|
||||||
PathStatus setDownloadAtPath(int row, bool downloadAtPath);
|
|
||||||
|
|
||||||
bool downloadInTorrentFolder(const QString &filePath) const;
|
|
||||||
QString downloadPathTorrentFolder(const QString &filePath) const;
|
|
||||||
void makePersistent();
|
void makePersistent();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -85,10 +96,15 @@ private:
|
|||||||
~ScanFoldersModel();
|
~ScanFoldersModel();
|
||||||
|
|
||||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||||
static ScanFoldersModel *m_instance;
|
bool downloadInWatchFolder(const QString &filePath) const;
|
||||||
class PathData;
|
bool downloadInDefaultFolder(const QString &filePath) const;
|
||||||
|
QString downloadPathTorrentFolder(const QString &filePath) const;
|
||||||
int findPathData(const QString &path) const;
|
int findPathData(const QString &path) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static ScanFoldersModel *m_instance;
|
||||||
|
struct PathData;
|
||||||
|
|
||||||
QList<PathData*> m_pathList;
|
QList<PathData*> m_pathList;
|
||||||
FileSystemWatcher *m_fsWatcher;
|
FileSystemWatcher *m_fsWatcher;
|
||||||
};
|
};
|
||||||
|
@ -42,6 +42,7 @@ HEADERS += \
|
|||||||
$$PWD/shutdownconfirm.h \
|
$$PWD/shutdownconfirm.h \
|
||||||
$$PWD/torrentmodel.h \
|
$$PWD/torrentmodel.h \
|
||||||
$$PWD/torrentcreatordlg.h \
|
$$PWD/torrentcreatordlg.h \
|
||||||
|
$$PWD/scanfoldersdelegate.h \
|
||||||
$$PWD/search/searchwidget.h \
|
$$PWD/search/searchwidget.h \
|
||||||
$$PWD/search/searchtab.h \
|
$$PWD/search/searchtab.h \
|
||||||
$$PWD/search/pluginselectdlg.h \
|
$$PWD/search/pluginselectdlg.h \
|
||||||
@ -79,6 +80,7 @@ SOURCES += \
|
|||||||
$$PWD/shutdownconfirm.cpp \
|
$$PWD/shutdownconfirm.cpp \
|
||||||
$$PWD/torrentmodel.cpp \
|
$$PWD/torrentmodel.cpp \
|
||||||
$$PWD/torrentcreatordlg.cpp \
|
$$PWD/torrentcreatordlg.cpp \
|
||||||
|
$$PWD/scanfoldersdelegate.cpp \
|
||||||
$$PWD/search/searchwidget.cpp \
|
$$PWD/search/searchwidget.cpp \
|
||||||
$$PWD/search/searchtab.cpp \
|
$$PWD/search/searchtab.cpp \
|
||||||
$$PWD/search/pluginselectdlg.cpp \
|
$$PWD/search/pluginselectdlg.cpp \
|
||||||
|
@ -714,7 +714,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_16">
|
<layout class="QHBoxLayout" name="horizontalLayout_16">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="scanFoldersView">
|
<widget class="QTreeView" name="scanFoldersView">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -727,30 +727,24 @@
|
|||||||
<height>150</height>
|
<height>150</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::AllEditTriggers</set>
|
||||||
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::SingleSelection</enum>
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectRows</enum>
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="showGrid">
|
<property name="textElideMode">
|
||||||
|
<enum>Qt::ElideNone</enum>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sortingEnabled">
|
<attribute name="headerDefaultSectionSize">
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
|
||||||
<number>80</number>
|
<number>80</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="horizontalHeaderStretchLastSection">
|
|
||||||
<bool>true</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -41,15 +41,17 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "options_imp.h"
|
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "advancedsettings.h"
|
|
||||||
#include "base/scanfoldersmodel.h"
|
#include "base/scanfoldersmodel.h"
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "guiiconprovider.h"
|
|
||||||
#include "base/net/dnsupdater.h"
|
#include "base/net/dnsupdater.h"
|
||||||
#include "base/unicodestrings.h"
|
#include "base/unicodestrings.h"
|
||||||
|
#include "advancedsettings.h"
|
||||||
|
#include "guiiconprovider.h"
|
||||||
|
#include "scanfoldersdelegate.h"
|
||||||
|
#include "options_imp.h"
|
||||||
|
|
||||||
#ifndef QT_NO_OPENSSL
|
#ifndef QT_NO_OPENSSL
|
||||||
#include <QSslKey>
|
#include <QSslKey>
|
||||||
@ -91,11 +93,12 @@ options_imp::options_imp(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QBT_USES_QT5
|
#ifndef QBT_USES_QT5
|
||||||
scanFoldersView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
scanFoldersView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
#else
|
#else
|
||||||
scanFoldersView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
scanFoldersView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
#endif
|
#endif
|
||||||
scanFoldersView->setModel(ScanFoldersModel::instance());
|
scanFoldersView->setModel(ScanFoldersModel::instance());
|
||||||
|
scanFoldersView->setItemDelegate(new ScanFoldersDelegate(this, scanFoldersView));
|
||||||
connect(ScanFoldersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(enableApplyButton()));
|
connect(ScanFoldersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(enableApplyButton()));
|
||||||
connect(scanFoldersView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(handleScanFolderViewSelectionChanged()));
|
connect(scanFoldersView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(handleScanFolderViewSelectionChanged()));
|
||||||
|
|
||||||
@ -1200,7 +1203,7 @@ 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"),
|
||||||
Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath())));
|
Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath())));
|
||||||
if (!dir.isEmpty()) {
|
if (!dir.isEmpty()) {
|
||||||
const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, true, "");
|
const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER, QString());
|
||||||
QString error;
|
QString error;
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case ScanFoldersModel::AlreadyInList:
|
case ScanFoldersModel::AlreadyInList:
|
||||||
@ -1215,7 +1218,8 @@ void options_imp::on_addScanFolderButton_clicked()
|
|||||||
default:
|
default:
|
||||||
pref->setScanDirsLastPath(dir);
|
pref->setScanDirsLastPath(dir);
|
||||||
addedScanDirs << dir;
|
addedScanDirs << dir;
|
||||||
scanFoldersView->resizeColumnsToContents();
|
for (int i = 0; i < ScanFoldersModel::instance()->columnCount(); ++i)
|
||||||
|
scanFoldersView->resizeColumnToContents(i);
|
||||||
enableApplyButton();
|
enableApplyButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
183
src/gui/scanfoldersdelegate.cpp
Normal file
183
src/gui/scanfoldersdelegate.cpp
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2015 sledgehammer999
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*
|
||||||
|
* Contact : hammered999@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QTreeView>
|
||||||
|
#include <QItemSelectionModel>
|
||||||
|
|
||||||
|
#include "base/scanfoldersmodel.h"
|
||||||
|
#include "base/preferences.h"
|
||||||
|
#include "scanfoldersdelegate.h"
|
||||||
|
|
||||||
|
|
||||||
|
ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView)
|
||||||
|
: QItemDelegate(parent)
|
||||||
|
, m_folderView(foldersView)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanFoldersDelegate::~ScanFoldersDelegate() {}
|
||||||
|
|
||||||
|
void ScanFoldersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
switch(index.column()) {
|
||||||
|
case ScanFoldersModel::WATCH:
|
||||||
|
QItemDelegate::paint(painter, option, index);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ScanFoldersModel::DOWNLOAD: {
|
||||||
|
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||||
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
QString text;
|
||||||
|
|
||||||
|
switch (index.data().toInt()) {
|
||||||
|
case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER:
|
||||||
|
text = tr("Watch Folder");
|
||||||
|
break;
|
||||||
|
case ScanFoldersModel::DEFAULT_LOCATION:
|
||||||
|
text = tr("Default Folder");
|
||||||
|
break;
|
||||||
|
case ScanFoldersModel::CUSTOM_LOCATION:
|
||||||
|
text = index.data(Qt::UserRole).toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScanFoldersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||||||
|
// Set combobox index
|
||||||
|
if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION)
|
||||||
|
combobox->setCurrentIndex(4); // '4' is the index of the item after the separator in the QComboBox menu
|
||||||
|
else
|
||||||
|
combobox->setCurrentIndex(index.data().toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (index.column() != ScanFoldersModel::DOWNLOAD) return 0;
|
||||||
|
|
||||||
|
QComboBox* editor = new QComboBox(parent);
|
||||||
|
editor->setFocusPolicy(Qt::StrongFocus);
|
||||||
|
editor->addItem(tr("Watch Folder"));
|
||||||
|
editor->addItem(tr("Default Folder"));
|
||||||
|
editor->addItem(tr("Browse..."));
|
||||||
|
if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION) {
|
||||||
|
editor->insertSeparator(3);
|
||||||
|
editor->addItem(index.data(Qt::UserRole).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||||||
|
int value = combobox->currentIndex();
|
||||||
|
|
||||||
|
switch(value) {
|
||||||
|
case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER:
|
||||||
|
case ScanFoldersModel::DEFAULT_LOCATION:
|
||||||
|
model->setData(index, value, Qt::DisplayRole);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: // '4' is the index of the item after the separator in the QComboBox menu
|
||||||
|
model->setData(index, combobox->currentText(), Qt::UserRole);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScanFoldersDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||||
|
{
|
||||||
|
qDebug("UpdateEditor Geometry called");
|
||||||
|
editor->setGeometry(option.rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScanFoldersDelegate::comboboxIndexChanged(int index)
|
||||||
|
{
|
||||||
|
if (index < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (index == 2) {
|
||||||
|
QString path;
|
||||||
|
QString newPath;
|
||||||
|
QModelIndexList selIndex = m_folderView->selectionModel()->selectedRows(1);
|
||||||
|
|
||||||
|
if (selIndex.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ScanFoldersModel::PathType type = static_cast<ScanFoldersModel::PathType>(selIndex.at(0).data().toInt());
|
||||||
|
|
||||||
|
if (type == ScanFoldersModel::CUSTOM_LOCATION)
|
||||||
|
path = selIndex.at(0).data(Qt::UserRole).toString();
|
||||||
|
else
|
||||||
|
path = Preferences::instance()->getSavePath();
|
||||||
|
|
||||||
|
newPath = QFileDialog::getExistingDirectory(0, tr("Choose save path"), path);
|
||||||
|
QComboBox *combobox = static_cast<QComboBox*>(sender());
|
||||||
|
disconnect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||||
|
|
||||||
|
if (!newPath.isEmpty()) {
|
||||||
|
if (combobox->count() != 5) {
|
||||||
|
combobox->insertSeparator(3);
|
||||||
|
combobox->addItem(newPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
combobox->setItemText(4, newPath);
|
||||||
|
}
|
||||||
|
combobox->setCurrentIndex(4);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (type == ScanFoldersModel::CUSTOM_LOCATION)
|
||||||
|
combobox->setCurrentIndex(4);
|
||||||
|
else
|
||||||
|
combobox->setCurrentIndex(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||||
|
}
|
||||||
|
}
|
65
src/gui/scanfoldersdelegate.h
Normal file
65
src/gui/scanfoldersdelegate.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2015 sledgehammer999
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*
|
||||||
|
* Contact : hammered999@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCANFOLDERSDELEGATE_H
|
||||||
|
#define SCANFOLDERSDELEGATE_H
|
||||||
|
|
||||||
|
#include <QItemDelegate>
|
||||||
|
|
||||||
|
class QPainter;
|
||||||
|
class QModelIndex;
|
||||||
|
class QStyleOptionViewItem;
|
||||||
|
class QAbstractItemModel;
|
||||||
|
class PropertiesWidget;
|
||||||
|
class QTreeView;
|
||||||
|
|
||||||
|
class ScanFoldersDelegate : public QItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ScanFoldersDelegate(QObject *parent, QTreeView *foldersView);
|
||||||
|
~ScanFoldersDelegate();
|
||||||
|
|
||||||
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||||
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||||
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const;
|
||||||
|
void comboboxIndexChanged(int index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTreeView *m_folderView;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SCANFOLDERSDELEGATE_H
|
||||||
|
|
@ -58,7 +58,7 @@ QByteArray prefjson::getPreferences()
|
|||||||
data["temp_path"] = Utils::Fs::toNativePath(pref->getTempPath());
|
data["temp_path"] = Utils::Fs::toNativePath(pref->getTempPath());
|
||||||
data["preallocate_all"] = pref->preAllocateAllFiles();
|
data["preallocate_all"] = pref->preAllocateAllFiles();
|
||||||
data["incomplete_files_ext"] = pref->useIncompleteFilesExtension();
|
data["incomplete_files_ext"] = pref->useIncompleteFilesExtension();
|
||||||
QVariantList scanDirs;
|
/*QVariantList scanDirs;
|
||||||
foreach (const QString& s, pref->getScanDirs()) {
|
foreach (const QString& s, pref->getScanDirs()) {
|
||||||
scanDirs << Utils::Fs::toNativePath(s);
|
scanDirs << Utils::Fs::toNativePath(s);
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ QByteArray prefjson::getPreferences()
|
|||||||
foreach (bool b, pref->getDownloadInScanDirs()) {
|
foreach (bool b, pref->getDownloadInScanDirs()) {
|
||||||
var_list << b;
|
var_list << b;
|
||||||
}
|
}
|
||||||
data["download_in_scan_dirs"] = var_list;
|
data["download_in_scan_dirs"] = var_list;*/
|
||||||
data["export_dir"] = Utils::Fs::toNativePath(pref->getTorrentExportDir());
|
data["export_dir"] = Utils::Fs::toNativePath(pref->getTorrentExportDir());
|
||||||
data["export_dir_fin"] = Utils::Fs::toNativePath(pref->getFinishedTorrentExportDir());
|
data["export_dir_fin"] = Utils::Fs::toNativePath(pref->getFinishedTorrentExportDir());
|
||||||
// Email notification upon download completion
|
// Email notification upon download completion
|
||||||
@ -188,7 +188,7 @@ void prefjson::setPreferences(const QString& json)
|
|||||||
pref->preAllocateAllFiles(m["preallocate_all"].toBool());
|
pref->preAllocateAllFiles(m["preallocate_all"].toBool());
|
||||||
if (m.contains("incomplete_files_ext"))
|
if (m.contains("incomplete_files_ext"))
|
||||||
pref->useIncompleteFilesExtension(m["incomplete_files_ext"].toBool());
|
pref->useIncompleteFilesExtension(m["incomplete_files_ext"].toBool());
|
||||||
if (m.contains("scan_dirs") && m.contains("download_in_scan_dirs") && m.contains("scan_dirs_download_paths")) {
|
/*if (m.contains("scan_dirs") && m.contains("download_in_scan_dirs") && m.contains("scan_dirs_download_paths")) {
|
||||||
QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList();
|
QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList();
|
||||||
QList<bool> download_at_path;
|
QList<bool> download_at_path;
|
||||||
foreach (QVariant var, download_at_path_tmp) {
|
foreach (QVariant var, download_at_path_tmp) {
|
||||||
@ -217,7 +217,7 @@ void prefjson::setPreferences(const QString& json)
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
if (m.contains("export_dir"))
|
if (m.contains("export_dir"))
|
||||||
pref->setTorrentExportDir(m["export_dir"].toString());
|
pref->setTorrentExportDir(m["export_dir"].toString());
|
||||||
if (m.contains("export_dir_fin"))
|
if (m.contains("export_dir_fin"))
|
||||||
|
Loading…
Reference in New Issue
Block a user