mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 11:38:50 -07:00
Merge pull request #7596 from evsh/path-history-items
Add option to tune download history list length. Closes #4043.
This commit is contained in:
commit
08755a211b
6 changed files with 74 additions and 12 deletions
|
@ -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 @@
|
|||
#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
|
|||
}
|
||||
}
|
||||
|
||||
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
|
|||
|
||||
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)
|
|||
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
|
|||
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
|
|||
// 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue