evolution-3.6.4/calendar/gui/calendar-view-factory.c

No issues found

  1 /*
  2  * Evolution calendar - Generic view factory for calendar views
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  *
 18  * Authors:
 19  *		Federico Mena-Quintero <federico@ximian.com>
 20  *
 21  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 22  *
 23  */
 24 
 25 #ifdef HAVE_CONFIG_H
 26 #include <config.h>
 27 #endif
 28 
 29 #include <glib/gi18n.h>
 30 #include "calendar-view-factory.h"
 31 #include "calendar-view.h"
 32 
 33 #define CALENDAR_VIEW_FACTORY_GET_PRIVATE(obj) \
 34 	(G_TYPE_INSTANCE_GET_PRIVATE \
 35 	((obj), TYPE_CALENDAR_VIEW_FACTORY, CalendarViewFactoryPrivate))
 36 
 37 struct _CalendarViewFactoryPrivate {
 38 	/* Type of views created by this factory */
 39 	GnomeCalendarViewType view_type;
 40 };
 41 
 42 static const gchar *
 43 		calendar_view_factory_get_title	(GalViewFactory *factory);
 44 static const gchar *
 45 		calendar_view_factory_get_type_code
 46 						(GalViewFactory *factory);
 47 static GalView *
 48 		calendar_view_factory_new_view	(GalViewFactory *factory,
 49 						 const gchar *name);
 50 
 51 G_DEFINE_TYPE (
 52 	CalendarViewFactory,
 53 	calendar_view_factory,
 54 	GAL_TYPE_VIEW_FACTORY)
 55 
 56 static void
 57 calendar_view_factory_class_init (CalendarViewFactoryClass *class)
 58 {
 59 	GalViewFactoryClass *gal_view_factory_class;
 60 
 61 	g_type_class_add_private (class, sizeof (CalendarViewFactoryPrivate));
 62 
 63 	gal_view_factory_class = GAL_VIEW_FACTORY_CLASS (class);
 64 	gal_view_factory_class->get_title = calendar_view_factory_get_title;
 65 	gal_view_factory_class->get_type_code = calendar_view_factory_get_type_code;
 66 	gal_view_factory_class->new_view = calendar_view_factory_new_view;
 67 }
 68 
 69 static void
 70 calendar_view_factory_init (CalendarViewFactory *cal_view_factory)
 71 {
 72 	cal_view_factory->priv =
 73 		CALENDAR_VIEW_FACTORY_GET_PRIVATE (cal_view_factory);
 74 }
 75 
 76 /* get_title method for the calendar view factory */
 77 static const gchar *
 78 calendar_view_factory_get_title (GalViewFactory *factory)
 79 {
 80 	CalendarViewFactory *cal_view_factory;
 81 	CalendarViewFactoryPrivate *priv;
 82 
 83 	cal_view_factory = CALENDAR_VIEW_FACTORY (factory);
 84 	priv = cal_view_factory->priv;
 85 
 86 	switch (priv->view_type) {
 87 	case GNOME_CAL_DAY_VIEW:
 88 		return _("Day View");
 89 
 90 	case GNOME_CAL_WORK_WEEK_VIEW:
 91 		return _("Work Week View");
 92 
 93 	case GNOME_CAL_WEEK_VIEW:
 94 		return _("Week View");
 95 
 96 	case GNOME_CAL_MONTH_VIEW:
 97 		return _("Month View");
 98 
 99 	default:
100 		g_return_val_if_reached (NULL);
101 	}
102 }
103 
104 /* get_type_code method for the calendar view factory */
105 static const gchar *
106 calendar_view_factory_get_type_code (GalViewFactory *factory)
107 {
108 	CalendarViewFactory *cal_view_factory;
109 	CalendarViewFactoryPrivate *priv;
110 
111 	cal_view_factory = CALENDAR_VIEW_FACTORY (factory);
112 	priv = cal_view_factory->priv;
113 
114 	switch (priv->view_type) {
115 	case GNOME_CAL_DAY_VIEW:
116 		return "day_view";
117 
118 	case GNOME_CAL_WORK_WEEK_VIEW:
119 		return "work_week_view";
120 
121 	case GNOME_CAL_WEEK_VIEW:
122 		return "week_view";
123 
124 	case GNOME_CAL_MONTH_VIEW:
125 		return "month_view";
126 
127 	default:
128 		g_return_val_if_reached (NULL);
129 	}
130 }
131 
132 /* new_view method for the calendar view factory */
133 static GalView *
134 calendar_view_factory_new_view (GalViewFactory *factory,
135                                 const gchar *name)
136 {
137 	CalendarViewFactory *cal_view_factory;
138 	CalendarViewFactoryPrivate *priv;
139 	CalendarView *cal_view;
140 
141 	cal_view_factory = CALENDAR_VIEW_FACTORY (factory);
142 	priv = cal_view_factory->priv;
143 
144 	cal_view = calendar_view_new (priv->view_type, name);
145 	return GAL_VIEW (cal_view);
146 }
147 
148 /**
149  * calendar_view_factory_construct:
150  * @cal_view_factory: A calendar view factory.
151  * @view_type: Type of calendar views that the factory will create.
152  *
153  * Constructs a calendar view factory by setting the type of views it will
154  * create.
155  *
156  * Return value: The same value as @cal_view_factory.
157  **/
158 GalViewFactory *
159 calendar_view_factory_construct (CalendarViewFactory *cal_view_factory,
160                                  GnomeCalendarViewType view_type)
161 {
162 	CalendarViewFactoryPrivate *priv;
163 
164 	g_return_val_if_fail (cal_view_factory != NULL, NULL);
165 	g_return_val_if_fail (IS_CALENDAR_VIEW_FACTORY (cal_view_factory), NULL);
166 
167 	priv = cal_view_factory->priv;
168 
169 	priv->view_type = view_type;
170 
171 	return GAL_VIEW_FACTORY (cal_view_factory);
172 }
173 
174 /**
175  * calendar_view_factory_new:
176  * @view_type: Type of calendar views that the factory will create.
177  *
178  * Creates a new factory for calendar views.
179  *
180  * Return value: A newly-created calendar view factory.
181  **/
182 GalViewFactory *
183 calendar_view_factory_new (GnomeCalendarViewType view_type)
184 {
185 	CalendarViewFactory *cal_view_factory;
186 
187 	cal_view_factory = g_object_new (TYPE_CALENDAR_VIEW_FACTORY, NULL);
188 	return calendar_view_factory_construct (cal_view_factory, view_type);
189 }