From 0c7ae9d686674986e1a5304dde25aa9e92010bd6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 26 Apr 2011 21:39:06 -0500 Subject: Dropping the serializable menu item. Not a bad idea, but we can do better. --- libdbusmenu-gtk/Makefile.am | 7 +- libdbusmenu-gtk/dbusmenu-gtk.h | 1 - libdbusmenu-gtk/parser.c | 9 +- libdbusmenu-gtk/serializablemenuitem.c | 288 --------------------------------- libdbusmenu-gtk/serializablemenuitem.h | 133 --------------- 5 files changed, 3 insertions(+), 435 deletions(-) delete mode 100644 libdbusmenu-gtk/serializablemenuitem.c delete mode 100644 libdbusmenu-gtk/serializablemenuitem.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index aa36445..9a979d7 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -24,8 +24,7 @@ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ menuitem.h \ - parser.h \ - serializablemenuitem.h + parser.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -37,9 +36,7 @@ libdbusmenu_gtk_la_SOURCES = \ menuitem.h \ menuitem.c \ parser.h \ - parser.c \ - serializablemenuitem.h \ - serializablemenuitem.c + parser.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h index f2fe5be..de63c61 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk.h +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -36,6 +36,5 @@ License version 3 and version 2.1 along with this program. If not, see #include #include #include -#include #endif /* __DBUSMENU_GLIB_H__ */ diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4708a64..a304511 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -28,7 +28,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" -#include "serializablemenuitem.h" +#include "client.h" #define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" #define PARSER_DATA "dbusmenu-gtk-parser-data" @@ -473,13 +473,6 @@ sanitize_label (GtkLabel * label) static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget) { - /* If it's a subclass of our serializable menu item then we can - use its own build function */ - if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { - DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); - return dbusmenu_gtk_serializable_menu_item_build_menuitem(smi); - } - /* If it's a standard GTK Menu Item we need to do some of our own work */ if (GTK_IS_MENU_ITEM (widget)) { diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c deleted file mode 100644 index b560fe3..0000000 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ /dev/null @@ -1,288 +0,0 @@ -/* -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 - -#include "client.h" -#include "serializablemenuitem.h" - -/* - DbusmenuGtkSerializableMenuItemPrivate: - @mi: Menuitem to watch the property changes from -*/ -struct _DbusmenuGtkSerializableMenuItemPrivate { - DbusmenuMenuitem * mi; -}; - -/* Properties */ -enum { - PROP_0, - 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); -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); - -/* Initialize the stuff in the class structure */ -static void -dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (DbusmenuGtkSerializableMenuItemPrivate)); - - 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", - "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; -} - -/* Initialize the object structures and private structure */ -static void -dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) -{ - self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); - - self->priv->mi = NULL; - - return; -} - -/* Free all references to objects */ -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); - return; -} - -/* Free memory */ -static void -dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) -{ - - - - G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->finalize (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_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: (transfer full): A #DbusmenuMenuitem who's values will be - * set by this object. - */ -DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_build_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->build_dbusmenu_menuitem != NULL) { - return klass->build_dbusmenu_menuitem(smi); - } - - return NULL; -} - -/* Callback to the generic type handler */ -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) -{ - 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_menuitem(smi, newitem); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); - - return TRUE; -} - -/* Destruction is inevitable */ -static void -type_destroy_handler (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; -} - -/** - * 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) -{ - 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); - - 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 DbusmenuGtkSerializableMenuItem"); - return; - } - - /* Register type */ - type_handler_t * th = g_new0(type_handler_t, 1); - th->class = class; - th->type = item_type; - if (!dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler)) { - type_destroy_handler(th); - } - - /* Register defaults */ - /* TODO: Need API on another branch */ - - return; -} - -/** - * dbusmenu_gtk_serializable_menu_item_set_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_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; -} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h deleted file mode 100644 index 9bea89f..0000000 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -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 - -*/ - -#ifndef DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ 1 - -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM (dbusmenu_gtk_serializable_menu_item_get_type ()) -#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItem)) -#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) -#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) -#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) -#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) - -/** - * DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM: - * - * String to access property #DbusmenuGtkSerializableMenuItem:dbusmenu-menuitem - */ -#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM "dbusmenu-menuitem" - -typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; -typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; -typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; - -/** - DbusmenuGtkSerializableMenuItemClass: - @parent_class: Inherit from GtkMenuItem - @get_type_string: Static function to get a string describing this type - @get_default_properties: Return a hashtable of defaults for the menu item type - @build_dbusmenu_menuitem: Build a menuitem that can be sent over dbus - @_dbusmenu_gtk_serializable_menu_item_reserved1: Reserved for future use. - @_dbusmenu_gtk_serializable_menu_item_reserved2: Reserved for future use. - @_dbusmenu_gtk_serializable_menu_item_reserved3: Reserved for future use. - @_dbusmenu_gtk_serializable_menu_item_reserved4: Reserved for future use. - @_dbusmenu_gtk_serializable_menu_item_reserved5: Reserved for future use. - @_dbusmenu_gtk_serializable_menu_item_reserved6: Reserved for future use. - - Signals and functions for #DbusmenuGtkSerializableMenuItem. -*/ -struct _DbusmenuGtkSerializableMenuItemClass { - GtkMenuItemClass parent_class; - - /* Subclassable functions */ - const gchar * (*get_type_string) (void); - GHashTable * (*get_default_properties) (void); - - DbusmenuMenuitem * (*build_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); - - /* Signals */ - - - - /* Empty Space */ - /*< Private >*/ - void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); - void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); - void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); - void (*_dbusmenu_gtk_serializable_menu_item_reserved4) (void); - void (*_dbusmenu_gtk_serializable_menu_item_reserved5) (void); - void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); -}; - -/** - DbusmenuGtkSerializableMenuItem: - @parent: Inherit from GtkMenuItem - @priv: Blind structure of private variables - - The Serializable Menuitem provides a way for menu items to be created - that can easily be picked up by the Dbusmenu GTK Parser. This way - you can create custom items, and transport them across dbusmenu to - your menus or the appmenu on the other side of the bus. By providing - these function the parser has enough information to both serialize, and - deserialize on the other side, the menuitem you've so carefully created. -*/ -struct _DbusmenuGtkSerializableMenuItem { - GtkMenuItem parent; - - DbusmenuGtkSerializableMenuItemPrivate * priv; -}; - -GType dbusmenu_gtk_serializable_menu_item_get_type (void); - -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi); -void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); -void dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); - -/** - SECTION:serializablemenuitem - @short_description: A way to build #GtkMenuItems that can be sent over Dbusmenu - @stability: Unstable - @include: libdbusmenu-gtk/serializablemenuitem.h - - Menuitems can subclass from this instead of #GtkMenuItem and - by providing the appropriate functions Dbusmenu will be able - to parse them and send them over the bus. -*/ - -G_END_DECLS - -#endif -- cgit v1.2.3