Changeset View
Changeset View
Standalone View
Standalone View
libs/editor/settings/wificonnectionwidget.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "debug.h" | 21 | #include "debug.h" | ||
22 | #include "wificonnectionwidget.h" | 22 | #include "wificonnectionwidget.h" | ||
23 | #include "ui_wificonnectionwidget.h" | 23 | #include "ui_wificonnectionwidget.h" | ||
24 | 24 | | |||
25 | #include <NetworkManagerQt/Utils> | 25 | #include <NetworkManagerQt/Utils> | ||
26 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
27 | #include <QRandomGenerator> | ||||
27 | 28 | | |||
28 | #include "uiutils.h" | 29 | #include "uiutils.h" | ||
29 | 30 | | |||
30 | WifiConnectionWidget::WifiConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): | 31 | WifiConnectionWidget::WifiConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): | ||
31 | SettingWidget(setting, parent, f), | 32 | SettingWidget(setting, parent, f), | ||
32 | m_ui(new Ui::WifiConnectionWidget) | 33 | m_ui(new Ui::WifiConnectionWidget) | ||
33 | { | 34 | { | ||
34 | qsrand(QTime::currentTime().msec()); | | |||
35 | | ||||
36 | m_ui->setupUi(this); | 35 | m_ui->setupUi(this); | ||
37 | 36 | | |||
38 | connect(m_ui->btnRandomMacAddr, &QPushButton::clicked, this, &WifiConnectionWidget::generateRandomClonedMac); | 37 | connect(m_ui->btnRandomMacAddr, &QPushButton::clicked, this, &WifiConnectionWidget::generateRandomClonedMac); | ||
39 | connect(m_ui->SSIDCombo, &SsidComboBox::ssidChanged, this, QOverload<>::of(&WifiConnectionWidget::ssidChanged)); | 38 | connect(m_ui->SSIDCombo, &SsidComboBox::ssidChanged, this, QOverload<>::of(&WifiConnectionWidget::ssidChanged)); | ||
39 | #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) | ||||
40 | connect(m_ui->modeComboBox, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::modeChanged); | 40 | connect(m_ui->modeComboBox, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::modeChanged); | ||
41 | #else | ||||
42 | connect(m_ui->modeComboBox, QOverload<int, const QString &>::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::modeChanged); | ||||
43 | #endif | ||||
44 | #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) | ||||
41 | connect(m_ui->band, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::bandChanged); | 45 | connect(m_ui->band, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::bandChanged); | ||
46 | #else | ||||
47 | connect(m_ui->band, QOverload<int, const QString &>::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::bandChanged); | ||||
48 | #endif | ||||
42 | 49 | | |||
43 | // Connect for setting check | 50 | // Connect for setting check | ||
44 | watchChangedSetting(); | 51 | watchChangedSetting(); | ||
45 | 52 | | |||
46 | // Connect for validity check | 53 | // Connect for validity check | ||
47 | connect(m_ui->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WifiConnectionWidget::slotWidgetChanged); | 54 | connect(m_ui->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WifiConnectionWidget::slotWidgetChanged); | ||
48 | connect(m_ui->BSSIDCombo, &BssidComboBox::bssidChanged, this, &WifiConnectionWidget::slotWidgetChanged); | 55 | connect(m_ui->BSSIDCombo, &BssidComboBox::bssidChanged, this, &WifiConnectionWidget::slotWidgetChanged); | ||
49 | 56 | | |||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 103 | { | |||
120 | wifiSetting.setHidden(m_ui->hiddenNetwork->isChecked()); | 127 | wifiSetting.setHidden(m_ui->hiddenNetwork->isChecked()); | ||
121 | 128 | | |||
122 | return wifiSetting.toMap(); | 129 | return wifiSetting.toMap(); | ||
123 | } | 130 | } | ||
124 | 131 | | |||
125 | void WifiConnectionWidget::generateRandomClonedMac() | 132 | void WifiConnectionWidget::generateRandomClonedMac() | ||
126 | { | 133 | { | ||
127 | QByteArray mac; | 134 | QByteArray mac; | ||
135 | auto *generator = QRandomGenerator::global(); | ||||
128 | mac.resize(6); | 136 | mac.resize(6); | ||
129 | for (int i = 0; i < 6; i++) { | 137 | for (int i = 0; i < 6; i++) { | ||
130 | int random = qrand() % 255; | 138 | const int random = generator->bounded(255); | ||
131 | mac[i] = random; | 139 | mac[i] = random; | ||
132 | } | 140 | } | ||
133 | 141 | | |||
134 | // Disable the multicast bit and enable the locally administered bit. | 142 | // Disable the multicast bit and enable the locally administered bit. | ||
135 | mac[0] = mac[0] & ~0x1; | 143 | mac[0] = mac[0] & ~0x1; | ||
136 | mac[0] = mac[0] | 0x2; | 144 | mac[0] = mac[0] | 0x2; | ||
137 | 145 | | |||
138 | m_ui->clonedMacAddress->setText(NetworkManager::macAddressAsString(mac)); | 146 | m_ui->clonedMacAddress->setText(NetworkManager::macAddressAsString(mac)); | ||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |