From 614606a905667c45ab851dc13ec683250b866333 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 11:46:51 -0600 Subject: Stripping out the symbols for the old stuff, and going with the new of just getting a type. --- libindicator/indicator.h | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/libindicator/indicator.h b/libindicator/indicator.h index 85fe2e9..9aab6c4 100644 --- a/libindicator/indicator.h +++ b/libindicator/indicator.h @@ -25,31 +25,13 @@ License along with this library. If not, see #include -#define INDICATOR_GET_LABEL_S "get_label" -typedef GtkLabel * (*get_label_t)(void); -GtkLabel * get_label (void); - -#define INDICATOR_GET_ICON_S "get_icon" -typedef GtkImage * (*get_icon_t) (void); -GtkImage * get_icon (void); - -#define INDICATOR_GET_MENU_S "get_menu" -typedef GtkMenu * (*get_menu_t) (void); -GtkMenu * get_menu (void); - -#define INDICATOR_GET_VERSION_S "get_version" -typedef gchar * (*get_version_t) (void); -gchar * get_version (void); - -#define INDICATOR_VERSION "0.2.0" +#define INDICATOR_VERSION "0.3.0" #define INDICATOR_SET_VERSION gchar * get_version(void) { return INDICATOR_VERSION; } #define INDICATOR_VERSION_CHECK(x) (!g_strcmp0(x, INDICATOR_VERSION)) -#define INDICATOR_GET_NAME_S "get_name" -typedef gchar * (*get_name_t) (void); -gchar * get_name (void); -#define INDICATOR_SET_NAME(x) gchar * get_name(void) {return (x); } - +#define INDICATOR_GET_NAME_S "get_type" +typedef GType (*get_type_t) (void); +GType get_type (void); #endif /* __LIBINDICATOR_INDICATOR_H_SEEN__ */ -- cgit v1.2.3 From aaacaacde502d2593108db0a5bf4182b9552ce4d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 11:52:16 -0600 Subject: Adding in the basis for the instance class. --- .bzrignore | 1 + libindicator/Makefile.am | 2 ++ libindicator/indicator-instance.c | 26 ++++++++++++++++++++++++++ libindicator/indicator-instance.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 libindicator/indicator-instance.c create mode 100644 libindicator/indicator-instance.h diff --git a/.bzrignore b/.bzrignore index e81c2cd..e9dc59e 100644 --- a/.bzrignore +++ b/.bzrignore @@ -117,3 +117,4 @@ tests/libdummy-indicator-blank.la tests/libdummy_indicator_blank_la-dummy-indicator-blank.lo libindicator-[0-9].[0-9].[0-9].tar.gz libindicator-[0-9].[0-9].[0-9].tar.gz.asc +libindicator/libindicator_la-indicator-instance.lo diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index db45f3c..38b6498 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -5,6 +5,7 @@ libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator indicator_headers = \ indicator.h \ + indicator-instance.h \ indicator-object.h libindicatorinclude_HEADERS = \ @@ -15,6 +16,7 @@ lib_LTLIBRARIES = \ libindicator_la_SOURCES = \ $(indicator_headers) \ + indicator-instance.c \ indicator-object.c libindicator_la_CFLAGS = \ diff --git a/libindicator/indicator-instance.c b/libindicator/indicator-instance.c new file mode 100644 index 0000000..b205c53 --- /dev/null +++ b/libindicator/indicator-instance.c @@ -0,0 +1,26 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "indicator-instance.h" + +static void indicator_instance_class_init (IndicatorInstanceClass *klass); +static void indicator_instance_init (IndicatorInstance *self); + +G_DEFINE_TYPE (IndicatorInstance, indicator_instance, G_TYPE_OBJECT); + +static void +indicator_instance_class_init (IndicatorInstanceClass *klass) +{ + + return; +} + +static void +indicator_instance_init (IndicatorInstance *self) +{ + /* No Data for this Class */ + + return; +} + diff --git a/libindicator/indicator-instance.h b/libindicator/indicator-instance.h new file mode 100644 index 0000000..c83b01e --- /dev/null +++ b/libindicator/indicator-instance.h @@ -0,0 +1,31 @@ +#ifndef __INDICATOR_INSTANCE_H__ +#define __INDICATOR_INSTANCE_H__ + +#include +#include + +G_BEGIN_DECLS + +#define INDICATOR_INSTANCE_TYPE (indicator_instance_get_type ()) +#define INDICATOR_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_INSTANCE_TYPE, IndicatorInstance)) +#define INDICATOR_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_INSTANCE_TYPE, IndicatorInstanceClass)) +#define INDICATOR_IS_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_INSTANCE_TYPE)) +#define INDICATOR_IS_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_INSTANCE_TYPE)) +#define INDICATOR_INSTANCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_INSTANCE_TYPE, IndicatorInstanceClass)) + +typedef struct _IndicatorInstance IndicatorInstance; +typedef struct _IndicatorInstanceClass IndicatorInstanceClass; + +struct _IndicatorInstanceClass { + GObjectClass parent_class; +}; + +struct _IndicatorInstance { + GObject parent; +}; + +GType indicator_instance_get_type (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 6935a6b06c356e2e71dd94acfb894893f8040df1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 11:54:09 -0600 Subject: Switching to a set_type function instead of making people do that themselves. --- libindicator/indicator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicator/indicator.h b/libindicator/indicator.h index 9aab6c4..31ce0f6 100644 --- a/libindicator/indicator.h +++ b/libindicator/indicator.h @@ -31,7 +31,7 @@ License along with this library. If not, see #define INDICATOR_GET_NAME_S "get_type" typedef GType (*get_type_t) (void); -GType get_type (void); +#define INDICATOR_SET_TYPE(x) GType get_type (void) { return x; } #endif /* __LIBINDICATOR_INDICATOR_H_SEEN__ */ -- cgit v1.2.3 From e2ce2dd0c4f34c806c371d9595ce01390b11785a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 13:03:50 -0600 Subject: Removing the instance object. I think that we can do everything we need by using the object. --- libindicator/Makefile.am | 2 -- libindicator/indicator-instance.c | 26 -------------------------- libindicator/indicator-instance.h | 31 ------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 libindicator/indicator-instance.c delete mode 100644 libindicator/indicator-instance.h diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 38b6498..db45f3c 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -5,7 +5,6 @@ libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator indicator_headers = \ indicator.h \ - indicator-instance.h \ indicator-object.h libindicatorinclude_HEADERS = \ @@ -16,7 +15,6 @@ lib_LTLIBRARIES = \ libindicator_la_SOURCES = \ $(indicator_headers) \ - indicator-instance.c \ indicator-object.c libindicator_la_CFLAGS = \ diff --git a/libindicator/indicator-instance.c b/libindicator/indicator-instance.c deleted file mode 100644 index b205c53..0000000 --- a/libindicator/indicator-instance.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "indicator-instance.h" - -static void indicator_instance_class_init (IndicatorInstanceClass *klass); -static void indicator_instance_init (IndicatorInstance *self); - -G_DEFINE_TYPE (IndicatorInstance, indicator_instance, G_TYPE_OBJECT); - -static void -indicator_instance_class_init (IndicatorInstanceClass *klass) -{ - - return; -} - -static void -indicator_instance_init (IndicatorInstance *self) -{ - /* No Data for this Class */ - - return; -} - diff --git a/libindicator/indicator-instance.h b/libindicator/indicator-instance.h deleted file mode 100644 index c83b01e..0000000 --- a/libindicator/indicator-instance.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __INDICATOR_INSTANCE_H__ -#define __INDICATOR_INSTANCE_H__ - -#include -#include - -G_BEGIN_DECLS - -#define INDICATOR_INSTANCE_TYPE (indicator_instance_get_type ()) -#define INDICATOR_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_INSTANCE_TYPE, IndicatorInstance)) -#define INDICATOR_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_INSTANCE_TYPE, IndicatorInstanceClass)) -#define INDICATOR_IS_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_INSTANCE_TYPE)) -#define INDICATOR_IS_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_INSTANCE_TYPE)) -#define INDICATOR_INSTANCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_INSTANCE_TYPE, IndicatorInstanceClass)) - -typedef struct _IndicatorInstance IndicatorInstance; -typedef struct _IndicatorInstanceClass IndicatorInstanceClass; - -struct _IndicatorInstanceClass { - GObjectClass parent_class; -}; - -struct _IndicatorInstance { - GObject parent; -}; - -GType indicator_instance_get_type (void); - -G_END_DECLS - -#endif -- cgit v1.2.3 From 0575b91145b07ecc7fc861bcb8648296fbd74bb4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 13:19:25 -0600 Subject: Redefining the interface. Now this object should get subclassed by folks. --- libindicator/indicator-object.h | 71 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index fa6373d..6637f05 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -36,25 +36,82 @@ G_BEGIN_DECLS #define IS_INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) -typedef struct _IndicatorObject IndicatorObject; -typedef struct _IndicatorObjectClass IndicatorObjectClass; - +typedef struct _IndicatorObject IndicatorObject; +typedef struct _IndicatorObjectClass IndicatorObjectClass; +typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; +typedef struct _IndicatorObjectEntry IndicatorObjectEntry; + +/** + IndicatorObjectClass: + @parent_class: #GObjectClass + @get_label: Gets the label for this object. Should be set + to #NULL if @get_entries is set. Should NOT ref the + object. + @get_image: Gets the image for this object. Should be set + to #NULL if @get_entries is set. Should NOT ref the + object. + @get_menu: Gets the image for this object. Should be set + to #NULL if @get_entries is set. Should NOT ref the + object. + @get_entires: Gets all of the entires for this object returning + a #GList of #IndicatorObjectEntries. The list should be + under the ownership of the caller but the entires will + not be. + @entry_added: Slot for #IndicatorObject::entry-added + @entry_removed: Slot for #IndicatorObject::entry-removed + @indicator_object_reserved_1: Reserved for future use + @indicator_object_reserved_2: Reserved for future use + @indicator_object_reserved_3: Reserved for future use + @indicator_object_reserved_4: Reserved for future use +*/ struct _IndicatorObjectClass { GObjectClass parent_class; - + + /* Virtual Functions */ + GtkLabel * get_label (IndicatorObject * io); + GtkImage * get_image (IndicatorObject * io); + GtkMenu * get_menu (IndicatorObject * io); + + GList * get_entries (IndicatorObject * io); + + /* Signals */ + void entry_added (IndicatorObject * io, IndicatorEntry * entry, gpointer user_data); + void entry_removed (IndicatorObject * io, IndicatorEntry * entry, gpointer user_data); + + /* Reserved */ + void (* indicator_object_reserved_1) (void); + void (* indicator_object_reserved_2) (void); + void (* indicator_object_reserved_3) (void); + void (* indicator_object_reserved_4) (void); }; +/** + IndicatorObject: + @parent: #GObject + @priv: A cached reference to the private data for the + instance. +*/ struct _IndicatorObject { GObject parent; + IndicatorObjectPrivate * priv; +}; +/** + IndicatorObjectEntry: + @label: The label to be shown on the panel + @image: The image to be shown on the panel + @menu: The menu to be added to the menubar +*/ +struct _IndicatorObjectEntry { + GtkLabel * label; + GtkImage * image; + GtkMenu * menu; }; GType indicator_object_get_type (void); IndicatorObject * indicator_object_new_from_file (const gchar * file); -GtkLabel * indicator_object_get_label (IndicatorObject * io); -GtkImage * indicator_object_get_icon (IndicatorObject * io); -GtkMenu * indicator_object_get_menu (IndicatorObject * io); +GList * indicator_object_get_entries (IndicatorObject * io); G_END_DECLS -- cgit v1.2.3 From ed409d4cb434272e2ec0110305d53a06735b00c4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 13:40:10 -0600 Subject: Whew, blew up the interface and built it back again. --- libindicator/indicator-object.c | 171 ++++++++++------------------------------ libindicator/indicator-object.h | 16 ++-- libindicator/indicator.h | 6 +- 3 files changed, 54 insertions(+), 139 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 72cea9d..d9d6d8e 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -30,21 +30,16 @@ License along with this library. If not, see /** IndicatorObjectPrivate: - @label: The label representing this indicator or #NULL if none. - @icon: The icon representing this indicator or #NULL if none. - @menu: The menu representing this indicator or #NULL if none. + @module: The loaded module representing the object. Note to + subclasses: This will not be set when you're initalized. Private data for the object. */ -typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { - GtkLabel * label; - GtkImage * icon; - GtkMenu * menu; + GModule * module; }; -#define INDICATOR_OBJECT_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_OBJECT_TYPE, IndicatorObjectPrivate)) +#define INDICATOR_OBJECT_GET_PRIVATE(o) (INDICATOR_OBJECT(o)->priv) static void indicator_object_class_init (IndicatorObjectClass *klass); static void indicator_object_init (IndicatorObject *self); @@ -65,6 +60,10 @@ indicator_object_class_init (IndicatorObjectClass *klass) object_class->dispose = indicator_object_dispose; object_class->finalize = indicator_object_finalize; + klass->get_label = NULL; + klass->get_menu = NULL; + klass->get_image = NULL; + return; } @@ -72,11 +71,9 @@ indicator_object_class_init (IndicatorObjectClass *klass) static void indicator_object_init (IndicatorObject *self) { - IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(self); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_OBJECT_TYPE, IndicatorObjectPrivate); - priv->label = NULL; - priv->icon = NULL; - priv->menu = NULL; + self->priv->module = NULL; return; } @@ -87,19 +84,9 @@ indicator_object_dispose (GObject *object) { IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); - if (priv->label != NULL) { - g_object_unref(priv->label); - priv->label = NULL; - } - - if (priv->icon != NULL) { - g_object_unref(priv->icon); - priv->icon = NULL; - } - - if (priv->menu != NULL) { - g_object_unref(priv->menu); - priv->menu = NULL; + if (priv->module != NULL) { + g_object_unref(priv->module); + priv->module = NULL; } G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); @@ -129,6 +116,9 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { + GObject * object = NULL; + GModule * module = NULL; + /* Check to make sure the name exists and that the file itself exists */ if (file == NULL) { @@ -143,8 +133,8 @@ indicator_object_new_from_file (const gchar * file) /* Grab the g_module reference, pull it in but let's keep the symbols local to avoid conflicts. */ - GModule * module = g_module_open(file, - G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); + module = g_module_open(file, + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if(module == NULL) { g_warning("Unable to load module: %s", file); return NULL; @@ -164,126 +154,47 @@ indicator_object_new_from_file (const gchar * file) return NULL; } - /* A this point we allocate the object, any code beyond - here needs to deallocate it if we're returning in an - error'd state. */ - GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); - IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); - /* The function for grabbing a label from the module execute it, and make sure everything is a-okay */ - get_label_t lget_label = NULL; - if (!g_module_symbol(module, INDICATOR_GET_LABEL_S, (gpointer *)(&lget_label))) { - g_warning("Unable to get '" INDICATOR_GET_LABEL_S "' symbol from module: %s", file); + get_type_t lget_type = NULL; + if (!g_module_symbol(module, INDICATOR_GET_TYPE_S, (gpointer *)(&lget_type))) { + g_warning("Unable to get '" INDICATOR_GET_TYPE_S "' symbol from module: %s", file); goto unrefandout; } - if (lget_label == NULL) { - g_warning("Symbol '" INDICATOR_GET_LABEL_S "' is (null) in module: %s", file); + if (lget_type == NULL) { + g_warning("Symbol '" INDICATOR_GET_TYPE_S "' is (null) in module: %s", file); goto unrefandout; } - priv->label = lget_label(); - if (priv->label) { - g_object_ref(G_OBJECT(priv->label)); - } - /* The function for grabbing an icon from the module - execute it, and make sure everything is a-okay */ - get_icon_t lget_icon = NULL; - if (!g_module_symbol(module, INDICATOR_GET_ICON_S, (gpointer *)(&lget_icon))) { - g_warning("Unable to get '" INDICATOR_GET_ICON_S "' symbol from module: %s", file); - goto unrefandout; - } - if (lget_icon == NULL) { - g_warning("Symbol '" INDICATOR_GET_ICON_S "' is (null) in module: %s", file); - goto unrefandout; - } - priv->icon = lget_icon(); - if (priv->icon) { - g_object_ref(G_OBJECT(priv->icon)); - } - - /* The function for grabbing a menu from the module - execute it, and make sure everything is a-okay */ - get_menu_t lget_menu = NULL; - if (!g_module_symbol(module, INDICATOR_GET_MENU_S, (gpointer *)(&lget_menu))) { - g_warning("Unable to get '" INDICATOR_GET_MENU_S "' symbol from module: %s", file); + /* A this point we allocate the object, any code beyond + here needs to deallocate it if we're returning in an + error'd state. */ + object = g_object_new(lget_type(), NULL); + if (object == NULL) { + g_warning("Unable to build an object if type '%d' in module: %s", lget_type(), file); goto unrefandout; } - if (lget_menu == NULL) { - g_warning("Symbol '" INDICATOR_GET_MENU_S "' is (null) in module: %s", file); + if (!INDICATOR_IS_OBJECT(object)) { + g_warning("Type '%d' in file %s is not a subclass of IndicatorObject.", lget_type(), file); goto unrefandout; } - priv->menu = lget_menu(); - if (priv->menu) { - g_object_ref(G_OBJECT(priv->menu)); - } - if (priv->label == NULL && priv->icon == NULL) { - /* This is the case where there is nothing to display, - kinda odd that we'd have a module with nothing. */ - g_warning("No label or icon. Odd."); - goto unrefandout; - } + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); + /* Now we can track the module */ + priv->module = module; return INDICATOR_OBJECT(object); /* Error, let's drop the object and return NULL. Sad when this happens. */ unrefandout: - g_object_unref(object); + if (object != NULL) { + g_object_unref(object); + } + if (module != NULL) { + g_object_unref(module); + } + g_warning("Error building IndicatorObject from file: %s", file); return NULL; } -/** - indicator_object_get_label: - @io: An #IndicatorObject. - - A function to get the label for a particular object. This - function does not increase the refcount. That's your job - if you want to do it. - - Return value: A #GtkLabel or #NULL if unavailable. -*/ -GtkLabel * -indicator_object_get_label (IndicatorObject * io) -{ - g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); - IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); - return priv->label; -} - -/** - indicator_object_get_icon: - @io: An #IndicatorObject. - - A function to get the icon for a particular object. This - function does not increase the refcount. That's your job - if you want to do it. - - Return value: A #GtkImage or #NULL if unavailable. -*/ -GtkImage * -indicator_object_get_icon (IndicatorObject * io) -{ - g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); - IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); - return priv->icon; -} - -/** - indicator_object_get_menu: - @io: An #IndicatorObject. - - A function to get the menu for a particular object. This - function does not increase the refcount. That's your job - if you want to do it. - - Return value: A #GtkMenu or #NULL if unavailable. -*/ -GtkMenu * -indicator_object_get_menu (IndicatorObject * io) -{ - g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); - IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); - return priv->menu; -} diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index 6637f05..cd8cc79 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -32,8 +32,8 @@ G_BEGIN_DECLS #define INDICATOR_OBJECT_TYPE (indicator_object_get_type ()) #define INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_OBJECT_TYPE, IndicatorObject)) #define INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) -#define IS_INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_OBJECT_TYPE)) -#define IS_INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) +#define INDICATOR_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_OBJECT_TYPE)) +#define INDICATOR_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) typedef struct _IndicatorObject IndicatorObject; @@ -68,15 +68,15 @@ struct _IndicatorObjectClass { GObjectClass parent_class; /* Virtual Functions */ - GtkLabel * get_label (IndicatorObject * io); - GtkImage * get_image (IndicatorObject * io); - GtkMenu * get_menu (IndicatorObject * io); + GtkLabel * (*get_label) (IndicatorObject * io); + GtkImage * (*get_image) (IndicatorObject * io); + GtkMenu * (*get_menu) (IndicatorObject * io); - GList * get_entries (IndicatorObject * io); + GList * (*get_entries) (IndicatorObject * io); /* Signals */ - void entry_added (IndicatorObject * io, IndicatorEntry * entry, gpointer user_data); - void entry_removed (IndicatorObject * io, IndicatorEntry * entry, gpointer user_data); + void (*entry_added) (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); + void (*entry_removed) (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); /* Reserved */ void (* indicator_object_reserved_1) (void); diff --git a/libindicator/indicator.h b/libindicator/indicator.h index 31ce0f6..8bff270 100644 --- a/libindicator/indicator.h +++ b/libindicator/indicator.h @@ -25,11 +25,15 @@ License along with this library. If not, see #include +#define INDICATOR_GET_VERSION_S "get_version" +typedef gchar * (*get_version_t) (void); +gchar * get_version (void); + #define INDICATOR_VERSION "0.3.0" #define INDICATOR_SET_VERSION gchar * get_version(void) { return INDICATOR_VERSION; } #define INDICATOR_VERSION_CHECK(x) (!g_strcmp0(x, INDICATOR_VERSION)) -#define INDICATOR_GET_NAME_S "get_type" +#define INDICATOR_GET_TYPE_S "get_type" typedef GType (*get_type_t) (void); #define INDICATOR_SET_TYPE(x) GType get_type (void) { return x; } -- cgit v1.2.3 From 78868a0db98b9f2dc9a52b5f104f6f76a5dae549 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 14:00:08 -0600 Subject: Adding in a default handler for get_entries. --- libindicator/indicator-object.c | 66 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index d9d6d8e..8c683da 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -32,11 +32,19 @@ License along with this library. If not, see IndicatorObjectPrivate: @module: The loaded module representing the object. Note to subclasses: This will not be set when you're initalized. + @entry: A default entry for objects that don't need all the + fancy stuff. This works with #get_entries_default. + @gotten_entries: A check to see if the @entry has been + populated intelligently yet. Private data for the object. */ struct _IndicatorObjectPrivate { GModule * module; + + /* For get_entries_default */ + IndicatorObjectEntry entry; + gboolean gotten_entries; }; #define INDICATOR_OBJECT_GET_PRIVATE(o) (INDICATOR_OBJECT(o)->priv) @@ -46,6 +54,8 @@ static void indicator_object_init (IndicatorObject *self); static void indicator_object_dispose (GObject *object); static void indicator_object_finalize (GObject *object); +static GList * get_entries_default (IndicatorObject * io); + G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT); /* Setup the class and put the functions into the @@ -60,9 +70,11 @@ indicator_object_class_init (IndicatorObjectClass *klass) object_class->dispose = indicator_object_dispose; object_class->finalize = indicator_object_finalize; - klass->get_label = NULL; - klass->get_menu = NULL; - klass->get_image = NULL; + klass->get_label = NULL; + klass->get_menu = NULL; + klass->get_image = NULL; + + klass->get_entries = get_entries_default; return; } @@ -75,6 +87,12 @@ indicator_object_init (IndicatorObject *self) self->priv->module = NULL; + self->priv->entry.menu = NULL; + self->priv->entry.label = NULL; + self->priv->entry.image = NULL; + + self->priv->gotten_entries = FALSE; + return; } @@ -135,7 +153,7 @@ indicator_object_new_from_file (const gchar * file) keep the symbols local to avoid conflicts. */ module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - if(module == NULL) { + if (module == NULL) { g_warning("Unable to load module: %s", file); return NULL; } @@ -198,3 +216,43 @@ unrefandout: return NULL; } +/* The default get entries function uses the other single + entries in the class to create an entry structure and + put it into a list. This makes it simple for simple objects + to create the list. Small changes from the way they + previously were. */ +static GList * +get_entries_default (IndicatorObject * io) +{ + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); + + if (!priv->gotten_entries) { + IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); + + if (class->get_label) { + priv->entry.label = class->get_label(io); + } + + if (class->get_image) { + priv->entry.image = class->get_image(io); + } + + if (priv->entry.image == NULL && priv->entry.label == NULL) { + g_warning("IndicatorObject class does not create an image or a label. We need one of those."); + return NULL; + } + + if (class->get_menu) { + priv->entry.menu = class->get_menu(io); + } + + if (priv->entry.menu == NULL) { + g_warning("IndicatorObject class does not create a menu. We need one of those."); + return NULL; + } + + priv->gotten_entries = TRUE; + } + + return g_list_append(NULL, &(priv->entry)); +} -- cgit v1.2.3 From 258f461b7bcd5d3c811a41fe6a7ad4ffae73f4be Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 16:38:05 -0600 Subject: Creating the actual backing function for indicator_object_get_entries. --- libindicator/indicator-object.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 8c683da..db4b819 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -256,3 +256,29 @@ get_entries_default (IndicatorObject * io) return g_list_append(NULL, &(priv->entry)); } + +/** + indicator_object_get_entires: + @io: #IndicatorObject to query + + This function looks on the class for the object and calls + it's #IndicatorObjectClass::get_entries function. The + list should be owned by the caller, but the individual + enteries should not be. + + Return value: A list if #IndicatorObjectEntry structures or + NULL if there is an error. +*/ +GList * +indicator_object_get_entries (IndicatorObject * io) +{ + g_return_val_if_fail(INDICATOR_IS_OBJECT(io), NULL); + IndicatorObjectClass * class = INDICATOR_OBJECT_GET_CLASS(io); + + if (class->get_entries) { + return class->get_entries(io); + } + + g_error("No get_entries function on object. It must have been deleted?!?!"); + return NULL; +} -- cgit v1.2.3 From 1f96a346f7c2465a6a7785413d78071938829891 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 16:38:11 -0600 Subject: Typo --- libindicator/indicator-object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index cd8cc79..c2d1944 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -53,7 +53,7 @@ typedef struct _IndicatorObjectEntry IndicatorObjectEntry; @get_menu: Gets the image for this object. Should be set to #NULL if @get_entries is set. Should NOT ref the object. - @get_entires: Gets all of the entires for this object returning + @get_entries: Gets all of the entires for this object returning a #GList of #IndicatorObjectEntries. The list should be under the ownership of the caller but the entires will not be. -- cgit v1.2.3 From 57642ed848ab8f6afd9e364b503633727c5ee288 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 21:31:04 -0600 Subject: Converting the dummy indicators over to the new API. They compile now. --- tests/dummy-indicator-blank.c | 1 - tests/dummy-indicator-null.c | 80 +++++++++++++++++++++++++++++++++++++++--- tests/dummy-indicator-simple.c | 78 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 150 insertions(+), 9 deletions(-) diff --git a/tests/dummy-indicator-blank.c b/tests/dummy-indicator-blank.c index 41249f2..5cfe0f0 100644 --- a/tests/dummy-indicator-blank.c +++ b/tests/dummy-indicator-blank.c @@ -2,5 +2,4 @@ #include "libindicator/indicator.h" INDICATOR_SET_VERSION -INDICATOR_SET_NAME("dummy-indicator-null") diff --git a/tests/dummy-indicator-null.c b/tests/dummy-indicator-null.c index ff99d71..767067d 100644 --- a/tests/dummy-indicator-null.c +++ b/tests/dummy-indicator-null.c @@ -1,23 +1,95 @@ +#include +#include + #include "libindicator/indicator.h" +#include "libindicator/indicator-object.h" + +#define DUMMY_INDICATOR_NULL_TYPE (dummy_indicator_null_get_type ()) +#define DUMMY_INDICATOR_NULL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_NULL_TYPE, DummyIndicatorNull)) +#define DUMMY_INDICATOR_NULL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_NULL_TYPE, DummyIndicatorNullClass)) +#define IS_DUMMY_INDICATOR_NULL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_NULL_TYPE)) +#define IS_DUMMY_INDICATOR_NULL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_NULL_TYPE)) +#define DUMMY_INDICATOR_NULL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_NULL_TYPE, DummyIndicatorNullClass)) + +typedef struct _DummyIndicatorNull DummyIndicatorNull; +typedef struct _DummyIndicatorNullClass DummyIndicatorNullClass; + +struct _DummyIndicatorNullClass { + IndicatorObjectClass parent_class; +}; + +struct _DummyIndicatorNull { + IndicatorObject parent; +}; + +GType dummy_indicator_null_get_type (void); INDICATOR_SET_VERSION -INDICATOR_SET_NAME("dummy-indicator-null") +INDICATOR_SET_TYPE(DUMMY_INDICATOR_NULL_TYPE) + GtkLabel * -get_label (void) +get_label (IndicatorObject * io) { return NULL; } GtkImage * -get_icon (void) +get_icon (IndicatorObject * io) { return NULL; } GtkMenu * -get_menu (void) +get_menu (IndicatorObject * io) { return NULL; } + +static void dummy_indicator_null_class_init (DummyIndicatorNullClass *klass); +static void dummy_indicator_null_init (DummyIndicatorNull *self); +static void dummy_indicator_null_dispose (GObject *object); +static void dummy_indicator_null_finalize (GObject *object); + +G_DEFINE_TYPE (DummyIndicatorNull, dummy_indicator_null, INDICATOR_OBJECT_TYPE); + +static void +dummy_indicator_null_class_init (DummyIndicatorNullClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = dummy_indicator_null_dispose; + object_class->finalize = dummy_indicator_null_finalize; + + IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); + + io_class->get_label = get_label; + io_class->get_image = get_icon; + io_class->get_menu = get_menu; + + return; +} + +static void +dummy_indicator_null_init (DummyIndicatorNull *self) +{ + + return; +} + +static void +dummy_indicator_null_dispose (GObject *object) +{ + + G_OBJECT_CLASS (dummy_indicator_null_parent_class)->dispose (object); + return; +} + +static void +dummy_indicator_null_finalize (GObject *object) +{ + + G_OBJECT_CLASS (dummy_indicator_null_parent_class)->finalize (object); + return; +} diff --git a/tests/dummy-indicator-simple.c b/tests/dummy-indicator-simple.c index cee4eac..654650f 100644 --- a/tests/dummy-indicator-simple.c +++ b/tests/dummy-indicator-simple.c @@ -1,23 +1,46 @@ +#include +#include #include "libindicator/indicator.h" +#include "libindicator/indicator-object.h" + +#define DUMMY_INDICATOR_SIMPLE_TYPE (dummy_indicator_simple_get_type ()) +#define DUMMY_INDICATOR_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_SIMPLE_TYPE, DummyIndicatorSimple)) +#define DUMMY_INDICATOR_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_SIMPLE_TYPE, DummyIndicatorSimpleClass)) +#define IS_DUMMY_INDICATOR_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_SIMPLE_TYPE)) +#define IS_DUMMY_INDICATOR_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_SIMPLE_TYPE)) +#define DUMMY_INDICATOR_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_SIMPLE_TYPE, DummyIndicatorSimpleClass)) + +typedef struct _DummyIndicatorSimple DummyIndicatorSimple; +typedef struct _DummyIndicatorSimpleClass DummyIndicatorSimpleClass; + +struct _DummyIndicatorSimpleClass { + IndicatorObjectClass parent_class; +}; + +struct _DummyIndicatorSimple { + IndicatorObject parent; +}; + +GType dummy_indicator_simple_get_type (void); INDICATOR_SET_VERSION -INDICATOR_SET_NAME("dummy-indicator-simple") +INDICATOR_SET_TYPE(DUMMY_INDICATOR_SIMPLE_TYPE) GtkLabel * -get_label (void) +get_label (IndicatorObject * io) { return GTK_LABEL(gtk_label_new("Simple Item")); } GtkImage * -get_icon (void) +get_icon (IndicatorObject * io) { return GTK_IMAGE(gtk_image_new()); } GtkMenu * -get_menu (void) +get_menu (IndicatorObject * io) { GtkMenu * main_menu = GTK_MENU(gtk_menu_new()); GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading..."); @@ -26,3 +49,50 @@ get_menu (void) return main_menu; } + +static void dummy_indicator_simple_class_init (DummyIndicatorSimpleClass *klass); +static void dummy_indicator_simple_init (DummyIndicatorSimple *self); +static void dummy_indicator_simple_dispose (GObject *object); +static void dummy_indicator_simple_finalize (GObject *object); + +G_DEFINE_TYPE (DummyIndicatorSimple, dummy_indicator_simple, INDICATOR_OBJECT_TYPE); + +static void +dummy_indicator_simple_class_init (DummyIndicatorSimpleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = dummy_indicator_simple_dispose; + object_class->finalize = dummy_indicator_simple_finalize; + + IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); + + io_class->get_label = get_label; + io_class->get_image = get_icon; + io_class->get_menu = get_menu; + + return; +} + +static void +dummy_indicator_simple_init (DummyIndicatorSimple *self) +{ + + return; +} + +static void +dummy_indicator_simple_dispose (GObject *object) +{ + + G_OBJECT_CLASS (dummy_indicator_simple_parent_class)->dispose (object); + return; +} + +static void +dummy_indicator_simple_finalize (GObject *object) +{ + + G_OBJECT_CLASS (dummy_indicator_simple_parent_class)->finalize (object); + return; +} -- cgit v1.2.3 From bffbb2c3612b6cc73d7845c365b1dcb05907e010 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 21:33:08 -0600 Subject: Switching to checking the entires list instead of individual functions. --- tests/test-loader.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 4b2b096..141ad78 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -9,9 +9,7 @@ test_loader_filename_dummy_simple_accessors (void) IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); g_assert(object != NULL); - g_assert(indicator_object_get_label(object) != NULL); - g_assert(indicator_object_get_menu(object) != NULL); - g_assert(indicator_object_get_icon(object) != NULL); + g_assert(indicator_object_get_entries(object) != NULL); g_object_unref(object); -- cgit v1.2.3 From 10aa800201db066427fa17b055c33cae00d23d2a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 21:38:09 -0600 Subject: Linking the indicators with the libindicator library. --- tests/Makefile.am | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 8121136..a7d01ec 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -34,7 +34,9 @@ libdummy_indicator_blank_la_CFLAGS = \ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) libdummy_indicator_blank_la_LIBADD = \ - $(LIBINDICATOR_LIBS) + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator libdummy_indicator_blank_la_LDFLAGS = \ -module \ @@ -52,7 +54,9 @@ libdummy_indicator_null_la_CFLAGS = \ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) libdummy_indicator_null_la_LIBADD = \ - $(LIBINDICATOR_LIBS) + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator libdummy_indicator_null_la_LDFLAGS = \ -module \ @@ -70,7 +74,9 @@ libdummy_indicator_simple_la_CFLAGS = \ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) libdummy_indicator_simple_la_LIBADD = \ - $(LIBINDICATOR_LIBS) + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator libdummy_indicator_simple_la_LDFLAGS = \ -module \ -- cgit v1.2.3 From 1a528a74f3e4ed386f7c0325407de6f8e40c6f2a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 21:44:51 -0600 Subject: Make the tester dynamically link the lib so that there's not two versions of everything. --- tests/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index a7d01ec..656d53e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,7 +20,9 @@ test_loader_CFLAGS = \ -DBUILD_DIR="\"$(builddir)\"" test_loader_LDADD = \ - $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator ############################# # Dummy Indicator Blank -- cgit v1.2.3 From 03e89036c7db8eb1afcdc39b4de81863b4ee41f4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 22:16:43 -0600 Subject: Having the test expect an object, but fail when calling the functions. --- tests/test-loader.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 141ad78..263e54f 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -43,7 +43,9 @@ void test_loader_filename_dummy_null (void) { IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-null.so"); - g_assert(object == NULL); + g_assert(object != NULL); + g_assert(indicator_object_get_entries(object) == NULL); + g_object_unref(G_OBJECT(object)); return; } -- cgit v1.2.3 From e354bc4560602a9dbcf73ed8ca3b4ace7297c58a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 22:23:16 -0600 Subject: Changing the way the module is free'd --- libindicator/indicator-object.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index db4b819..442ba78 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -100,21 +100,37 @@ indicator_object_init (IndicatorObject *self) static void indicator_object_dispose (GObject *object) { - IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); - - if (priv->module != NULL) { - g_object_unref(priv->module); - priv->module = NULL; - } G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); return; } +/* A small helper function that unreferences an object but + in the function prototype of a GSourceFunc. */ +static gboolean +module_unref (gpointer data) +{ + g_object_unref(G_OBJECT(data)); + return FALSE; +} + /* Free memory */ static void indicator_object_finalize (GObject *object) { + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); + + if (priv->module != NULL) { + /* Wow, this is convoluted. So basically we want to unref + the module which will cause the code it included to be + removed. But, since it's finalize function is the function + that called this one, we can't really remove it before + it finishes being executed. So we're putting the job into + the main loop to remove it the next time it gets a chance. + Slightly non-deterministic, but should work. */ + g_idle_add(module_unref, priv->module); + priv->module = NULL; + } G_OBJECT_CLASS (indicator_object_parent_class)->finalize (object); return; -- cgit v1.2.3 From 0db39bf65d1007924bded3d48d928a1a7c034581 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 23:15:10 -0600 Subject: Adding in some signals to make for some more fun. --- libindicator/indicator-object.c | 40 ++++++++++++++++++++++++++++++++++++++++ libindicator/indicator-object.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 108fecb..2ab0f84 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -50,6 +50,16 @@ struct _IndicatorObjectPrivate { #define INDICATOR_OBJECT_GET_PRIVATE(o) (INDICATOR_OBJECT(o)->priv) +/* Signals Stuff */ +enum { + ENTRY_ADDED, + ENTRY_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +/* GObject stuff */ static void indicator_object_class_init (IndicatorObjectClass *klass); static void indicator_object_init (IndicatorObject *self); static void indicator_object_dispose (GObject *object); @@ -77,6 +87,36 @@ indicator_object_class_init (IndicatorObjectClass *klass) klass->get_entries = get_entries_default; + /** + IndicatorObject::entry-added: + @arg0: The #IndicatorObject object + + Signaled when a new entry is added and should + be shown by the person using this object. + */ + signals[ENTRY_ADDED] = g_signal_new (INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicatorObjectClass, entry_added), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER, G_TYPE_NONE); + + /** + IndicatorObject::entry-removed: + @arg0: The #IndicatorObject object + + Signaled when an entry is removed and should + be removed by the person using this object. + */ + signals[ENTRY_REMOVED] = g_signal_new (INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicatorObjectClass, entry_removed), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER, G_TYPE_NONE); + return; } diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index c2d1944..1ac39b0 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -36,6 +36,9 @@ G_BEGIN_DECLS #define INDICATOR_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) +#define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED "entry-added" +#define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED "entry-removed" + typedef struct _IndicatorObject IndicatorObject; typedef struct _IndicatorObjectClass IndicatorObjectClass; typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; -- cgit v1.2.3 From 7db7886923d8df734ccb9c300db8bd4a2ebf6e33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 23:17:33 -0600 Subject: Adding in some ID helpers. --- libindicator/indicator-object.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index 1ac39b0..14f0db0 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -36,8 +36,10 @@ G_BEGIN_DECLS #define INDICATOR_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) -#define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED "entry-added" -#define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED "entry-removed" +#define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED "entry-added" +#define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, INDICATOR_TYPE_OBJECT)) +#define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED "entry-removed" +#define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, INDICATOR_TYPE_OBJECT)) typedef struct _IndicatorObject IndicatorObject; typedef struct _IndicatorObjectClass IndicatorObjectClass; -- cgit v1.2.3 From db2a2391c759a2b8a17f4c661cc7e62e6c1d1495 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Nov 2009 10:53:14 -0600 Subject: Using the proper define for the type. --- libindicator/indicator-object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index 14f0db0..c100d02 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -37,9 +37,9 @@ G_BEGIN_DECLS #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) #define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED "entry-added" -#define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, INDICATOR_TYPE_OBJECT)) +#define INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, INDICATOR_OBJECT_TYPE)) #define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED "entry-removed" -#define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, INDICATOR_TYPE_OBJECT)) +#define INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID (g_signal_lookup(INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, INDICATOR_OBJECT_TYPE)) typedef struct _IndicatorObject IndicatorObject; typedef struct _IndicatorObjectClass IndicatorObjectClass; -- cgit v1.2.3 From 8033011194d1063ca6cb16ec99e00e6ade2fcc42 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Nov 2009 10:55:48 -0600 Subject: Building a dummy indicator that signals. --- .bzrignore | 2 + tests/Makefile.am | 21 ++++++++ tests/dummy-indicator-signaler.c | 109 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 tests/dummy-indicator-signaler.c diff --git a/.bzrignore b/.bzrignore index e9dc59e..470e214 100644 --- a/.bzrignore +++ b/.bzrignore @@ -118,3 +118,5 @@ tests/libdummy_indicator_blank_la-dummy-indicator-blank.lo libindicator-[0-9].[0-9].[0-9].tar.gz libindicator-[0-9].[0-9].[0-9].tar.gz.asc libindicator/libindicator_la-indicator-instance.lo +tests/libdummy-indicator-signaler.la +tests/libdummy_indicator_signaler_la-dummy-indicator-signaler.lo diff --git a/tests/Makefile.am b/tests/Makefile.am index 656d53e..6150449 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,6 +5,7 @@ check_PROGRAMS = \ lib_LTLIBRARIES = \ libdummy-indicator-blank.la \ libdummy-indicator-null.la \ + libdummy-indicator-signaler.la \ libdummy-indicator-simple.la ############################# @@ -64,6 +65,26 @@ libdummy_indicator_null_la_LDFLAGS = \ -module \ -avoid-version +############################# +# Dummy Indicator Signaler +############################# + +libdummy_indicator_signaler_la_SOURCES = \ + dummy-indicator-signaler.c + +libdummy_indicator_signaler_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_signaler_la_LIBADD = \ + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator + +libdummy_indicator_signaler_la_LDFLAGS = \ + -module \ + -avoid-version + ############################# # Dummy Indicator Simple ############################# diff --git a/tests/dummy-indicator-signaler.c b/tests/dummy-indicator-signaler.c new file mode 100644 index 0000000..b88cea9 --- /dev/null +++ b/tests/dummy-indicator-signaler.c @@ -0,0 +1,109 @@ +#include +#include + +#include "libindicator/indicator.h" +#include "libindicator/indicator-object.h" + +#define DUMMY_INDICATOR_SIGNALER_TYPE (dummy_indicator_signaler_get_type ()) +#define DUMMY_INDICATOR_SIGNALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignaler)) +#define DUMMY_INDICATOR_SIGNALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass)) +#define IS_DUMMY_INDICATOR_SIGNALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_INDICATOR_SIGNALER_TYPE)) +#define IS_DUMMY_INDICATOR_SIGNALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_INDICATOR_SIGNALER_TYPE)) +#define DUMMY_INDICATOR_SIGNALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_INDICATOR_SIGNALER_TYPE, DummyIndicatorSignalerClass)) + +typedef struct _DummyIndicatorSignaler DummyIndicatorSignaler; +typedef struct _DummyIndicatorSignalerClass DummyIndicatorSignalerClass; + +struct _DummyIndicatorSignalerClass { + IndicatorObjectClass parent_class; +}; + +struct _DummyIndicatorSignaler { + IndicatorObject parent; +}; + +GType dummy_indicator_signaler_get_type (void); + +INDICATOR_SET_VERSION +INDICATOR_SET_TYPE(DUMMY_INDICATOR_SIGNALER_TYPE) + +GtkLabel * +get_label (IndicatorObject * io) +{ + return GTK_LABEL(gtk_label_new("Signaler Item")); +} + +GtkImage * +get_icon (IndicatorObject * io) +{ + return GTK_IMAGE(gtk_image_new()); +} + +GtkMenu * +get_menu (IndicatorObject * io) +{ + GtkMenu * main_menu = GTK_MENU(gtk_menu_new()); + GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading..."); + gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item); + gtk_widget_show(GTK_WIDGET(loading_item)); + + return main_menu; +} + +static void dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass); +static void dummy_indicator_signaler_init (DummyIndicatorSignaler *self); +static void dummy_indicator_signaler_dispose (GObject *object); +static void dummy_indicator_signaler_finalize (GObject *object); + +G_DEFINE_TYPE (DummyIndicatorSignaler, dummy_indicator_signaler, INDICATOR_OBJECT_TYPE); + +static void +dummy_indicator_signaler_class_init (DummyIndicatorSignalerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = dummy_indicator_signaler_dispose; + object_class->finalize = dummy_indicator_signaler_finalize; + + IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); + + io_class->get_label = get_label; + io_class->get_image = get_icon; + io_class->get_menu = get_menu; + + return; +} + +static gboolean +idle_signal (gpointer data) +{ + DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data); + + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, (gpointer)5, TRUE); + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, (gpointer)5, TRUE); + + return FALSE; /* Don't queue again */ +} + +static void +dummy_indicator_signaler_init (DummyIndicatorSignaler *self) +{ + g_idle_add(idle_signal, self); + return; +} + +static void +dummy_indicator_signaler_dispose (GObject *object) +{ + + G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->dispose (object); + return; +} + +static void +dummy_indicator_signaler_finalize (GObject *object) +{ + + G_OBJECT_CLASS (dummy_indicator_signaler_parent_class)->finalize (object); + return; +} -- cgit v1.2.3 From 8c321faf4fe07293d747438923d10839bbf9ac6c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Nov 2009 11:14:22 -0600 Subject: Adding a simple indicator test that checks to make sure we can signal up the stack. --- tests/dummy-indicator-signaler.c | 4 ++-- tests/test-loader.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/dummy-indicator-signaler.c b/tests/dummy-indicator-signaler.c index b88cea9..0444110 100644 --- a/tests/dummy-indicator-signaler.c +++ b/tests/dummy-indicator-signaler.c @@ -79,8 +79,8 @@ idle_signal (gpointer data) { DummyIndicatorSignaler * self = DUMMY_INDICATOR_SIGNALER(data); - g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, (gpointer)5, TRUE); - g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, (gpointer)5, TRUE); + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, GUINT_TO_POINTER(5), TRUE); + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED_ID, 0, GUINT_TO_POINTER(5), TRUE); return FALSE; /* Don't queue again */ } diff --git a/tests/test-loader.c b/tests/test-loader.c index 263e54f..485a951 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -3,6 +3,42 @@ void destroy_cb (gpointer data, GObject * object); +void +entry_change_cb (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer data) +{ + gpointer * valuestore = (gpointer *)data; + *valuestore = entry; + return; +} + +void +test_loader_filename_dummy_signaler (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-signaler.so"); + g_assert(object != NULL); + + gpointer added_value = NULL, removed_value = NULL; + + g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_change_cb), &added_value); + g_signal_connect(G_OBJECT(object), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_change_cb), &removed_value); + + GList * list = indicator_object_get_entries(object); + g_assert(list != NULL); + g_list_free(list); + + while (g_main_context_pending(NULL)) { + g_main_context_iteration(NULL, TRUE); + } + + g_assert(GPOINTER_TO_UINT(added_value) == 5); + g_assert(GPOINTER_TO_UINT(removed_value) == 5); + + g_object_unref(object); + + return; +} + + void test_loader_filename_dummy_simple_accessors (void) { @@ -89,6 +125,7 @@ test_loader_creation_deletion_suite (void) g_test_add_func ("/libindicator/loader/dummy/blank_load", test_loader_filename_dummy_null); g_test_add_func ("/libindicator/loader/dummy/simple_load", test_loader_filename_dummy_simple); g_test_add_func ("/libindicator/loader/dummy/simple_accessors", test_loader_filename_dummy_simple_accessors); + g_test_add_func ("/libindicator/loader/dummy/signaler", test_loader_filename_dummy_signaler); return; } -- cgit v1.2.3 From 534aab3aa87e4ffcca3e14f5c19498843c0adbca Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Nov 2009 11:19:26 -0600 Subject: Use close instead of unreffing. --- libindicator/indicator-object.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 2ab0f84..a492038 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -146,12 +146,15 @@ indicator_object_dispose (GObject *object) return; } -/* A small helper function that unreferences an object but +/* A small helper function that closes a module but in the function prototype of a GSourceFunc. */ static gboolean module_unref (gpointer data) { - g_object_unref(G_OBJECT(data)); + if (!g_module_close((GModule *)data)) { + /* All we can do is warn. */ + g_warning("Unable to close module!"); + } return FALSE; } -- cgit v1.2.3 From 4a558fc09327f1a844f6588081cb742a2c7d742f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Nov 2009 11:34:00 -0600 Subject: Moving everything up to '3' as we're breaking everyone pretty bad at this point. --- configure.ac | 4 ++-- libindicator/indicator.pc.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index d2e18fc..676af4e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(libindicator, 0.2.1, ted@canonical.com) +AC_INIT(libindicator, 0.3.0, ted@canonical.com) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libindicator, 0.2.1) +AM_INIT_AUTOMAKE(libindicator, 0.3.0) AM_MAINTAINER_MODE m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES]) diff --git a/libindicator/indicator.pc.in b/libindicator/indicator.pc.in index 9a8169e..9ef3092 100644 --- a/libindicator/indicator.pc.in +++ b/libindicator/indicator.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -indicatordir=${libdir}/indicators/2/ +indicatordir=${libdir}/indicators/3/ iconsdir=@datarootdir@/@PACKAGE@/icons/ Cflags: -I${includedir}/libindicator-0.1 -- cgit v1.2.3 From 34f914c264d268efff97142ba1ea7f2c3eab0493 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Nov 2009 11:34:44 -0600 Subject: Changing the include directory as well. --- libindicator/Makefile.am | 2 +- libindicator/indicator.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 5c512cd..717d60f 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -3,7 +3,7 @@ CLEANFILES = EXTRA_DIST = \ indicator.pc.in -libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator +libindicatorincludedir=$(includedir)/libindicator-0.3/libindicator indicator_headers = \ indicator.h \ diff --git a/libindicator/indicator.pc.in b/libindicator/indicator.pc.in index 9ef3092..91b70b1 100644 --- a/libindicator/indicator.pc.in +++ b/libindicator/indicator.pc.in @@ -7,7 +7,7 @@ includedir=@includedir@ indicatordir=${libdir}/indicators/3/ iconsdir=@datarootdir@/@PACKAGE@/icons/ -Cflags: -I${includedir}/libindicator-0.1 +Cflags: -I${includedir}/libindicator-0.3 Requires: gtk+-2.0 Libs: -lindicator -- cgit v1.2.3