diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2012-10-08 06:57:42 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2012-10-08 08:07:51 +0200 |
commit | 16d45a485fbb4bfc6807311ee1b230c9d1178a17 (patch) | |
tree | e775aa051d4441e210625d0f4309c1681d5df8bc /liblogdiag | |
parent | 492daa3ce371f150ab927ceb22d95bf09f372812 (diff) | |
download | logdiag-16d45a485fbb4bfc6807311ee1b230c9d1178a17.tar.gz logdiag-16d45a485fbb4bfc6807311ee1b230c9d1178a17.tar.xz logdiag-16d45a485fbb4bfc6807311ee1b230c9d1178a17.zip |
Add LdCategoryViewIf.
Deduplicates parts of LdCategory{,Symbol}View.
Diffstat (limited to 'liblogdiag')
-rw-r--r-- | liblogdiag/ld-category-symbol-view.c | 106 | ||||
-rw-r--r-- | liblogdiag/ld-category-symbol-view.h | 8 | ||||
-rw-r--r-- | liblogdiag/ld-category-view-if.c | 99 | ||||
-rw-r--r-- | liblogdiag/ld-category-view-if.h | 58 | ||||
-rw-r--r-- | liblogdiag/ld-category-view.c | 105 | ||||
-rw-r--r-- | liblogdiag/ld-category-view.h | 6 | ||||
-rw-r--r-- | liblogdiag/liblogdiag.h | 1 |
7 files changed, 221 insertions, 162 deletions
diff --git a/liblogdiag/ld-category-symbol-view.c b/liblogdiag/ld-category-symbol-view.c index 6116566..3cf975f 100644 --- a/liblogdiag/ld-category-symbol-view.c +++ b/liblogdiag/ld-category-symbol-view.c @@ -70,6 +70,11 @@ static void ld_category_symbol_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); static void ld_category_symbol_view_finalize (GObject *gobject); +static void ld_category_symbol_view_set_category + (LdCategoryViewIf *iface, LdCategory *category); +static LdCategory *ld_category_symbol_view_get_category + (LdCategoryViewIf *iface); + static void on_size_request (GtkWidget *widget, GtkRequisition *requisition, gpointer user_data); static void on_size_allocate (GtkWidget *widget, GdkRectangle *allocation, @@ -78,59 +83,28 @@ static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data); -G_DEFINE_TYPE (LdCategorySymbolView, - ld_category_symbol_view, GTK_TYPE_DRAWING_AREA); +static void +ld_category_view_if_init (LdCategoryViewIfInterface *iface) +{ + iface->set_category = ld_category_symbol_view_set_category; + iface->get_category = ld_category_symbol_view_get_category; +} + +G_DEFINE_TYPE_WITH_CODE (LdCategorySymbolView, + ld_category_symbol_view, GTK_TYPE_DRAWING_AREA, + G_IMPLEMENT_INTERFACE (LD_TYPE_CATEGORY_VIEW_IF, ld_category_view_if_init)); static void ld_category_symbol_view_class_init (LdCategorySymbolViewClass *klass) { GObjectClass *object_class; - GParamSpec *pspec; object_class = G_OBJECT_CLASS (klass); object_class->get_property = ld_category_symbol_view_get_property; object_class->set_property = ld_category_symbol_view_set_property; object_class->finalize = ld_category_symbol_view_finalize; -/** - * LdCategorySymbolView::symbol-selected: - * @self: an #LdCategorySymbolView object. - * @symbol: the selected #LdSymbol object. - * @path: location of the symbol within the library. - * - * A symbol has been selected. - */ - klass->symbol_selected_signal = g_signal_new - ("symbol-selected", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ld_marshal_VOID__OBJECT_STRING, - G_TYPE_NONE, 2, LD_TYPE_SYMBOL, - G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); - -/** - * LdCategorySymbolView::symbol-deselected: - * @self: an #LdCategorySymbolView object. - * @symbol: the deselected #LdSymbol object. - * @path: location of the symbol within the library. - * - * A symbol has been deselected. - */ - klass->symbol_deselected_signal = g_signal_new - ("symbol-deselected", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ld_marshal_VOID__OBJECT_STRING, - G_TYPE_NONE, 2, LD_TYPE_SYMBOL, - G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); - -/** - * LdCategorySymbolView:category: - * - * The underlying #LdCategory object of this view. - */ - pspec = g_param_spec_object ("category", "Category", - "The underlying category object of this view.", - LD_TYPE_CATEGORY, G_PARAM_READWRITE); - g_object_class_install_property (object_class, PROP_CATEGORY, pspec); + g_object_class_override_property (object_class, PROP_CATEGORY, "category"); g_type_class_add_private (klass, sizeof (LdCategorySymbolViewPrivate)); } @@ -154,7 +128,7 @@ symbol_deselect (LdCategorySymbolView *self) if (!preselected) return; - g_signal_emit (self, LD_CATEGORY_SYMBOL_VIEW_GET_CLASS (self)-> + g_signal_emit (self, LD_CATEGORY_VIEW_IF_GET_INTERFACE (self)-> symbol_deselected_signal, 0, preselected->symbol, preselected->path); symbol_redraw (self, preselected); @@ -201,7 +175,7 @@ on_motion_notify (GtkWidget *widget, GdkEventMotion *event, gpointer user_data) gtk_drag_source_set (widget, GDK_BUTTON1_MASK, &target, 1, GDK_ACTION_COPY); - g_signal_emit (self, LD_CATEGORY_SYMBOL_VIEW_GET_CLASS (self)-> + g_signal_emit (self, LD_CATEGORY_VIEW_IF_GET_INTERFACE (self)-> symbol_selected_signal, 0, data->symbol, data->path); } return FALSE; @@ -320,13 +294,11 @@ static void ld_category_symbol_view_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - LdCategorySymbolView *self; - - self = LD_CATEGORY_SYMBOL_VIEW (object); switch (property_id) { case PROP_CATEGORY: - g_value_set_object (value, ld_category_symbol_view_get_category (self)); + g_value_set_object (value, + ld_category_view_if_get_category (LD_CATEGORY_VIEW_IF (object))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -337,13 +309,10 @@ static void ld_category_symbol_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - LdCategorySymbolView *self; - - self = LD_CATEGORY_SYMBOL_VIEW (object); switch (property_id) { case PROP_CATEGORY: - ld_category_symbol_view_set_category (self, + ld_category_view_if_set_category (LD_CATEGORY_VIEW_IF (object), LD_CATEGORY (g_value_get_object (value))); break; default: @@ -572,24 +541,20 @@ ld_category_symbol_view_new (LdCategory *category) LdCategorySymbolView *self; self = g_object_new (LD_TYPE_CATEGORY_SYMBOL_VIEW, NULL); - ld_category_symbol_view_set_category (self, category); + ld_category_view_if_set_category (LD_CATEGORY_VIEW_IF (self), category); return GTK_WIDGET (self); } -/** - * ld_category_symbol_view_set_category: - * @self: an #LdCategorySymbolView object. - * @category: the #LdCategory to be assigned to the view. - * - * Assign an #LdCategory object to the view. - */ -void -ld_category_symbol_view_set_category (LdCategorySymbolView *self, +static void +ld_category_symbol_view_set_category (LdCategoryViewIf *iface, LdCategory *category) { - g_return_if_fail (LD_IS_CATEGORY_SYMBOL_VIEW (self)); + LdCategorySymbolView *self; + + g_return_if_fail (LD_IS_CATEGORY_SYMBOL_VIEW (iface)); g_return_if_fail (LD_IS_CATEGORY (category)); + self = LD_CATEGORY_SYMBOL_VIEW (iface); if (self->priv->category) { g_object_unref (self->priv->category); @@ -609,16 +574,9 @@ ld_category_symbol_view_set_category (LdCategorySymbolView *self, gtk_widget_queue_resize (GTK_WIDGET (self)); } -/** - * ld_category_symbol_view_get_category: - * @self: an #LdCategorySymbolView object. - * - * Get the #LdCategory object assigned to this view. - * The reference count on the category is not incremented. - */ -LdCategory * -ld_category_symbol_view_get_category (LdCategorySymbolView *self) +static LdCategory * +ld_category_symbol_view_get_category (LdCategoryViewIf *iface) { - g_return_val_if_fail (LD_IS_CATEGORY_SYMBOL_VIEW (self), NULL); - return self->priv->category; + g_return_val_if_fail (LD_IS_CATEGORY_SYMBOL_VIEW (iface), NULL); + return LD_CATEGORY_SYMBOL_VIEW (iface)->priv->category; } diff --git a/liblogdiag/ld-category-symbol-view.h b/liblogdiag/ld-category-symbol-view.h index bc41657..964469a 100644 --- a/liblogdiag/ld-category-symbol-view.h +++ b/liblogdiag/ld-category-symbol-view.h @@ -45,9 +45,6 @@ struct _LdCategorySymbolViewClass { /*< private >*/ GtkDrawingAreaClass parent_class; - - guint symbol_selected_signal; - guint symbol_deselected_signal; }; @@ -55,11 +52,6 @@ GType ld_category_symbol_view_get_type (void) G_GNUC_CONST; GtkWidget *ld_category_symbol_view_new (LdCategory *category); -void ld_category_symbol_view_set_category - (LdCategorySymbolView *self, LdCategory *category); -LdCategory *ld_category_symbol_view_get_category - (LdCategorySymbolView *self); - G_END_DECLS diff --git a/liblogdiag/ld-category-view-if.c b/liblogdiag/ld-category-view-if.c new file mode 100644 index 0000000..18a37e1 --- /dev/null +++ b/liblogdiag/ld-category-view-if.c @@ -0,0 +1,99 @@ +/* + * ld-category-view-if.c + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2012. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#include "liblogdiag.h" +#include "config.h" + + +/** + * SECTION:ld-category-view-if + * @short_description: Interface for objects displaying categories + * @see_also: #LdCategory + * + * #LdCategoryViewIf defines objects displaying contents of #LdCategory + * hierarchies. + */ + +G_DEFINE_INTERFACE (LdCategoryViewIf, ld_category_view_if, 0); + +static void +ld_category_view_if_default_init (LdCategoryViewIfInterface *iface) +{ + GParamSpec *pspec; + +/** + * LdCategoryViewIf::symbol-selected: + * @self: an #LdCategoryView object. + * @symbol: the selected #LdSymbol object. + * @path: location of the symbol within the library. + * + * A symbol has been selected. + */ + iface->symbol_selected_signal = g_signal_new + ("symbol-selected", G_TYPE_FROM_INTERFACE (iface), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + ld_marshal_VOID__OBJECT_STRING, + G_TYPE_NONE, 2, LD_TYPE_SYMBOL, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + +/** + * LdCategoryViewIf::symbol-deselected: + * @self: an #LdCategoryView object. + * @symbol: the deselected #LdSymbol object. + * @path: location of the symbol within the library. + * + * A symbol has been deselected. + */ + iface->symbol_deselected_signal = g_signal_new + ("symbol-deselected", G_TYPE_FROM_INTERFACE (iface), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + ld_marshal_VOID__OBJECT_STRING, + G_TYPE_NONE, 2, LD_TYPE_SYMBOL, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + +/** + * LdCategoryViewIf:category: + * + * The #LdCategory this object retrieves content from. + */ + pspec = g_param_spec_object ("category", "Category", + "The symbol category that is shown by this object.", + LD_TYPE_CATEGORY, G_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); +} + +/** + * ld_category_view_if_set_category: + * @self: an #LdCategorylViewIf object. + * @category: the #LdCategory to be assigned to the view. + * + * Assign an #LdCategory object to the view. + */ +void +ld_category_view_if_set_category (LdCategoryViewIf *self, + LdCategory *category) +{ + g_return_if_fail (LD_IS_CATEGORY_VIEW_IF (self)); + LD_CATEGORY_VIEW_IF_GET_INTERFACE (self)->set_category (self, category); +} + +/** + * ld_category_view_if_get_category: + * @self: an #LdCategoryViewIf object. + * + * Get the #LdCategory object assigned to this view. + * The reference count on the category is not incremented. + */ +LdCategory * +ld_category_view_if_get_category (LdCategoryViewIf *self) +{ + g_return_val_if_fail (LD_IS_CATEGORY_VIEW_IF (self), NULL); + return LD_CATEGORY_VIEW_IF_GET_INTERFACE (self)->get_category (self); +} diff --git a/liblogdiag/ld-category-view-if.h b/liblogdiag/ld-category-view-if.h new file mode 100644 index 0000000..7cdfa9d --- /dev/null +++ b/liblogdiag/ld-category-view-if.h @@ -0,0 +1,58 @@ +/* + * ld-category-view-if.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2012. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __LD_CATEGORY_VIEW_IF_H__ +#define __LD_CATEGORY_VIEW_IF_H__ + +G_BEGIN_DECLS + + +#define LD_TYPE_CATEGORY_VIEW_IF (ld_category_view_if_get_type ()) +#define LD_CATEGORY_VIEW_IF(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LD_TYPE_CATEGORY_VIEW_IF, LdCategoryViewIf)) +#define LD_IS_CATEGORY_VIEW_IF(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LD_TYPE_CATEGORY_VIEW_IF)) +#define LD_CATEGORY_VIEW_IF_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE \ + ((inst), LD_TYPE_CATEGORY_VIEW_IF, LdCategoryViewIfInterface)) + +typedef struct _LdCategoryViewIf LdCategoryViewIf; +typedef struct _LdCategoryViewIfInterface LdCategoryViewIfInterface; + +/** + * LdCategoryViewIf: + */ +struct _LdCategoryViewIf +{ + /* Just to remind gtk-doc that this really exists. */ +}; + +struct _LdCategoryViewIfInterface +{ +/*< private >*/ + GTypeInterface parent; + + guint symbol_selected_signal; + guint symbol_deselected_signal; + + void (*set_category) (LdCategoryViewIf *self, LdCategory *category); + LdCategory *(*get_category) (LdCategoryViewIf *self); +}; + + +GType ld_category_view_if_get_type (void) G_GNUC_CONST; + +void ld_category_view_if_set_category (LdCategoryViewIf *self, + LdCategory *category); +LdCategory *ld_category_view_if_get_category (LdCategoryViewIf *self); + + +G_END_DECLS + +#endif /* ! __LD_CATEGORY_VIEW_IF_H__ */ diff --git a/liblogdiag/ld-category-view.c b/liblogdiag/ld-category-view.c index 6314cd5..707627d 100644 --- a/liblogdiag/ld-category-view.c +++ b/liblogdiag/ld-category-view.c @@ -44,62 +44,35 @@ static void ld_category_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); static void ld_category_view_dispose (GObject *gobject); +static void ld_category_view_set_category (LdCategoryViewIf *iface, + LdCategory *category); +static LdCategory *ld_category_view_get_category (LdCategoryViewIf *iface); + static void reload_category (LdCategoryView *self); static void load_category_cb (gpointer data, gpointer user_data); -G_DEFINE_TYPE (LdCategoryView, ld_category_view, GTK_TYPE_VBOX); +static void +ld_category_view_if_init (LdCategoryViewIfInterface *iface) +{ + iface->set_category = ld_category_view_set_category; + iface->get_category = ld_category_view_get_category; +} + +G_DEFINE_TYPE_WITH_CODE (LdCategoryView, ld_category_view, GTK_TYPE_VBOX, + G_IMPLEMENT_INTERFACE (LD_TYPE_CATEGORY_VIEW_IF, ld_category_view_if_init)); static void ld_category_view_class_init (LdCategoryViewClass *klass) { GObjectClass *object_class; - GParamSpec *pspec; object_class = G_OBJECT_CLASS (klass); object_class->get_property = ld_category_view_get_property; object_class->set_property = ld_category_view_set_property; object_class->dispose = ld_category_view_dispose; -/** - * LdCategoryView::symbol-selected: - * @self: an #LdCategoryView object. - * @symbol: the selected #LdSymbol object. - * @path: location of the symbol within the library. - * - * A symbol has been selected. - */ - klass->symbol_selected_signal = g_signal_new - ("symbol-selected", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ld_marshal_VOID__OBJECT_STRING, - G_TYPE_NONE, 2, LD_TYPE_SYMBOL, - G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); - -/** - * LdCategoryView::symbol-deselected: - * @self: an #LdCategoryView object. - * @symbol: the deselected #LdSymbol object. - * @path: location of the symbol within the library. - * - * A symbol has been deselected. - */ - klass->symbol_deselected_signal = g_signal_new - ("symbol-deselected", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ld_marshal_VOID__OBJECT_STRING, - G_TYPE_NONE, 2, LD_TYPE_SYMBOL, - G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); - -/** - * LdCategoryView:category: - * - * The #LdCategory this widget retrieves content from. - */ - pspec = g_param_spec_object ("category", "Category", - "The symbol category that is shown by this widget.", - LD_TYPE_CATEGORY, G_PARAM_READWRITE); - g_object_class_install_property (object_class, PROP_CATEGORY, pspec); + g_object_class_override_property (object_class, PROP_CATEGORY, "category"); g_type_class_add_private (klass, sizeof (LdCategoryViewPrivate)); } @@ -117,7 +90,7 @@ ld_category_view_dispose (GObject *gobject) LdCategoryView *self; self = LD_CATEGORY_VIEW (gobject); - ld_category_view_set_category (self, NULL); + ld_category_view_if_set_category (LD_CATEGORY_VIEW_IF (self), NULL); g_free (self->priv->expander_prefix); self->priv->expander_prefix = NULL; @@ -130,13 +103,11 @@ static void ld_category_view_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - LdCategoryView *self; - - self = LD_CATEGORY_VIEW (object); switch (property_id) { case PROP_CATEGORY: - g_value_set_object (value, ld_category_view_get_category (self)); + g_value_set_object (value, + ld_category_view_if_get_category (LD_CATEGORY_VIEW_IF (object))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -147,13 +118,10 @@ static void ld_category_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - LdCategoryView *self; - - self = LD_CATEGORY_VIEW (object); switch (property_id) { case PROP_CATEGORY: - ld_category_view_set_category (self, + ld_category_view_if_set_category (LD_CATEGORY_VIEW_IF (object), LD_CATEGORY (g_value_get_object (value))); break; default: @@ -174,23 +142,19 @@ ld_category_view_new (LdCategory *category) LdCategoryView *self; self = g_object_new (LD_TYPE_CATEGORY_VIEW, NULL); - ld_category_view_set_category (self, category); + ld_category_view_if_set_category (LD_CATEGORY_VIEW_IF (self), category); return GTK_WIDGET (self); } -/** - * ld_category_view_set_category: - * @self: an #LdCategoryView object. - * @category: (allow-none): the category to be assigned to the widget. - * - * Assign an #LdCategory object to the widget. - */ -void -ld_category_view_set_category (LdCategoryView *self, LdCategory *category) +static void +ld_category_view_set_category (LdCategoryViewIf *iface, LdCategory *category) { - g_return_if_fail (LD_IS_CATEGORY_VIEW (self)); + LdCategoryView *self; + + g_return_if_fail (LD_IS_CATEGORY_VIEW (iface)); g_return_if_fail (LD_IS_CATEGORY (category) || category == NULL); + self = LD_CATEGORY_VIEW (iface); if (self->priv->category) { g_signal_handlers_disconnect_by_func (self->priv->category, @@ -214,18 +178,11 @@ ld_category_view_set_category (LdCategoryView *self, LdCategory *category) g_object_notify (G_OBJECT (self), "category"); } -/** - * ld_category_view_get_category: - * @self: an #LdCategoryView object. - * - * Return value: (transfer none): the #LdCategory object - * assigned to the widget. - */ -LdCategory * -ld_category_view_get_category (LdCategoryView *self) +static LdCategory * +ld_category_view_get_category (LdCategoryViewIf *iface) { - g_return_val_if_fail (LD_IS_CATEGORY_VIEW (self), NULL); - return self->priv->category; + g_return_val_if_fail (LD_IS_CATEGORY_VIEW (iface), NULL); + return LD_CATEGORY_VIEW (iface)->priv->category; } static GtkWidget * @@ -291,7 +248,7 @@ static void on_symbol_selected (GObject *source, LdSymbol *symbol, const gchar *path, LdCategoryView *self) { - g_signal_emit (self, LD_CATEGORY_VIEW_GET_CLASS (self)-> + g_signal_emit (self, LD_CATEGORY_VIEW_IF_GET_INTERFACE (self)-> symbol_selected_signal, 0, symbol, path); } @@ -299,7 +256,7 @@ static void on_symbol_deselected (GObject *source, LdSymbol *symbol, const gchar *path, LdCategoryView *self) { - g_signal_emit (self, LD_CATEGORY_VIEW_GET_CLASS (self)-> + g_signal_emit (self, LD_CATEGORY_VIEW_IF_GET_INTERFACE (self)-> symbol_deselected_signal, 0, symbol, path); } diff --git a/liblogdiag/ld-category-view.h b/liblogdiag/ld-category-view.h index af4904e..b684448 100644 --- a/liblogdiag/ld-category-view.h +++ b/liblogdiag/ld-category-view.h @@ -45,9 +45,6 @@ struct _LdCategoryViewClass { /*< private >*/ GtkVBoxClass parent_class; - - guint symbol_selected_signal; - guint symbol_deselected_signal; }; @@ -55,9 +52,6 @@ GType ld_category_view_get_type (void) G_GNUC_CONST; GtkWidget *ld_category_view_new (LdCategory *category); -void ld_category_view_set_category (LdCategoryView *self, LdCategory *category); -LdCategory *ld_category_view_get_category (LdCategoryView *self); - G_END_DECLS diff --git a/liblogdiag/liblogdiag.h b/liblogdiag/liblogdiag.h index e3b0d90..f3ec94b 100644 --- a/liblogdiag/liblogdiag.h +++ b/liblogdiag/liblogdiag.h @@ -28,6 +28,7 @@ #include "ld-diagram.h" #include "ld-diagram-view.h" +#include "ld-category-view-if.h" #include "ld-category-symbol-view.h" #include "ld-category-view.h" |