From e319b07fba9a47a15aae9ef7c85da464b75874ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:02:48 -0600 Subject: Steal the serializable menuitem from IDO --- libdbusmenu-gtk/serializablemenuitem.c | 99 ++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 libdbusmenu-gtk/serializablemenuitem.c (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c new file mode 100644 index 0000000..2c166d8 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -0,0 +1,99 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "idoserializablemenuitem.h" + +struct _IdoSerializableMenuItemPrivate { + int dummy; +}; + +#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) + +static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); +static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); +static void ido_serializable_menu_item_dispose (GObject *object); +static void ido_serializable_menu_item_finalize (GObject *object); + +G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); + +static void +ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + + object_class->dispose = ido_serializable_menu_item_dispose; + object_class->finalize = ido_serializable_menu_item_finalize; + + return; +} + +static void +ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +{ + self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + + self->priv->dummy = 5; + + return; +} + +static void +ido_serializable_menu_item_dispose (GObject *object) +{ + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + return; +} + +static void +ido_serializable_menu_item_finalize (GObject *object) +{ + + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + return; +} + +DbusmenuMenuitem * +ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +{ + g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + + IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + if (klass->get_dbusmenu_menuitem != NULL) { + return klass->get_dbusmenu_menuitem(smi); + } + + return NULL; +} + +void +ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +{ + g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + + gpointer type_class = g_type_class_ref(item_type); + g_return_if_fail(type_class != NULL); + + IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + + if (class->get_type_string == NULL) { + g_type_class_unref(type_class); + g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + return; + } + + /* Register type */ + + + /* Register defaults */ + + + return; +} -- cgit v1.2.3 From 8122074a5e67cf69f147a8b10b31c1fefaf64486 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:32:02 -0600 Subject: Changing namespace from IDO to DBusMenu GTK --- libdbusmenu-gtk/serializablemenuitem.c | 52 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 2c166d8..c9eb416 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -2,39 +2,39 @@ #include "config.h" #endif -#include "idoserializablemenuitem.h" +#include "serializablemenuitem.h" -struct _IdoSerializableMenuItemPrivate { +struct _DbusmenuGtkSerializableMenuItemPrivate { int dummy; }; -#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) -static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); -static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); -static void ido_serializable_menu_item_dispose (GObject *object); -static void ido_serializable_menu_item_finalize (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); +static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); +static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); -G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); +G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); static void -ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + g_type_class_add_private (klass, sizeof (DbusmenuGtkSerializableMenuItemPrivate)); - object_class->dispose = ido_serializable_menu_item_dispose; - object_class->finalize = ido_serializable_menu_item_finalize; + object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; + object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; return; } static void -ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { - self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); self->priv->dummy = 5; @@ -42,30 +42,30 @@ ido_serializable_menu_item_init (IdoSerializableMenuItem *self) } static void -ido_serializable_menu_item_dispose (GObject *object) +dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); return; } static void -ido_serializable_menu_item_finalize (GObject *object) +dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->finalize (object); return; } DbusmenuMenuitem * -ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { - g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); - IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); if (klass->get_dbusmenu_menuitem != NULL) { return klass->get_dbusmenu_menuitem(smi); } @@ -74,18 +74,18 @@ ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) } void -ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { - g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + g_return_if_fail(g_type_is_a(item_type, DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)); gpointer type_class = g_type_class_ref(item_type); g_return_if_fail(type_class != NULL); - IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + DbusmenuGtkSerializableMenuItemClass * class = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(type_class); if (class->get_type_string == NULL) { g_type_class_unref(type_class); - g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + g_error("No 'get_type_string' in subclass of DbusmenuGtkSerializableMenuItem"); return; } -- cgit v1.2.3 From 6ec53854067f149492c18d35d680c2dad01d0a41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:45:44 -0600 Subject: Setting up the type handler, need more API --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index c9eb416..4d23635 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,14 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +/* Handle the type with this item. */ +static gboolean +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + + return TRUE; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -90,10 +98,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - + dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ /* Register defaults */ - + /* TODO: Need API on another branch */ return; } -- cgit v1.2.3 From 61fd5050b6319de6b948cdb0cd36e1b985d7b2a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:02:00 -0600 Subject: Setup to the use the full type handler --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 4d23635..42d79b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -75,12 +75,20 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab /* Handle the type with this item. */ static gboolean -type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { return TRUE; } +/* Destruction is inevitable */ +static void +type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) +{ + + return; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -98,7 +106,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 5d6f408aad06b27f8d29b52df9bd8d76155eabe4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:05:31 -0600 Subject: Build a type handler structure to handle the class struct --- libdbusmenu-gtk/serializablemenuitem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 42d79b2..16b3910 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,12 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +typedef struct _type_handler_t type_handler_t; +struct _type_handler_t { + DbusmenuGtkSerializableMenuItemClass * class; + GType type; +}; + /* Handle the type with this item. */ static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) @@ -85,7 +91,10 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli static void type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) { - + g_return_if_fail(user_data != NULL); + type_handler_t * th = (type_handler_t *)user_data; + g_type_class_unref(th->class); + g_free(user_data); return; } @@ -106,7 +115,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ + type_handler_t * th = g_new0(type_handler_t, 1); + th->class = class; + th->type = item_type; + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 43b377b84c868f652e8ea0db989b985cf20a3304 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:06:28 -0600 Subject: Clean up on failure --- libdbusmenu-gtk/serializablemenuitem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 16b3910..1d4703f 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -118,7 +118,9 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, type_handler_t * th = g_new0(type_handler_t, 1); th->class = class; th->type = item_type; - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ + if (!dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler)) { + type_destroy_handler(client, class->get_type_string(), th); + } /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 4d6b2a232814fc61e7652199a142d5af39c4f78f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 10:52:33 -0600 Subject: License headers --- libdbusmenu-gtk/serializablemenuitem.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 1d4703f..e8ad22b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -- cgit v1.2.3 From c0990d9fa4889042ae255ed1358c0686d5dec241 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 16:50:34 -0600 Subject: Filling out the type handler --- libdbusmenu-gtk/serializablemenuitem.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index e8ad22b..de7bb04 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include "client.h" #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { @@ -111,6 +112,13 @@ struct _type_handler_t { static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { + type_handler_t * th = (type_handler_t *)user_data; + + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); + g_return_val_if_fail(smi != NULL, FALSE); + + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; } -- cgit v1.2.3 From 5dc7f70d50ba5cf9cdc86693e7b759f567fb862c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 17:00:50 -0600 Subject: Adding a function to tell the menu item about where it's properties are coming from. --- libdbusmenu-gtk/serializablemenuitem.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index de7bb04..74e0bec 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -163,3 +163,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } + +void +dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +{ + + return; +} -- cgit v1.2.3 From abe1a8b281bf08217367666fbac41eb812708d33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 19:56:14 -0600 Subject: Switching the name to build so that we realize what's going on there. --- libdbusmenu-gtk/serializablemenuitem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 74e0bec..32be773 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -90,13 +90,13 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) } DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); - if (klass->get_dbusmenu_menuitem != NULL) { - return klass->get_dbusmenu_menuitem(smi); + if (klass->build_dbusmenu_menuitem != NULL) { + return klass->build_dbusmenu_menuitem(smi); } return NULL; -- cgit v1.2.3 From aea42d14c645517cc32611ab0e8580223948aad3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 20:09:39 -0600 Subject: Installing a property for the menuitem in the super-class --- libdbusmenu-gtk/serializablemenuitem.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 32be773..5089af0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -34,7 +34,13 @@ License version 3 and version 2.1 along with this program. If not, see #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { - int dummy; + DbusmenuMenuitem * mi; +}; + +/* Properties */ +enum { + PROP_0, + PROP_MENUITEM }; #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ @@ -57,6 +63,12 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + g_object_class_install_property (object_class, PROP_MENUITEM, + g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", + "A menuitem who's properties are being watched and where changes should be watched for updates. It is the responsibility of subclasses to set up the signal handlers for those property changes.", + DBUSMENU_TYPE_MENUITEM, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + return; } @@ -65,7 +77,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); - self->priv->dummy = 5; + self->priv->mi = NULL; return; } @@ -73,6 +85,13 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(object); + g_return_if_fail(smi != NULL); + + if (smi->priv->mi != NULL) { + g_object_unref(G_OBJECT(smi->priv->mi)); + smi->priv->mi = NULL; + } G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); -- cgit v1.2.3 From efd5c63d09eed1230bb0bb822f3040f55d30638d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:01:20 -0600 Subject: More documentation --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 5089af0..01b20b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -33,6 +33,10 @@ License version 3 and version 2.1 along with this program. If not, see #include "client.h" #include "serializablemenuitem.h" +/** + DbusmenuGtkSerializableMenuItemPrivate: + @mi: Menuitem to watch the property changes from +*/ struct _DbusmenuGtkSerializableMenuItemPrivate { DbusmenuMenuitem * mi; }; @@ -43,16 +47,20 @@ enum { PROP_MENUITEM }; +/* Private macro, only used in object init */ #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) +/* Function prototypes */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +/* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); +/* Initialize the stuff in the class structure */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { @@ -72,6 +80,7 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC return; } +/* Initialize the object structures and private structure */ static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { @@ -82,6 +91,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) return; } +/* Free all references to objects */ static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { @@ -98,6 +108,7 @@ dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) return; } +/* Free memory */ static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { @@ -121,6 +132,7 @@ dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializ return NULL; } +/* Callback to the generic type handler */ typedef struct _type_handler_t type_handler_t; struct _type_handler_t { DbusmenuGtkSerializableMenuItemClass * class; -- cgit v1.2.3 From 91544bb4a5ae2bc6eea3e930da6c7ebbb32216d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:37:44 -0600 Subject: gtk-doc documentation for public API functions --- libdbusmenu-gtk/serializablemenuitem.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 01b20b2..06dfa59 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -119,6 +119,19 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/** + dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring + + This function is for menu items that are instanciated from + GTK and have their properites set using GTK functions. This + builds a #DbusmenuMenuitem that then has the properties that + should be sent over the bus to create a new item of this + type on the other side. + + Return value: A #DbusmenuMenuitem who's values will be set by + this object. +*/ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { @@ -165,6 +178,16 @@ type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user return; } +/** + dbusmenu_gtk_serializable_menu_item_register_to_client: + @client: #DbusmenuClient that we should register a type at. + @item_type: The #GType of a class that is a subclass of #DbusmenuGtkSerializableMenuItem + + Registers a generic handler for dealing with all subclasses of + #DbusmenuGtkSerializableMenuItem. This handler responds to the callback, + creates a new object and attaches it to the appropriate #DbusmenuMenuitem + object. +*/ void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -195,6 +218,17 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } +/** + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of + @mi: Menuitem to get the properties from + + This function is used on the server side to signal to the object + that it should get its' property change events from @mi instead + of expecting calls to its' API. A call to this function sets the + property and subclasses should listen to the notify signal to + pick up this property being set. +*/ void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { -- cgit v1.2.3 From 97083dc0b396d91c68fe9f439024cc048333e87b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:43:44 -0600 Subject: Adding in set and get property functions. --- libdbusmenu-gtk/serializablemenuitem.c | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 06dfa59..99bc585 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -56,6 +56,14 @@ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializa static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +static void set_property (GObject * obj, + guint id, + const GValue * value, + GParamSpec * pspec); +static void get_property (GObject * obj, + guint id, + GValue * value, + GParamSpec * pspec); /* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); @@ -70,6 +78,8 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + object_class->set_property = set_property; + object_class->get_property = get_property; g_object_class_install_property (object_class, PROP_MENUITEM, g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", @@ -119,6 +129,42 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/* Set an object property */ +static void +set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + smi->priv->mi = g_value_get_object(value); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + +/* Get an object property */ +static void +get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + g_value_set_object(value, smi->priv->mi); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + /** dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring -- cgit v1.2.3 From 555f085168fac50cf55c910c746363f8ce268823 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:46:27 -0600 Subject: Fleshing out setting the property --- libdbusmenu-gtk/serializablemenuitem.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 99bc585..6bc3695 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -278,6 +278,11 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { + g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); + g_return_if_fail(mi != NULL); + + smi->priv->mi = mi; + g_object_notify(G_OBJECT(smi), DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM); return; } -- cgit v1.2.3 From edef8613dd3e78e5d11a2754e6175dd8e55ff87e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:59:35 -0600 Subject: Adding a transfer annotation --- libdbusmenu-gtk/serializablemenuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk/serializablemenuitem.c') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 6bc3695..f67434e 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -175,8 +175,8 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) should be sent over the bus to create a new item of this type on the other side. - Return value: A #DbusmenuMenuitem who's values will be set by - this object. + Return value: (transfer full) A #DbusmenuMenuitem who's values will be + set by this object. */ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) -- cgit v1.2.3