Browse Source

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

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

56
src/gui/addnewtorrentdialog.cpp

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

7
src/gui/addnewtorrentdialog.h

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

8
src/gui/advancedsettings.cpp

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

2
src/gui/advancedsettings.h

@ -76,7 +76,7 @@ private: @@ -76,7 +76,7 @@ private:
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,
spinSendBufferWatermark, spinSendBufferLowWatermark, spinSendBufferWatermarkFactor;
spinSendBufferWatermark, spinSendBufferLowWatermark, spinSendBufferWatermarkFactor, spinSavePathHistoryLength;
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_confirm_torrent_recheck, cb_confirm_remove_all_tags, cb_listen_ipv6, cb_announce_all_trackers, cbGuidedReadCache, cbMultiConnectionsPerIp,

Loading…
Cancel
Save