Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 3e66c004 authored by Jan Grulich's avatar Jan Grulich

Minor coding style improvements

parent 389a5e19
......@@ -39,9 +39,7 @@
#include "nm-wireguard-service.h"
K_PLUGIN_FACTORY_WITH_JSON(WireGuardUiPluginFactory,
"plasmanetworkmanagement_wireguardui.json",
registerPlugin<WireGuardUiPlugin>();)
K_PLUGIN_FACTORY_WITH_JSON(WireGuardUiPluginFactory, "plasmanetworkmanagement_wireguardui.json", registerPlugin<WireGuardUiPlugin>(); )
#define NMV_WG_TAG_INTERFACE "Interface"
#define NMV_WG_TAG_PRIVATE_KEY "PrivateKey"
......@@ -64,7 +62,8 @@ K_PLUGIN_FACTORY_WITH_JSON(WireGuardUiPluginFactory,
#define NMV_WG_TAG_PERSISTENT_KEEPALIVE "PersistentKeepalive"
WireGuardUiPlugin::WireGuardUiPlugin(QObject *parent, const QVariantList &) : VpnUiPlugin(parent)
WireGuardUiPlugin::WireGuardUiPlugin(QObject *parent, const QVariantList &)
: VpnUiPlugin(parent)
{
}
......@@ -72,14 +71,12 @@ WireGuardUiPlugin::~WireGuardUiPlugin()
{
}
SettingWidget *WireGuardUiPlugin::widget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent)
SettingWidget *WireGuardUiPlugin::widget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent)
{
return new WireGuardSettingWidget(setting, parent);
}
SettingWidget *WireGuardUiPlugin::askUser(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent)
SettingWidget *WireGuardUiPlugin::askUser(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent)
{
return new WireGuardAuthWidget(setting, parent);
}
......@@ -103,8 +100,7 @@ NMVariantMapMap WireGuardUiPlugin::importConnectionSettings(const QString &fileN
const KConfigGroup peerGroup = importFile.group(NMV_WG_TAG_PEER);
// The config file must have both [Interface] and [Peer] sections
if (!interfaceGroup.exists()
|| !peerGroup.exists()) {
if (!interfaceGroup.exists() || !peerGroup.exists()) {
mError = VpnUiPlugin::Error;
mErrorMessage = i18n("Config file needs both [Peer] and [Interface]");
return result;
......@@ -179,9 +175,7 @@ NMVariantMapMap WireGuardUiPlugin::importConnectionSettings(const QString &fileN
// Allowed IPs
value = peerGroup.readEntry(NMV_WG_TAG_ALLOWED_IPS);
if (!value.isEmpty()) {
SimpleIpListValidator validator(this,
SimpleIpListValidator::WithCidr,
SimpleIpListValidator::Both);
SimpleIpListValidator validator(this, SimpleIpListValidator::WithCidr, SimpleIpListValidator::Both);
if (validator.validate(value, pos) != QValidator::State::Invalid) {
dataMap.insert(QLatin1String(NM_WG_KEY_ALLOWED_IPS), value);
......
......@@ -29,16 +29,13 @@ Q_OBJECT
public:
explicit WireGuardUiPlugin(QObject *parent = nullptr, const QVariantList& = QVariantList());
~WireGuardUiPlugin() override;
SettingWidget *widget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent = nullptr) override;
SettingWidget *askUser(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent = nullptr) override;
SettingWidget *widget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent = nullptr) override;
SettingWidget *askUser(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent = nullptr) override;
QString suggestedFileName(const NetworkManager::ConnectionSettings::Ptr &connection) const override;
QString supportedFileExtensions() const override;
NMVariantMapMap importConnectionSettings(const QString &fileName) override;
bool exportConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &connection,
const QString &fileName) override;
bool exportConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &connection, const QString &fileName) override;
};
#endif // PLASMANM_WIREGUARD_H
......@@ -29,6 +29,9 @@
class WireGuardAdvancedWidget::Private
{
public:
~Private();
Private();
NetworkManager::VpnSetting::Ptr setting;
Ui::WireGuardAdvancedWidget ui;
QPalette warningPalette;
......@@ -39,16 +42,15 @@ public:
QRegularExpressionValidator *fwMarkValidator;
QIntValidator *persistentKeepaliveValidator;
QRegularExpressionValidator *tableValidator;
~Private();
Private();
bool fwMarkValid;
bool presharedKeyValid;
bool tableValid;
};
WireGuardAdvancedWidget::Private::Private() : fwMarkValid(true),
presharedKeyValid(true),
tableValid(true)
WireGuardAdvancedWidget::Private::Private()
: fwMarkValid(true)
, presharedKeyValid(true)
, tableValid(true)
{
}
......@@ -62,9 +64,9 @@ WireGuardAdvancedWidget::Private::~Private()
delete tableValidator;
}
WireGuardAdvancedWidget::WireGuardAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent)
: QDialog(parent), d(new Private)
WireGuardAdvancedWidget::WireGuardAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent)
: QDialog(parent)
, d(new Private)
{
KSharedConfigPtr config = KSharedConfig::openConfig();
d->warningPalette = KColorScheme::createApplicationPalette(config);
......@@ -91,12 +93,9 @@ WireGuardAdvancedWidget::WireGuardAdvancedWidget(const NetworkManager::VpnSettin
connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &WireGuardAdvancedWidget::accept);
connect(d->ui.buttonBox, &QDialogButtonBox::rejected, this, &WireGuardAdvancedWidget::reject);
connect(d->ui.presharedKeyLineEdit, &PasswordField::textChanged,
this, &WireGuardAdvancedWidget::checkPresharedKey);
connect(d->ui.tableLineEdit, &QLineEdit::textChanged,
this, &WireGuardAdvancedWidget::checkTable);
connect(d->ui.fwMarkLineEdit, &QLineEdit::textChanged,
this, &WireGuardAdvancedWidget::checkFwMark);
connect(d->ui.presharedKeyLineEdit, &PasswordField::textChanged, this, &WireGuardAdvancedWidget::checkPresharedKey);
connect(d->ui.tableLineEdit, &QLineEdit::textChanged, this, &WireGuardAdvancedWidget::checkTable);
connect(d->ui.fwMarkLineEdit, &QLineEdit::textChanged, this, &WireGuardAdvancedWidget::checkFwMark);
d->ui.presharedKeyLineEdit->setPasswordModeEnabled(true);
d->listenPortValidator = new QIntValidator(0, 65535, nullptr);
......@@ -198,8 +197,7 @@ NetworkManager::VpnSetting::Ptr WireGuardAdvancedWidget::setting() const
QString stringVal;
setProperty(data, QLatin1String(NM_WG_KEY_LISTEN_PORT), d->ui.listenPortLineEdit->displayText());
setProperty(data, QLatin1String(NM_WG_KEY_PERSISTENT_KEEPALIVE),
d->ui.persistentKeepaliveLineEdit->displayText());
setProperty(data, QLatin1String(NM_WG_KEY_PERSISTENT_KEEPALIVE), d->ui.persistentKeepaliveLineEdit->displayText());
setProperty(data, QLatin1String(NM_WG_KEY_MTU), d->ui.mtuLineEdit->displayText());
setProperty(data, QLatin1String(NM_WG_KEY_TABLE), d->ui.tableLineEdit->displayText());
setProperty(data, QLatin1String(NM_WG_KEY_FWMARK), d->ui.fwMarkLineEdit->displayText());
......
......@@ -38,8 +38,7 @@ class WireGuardAdvancedWidget : public QDialog
Q_OBJECT
public:
explicit WireGuardAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent = 0);
explicit WireGuardAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent = nullptr);
~WireGuardAdvancedWidget() override;
NetworkManager::VpnSetting::Ptr setting() const;
......
......@@ -30,8 +30,7 @@ public:
NetworkManager::VpnSetting::Ptr setting;
};
WireGuardAuthWidget::WireGuardAuthWidget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent)
WireGuardAuthWidget::WireGuardAuthWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent)
: SettingWidget(setting, parent)
, d_ptr(new WireGuardAuthWidgetPrivate)
{
......
......@@ -32,7 +32,7 @@ class WireGuardAuthWidget : public SettingWidget
Q_OBJECT
Q_DECLARE_PRIVATE(WireGuardAuthWidget)
public:
explicit WireGuardAuthWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent = 0);
explicit WireGuardAuthWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent = nullptr);
~WireGuardAuthWidget() override;
virtual QVariantMap setting() const override;
......
......@@ -35,6 +35,7 @@ class WireGuardSettingWidget::Private
{
public:
Private();
Ui_WireGuardProp ui;
NetworkManager::VpnSetting::Ptr setting;
KSharedConfigPtr config;
......@@ -49,19 +50,19 @@ public:
bool endpointValid;
};
WireGuardSettingWidget::Private::Private(void) : addressValid(false),
privateKeyValid(false),
publicKeyValid(false),
dnsValid(true), // optional so blank is valid
allowedIpsValid(false),
endpointValid(true) // optional so blank is valid
WireGuardSettingWidget::Private::Private(void)
: addressValid(false)
, privateKeyValid(false)
, publicKeyValid(false)
, dnsValid(true) // optional so blank is valid
, allowedIpsValid(false)
, endpointValid(true) // optional so blank is valid
{
}
WireGuardSettingWidget::WireGuardSettingWidget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent)
: SettingWidget(setting, parent),
d(new Private)
WireGuardSettingWidget::WireGuardSettingWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent)
: SettingWidget(setting, parent)
, d(new Private)
{
qDBusRegisterMetaType<NMStringMap>();
......@@ -71,33 +72,20 @@ WireGuardSettingWidget::WireGuardSettingWidget(const NetworkManager::VpnSetting:
d->config = KSharedConfig::openConfig();
d->warningPalette = KColorScheme::createApplicationPalette(d->config);
d->normalPalette = KColorScheme::createApplicationPalette(d->config);
KColorScheme::adjustBackground(d->warningPalette,
KColorScheme::NegativeBackground,
QPalette::Base,
KColorScheme::ColorSet::View,
d->config);
KColorScheme::adjustBackground(d->normalPalette,
KColorScheme::NormalBackground,
QPalette::Base,
KColorScheme::ColorSet::View,
d->config);
connect(d->ui.addressIPv4LineEdit, &QLineEdit::textChanged, this,
&WireGuardSettingWidget::checkAddressValid);
connect(d->ui.addressIPv6LineEdit, &QLineEdit::textChanged, this,
&WireGuardSettingWidget::checkAddressValid);
connect(d->ui.privateKeyLineEdit, &PasswordField::textChanged, this,
&WireGuardSettingWidget::checkPrivateKeyValid);
connect(d->ui.publicKeyLineEdit, &QLineEdit::textChanged, this,
&WireGuardSettingWidget::checkPublicKeyValid);
connect(d->ui.allowedIPsLineEdit, &QLineEdit::textChanged, this,
&WireGuardSettingWidget::checkAllowedIpsValid);
connect(d->ui.endpointLineEdit, &QLineEdit::textChanged, this,
&WireGuardSettingWidget::checkEndpointValid);
connect(d->ui.dNSLineEdit, &QLineEdit::textChanged, this,
&WireGuardSettingWidget::checkDnsValid);
KColorScheme::adjustBackground(d->warningPalette, KColorScheme::NegativeBackground, QPalette::Base,
KColorScheme::ColorSet::View, d->config);
KColorScheme::adjustBackground(d->normalPalette, KColorScheme::NormalBackground, QPalette::Base,
KColorScheme::ColorSet::View, d->config);
connect(d->ui.addressIPv4LineEdit, &QLineEdit::textChanged, this, &WireGuardSettingWidget::checkAddressValid);
connect(d->ui.addressIPv6LineEdit, &QLineEdit::textChanged, this, &WireGuardSettingWidget::checkAddressValid);
connect(d->ui.privateKeyLineEdit, &PasswordField::textChanged, this, &WireGuardSettingWidget::checkPrivateKeyValid);
connect(d->ui.publicKeyLineEdit, &QLineEdit::textChanged, this, &WireGuardSettingWidget::checkPublicKeyValid);
connect(d->ui.allowedIPsLineEdit, &QLineEdit::textChanged, this, &WireGuardSettingWidget::checkAllowedIpsValid);
connect(d->ui.endpointLineEdit, &QLineEdit::textChanged, this, &WireGuardSettingWidget::checkEndpointValid);
connect(d->ui.dNSLineEdit, &QLineEdit::textChanged, this, &WireGuardSettingWidget::checkDnsValid);
d->ui.privateKeyLineEdit->setPasswordModeEnabled(true);
......@@ -129,8 +117,7 @@ WireGuardSettingWidget::WireGuardSettingWidget(const NetworkManager::VpnSetting:
d->ui.endpointLineEdit->setValidator(endpointValidator);
// Create validator for AllowedIPs
SimpleIpListValidator *allowedIPsValidator = new SimpleIpListValidator(this,
SimpleIpListValidator::WithCidr,
SimpleIpListValidator *allowedIPsValidator = new SimpleIpListValidator(this, SimpleIpListValidator::WithCidr,
SimpleIpListValidator::Both);
d->ui.allowedIPsLineEdit->setValidator(allowedIPsValidator);
......@@ -199,9 +186,7 @@ QVariantMap WireGuardSettingWidget::setting() const
return setting.toMap();
}
void WireGuardSettingWidget::setProperty(NMStringMap &data,
const QLatin1String &key,
const QString &value) const
void WireGuardSettingWidget::setProperty(NMStringMap &data, const QLatin1String &key, const QString &value) const
{
if (!value.isEmpty())
data.insert(key, value);
......@@ -253,9 +238,7 @@ void WireGuardSettingWidget::checkAddressValid()
bool ip6valid = QValidator::Acceptable == widget->validator()->validate(value, pos);
bool ip6present = !widget->displayText().isEmpty();
d->addressValid = (ip4valid && ip6valid)
|| (ip4valid && !ip6present)
|| (!ip4present && ip6valid);
d->addressValid = (ip4valid && ip6valid) || (ip4valid && !ip6present) || (!ip4present && ip6valid);
setBackground(d->ui.addressIPv4LineEdit, d->addressValid);
setBackground(d->ui.addressIPv6LineEdit, d->addressValid);
......
......@@ -30,8 +30,7 @@ class WireGuardSettingWidget : public SettingWidget
{
Q_OBJECT
public:
explicit WireGuardSettingWidget(const NetworkManager::VpnSetting::Ptr &setting,
QWidget *parent = 0);
explicit WireGuardSettingWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent = nullptr);
~WireGuardSettingWidget() override;
void loadConfig(const NetworkManager::Setting::Ptr &setting) override;
......@@ -45,8 +44,6 @@ private Q_SLOTS:
void showAdvanced();
private:
class Private;
Private *d;
void setProperty(NMStringMap &data, const QLatin1String &key, const QString &value) const;
void setBackground(QWidget *w, bool result) const;
void checkAddressValid();
......@@ -55,6 +52,9 @@ private:
void checkDnsValid();
void checkAllowedIpsValid();
void checkEndpointValid();
class Private;
Private *d;
};
#endif // WIREGUARDWIDGET_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment