Browse Source

Add option to tune download history list length. Closes #4043.

adaptive-webui-19844
Eugene Shalygin 7 years ago
parent
commit
1fed324f91
  1. 42
      src/gui/addnewtorrentdialog.cpp
  2. 7
      src/gui/addnewtorrentdialog.h
  3. 8
      src/gui/advancedsettings.cpp
  4. 2
      src/gui/advancedsettings.h

42
src/gui/addnewtorrentdialog.cpp

@ -38,6 +38,7 @@
#include "base/preferences.h" #include "base/preferences.h"
#include "base/settingsstorage.h" #include "base/settingsstorage.h"
#include "base/settingvalue.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
@ -58,6 +59,8 @@
#include "ui_addnewtorrentdialog.h" #include "ui_addnewtorrentdialog.h"
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
namespace
{
#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name #define SETTINGS_KEY(name) "AddNewTorrentDialog/" name
const QString KEY_ENABLED = SETTINGS_KEY("Enabled"); const QString KEY_ENABLED = SETTINGS_KEY("Enabled");
const QString KEY_DEFAULTCATEGORY = SETTINGS_KEY("DefaultCategory"); const QString KEY_DEFAULTCATEGORY = SETTINGS_KEY("DefaultCategory");
@ -66,9 +69,8 @@ const QString KEY_WIDTH = SETTINGS_KEY("Width");
const QString KEY_EXPANDED = SETTINGS_KEY("Expanded"); const QString KEY_EXPANDED = SETTINGS_KEY("Expanded");
const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel"); const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel");
const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory"); const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory");
const char KEY_SAVEPATHHISTORYLENGTH[] = SETTINGS_KEY("SavePathHistoryLength");
namespace
{
// just a shortcut // just a shortcut
inline SettingsStorage *settings() inline SettingsStorage *settings()
{ {
@ -76,6 +78,9 @@ namespace
} }
} }
constexpr int AddNewTorrentDialog::minPathHistoryLength;
constexpr int AddNewTorrentDialog::maxPathHistoryLength;
AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent) AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::AddNewTorrentDialog) , ui(new Ui::AddNewTorrentDialog)
@ -93,6 +98,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
ui->savePath->setMode(FileSystemPathEdit::Mode::DirectorySave); ui->savePath->setMode(FileSystemPathEdit::Mode::DirectorySave);
ui->savePath->setDialogCaption(tr("Choose save path")); ui->savePath->setDialogCaption(tr("Choose save path"));
ui->savePath->setMaxVisibleItems(20);
auto session = BitTorrent::Session::instance(); auto session = BitTorrent::Session::instance();
@ -175,6 +181,34 @@ void AddNewTorrentDialog::setTopLevel(bool value)
SettingsStorage::instance()->storeValue(KEY_TOPLEVEL, value); SettingsStorage::instance()->storeValue(KEY_TOPLEVEL, value);
} }
int AddNewTorrentDialog::savePathHistoryLength()
{
return savePathHistoryLengthSetting();
}
void AddNewTorrentDialog::setSavePathHistoryLength(int value)
{
Q_ASSERT(value >= minPathHistoryLength);
Q_ASSERT(value <= maxPathHistoryLength);
const int oldValue = savePathHistoryLength();
if (oldValue != value) {
savePathHistoryLengthSetting() = value;
settings()->storeValue(KEY_SAVEPATHHISTORY,
QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList().mid(0, value)));
}
}
CachedSettingValue<int> &AddNewTorrentDialog::savePathHistoryLengthSetting()
{
const int defaultHistoryLength = 8;
static CachedSettingValue<int> setting(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength,
[](int v)
{
return std::max(minPathHistoryLength, std::min(maxPathHistoryLength, v));
});
return setting;
}
void AddNewTorrentDialog::loadState() void AddNewTorrentDialog::loadState()
{ {
m_headerState = settings()->loadValue(KEY_TREEHEADERSTATE).toByteArray(); m_headerState = settings()->loadValue(KEY_TREEHEADERSTATE).toByteArray();
@ -362,6 +396,8 @@ void AddNewTorrentDialog::saveSavePathHistory() const
QDir selectedSavePath(ui->savePath->selectedPath()); QDir selectedSavePath(ui->savePath->selectedPath());
// Get current history // Get current history
QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList(); QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList();
if (history.size() > savePathHistoryLength())
history = history.mid(0, savePathHistoryLength());
QList<QDir> historyDirs; QList<QDir> historyDirs;
foreach (const QString dir, history) foreach (const QString dir, history)
historyDirs << QDir(dir); historyDirs << QDir(dir);
@ -369,7 +405,7 @@ void AddNewTorrentDialog::saveSavePathHistory() const
// Add save path to history // Add save path to history
history.push_front(selectedSavePath.absolutePath()); history.push_front(selectedSavePath.absolutePath());
// Limit list size // Limit list size
if (history.size() > 8) if (history.size() > savePathHistoryLength())
history.pop_back(); history.pop_back();
// Save history // Save history
settings()->storeValue(KEY_SAVEPATHHISTORY, history); settings()->storeValue(KEY_SAVEPATHHISTORY, history);

7
src/gui/addnewtorrentdialog.h

@ -53,18 +53,24 @@ namespace Ui
class TorrentContentFilterModel; class TorrentContentFilterModel;
class TorrentFileGuard; class TorrentFileGuard;
class PropListDelegate; class PropListDelegate;
template <typename T> class CachedSettingValue;
class AddNewTorrentDialog: public QDialog class AddNewTorrentDialog: public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
static constexpr int minPathHistoryLength = 0;
static constexpr int maxPathHistoryLength = 99;
~AddNewTorrentDialog(); ~AddNewTorrentDialog();
static bool isEnabled(); static bool isEnabled();
static void setEnabled(bool value); static void setEnabled(bool value);
static bool isTopLevel(); static bool isTopLevel();
static void setTopLevel(bool value); static void setTopLevel(bool value);
static int savePathHistoryLength();
static void setSavePathHistoryLength(int value);
static void show(QString source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent); static void show(QString source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
static void show(QString source, QWidget *parent); static void show(QString source, QWidget *parent);
@ -99,6 +105,7 @@ private:
void setupTreeview(); void setupTreeview();
void setCommentText(const QString &str) const; void setCommentText(const QString &str) const;
void setSavePath(const QString &newPath); void setSavePath(const QString &newPath);
static CachedSettingValue<int> &savePathHistoryLengthSetting();
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;

8
src/gui/advancedsettings.cpp

@ -37,6 +37,7 @@
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "gui/addnewtorrentdialog.h"
#include "gui/mainwindow.h" #include "gui/mainwindow.h"
enum AdvSettingsCols enum AdvSettingsCols
@ -69,6 +70,7 @@ enum AdvSettingsRows
TORRENT_ADDED_NOTIFICATIONS, TORRENT_ADDED_NOTIFICATIONS,
CONFIRM_REMOVE_ALL_TAGS, CONFIRM_REMOVE_ALL_TAGS,
DOWNLOAD_TRACKER_FAVICON, DOWNLOAD_TRACKER_FAVICON,
SAVE_PATH_HISTORY_LENGTH,
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
USE_ICON_THEME, USE_ICON_THEME,
#endif #endif
@ -196,6 +198,7 @@ void AdvancedSettings::saveAdvancedSettings()
mainWindow->setTorrentAddedNotificationsEnabled(cb_torrent_added_notifications.isChecked()); mainWindow->setTorrentAddedNotificationsEnabled(cb_torrent_added_notifications.isChecked());
// Misc GUI properties // Misc GUI properties
mainWindow->setDownloadTrackerFavicon(cb_tracker_favicon.isChecked()); mainWindow->setDownloadTrackerFavicon(cb_tracker_favicon.isChecked());
AddNewTorrentDialog::setSavePathHistoryLength(spinSavePathHistoryLength.value());
// Tracker // Tracker
session->setTrackerEnabled(cb_tracker_status.isChecked()); session->setTrackerEnabled(cb_tracker_status.isChecked());
@ -418,7 +421,10 @@ void AdvancedSettings::loadAdvancedSettings()
// Download tracker's favicon // Download tracker's favicon
cb_tracker_favicon.setChecked(mainWindow->isDownloadTrackerFavicon()); cb_tracker_favicon.setChecked(mainWindow->isDownloadTrackerFavicon());
addRow(DOWNLOAD_TRACKER_FAVICON, tr("Download tracker's favicon"), &cb_tracker_favicon); addRow(DOWNLOAD_TRACKER_FAVICON, tr("Download tracker's favicon"), &cb_tracker_favicon);
// Save path history length
spinSavePathHistoryLength.setRange(AddNewTorrentDialog::minPathHistoryLength, AddNewTorrentDialog::maxPathHistoryLength);
spinSavePathHistoryLength.setValue(AddNewTorrentDialog::savePathHistoryLength());
addRow(SAVE_PATH_HISTORY_LENGTH, tr("Save path history length"), &spinSavePathHistoryLength);
// Tracker State // Tracker State
cb_tracker_status.setChecked(session->isTrackerEnabled()); cb_tracker_status.setChecked(session->isTrackerEnabled());
addRow(TRACKER_STATUS, tr("Enable embedded tracker"), &cb_tracker_status); addRow(TRACKER_STATUS, tr("Enable embedded tracker"), &cb_tracker_status);

2
src/gui/advancedsettings.h

@ -76,7 +76,7 @@ private:
QLabel labelQbtLink, labelLibtorrentLink; QLabel labelQbtLink, labelLibtorrentLink;
QSpinBox spin_cache, spin_save_resume_data_interval, outgoing_ports_min, outgoing_ports_max, spin_list_refresh, spin_maxhalfopen, spin_tracker_port, spin_cache_ttl, QSpinBox spin_cache, spin_save_resume_data_interval, outgoing_ports_min, outgoing_ports_max, spin_list_refresh, spin_maxhalfopen, spin_tracker_port, spin_cache_ttl,
spinSendBufferWatermark, spinSendBufferLowWatermark, spinSendBufferWatermarkFactor; spinSendBufferWatermark, spinSendBufferLowWatermark, spinSendBufferWatermarkFactor, spinSavePathHistoryLength;
QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding, QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding,
cb_program_notifications, cb_torrent_added_notifications, cb_tracker_favicon, cb_tracker_status, cb_program_notifications, cb_torrent_added_notifications, cb_tracker_favicon, cb_tracker_status,
cb_confirm_torrent_recheck, cb_confirm_remove_all_tags, cb_listen_ipv6, cb_announce_all_trackers, cbGuidedReadCache, cbMultiConnectionsPerIp, cb_confirm_torrent_recheck, cb_confirm_remove_all_tags, cb_listen_ipv6, cb_announce_all_trackers, cbGuidedReadCache, cbMultiConnectionsPerIp,

Loading…
Cancel
Save