diff options
-rw-r--r-- | libindicator/indicator-object.c | 171 | ||||
-rw-r--r-- | libindicator/indicator-object.h | 16 | ||||
-rw-r--r-- | 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 <gtk/gtk.h> +#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; } |