Changeset View
Changeset View
Standalone View
Standalone View
libs/editor/settings/wiredconnectionwidget.cpp
Show All 26 Lines | |||||
27 | 27 | | |||
28 | WiredConnectionWidget::WiredConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): | 28 | WiredConnectionWidget::WiredConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): | ||
29 | SettingWidget(setting, parent, f), | 29 | SettingWidget(setting, parent, f), | ||
30 | m_widget(new Ui::WiredConnectionWidget) | 30 | m_widget(new Ui::WiredConnectionWidget) | ||
31 | { | 31 | { | ||
32 | qsrand(QTime::currentTime().msec()); | 32 | qsrand(QTime::currentTime().msec()); | ||
33 | 33 | | |||
34 | m_widget->setupUi(this); | 34 | m_widget->setupUi(this); | ||
35 | m_widget->speedLabel->setHidden(true); | | |||
36 | m_widget->speed->setHidden(true); | | |||
37 | m_widget->duplexLabel->setHidden(true); | | |||
38 | m_widget->duplex->setHidden(true); | | |||
39 | 35 | | |||
40 | connect(m_widget->btnRandomMacAddr, &QPushButton::clicked, this, &WiredConnectionWidget::generateRandomClonedMac); | 36 | connect(m_widget->btnRandomMacAddr, &QPushButton::clicked, this, &WiredConnectionWidget::generateRandomClonedMac); | ||
41 | 37 | | |||
42 | // Connect for setting check | 38 | // Connect for setting check | ||
43 | watchChangedSetting(); | 39 | watchChangedSetting(); | ||
44 | 40 | | |||
45 | // Connect for validity check | 41 | // Connect for validity check | ||
46 | connect(m_widget->autonegotiate, &QCheckBox::stateChanged, this, &WiredConnectionWidget::slotWidgetChanged); | | |||
47 | connect(m_widget->clonedMacAddress, &KLineEdit::textChanged, this, &WiredConnectionWidget::slotWidgetChanged); | 42 | connect(m_widget->clonedMacAddress, &KLineEdit::textChanged, this, &WiredConnectionWidget::slotWidgetChanged); | ||
48 | connect(m_widget->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WiredConnectionWidget::slotWidgetChanged); | 43 | connect(m_widget->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WiredConnectionWidget::slotWidgetChanged); | ||
49 | connect(m_widget->speed, QOverload<int>::of(&QSpinBox::valueChanged), this, &WiredConnectionWidget::slotWidgetChanged); | 44 | connect(m_widget->linkNegotiation, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this] (int index) { | ||
45 | m_widget->duplex->setEnabled(index == LinkNegotiation::Manual); | ||||
46 | m_widget->speed->setEnabled(index == LinkNegotiation::Manual); | ||||
47 | }); | ||||
50 | 48 | | |||
51 | KAcceleratorManager::manage(this); | 49 | KAcceleratorManager::manage(this); | ||
52 | 50 | | |||
53 | if (setting) { | 51 | if (setting) { | ||
54 | loadConfig(setting); | 52 | loadConfig(setting); | ||
55 | } | 53 | } | ||
56 | } | 54 | } | ||
57 | 55 | | |||
Show All 11 Lines | 62 | { | |||
69 | if (!wiredSetting->clonedMacAddress().isEmpty()) { | 67 | if (!wiredSetting->clonedMacAddress().isEmpty()) { | ||
70 | m_widget->clonedMacAddress->setText(NetworkManager::macAddressAsString(wiredSetting->clonedMacAddress())); | 68 | m_widget->clonedMacAddress->setText(NetworkManager::macAddressAsString(wiredSetting->clonedMacAddress())); | ||
71 | } | 69 | } | ||
72 | 70 | | |||
73 | if (wiredSetting->mtu()) { | 71 | if (wiredSetting->mtu()) { | ||
74 | m_widget->mtu->setValue(wiredSetting->mtu()); | 72 | m_widget->mtu->setValue(wiredSetting->mtu()); | ||
75 | } | 73 | } | ||
76 | 74 | | |||
77 | if (!wiredSetting->autoNegotiate()) { | 75 | if (wiredSetting->autoNegotiate()) { | ||
78 | m_widget->autonegotiate->setChecked(false); | 76 | m_widget->linkNegotiation->setCurrentIndex(LinkNegotiation::Automatic); | ||
77 | } else if (wiredSetting->speed() && wiredSetting->duplexType() != NetworkManager::WiredSetting::UnknownDuplexType) { | ||||
78 | m_widget->linkNegotiation->setCurrentIndex(LinkNegotiation::Manual); | ||||
79 | } | ||||
davidedmundson: can loadConfig can be called multiple times?
If so we need an explicit
```
else {… | |||||
jgrulich: No, it cannot be called multiple times. | |||||
79 | 80 | | |||
80 | if (wiredSetting->speed()) { | 81 | if (wiredSetting->speed()) { | ||
81 | m_widget->speed->setValue(wiredSetting->speed()); | 82 | switch(wiredSetting->speed()) { | ||
83 | case 10: | ||||
84 | m_widget->speed->setCurrentIndex(0); | ||||
85 | break; | ||||
86 | case 100: | ||||
87 | m_widget->speed->setCurrentIndex(1); | ||||
88 | break; | ||||
89 | case 1000: | ||||
90 | m_widget->speed->setCurrentIndex(2); | ||||
91 | break; | ||||
92 | case 10000: | ||||
93 | m_widget->speed->setCurrentIndex(3); | ||||
94 | break; | ||||
95 | } | ||||
82 | } | 96 | } | ||
83 | 97 | | |||
84 | // Default to "Full" duplex when duplex type is not set | 98 | if (wiredSetting->duplexType() != NetworkManager::WiredSetting::Half) { | ||
85 | if (wiredSetting->duplexType() == NetworkManager::WiredSetting::Full || wiredSetting->duplexType() == NetworkManager::WiredSetting::UnknownDuplexType) { | 99 | m_widget->duplex->setCurrentIndex(Duplex::Full); | ||
86 | m_widget->duplex->setCurrentIndex(0); | | |||
87 | } else { | 100 | } else { | ||
88 | m_widget->duplex->setCurrentIndex(1); | 101 | m_widget->duplex->setCurrentIndex(Duplex::Half); | ||
89 | } | | |||
90 | } | 102 | } | ||
91 | } | 103 | } | ||
92 | 104 | | |||
93 | QVariantMap WiredConnectionWidget::setting() const | 105 | QVariantMap WiredConnectionWidget::setting() const | ||
94 | { | 106 | { | ||
95 | NetworkManager::WiredSetting wiredSetting; | 107 | NetworkManager::WiredSetting wiredSetting; | ||
96 | 108 | | |||
97 | wiredSetting.setMacAddress(NetworkManager::macAddressFromString(m_widget->macAddress->hwAddress())); | 109 | wiredSetting.setMacAddress(NetworkManager::macAddressFromString(m_widget->macAddress->hwAddress())); | ||
98 | 110 | | |||
99 | if (!m_widget->clonedMacAddress->text().isEmpty() && m_widget->clonedMacAddress->text() != ":::::") { | 111 | if (!m_widget->clonedMacAddress->text().isEmpty() && m_widget->clonedMacAddress->text() != ":::::") { | ||
100 | wiredSetting.setClonedMacAddress(NetworkManager::macAddressFromString(m_widget->clonedMacAddress->text())); | 112 | wiredSetting.setClonedMacAddress(NetworkManager::macAddressFromString(m_widget->clonedMacAddress->text())); | ||
101 | } | 113 | } | ||
102 | 114 | | |||
103 | if (m_widget->mtu->value()) { | 115 | if (m_widget->mtu->value()) { | ||
104 | wiredSetting.setMtu(m_widget->mtu->value()); | 116 | wiredSetting.setMtu(m_widget->mtu->value()); | ||
105 | } | 117 | } | ||
106 | 118 | | |||
107 | if (m_widget->autonegotiate->isChecked()) { | 119 | if (m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Automatic || m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Ignore) { | ||
108 | wiredSetting.setAutoNegotiate(true); | | |||
109 | wiredSetting.setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType); | 120 | wiredSetting.setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType); | ||
110 | wiredSetting.setSpeed(0); | 121 | wiredSetting.setSpeed(0); | ||
111 | } else { | 122 | } else { | ||
112 | wiredSetting.setAutoNegotiate(false); | 123 | switch (m_widget->speed->currentIndex()) { | ||
113 | wiredSetting.setSpeed(m_widget->speed->value()); | 124 | case 0: | ||
125 | wiredSetting.setSpeed(10); | ||||
126 | break; | ||||
127 | case 1: | ||||
128 | wiredSetting.setSpeed(100); | ||||
129 | break; | ||||
130 | case 2: | ||||
131 | wiredSetting.setSpeed(1000); | ||||
132 | break; | ||||
133 | case 3: | ||||
134 | wiredSetting.setSpeed(10000); | ||||
135 | break; | ||||
136 | } | ||||
114 | 137 | | |||
115 | if (m_widget->duplex->currentIndex() == 0) { | 138 | if (m_widget->duplex->currentIndex() == Duplex::Full) { | ||
116 | wiredSetting.setDuplexType(NetworkManager::WiredSetting::Full); | 139 | wiredSetting.setDuplexType(NetworkManager::WiredSetting::Full); | ||
117 | } else { | 140 | } else { | ||
118 | wiredSetting.setDuplexType(NetworkManager::WiredSetting::Half); | 141 | wiredSetting.setDuplexType(NetworkManager::WiredSetting::Half); | ||
119 | } | 142 | } | ||
120 | } | 143 | } | ||
121 | 144 | | |||
145 | wiredSetting.setAutoNegotiate(m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Automatic); | ||||
146 | | ||||
147 | | ||||
122 | return wiredSetting.toMap(); | 148 | return wiredSetting.toMap(); | ||
123 | } | 149 | } | ||
124 | 150 | | |||
125 | void WiredConnectionWidget::generateRandomClonedMac() | 151 | void WiredConnectionWidget::generateRandomClonedMac() | ||
126 | { | 152 | { | ||
127 | QByteArray mac; | 153 | QByteArray mac; | ||
128 | mac.resize(6); | 154 | mac.resize(6); | ||
129 | for (int i = 0; i < 6; i++) { | 155 | for (int i = 0; i < 6; i++) { | ||
Show All 15 Lines | 168 | { | |||
145 | } | 171 | } | ||
146 | 172 | | |||
147 | if (m_widget->clonedMacAddress->text() != ":::::") { | 173 | if (m_widget->clonedMacAddress->text() != ":::::") { | ||
148 | if (!NetworkManager::macAddressIsValid(m_widget->clonedMacAddress->text())) { | 174 | if (!NetworkManager::macAddressIsValid(m_widget->clonedMacAddress->text())) { | ||
149 | return false; | 175 | return false; | ||
150 | } | 176 | } | ||
151 | } | 177 | } | ||
152 | 178 | | |||
153 | if (!m_widget->autonegotiate->isChecked()) { | | |||
154 | if (!m_widget->speed->value()) { | | |||
155 | return false; | | |||
156 | } | | |||
157 | } | | |||
158 | | ||||
159 | return true; | 179 | return true; | ||
160 | } | 180 | } |
can loadConfig can be called multiple times?
If so we need an explicit