Skip to content

Initial support and wiring for currently implemented connection settings #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/qml/components/ConnectionSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,34 @@ ColumnLayout {
Layout.fillWidth: true
header: qsTr("Enable listening")
description: qsTr("Allows incoming connections")
actionItem: OptionSwitch {}
actionItem: OptionSwitch {
checked: optionsModel.listen
onToggled: optionsModel.listen = checked
}
}
Setting {
Layout.fillWidth: true
header: qsTr("Map port using UPnP")
actionItem: OptionSwitch {}
actionItem: OptionSwitch {
checked: optionsModel.upnp
onToggled: optionsModel.upnp = checked
}
}
Setting {
Layout.fillWidth: true
header: qsTr("Map port using NAT-PMP")
actionItem: OptionSwitch {}
actionItem: OptionSwitch {
checked: optionsModel.natpmp
onToggled: optionsModel.natpmp = checked
}
}
Setting {
Layout.fillWidth: true
header: qsTr("Enable RPC server")
actionItem: OptionSwitch {}
actionItem: OptionSwitch {
checked: optionsModel.server
onToggled: optionsModel.server = checked
}
}
Setting {
last: true
Expand Down
36 changes: 36 additions & 0 deletions src/qml/options_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
m_prune_size_gb = m_prune ? PruneMiBtoGB(prune_value) : DEFAULT_PRUNE_TARGET_GB;
}

void OptionsQmlModel::setListen(bool new_listen)
{
if (new_listen != m_listen) {
m_listen = new_listen;
m_node.updateRwSetting("listen", new_listen);
Q_EMIT listenChanged(new_listen);
}
}

void OptionsQmlModel::setNatpmp(bool new_natpmp)
{
if (new_natpmp != m_natpmp) {
m_natpmp = new_natpmp;
m_node.updateRwSetting("natpmp", new_natpmp);
Q_EMIT natpmpChanged(new_natpmp);
}
}

void OptionsQmlModel::setPrune(bool new_prune)
{
if (new_prune != m_prune) {
Expand All @@ -39,6 +57,24 @@ void OptionsQmlModel::setPruneSizeGB(int new_prune_size_gb)
}
}

void OptionsQmlModel::setServer(bool new_server)
{
if (new_server != m_server) {
m_server = new_server;
m_node.updateRwSetting("server", new_server);
Q_EMIT serverChanged(new_server);
}
}

void OptionsQmlModel::setUpnp(bool new_upnp)
{
if (new_upnp != m_upnp) {
m_upnp = new_upnp;
m_node.updateRwSetting("upnp", new_upnp);
Q_EMIT upnpChanged(new_upnp);
}
}

util::SettingsValue OptionsQmlModel::pruneSetting() const
{
assert(!m_prune || m_prune_size_gb >= 1);
Expand Down
20 changes: 20 additions & 0 deletions src/qml/options_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,47 @@ class Node;
class OptionsQmlModel : public QObject
{
Q_OBJECT
Q_PROPERTY(bool listen READ listen WRITE setListen NOTIFY listenChanged)
Q_PROPERTY(bool natpmp READ natpmp WRITE setNatpmp NOTIFY natpmpChanged)
Q_PROPERTY(bool prune READ prune WRITE setPrune NOTIFY pruneChanged)
Q_PROPERTY(int pruneSizeGB READ pruneSizeGB WRITE setPruneSizeGB NOTIFY pruneSizeGBChanged)
Q_PROPERTY(bool server READ server WRITE setServer NOTIFY serverChanged)
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)

public:
explicit OptionsQmlModel(interfaces::Node& node);

bool listen() const { return m_listen; }
void setListen(bool new_listen);
bool natpmp() const { return m_natpmp; }
void setNatpmp(bool new_natpmp);
bool prune() const { return m_prune; }
void setPrune(bool new_prune);
int pruneSizeGB() const { return m_prune_size_gb; }
void setPruneSizeGB(int new_prune_size);
bool server() const { return m_server; }
void setServer(bool new_server);
bool upnp() const { return m_upnp; }
void setUpnp(bool new_upnp);

Q_SIGNALS:
void listenChanged(bool new_listen);
void natpmpChanged(bool new_natpmp);
void pruneChanged(bool new_prune);
void pruneSizeGBChanged(int new_prune_size_gb);
void serverChanged(bool new_server);
void upnpChanged(bool new_upnp);

private:
interfaces::Node& m_node;

// Properties that are exposed to QML.
bool m_listen;
bool m_natpmp;
bool m_prune;
int m_prune_size_gb;
bool m_server;
bool m_upnp;

util::SettingsValue pruneSetting() const;
};
Expand Down