diff options
author | Ted Gould <ted@canonical.com> | 2009-04-16 12:39:26 -0500 |
---|---|---|
committer | Ted Gould <ted@canonical.com> | 2009-04-16 12:39:26 -0500 |
commit | 67dfe0a32531fccc566dba9079673009d6c7f5c1 (patch) | |
tree | 5c570c92c51dd1308aba6a4ee04166525daed9c7 | |
parent | 4d73ec986ea8f7bcdceac7dcfd2ffefcd0c63e7f (diff) | |
download | libdbusmenu-67dfe0a32531fccc566dba9079673009d6c7f5c1.tar.gz libdbusmenu-67dfe0a32531fccc566dba9079673009d6c7f5c1.tar.bz2 libdbusmenu-67dfe0a32531fccc566dba9079673009d6c7f5c1.zip |
Okay, now we're getting and setting properties. Fleshing out these functions.
-rw-r--r-- | libdbusmenu-glib/menuitem.h | 2 | ||||
-rw-r--r-- | libdbusmenu-glib/server.c | 51 |
2 files changed, 51 insertions, 2 deletions
diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index e5d2b92..a820d4b 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -54,6 +54,8 @@ gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * pr const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property); gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property); +void dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray ** array); + G_END_DECLS #endif diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index ef24c86..70a1482 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -115,6 +115,7 @@ dbusmenu_server_init (DbusmenuServer *self) DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(self); priv->root = NULL; + priv->dbusobject = NULL; return; } @@ -136,13 +137,30 @@ dbusmenu_server_finalize (GObject *object) static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) { + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(obj); + switch (id) { case PROP_DBUS_OBJECT: + g_return_if_fail(priv->dbusobject == NULL); + priv->dbusobject = g_value_dup_string(value); + DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + dbus_g_connection_register_g_object(connection, + priv->dbusobject, + obj); break; case PROP_ROOT_NODE: + if (priv->root != NULL) { + g_object_unref(G_OBJECT(priv->root)); + priv->root = NULL; + } + priv->root = DBUSMENU_MENUITEM(g_value_get_pointer(value)); + if (priv->root != NULL) { + g_object_ref(G_OBJECT(priv->root)); + } break; case PROP_LAYOUT: - break; + /* Can't set this, fall through to error */ + g_warning("Can not set property: layout"); default: g_return_if_reached(); break; @@ -152,15 +170,44 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) } static void +xmlarray_foreach_free (gpointer arrayentry, gpointer userdata) +{ + if (arrayentry != NULL) { + g_free(arrayentry); + } + + return; +} + +static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) { + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(obj); + switch (id) { case PROP_DBUS_OBJECT: + g_value_set_string(value, priv->dbusobject); break; case PROP_ROOT_NODE: + g_value_set_pointer(value, priv->root); break; - case PROP_LAYOUT: + case PROP_LAYOUT: { + GPtrArray * xmlarray = g_ptr_array_new(); + g_ptr_array_add(xmlarray, g_strdup("<menu>")); + if (priv->root != NULL) { + dbusmenu_menuitem_buildxml(priv->root, &xmlarray); + } + g_ptr_array_add(xmlarray, g_strdup("</menu>")); + g_ptr_array_add(xmlarray, NULL); + + /* build string */ + gchar * finalstring = g_strjoinv("\n", (gchar **)xmlarray->pdata); + g_value_take_string(value, finalstring); + + g_ptr_array_foreach(xmlarray, xmlarray_foreach_free, NULL); + g_ptr_array_free(xmlarray, TRUE); break; + } default: g_return_if_reached(); break; |