From 83b58468d9ff1eb58f6f655bf164e4adfd92aabd Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 17 May 2016 01:46:28 +0800 Subject: [PATCH 1/3] Improve error messages for "Auto download torrents" --- src/gui/options_imp.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index 94ae625d2..947ece91a 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -1314,20 +1314,20 @@ int options_imp::getActionOnDblClOnTorrentFn() const void options_imp::on_addScanFolderButton_clicked() { Preferences* const pref = Preferences::instance(); - const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan"), + const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder to monitor"), Utils::Fs::toNativePath(Utils::Fs::folderName(pref->getScanDirsLastPath()))); if (!dir.isEmpty()) { const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, ScanFoldersModel::DEFAULT_LOCATION, QString(), false); QString error; switch (status) { case ScanFoldersModel::AlreadyInList: - error = tr("Folder is already being watched."); + error = tr("Folder is already being monitored:"); break; case ScanFoldersModel::DoesNotExist: - error = tr("Folder does not exist."); + error = tr("Folder does not exist:"); break; case ScanFoldersModel::CannotRead: - error = tr("Folder is not readable."); + error = tr("Folder is not readable:"); break; default: pref->setScanDirsLastPath(dir); @@ -1338,7 +1338,7 @@ void options_imp::on_addScanFolderButton_clicked() } if (!error.isEmpty()) - QMessageBox::warning(this, tr("Failure"), tr("Failed to add Scan Folder '%1': %2").arg(dir).arg(error)); + QMessageBox::critical(this, tr("Adding entry failed"), QString("%1\n%2").arg(error).arg(dir)); } } From 6ead0ae9eebce955af02526b61598ddf5ea287e1 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 17 May 2016 03:02:27 +0800 Subject: [PATCH 2/3] Add lookup function to get PathType display names --- src/base/scanfoldersmodel.cpp | 19 ++++++++++++++++--- src/base/scanfoldersmodel.h | 2 ++ src/gui/scanfoldersdelegate.cpp | 6 +++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index d2844506a..9960e2f92 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -128,10 +128,8 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const else if (role == Qt::DisplayRole) { switch (pathData->downloadType) { case DOWNLOAD_IN_WATCH_FOLDER: - value = tr("Watch Folder"); - break; case DEFAULT_LOCATION: - value = tr("Default Folder"); + value = pathTypeDisplayName(pathData->downloadType); break; case CUSTOM_LOCATION: value = pathData->downloadPath; @@ -392,3 +390,18 @@ void ScanFoldersModel::addTorrentsToSession(const QStringList &pathList) } } } + +QString ScanFoldersModel::pathTypeDisplayName(const PathType type) +{ + switch(type) { + case DOWNLOAD_IN_WATCH_FOLDER: + return tr("Monitored folder"); + case DEFAULT_LOCATION: + return tr("Default save location"); + case CUSTOM_LOCATION: + return tr("Browse..."); + default: + qDebug("Invalid PathType: %d", type); + }; + return QString(); +} diff --git a/src/base/scanfoldersmodel.h b/src/base/scanfoldersmodel.h index 25dfdfd22..24bd05549 100644 --- a/src/base/scanfoldersmodel.h +++ b/src/base/scanfoldersmodel.h @@ -73,6 +73,8 @@ public: static void freeInstance(); static ScanFoldersModel *instance(); + static QString pathTypeDisplayName(const PathType type); + int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; diff --git a/src/gui/scanfoldersdelegate.cpp b/src/gui/scanfoldersdelegate.cpp index 5ad14f641..56fa993fc 100644 --- a/src/gui/scanfoldersdelegate.cpp +++ b/src/gui/scanfoldersdelegate.cpp @@ -63,9 +63,9 @@ QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionVi QComboBox* editor = new QComboBox(parent); editor->setFocusPolicy(Qt::StrongFocus); - editor->addItem(tr("Same as monitored folder")); - editor->addItem(tr("Default save location")); - editor->addItem(tr("Browse...")); + editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER)); + editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::DEFAULT_LOCATION)); + editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::CUSTOM_LOCATION)); if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION) { editor->insertSeparator(3); editor->addItem(index.data().toString()); From c907a2f857a2ee2b5117a71105f575020cbd4fa3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 17 May 2016 13:32:57 +0800 Subject: [PATCH 3/3] Cleanup headers Code formatting --- src/base/scanfoldersmodel.cpp | 13 +++++-------- src/base/scanfoldersmodel.h | 11 ++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index 9960e2f92..ea1bc6335 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -28,20 +28,17 @@ * Contact : chris@qbittorrent.org */ +#include "scanfoldersmodel.h" + #include #include -#include #include -#include #include -#include "utils/misc.h" -#include "utils/fs.h" -#include "preferences.h" -#include "logger.h" -#include "filesystemwatcher.h" #include "bittorrent/session.h" -#include "scanfoldersmodel.h" +#include "filesystemwatcher.h" +#include "preferences.h" +#include "utils/fs.h" struct ScanFoldersModel::PathData { diff --git a/src/base/scanfoldersmodel.h b/src/base/scanfoldersmodel.h index 24bd05549..41fd3a288 100644 --- a/src/base/scanfoldersmodel.h +++ b/src/base/scanfoldersmodel.h @@ -34,13 +34,10 @@ #include #include -QT_BEGIN_NAMESPACE class QStringList; -QT_END_NAMESPACE - class FileSystemWatcher; -class ScanFoldersModel : public QAbstractListModel +class ScanFoldersModel: public QAbstractListModel { Q_OBJECT Q_DISABLE_COPY(ScanFoldersModel) @@ -71,7 +68,7 @@ public: static bool initInstance(QObject *parent = 0); static void freeInstance(); - static ScanFoldersModel *instance(); + static ScanFoldersModel* instance(); static QString pathTypeDisplayName(const PathType type); @@ -83,8 +80,8 @@ public: // TODO: removePaths(); singular version becomes private helper functions; // also: remove functions should take modelindexes - PathStatus addPath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath, bool addToFSWatcher = true); - PathStatus updatePath(const QString &watchPath, const PathType& downloadType, const QString &downloadPath); + PathStatus addPath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath, bool addToFSWatcher = true); + PathStatus updatePath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath); // PRECONDITION: The paths must have been added with addPath() first. void addToFSWatcher(const QStringList &watchPaths); void removePath(int row, bool removeFromFSWatcher = true);