Skip to content

Commit 27dcefa

Browse files
committed
util: fix wifi AP password entry not always presenting itself
1 parent 977e201 commit 27dcefa

4 files changed

Lines changed: 26 additions & 20 deletions

File tree

src/util/network/manager.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -566,27 +566,26 @@ void NetworkManager::activate_connection(std::string p1, std::string p2, std::st
566566
Glib::VariantStringBase::create_object_path(path2, p2);
567567
Glib::VariantStringBase::create_object_path(path3, p3);
568568
auto paths = Glib::VariantContainerBase::create_tuple({path1, path2, path3});
569-
// auto data = Glib::VariantContainerBase::create_tuple(paths);
570569

571570
try {
572571
nm_proxy->call("ActivateConnection", paths);
573572
} catch (...)
573+
{}
574+
}
575+
576+
void NetworkManager::request_password(std::string p2, std::string p3)
577+
{
578+
if (p2.find("/Devices/") != std::string::npos)
574579
{
575-
/* It's most likely a WIFI AP with no password set. Let's ask */
576-
std::cout << p2 << std::endl;
577-
/* No, it's not a regex */
578-
if (p2.find("/Devices/") != std::string::npos)
580+
auto device = std::dynamic_pointer_cast<WifiNetwork>(all_devices[p2]);
581+
if (device)
579582
{
580-
auto device = std::dynamic_pointer_cast<WifiNetwork>(all_devices[p2]);
581-
if (device)
582-
{
583-
popup_cache_p2 = p2;
584-
popup_cache_p3 = p3;
585-
auto ap = device->get_access_points()[p3];
586-
popup_label.set_label("Preshared Key required for Access Point '" + ap->get_ssid() + "'");
587-
popup_window.present();
588-
popup_window.get_focus();
589-
}
583+
popup_cache_p2 = p2;
584+
popup_cache_p3 = p3;
585+
auto ap = device->get_access_points()[p3];
586+
popup_label.set_label("Preshared Key required for Access Point '" + ap->get_ssid() + "'");
587+
popup_window.present();
588+
popup_window.get_focus();
590589
}
591590
}
592591
}

src/util/network/manager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class NetworkManager
178178
void mobile_global_set(bool value);
179179
void networking_global_set(bool value);
180180
void submit_password();
181+
void request_password(std::string p2, std::string p3);
181182

182183
std::shared_ptr<NetworkSettings> get_setting_for_ssid(std::string ssid);
183184
};

src/util/network/network-widget.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ void DeviceControlWidget::add_access_point(std::shared_ptr<AccessPoint> ap)
257257
auto click = Gtk::GestureClick::create();
258258

259259
auto sig = click->signal_released().connect(
260-
[this, path] (int, double, double)
260+
[this, path, widget] (int, double, double)
261261
{
262-
selected_access_point(path);
262+
selected_access_point(path, widget);
263263
});
264264
widget->add_controller(click);
265265
widget->signals.push_back(sig);
@@ -268,7 +268,7 @@ void DeviceControlWidget::add_access_point(std::shared_ptr<AccessPoint> ap)
268268
sort_access_points();
269269
}
270270

271-
void DeviceControlWidget::selected_access_point(std::string path)
271+
void DeviceControlWidget::selected_access_point(std::string path, std::shared_ptr<AccessPointWidget> widget)
272272
{
273273
auto wifi = std::dynamic_pointer_cast<WifiNetwork>(network);
274274
if (!wifi)
@@ -286,7 +286,13 @@ void DeviceControlWidget::selected_access_point(std::string path)
286286
wifi->disconnect();
287287
} else
288288
{
289-
wifi->connect(path);
289+
if (widget->get_ap()->has_saved_password())
290+
{
291+
wifi->connect(path);
292+
} else
293+
{
294+
NetworkManager::getInstance()->request_password(wifi->get_path(), path);
295+
}
290296
}
291297
}
292298

src/util/network/network-widget.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DeviceControlWidget : public Gtk::Box
4141
~DeviceControlWidget();
4242
void add_access_point(std::shared_ptr<AccessPoint> ap);
4343
void remove_access_point(std::string path);
44-
void selected_access_point(std::string path);
44+
void selected_access_point(std::string path, std::shared_ptr<AccessPointWidget> widget);
4545
void sort_access_points();
4646
std::string type;
4747
};

0 commit comments

Comments
 (0)