No issues found
1 /*
2 * Evolution calendar - Generic view object 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 "calendar-view.h"
30
31 #define CALENDAR_VIEW_GET_PRIVATE(obj) \
32 (G_TYPE_INSTANCE_GET_PRIVATE \
33 ((obj), TYPE_CALENDAR_VIEW, CalendarViewPrivate))
34
35 struct _CalendarViewPrivate {
36 /* Type of the view */
37 GnomeCalendarViewType view_type;
38
39 /* Title of the view */
40 gchar *title;
41 };
42
43 static void calendar_view_finalize (GObject *object);
44
45 static void calendar_view_load (GalView *view, const gchar *filename);
46 static void calendar_view_save (GalView *view, const gchar *filename);
47 static const gchar *calendar_view_get_title (GalView *view);
48 static void calendar_view_set_title (GalView *view, const gchar *title);
49 static const gchar *calendar_view_get_type_code (GalView *view);
50 static GalView *calendar_view_clone (GalView *view);
51
52 G_DEFINE_TYPE (CalendarView, calendar_view, GAL_TYPE_VIEW)
53
54 /* Class initialization function for the calendar view */
55 static void
56 calendar_view_class_init (CalendarViewClass *class)
57 {
58 GalViewClass *gal_view_class;
59 GObjectClass *object_class;
60
61 g_type_class_add_private (class, sizeof (CalendarViewPrivate));
62
63 gal_view_class = (GalViewClass *) class;
64 object_class = (GObjectClass *) class;
65
66 gal_view_class->edit = NULL;
67 gal_view_class->load = calendar_view_load;
68 gal_view_class->save = calendar_view_save;
69 gal_view_class->get_title = calendar_view_get_title;
70 gal_view_class->set_title = calendar_view_set_title;
71 gal_view_class->get_type_code = calendar_view_get_type_code;
72 gal_view_class->clone = calendar_view_clone;
73
74 object_class->finalize = calendar_view_finalize;
75 }
76
77 /* Object initialization function for the calendar view */
78 static void
79 calendar_view_init (CalendarView *cal_view)
80 {
81 cal_view->priv = CALENDAR_VIEW_GET_PRIVATE (cal_view);
82 }
83
84 /* Destroy method for the calendar view */
85 static void
86 calendar_view_finalize (GObject *object)
87 {
88 CalendarViewPrivate *priv;
89
90 priv = CALENDAR_VIEW_GET_PRIVATE (object);
91
92 g_free (priv->title);
93
94 /* Chain up to parent's finalize() method. */
95 G_OBJECT_CLASS (calendar_view_parent_class)->finalize (object);
96 }
97
98 /* load method of the calendar view */
99 static void
100 calendar_view_load (GalView *view,
101 const gchar *filename)
102 {
103 /* nothing */
104 }
105
106 /* save method of the calendar view */
107 static void
108 calendar_view_save (GalView *view,
109 const gchar *filename)
110 {
111 /* nothing */
112 }
113
114 /* get_title method of the calendar view */
115 static const gchar *
116 calendar_view_get_title (GalView *view)
117 {
118 CalendarView *cal_view;
119 CalendarViewPrivate *priv;
120
121 cal_view = CALENDAR_VIEW (view);
122 priv = cal_view->priv;
123
124 return (const gchar *) priv->title;
125 }
126
127 /* set_title method of the calendar view */
128 static void
129 calendar_view_set_title (GalView *view,
130 const gchar *title)
131 {
132 CalendarView *cal_view;
133 CalendarViewPrivate *priv;
134
135 cal_view = CALENDAR_VIEW (view);
136 priv = cal_view->priv;
137
138 if (priv->title)
139 g_free (priv->title);
140
141 priv->title = g_strdup (title);
142 }
143
144 /* get_type_code method for the calendar view */
145 static const gchar *
146 calendar_view_get_type_code (GalView *view)
147 {
148 CalendarView *cal_view;
149 CalendarViewPrivate *priv;
150
151 cal_view = CALENDAR_VIEW (view);
152 priv = cal_view->priv;
153
154 switch (priv->view_type) {
155 case GNOME_CAL_DAY_VIEW:
156 return "day_view";
157
158 case GNOME_CAL_WORK_WEEK_VIEW:
159 return "work_week_view";
160
161 case GNOME_CAL_WEEK_VIEW:
162 return "week_view";
163
164 case GNOME_CAL_MONTH_VIEW:
165 return "month_view";
166
167 default:
168 g_return_val_if_reached (NULL);
169 }
170 }
171
172 /* clone method for the calendar view */
173 static GalView *
174 calendar_view_clone (GalView *view)
175 {
176 CalendarView *cal_view;
177 CalendarViewPrivate *priv;
178 CalendarView *new_view;
179 CalendarViewPrivate *new_priv;
180
181 cal_view = CALENDAR_VIEW (view);
182 priv = cal_view->priv;
183
184 new_view = g_object_new (TYPE_CALENDAR_VIEW, NULL);
185 new_priv = new_view->priv;
186
187 new_priv->view_type = priv->view_type;
188 new_priv->title = g_strdup (priv->title);
189
190 return GAL_VIEW (new_view);
191 }
192
193 /**
194 * calendar_view_construct:
195 * @cal_view: A calendar view.
196 * @view_type: The type of calendar view that this object will represent.
197 * @title: Title for the view.
198 *
199 * Constructs a calendar view by setting its view type and title.
200 *
201 * Return value: The same value as @cal_view.
202 **/
203 CalendarView *
204 calendar_view_construct (CalendarView *cal_view,
205 GnomeCalendarViewType view_type,
206 const gchar *title)
207 {
208 CalendarViewPrivate *priv;
209
210 g_return_val_if_fail (cal_view != NULL, NULL);
211 g_return_val_if_fail (IS_CALENDAR_VIEW (cal_view), NULL);
212 g_return_val_if_fail (title != NULL, NULL);
213
214 priv = cal_view->priv;
215
216 priv->view_type = view_type;
217 priv->title = g_strdup (title);
218
219 return cal_view;
220 }
221
222 /**
223 * calendar_view_new:
224 * @view_type: The type of calendar view that this object will represent.
225 * @title: Title for the view.
226 *
227 * Creates a new calendar view object.
228 *
229 * Return value: A newly-created calendar view.
230 **/
231 CalendarView *
232 calendar_view_new (GnomeCalendarViewType view_type,
233 const gchar *title)
234 {
235 CalendarView *cal_view;
236
237 cal_view = g_object_new (TYPE_CALENDAR_VIEW, NULL);
238 return calendar_view_construct (cal_view, view_type, title);
239 }
240
241 /**
242 * calendar_view_get_view_type:
243 * @cal_view: A calendar view.
244 *
245 * Queries the calendar view type of a calendar view.
246 *
247 * Return value: Type of calendar view.
248 **/
249 GnomeCalendarViewType
250 calendar_view_get_view_type (CalendarView *cal_view)
251 {
252 CalendarViewPrivate *priv;
253
254 g_return_val_if_fail (cal_view != NULL, GNOME_CAL_DAY_VIEW);
255 g_return_val_if_fail (IS_CALENDAR_VIEW (cal_view), GNOME_CAL_DAY_VIEW);
256
257 priv = cal_view->priv;
258 return priv->view_type;
259 }