Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/util/network/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,27 +566,26 @@ void NetworkManager::activate_connection(std::string p1, std::string p2, std::st
Glib::VariantStringBase::create_object_path(path2, p2);
Glib::VariantStringBase::create_object_path(path3, p3);
auto paths = Glib::VariantContainerBase::create_tuple({path1, path2, path3});
// auto data = Glib::VariantContainerBase::create_tuple(paths);

try {
nm_proxy->call("ActivateConnection", paths);
} catch (...)
{}
}

void NetworkManager::request_password(std::string device_path, std::string ap_path)
{
if (device_path.find("/Devices/") != std::string::npos)
{
/* It's most likely a WIFI AP with no password set. Let's ask */
std::cout << p2 << std::endl;
/* No, it's not a regex */
if (p2.find("/Devices/") != std::string::npos)
auto device = std::dynamic_pointer_cast<WifiNetwork>(all_devices[device_path]);
if (device)
{
auto device = std::dynamic_pointer_cast<WifiNetwork>(all_devices[p2]);
if (device)
{
popup_cache_p2 = p2;
popup_cache_p3 = p3;
auto ap = device->get_access_points()[p3];
popup_label.set_label("Preshared Key required for Access Point '" + ap->get_ssid() + "'");
popup_window.present();
popup_window.get_focus();
}
popup_cache_device = device_path;
popup_cache_ap = ap_path;
auto ap = device->get_access_points()[ap_path];
popup_label.set_label("Preshared Key required for Access Point '" + ap->get_ssid() + "'");
popup_window.present();
popup_window.get_focus();
}
}
}
Expand Down Expand Up @@ -717,13 +716,13 @@ void NetworkManager::submit_password()
}

popup_entry.set_text("");
auto wifi = std::dynamic_pointer_cast<WifiNetwork>(all_devices[popup_cache_p2]);
auto wifi = std::dynamic_pointer_cast<WifiNetwork>(all_devices[popup_cache_device]);
if (!wifi)
{
return;
}

auto ap = wifi->get_access_points()[popup_cache_p3];
auto ap = wifi->get_access_points()[popup_cache_ap];
if (!ap)
{
return;
Expand Down Expand Up @@ -789,7 +788,7 @@ void NetworkManager::submit_password()
// Object paths (o)
// ------------------------
auto device_path =
Glib::Variant<Glib::DBusObjectPathString>::create(popup_cache_p2);
Glib::Variant<Glib::DBusObjectPathString>::create(popup_cache_device);
// Access point path is "/" → NM autoselects AP matching SSID
auto ap_path = Glib::Variant<Glib::DBusObjectPathString>::create("/");
// ------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/util/network/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class NetworkManager
Gtk::Label popup_label;
Gtk::Entry popup_entry;

std::string popup_cache_p2 = "", popup_cache_p3 = "";
std::string popup_cache_device = "", popup_cache_ap = "";
inline static std::weak_ptr<NetworkManager> instance;

public:
Expand Down Expand Up @@ -178,6 +178,7 @@ class NetworkManager
void mobile_global_set(bool value);
void networking_global_set(bool value);
void submit_password();
void request_password(std::string device_path, std::string ap_path);

std::shared_ptr<NetworkSettings> get_setting_for_ssid(std::string ssid);
};
14 changes: 10 additions & 4 deletions src/util/network/network-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ void DeviceControlWidget::add_access_point(std::shared_ptr<AccessPoint> ap)
auto click = Gtk::GestureClick::create();

auto sig = click->signal_released().connect(
[this, path] (int, double, double)
[this, path, widget] (int, double, double)
{
selected_access_point(path);
selected_access_point(path, widget);
});
widget->add_controller(click);
widget->signals.push_back(sig);
Expand All @@ -268,7 +268,7 @@ void DeviceControlWidget::add_access_point(std::shared_ptr<AccessPoint> ap)
sort_access_points();
}

void DeviceControlWidget::selected_access_point(std::string path)
void DeviceControlWidget::selected_access_point(std::string path, std::shared_ptr<AccessPointWidget> widget)
{
auto wifi = std::dynamic_pointer_cast<WifiNetwork>(network);
if (!wifi)
Expand All @@ -286,7 +286,13 @@ void DeviceControlWidget::selected_access_point(std::string path)
wifi->disconnect();
} else
{
wifi->connect(path);
if (widget->get_ap()->has_saved_password())
{
wifi->connect(path);
} else
{
NetworkManager::getInstance()->request_password(wifi->get_path(), path);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/network/network-widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DeviceControlWidget : public Gtk::Box
~DeviceControlWidget();
void add_access_point(std::shared_ptr<AccessPoint> ap);
void remove_access_point(std::string path);
void selected_access_point(std::string path);
void selected_access_point(std::string path, std::shared_ptr<AccessPointWidget> widget);
void sort_access_points();
std::string type;
};
Expand Down
Loading