diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-07-03 00:30:41 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-07-06 04:40:49 +0800 |
commit | 369daca6146c0e97db0308adb9c64c10ad1cb096 (patch) | |
tree | e0233224891a46527a4933e268dd63db290ad801 | |
parent | a2818bc4eaed3c304a9067b8cf25b4aee345d9b4 (diff) | |
download | gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.tar gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.tar.gz gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.tar.bz2 gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.tar.lz gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.tar.xz gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.tar.zst gsoc2013-evolution-369daca6146c0e97db0308adb9c64c10ad1cb096.zip |
GalView: Store the title string internally.
This replaces the get_title() and set_title() class methods, since
it's silly to defer to subclasses to track a simple string property.
-rw-r--r-- | addressbook/gui/widgets/gal-view-minicard.c | 54 | ||||
-rw-r--r-- | addressbook/gui/widgets/gal-view-minicard.h | 3 | ||||
-rw-r--r-- | calendar/gui/calendar-view.c | 94 | ||||
-rw-r--r-- | calendar/gui/calendar-view.h | 4 | ||||
-rw-r--r-- | e-util/gal-view-etable.c | 30 | ||||
-rw-r--r-- | e-util/gal-view-etable.h | 4 | ||||
-rw-r--r-- | e-util/gal-view-instance.c | 2 | ||||
-rw-r--r-- | e-util/gal-view.c | 40 | ||||
-rw-r--r-- | e-util/gal-view.h | 3 |
9 files changed, 39 insertions, 195 deletions
diff --git a/addressbook/gui/widgets/gal-view-minicard.c b/addressbook/gui/widgets/gal-view-minicard.c index 61cd1444ac..9abf8124c4 100644 --- a/addressbook/gui/widgets/gal-view-minicard.c +++ b/addressbook/gui/widgets/gal-view-minicard.c @@ -59,11 +59,7 @@ view_minicard_finalize (GObject *object) { GalViewMinicard *view = GAL_VIEW_MINICARD (object); - if (view->title != NULL) { - gal_view_minicard_detach (view); - g_free (view->title); - view->title = NULL; - } + gal_view_minicard_detach (view); /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (gal_view_minicard_parent_class)->finalize (object); @@ -110,28 +106,6 @@ view_minicard_save (GalView *view, } static const gchar * -view_minicard_get_title (GalView *view) -{ - GalViewMinicard *view_minicard; - - view_minicard = GAL_VIEW_MINICARD (view); - - return view_minicard->title; -} - -static void -view_minicard_set_title (GalView *view, - const gchar *title) -{ - GalViewMinicard *view_minicard; - - view_minicard = GAL_VIEW_MINICARD (view); - - g_free (view_minicard->title); - view_minicard->title = g_strdup (title); -} - -static const gchar * view_minicard_get_type_code (GalView *view) { return "minicard"; @@ -148,7 +122,6 @@ view_minicard_clone (GalView *view) view_minicard = GAL_VIEW_MINICARD (view); GAL_VIEW_MINICARD (clone)->column_width = view_minicard->column_width; - GAL_VIEW_MINICARD (clone)->title = g_strdup (view_minicard->title); return clone; } @@ -165,8 +138,6 @@ gal_view_minicard_class_init (GalViewMinicardClass *class) gal_view_class = GAL_VIEW_CLASS (class); gal_view_class->load = view_minicard_load; gal_view_class->save = view_minicard_save; - gal_view_class->get_title = view_minicard_get_title; - gal_view_class->set_title = view_minicard_set_title; gal_view_class->get_type_code = view_minicard_get_type_code; gal_view_class->clone = view_minicard_clone; @@ -175,7 +146,6 @@ gal_view_minicard_class_init (GalViewMinicardClass *class) static void gal_view_minicard_init (GalViewMinicard *gvm) { - gvm->title = NULL; gvm->column_width = 225.0; gvm->emvw = NULL; @@ -194,27 +164,7 @@ gal_view_minicard_init (GalViewMinicard *gvm) GalView * gal_view_minicard_new (const gchar *title) { - return gal_view_minicard_construct ( - g_object_new (GAL_TYPE_VIEW_MINICARD, NULL), title); -} - -/** - * gal_view_minicard_construct - * @view: The view to construct. - * @title: The name of the new view. - * - * Constructs the GalViewMinicard. To be used by subclasses and - * language bindings. - * - * Returns: The GalViewMinicard. - */ -GalView * -gal_view_minicard_construct (GalViewMinicard *view, - const gchar *title) -{ - view->title = g_strdup (title); - - return GAL_VIEW (view); + return g_object_new (GAL_TYPE_VIEW_MINICARD, "title", title, NULL); } void diff --git a/addressbook/gui/widgets/gal-view-minicard.h b/addressbook/gui/widgets/gal-view-minicard.h index 04e67113de..4cec9568ca 100644 --- a/addressbook/gui/widgets/gal-view-minicard.h +++ b/addressbook/gui/widgets/gal-view-minicard.h @@ -56,7 +56,6 @@ typedef struct _GalViewMinicardClass GalViewMinicardClass; struct _GalViewMinicard { GalView parent; - gchar *title; gdouble column_width; EMinicardViewWidget *emvw; @@ -69,8 +68,6 @@ struct _GalViewMinicardClass { GType gal_view_minicard_get_type (void); GalView * gal_view_minicard_new (const gchar *title); -GalView * gal_view_minicard_construct (GalViewMinicard *view, - const gchar *title); void gal_view_minicard_attach (GalViewMinicard *view, EAddressbookView *address_view); void gal_view_minicard_detach (GalViewMinicard *view); diff --git a/calendar/gui/calendar-view.c b/calendar/gui/calendar-view.c index 08bac07590..3639d3f7f6 100644 --- a/calendar/gui/calendar-view.c +++ b/calendar/gui/calendar-view.c @@ -35,15 +35,8 @@ struct _CalendarViewPrivate { /* Type of the view */ GnomeCalendarViewType view_type; - - /* Title of the view */ - gchar *title; }; -static void calendar_view_finalize (GObject *object); - -static const gchar *calendar_view_get_title (GalView *view); -static void calendar_view_set_title (GalView *view, const gchar *title); static const gchar *calendar_view_get_type_code (GalView *view); static GalView *calendar_view_clone (GalView *view); @@ -54,19 +47,13 @@ static void calendar_view_class_init (CalendarViewClass *class) { GalViewClass *gal_view_class; - GObjectClass *object_class; g_type_class_add_private (class, sizeof (CalendarViewPrivate)); gal_view_class = (GalViewClass *) class; - object_class = (GObjectClass *) class; - gal_view_class->get_title = calendar_view_get_title; - gal_view_class->set_title = calendar_view_set_title; gal_view_class->get_type_code = calendar_view_get_type_code; gal_view_class->clone = calendar_view_clone; - - object_class->finalize = calendar_view_finalize; } /* Object initialization function for the calendar view */ @@ -76,50 +63,6 @@ calendar_view_init (CalendarView *cal_view) cal_view->priv = CALENDAR_VIEW_GET_PRIVATE (cal_view); } -/* Destroy method for the calendar view */ -static void -calendar_view_finalize (GObject *object) -{ - CalendarViewPrivate *priv; - - priv = CALENDAR_VIEW_GET_PRIVATE (object); - - g_free (priv->title); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (calendar_view_parent_class)->finalize (object); -} - -/* get_title method of the calendar view */ -static const gchar * -calendar_view_get_title (GalView *view) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - - cal_view = CALENDAR_VIEW (view); - priv = cal_view->priv; - - return (const gchar *) priv->title; -} - -/* set_title method of the calendar view */ -static void -calendar_view_set_title (GalView *view, - const gchar *title) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - - cal_view = CALENDAR_VIEW (view); - priv = cal_view->priv; - - if (priv->title) - g_free (priv->title); - - priv->title = g_strdup (title); -} - /* get_type_code method for the calendar view */ static const gchar * calendar_view_get_type_code (GalView *view) @@ -160,41 +103,11 @@ calendar_view_clone (GalView *view) cal_view = CALENDAR_VIEW (view); CALENDAR_VIEW (clone)->priv->view_type = cal_view->priv->view_type; - CALENDAR_VIEW (clone)->priv->title = g_strdup (cal_view->priv->title); return clone; } /** - * calendar_view_construct: - * @cal_view: A calendar view. - * @view_type: The type of calendar view that this object will represent. - * @title: Title for the view. - * - * Constructs a calendar view by setting its view type and title. - * - * Return value: The same value as @cal_view. - **/ -CalendarView * -calendar_view_construct (CalendarView *cal_view, - GnomeCalendarViewType view_type, - const gchar *title) -{ - CalendarViewPrivate *priv; - - g_return_val_if_fail (cal_view != NULL, NULL); - g_return_val_if_fail (IS_CALENDAR_VIEW (cal_view), NULL); - g_return_val_if_fail (title != NULL, NULL); - - priv = cal_view->priv; - - priv->view_type = view_type; - priv->title = g_strdup (title); - - return cal_view; -} - -/** * calendar_view_new: * @view_type: The type of calendar view that this object will represent. * @title: Title for the view. @@ -209,8 +122,11 @@ calendar_view_new (GnomeCalendarViewType view_type, { CalendarView *cal_view; - cal_view = g_object_new (TYPE_CALENDAR_VIEW, NULL); - return calendar_view_construct (cal_view, view_type, title); + cal_view = g_object_new (TYPE_CALENDAR_VIEW, "title", title, NULL); + + cal_view->priv->view_type = view_type; + + return cal_view; } /** diff --git a/calendar/gui/calendar-view.h b/calendar/gui/calendar-view.h index d76f3f5449..00e1eb6ed1 100644 --- a/calendar/gui/calendar-view.h +++ b/calendar/gui/calendar-view.h @@ -52,10 +52,6 @@ typedef struct { GType calendar_view_get_type (void); -CalendarView *calendar_view_construct (CalendarView *cal_view, - GnomeCalendarViewType view_type, - const gchar *title); - CalendarView *calendar_view_new (GnomeCalendarViewType view_type, const gchar *title); diff --git a/e-util/gal-view-etable.c b/e-util/gal-view-etable.c index 53782eefca..747c169d0c 100644 --- a/e-util/gal-view-etable.c +++ b/e-util/gal-view-etable.c @@ -61,20 +61,6 @@ gal_view_etable_save (GalView *view, } static const gchar * -gal_view_etable_get_title (GalView *view) -{ - return GAL_VIEW_ETABLE (view)->title; -} - -static void -gal_view_etable_set_title (GalView *view, - const gchar *title) -{ - g_free (GAL_VIEW_ETABLE (view)->title); - GAL_VIEW_ETABLE (view)->title = g_strdup (title); -} - -static const gchar * gal_view_etable_get_type_code (GalView *view) { return "etable"; @@ -92,7 +78,6 @@ gal_view_etable_clone (GalView *view) gve = GAL_VIEW_ETABLE (view); GAL_VIEW_ETABLE (clone)->spec = g_object_ref (gve->spec); GAL_VIEW_ETABLE (clone)->state = e_table_state_duplicate (gve->state); - GAL_VIEW_ETABLE (clone)->title = g_strdup (gve->title); return clone; } @@ -104,9 +89,6 @@ gal_view_etable_dispose (GObject *object) gal_view_etable_detach (view); - g_free (view->title); - view->title = NULL; - g_clear_object (&view->spec); g_clear_object (&view->state); @@ -126,8 +108,6 @@ gal_view_etable_class_init (GalViewEtableClass *class) gal_view_class = GAL_VIEW_CLASS (class); gal_view_class->load = gal_view_etable_load; gal_view_class->save = gal_view_etable_save; - gal_view_class->get_title = gal_view_etable_get_title; - gal_view_class->set_title = gal_view_etable_set_title; gal_view_class->get_type_code = gal_view_etable_get_type_code; gal_view_class->clone = gal_view_etable_clone; } @@ -155,16 +135,15 @@ gal_view_etable_new (ETableSpecification *spec, g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (spec), NULL); - view = g_object_new (GAL_TYPE_VIEW_ETABLE, NULL); + view = g_object_new (GAL_TYPE_VIEW_ETABLE, "title", title, NULL); - return gal_view_etable_construct (view, spec, title); + return gal_view_etable_construct (view, spec); } /** * gal_view_etable_construct * @view: The view to construct. * @spec: The ETableSpecification that this view will be based upon. - * @title: The name of the new view. * * constructs the GalViewEtable. To be used by subclasses and * language bindings. @@ -173,8 +152,7 @@ gal_view_etable_new (ETableSpecification *spec, */ GalView * gal_view_etable_construct (GalViewEtable *view, - ETableSpecification *spec, - const gchar *title) + ETableSpecification *spec) { g_return_val_if_fail (GAL_IS_VIEW_ETABLE (view), NULL); g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (spec), NULL); @@ -184,8 +162,6 @@ gal_view_etable_construct (GalViewEtable *view, g_clear_object (&view->state); view->state = e_table_state_duplicate (spec->state); - view->title = g_strdup (title); - return GAL_VIEW (view); } diff --git a/e-util/gal-view-etable.h b/e-util/gal-view-etable.h index e304ec00f0..b0e93a2ec3 100644 --- a/e-util/gal-view-etable.h +++ b/e-util/gal-view-etable.h @@ -59,7 +59,6 @@ struct _GalViewEtable { ETableSpecification *spec; ETableState *state; - gchar *title; ETable *table; guint table_state_changed_id; @@ -76,8 +75,7 @@ GType gal_view_etable_get_type (void); GalView * gal_view_etable_new (ETableSpecification *spec, const gchar *title); GalView * gal_view_etable_construct (GalViewEtable *view, - ETableSpecification *spec, - const gchar *title); + ETableSpecification *spec); void gal_view_etable_set_state (GalViewEtable *view, ETableState *state); void gal_view_etable_attach_table (GalViewEtable *view, diff --git a/e-util/gal-view-instance.c b/e-util/gal-view-instance.c index ad66773756..32f8a5fd26 100644 --- a/e-util/gal-view-instance.c +++ b/e-util/gal-view-instance.c @@ -141,7 +141,7 @@ connect_view (GalViewInstance *instance, { if (instance->current_view) disconnect_view (instance); - instance->current_view = view; + instance->current_view = g_object_ref (view); instance->current_title = g_strdup (gal_view_get_title (view)); instance->current_type = g_strdup (gal_view_get_type_code (view)); diff --git a/e-util/gal-view.c b/e-util/gal-view.c index 4fd777182f..7b3743af72 100644 --- a/e-util/gal-view.c +++ b/e-util/gal-view.c @@ -23,7 +23,7 @@ ((obj), GAL_TYPE_VIEW, GalViewPrivate)) struct _GalViewPrivate { - gint placeholder; + gchar *title; }; enum { @@ -82,6 +82,19 @@ view_get_property (GObject *object, } static void +view_finalize (GObject *object) +{ + GalViewPrivate *priv; + + priv = GAL_VIEW_GET_PRIVATE (object); + + g_free (priv->title); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (gal_view_parent_class)->finalize (object); +} + +static void view_load (GalView *view, const gchar *filename) { @@ -96,7 +109,13 @@ view_save (GalView *view, static GalView * view_clone (GalView *view) { - return g_object_new (G_OBJECT_TYPE (view), NULL); + const gchar *title; + + title = gal_view_get_title (view); + + return g_object_new ( + G_OBJECT_TYPE (view), + "title", title, NULL); } static void @@ -109,6 +128,7 @@ gal_view_class_init (GalViewClass *class) object_class = G_OBJECT_CLASS (class); object_class->set_property = view_set_property; object_class->get_property = view_get_property; + object_class->finalize = view_finalize; class->load = view_load; class->save = view_save; @@ -201,14 +221,9 @@ gal_view_save (GalView *view, const gchar * gal_view_get_title (GalView *view) { - GalViewClass *class; - g_return_val_if_fail (GAL_IS_VIEW (view), NULL); - class = GAL_VIEW_GET_CLASS (view); - g_return_val_if_fail (class->get_title != NULL, NULL); - - return class->get_title (view); + return view->priv->title; } /** @@ -220,14 +235,13 @@ void gal_view_set_title (GalView *view, const gchar *title) { - GalViewClass *class; - g_return_if_fail (GAL_IS_VIEW (view)); - class = GAL_VIEW_GET_CLASS (view); - g_return_if_fail (class->set_title != NULL); + if (g_strcmp0 (title, view->priv->title) == 0) + return; - class->set_title (view, title); + g_free (view->priv->title); + view->priv->title = g_strdup (title); g_object_notify (G_OBJECT (view), "title"); } diff --git a/e-util/gal-view.h b/e-util/gal-view.h index 18de6d1ad5..94f89b989e 100644 --- a/e-util/gal-view.h +++ b/e-util/gal-view.h @@ -63,9 +63,6 @@ struct _GalViewClass { const gchar *filename); void (*save) (GalView *view, const gchar *filename); - const gchar * (*get_title) (GalView *view); - void (*set_title) (GalView *view, - const gchar *title); const gchar * (*get_type_code) (GalView *view); GalView * (*clone) (GalView *view); |