[network-manager-applet/jk/applet-editor-libnm-port: 2/4] editor: 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: 2/4] editor: GHashTable-to-GVariant and libnm sync/async related changes
- Date: Mon, 29 Sep 2014 17:47:12 +0000 (UTC)
commit fd9bdb9a83943c00aee6ff9c5d796ee84f17d0ac
Author: Jiří Klimeš <jklimes redhat com>
Date: Mon Sep 29 17:20:30 2014 +0200
editor: GHashTable-to-GVariant and libnm sync/async related changes
src/connection-editor/ce-page.c | 24 ++++++---
src/connection-editor/ce-page.h | 2 +-
src/connection-editor/connection-helpers.c | 11 +++--
src/connection-editor/nm-connection-editor.c | 75 +++++++++++++++++---------
src/libnm-gtk/nm-wifi-dialog.c | 48 ++++++++--------
5 files changed, 97 insertions(+), 63 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index a00b492..1a1c70b 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -283,22 +283,29 @@ emit_initialized (CEPage *self, GError *error)
void
ce_page_complete_init (CEPage *self,
const char *setting_name,
- GHashTable *secrets,
+ GVariant *secrets,
GError *error)
{
GError *update_error = NULL;
- GHashTable *setting_hash;
+ GVariant *setting_dict;
+ char *dbus_err;
+ gboolean ignore_error = FALSE;
g_return_if_fail (self != NULL);
g_return_if_fail (CE_IS_PAGE (self));
+ if (error) {
+ dbus_err = g_dbus_error_get_remote_error (error);
+ ignore_error = !g_strcmp0 (dbus_err,
"org.freedesktop.NetworkManager.Settings.InvalidSetting")
+ || !g_strcmp0 (dbus_err,
"org.freedesktop.NetworkManager.AgentManager.NoSecrets");
+ g_free (dbus_err);
+ }
+
/* Ignore missing settings errors */
- if ( error
- && !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.InvalidSetting")
- && !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.AgentManager.NoSecrets")) {
+ if (error && !ignore_error) {
emit_initialized (self, error);
return;
- } else if (!setting_name || !secrets || !g_hash_table_size (secrets)) {
+ } else if (!setting_name || !secrets) {
/* Success, no secrets */
emit_initialized (self, NULL);
return;
@@ -307,12 +314,13 @@ ce_page_complete_init (CEPage *self,
g_assert (setting_name);
g_assert (secrets);
- setting_hash = g_hash_table_lookup (secrets, setting_name);
- if (!setting_hash) {
+ setting_dict = g_variant_lookup_value (secrets, setting_name, NM_VARIANT_TYPE_SETTING);
+ if (!setting_dict) {
/* Success, no secrets */
emit_initialized (self, NULL);
return;
}
+ g_variant_unref (setting_dict);
/* Update the connection with the new secrets */
if (nm_connection_update_secrets (self->connection,
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index 7450ca1..6c1f537 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -123,7 +123,7 @@ int ce_get_property_default (NMSetting *setting, const char *property_name);
void ce_page_complete_init (CEPage *self,
const char *setting_name,
- GHashTable *secrets,
+ GVariant *secrets,
GError *error);
gboolean ce_page_get_initialized (CEPage *self);
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c
index 1d74867..29446e2 100644
--- a/src/connection-editor/connection-helpers.c
+++ b/src/connection-editor/connection-helpers.c
@@ -510,13 +510,15 @@ typedef struct {
} DeleteInfo;
static void
-delete_cb (NMRemoteConnection *connection,
- GError *error,
+delete_cb (GObject *connection,
+ GAsyncResult *result,
gpointer user_data)
{
DeleteInfo *info = user_data;
DeleteConnectionResultFunc result_func;
+ GError *error = NULL;
+ nm_remote_connection_delete_finish (NM_REMOTE_CONNECTION (connection), result, &error);
if (error) {
nm_connection_editor_error (info->parent_window,
_("Connection delete failed"),
@@ -533,9 +535,10 @@ delete_cb (NMRemoteConnection *connection,
result_func = info->result_func;
user_data = info->user_data;
g_free (info);
+ g_clear_error (&error);
if (result_func)
- (*result_func) (connection, error == NULL, user_data);
+ (*result_func) (NM_REMOTE_CONNECTION (connection), error == NULL, user_data);
}
void
@@ -588,7 +591,7 @@ delete_connection (GtkWindow *parent_window,
if (editor)
nm_connection_editor_set_busy (editor, TRUE);
- nm_remote_connection_delete (connection, delete_cb, info);
+ nm_remote_connection_delete_async (connection, NULL, delete_cb, info);
}
gboolean
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 0b55e17..6359c6a 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -588,19 +588,23 @@ page_initialized (CEPage *page, GError *error, gpointer user_data)
static void request_secrets (GetSecretsInfo *info);
static void
-get_secrets_cb (NMRemoteConnection *connection,
- GHashTable *secrets,
- GError *error,
+get_secrets_cb (GObject *object,
+ GAsyncResult *result,
gpointer user_data)
{
+ NMRemoteConnection *connection = NM_REMOTE_CONNECTION (object);
GetSecretsInfo *info = user_data;
NMConnectionEditor *self;
+ GVariant *secrets;
+ GError *error = NULL;
if (info->canceled) {
get_secrets_info_free (info);
return;
}
+ secrets = nm_remote_connection_get_secrets_finish (connection, result, &error);
+
self = info->self;
/* Complete this secrets request; completion can actually dispose of the
@@ -626,10 +630,8 @@ request_secrets (GetSecretsInfo *info)
{
g_return_if_fail (info != NULL);
- nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (info->self->orig_connection),
- info->setting_name,
- get_secrets_cb,
- info);
+ nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (info->self->orig_connection),
+ info->setting_name, NULL, get_secrets_cb, info);
}
static void
@@ -864,22 +866,26 @@ editor_closed_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data)
}
static void
-added_connection_cb (NMRemoteSettings *settings,
- NMRemoteConnection *connection,
- GError *error,
+added_connection_cb (GObject *settings,
+ GAsyncResult *result,
gpointer user_data)
{
NMConnectionEditor *self = user_data;
+ NMRemoteConnection *connection;
+ GError *error = NULL;
nm_connection_editor_set_busy (self, FALSE);
+ connection = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings),
+ result, &error);
if (error) {
nm_connection_editor_error (self->parent_window, _("Connection add failed"),
"%s", error->message);
-
/* Leave the editor open */
return;
}
+ g_clear_object (&connection);
+ g_clear_error (&error);
g_signal_emit (self, editor_signals[EDITOR_DONE], 0, GTK_RESPONSE_OK);
}
@@ -892,9 +898,15 @@ update_complete (NMConnectionEditor *self, GError *error)
}
static void
-updated_connection_cb (NMRemoteConnection *connection, GError *error, gpointer user_data)
+updated_connection_cb (GObject *connection,
+ GAsyncResult *result,
+ gpointer user_data)
{
NMConnectionEditor *self = NM_CONNECTION_EDITOR (user_data);
+ GError *error = NULL;
+
+ nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (connection),
+ result, &error);
/* Clear secrets so they don't lay around in memory; they'll get requested
* again anyway next time the connection is edited.
@@ -902,6 +914,7 @@ updated_connection_cb (NMRemoteConnection *connection, GError *error, gpointer u
nm_connection_clear_secrets (NM_CONNECTION (connection));
update_complete (self, error);
+ g_clear_error (&error);
}
static void
@@ -916,13 +929,15 @@ ok_button_clicked_save_connection (NMConnectionEditor *self)
eap_method_ca_cert_ignore_save (self->connection);
if (self->is_new_connection) {
- nm_remote_settings_add_connection (self->settings,
- self->orig_connection,
- added_connection_cb,
- self);
+ nm_remote_settings_add_connection_async (self->settings,
+ self->orig_connection,
+ TRUE,
+ NULL,
+ added_connection_cb,
+ self);
} else {
- nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (self->orig_connection),
- updated_connection_cb, self);
+ nm_remote_connection_commit_changes_async (NM_REMOTE_CONNECTION (self->orig_connection),
+ TRUE, NULL, updated_connection_cb, self);
}
}
@@ -944,24 +959,31 @@ ok_button_clicked_cb (GtkWidget *widget, gpointer user_data)
}
static void
-vpn_export_get_secrets_cb (NMRemoteConnection *connection,
- GHashTable *secrets,
- GError *error,
+vpn_export_get_secrets_cb (GObject *object,
+ GAsyncResult *result,
gpointer user_data)
{
NMConnection *tmp;
+ GVariant *secrets;
+ GError *error = NULL;
+
+ secrets = nm_remote_connection_get_secrets_finish (NM_REMOTE_CONNECTION (object),
+ result, &error);
/* We don't really care about errors; if the user couldn't authenticate
* then just let them export everything except secrets. Duplicate the
* connection so that we don't let secrets sit around in the original
* one.
*/
- tmp = nm_simple_connection_new_clone (NM_CONNECTION (connection));
+ tmp = nm_simple_connection_new_clone (NM_CONNECTION (object));
g_assert (tmp);
if (secrets)
nm_connection_update_secrets (tmp, NM_SETTING_VPN_SETTING_NAME, secrets, NULL);
vpn_export (tmp);
g_object_unref (tmp);
+ if (secrets)
+ g_variant_ref (secrets);
+ g_clear_error (&error);
}
static void
@@ -971,10 +993,11 @@ export_button_clicked_cb (GtkWidget *widget, gpointer user_data)
if (NM_IS_REMOTE_CONNECTION (self->orig_connection)) {
/* Grab secrets if we can */
- nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (self->orig_connection),
- NM_SETTING_VPN_SETTING_NAME,
- vpn_export_get_secrets_cb,
- self);
+ nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (self->orig_connection),
+ NM_SETTING_VPN_SETTING_NAME,
+ NULL,
+ vpn_export_get_secrets_cb,
+ self);
} else
vpn_export (self->connection);
}
diff --git a/src/libnm-gtk/nm-wifi-dialog.c b/src/libnm-gtk/nm-wifi-dialog.c
index 03f7d2f..7a4164a 100644
--- a/src/libnm-gtk/nm-wifi-dialog.c
+++ b/src/libnm-gtk/nm-wifi-dialog.c
@@ -715,21 +715,33 @@ add_security_item (NMAWifiDialog *self,
}
static void
-get_secrets_cb (NMRemoteConnection *connection,
- GHashTable *secrets,
- GError *error,
+get_secrets_cb (GObject *object,
+ GAsyncResult *result,
gpointer user_data)
{
GetSecretsInfo *info = user_data;
+ NMRemoteConnection *connection = NM_REMOTE_CONNECTION (object);
NMAWifiDialogPrivate *priv;
- GHashTableIter hash_iter;
- gpointer key, value;
+ GVariant *secrets;
+ GVariantIter variant_iter;
+ const char *setting_name;
+ GVariant *setting_dict;
GtkTreeModel *model;
GtkTreeIter iter;
+ GError *error = NULL;
if (info->canceled)
goto out;
+ secrets = nm_remote_connection_get_secrets_finish (connection, result, &error);
+ if (error) {
+ g_warning ("%s: error getting connection secrets: (%d) %s",
+ __func__,
+ error ? error->code : -1,
+ error && error->message ? error->message : "(unknown)");
+ goto out;
+ }
+
priv = NMA_WIFI_DIALOG_GET_PRIVATE (info->self);
if (priv->secrets_info == info) {
priv->secrets_info = NULL;
@@ -741,33 +753,22 @@ get_secrets_cb (NMRemoteConnection *connection,
gtk_dialog_set_response_sensitive (GTK_DIALOG (info->self), GTK_RESPONSE_OK, TRUE);
}
- if (error) {
- g_warning ("%s: error getting connection secrets: (%d) %s",
- __func__,
- error ? error->code : -1,
- error && error->message ? error->message : "(unknown)");
- goto out;
- }
-
/* User might have changed the connection while the secrets call was in
* progress, so don't try to update the wrong connection with the secrets
* we just received.
*/
if ( (priv->connection != info->connection)
- || !secrets
- || !g_hash_table_size (secrets))
+ || !secrets)
goto out;
/* Try to update the connection's secrets; log errors but we don't care */
- g_hash_table_iter_init (&hash_iter, secrets);
- while (g_hash_table_iter_next (&hash_iter, &key, &value)) {
+ g_variant_iter_init (&variant_iter, secrets);
+ while (g_variant_iter_next (&variant_iter, "{&s a{sv}}", &setting_name, &setting_dict)) {
GError *update_error = NULL;
- const char *setting_name = key;
- GHashTable *setting_hash = value;
if (!nm_connection_update_secrets (priv->connection,
setting_name,
- setting_hash,
+ setting_dict,
&update_error)) {
g_warning ("%s: error updating connection secrets: (%d) %s",
__func__,
@@ -775,6 +776,7 @@ get_secrets_cb (NMRemoteConnection *connection,
update_error && update_error->message ? update_error->message :
"(unknown)");
g_clear_error (&update_error);
}
+ g_variant_unref (setting_dict);
}
/* Update each security method's UI elements with the new secrets */
@@ -977,10 +979,8 @@ security_combo_init (NMAWifiDialog *self, gboolean secrets_only)
info->connection = g_object_ref (priv->connection);
priv->secrets_info = info;
- nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (priv->connection),
- setting_name,
- get_secrets_cb,
- info);
+ nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (priv->connection),
+ setting_name, NULL, get_secrets_cb, info);
}
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]