aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-03 02:44:14 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-06 04:40:49 +0800
commit3f5f362e0df717f2aaca8d21c3b3e180904a6897 (patch)
tree777bb5c4b968e627e893afd04d66b9189aef6f5f
parent2b9713656b939ec657b8d77932a2a7d147aa1f23 (diff)
downloadgsoc2013-evolution-3f5f362e0df717f2aaca8d21c3b3e180904a6897.tar.gz
gsoc2013-evolution-3f5f362e0df717f2aaca8d21c3b3e180904a6897.tar.zst
gsoc2013-evolution-3f5f362e0df717f2aaca8d21c3b3e180904a6897.zip
Split CalendarView into separate classes by view type.
It's better to have separate classes each with a fixed type code, than one class with a variable type code. You'll see why in the next commit.
-rw-r--r--calendar/gui/calendar-view-factory.c26
-rw-r--r--calendar/gui/calendar-view.c162
-rw-r--r--calendar/gui/calendar-view.h57
-rw-r--r--modules/calendar/e-cal-shell-content.c25
4 files changed, 122 insertions, 148 deletions
diff --git a/calendar/gui/calendar-view-factory.c b/calendar/gui/calendar-view-factory.c
index d84f770141..d975e491de 100644
--- a/calendar/gui/calendar-view-factory.c
+++ b/calendar/gui/calendar-view-factory.c
@@ -101,17 +101,31 @@ calendar_view_factory_get_type_code (GalViewFactory *factory)
/* new_view method for the calendar view factory */
static GalView *
calendar_view_factory_new_view (GalViewFactory *factory,
- const gchar *name)
+ const gchar *title)
{
CalendarViewFactory *cal_view_factory;
- CalendarViewFactoryPrivate *priv;
- CalendarView *cal_view;
+ GType type;
cal_view_factory = CALENDAR_VIEW_FACTORY (factory);
- priv = cal_view_factory->priv;
- cal_view = calendar_view_new (priv->view_type, name);
- return GAL_VIEW (cal_view);
+ switch (cal_view_factory->priv->view_type) {
+ case GNOME_CAL_DAY_VIEW:
+ type = GAL_TYPE_VIEW_CALENDAR_DAY;
+ break;
+ case GNOME_CAL_WORK_WEEK_VIEW:
+ type = GAL_TYPE_VIEW_CALENDAR_WORK_WEEK;
+ break;
+ case GNOME_CAL_WEEK_VIEW:
+ type = GAL_TYPE_VIEW_CALENDAR_WEEK;
+ break;
+ case GNOME_CAL_MONTH_VIEW:
+ type = GAL_TYPE_VIEW_CALENDAR_MONTH;
+ break;
+ default:
+ g_return_val_if_reached (NULL);
+ }
+
+ return g_object_new (type, "title", title, NULL);
}
/**
diff --git a/calendar/gui/calendar-view.c b/calendar/gui/calendar-view.c
index 3639d3f7f6..f373469541 100644
--- a/calendar/gui/calendar-view.c
+++ b/calendar/gui/calendar-view.c
@@ -1,5 +1,5 @@
/*
- * Evolution calendar - Generic view object for calendar views
+ * calendar-view.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,137 +14,95 @@
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
- *
- * Authors:
- * Federico Mena-Quintero <federico@ximian.com>
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include "calendar-view.h"
-#define CALENDAR_VIEW_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE \
- ((obj), TYPE_CALENDAR_VIEW, CalendarViewPrivate))
+G_DEFINE_TYPE (
+ GalViewCalendarDay,
+ gal_view_calendar_day,
+ GAL_TYPE_VIEW)
-struct _CalendarViewPrivate {
- /* Type of the view */
- GnomeCalendarViewType view_type;
-};
+G_DEFINE_TYPE (
+ GalViewCalendarWorkWeek,
+ gal_view_calendar_work_week,
+ GAL_TYPE_VIEW)
-static const gchar *calendar_view_get_type_code (GalView *view);
-static GalView *calendar_view_clone (GalView *view);
+G_DEFINE_TYPE (
+ GalViewCalendarWeek,
+ gal_view_calendar_week,
+ GAL_TYPE_VIEW)
-G_DEFINE_TYPE (CalendarView, calendar_view, GAL_TYPE_VIEW)
+G_DEFINE_TYPE (
+ GalViewCalendarMonth,
+ gal_view_calendar_month,
+ GAL_TYPE_VIEW)
-/* Class initialization function for the calendar view */
-static void
-calendar_view_class_init (CalendarViewClass *class)
+static const gchar *
+gal_view_calendar_day_get_type_code (GalView *view)
{
- GalViewClass *gal_view_class;
-
- g_type_class_add_private (class, sizeof (CalendarViewPrivate));
-
- gal_view_class = (GalViewClass *) class;
+ return "day_view";
+}
- gal_view_class->get_type_code = calendar_view_get_type_code;
- gal_view_class->clone = calendar_view_clone;
+static void
+gal_view_calendar_day_class_init (GalViewClass *class)
+{
+ class->get_type_code = gal_view_calendar_day_get_type_code;
}
-/* Object initialization function for the calendar view */
static void
-calendar_view_init (CalendarView *cal_view)
+gal_view_calendar_day_init (GalView *view)
{
- cal_view->priv = CALENDAR_VIEW_GET_PRIVATE (cal_view);
}
-/* get_type_code method for the calendar view */
static const gchar *
-calendar_view_get_type_code (GalView *view)
+gal_view_calendar_work_week_get_type_code (GalView *view)
{
- CalendarView *cal_view;
- CalendarViewPrivate *priv;
-
- cal_view = CALENDAR_VIEW (view);
- priv = cal_view->priv;
-
- switch (priv->view_type) {
- case GNOME_CAL_DAY_VIEW:
- return "day_view";
-
- case GNOME_CAL_WORK_WEEK_VIEW:
- return "work_week_view";
-
- case GNOME_CAL_WEEK_VIEW:
- return "week_view";
-
- case GNOME_CAL_MONTH_VIEW:
- return "month_view";
-
- default:
- g_return_val_if_reached (NULL);
- }
+ return "work_week_view";
}
-/* clone method for the calendar view */
-static GalView *
-calendar_view_clone (GalView *view)
+static void
+gal_view_calendar_work_week_class_init (GalViewClass *class)
{
- CalendarView *cal_view;
- GalView *clone;
-
- /* Chain up to parent's clone() method. */
- clone = GAL_VIEW_CLASS (calendar_view_parent_class)->clone (view);
-
- cal_view = CALENDAR_VIEW (view);
- CALENDAR_VIEW (clone)->priv->view_type = cal_view->priv->view_type;
-
- return clone;
+ class->get_type_code = gal_view_calendar_work_week_get_type_code;
}
-/**
- * calendar_view_new:
- * @view_type: The type of calendar view that this object will represent.
- * @title: Title for the view.
- *
- * Creates a new calendar view object.
- *
- * Return value: A newly-created calendar view.
- **/
-CalendarView *
-calendar_view_new (GnomeCalendarViewType view_type,
- const gchar *title)
+static void
+gal_view_calendar_work_week_init (GalView *view)
{
- CalendarView *cal_view;
+}
- cal_view = g_object_new (TYPE_CALENDAR_VIEW, "title", title, NULL);
+static const gchar *
+gal_view_calendar_week_get_type_code (GalView *view)
+{
+ return "week_view";
+}
- cal_view->priv->view_type = view_type;
+static void
+gal_view_calendar_week_class_init (GalViewClass *class)
+{
+ class->get_type_code = gal_view_calendar_week_get_type_code;
+}
- return cal_view;
+static void
+gal_view_calendar_week_init (GalView *view)
+{
}
-/**
- * calendar_view_get_view_type:
- * @cal_view: A calendar view.
- *
- * Queries the calendar view type of a calendar view.
- *
- * Return value: Type of calendar view.
- **/
-GnomeCalendarViewType
-calendar_view_get_view_type (CalendarView *cal_view)
+static const gchar *
+gal_view_calendar_month_get_type_code (GalView *view)
{
- CalendarViewPrivate *priv;
+ return "month_view";
+}
- g_return_val_if_fail (cal_view != NULL, GNOME_CAL_DAY_VIEW);
- g_return_val_if_fail (IS_CALENDAR_VIEW (cal_view), GNOME_CAL_DAY_VIEW);
+static void
+gal_view_calendar_month_class_init (GalViewClass *class)
+{
+ class->get_type_code = gal_view_calendar_month_get_type_code;
+}
- priv = cal_view->priv;
- return priv->view_type;
+static void
+gal_view_calendar_month_init (GalView *view)
+{
}
+
diff --git a/calendar/gui/calendar-view.h b/calendar/gui/calendar-view.h
index 00e1eb6ed1..60b41ea0ea 100644
--- a/calendar/gui/calendar-view.h
+++ b/calendar/gui/calendar-view.h
@@ -1,6 +1,5 @@
/*
- *
- * Evolution calendar - Generic view object for calendar views
+ * calendar-view.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -15,48 +14,42 @@
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
- *
- * Authors:
- * Federico Mena-Quintero <federico@ximian.com>
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
*/
#ifndef CALENDAR_VIEW_H
#define CALENDAR_VIEW_H
-#include "gnome-cal.h"
+#include <e-util/e-util.h>
-G_BEGIN_DECLS
-
-#define TYPE_CALENDAR_VIEW (calendar_view_get_type ())
-#define CALENDAR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CALENDAR_VIEW, CalendarView))
-#define CALENDAR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CALENDAR_VIEW, \
- CalendarViewClass))
-#define IS_CALENDAR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CALENDAR_VIEW))
-#define IS_CALENDAR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CALENDAR_VIEW))
+/* Standard GObject macros */
+#define GAL_TYPE_VIEW_CALENDAR_DAY \
+ (gal_view_calendar_day_get_type ())
+#define GAL_TYPE_VIEW_CALENDAR_WORK_WEEK \
+ (gal_view_calendar_work_week_get_type ())
+#define GAL_TYPE_VIEW_CALENDAR_WEEK \
+ (gal_view_calendar_week_get_type ())
+#define GAL_TYPE_VIEW_CALENDAR_MONTH \
+ (gal_view_calendar_month_get_type ())
-typedef struct _CalendarViewPrivate CalendarViewPrivate;
-
-typedef struct {
- GalView view;
+G_BEGIN_DECLS
- /* Private data */
- CalendarViewPrivate *priv;
-} CalendarView;
+typedef struct _GalView GalViewCalendarDay;
+typedef struct _GalViewClass GalViewCalendarDayClass;
-typedef struct {
- GalViewClass parent_class;
-} CalendarViewClass;
+typedef struct _GalView GalViewCalendarWorkWeek;
+typedef struct _GalViewClass GalViewCalendarWorkWeekClass;
-GType calendar_view_get_type (void);
+typedef struct _GalView GalViewCalendarWeek;
+typedef struct _GalViewClass GalViewCalendarWeekClass;
-CalendarView *calendar_view_new (GnomeCalendarViewType view_type,
- const gchar *title);
+typedef struct _GalView GalViewCalendarMonth;
+typedef struct _GalViewClass GalViewCalendarMonthClass;
-GnomeCalendarViewType calendar_view_get_view_type (CalendarView *cal_view);
+GType gal_view_calendar_day_get_type (void) G_GNUC_CONST;
+GType gal_view_calendar_work_week_get_type (void) G_GNUC_CONST;
+GType gal_view_calendar_week_get_type (void) G_GNUC_CONST;
+GType gal_view_calendar_month_get_type (void) G_GNUC_CONST;
G_END_DECLS
-#endif
+#endif /* CALENDAR_VIEW_H */
diff --git a/modules/calendar/e-cal-shell-content.c b/modules/calendar/e-cal-shell-content.c
index 5c91354d51..cccc9993e8 100644
--- a/modules/calendar/e-cal-shell-content.c
+++ b/modules/calendar/e-cal-shell-content.c
@@ -78,15 +78,12 @@ cal_shell_content_display_view_cb (ECalShellContent *cal_shell_content,
{
GnomeCalendar *calendar;
GnomeCalendarViewType view_type;
+ GType gal_view_type;
- /* XXX This is confusing: we have CalendarView and ECalendarView.
- * ECalendarView is an abstract base class for calendar view
- * widgets (day view, week view, etc). CalendarView is a
- * simple GalView subclass that represents a calendar view. */
-
+ gal_view_type = G_OBJECT_TYPE (gal_view);
calendar = e_cal_shell_content_get_calendar (cal_shell_content);
- if (GAL_IS_VIEW_ETABLE (gal_view)) {
+ if (gal_view_type == GAL_TYPE_VIEW_ETABLE) {
ECalendarView *calendar_view;
view_type = GNOME_CAL_LIST_VIEW;
@@ -95,9 +92,21 @@ cal_shell_content_display_view_cb (ECalShellContent *cal_shell_content,
gal_view_etable_attach_table (
GAL_VIEW_ETABLE (gal_view),
E_CAL_LIST_VIEW (calendar_view)->table);
+
+ } else if (gal_view_type == GAL_TYPE_VIEW_CALENDAR_DAY) {
+ view_type = GNOME_CAL_DAY_VIEW;
+
+ } else if (gal_view_type == GAL_TYPE_VIEW_CALENDAR_WORK_WEEK) {
+ view_type = GNOME_CAL_WORK_WEEK_VIEW;
+
+ } else if (gal_view_type == GAL_TYPE_VIEW_CALENDAR_WEEK) {
+ view_type = GNOME_CAL_WEEK_VIEW;
+
+ } else if (gal_view_type == GAL_TYPE_VIEW_CALENDAR_MONTH) {
+ view_type = GNOME_CAL_MONTH_VIEW;
+
} else {
- view_type = calendar_view_get_view_type (
- CALENDAR_VIEW (gal_view));
+ g_return_if_reached ();
}
gnome_calendar_display_view (calendar, view_type);