mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-03-01 13:13:52 +08:00
Networking: populate tethering password (#21455)
* populate password from hotspot connection move to setup() populate tethering password fix password editing setup tethering when editing password or enabling fix * fixes * last fix, don't activate when adding * check before * if not
This commit is contained in:
@@ -125,8 +125,8 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
|
||||
// Change tethering password
|
||||
editPasswordButton = new ButtonControl("Tethering Password", "EDIT");
|
||||
connect(editPasswordButton, &ButtonControl::released, [=]() {
|
||||
QString pass = InputDialog::getText("Enter new tethering password", 8);
|
||||
if (pass.size()) {
|
||||
QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword());
|
||||
if (!pass.isEmpty()) {
|
||||
wifi->changeTetheringPassword(pass);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -277,7 +277,7 @@ bool WifiManager::isWirelessAdapter(const QDBusObjectPath &path) {
|
||||
void WifiManager::requestScan() {
|
||||
QDBusInterface nm(NM_DBUS_SERVICE, adapter, NM_DBUS_INTERFACE_DEVICE_WIRELESS, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
nm.call("RequestScan", QVariantMap());
|
||||
nm.call("RequestScan", QVariantMap());
|
||||
}
|
||||
|
||||
uint WifiManager::get_wifi_device_state() {
|
||||
@@ -365,7 +365,9 @@ void WifiManager::connectionRemoved(const QDBusObjectPath &path) {
|
||||
|
||||
void WifiManager::newConnection(const QDBusObjectPath &path) {
|
||||
knownConnections[path] = getConnectionSsid(path);
|
||||
activateWifiConnection(knownConnections[path]);
|
||||
if (knownConnections[path] != tethering_ssid) {
|
||||
activateWifiConnection(knownConnections[path]);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiManager::disconnect() {
|
||||
@@ -428,7 +430,7 @@ void WifiManager::addTetheringConnection() {
|
||||
connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk";
|
||||
connection["802-11-wireless-security"]["pairwise"] = QStringList("ccmp");
|
||||
connection["802-11-wireless-security"]["proto"] = QStringList("rsn");
|
||||
connection["802-11-wireless-security"]["psk"] = tetheringPassword;
|
||||
connection["802-11-wireless-security"]["psk"] = defaultTetheringPassword;
|
||||
|
||||
connection["ipv4"]["method"] = "shared";
|
||||
QMap<QString,QVariant> address;
|
||||
@@ -445,7 +447,7 @@ void WifiManager::addTetheringConnection() {
|
||||
}
|
||||
|
||||
void WifiManager::enableTethering() {
|
||||
if (!isKnownConnection(tethering_ssid.toUtf8())) {
|
||||
if (!isKnownConnection(tethering_ssid)) {
|
||||
addTetheringConnection();
|
||||
}
|
||||
activateWifiConnection(tethering_ssid.toUtf8());
|
||||
@@ -465,8 +467,29 @@ bool WifiManager::tetheringEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WifiManager::changeTetheringPassword(const QString &newPassword) {
|
||||
tetheringPassword = newPassword;
|
||||
forgetConnection(tethering_ssid.toUtf8());
|
||||
addTetheringConnection();
|
||||
QString WifiManager::getTetheringPassword() {
|
||||
if (!isKnownConnection(tethering_ssid)) {
|
||||
addTetheringConnection();
|
||||
}
|
||||
const QDBusObjectPath &path = getConnectionPath(tethering_ssid);
|
||||
if (!path.path().isEmpty()) {
|
||||
QDBusInterface nm(NM_DBUS_INTERFACE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
|
||||
const QDBusReply<QMap<QString, QMap<QString, QVariant>>> response = nm.call("GetSecrets", "802-11-wireless-security");
|
||||
return response.value().value("802-11-wireless-security").value("psk").toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void WifiManager::changeTetheringPassword(const QString &newPassword) {
|
||||
const QDBusObjectPath &path = getConnectionPath(tethering_ssid);
|
||||
if (!path.path().isEmpty()) {
|
||||
QDBusInterface nm(NM_DBUS_INTERFACE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
|
||||
Connection settings = QDBusReply<Connection>(nm.call("GetSettings")).value();
|
||||
settings["802-11-wireless-security"]["psk"] = newPassword;
|
||||
nm.call("Update", QVariant::fromValue(settings));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
void addTetheringConnection();
|
||||
void activateWifiConnection(const QString &ssid);
|
||||
void changeTetheringPassword(const QString &newPassword);
|
||||
QString getTetheringPassword();
|
||||
|
||||
private:
|
||||
QVector<QByteArray> seen_ssids;
|
||||
@@ -62,7 +63,7 @@ private:
|
||||
unsigned int raw_adapter_state; // Connection status https://developer.gnome.org/NetworkManager/1.26/nm-dbus-types.html#NMDeviceState
|
||||
QString connecting_to_network;
|
||||
QString tethering_ssid;
|
||||
QString tetheringPassword = "swagswagcommma";
|
||||
const QString defaultTetheringPassword = "swagswagcommma";
|
||||
|
||||
bool firstScan = true;
|
||||
QString getAdapter();
|
||||
|
||||
@@ -57,8 +57,9 @@ InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog(
|
||||
|
||||
}
|
||||
|
||||
QString InputDialog::getText(const QString &prompt, int minLength) {
|
||||
QString InputDialog::getText(const QString &prompt, int minLength, const QString &defaultText) {
|
||||
InputDialog d = InputDialog(prompt);
|
||||
d.line->setText(defaultText);
|
||||
d.setMinLength(minLength);
|
||||
const int ret = d.exec();
|
||||
return ret ? d.text() : QString();
|
||||
|
||||
@@ -14,7 +14,7 @@ class InputDialog : public QDialog {
|
||||
|
||||
public:
|
||||
explicit InputDialog(const QString &prompt_text, QWidget* parent = 0);
|
||||
static QString getText(const QString &prompt, int minLength = -1);
|
||||
static QString getText(const QString &prompt, int minLength = -1, const QString &defaultText = "");
|
||||
QString text();
|
||||
void setMessage(const QString &message, bool clearInputField = true);
|
||||
void setMinLength(int length);
|
||||
|
||||
Reference in New Issue
Block a user