[gnome-bluetooth] Some more simplification of the agent code
- From: Bastien Nocera <hadess src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-bluetooth] Some more simplification of the agent code
- Date: Sat, 13 Jun 2009 19:12:11 -0400 (EDT)
commit 322eff83d9f32a500e579bcc4bd9768607cf7c78
Author: Bastien Nocera <hadess hadess net>
Date: Sat Jun 13 23:59:13 2009 +0100
Some more simplification of the agent code
Move all the property getting into its own functions.
applet/agent.c | 236 +++++++++++++++++++--------------------------
applet/test-agentdialog.c | 8 +-
2 files changed, 102 insertions(+), 142 deletions(-)
---
diff --git a/applet/agent.c b/applet/agent.c
index 7fd8651..2a9b8db 100644
--- a/applet/agent.c
+++ b/applet/agent.c
@@ -198,9 +198,12 @@ static void toggled_callback(GtkWidget *button, gpointer user_data)
gtk_entry_set_visibility(GTK_ENTRY(input->entry), mode);
}
-static void passkey_dialog(DBusGProxy *adapter, DBusGProxy *device,
- const char *address, const char *name, gboolean numeric,
- DBusGMethodInvocation *context)
+static void
+passkey_dialog (DBusGProxy *adapter,
+ DBusGProxy *device,
+ const char *name,
+ gboolean numeric,
+ DBusGMethodInvocation *context)
{
GtkWidget *dialog;
GtkWidget *button;
@@ -305,15 +308,19 @@ static void passkey_dialog(DBusGProxy *adapter, DBusGProxy *device,
enable_blinking();
}
+#if 0
static void display_dialog(DBusGProxy *adapter, DBusGProxy *device,
const char *address, const char *name, const char *value,
guint entered, DBusGMethodInvocation *context)
{
}
-
-static void confirm_dialog(DBusGProxy *adapter, DBusGProxy *device,
- const char *address, const char *name, const char *value,
- DBusGMethodInvocation *context)
+#endif
+static void
+confirm_dialog (DBusGProxy *adapter,
+ DBusGProxy *device,
+ const char *name,
+ const char *value,
+ DBusGMethodInvocation *context)
{
GtkWidget *dialog;
GtkWidget *button;
@@ -394,9 +401,12 @@ static void confirm_dialog(DBusGProxy *adapter, DBusGProxy *device,
enable_blinking();
}
-static void auth_dialog(DBusGProxy *adapter, DBusGProxy *device,
- const char *address, const char *name, const char *uuid,
- DBusGMethodInvocation *context)
+static void
+auth_dialog (DBusGProxy *adapter,
+ DBusGProxy *device,
+ const char *name,
+ const char *uuid,
+ DBusGMethodInvocation *context)
{
GtkWidget *dialog;
GtkWidget *button;
@@ -508,44 +518,70 @@ static void notification_closed(GObject *object, gpointer user_data)
(dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
#endif
-static gboolean device_get_properties(DBusGProxy *proxy,
- GHashTable **hash, GError **error)
+static char *
+device_get_name(DBusGProxy *proxy, char **ret_alias)
{
- return dbus_g_proxy_call(proxy, "GetProperties", error,
- G_TYPE_INVALID, DBUS_TYPE_G_DICTIONARY, hash, G_TYPE_INVALID);
+ GHashTable *hash;
+ GValue *value;
+ char *alias, *address;
+
+ if (dbus_g_proxy_call (proxy, "GetProperties", NULL,
+ G_TYPE_INVALID,
+ DBUS_TYPE_G_DICTIONARY, &hash,
+ G_TYPE_INVALID) == FALSE) {
+ return NULL;
+ }
+
+ value = g_hash_table_lookup(hash, "Address");
+ if (value == NULL) {
+ g_hash_table_destroy (hash);
+ return NULL;
+ }
+ address = g_value_dup_string(value);
+
+ value = g_hash_table_lookup(hash, "Alias");
+ alias = value ? g_value_dup_string(value) : NULL;
+
+ g_hash_table_destroy (hash);
+
+ if (ret_alias != NULL)
+ *ret_alias = alias;
+
+ return address;
}
-static gboolean pincode_request(DBusGMethodInvocation *context,
- DBusGProxy *device, gpointer user_data)
+static char *
+get_name_for_display (DBusGProxy *proxy)
{
- DBusGProxy *adapter = user_data;
- GHashTable *hash = NULL;
- GValue *value;
- const gchar *address, *alias;
- gchar *name, *line;
+ char *address, *alias, *name;
- device_get_properties(device, &hash, NULL);
+ address = device_get_name(proxy, &alias);
+ if (address == NULL)
+ return NULL;
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Address");
- address = value ? g_value_get_string(value) : NULL;
-
- value = g_hash_table_lookup(hash, "Name");
- alias = value ? g_value_get_string(value) : NULL;
- } else {
- address = NULL;
- alias = NULL;
+ if (g_strrstr(alias, address)) {
+ g_free (address);
+ return alias;
}
+ name = g_strdup_printf("%s (%s)", alias, address);
- if (alias) {
- if (g_strrstr(alias, address))
- name = g_strdup(alias);
- else
- name = g_strdup_printf("%s (%s)", alias, address);
- } else
- name = g_strdup(address);
+ g_free (alias);
+ g_free (address);
- passkey_dialog(adapter, device, address, name, FALSE, context);
+ return name;
+}
+
+static gboolean pincode_request(DBusGMethodInvocation *context,
+ DBusGProxy *device, gpointer user_data)
+{
+ DBusGProxy *adapter = user_data;
+ char *name, *line;
+
+ name = get_name_for_display (device);
+ if (name == NULL)
+ return FALSE;
+
+ passkey_dialog(adapter, device, name, FALSE, context);
if (notification_supports_actions () == FALSE) {
g_free (name);
@@ -572,33 +608,13 @@ static gboolean passkey_request(DBusGMethodInvocation *context,
DBusGProxy *device, gpointer user_data)
{
DBusGProxy *adapter = user_data;
- GHashTable *hash = NULL;
- GValue *value;
- const gchar *address, *alias;
- gchar *name, *line;
-
- device_get_properties(device, &hash, NULL);
-
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Address");
- address = value ? g_value_get_string(value) : NULL;
+ char *name, *line;
- value = g_hash_table_lookup(hash, "Name");
- alias = value ? g_value_get_string(value) : NULL;
- } else {
- address = NULL;
- alias = NULL;
- }
-
- if (alias) {
- if (g_strrstr(alias, address))
- name = g_strdup(alias);
- else
- name = g_strdup_printf("%s (%s)", alias, address);
- } else
- name = g_strdup(address);
+ name = get_name_for_display (device);
+ if (name == NULL)
+ return FALSE;
- passkey_dialog(adapter, device, address, name, TRUE, context);
+ passkey_dialog(adapter, device, name, TRUE, context);
if (notification_supports_actions () == FALSE) {
g_free (name);
@@ -625,32 +641,15 @@ static gboolean display_request(DBusGMethodInvocation *context,
DBusGProxy *device, guint passkey,
guint entered, gpointer user_data)
{
+ g_warning ("Not implemented, please file a bug at how this happened");
+ return FALSE;
+#if 0
DBusGProxy *adapter = user_data;
- GHashTable *hash = NULL;
- GValue *value;
- const gchar *address, *alias;
- gchar *name, *line, *text;
-
- device_get_properties(device, &hash, NULL);
+ char *name, *text;
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Address");
- address = value ? g_value_get_string(value) : NULL;
-
- value = g_hash_table_lookup(hash, "Name");
- alias = value ? g_value_get_string(value) : NULL;
- } else {
- address = NULL;
- alias = NULL;
- }
-
- if (alias) {
- if (g_strrstr(alias, address))
- name = g_strdup(alias);
- else
- name = g_strdup_printf("%s (%s)", alias, address);
- } else
- name = g_strdup(address);
+ name = get_name_for_display (device);
+ if (name == NULL)
+ return FALSE;
text = g_strdup_printf("%d", passkey);
display_dialog(adapter, device, address, name, text, entered, context);
@@ -675,40 +674,21 @@ static gboolean display_request(DBusGMethodInvocation *context,
g_free(line);
return TRUE;
+#endif
}
static gboolean confirm_request(DBusGMethodInvocation *context,
DBusGProxy *device, guint passkey, gpointer user_data)
{
DBusGProxy *adapter = user_data;
- GHashTable *hash = NULL;
- GValue *value;
- const gchar *address, *alias;
- gchar *name, *line, *text;
+ char *name, *line, *text;
- device_get_properties(device, &hash, NULL);
-
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Address");
- address = value ? g_value_get_string(value) : NULL;
-
- value = g_hash_table_lookup(hash, "Name");
- alias = value ? g_value_get_string(value) : NULL;
- } else {
- address = NULL;
- alias = NULL;
- }
-
- if (alias) {
- if (g_strrstr(alias, address))
- name = g_strdup(alias);
- else
- name = g_strdup_printf("%s (%s)", alias, address);
- } else
- name = g_strdup(address);
+ name = get_name_for_display (device);
+ if (name == NULL)
+ return FALSE;
text = g_strdup_printf("%d", passkey);
- confirm_dialog(adapter, device, address, name, text, context);
+ confirm_dialog(adapter, device, name, text, context);
g_free(text);
/* translators: this is a popup telling you a particular device
@@ -733,33 +713,13 @@ static gboolean authorize_request(DBusGMethodInvocation *context,
DBusGProxy *device, const char *uuid, gpointer user_data)
{
DBusGProxy *adapter = user_data;
- GHashTable *hash = NULL;
- GValue *value;
- const gchar *address, *alias;
- gchar *name, *line;
+ char *name, *line;
- device_get_properties(device, &hash, NULL);
-
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Address");
- address = value ? g_value_get_string(value) : NULL;
-
- value = g_hash_table_lookup(hash, "Name");
- alias = value ? g_value_get_string(value) : NULL;
- } else {
- address = NULL;
- alias = NULL;
- }
-
- if (alias) {
- if (g_strrstr(alias, address))
- name = g_strdup(alias);
- else
- name = g_strdup_printf("%s (%s)", alias, address);
- } else
- name = g_strdup(address);
+ name = get_name_for_display (device);
+ if (name == NULL)
+ return FALSE;
- auth_dialog(adapter, device, address, name, uuid, context);
+ auth_dialog(adapter, device, name, uuid, context);
if (notification_supports_actions () == FALSE) {
g_free (name);
diff --git a/applet/test-agentdialog.c b/applet/test-agentdialog.c
index 7a40a9b..806a022 100644
--- a/applet/test-agentdialog.c
+++ b/applet/test-agentdialog.c
@@ -64,10 +64,10 @@ int main(int argc, char *argv[])
device = dbus_g_proxy_new_from_proxy(adapter,
"/hci0/dev_11_22_33_44_55_66", "org.bluez.Device");
- //display_dialog(adapter, device, "00:11:22:33:44:55", "Test", "123456", 0, NULL);
- passkey_dialog(adapter, device, "00:11:22:33:44:55", "Test", FALSE, NULL);
- //confirm_dialog(adapter, device, "00:11:22:33:44:55", "Test", "123456", NULL);
- //auth_dialog(adpater, device, "00:11:22:33:44:55", "Test", "UUID", NULL);
+ //display_dialog(adapter, device, "Test (00:11:22:33:44:55)", "123456", 0, NULL);
+ passkey_dialog(adapter, device, "Test (00:11:22:33:44:55)", FALSE, NULL);
+ //confirm_dialog(adapter, device, "Test (00:11:22:33:44:55)", "123456", NULL);
+ //auth_dialog(adpater, device, "Test (00:11:22:33:44:55)", "UUID", NULL);
gtk_main();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]