gboolean NetworkSettings::add_connection(NMRemoteSettings *settings, GMainLoop *loop, const char *con_name, std::string SSID, std::string sKey)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingIP4Config *s_ip4;
char *uuid;
gboolean success;
// Create a new connection object
connection = nm_connection_new();
// Build up the 'connection' Setting
s_con = (NMSettingConnection *)nm_setting_connection_new();
uuid = nm_utils_uuid_generate();
g_object_set(G_OBJECT(s_con),
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_ID, con_name,
NM_SETTING_CONNECTION_TYPE, "802-11-wireless",
NULL);
g_free(uuid);
nm_connection_add_setting(connection, NM_SETTING(s_con));
// Build up the 'wireless' Setting
s_wireless = (NMSettingWireless *)nm_setting_wireless_new();
g_object_set(G_OBJECT(s_wireless),
NM_SETTING_WIRELESS_SSID, SSID.c_str(),
NM_SETTING_WIRELESS_SEC, sKey.c_str(),
NULL);
nm_connection_add_setting(connection, NM_SETTING(s_wireless));
// Build up the 'ipv4' Setting
s_ip4 = (NMSettingIP4Config *)nm_setting_ip4_config_new();
g_object_set(G_OBJECT(s_ip4),
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting(connection, NM_SETTING(s_ip4));
// Ask the settings service to add the new connection; we'll quit the
// mainloop and exit when the callback is called.
success = nm_remote_settings_add_connection(settings, connection, NetworkSettings::added_cb, loop);
if(!success)
g_print("Error adding connection\n");
g_object_unref(connection);
return success;
}