[network-manager-applet/jk/applet-editor-libnm-port: 3/4] applet: GHashTable-to-GVariant and libnm sync/async related changes
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/jk/applet-editor-libnm-port: 3/4] applet: GHashTable-to-GVariant and libnm sync/async related changes
- Date: Tue, 30 Sep 2014 07:33:32 +0000 (UTC)
commit 92762f518b9eab6e5c9f7fea07242e9ac3665db0
Author: Jiří Klimeš <jklimes redhat com>
Date: Mon Sep 29 19:44:40 2014 +0200
applet: GHashTable-to-GVariant and libnm sync/async related changes
src/applet-agent.c | 59 +++++++-------------
src/applet-agent.h | 2 +-
src/applet-device-cdma.c | 26 ++++++----
src/applet-device-ethernet.c | 4 +-
src/applet-device-gsm.c | 25 +++++----
src/applet-device-wifi.c | 120 ++++++++++++++++++++++++++----------------
src/applet-vpn-request.c | 29 +++++-----
src/applet.c | 119 +++++++++++++++++++++++++----------------
src/applet.h | 2 +-
src/migration-tool.c | 23 ++++-----
10 files changed, 227 insertions(+), 182 deletions(-)
---
diff --git a/src/applet-agent.c b/src/applet-agent.c
index 665c4ae..3fd6b62 100644
--- a/src/applet-agent.c
+++ b/src/applet-agent.c
@@ -153,7 +153,7 @@ get_save_cb (NMSecretAgent *agent,
static void
get_secrets_cb (AppletAgent *self,
- GHashTable *secrets,
+ GVariant *secrets,
GError *error,
gpointer user_data)
{
@@ -172,13 +172,13 @@ get_secrets_cb (AppletAgent *self,
*/
if (secrets && (r->flags != NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE)) {
NMConnection *dupl;
- GHashTableIter iter;
+ GVariantIter iter;
const char *setting_name;
/* Copy the existing connection and update its secrets */
dupl = nm_simple_connection_new_clone (r->connection);
- g_hash_table_iter_init (&iter, secrets);
- while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, NULL))
+ g_variant_iter_init (&iter, secrets);
+ while (g_variant_iter_next (&iter, (gpointer) &setting_name, NULL))
nm_connection_update_secrets (dupl, setting_name, secrets, NULL);
/* And save updated secrets to the keyring */
@@ -276,24 +276,6 @@ is_connection_always_ask (NMConnection *connection)
return FALSE;
}
-static GValue *
-string_to_gvalue (const char *str)
-{
- GValue *val;
-
- val = g_slice_new0 (GValue);
- g_value_init (val, G_TYPE_STRING);
- g_value_set_string (val, str);
- return val;
-}
-
-static void
-destroy_gvalue (gpointer data)
-{
- g_value_unset ((GValue *) data);
- g_slice_free (GValue, data);
-}
-
static void
keyring_find_secrets_cb (GObject *source,
GAsyncResult *result,
@@ -303,7 +285,8 @@ keyring_find_secrets_cb (GObject *source,
GError *error = NULL;
GError *search_error = NULL;
const char *connection_id = NULL;
- GHashTable *secrets = NULL, *settings = NULL;
+ GVariantBuilder builder;
+ GVariant *secrets = NULL, *settings = NULL;
GList *list = NULL;
GList *iter;
gboolean hint_found = FALSE, ask = FALSE;
@@ -344,7 +327,7 @@ keyring_find_secrets_cb (GObject *source,
return;
}
- secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+ g_variant_builder_init (&builder, NM_VARIANT_TYPE_SETTING);
/* Extract the secrets from the list of matching keyring items */
for (iter = list; iter != NULL; iter = g_list_next (iter)) {
@@ -363,8 +346,8 @@ keyring_find_secrets_cb (GObject *source,
continue;
}
- g_hash_table_insert (secrets, g_strdup (key_name),
- string_to_gvalue (secret_value_get (secret, NULL)));
+ g_variant_builder_add (&builder, "{sv}", key_name,
+ g_variant_new_string (secret_value_get (secret, NULL)));
/* See if this property matches a given hint */
if (r->hints && r->hints[0]) {
@@ -377,6 +360,7 @@ keyring_find_secrets_cb (GObject *source,
break;
}
}
+ secrets = g_variant_builder_end (&builder);
/* If there were hints, and none of the hints were returned by the keyring,
* get some new secrets.
@@ -395,25 +379,24 @@ keyring_find_secrets_cb (GObject *source,
/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
* will contain all the individual settings hashes.
*/
- settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)
g_hash_table_destroy);
- g_hash_table_insert (settings, g_strdup (r->setting_name), secrets);
+ g_variant_builder_init (&builder, NM_VARIANT_TYPE_CONNECTION);
+ g_variant_builder_add (&builder, "{sa{sv}}", r->setting_name, secrets);
+ settings = g_variant_builder_end (&builder);
done:
g_list_free_full (list, g_object_unref);
if (ask) {
- GHashTableIter hash_iter;
+ GVariantIter dict_iter;
const char *setting_name;
- GHashTable *setting_hash;
+ GVariant *setting_dict;
/* Stuff all the found secrets into the connection for the UI to use */
- g_hash_table_iter_init (&hash_iter, settings);
- while (g_hash_table_iter_next (&hash_iter,
- (gpointer *) &setting_name,
- (gpointer *) &setting_hash)) {
+ g_variant_iter_init (&dict_iter, settings);
+ while (g_variant_iter_next (&dict_iter, "{sa{sv}}", &setting_name, &setting_dict)) {
nm_connection_update_secrets (r->connection,
- setting_name,
- setting_hash,
- NULL);
+ setting_name,
+ setting_dict,
+ NULL);
}
ask_for_secrets (r);
@@ -424,7 +407,7 @@ done:
}
if (settings)
- g_hash_table_destroy (settings);
+ g_variant_unref (settings);
g_clear_error (&error);
}
diff --git a/src/applet-agent.h b/src/applet-agent.h
index b5f6b7e..f82de43 100644
--- a/src/applet-agent.h
+++ b/src/applet-agent.h
@@ -39,7 +39,7 @@ typedef struct {
} AppletAgent;
typedef void (*AppletAgentSecretsCallback) (AppletAgent *self,
- GHashTable *secrets,
+ GVariant *secrets,
GError *error,
gpointer user_data);
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index 419e3b9..99094d3 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -92,14 +92,19 @@ cdma_new_auto_connection (NMDevice *device,
}
static void
-dbus_3g_add_and_activate_cb (NMClient *client,
- NMActiveConnection *active,
- const char *connection_path,
- GError *error,
+dbus_3g_add_and_activate_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error)
g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
+
+ g_clear_object (&active);
+ g_clear_error (&error);
}
typedef struct {
@@ -121,12 +126,13 @@ dbus_connect_3g_cb (NMConnection *connection,
/* Ask NM to add the new connection and activate it; NM will fill in the
* missing details based on the specific object and the device.
*/
- nm_client_add_and_activate_connection (info->applet->nm_client,
- connection,
- info->device,
- "/",
- dbus_3g_add_and_activate_cb,
- info->applet);
+ nm_client_add_and_activate_connection_async (info->applet->nm_client,
+ connection,
+ info->device,
+ "/",
+ NULL,
+ dbus_3g_add_and_activate_cb,
+ info->applet);
}
g_object_unref (info->device);
diff --git a/src/applet-device-ethernet.c b/src/applet-device-ethernet.c
index 146c6c8..570509a 100644
--- a/src/applet-device-ethernet.c
+++ b/src/applet-device-ethernet.c
@@ -272,7 +272,7 @@ get_pppoe_secrets_cb (GtkDialog *dialog, gint response, gpointer user_data)
SecretsRequest *req = user_data;
NMPppoeInfo *info = (NMPppoeInfo *) req;
NMSettingPppoe *setting;
- GHashTable *secrets = NULL;
+ GVariant *secrets = NULL;
GError *error = NULL;
if (response != GTK_RESPONSE_OK) {
@@ -301,7 +301,7 @@ done:
applet_secrets_request_free (req);
if (secrets)
- g_hash_table_destroy (secrets);
+ g_variant_unref (secrets);
}
static void
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 9829c90..8476563 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -125,14 +125,18 @@ gsm_new_auto_connection (NMDevice *device,
}
static void
-dbus_3g_add_and_activate_cb (NMClient *client,
- NMActiveConnection *active,
- const char *connection_path,
- GError *error,
+dbus_3g_add_and_activate_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error)
g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
+ g_clear_object (&active);
+ g_clear_error (&error);
}
typedef struct {
@@ -154,12 +158,13 @@ dbus_connect_3g_cb (NMConnection *connection,
/* Ask NM to add the new connection and activate it; NM will fill in the
* missing details based on the specific object and the device.
*/
- nm_client_add_and_activate_connection (info->applet->nm_client,
- connection,
- info->device,
- "/",
- dbus_3g_add_and_activate_cb,
- info->applet);
+ nm_client_add_and_activate_connection_async (info->applet->nm_client,
+ connection,
+ info->device,
+ "/",
+ NULL,
+ dbus_3g_add_and_activate_cb,
+ info->applet);
}
g_object_unref (info->device);
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index 0ac92de..88cba2a 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -149,14 +149,19 @@ nma_menu_add_create_network_item (GtkWidget *menu, NMApplet *applet)
}
static void
-dbus_8021x_add_and_activate_cb (NMClient *client,
- NMActiveConnection *active,
- const char *connection_path,
- GError *error,
+dbus_8021x_add_and_activate_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
if (error)
g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
+
+ g_clear_object (&active);
+ g_clear_error (&error);
}
typedef struct {
@@ -179,12 +184,13 @@ dbus_connect_8021x_cb (NMConnection *connection,
/* Ask NM to add the new connection and activate it; NM will fill in the
* missing details based on the specific object and the device.
*/
- nm_client_add_and_activate_connection (info->applet->nm_client,
- connection,
- info->device,
- nm_object_get_path (NM_OBJECT (info->ap)),
- dbus_8021x_add_and_activate_cb,
- info->applet);
+ nm_client_add_and_activate_connection_async (info->applet->nm_client,
+ connection,
+ info->device,
+ nm_object_get_path (NM_OBJECT (info->ap)),
+ NULL,
+ dbus_8021x_add_and_activate_cb,
+ info->applet);
}
g_object_unref (info->device);
@@ -1313,11 +1319,15 @@ wifi_get_icon (NMDevice *device,
static void
-activate_existing_cb (NMClient *client,
- NMActiveConnection *active,
- GError *error,
+activate_existing_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
+ g_clear_object (&active);
if (error) {
const char *text = _("Failed to activate connection");
char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -1326,17 +1336,21 @@ activate_existing_cb (NMClient *client,
g_warning ("%s: %s", text, err_text);
utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
g_free (err_text);
+ g_error_free (error);
}
applet_schedule_update_icon (NM_APPLET (user_data));
}
static void
-activate_new_cb (NMClient *client,
- NMActiveConnection *active,
- const char *connection_path,
- GError *error,
+activate_new_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
+ g_clear_object (&active);
if (error) {
const char *text = _("Failed to add new connection");
char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -1345,6 +1359,7 @@ activate_new_cb (NMClient *client,
g_warning ("%s: %s", text, err_text);
utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
g_free (err_text);
+ g_error_free (error);
}
applet_schedule_update_icon (NM_APPLET (user_data));
}
@@ -1384,12 +1399,13 @@ wifi_dialog_response_cb (GtkDialog *foo,
g_slist_free (all);
if (fuzzy_match) {
- nm_client_activate_connection (applet->nm_client,
- fuzzy_match,
- device,
- ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
- activate_existing_cb,
- applet);
+ nm_client_activate_connection_async (applet->nm_client,
+ fuzzy_match,
+ device,
+ ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
+ NULL,
+ activate_existing_cb,
+ applet);
} else {
NMSetting *s_con;
NMSettingWireless *s_wifi = NULL;
@@ -1410,12 +1426,13 @@ wifi_dialog_response_cb (GtkDialog *foo,
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
}
- nm_client_add_and_activate_connection (applet->nm_client,
- connection,
- device,
- ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
- activate_new_cb,
- applet);
+ nm_client_add_and_activate_connection_async (applet->nm_client,
+ connection,
+ device,
+ ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
+ NULL,
+ activate_new_cb,
+ applet);
}
/* Balance nma_wifi_dialog_get_connection() */
@@ -1426,17 +1443,29 @@ done:
gtk_widget_destroy (GTK_WIDGET (dialog));
}
-static gboolean
-remove_unwanted_secrets (gpointer key, gpointer value, gpointer user_data)
+static GVariant *
+remove_unwanted_secrets (GVariant *secrets, gboolean keep_8021X)
{
- gboolean keep_8021X = (gboolean) GPOINTER_TO_UINT (user_data);
-
- if ( strcmp ((char *) key, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)
- && (strcmp ((char *)key, NM_SETTING_802_1X_SETTING_NAME) || !keep_8021X))
- return TRUE;
+ GVariant *copy, *setting_dict;
+ const char *setting_name;
+ GVariantBuilder conn_builder;
+ GVariantIter conn_iter;
+
+ g_variant_builder_init (&conn_builder, NM_VARIANT_TYPE_CONNECTION);
+ g_variant_iter_init (&conn_iter, secrets);
+ while (g_variant_iter_next (&conn_iter, "{&s a{sv}}", &setting_name, &setting_dict)) {
+ if ( !strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)
+ || (!strcmp (setting_name, NM_SETTING_802_1X_SETTING_NAME) && keep_8021X))
+ g_variant_builder_add (&conn_builder, "{s a{sv}}", setting_name, setting_dict);
+
+ g_variant_unref (setting_dict);
+ }
+ copy = g_variant_builder_end (&conn_builder);
+ g_variant_unref (secrets);
- return FALSE;
+ return copy;
}
+
typedef struct {
SecretsRequest req;
@@ -1465,7 +1494,7 @@ get_secrets_dialog_response_cb (GtkDialog *foo,
NMAWifiDialog *dialog = NMA_WIFI_DIALOG (info->dialog);
NMConnection *connection = NULL;
NMSettingWirelessSecurity *s_wireless_sec;
- GHashTable *hash = NULL;
+ GVariant *secrets = NULL;
const char *key_mgmt, *auth_alg;
gboolean keep_8021X = FALSE;
GError *error = NULL;
@@ -1501,8 +1530,8 @@ get_secrets_dialog_response_cb (GtkDialog *foo,
goto done; /* Unencrypted */
}
- hash = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
- if (!hash) {
+ secrets = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
+ if (!secrets) {
g_set_error (&error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
@@ -1536,16 +1565,15 @@ get_secrets_dialog_response_cb (GtkDialog *foo,
}
}
- /* Remove all not-relevant secrets (inner hashes) */
- if (g_hash_table_size (hash) > 0)
- g_hash_table_foreach_remove (hash, remove_unwanted_secrets, GUINT_TO_POINTER (keep_8021X));
+ /* Remove all not-relevant secrets (inner dicts) */
+ secrets = remove_unwanted_secrets (secrets, keep_8021X);
done:
- applet_secrets_request_complete (req, hash, error);
+ applet_secrets_request_complete (req, secrets, error);
applet_secrets_request_free (req);
- if (hash)
- g_hash_table_destroy (hash);
+ if (secrets)
+ g_variant_unref (secrets);
if (connection)
nm_connection_clear_secrets (connection);
}
diff --git a/src/applet-vpn-request.c b/src/applet-vpn-request.c
index 2fed5bb..3d2c1d2 100644
--- a/src/applet-vpn-request.c
+++ b/src/applet-vpn-request.c
@@ -95,22 +95,15 @@ child_finished_cb (GPid pid, gint status, gpointer user_data)
AppletVpnRequest *self = info->vpn;
AppletVpnRequestPrivate *priv = APPLET_VPN_REQUEST_GET_PRIVATE (self);
GError *error = NULL;
- GHashTable *settings = NULL;
+ GVariant *settings = NULL;
+ GVariantBuilder settings_builder, vpn_builder, secrets_builder;
if (status == 0) {
- GHashTable *vpn, *secrets;
- GValue val = { 0 };
GSList *iter;
- settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)
g_hash_table_destroy);
-
- vpn = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_value_unset);
- g_hash_table_insert (settings, NM_SETTING_VPN_SETTING_NAME, vpn);
-
- secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
- g_value_init (&val, DBUS_TYPE_G_MAP_OF_STRING);
- g_value_take_boxed (&val, secrets);
- g_hash_table_insert (vpn, NM_SETTING_VPN_SECRETS, &val);
+ g_variant_builder_init (&settings_builder, NM_VARIANT_TYPE_CONNECTION);
+ g_variant_builder_init (&vpn_builder, NM_VARIANT_TYPE_SETTING);
+ g_variant_builder_init (&secrets_builder, G_VARIANT_TYPE ("a{ss}"));
/* The length of 'lines' must be divisible by 2 since it must contain
* key:secret pairs with the key on one line and the associated secret
@@ -119,9 +112,17 @@ child_finished_cb (GPid pid, gint status, gpointer user_data)
for (iter = priv->lines; iter; iter = g_slist_next (iter)) {
if (!iter->next)
break;
- g_hash_table_insert (secrets, (char *) iter->data, (char *) iter->next->data);
+ g_variant_builder_add (&secrets_builder, "{ss}", iter->data, iter->next->data);
iter = iter->next;
}
+
+ g_variant_builder_add (&vpn_builder, "{sv}",
+ NM_SETTING_VPN_SECRETS,
+ g_variant_builder_end (&secrets_builder));
+ g_variant_builder_add (&settings_builder, "{sa{sv}}",
+ NM_SETTING_VPN_SETTING_NAME,
+ &vpn_builder);
+ settings = g_variant_builder_end (&settings_builder);
} else {
error = g_error_new (NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_USER_CANCELED,
@@ -133,7 +134,7 @@ child_finished_cb (GPid pid, gint status, gpointer user_data)
applet_secrets_request_free (req);
if (settings)
- g_hash_table_destroy (settings);
+ g_variant_unref (settings);
g_clear_error (&error);
}
diff --git a/src/applet.c b/src/applet.c
index ab0f888..332a844 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -539,12 +539,16 @@ applet_item_activate_info_destroy (AppletItemActivateInfo *info)
}
static void
-add_and_activate_cb (NMClient *client,
- NMActiveConnection *active,
- const char *connection_path,
- GError *error,
+add_and_activate_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_add_and_activate_connection_finish (NM_CLIENT (client), result, &error);
+ g_clear_object (&active);
+
if (error) {
const char *text = _("Failed to add/activate connection");
char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -553,6 +557,7 @@ add_and_activate_cb (NMClient *client,
g_warning ("%s: %s", text, err_text);
utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
g_free (err_text);
+ g_error_free (error);
}
applet_schedule_update_icon (NM_APPLET (user_data));
@@ -576,19 +581,26 @@ applet_menu_item_activate_helper_new_connection (NMConnection *connection,
/* Ask NM to add the new connection and activate it; NM will fill in the
* missing details based on the specific object and the device.
*/
- nm_client_add_and_activate_connection (info->applet->nm_client,
- connection,
- info->device,
- info->specific_object,
- add_and_activate_cb,
- info->applet);
+ nm_client_add_and_activate_connection_async (info->applet->nm_client,
+ connection,
+ info->device,
+ info->specific_object,
+ NULL,
+ add_and_activate_cb,
+ info->applet);
applet_item_activate_info_destroy (info);
}
static void
-disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
+disconnect_cb (GObject *device,
+ GAsyncResult *result,
+ gpointer user_data)
+
{
+ GError *error = NULL;
+
+ nm_device_disconnect_finish (NM_DEVICE (device), result, &error);
if (error) {
const char *text = _("Device disconnect failed");
char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -597,6 +609,7 @@ disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
g_warning ("%s: %s: %s", __func__, text, err_text);
utils_show_error_dialog (_("Disconnect failure"), text, err_text, FALSE, NULL);
g_free (err_text);
+ g_error_free (error);
}
}
@@ -606,15 +619,20 @@ applet_menu_item_disconnect_helper (NMDevice *device,
{
g_return_if_fail (NM_IS_DEVICE (device));
- nm_device_disconnect (device, disconnect_cb, NULL);
+ nm_device_disconnect_async (device, NULL, disconnect_cb, NULL);
}
static void
-activate_connection_cb (NMClient *client,
- NMActiveConnection *active,
- GError *error,
+activate_connection_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
+ GError *error = NULL;
+ NMActiveConnection *active;
+
+ active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
+ g_clear_object (&active);
+
if (error) {
const char *text = _("Connection activation failed");
char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -623,6 +641,7 @@ activate_connection_cb (NMClient *client,
g_warning ("%s: %s", text, err_text);
utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
g_free (err_text);
+ g_error_free (error);
}
applet_schedule_update_icon (NM_APPLET (user_data));
@@ -642,12 +661,13 @@ applet_menu_item_activate_helper (NMDevice *device,
/* If the menu item had an associated connection already, just tell
* NM to activate that connection.
*/
- nm_client_activate_connection (applet->nm_client,
- connection,
- device,
- specific_object,
- activate_connection_cb,
- applet);
+ nm_client_activate_connection_async (applet->nm_client,
+ connection,
+ device,
+ specific_object,
+ NULL,
+ activate_connection_cb,
+ applet);
return;
}
@@ -1160,13 +1180,17 @@ typedef struct {
} VPNActivateInfo;
static void
-activate_vpn_cb (NMClient *client,
- NMActiveConnection *active,
- GError *error,
+activate_vpn_cb (GObject *client,
+ GAsyncResult *result,
gpointer user_data)
{
VPNActivateInfo *info = (VPNActivateInfo *) user_data;
+ NMActiveConnection *active;
char *title, *msg, *name;
+ GError *error = NULL;
+
+ active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error);
+ g_clear_object (&active);
if (error) {
clear_animation_timeout (info->applet);
@@ -1187,9 +1211,9 @@ activate_vpn_cb (NMClient *client,
applet_do_notify_with_pref (info->applet, title, msg, "gnome-lockscreen",
PREF_DISABLE_VPN_NOTIFICATIONS);
- g_free (msg);
-
g_warning ("VPN Connection activation failed: (%s) %s", name, error->message);
+ g_free (msg);
+ g_error_free (error);
}
applet_schedule_update_icon (info->applet);
@@ -1229,12 +1253,13 @@ nma_menu_vpn_item_clicked (GtkMenuItem *item, gpointer user_data)
info->vpn_name = g_strdup (nm_setting_connection_get_id (s_con));
/* Connection inactive, activate */
- nm_client_activate_connection (applet->nm_client,
- connection,
- device,
- nm_object_get_path (NM_OBJECT (active)),
- activate_vpn_cb,
- info);
+ nm_client_activate_connection_async (applet->nm_client,
+ connection,
+ device,
+ nm_object_get_path (NM_OBJECT (active)),
+ NULL,
+ activate_vpn_cb,
+ info);
start_animation_timeout (applet);
// nmi_dbus_signal_user_interface_activated (applet->connection);
@@ -1304,7 +1329,7 @@ nma_menu_disconnect_vpn_item_activate (GtkMenuItem *item, gpointer user_data)
active_vpn = applet_get_first_active_vpn_connection (applet, &state);
if (active_vpn)
- nm_client_deactivate_connection (applet->nm_client, active_vpn);
+ nm_client_deactivate_connection (applet->nm_client, active_vpn, NULL, NULL);
else
g_warning ("%s: deactivate clicked but no active VPN connection could be found.", __func__);
// nmi_dbus_signal_user_interface_activated (applet->connection);
@@ -3042,7 +3067,7 @@ applet_secrets_request_set_free_func (SecretsRequest *req,
void
applet_secrets_request_complete (SecretsRequest *req,
- GHashTable *settings,
+ GVariant *settings,
GError *error)
{
req->callback (req->applet->agent, error ? NULL : settings, error, req->callback_data);
@@ -3054,29 +3079,29 @@ applet_secrets_request_complete_setting (SecretsRequest *req,
GError *error)
{
NMSetting *setting;
- GHashTable *secrets_hash = NULL;
+ GVariant *secrets_dict = NULL;
if (setting_name && !error) {
setting = nm_connection_get_setting_by_name (req->connection, setting_name);
if (setting) {
- secrets_hash = nm_connection_to_dbus (req->connection, NM_CONNECTION_SERIALIZE_ALL);
- if (!secrets_hash) {
+ secrets_dict = nm_connection_to_dbus (req->connection, NM_CONNECTION_SERIALIZE_ALL);
+ if (!secrets_dict) {
g_set_error (&error,
- NM_SECRET_AGENT_ERROR,
- NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
- "%s.%d (%s): failed to hash setting '%s'.",
- __FILE__, __LINE__, __func__, setting_name);
+ NM_SECRET_AGENT_ERROR,
+ NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
+ "%s.%d (%s): failed to hash setting '%s'.",
+ __FILE__, __LINE__, __func__, setting_name);
}
} else {
g_set_error (&error,
- NM_SECRET_AGENT_ERROR,
- NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
- "%s.%d (%s): unhandled setting '%s'",
- __FILE__, __LINE__, __func__, setting_name);
+ NM_SECRET_AGENT_ERROR,
+ NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
+ "%s.%d (%s): unhandled setting '%s'",
+ __FILE__, __LINE__, __func__, setting_name);
}
}
- req->callback (req->applet->agent, secrets_hash, error, req->callback_data);
+ req->callback (req->applet->agent, secrets_dict, error, req->callback_data);
}
void
@@ -3099,7 +3124,7 @@ applet_secrets_request_free (SecretsRequest *req)
static void
get_existing_secrets_cb (NMSecretAgent *agent,
NMConnection *connection,
- GHashTable *secrets,
+ GVariant *secrets,
GError *secrets_error,
gpointer user_data)
{
diff --git a/src/applet.h b/src/applet.h
index 6133497..fbd96c7 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -215,7 +215,7 @@ struct _SecretsRequest {
void applet_secrets_request_set_free_func (SecretsRequest *req,
SecretsRequestFreeFunc free_func);
void applet_secrets_request_complete (SecretsRequest *req,
- GHashTable *settings,
+ GVariant *settings,
GError *error);
void applet_secrets_request_complete_setting (SecretsRequest *req,
const char *setting_name,
diff --git a/src/migration-tool.c b/src/migration-tool.c
index 22644bd..7ef77b1 100644
--- a/src/migration-tool.c
+++ b/src/migration-tool.c
@@ -30,20 +30,22 @@
gboolean success = TRUE;
static void
-add_cb (NMRemoteSettings *settings,
- NMRemoteConnection *connection,
- GError *error,
+add_cb (GObject *settings,
+ GAsyncResult *result,
gpointer user_data)
{
- NMConnection *c = user_data;
+ NMRemoteConnection *c;
+ GError *error = NULL;
+ c = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
+ result, &error);
if (error) {
g_printerr ("Failed to move connection '%s' to NetworkManager system settings: %s",
- nm_connection_get_id (c),
- error->message);
+ nm_connection_get_id (NM_CONNECTION (c)), error->message);
success = FALSE;
+ g_error_free (error);
}
- g_object_unref (c);
+ g_clear_object (&c);
}
static void
@@ -51,12 +53,7 @@ import_cb (NMConnection *connection, gpointer user_data)
{
NMRemoteSettings *settings = user_data;
- if (!nm_remote_settings_add_connection (settings, connection, add_cb, g_object_ref (connection))) {
- g_warning ("Failed to move connection '%s' to NetworkManager system settings.",
- nm_connection_get_id (connection));
- g_object_unref (connection);
- success = FALSE;
- }
+ nm_remote_settings_add_connection_async (settings, connection, TRUE, NULL, add_cb, NULL);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]