From 1f822bf64b8891dab03937060dd47b8003bb8ab5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 15:28:41 -0400 Subject: Building a base object. --- libindicator/Makefile.am | 10 +++++++- libindicator/indicator-object.c | 55 +++++++++++++++++++++++++++++++++++++++++ libindicator/indicator-object.h | 33 +++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 libindicator/indicator-object.c create mode 100644 libindicator/indicator-object.h (limited to 'libindicator') diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index be68721..29b7bb5 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -4,11 +4,19 @@ EXTRA_DIST = \ libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator indicator_headers = \ - indicator.h + indicator.h \ + indicator-object.h libindicatorinclude_HEADERS = \ $(indicator_headers) +lib_LTLIBRARIES = \ + libindicator.la + +libindicator_la_SOURCES = \ + $(indicator_headers) \ + indicator-object.c + pkgconfig_DATA = indicator.pc pkgconfigdir = $(libdir)/pkgconfig diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c new file mode 100644 index 0000000..772110b --- /dev/null +++ b/libindicator/indicator-object.c @@ -0,0 +1,55 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "indicator-object.h" + +typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; +struct _IndicatorObjectPrivate { +}; + +#define INDICATOR_OBJECT_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_OBJECT_TYPE, IndicatorObjectPrivate)) + +static void indicator_object_class_init (IndicatorObjectClass *klass); +static void indicator_object_init (IndicatorObject *self); +static void indicator_object_dispose (GObject *object); +static void indicator_object_finalize (GObject *object); + +G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT); + +static void +indicator_object_class_init (IndicatorObjectClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IndicatorObjectPrivate)); + + object_class->dispose = indicator_object_dispose; + object_class->finalize = indicator_object_finalize; + + return; +} + +static void +indicator_object_init (IndicatorObject *self) +{ + + return; +} + +static void +indicator_object_dispose (GObject *object) +{ + + G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); + return; +} + +static void +indicator_object_finalize (GObject *object) +{ + + G_OBJECT_CLASS (indicator_object_parent_class)->finalize (object); + return; +} diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h new file mode 100644 index 0000000..9c6c103 --- /dev/null +++ b/libindicator/indicator-object.h @@ -0,0 +1,33 @@ +#ifndef __INDICATOR_OBJECT_H__ +#define __INDICATOR_OBJECT_H__ + +#include +#include + +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_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) + +typedef struct _IndicatorObject IndicatorObject; +typedef struct _IndicatorObjectClass IndicatorObjectClass; + +struct _IndicatorObjectClass { + GObjectClass parent_class; + +}; + +struct _IndicatorObject { + GObject parent; + +}; + +GType indicator_object_get_type (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 24d025363c4a708c61acee26456a42a0b9a4b609 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 16:32:23 -0400 Subject: Adding some pkg-config love to get things compiling all nice like. --- libindicator/Makefile.am | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libindicator') diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 29b7bb5..db45f3c 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -17,6 +17,13 @@ libindicator_la_SOURCES = \ $(indicator_headers) \ indicator-object.c +libindicator_la_CFLAGS = \ + $(LIBINDICATOR_CFLAGS) \ + -Wall -Werror + +libindicator_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + pkgconfig_DATA = indicator.pc pkgconfigdir = $(libdir)/pkgconfig -- cgit v1.2.3 From 3bf9efb38a2bd564bede8e542d5adc267056ec0a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 16:32:19 -0400 Subject: Putting data in the private --- libindicator/indicator-object.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 772110b..bb154fc 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -6,6 +6,7 @@ typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { + guint data; }; #define INDICATOR_OBJECT_GET_PRIVATE(o) \ -- cgit v1.2.3 From b4d20eb0049cc36dbdd03754f820bd46df6e60ec Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:09:21 -0400 Subject: Adding a function to create an object from a file --- libindicator/indicator-object.c | 6 ++++++ libindicator/indicator-object.h | 1 + 2 files changed, 7 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index bb154fc..00ede90 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -54,3 +54,9 @@ indicator_object_finalize (GObject *object) G_OBJECT_CLASS (indicator_object_parent_class)->finalize (object); return; } + +IndicatorObject * +indicator_object_new_from_file (const gchar * file) +{ + return NULL; +} diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index 9c6c103..fd7f470 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -27,6 +27,7 @@ struct _IndicatorObject { }; GType indicator_object_get_type (void); +IndicatorObject * indicator_object_new_from_file (const gchar * file); G_END_DECLS -- cgit v1.2.3 From f4b307cda5b10c41dd733d6189fd5a1ce7fe3111 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 18:36:06 -0400 Subject: Fleshing out the load from file function. Still fails. --- libindicator/indicator-object.c | 68 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 00ede90..afeaf19 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -1,12 +1,16 @@ + #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "indicator.h" #include "indicator-object.h" typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { - guint data; + GtkLabel * label; + GtkImage * icon; + GtkMenu * menu; }; #define INDICATOR_OBJECT_GET_PRIVATE(o) \ @@ -35,6 +39,11 @@ indicator_object_class_init (IndicatorObjectClass *klass) static void indicator_object_init (IndicatorObject *self) { + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(self); + + priv->label = NULL; + priv->icon = NULL; + priv->menu = NULL; return; } @@ -42,6 +51,22 @@ indicator_object_init (IndicatorObject *self) static void 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; + } G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); return; @@ -58,5 +83,44 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - return NULL; + g_return_val_if_fail(file != NULL, NULL); + + GModule * module = g_module_open(file, + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); + g_return_val_if_fail(module != NULL, NULL); + + get_version_t lget_version = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version)), FALSE); + if (!INDICATOR_VERSION_CHECK(lget_version())) { + g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); + return NULL; + } + + GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); + + get_label_t lget_label = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_LABEL_S, (gpointer *)(&lget_label)), FALSE); + g_return_val_if_fail(lget_label != NULL, FALSE); + priv->label = lget_label(); + + get_icon_t lget_icon = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_ICON_S, (gpointer *)(&lget_icon)), FALSE); + g_return_val_if_fail(lget_icon != NULL, FALSE); + priv->icon = lget_icon(); + + get_menu_t lget_menu = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_MENU_S, (gpointer *)(&lget_menu)), FALSE); + g_return_val_if_fail(lget_menu != NULL, FALSE); + priv->menu = lget_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."); + g_object_unref(object); + return NULL; + } + + return INDICATOR_OBJECT(object); } -- cgit v1.2.3 From bece9de31705d57c83822ce3ece6dd24f92b9283 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 18:43:10 -0400 Subject: Making it so that we're not using g_return_if_fail as it messes up the test suite. --- libindicator/indicator-object.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index afeaf19..06ca48f 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -83,14 +83,20 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - g_return_val_if_fail(file != NULL, NULL); + if (file != NULL) + return NULL; GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - g_return_val_if_fail(module != NULL, NULL); + if(module != NULL) { + g_warning("Unable to load module: %s", file); + return NULL; + } get_version_t lget_version = NULL; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version)), FALSE); + if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) + return NULL; + if (!INDICATOR_VERSION_CHECK(lget_version())) { g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); return NULL; -- cgit v1.2.3 From a65694f2fc7c4c3aa4b955f101617278e4f1c9b4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:04:51 -0400 Subject: Turning all the return if fails into proper if's with warning and unref the object so there aren't any memory leaks. --- libindicator/indicator-object.c | 48 ++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 06ca48f..d7f18d3 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -83,8 +83,10 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - if (file != NULL) + if (file != NULL) { + g_warning("Invalid filename."); return NULL; + } GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); @@ -94,8 +96,10 @@ indicator_object_new_from_file (const gchar * file) } get_version_t lget_version = NULL; - if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) + if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) { + g_warning("Unable to get the symbol for getting the version."); return NULL; + } if (!INDICATOR_VERSION_CHECK(lget_version())) { g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); @@ -105,19 +109,43 @@ indicator_object_new_from_file (const gchar * file) 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; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_LABEL_S, (gpointer *)(&lget_label)), FALSE); - g_return_val_if_fail(lget_label != NULL, FALSE); + 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); + goto unrefandout; + } + if (lget_label == NULL) { + g_warning("Symbol '" INDICATOR_GET_LABEL_S "' is (null) in module: %s", file); + goto unrefandout; + } priv->label = lget_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; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_ICON_S, (gpointer *)(&lget_icon)), FALSE); - g_return_val_if_fail(lget_icon != NULL, FALSE); + 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(); + /* The function for grabbing a menu from the module + execute it, and make sure everything is a-okay */ get_menu_t lget_menu = NULL; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_MENU_S, (gpointer *)(&lget_menu)), FALSE); - g_return_val_if_fail(lget_menu != NULL, FALSE); + 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); + goto unrefandout; + } + if (lget_menu == NULL) { + g_warning("Symbol '" INDICATOR_GET_MENU_S "' is (null) in module: %s", file); + goto unrefandout; + } priv->menu = lget_menu(); if (priv->label == NULL && priv->icon == NULL) { @@ -129,4 +157,8 @@ indicator_object_new_from_file (const gchar * file) } return INDICATOR_OBJECT(object); + +unrefandout: + g_object_unref(object); + return NULL; } -- cgit v1.2.3 From 18f63963ad625504956f753677927bda0e83d0dc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:07:03 -0400 Subject: Truth. Sucks. --- libindicator/indicator-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index d7f18d3..7188a07 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -83,7 +83,7 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - if (file != NULL) { + if (file == NULL) { g_warning("Invalid filename."); return NULL; } -- cgit v1.2.3 From b2942d9cc8631275fe8abdc53bd518b5b9f9ffcc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:12:47 -0400 Subject: Checking to see if a file exists before trying to load it. --- libindicator/indicator-object.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 7188a07..9fc439e 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -88,6 +88,11 @@ indicator_object_new_from_file (const gchar * file) return NULL; } + if (!g_file_test(file, G_FILE_TEST_EXISTS)) { + g_warning("File '%s' does not exist.", file); + return NULL; + } + GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if(module != NULL) { -- cgit v1.2.3 From 4ea28685563e8f7267ca75c28541582b4f3e544b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:17:15 -0400 Subject: Truth again. Keeps bitting back. I shouldn't of lied in the 2nd grade, I confess! No more, please. --- libindicator/indicator-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 9fc439e..a70a3ec 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -95,7 +95,7 @@ indicator_object_new_from_file (const gchar * file) GModule * 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; } -- cgit v1.2.3 From 66b0d1beb9907963f35dd36ccf3e193eb641f694 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:48:44 -0400 Subject: Making it so that we use the same unref code as everyone else. --- libindicator/indicator-object.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index a70a3ec..6a638ec 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -157,8 +157,7 @@ indicator_object_new_from_file (const gchar * file) /* 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."); - g_object_unref(object); - return NULL; + goto unrefandout; } return INDICATOR_OBJECT(object); -- cgit v1.2.3 From fda24e437ad0664e7287237e5bcffcbe15faade4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:22:59 -0400 Subject: Maintaining a reference to the objects we create in the object. --- libindicator/indicator-object.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 6a638ec..71e72d8 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -126,6 +126,9 @@ indicator_object_new_from_file (const gchar * 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 */ @@ -139,6 +142,9 @@ indicator_object_new_from_file (const gchar * 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 */ @@ -152,6 +158,9 @@ indicator_object_new_from_file (const gchar * 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, -- cgit v1.2.3 From 5144944dbe90e1eaf65bfeedbd6057b858880abc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:47:19 -0400 Subject: Adding some accessor functions for the various GTK objects. --- libindicator/indicator-object.c | 24 ++++++++++++++++++++++++ libindicator/indicator-object.h | 4 ++++ 2 files changed, 28 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 71e72d8..38847dd 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -175,3 +175,27 @@ unrefandout: g_object_unref(object); return NULL; } + +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; +} + +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; +} + +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 fd7f470..d06355b 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -29,6 +29,10 @@ struct _IndicatorObject { 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); + G_END_DECLS #endif -- cgit v1.2.3 From a8b1436ded0d74d44a414b0ab3df9334e24eb426 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:37:49 -0500 Subject: Adding in comments. --- libindicator/indicator-object.c | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 38847dd..e80c1d5 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -6,6 +6,14 @@ #include "indicator.h" #include "indicator-object.h" +/** + 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. + + Private data for the object. +*/ typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { GtkLabel * label; @@ -23,6 +31,8 @@ static void indicator_object_finalize (GObject *object); G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT); +/* Setup the class and put the functions into the + class structure */ static void indicator_object_class_init (IndicatorObjectClass *klass) { @@ -36,6 +46,7 @@ indicator_object_class_init (IndicatorObjectClass *klass) return; } +/* Inititalize an instance */ static void indicator_object_init (IndicatorObject *self) { @@ -48,6 +59,7 @@ indicator_object_init (IndicatorObject *self) return; } +/* Unref the objects that we're holding on to. */ static void indicator_object_dispose (GObject *object) { @@ -72,6 +84,7 @@ indicator_object_dispose (GObject *object) return; } +/* Free memory */ static void indicator_object_finalize (GObject *object) { @@ -80,9 +93,22 @@ indicator_object_finalize (GObject *object) return; } +/** + indicator_object_new_from_file: + @file: Filename containing a loadable module + + This function builds an #IndicatorObject using the symbols + that are found in @file. The module is loaded and the + references are all kept by the object. To unload the + module the object must be destroyed. + + Return value: A valid #IndicatorObject or #NULL if error. +*/ IndicatorObject * indicator_object_new_from_file (const gchar * file) { + /* Check to make sure the name exists and that the + file itself exists */ if (file == NULL) { g_warning("Invalid filename."); return NULL; @@ -93,6 +119,8 @@ indicator_object_new_from_file (const gchar * file) return NULL; } + /* 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); if(module == NULL) { @@ -100,17 +128,23 @@ indicator_object_new_from_file (const gchar * file) return NULL; } + /* Look for the version function, error if not found. */ get_version_t lget_version = NULL; if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) { g_warning("Unable to get the symbol for getting the version."); return NULL; } + /* Check the version with the macro and make sure we're + all talking the same language. */ if (!INDICATOR_VERSION_CHECK(lget_version())) { g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); 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); @@ -171,11 +205,23 @@ indicator_object_new_from_file (const gchar * file) return INDICATOR_OBJECT(object); + /* Error, let's drop the object and return NULL. Sad when + this happens. */ unrefandout: g_object_unref(object); 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) { @@ -184,6 +230,16 @@ indicator_object_get_label (IndicatorObject * 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) { @@ -192,6 +248,16 @@ indicator_object_get_icon (IndicatorObject * 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) { -- cgit v1.2.3 From 755adf0afbb0b0478f6c9f3534f04f21bcdea910 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:41:34 -0500 Subject: Oh, legal headers. Fun, fun. --- libindicator/indicator-object.c | 21 +++++++++++++++++++++ libindicator/indicator-object.h | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index e80c1d5..5921ce5 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -1,3 +1,24 @@ +/* +An interface for indicators to link to for creation. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 3.0 as published by the Free Software Foundation. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3.0 for more details. + +You should have received a copy of the GNU General Public +License along with this library. If not, see +. +*/ #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index d06355b..cb01b85 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -1,3 +1,25 @@ +/* +An interface for indicators to link to for creation. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 3.0 as published by the Free Software Foundation. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3.0 for more details. + +You should have received a copy of the GNU General Public +License along with this library. If not, see +. +*/ + #ifndef __INDICATOR_OBJECT_H__ #define __INDICATOR_OBJECT_H__ -- cgit v1.2.3