transmission/qt/PrefsDialog.cc

682 lines
21 KiB
C++
Raw Normal View History

2009-04-09 18:55:47 +00:00
/*
* This file Copyright (C) 2009-2015 Mnemosyne LLC
2009-04-09 18:55:47 +00:00
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
2009-04-09 18:55:47 +00:00
*
*/
#ifdef _WIN32
#include <winsock2.h> // FD_SETSIZE
#else
#include <sys/select.h> // FD_SETSIZE
#endif
2009-04-09 18:55:47 +00:00
#include <cassert>
#include <QCheckBox>
#include <QComboBox>
2009-10-06 00:27:26 +00:00
#include <QCoreApplication>
2009-04-09 18:55:47 +00:00
#include <QDialogButtonBox>
#include <QDoubleSpinBox>
2009-10-06 00:27:26 +00:00
#include <QFileIconProvider>
#include <QFileInfo>
2009-04-09 18:55:47 +00:00
#include <QHBoxLayout>
2009-10-06 00:27:26 +00:00
#include <QIcon>
2009-04-09 18:55:47 +00:00
#include <QLabel>
#include <QLineEdit>
#include <QList>
2009-10-06 00:27:26 +00:00
#include <QMessageBox>
2009-04-09 18:55:47 +00:00
#include <QPushButton>
#include <QSpinBox>
#include <QStyle>
#include <QTabWidget>
#include <QTime>
#include <QTimeEdit>
#include <QTimer>
#include <QVBoxLayout>
#include "ColumnResizer.h"
#include "FreeSpaceLabel.h"
#include "Formatter.h"
#include "Prefs.h"
#include "PrefsDialog.h"
#include "Session.h"
#include "Utils.h"
2009-04-09 18:55:47 +00:00
/***
****
***/
namespace
{
2013-09-14 22:45:04 +00:00
const char * PREF_KEY ("pref-key");
void
setPrefKey (QObject * object, int key)
{
object->setProperty (PREF_KEY, key);
}
int
getPrefKey (const QObject * object)
{
return object->property (PREF_KEY).toInt ();
}
int
qtDayToTrDay (int day)
{
switch (day)
{
case Qt::Monday:
return TR_SCHED_MON;
case Qt::Tuesday:
return TR_SCHED_TUES;
case Qt::Wednesday:
return TR_SCHED_WED;
case Qt::Thursday:
return TR_SCHED_THURS;
case Qt::Friday:
return TR_SCHED_FRI;
case Qt::Saturday:
return TR_SCHED_SAT;
case Qt::Sunday:
return TR_SCHED_SUN;
default:
assert (0 && "Invalid day of week");
return 0;
}
}
QString
qtDayName (int day)
{
switch (day)
{
case Qt::Monday:
return PrefsDialog::tr ("Monday");
case Qt::Tuesday:
return PrefsDialog::tr ("Tuesday");
case Qt::Wednesday:
return PrefsDialog::tr ("Wednesday");
case Qt::Thursday:
return PrefsDialog::tr ("Thursday");
case Qt::Friday:
return PrefsDialog::tr ("Friday");
case Qt::Saturday:
return PrefsDialog::tr ("Saturday");
case Qt::Sunday:
return PrefsDialog::tr ("Sunday");
default:
assert (0 && "Invalid day of week");
return QString ();
}
}
}
2009-04-09 18:55:47 +00:00
bool
PrefsDialog::updateWidgetValue (QWidget * widget, int prefKey)
{
if (auto w = qobject_cast<QCheckBox*> (widget))
w->setChecked (myPrefs.getBool (prefKey));
else if (auto w = qobject_cast<QSpinBox*> (widget))
w->setValue (myPrefs.getInt (prefKey));
else if (auto w = qobject_cast<QDoubleSpinBox*> (widget))
w->setValue (myPrefs.getDouble (prefKey));
else if (auto w = qobject_cast<QTimeEdit*> (widget))
w->setTime (QTime (0, 0).addSecs (myPrefs.getInt(prefKey) * 60));
else if (auto w = qobject_cast<QLineEdit*> (widget))
w->setText (myPrefs.getString (prefKey));
else if (auto w = qobject_cast<PathButton*> (widget))
2015-01-25 19:55:05 +00:00
w->setPath (myPrefs.getString (prefKey));
else if (auto w = qobject_cast<FreeSpaceLabel*> (widget))
w->setPath (myPrefs.getString (prefKey));
else
return false;
return true;
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::linkWidgetToPref (QWidget * widget, int prefKey)
2009-04-09 18:55:47 +00:00
{
setPrefKey (widget, prefKey);
updateWidgetValue (widget, prefKey);
myWidgets.insert (prefKey, widget);
if (widget->inherits ("QCheckBox"))
connect (widget, SIGNAL (toggled (bool)), SLOT (checkBoxToggled (bool)));
else if (widget->inherits ("QTimeEdit"))
connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ()));
else if (widget->inherits ("QLineEdit"))
connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ()));
else if (widget->inherits ("PathButton"))
2015-01-25 19:55:05 +00:00
connect (widget, SIGNAL (pathChanged (QString)), SLOT (pathChanged (QString)));
else if (widget->inherits ("QAbstractSpinBox"))
connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ()));
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::checkBoxToggled (bool checked)
2009-04-09 18:55:47 +00:00
{
if (auto c = qobject_cast<QCheckBox*> (sender ()))
setPref (getPrefKey (c), checked);
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::spinBoxEditingFinished ()
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
const QObject * spin = sender();
const int key = getPrefKey (spin);
2013-09-14 22:45:04 +00:00
if (auto e = qobject_cast<const QDoubleSpinBox*> (spin))
setPref (key, e->value ());
else if (auto e = qobject_cast<const QSpinBox*> (spin))
setPref (key, e->value ());
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::timeEditingFinished ()
2009-04-09 18:55:47 +00:00
{
if (auto e = qobject_cast<const QTimeEdit*> (sender ()))
setPref(getPrefKey (e), QTime (0, 0).secsTo (e->time()) / 60);
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::lineEditingFinished ()
2009-04-09 18:55:47 +00:00
{
if (auto e = qobject_cast<const QLineEdit*> (sender ()))
{
if (e->isModified ())
setPref (getPrefKey (e), e->text());
}
2009-04-09 18:55:47 +00:00
}
2013-09-14 22:45:04 +00:00
2015-01-25 19:55:05 +00:00
void
PrefsDialog::pathChanged (const QString& path)
{
if (auto b = qobject_cast<const PathButton*> (sender ()))
2015-01-25 19:55:05 +00:00
setPref(getPrefKey (b), path);
}
2009-04-09 18:55:47 +00:00
/***
****
***/
void
PrefsDialog::initRemoteTab ()
{
linkWidgetToPref (ui.enableRpcCheck, Prefs::RPC_ENABLED);
linkWidgetToPref (ui.rpcPortSpin, Prefs::RPC_PORT);
linkWidgetToPref (ui.requireRpcAuthCheck, Prefs::RPC_AUTH_REQUIRED);
linkWidgetToPref (ui.rpcUsernameEdit, Prefs::RPC_USERNAME);
linkWidgetToPref (ui.rpcPasswordEdit, Prefs::RPC_PASSWORD);
linkWidgetToPref (ui.enableRpcWhitelistCheck, Prefs::RPC_WHITELIST_ENABLED);
linkWidgetToPref (ui.rpcWhitelistEdit, Prefs::RPC_WHITELIST);
myWebWidgets <<
ui.rpcPortLabel <<
ui.rpcPortSpin <<
ui.requireRpcAuthCheck <<
ui.enableRpcWhitelistCheck;
myWebAuthWidgets <<
ui.rpcUsernameLabel <<
ui.rpcUsernameEdit <<
ui.rpcPasswordLabel <<
ui.rpcPasswordEdit;
myWebWhitelistWidgets <<
ui.rpcWhitelistLabel <<
ui.rpcWhitelistEdit;
myUnsupportedWhenRemote <<
ui.enableRpcCheck <<
myWebWidgets <<
myWebAuthWidgets <<
myWebWhitelistWidgets;
connect (ui.openWebClientButton, SIGNAL (clicked ()), &mySession, SLOT (launchWebInterface ()));
2009-04-09 18:55:47 +00:00
}
/***
****
***/
void
PrefsDialog::altSpeedDaysEdited (int i)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
const int value = qobject_cast<QComboBox*>(sender())->itemData(i).toInt();
setPref (Prefs::ALT_SPEED_LIMIT_TIME_DAY, value);
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::initSpeedTab ()
2013-09-14 22:45:04 +00:00
{
const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB);
const QLocale locale;
ui.uploadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
ui.downloadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
ui.altUploadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
ui.altDownloadSpeedLimitSpin->setSuffix (QString::fromLatin1 (" %1").arg (speed_K_str));
ui.altSpeedLimitDaysCombo->addItem (tr ("Every Day"), QVariant (TR_SCHED_ALL));
ui.altSpeedLimitDaysCombo->addItem (tr ("Weekdays"), QVariant (TR_SCHED_WEEKDAY));
ui.altSpeedLimitDaysCombo->addItem (tr ("Weekends"), QVariant (TR_SCHED_WEEKEND));
ui.altSpeedLimitDaysCombo->insertSeparator (ui.altSpeedLimitDaysCombo->count ());
for (int i = locale.firstDayOfWeek (); i <= Qt::Sunday; ++i)
ui.altSpeedLimitDaysCombo->addItem (qtDayName (i), qtDayToTrDay (i));
for (int i = Qt::Monday; i < locale.firstDayOfWeek (); ++i)
ui.altSpeedLimitDaysCombo->addItem (qtDayName (i), qtDayToTrDay (i));
ui.altSpeedLimitDaysCombo->setCurrentIndex (ui.altSpeedLimitDaysCombo->findData (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_TIME_DAY)));
linkWidgetToPref (ui.uploadSpeedLimitCheck, Prefs::USPEED_ENABLED);
linkWidgetToPref (ui.uploadSpeedLimitSpin, Prefs::USPEED);
linkWidgetToPref (ui.downloadSpeedLimitCheck, Prefs::DSPEED_ENABLED);
linkWidgetToPref (ui.downloadSpeedLimitSpin, Prefs::DSPEED);
linkWidgetToPref (ui.altUploadSpeedLimitSpin, Prefs::ALT_SPEED_LIMIT_UP);
linkWidgetToPref (ui.altDownloadSpeedLimitSpin, Prefs::ALT_SPEED_LIMIT_DOWN);
linkWidgetToPref (ui.altSpeedLimitScheduleCheck, Prefs::ALT_SPEED_LIMIT_TIME_ENABLED);
linkWidgetToPref (ui.altSpeedLimitStartTimeEdit, Prefs::ALT_SPEED_LIMIT_TIME_BEGIN);
linkWidgetToPref (ui.altSpeedLimitEndTimeEdit, Prefs::ALT_SPEED_LIMIT_TIME_END);
mySchedWidgets <<
ui.altSpeedLimitStartTimeEdit <<
ui.altSpeedLimitToLabel <<
ui.altSpeedLimitEndTimeEdit <<
ui.altSpeedLimitDaysLabel <<
ui.altSpeedLimitDaysCombo;
ColumnResizer * cr (new ColumnResizer (this));
cr->addLayout (ui.speedLimitsSectionLayout);
cr->addLayout (ui.altSpeedLimitsSectionLayout);
cr->update ();
connect (ui.altSpeedLimitDaysCombo, SIGNAL (activated (int)), SLOT (altSpeedDaysEdited (int)));
2009-04-09 18:55:47 +00:00
}
/***
****
***/
void
PrefsDialog::initDesktopTab ()
{
linkWidgetToPref (ui.showTrayIconCheck, Prefs::SHOW_TRAY_ICON);
linkWidgetToPref (ui.startMinimizedCheck, Prefs::START_MINIMIZED);
linkWidgetToPref (ui.notifyOnTorrentAddedCheck, Prefs::SHOW_NOTIFICATION_ON_ADD);
linkWidgetToPref (ui.notifyOnTorrentCompletedCheck, Prefs::SHOW_NOTIFICATION_ON_COMPLETE);
linkWidgetToPref (ui.playSoundOnTorrentCompletedCheck, Prefs::COMPLETE_SOUND_ENABLED);
}
/***
****
***/
2009-04-09 18:55:47 +00:00
void
PrefsDialog::onPortTested (bool isOpen)
2009-04-09 18:55:47 +00:00
{
ui.testPeerPortButton->setEnabled (true);
2013-09-14 22:45:04 +00:00
myWidgets[Prefs::PEER_PORT]->setEnabled (true);
ui.peerPortStatusLabel->setText (isOpen ? tr ("Port is <b>open</b>")
: tr ("Port is <b>closed</b>"));
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::onPortTest ()
2009-04-09 18:55:47 +00:00
{
ui.peerPortStatusLabel->setText (tr ("Testing TCP Port..."));
ui.testPeerPortButton->setEnabled (false);
2013-09-14 22:45:04 +00:00
myWidgets[Prefs::PEER_PORT]->setEnabled (false);
mySession.portTest ();
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::initNetworkTab ()
2013-09-14 22:45:04 +00:00
{
ui.torrentPeerLimitSpin->setRange (1, FD_SETSIZE);
ui.globalPeerLimitSpin->setRange (1, FD_SETSIZE);
2013-09-14 22:45:04 +00:00
linkWidgetToPref (ui.peerPortSpin, Prefs::PEER_PORT);
linkWidgetToPref (ui.randomPeerPortCheck, Prefs::PEER_PORT_RANDOM_ON_START);
linkWidgetToPref (ui.enablePortForwardingCheck, Prefs::PORT_FORWARDING);
linkWidgetToPref (ui.torrentPeerLimitSpin, Prefs::PEER_LIMIT_TORRENT);
linkWidgetToPref (ui.globalPeerLimitSpin, Prefs::PEER_LIMIT_GLOBAL);
linkWidgetToPref (ui.enableUtpCheck, Prefs::UTP_ENABLED);
linkWidgetToPref (ui.enablePexCheck, Prefs::PEX_ENABLED);
linkWidgetToPref (ui.enableDhtCheck, Prefs::DHT_ENABLED);
linkWidgetToPref (ui.enableLpdCheck, Prefs::LPD_ENABLED);
2013-09-14 22:45:04 +00:00
ColumnResizer * cr (new ColumnResizer (this));
cr->addLayout (ui.incomingPeersSectionLayout);
cr->addLayout (ui.peerLimitsSectionLayout);
cr->update ();
2013-09-14 22:45:04 +00:00
connect (ui.testPeerPortButton, SIGNAL (clicked ()), SLOT (onPortTest ()));
connect (&mySession, SIGNAL (portTested (bool)), SLOT (onPortTested (bool)));
2009-04-09 18:55:47 +00:00
}
/***
****
***/
void
PrefsDialog::onBlocklistDialogDestroyed (QObject * o)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
Q_UNUSED (o);
2009-04-09 18:55:47 +00:00
2013-09-14 22:45:04 +00:00
myBlocklistDialog = 0;
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::onUpdateBlocklistCancelled ()
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
disconnect (&mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int)));
myBlocklistDialog->deleteLater ();
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::onBlocklistUpdated (int n)
2009-04-09 18:55:47 +00:00
{
myBlocklistDialog->setText (tr ("<b>Update succeeded!</b><p>Blocklist now has %Ln rule(s).", 0, n));
2013-09-14 22:45:04 +00:00
myBlocklistDialog->setTextFormat (Qt::RichText);
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::onUpdateBlocklistClicked ()
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
myBlocklistDialog = new QMessageBox (QMessageBox::Information,
QString(),
tr ("<b>Update Blocklist</b><p>Getting new blocklist..."),
QMessageBox::Close,
this);
connect (myBlocklistDialog, SIGNAL(rejected()), this, SLOT(onUpdateBlocklistCancelled()));
connect (&mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int)));
myBlocklistDialog->show ();
mySession.updateBlocklist ();
2009-04-09 18:55:47 +00:00
}
2009-04-09 18:55:47 +00:00
void
PrefsDialog::encryptionEdited (int i)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
const int value (qobject_cast<QComboBox*>(sender())->itemData(i).toInt ());
setPref (Prefs::ENCRYPTION, value);
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::initPrivacyTab ()
2009-04-09 18:55:47 +00:00
{
ui.encryptionModeCombo->addItem (tr ("Allow encryption"), 0);
ui.encryptionModeCombo->addItem (tr ("Prefer encryption"), 1);
ui.encryptionModeCombo->addItem (tr ("Require encryption"), 2);
linkWidgetToPref (ui.encryptionModeCombo, Prefs::ENCRYPTION);
linkWidgetToPref (ui.blocklistCheck, Prefs::BLOCKLIST_ENABLED);
linkWidgetToPref (ui.blocklistEdit, Prefs::BLOCKLIST_URL);
linkWidgetToPref (ui.autoUpdateBlocklistCheck, Prefs::BLOCKLIST_UPDATES_ENABLED);
myBlockWidgets <<
ui.blocklistEdit <<
ui.blocklistStatusLabel <<
ui.updateBlocklistButton <<
ui.autoUpdateBlocklistCheck;
ColumnResizer * cr (new ColumnResizer (this));
cr->addLayout (ui.encryptionSectionLayout);
cr->addLayout (ui.blocklistSectionLayout);
cr->update ();
connect (ui.encryptionModeCombo, SIGNAL (activated (int)), SLOT (encryptionEdited (int)));
connect (ui.updateBlocklistButton, SIGNAL (clicked ()), SLOT (onUpdateBlocklistClicked ()));
2013-09-14 22:45:04 +00:00
updateBlocklistLabel ();
2009-04-09 18:55:47 +00:00
}
/***
****
***/
void
PrefsDialog::onIdleLimitChanged ()
{
//: Spin box suffix, "Stop seeding if idle for: [ 5 minutes ]" (includes leading space after the number, if needed)
const QString unitsSuffix = tr (" minute(s)", 0, ui.idleLimitSpin->value ());
if (ui.idleLimitSpin->suffix () != unitsSuffix)
ui.idleLimitSpin->setSuffix (unitsSuffix);
}
void
PrefsDialog::initSeedingTab ()
2009-04-09 18:55:47 +00:00
{
linkWidgetToPref (ui.ratioLimitCheck, Prefs::RATIO_ENABLED);
linkWidgetToPref (ui.ratioLimitSpin, Prefs::RATIO);
linkWidgetToPref (ui.idleLimitCheck, Prefs::IDLE_LIMIT_ENABLED);
linkWidgetToPref (ui.idleLimitSpin, Prefs::IDLE_LIMIT);
connect (ui.idleLimitSpin, SIGNAL (valueChanged (int)), SLOT (onIdleLimitChanged ()));
onIdleLimitChanged ();
}
void
PrefsDialog::onQueueStalledMinutesChanged ()
{
//: Spin box suffix, "Download is inactive if data sharing stopped: [ 5 minutes ago ]" (includes leading space after the number, if needed)
const QString unitsSuffix = tr (" minute(s) ago", 0, ui.queueStalledMinutesSpin->value ());
if (ui.queueStalledMinutesSpin->suffix () != unitsSuffix)
ui.queueStalledMinutesSpin->setSuffix (unitsSuffix);
}
void
PrefsDialog::initDownloadingTab ()
2013-09-14 22:45:04 +00:00
{
ui.watchDirButton->setMode (PathButton::DirectoryMode);
ui.downloadDirButton->setMode (PathButton::DirectoryMode);
ui.incompleteDirButton->setMode (PathButton::DirectoryMode);
ui.completionScriptButton->setMode (PathButton::FileMode);
2015-01-25 19:55:05 +00:00
ui.watchDirButton->setTitle (tr ("Select Watch Directory"));
ui.downloadDirButton->setTitle (tr ("Select Destination"));
ui.incompleteDirButton->setTitle (tr ("Select Incomplete Directory"));
ui.completionScriptButton->setTitle (tr ("Select \"Torrent Done\" Script"));
2015-01-25 19:55:05 +00:00
ui.watchDirStack->setMinimumWidth (200);
ui.downloadDirFreeSpaceLabel->setSession (mySession);
ui.downloadDirFreeSpaceLabel->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR));
linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED);
linkWidgetToPref (ui.watchDirButton, Prefs::DIR_WATCH);
linkWidgetToPref (ui.watchDirEdit, Prefs::DIR_WATCH);
linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT);
linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START);
linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL);
linkWidgetToPref (ui.downloadDirButton, Prefs::DOWNLOAD_DIR);
linkWidgetToPref (ui.downloadDirEdit, Prefs::DOWNLOAD_DIR);
linkWidgetToPref (ui.downloadDirFreeSpaceLabel, Prefs::DOWNLOAD_DIR);
linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE);
linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES);
linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES);
linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED);
linkWidgetToPref (ui.incompleteDirButton, Prefs::INCOMPLETE_DIR);
linkWidgetToPref (ui.incompleteDirEdit, Prefs::INCOMPLETE_DIR);
linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
linkWidgetToPref (ui.completionScriptButton, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
linkWidgetToPref (ui.completionScriptEdit, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
ColumnResizer * cr (new ColumnResizer (this));
cr->addLayout (ui.addingSectionLayout);
cr->addLayout (ui.downloadQueueSectionLayout);
cr->addLayout (ui.incompleteSectionLayout);
cr->update ();
connect (ui.queueStalledMinutesSpin, SIGNAL (valueChanged (int)), SLOT (onQueueStalledMinutesChanged ()));
updateDownloadingWidgetsLocality ();
onQueueStalledMinutesChanged ();
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::updateDownloadingWidgetsLocality ()
{
ui.watchDirStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.watchDirButton) : ui.watchDirEdit);
ui.downloadDirStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.downloadDirButton) : ui.downloadDirEdit);
ui.incompleteDirStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.incompleteDirButton) : ui.incompleteDirEdit);
ui.completionScriptStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.completionScriptButton) : ui.completionScriptEdit);
ui.watchDirStack->setFixedHeight (ui.watchDirStack->currentWidget ()->sizeHint ().height ());
ui.downloadDirStack->setFixedHeight (ui.downloadDirStack->currentWidget ()->sizeHint ().height ());
ui.incompleteDirStack->setFixedHeight (ui.incompleteDirStack->currentWidget ()->sizeHint ().height ());
ui.completionScriptStack->setFixedHeight (ui.completionScriptStack->currentWidget ()->sizeHint ().height ());
ui.downloadDirLabel->setBuddy (ui.downloadDirStack->currentWidget ());
}
2009-04-09 18:55:47 +00:00
/***
****
***/
PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent):
BaseDialog (parent),
2013-09-14 22:45:04 +00:00
mySession (session),
2015-06-12 22:12:12 +00:00
myPrefs (prefs),
myIsServer (session.isServer ()),
myIsLocal (mySession.isLocal ())
2013-09-14 22:45:04 +00:00
{
ui.setupUi (this);
2013-09-14 22:45:04 +00:00
initSpeedTab ();
initDownloadingTab ();
initSeedingTab ();
initPrivacyTab ();
initNetworkTab ();
initDesktopTab ();
initRemoteTab ();
2013-09-14 22:45:04 +00:00
connect (&mySession, SIGNAL (sessionUpdated ()), SLOT (sessionUpdated ()));
2013-09-14 22:45:04 +00:00
QList<int> keys;
keys << Prefs::RPC_ENABLED
<< Prefs::ALT_SPEED_LIMIT_ENABLED
<< Prefs::ALT_SPEED_LIMIT_TIME_ENABLED
<< Prefs::ENCRYPTION
<< Prefs::BLOCKLIST_ENABLED
<< Prefs::DIR_WATCH
<< Prefs::DOWNLOAD_DIR
<< Prefs::INCOMPLETE_DIR
<< Prefs::INCOMPLETE_DIR_ENABLED
<< Prefs::SCRIPT_TORRENT_DONE_FILENAME;
for (const int key: keys)
2013-09-14 22:45:04 +00:00
refreshPref (key);
// if it's a remote session, disable the preferences
// that don't work in remote sessions
if (!myIsServer)
{
for (QWidget * const w: myUnsupportedWhenRemote)
2013-09-14 22:45:04 +00:00
{
w->setToolTip (tr ("Not supported by remote sessions"));
w->setEnabled (false);
2009-04-09 18:55:47 +00:00
}
}
adjustSize ();
2009-04-09 18:55:47 +00:00
}
PrefsDialog::~PrefsDialog ()
2009-04-09 18:55:47 +00:00
{
}
void
PrefsDialog::setPref (int key, const QVariant& v)
{
2013-09-14 22:45:04 +00:00
myPrefs.set (key, v);
refreshPref (key);
}
2009-04-09 18:55:47 +00:00
/***
****
***/
void
PrefsDialog::sessionUpdated ()
{
const bool isLocal = mySession.isLocal ();
if (myIsLocal != isLocal)
{
myIsLocal = isLocal;
updateDownloadingWidgetsLocality ();
}
2013-09-14 22:45:04 +00:00
updateBlocklistLabel ();
}
void
PrefsDialog::updateBlocklistLabel ()
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
const int n = mySession.blocklistSize ();
ui.blocklistStatusLabel->setText (tr ("<i>Blocklist contains %Ln rule(s)</i>", 0, n));
2009-04-09 18:55:47 +00:00
}
void
PrefsDialog::refreshPref (int key)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
switch (key)
2009-04-09 18:55:47 +00:00
{
case Prefs::RPC_ENABLED:
case Prefs::RPC_WHITELIST_ENABLED:
case Prefs::RPC_AUTH_REQUIRED:
2013-09-14 22:45:04 +00:00
{
const bool enabled (myPrefs.getBool (Prefs::RPC_ENABLED));
const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED));
const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED));
for (QWidget * const w: myWebWhitelistWidgets)
w->setEnabled (enabled && whitelist);
for (QWidget * const w: myWebAuthWidgets)
w->setEnabled (enabled && auth);
for (QWidget * const w: myWebWidgets)
w->setEnabled (enabled);
2013-09-14 22:45:04 +00:00
break;
2009-04-09 18:55:47 +00:00
}
case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED:
2013-09-14 22:45:04 +00:00
{
const bool enabled = myPrefs.getBool (key);
for (QWidget * const w: mySchedWidgets)
w->setEnabled (enabled);
2013-09-14 22:45:04 +00:00
break;
2009-04-09 18:55:47 +00:00
}
case Prefs::BLOCKLIST_ENABLED:
2013-09-14 22:45:04 +00:00
{
const bool enabled = myPrefs.getBool (key);
for (QWidget * const w: myBlockWidgets)
w->setEnabled (enabled);
2013-09-14 22:45:04 +00:00
break;
2009-04-09 18:55:47 +00:00
}
case Prefs::PEER_PORT:
ui.peerPortStatusLabel->setText (tr ("Status unknown"));
ui.testPeerPortButton->setEnabled (true);
2013-09-14 22:45:04 +00:00
break;
2009-04-09 18:55:47 +00:00
2013-09-14 22:45:04 +00:00
default:
break;
2009-04-09 18:55:47 +00:00
}
2013-09-14 22:45:04 +00:00
key2widget_t::iterator it (myWidgets.find (key));
if (it != myWidgets.end ())
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QWidget * w (it.value ());
if (!updateWidgetValue (w, key))
2009-04-09 18:55:47 +00:00
{
if (key == Prefs::ENCRYPTION)
{
QComboBox * comboBox (qobject_cast<QComboBox*> (w));
const int index = comboBox->findData (myPrefs.getInt (key));
comboBox->setCurrentIndex (index);
}
2009-04-09 18:55:47 +00:00
}
}
}