Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
301 lines
13 KiB
301 lines
13 KiB
15 years ago
|
#ifndef ADVANCEDSETTINGS_H
|
||
|
#define ADVANCEDSETTINGS_H
|
||
|
|
||
|
#include <QTableWidget>
|
||
|
#include <QHeaderView>
|
||
|
#include <QSpinBox>
|
||
14 years ago
|
#include <QHostAddress>
|
||
15 years ago
|
#include <QCheckBox>
|
||
14 years ago
|
#include <QLineEdit>
|
||
15 years ago
|
#include <QComboBox>
|
||
|
#include <QNetworkInterface>
|
||
15 years ago
|
#include <libtorrent/version.hpp>
|
||
15 years ago
|
#include "preferences.h"
|
||
|
|
||
|
enum AdvSettingsCols {PROPERTY, VALUE};
|
||
11 years ago
|
enum AdvSettingsRows {DISK_CACHE, DISK_CACHE_TTL, OS_CACHE, SAVE_RESUME_DATA_INTERVAL, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_LIMIT_LAN, RECHECK_COMPLETED, LIST_REFRESH, RESOLVE_COUNTRIES, RESOLVE_HOSTS, MAX_HALF_OPEN, SUPER_SEEDING, NETWORK_IFACE, NETWORK_LISTEN_IPV6, NETWORK_ADDRESS, PROGRAM_NOTIFICATIONS, TRACKER_STATUS, TRACKER_PORT,
|
||
11 years ago
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||
14 years ago
|
UPDATE_CHECK,
|
||
14 years ago
|
#endif
|
||
11 years ago
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||
14 years ago
|
USE_ICON_THEME,
|
||
13 years ago
|
#endif
|
||
13 years ago
|
CONFIRM_DELETE_TORRENT, TRACKER_EXCHANGE,
|
||
13 years ago
|
ANNOUNCE_ALL_TRACKERS,
|
||
14 years ago
|
ROW_COUNT};
|
||
15 years ago
|
|
||
|
class AdvancedSettings: public QTableWidget {
|
||
|
Q_OBJECT
|
||
|
|
||
|
private:
|
||
11 years ago
|
QSpinBox spin_cache, spin_save_resume_data_interval, outgoing_ports_min, outgoing_ports_max, spin_list_refresh, spin_maxhalfopen, spin_tracker_port;
|
||
10 years ago
|
QCheckBox cb_os_cache, cb_ignore_limits_lan, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts,
|
||
14 years ago
|
cb_super_seeding, cb_program_notifications, cb_tracker_status, cb_confirm_torrent_deletion,
|
||
10 years ago
|
cb_enable_tracker_ext, cb_listen_ipv6;
|
||
14 years ago
|
QComboBox combo_iface;
|
||
12 years ago
|
QSpinBox spin_cache_ttl;
|
||
11 years ago
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||
14 years ago
|
QCheckBox cb_update_check;
|
||
14 years ago
|
#endif
|
||
11 years ago
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||
14 years ago
|
QCheckBox cb_use_icon_theme;
|
||
13 years ago
|
#endif
|
||
13 years ago
|
QCheckBox cb_announce_all_trackers;
|
||
14 years ago
|
QLineEdit txt_network_address;
|
||
15 years ago
|
|
||
|
public:
|
||
|
AdvancedSettings(QWidget *parent=0): QTableWidget(parent) {
|
||
|
// Set visual appearance
|
||
15 years ago
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||
15 years ago
|
setAlternatingRowColors(true);
|
||
15 years ago
|
setColumnCount(2);
|
||
|
QStringList header;
|
||
14 years ago
|
header << tr("Setting") << tr("Value", "Value set for this setting");
|
||
15 years ago
|
setHorizontalHeaderLabels(header);
|
||
|
setColumnWidth(0, width()/2);
|
||
|
horizontalHeader()->setStretchLastSection(true);
|
||
15 years ago
|
verticalHeader()->setVisible(false);
|
||
15 years ago
|
setRowCount(ROW_COUNT);
|
||
12 years ago
|
// Signals
|
||
|
connect(&spin_cache, SIGNAL(valueChanged(int)), SLOT(updateCacheSpinSuffix(int)));
|
||
15 years ago
|
// Load settings
|
||
|
loadAdvancedSettings();
|
||
|
}
|
||
|
|
||
|
~AdvancedSettings() {
|
||
|
}
|
||
|
|
||
15 years ago
|
public slots:
|
||
15 years ago
|
void saveAdvancedSettings() {
|
||
11 years ago
|
Preferences* const pref = Preferences::instance();
|
||
15 years ago
|
// Disk write cache
|
||
11 years ago
|
pref->setDiskCacheSize(spin_cache.value());
|
||
|
pref->setDiskCacheTTL(spin_cache_ttl.value());
|
||
10 years ago
|
// Enable OS cache
|
||
|
pref->setOsCache(cb_os_cache.isChecked());
|
||
11 years ago
|
// Save resume data interval
|
||
|
pref->setSaveResumeDataInterval(spin_save_resume_data_interval.value());
|
||
15 years ago
|
// Outgoing ports
|
||
11 years ago
|
pref->setOutgoingPortsMin(outgoing_ports_min.value());
|
||
|
pref->setOutgoingPortsMax(outgoing_ports_max.value());
|
||
15 years ago
|
// Ignore limits on LAN
|
||
11 years ago
|
pref->ignoreLimitsOnLAN(cb_ignore_limits_lan.isChecked());
|
||
15 years ago
|
// Recheck torrents on completion
|
||
11 years ago
|
pref->recheckTorrentsOnCompletion(cb_recheck_completed.isChecked());
|
||
15 years ago
|
// Transfer list refresh interval
|
||
11 years ago
|
pref->setRefreshInterval(spin_list_refresh.value());
|
||
15 years ago
|
// Peer resolution
|
||
11 years ago
|
pref->resolvePeerCountries(cb_resolve_countries.isChecked());
|
||
|
pref->resolvePeerHostNames(cb_resolve_hosts.isChecked());
|
||
15 years ago
|
// Max Half-Open connections
|
||
11 years ago
|
pref->setMaxHalfOpenConnections(spin_maxhalfopen.value());
|
||
15 years ago
|
// Super seeding
|
||
11 years ago
|
pref->enableSuperSeeding(cb_super_seeding.isChecked());
|
||
15 years ago
|
// Network interface
|
||
13 years ago
|
if (combo_iface.currentIndex() == 0) {
|
||
15 years ago
|
// All interfaces (default)
|
||
11 years ago
|
pref->setNetworkInterface(QString::null);
|
||
|
pref->setNetworkInterfaceName(QString::null);
|
||
15 years ago
|
} else {
|
||
11 years ago
|
pref->setNetworkInterface(combo_iface.itemData(combo_iface.currentIndex()).toString());
|
||
|
pref->setNetworkInterfaceName(combo_iface.currentText());
|
||
15 years ago
|
}
|
||
10 years ago
|
// Listen on IPv6 address
|
||
|
pref->setListenIPv6(cb_listen_ipv6.isChecked());
|
||
14 years ago
|
// Network address
|
||
14 years ago
|
QHostAddress addr(txt_network_address.text().trimmed());
|
||
13 years ago
|
if (addr.isNull())
|
||
11 years ago
|
pref->setNetworkAddress("");
|
||
14 years ago
|
else
|
||
11 years ago
|
pref->setNetworkAddress(addr.toString());
|
||
15 years ago
|
// Program notification
|
||
11 years ago
|
pref->useProgramNotification(cb_program_notifications.isChecked());
|
||
14 years ago
|
// Tracker
|
||
11 years ago
|
pref->setTrackerEnabled(cb_tracker_status.isChecked());
|
||
|
pref->setTrackerPort(spin_tracker_port.value());
|
||
11 years ago
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||
11 years ago
|
pref->setUpdateCheckEnabled(cb_update_check.isChecked());
|
||
14 years ago
|
#endif
|
||
|
// Icon theme
|
||
11 years ago
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||
11 years ago
|
pref->useSystemIconTheme(cb_use_icon_theme.isChecked());
|
||
14 years ago
|
#endif
|
||
11 years ago
|
pref->setConfirmTorrentDeletion(cb_confirm_torrent_deletion.isChecked());
|
||
14 years ago
|
// Tracker exchange
|
||
11 years ago
|
pref->setTrackerExchangeEnabled(cb_enable_tracker_ext.isChecked());
|
||
|
pref->setAnnounceToAllTrackers(cb_announce_all_trackers.isChecked());
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
signals:
|
||
|
void settingsChanged();
|
||
|
|
||
|
private:
|
||
|
void setRow(int row, const QString &property, QSpinBox* editor) {
|
||
|
setItem(row, PROPERTY, new QTableWidgetItem(property));
|
||
|
bool ok; Q_UNUSED(ok);
|
||
|
ok = connect(editor, SIGNAL(valueChanged(int)), SIGNAL(settingsChanged()));
|
||
|
Q_ASSERT(ok);
|
||
|
setCellWidget(row, VALUE, editor);
|
||
|
}
|
||
|
|
||
|
void setRow(int row, const QString &property, QComboBox* editor) {
|
||
|
setItem(row, PROPERTY, new QTableWidgetItem(property));
|
||
|
bool ok; Q_UNUSED(ok);
|
||
|
ok = connect(editor, SIGNAL(currentIndexChanged(int)), SIGNAL(settingsChanged()));
|
||
|
Q_ASSERT(ok);
|
||
|
setCellWidget(row, VALUE, editor);
|
||
|
}
|
||
|
|
||
|
void setRow(int row, const QString &property, QCheckBox* editor) {
|
||
|
setItem(row, PROPERTY, new QTableWidgetItem(property));
|
||
|
bool ok; Q_UNUSED(ok);
|
||
|
ok = connect(editor, SIGNAL(stateChanged(int)), SIGNAL(settingsChanged()));
|
||
|
Q_ASSERT(ok);
|
||
|
setCellWidget(row, VALUE, editor);
|
||
|
}
|
||
|
|
||
|
void setRow(int row, const QString &property, QLineEdit* editor) {
|
||
|
setItem(row, PROPERTY, new QTableWidgetItem(property));
|
||
|
bool ok; Q_UNUSED(ok);
|
||
|
ok = connect(editor, SIGNAL(textChanged(QString)), SIGNAL(settingsChanged()));
|
||
|
Q_ASSERT(ok);
|
||
|
setCellWidget(row, VALUE, editor);
|
||
|
}
|
||
|
|
||
|
private slots:
|
||
12 years ago
|
void updateCacheSpinSuffix(int value)
|
||
|
{
|
||
|
if (value <= 0)
|
||
|
spin_cache.setSuffix(tr(" (auto)"));
|
||
|
else
|
||
|
spin_cache.setSuffix(tr(" MiB"));
|
||
|
}
|
||
|
|
||
|
void loadAdvancedSettings()
|
||
|
{
|
||
11 years ago
|
const Preferences* const pref = Preferences::instance();
|
||
15 years ago
|
// Disk write cache
|
||
12 years ago
|
spin_cache.setMinimum(0);
|
||
10 years ago
|
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes.
|
||
|
// These macros may not be available on compilers other than MSVC and GCC
|
||
10 years ago
|
#if !defined(_M_X64) && !defined(__amd64__)
|
||
10 years ago
|
//1800MiB to leave 248MiB room to the rest of program data in RAM
|
||
|
spin_cache.setMaximum(1800);
|
||
|
#else
|
||
|
// 4GiB
|
||
|
spin_cache.setMaximum(4*1024);
|
||
|
#endif
|
||
11 years ago
|
spin_cache.setValue(pref->diskCacheSize());
|
||
12 years ago
|
updateCacheSpinSuffix(spin_cache.value());
|
||
14 years ago
|
setRow(DISK_CACHE, tr("Disk write cache size"), &spin_cache);
|
||
12 years ago
|
// Disk cache expiry
|
||
|
spin_cache_ttl.setMinimum(15);
|
||
|
spin_cache_ttl.setMaximum(600);
|
||
11 years ago
|
spin_cache_ttl.setValue(pref->diskCacheTTL());
|
||
12 years ago
|
spin_cache_ttl.setSuffix(tr(" s", " seconds"));
|
||
|
setRow(DISK_CACHE_TTL, tr("Disk cache expiry interval"), &spin_cache_ttl);
|
||
10 years ago
|
// Enable OS cache
|
||
|
cb_os_cache.setChecked(pref->osCache());
|
||
|
setRow(OS_CACHE, tr("Enable OS cache"), &cb_os_cache);
|
||
11 years ago
|
// Save resume data interval
|
||
|
spin_save_resume_data_interval.setMinimum(1);
|
||
|
spin_save_resume_data_interval.setMaximum(1440);
|
||
|
spin_save_resume_data_interval.setValue(pref->saveResumeDataInterval());
|
||
|
spin_save_resume_data_interval.setSuffix(tr(" m", " minutes"));
|
||
10 years ago
|
setRow(SAVE_RESUME_DATA_INTERVAL, tr("Save resume data interval", "How often the fastresume file is saved."), &spin_save_resume_data_interval);
|
||
15 years ago
|
// Outgoing port Min
|
||
14 years ago
|
outgoing_ports_min.setMinimum(0);
|
||
|
outgoing_ports_min.setMaximum(65535);
|
||
11 years ago
|
outgoing_ports_min.setValue(pref->outgoingPortsMin());
|
||
14 years ago
|
setRow(OUTGOING_PORT_MIN, tr("Outgoing ports (Min) [0: Disabled]"), &outgoing_ports_min);
|
||
15 years ago
|
// Outgoing port Min
|
||
14 years ago
|
outgoing_ports_max.setMinimum(0);
|
||
|
outgoing_ports_max.setMaximum(65535);
|
||
11 years ago
|
outgoing_ports_max.setValue(pref->outgoingPortsMax());
|
||
14 years ago
|
setRow(OUTGOING_PORT_MAX, tr("Outgoing ports (Max) [0: Disabled]"), &outgoing_ports_max);
|
||
15 years ago
|
// Ignore transfer limits on local network
|
||
11 years ago
|
cb_ignore_limits_lan.setChecked(pref->ignoreLimitsOnLAN());
|
||
14 years ago
|
setRow(IGNORE_LIMIT_LAN, tr("Ignore transfer limits on local network"), &cb_ignore_limits_lan);
|
||
15 years ago
|
// Recheck completed torrents
|
||
11 years ago
|
cb_recheck_completed.setChecked(pref->recheckTorrentsOnCompletion());
|
||
14 years ago
|
setRow(RECHECK_COMPLETED, tr("Recheck torrents on completion"), &cb_recheck_completed);
|
||
15 years ago
|
// Transfer list refresh interval
|
||
14 years ago
|
spin_list_refresh.setMinimum(30);
|
||
|
spin_list_refresh.setMaximum(99999);
|
||
11 years ago
|
spin_list_refresh.setValue(pref->getRefreshInterval());
|
||
14 years ago
|
spin_list_refresh.setSuffix(tr(" ms", " milliseconds"));
|
||
14 years ago
|
setRow(LIST_REFRESH, tr("Transfer list refresh interval"), &spin_list_refresh);
|
||
15 years ago
|
// Resolve Peer countries
|
||
11 years ago
|
cb_resolve_countries.setChecked(pref->resolvePeerCountries());
|
||
14 years ago
|
setRow(RESOLVE_COUNTRIES, tr("Resolve peer countries (GeoIP)"), &cb_resolve_countries);
|
||
15 years ago
|
// Resolve peer hosts
|
||
11 years ago
|
cb_resolve_hosts.setChecked(pref->resolvePeerHostNames());
|
||
14 years ago
|
setRow(RESOLVE_HOSTS, tr("Resolve peer host names"), &cb_resolve_hosts);
|
||
15 years ago
|
// Max Half Open connections
|
||
14 years ago
|
spin_maxhalfopen.setMinimum(0);
|
||
|
spin_maxhalfopen.setMaximum(99999);
|
||
11 years ago
|
spin_maxhalfopen.setValue(pref->getMaxHalfOpenConnections());
|
||
14 years ago
|
setRow(MAX_HALF_OPEN, tr("Maximum number of half-open connections [0: Disabled]"), &spin_maxhalfopen);
|
||
15 years ago
|
// Super seeding
|
||
11 years ago
|
cb_super_seeding.setChecked(pref->isSuperSeedingEnabled());
|
||
14 years ago
|
setRow(SUPER_SEEDING, tr("Strict super seeding"), &cb_super_seeding);
|
||
15 years ago
|
// Network interface
|
||
14 years ago
|
combo_iface.addItem(tr("Any interface", "i.e. Any network interface"));
|
||
11 years ago
|
const QString current_iface = pref->getNetworkInterface();
|
||
12 years ago
|
bool interface_exists = current_iface.isEmpty();
|
||
15 years ago
|
int i = 1;
|
||
13 years ago
|
foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
|
||
|
if (iface.flags() & QNetworkInterface::IsLoopBack) continue;
|
||
12 years ago
|
combo_iface.addItem(iface.humanReadableName(),iface.name());
|
||
12 years ago
|
if (!current_iface.isEmpty() && iface.name() == current_iface) {
|
||
14 years ago
|
combo_iface.setCurrentIndex(i);
|
||
12 years ago
|
interface_exists = true;
|
||
|
}
|
||
15 years ago
|
++i;
|
||
|
}
|
||
12 years ago
|
// Saved interface does not exist, show it anyway
|
||
|
if (!interface_exists) {
|
||
11 years ago
|
combo_iface.addItem(pref->getNetworkInterfaceName(),current_iface);
|
||
12 years ago
|
combo_iface.setCurrentIndex(i);
|
||
|
}
|
||
14 years ago
|
setRow(NETWORK_IFACE, tr("Network Interface (requires restart)"), &combo_iface);
|
||
10 years ago
|
// Listen on IPv6 address
|
||
|
cb_listen_ipv6.setChecked(pref->getListenIPv6());
|
||
|
setRow(NETWORK_LISTEN_IPV6, tr("Listen on IPv6 address (requires restart)"), &cb_listen_ipv6);
|
||
14 years ago
|
// Network address
|
||
11 years ago
|
txt_network_address.setText(pref->getNetworkAddress());
|
||
14 years ago
|
setRow(NETWORK_ADDRESS, tr("IP Address to report to trackers (requires restart)"), &txt_network_address);
|
||
15 years ago
|
// Program notifications
|
||
11 years ago
|
cb_program_notifications.setChecked(pref->useProgramNotification());
|
||
14 years ago
|
setRow(PROGRAM_NOTIFICATIONS, tr("Display program on-screen notifications"), &cb_program_notifications);
|
||
14 years ago
|
// Tracker State
|
||
11 years ago
|
cb_tracker_status.setChecked(pref->isTrackerEnabled());
|
||
14 years ago
|
setRow(TRACKER_STATUS, tr("Enable embedded tracker"), &cb_tracker_status);
|
||
14 years ago
|
// Tracker port
|
||
14 years ago
|
spin_tracker_port.setMinimum(1);
|
||
|
spin_tracker_port.setMaximum(65535);
|
||
11 years ago
|
spin_tracker_port.setValue(pref->getTrackerPort());
|
||
14 years ago
|
setRow(TRACKER_PORT, tr("Embedded tracker port"), &spin_tracker_port);
|
||
11 years ago
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||
11 years ago
|
cb_update_check.setChecked(pref->isUpdateCheckEnabled());
|
||
14 years ago
|
setRow(UPDATE_CHECK, tr("Check for software updates"), &cb_update_check);
|
||
14 years ago
|
#endif
|
||
11 years ago
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||
11 years ago
|
cb_use_icon_theme.setChecked(pref->useSystemIconTheme());
|
||
14 years ago
|
setRow(USE_ICON_THEME, tr("Use system icon theme"), &cb_use_icon_theme);
|
||
14 years ago
|
#endif
|
||
14 years ago
|
// Torrent deletion confirmation
|
||
11 years ago
|
cb_confirm_torrent_deletion.setChecked(pref->confirmTorrentDeletion());
|
||
14 years ago
|
setRow(CONFIRM_DELETE_TORRENT, tr("Confirm torrent deletion"), &cb_confirm_torrent_deletion);
|
||
14 years ago
|
// Tracker exchange
|
||
11 years ago
|
cb_enable_tracker_ext.setChecked(pref->trackerExchangeEnabled());
|
||
14 years ago
|
setRow(TRACKER_EXCHANGE, tr("Exchange trackers with other peers"), &cb_enable_tracker_ext);
|
||
13 years ago
|
// Announce to all trackers
|
||
11 years ago
|
cb_announce_all_trackers.setChecked(pref->announceToAllTrackers());
|
||
13 years ago
|
setRow(ANNOUNCE_ALL_TRACKERS, tr("Always announce to all trackers"), &cb_announce_all_trackers);
|
||
15 years ago
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif // ADVANCEDSETTINGS_H
|