2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2009-2023 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "PrefsDialog.h"
|
|
|
|
|
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>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QMessageBox>
|
2022-02-21 03:25:49 +00:00
|
|
|
#include <QPlainTextEdit>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QTimeEdit>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "ColumnResizer.h"
|
|
|
|
#include "Formatter.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "FreeSpaceLabel.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Prefs.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-29 20:11:57 +00:00
|
|
|
class PreferenceWidget
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
static char const* const PrefKey;
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-29 20:11:57 +00:00
|
|
|
public:
|
2021-08-15 09:41:48 +00:00
|
|
|
explicit PreferenceWidget(QObject* object)
|
|
|
|
: object_(object)
|
2017-04-29 20:11:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2020-06-05 19:02:11 +00:00
|
|
|
[[nodiscard]] bool is() const
|
2017-04-29 20:11:57 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return qobject_cast<T*>(object_) != nullptr;
|
2017-04-29 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2020-06-05 19:02:11 +00:00
|
|
|
[[nodiscard]] T const* as() const
|
2017-04-29 20:11:57 +00:00
|
|
|
{
|
|
|
|
assert(is<T>());
|
2020-06-05 19:02:11 +00:00
|
|
|
return static_cast<T const*>(object_);
|
2017-04-29 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2020-06-05 19:02:11 +00:00
|
|
|
[[nodiscard]] T* as()
|
2017-04-29 20:11:57 +00:00
|
|
|
{
|
|
|
|
assert(is<T>());
|
2020-06-05 19:02:11 +00:00
|
|
|
return static_cast<T*>(object_);
|
2017-04-29 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setPrefKey(int key)
|
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
object_->setProperty(PrefKey, key);
|
2017-04-29 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
[[nodiscard]] int getPrefKey() const
|
2017-04-29 20:11:57 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return object_->property(PrefKey).toInt();
|
2017-04-29 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-06-05 19:02:11 +00:00
|
|
|
QObject* const object_;
|
2017-04-29 20:11:57 +00:00
|
|
|
};
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
char const* const PreferenceWidget::PrefKey = "pref-key";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
int qtDayToTrDay(int day)
|
|
|
|
{
|
2015-01-25 15:47:03 +00:00
|
|
|
switch (day)
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case Qt::Monday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_MON;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case Qt::Tuesday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_TUES;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case Qt::Wednesday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_WED;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case Qt::Thursday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_THURS;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case Qt::Friday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_FRI;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case Qt::Saturday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_SAT;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case Qt::Sunday:
|
2015-01-25 15:47:03 +00:00
|
|
|
return TR_SCHED_SUN;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
default:
|
2017-04-30 16:25:26 +00:00
|
|
|
assert(false && "Invalid day of week");
|
2015-01-25 15:47:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString qtDayName(int day)
|
|
|
|
{
|
2015-01-25 15:47:03 +00:00
|
|
|
switch (day)
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
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:
|
2017-04-30 16:25:26 +00:00
|
|
|
assert(false && "Invalid day of week");
|
2022-02-08 03:56:04 +00:00
|
|
|
return {};
|
2015-01-25 15:47:03 +00:00
|
|
|
}
|
2015-12-06 17:27:21 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
bool PrefsDialog::updateWidgetValue(QWidget* widget, int pref_key) const
|
2015-01-25 15:47:03 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget pref_widget(widget);
|
2017-04-29 20:11:57 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (pref_widget.is<QCheckBox>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<QCheckBox>()->setChecked(prefs_.getBool(pref_key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<QSpinBox>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<QSpinBox>()->setValue(prefs_.getInt(pref_key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<QDoubleSpinBox>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<QDoubleSpinBox>()->setValue(prefs_.getDouble(pref_key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<QTimeEdit>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<QTimeEdit>()->setTime(QTime(0, 0).addSecs(prefs_.getInt(pref_key) * 60));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<QLineEdit>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<QLineEdit>()->setText(prefs_.getString(pref_key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<PathButton>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<PathButton>()->setPath(prefs_.getString(pref_key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<FreeSpaceLabel>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.as<FreeSpaceLabel>()->setPath(prefs_.getString(pref_key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2022-02-20 17:54:20 +00:00
|
|
|
else if (pref_widget.is<QPlainTextEdit>())
|
|
|
|
{
|
|
|
|
pref_widget.as<QPlainTextEdit>()->setPlainText(prefs_.getString(pref_key));
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return true;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void PrefsDialog::linkWidgetToPref(QWidget* widget, int pref_key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget pref_widget(widget);
|
2017-04-29 20:11:57 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
pref_widget.setPrefKey(pref_key);
|
|
|
|
updateWidgetValue(widget, pref_key);
|
2023-06-19 21:51:34 +00:00
|
|
|
widgets_.try_emplace(pref_key, widget);
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const* check_box = qobject_cast<QCheckBox*>(widget); check_box != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(check_box, &QAbstractButton::toggled, this, &PrefsDialog::checkBoxToggled);
|
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-10-31 18:56:12 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const* time_edit = qobject_cast<QTimeEdit*>(widget); time_edit != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(time_edit, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::timeEditingFinished);
|
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-10-31 18:56:12 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const* line_edit = qobject_cast<QLineEdit*>(widget); line_edit != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(line_edit, &QLineEdit::editingFinished, this, &PrefsDialog::lineEditingFinished);
|
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-10-31 18:56:12 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const* path_button = qobject_cast<PathButton*>(widget); path_button != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(path_button, &PathButton::pathChanged, this, &PrefsDialog::pathChanged);
|
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-10-31 18:56:12 +00:00
|
|
|
|
2022-02-03 13:02:11 +00:00
|
|
|
if (auto const* spin_box = qobject_cast<QAbstractSpinBox*>(widget); spin_box != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(spin_box, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::spinBoxEditingFinished);
|
2022-02-20 17:54:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-02-21 03:25:49 +00:00
|
|
|
}
|
2022-02-20 17:54:20 +00:00
|
|
|
|
2022-02-21 03:25:49 +00:00
|
|
|
static bool isDescendantOf(QObject const* descendant, QObject const* ancestor)
|
|
|
|
{
|
|
|
|
if (ancestor == nullptr)
|
2022-02-20 17:54:20 +00:00
|
|
|
{
|
2022-02-21 03:25:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while (descendant != nullptr)
|
|
|
|
{
|
|
|
|
if (descendant == ancestor)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
descendant = descendant->parent();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrefsDialog::focusChanged(QWidget* old, QWidget* cur)
|
|
|
|
{
|
|
|
|
// We don't want to change the preference every time there's a keystroke
|
|
|
|
// in a QPlainTextEdit, so instead of connecting to the textChanged signal,
|
|
|
|
// only update the pref when the text changed AND focus was lost.
|
|
|
|
char const constexpr* const StartValue = "StartValue";
|
|
|
|
|
|
|
|
if (auto* const edit = qobject_cast<QPlainTextEdit*>(cur); isDescendantOf(edit, this))
|
|
|
|
{
|
|
|
|
edit->setProperty(StartValue, edit->toPlainText());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto const* const edit = qobject_cast<QPlainTextEdit*>(old); isDescendantOf(edit, this))
|
|
|
|
{
|
|
|
|
if (auto const val = edit->toPlainText(); val != edit->property(StartValue).toString())
|
|
|
|
{
|
|
|
|
setPref(PreferenceWidget{ old }.getPrefKey(), val);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2022-02-21 03:25:49 +00:00
|
|
|
|
|
|
|
// (TODO: we probably want to do this for single-line text entries too?)
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::checkBoxToggled(bool checked)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget const pref_widget(sender());
|
2017-04-29 20:11:57 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (pref_widget.is<QCheckBox>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setPref(pref_widget.getPrefKey(), checked);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::spinBoxEditingFinished()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget const pref_widget(sender());
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (pref_widget.is<QDoubleSpinBox>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setPref(pref_widget.getPrefKey(), pref_widget.as<QDoubleSpinBox>()->value());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2020-05-27 21:53:12 +00:00
|
|
|
else if (pref_widget.is<QSpinBox>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setPref(pref_widget.getPrefKey(), pref_widget.as<QSpinBox>()->value());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::timeEditingFinished()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget const pref_widget(sender());
|
2017-04-29 20:11:57 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (pref_widget.is<QTimeEdit>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setPref(pref_widget.getPrefKey(), QTime(0, 0).secsTo(pref_widget.as<QTimeEdit>()->time()) / 60);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::lineEditingFinished()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget const pref_widget(sender());
|
2017-04-29 20:11:57 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (pref_widget.is<QLineEdit>())
|
2010-12-04 00:19:52 +00:00
|
|
|
{
|
2022-02-01 17:30:51 +00:00
|
|
|
auto const* const line_edit = pref_widget.as<QLineEdit>();
|
|
|
|
|
|
|
|
if (line_edit->isModified())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
setPref(pref_widget.getPrefKey(), line_edit->text());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-12-04 00:19:52 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void PrefsDialog::pathChanged(QString const& path)
|
2015-01-25 19:55:05 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
PreferenceWidget const pref_widget(sender());
|
2017-04-29 20:11:57 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (pref_widget.is<PathButton>())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setPref(pref_widget.getPrefKey(), path);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-01-25 19:55:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initRemoteTab()
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
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);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
web_widgets_ << ui_.rpcPortLabel << ui_.rpcPortSpin << ui_.requireRpcAuthCheck << ui_.enableRpcWhitelistCheck;
|
|
|
|
web_auth_widgets_ << ui_.rpcUsernameLabel << ui_.rpcUsernameEdit << ui_.rpcPasswordLabel << ui_.rpcPasswordEdit;
|
|
|
|
web_whitelist_widgets_ << ui_.rpcWhitelistLabel << ui_.rpcWhitelistEdit;
|
|
|
|
unsupported_when_remote_ << ui_.enableRpcCheck << web_widgets_ << web_auth_widgets_ << web_whitelist_widgets_;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.openWebClientButton, &QAbstractButton::clicked, &session_, &Session::launchWebInterface);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::altSpeedDaysEdited(int i)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const value = qobject_cast<QComboBox*>(sender())->itemData(i).toInt();
|
2017-04-19 12:04:45 +00:00
|
|
|
setPref(Prefs::ALT_SPEED_LIMIT_TIME_DAY, value);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initSpeedTab()
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
QString const speed_unit_str = Formatter::get().unitStr(Formatter::get().SPEED, Formatter::get().KB);
|
2020-06-05 19:02:11 +00:00
|
|
|
auto const suffix = QStringLiteral(" %1").arg(speed_unit_str);
|
2017-04-20 16:02:19 +00:00
|
|
|
QLocale const locale;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
ui_.uploadSpeedLimitSpin->setSuffix(suffix);
|
|
|
|
ui_.downloadSpeedLimitSpin->setSuffix(suffix);
|
|
|
|
ui_.altUploadSpeedLimitSpin->setSuffix(suffix);
|
|
|
|
ui_.altDownloadSpeedLimitSpin->setSuffix(suffix);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
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());
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int i = locale.firstDayOfWeek(); i <= Qt::Sunday; ++i)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.altSpeedLimitDaysCombo->addItem(qtDayName(i), qtDayToTrDay(i));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int i = Qt::Monday; i < locale.firstDayOfWeek(); ++i)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.altSpeedLimitDaysCombo->addItem(qtDayName(i), qtDayToTrDay(i));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
ui_.altSpeedLimitDaysCombo->setCurrentIndex(
|
|
|
|
ui_.altSpeedLimitDaysCombo->findData(prefs_.getInt(Prefs::ALT_SPEED_LIMIT_TIME_DAY)));
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
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);
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
sched_widgets_ << ui_.altSpeedLimitStartTimeEdit << ui_.altSpeedLimitToLabel << ui_.altSpeedLimitEndTimeEdit
|
|
|
|
<< ui_.altSpeedLimitDaysLabel << ui_.altSpeedLimitDaysCombo;
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* cr = new ColumnResizer(this);
|
2020-05-27 21:53:12 +00:00
|
|
|
cr->addLayout(ui_.speedLimitsSectionLayout);
|
|
|
|
cr->addLayout(ui_.altSpeedLimitsSectionLayout);
|
2017-04-19 12:04:45 +00:00
|
|
|
cr->update();
|
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.altSpeedLimitDaysCombo, qOverload<int>(&QComboBox::activated), this, &PrefsDialog::altSpeedDaysEdited);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initDesktopTab()
|
2010-08-02 03:07:42 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
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);
|
2010-08-02 03:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onPortTested(bool isOpen)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.testPeerPortButton->setEnabled(true);
|
|
|
|
widgets_[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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onPortTest()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2022-10-11 15:39:41 +00:00
|
|
|
ui_.peerPortStatusLabel->setText(tr("Testing TCP Port…"));
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.testPeerPortButton->setEnabled(false);
|
|
|
|
widgets_[Prefs::PEER_PORT]->setEnabled(false);
|
|
|
|
session_.portTest();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initNetworkTab()
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2022-11-28 20:36:39 +00:00
|
|
|
ui_.torrentPeerLimitSpin->setRange(1, INT_MAX);
|
|
|
|
ui_.globalPeerLimitSpin->setRange(1, INT_MAX);
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2020-05-27 21:53:12 +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);
|
2022-02-20 17:54:20 +00:00
|
|
|
linkWidgetToPref(ui_.defaultTrackersPlainTextEdit, Prefs::DEFAULT_TRACKERS);
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* cr = new ColumnResizer(this);
|
2020-05-27 21:53:12 +00:00
|
|
|
cr->addLayout(ui_.incomingPeersSectionLayout);
|
|
|
|
cr->addLayout(ui_.peerLimitsSectionLayout);
|
2017-04-19 12:04:45 +00:00
|
|
|
cr->update();
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.testPeerPortButton, &QAbstractButton::clicked, this, &PrefsDialog::onPortTest);
|
|
|
|
connect(&session_, &Session::portTested, this, &PrefsDialog::onPortTested);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onBlocklistDialogDestroyed(QObject* o)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
Q_UNUSED(o)
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
blocklist_dialog_ = nullptr;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onUpdateBlocklistCancelled()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
disconnect(&session_, &Session::blocklistUpdated, this, &PrefsDialog::onBlocklistUpdated);
|
2020-05-27 21:53:12 +00:00
|
|
|
blocklist_dialog_->deleteLater();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onBlocklistUpdated(int n)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2022-10-11 15:39:41 +00:00
|
|
|
blocklist_dialog_->setText(tr("<b>Update succeeded!</b><p>Blocklist now has %Ln rule(s).</p>", nullptr, n));
|
2020-05-27 21:53:12 +00:00
|
|
|
blocklist_dialog_->setTextFormat(Qt::RichText);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onUpdateBlocklistClicked()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
blocklist_dialog_ = new QMessageBox(
|
|
|
|
QMessageBox::Information,
|
|
|
|
QString(),
|
2022-10-11 15:39:41 +00:00
|
|
|
tr("<b>Update Blocklist</b><p>Getting new blocklist…</p>"),
|
2021-08-15 09:41:48 +00:00
|
|
|
QMessageBox::Close,
|
|
|
|
this);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(blocklist_dialog_, &QDialog::rejected, this, &PrefsDialog::onUpdateBlocklistCancelled);
|
|
|
|
connect(&session_, &Session::blocklistUpdated, this, &PrefsDialog::onBlocklistUpdated);
|
2020-05-27 21:53:12 +00:00
|
|
|
blocklist_dialog_->show();
|
|
|
|
session_.updateBlocklist();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::encryptionEdited(int i)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const value(qobject_cast<QComboBox*>(sender())->itemData(i).toInt());
|
2017-04-19 12:04:45 +00:00
|
|
|
setPref(Prefs::ENCRYPTION, value);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initPrivacyTab()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.encryptionModeCombo->addItem(tr("Allow encryption"), 0);
|
|
|
|
ui_.encryptionModeCombo->addItem(tr("Prefer encryption"), 1);
|
|
|
|
ui_.encryptionModeCombo->addItem(tr("Require encryption"), 2);
|
2013-01-16 21:42:03 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
linkWidgetToPref(ui_.encryptionModeCombo, Prefs::ENCRYPTION);
|
|
|
|
linkWidgetToPref(ui_.blocklistCheck, Prefs::BLOCKLIST_ENABLED);
|
|
|
|
linkWidgetToPref(ui_.blocklistEdit, Prefs::BLOCKLIST_URL);
|
|
|
|
linkWidgetToPref(ui_.autoUpdateBlocklistCheck, Prefs::BLOCKLIST_UPDATES_ENABLED);
|
2013-01-16 21:42:03 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
block_widgets_ << ui_.blocklistEdit << ui_.blocklistStatusLabel << ui_.updateBlocklistButton
|
|
|
|
<< ui_.autoUpdateBlocklistCheck;
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* cr = new ColumnResizer(this);
|
2020-05-27 21:53:12 +00:00
|
|
|
cr->addLayout(ui_.encryptionSectionLayout);
|
|
|
|
cr->addLayout(ui_.blocklistSectionLayout);
|
2017-04-19 12:04:45 +00:00
|
|
|
cr->update();
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.updateBlocklistButton, &QAbstractButton::clicked, this, &PrefsDialog::onUpdateBlocklistClicked);
|
|
|
|
connect(ui_.encryptionModeCombo, qOverload<int>(&QComboBox::activated), this, &PrefsDialog::encryptionEdited);
|
2010-10-31 17:16:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
updateBlocklistLabel();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onIdleLimitChanged()
|
2014-12-22 03:06:09 +00:00
|
|
|
{
|
2023-04-14 18:38:56 +00:00
|
|
|
//: Spin box format, "Stop seeding if idle for: [ 5 minutes ]"
|
2023-04-18 04:11:09 +00:00
|
|
|
auto const* const units_format = QT_TRANSLATE_N_NOOP("PrefsDialog", "%1 minute(s)");
|
2023-04-14 18:38:56 +00:00
|
|
|
auto const placeholder = QStringLiteral("%1");
|
|
|
|
Utils::updateSpinBoxFormat(ui_.idleLimitSpin, "PrefsDialog", units_format, placeholder);
|
2014-12-22 03:06:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initSeedingTab()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2022-02-14 04:07:12 +00:00
|
|
|
ui_.doneSeedingScriptButton->setTitle(tr("Select \"Torrent Done Seeding\" Script"));
|
|
|
|
|
2020-05-27 21:53:12 +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);
|
2022-02-14 04:07:12 +00:00
|
|
|
linkWidgetToPref(ui_.doneSeedingScriptCheck, Prefs::SCRIPT_TORRENT_DONE_SEEDING_ENABLED);
|
|
|
|
linkWidgetToPref(ui_.doneSeedingScriptButton, Prefs::SCRIPT_TORRENT_DONE_SEEDING_FILENAME);
|
|
|
|
linkWidgetToPref(ui_.doneSeedingScriptEdit, Prefs::SCRIPT_TORRENT_DONE_SEEDING_FILENAME);
|
2009-10-20 14:01:15 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(ui_.idleLimitSpin, qOverload<int>(&QSpinBox::valueChanged), this, &PrefsDialog::onIdleLimitChanged);
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2022-02-14 04:07:12 +00:00
|
|
|
updateSeedingWidgetsLocality();
|
2017-04-19 12:04:45 +00:00
|
|
|
onIdleLimitChanged();
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::onQueueStalledMinutesChanged()
|
2015-01-11 21:10:46 +00:00
|
|
|
{
|
2023-04-14 18:38:56 +00:00
|
|
|
//: Spin box format, "Download is inactive if data sharing stopped: [ 5 minutes ago ]"
|
2023-04-18 04:11:09 +00:00
|
|
|
auto const* const units_format = QT_TRANSLATE_N_NOOP("PrefsDialog", "%1 minute(s) ago");
|
2023-04-14 18:38:56 +00:00
|
|
|
auto const placeholder = QStringLiteral("%1");
|
|
|
|
Utils::updateSpinBoxFormat(ui_.queueStalledMinutesSpin, "PrefsDialog", units_format, placeholder);
|
2015-01-11 21:10:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::initDownloadingTab()
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.watchDirButton->setMode(PathButton::DirectoryMode);
|
|
|
|
ui_.downloadDirButton->setMode(PathButton::DirectoryMode);
|
|
|
|
ui_.incompleteDirButton->setMode(PathButton::DirectoryMode);
|
2022-02-14 04:07:12 +00:00
|
|
|
ui_.doneDownloadingScriptButton->setMode(PathButton::FileMode);
|
|
|
|
ui_.doneSeedingScriptButton->setMode(PathButton::FileMode);
|
2020-05-27 21:53:12 +00:00
|
|
|
|
|
|
|
ui_.watchDirButton->setTitle(tr("Select Watch Directory"));
|
|
|
|
ui_.downloadDirButton->setTitle(tr("Select Destination"));
|
|
|
|
ui_.incompleteDirButton->setTitle(tr("Select Incomplete Directory"));
|
2022-02-14 04:07:12 +00:00
|
|
|
ui_.doneDownloadingScriptButton->setTitle(tr("Select \"Torrent Done Downloading\" Script"));
|
2020-05-27 21:53:12 +00:00
|
|
|
|
|
|
|
ui_.watchDirStack->setMinimumWidth(200);
|
|
|
|
|
|
|
|
ui_.downloadDirFreeSpaceLabel->setSession(session_);
|
|
|
|
ui_.downloadDirFreeSpaceLabel->setPath(prefs_.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);
|
2022-01-23 15:57:21 +00:00
|
|
|
linkWidgetToPref(ui_.detectTorrentFromClipboard, Prefs::READ_CLIPBOARD);
|
2020-05-27 21:53:12 +00:00
|
|
|
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);
|
2022-02-14 04:07:12 +00:00
|
|
|
linkWidgetToPref(ui_.doneDownloadingScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
|
|
|
|
linkWidgetToPref(ui_.doneDownloadingScriptButton, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
|
|
|
|
linkWidgetToPref(ui_.doneDownloadingScriptEdit, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* cr = new ColumnResizer(this);
|
2020-05-27 21:53:12 +00:00
|
|
|
cr->addLayout(ui_.addingSectionLayout);
|
|
|
|
cr->addLayout(ui_.downloadQueueSectionLayout);
|
|
|
|
cr->addLayout(ui_.incompleteSectionLayout);
|
2017-04-19 12:04:45 +00:00
|
|
|
cr->update();
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
connect(
|
|
|
|
ui_.queueStalledMinutesSpin,
|
|
|
|
qOverload<int>(&QSpinBox::valueChanged),
|
|
|
|
this,
|
|
|
|
&PrefsDialog::onQueueStalledMinutesChanged);
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
updateDownloadingWidgetsLocality();
|
|
|
|
onQueueStalledMinutesChanged();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::updateDownloadingWidgetsLocality()
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.watchDirStack->setCurrentWidget(is_local_ ? static_cast<QWidget*>(ui_.watchDirButton) : ui_.watchDirEdit);
|
|
|
|
ui_.downloadDirStack->setCurrentWidget(is_local_ ? static_cast<QWidget*>(ui_.downloadDirButton) : ui_.downloadDirEdit);
|
2021-08-15 09:41:48 +00:00
|
|
|
ui_.incompleteDirStack->setCurrentWidget(
|
|
|
|
is_local_ ? static_cast<QWidget*>(ui_.incompleteDirButton) : ui_.incompleteDirEdit);
|
2022-02-14 04:07:12 +00:00
|
|
|
ui_.doneDownloadingScriptStack->setCurrentWidget(
|
|
|
|
is_local_ ? static_cast<QWidget*>(ui_.doneDownloadingScriptButton) : ui_.doneDownloadingScriptEdit);
|
2016-10-03 18:26:28 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.watchDirStack->setFixedHeight(ui_.watchDirStack->currentWidget()->sizeHint().height());
|
|
|
|
ui_.downloadDirStack->setFixedHeight(ui_.downloadDirStack->currentWidget()->sizeHint().height());
|
|
|
|
ui_.incompleteDirStack->setFixedHeight(ui_.incompleteDirStack->currentWidget()->sizeHint().height());
|
2022-02-14 04:07:12 +00:00
|
|
|
ui_.doneDownloadingScriptStack->setFixedHeight(ui_.doneDownloadingScriptStack->currentWidget()->sizeHint().height());
|
2016-10-03 18:26:28 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.downloadDirLabel->setBuddy(ui_.downloadDirStack->currentWidget());
|
2016-10-03 18:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 04:07:12 +00:00
|
|
|
void PrefsDialog::updateSeedingWidgetsLocality()
|
|
|
|
{
|
|
|
|
ui_.doneSeedingScriptStack->setCurrentWidget(
|
|
|
|
is_local_ ? static_cast<QWidget*>(ui_.doneSeedingScriptButton) : ui_.doneSeedingScriptEdit);
|
|
|
|
ui_.doneSeedingScriptStack->setFixedHeight(ui_.doneSeedingScriptStack->currentWidget()->sizeHint().height());
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
PrefsDialog::PrefsDialog(Session& session, Prefs& prefs, QWidget* parent)
|
|
|
|
: BaseDialog(parent)
|
|
|
|
, session_(session)
|
|
|
|
, prefs_(prefs)
|
|
|
|
, is_server_(session.isServer())
|
|
|
|
, is_local_(session_.isLocal())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
initSpeedTab();
|
|
|
|
initDownloadingTab();
|
|
|
|
initSeedingTab();
|
|
|
|
initPrivacyTab();
|
|
|
|
initNetworkTab();
|
|
|
|
initDesktopTab();
|
|
|
|
initRemoteTab();
|
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&session_, &Session::sessionUpdated, this, &PrefsDialog::sessionUpdated);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static std::array<int, 10> constexpr InitKeys = {
|
2020-06-05 19:02:11 +00:00
|
|
|
Prefs::ALT_SPEED_LIMIT_ENABLED,
|
|
|
|
Prefs::ALT_SPEED_LIMIT_TIME_ENABLED,
|
|
|
|
Prefs::BLOCKLIST_ENABLED,
|
|
|
|
Prefs::DIR_WATCH,
|
|
|
|
Prefs::DOWNLOAD_DIR,
|
|
|
|
Prefs::ENCRYPTION,
|
|
|
|
Prefs::INCOMPLETE_DIR,
|
|
|
|
Prefs::INCOMPLETE_DIR_ENABLED,
|
|
|
|
Prefs::RPC_ENABLED,
|
2021-08-15 09:41:48 +00:00
|
|
|
Prefs::SCRIPT_TORRENT_DONE_FILENAME,
|
2020-06-05 19:02:11 +00:00
|
|
|
};
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
for (auto const key : InitKeys)
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshPref(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it's a remote session, disable the preferences
|
|
|
|
// that don't work in remote sessions
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!is_server_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QWidget* const w : unsupported_when_remote_)
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
w->setToolTip(tr("Not supported by remote sessions"));
|
|
|
|
w->setEnabled(false);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-25 15:47:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
adjustSize();
|
2022-02-21 03:25:49 +00:00
|
|
|
|
|
|
|
connect(qApp, &QApplication::focusChanged, this, &PrefsDialog::focusChanged);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void PrefsDialog::setPref(int key, QVariant const& v)
|
2010-08-02 16:30:24 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(key, v);
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshPref(key);
|
2010-08-02 16:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::sessionUpdated()
|
2009-04-09 22:42:55 +00:00
|
|
|
{
|
2022-02-03 13:02:11 +00:00
|
|
|
if (bool const is_local = session_.isLocal(); is_local_ != is_local)
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
is_local_ = is_local;
|
2017-04-19 12:04:45 +00:00
|
|
|
updateDownloadingWidgetsLocality();
|
2022-02-14 04:07:12 +00:00
|
|
|
updateSeedingWidgetsLocality();
|
2016-10-03 18:26:28 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
updateBlocklistLabel();
|
2009-04-09 22:42:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::updateBlocklistLabel()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
int const n = session_.blocklistSize();
|
|
|
|
ui_.blocklistStatusLabel->setText(tr("<i>Blocklist contains %Ln rule(s)</i>", nullptr, n));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void PrefsDialog::refreshPref(int key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (key)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RPC_ENABLED:
|
|
|
|
case Prefs::RPC_WHITELIST_ENABLED:
|
|
|
|
case Prefs::RPC_AUTH_REQUIRED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const enabled(prefs_.getBool(Prefs::RPC_ENABLED));
|
|
|
|
bool const whitelist(prefs_.getBool(Prefs::RPC_WHITELIST_ENABLED));
|
|
|
|
bool const auth(prefs_.getBool(Prefs::RPC_AUTH_REQUIRED));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QWidget* const w : web_whitelist_widgets_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
w->setEnabled(enabled && whitelist);
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QWidget* const w : web_auth_widgets_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
w->setEnabled(enabled && auth);
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QWidget* const w : web_widgets_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
w->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const enabled = prefs_.getBool(key);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QWidget* const w : sched_widgets_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
w->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::BLOCKLIST_ENABLED:
|
2013-09-14 22:45:04 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const enabled = prefs_.getBool(key);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
for (QWidget* const w : block_widgets_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
w->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::PEER_PORT:
|
2020-05-27 21:53:12 +00:00
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2013-09-14 22:45:04 +00:00
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2023-06-19 21:51:34 +00:00
|
|
|
if (auto iter = widgets_.find(key); iter != std::end(widgets_))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2023-06-19 21:51:34 +00:00
|
|
|
QWidget* const w = iter->second;
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2022-02-20 17:54:20 +00:00
|
|
|
w->blockSignals(true);
|
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
if (!updateWidgetValue(w, key) && (key == Prefs::ENCRYPTION))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-11-01 21:47:57 +00:00
|
|
|
auto* combo_box = qobject_cast<QComboBox*>(w);
|
|
|
|
int const index = combo_box->findData(prefs_.getInt(key));
|
|
|
|
combo_box->setCurrentIndex(index);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2022-02-20 17:54:20 +00:00
|
|
|
|
|
|
|
w->blockSignals(false);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|