1 /*
2  * Copyright (C) 2015 Red Hat, Inc. (www.redhat.com)
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #ifndef E_COMP_EDITOR_PROPERTY_PART_H
19 #define E_COMP_EDITOR_PROPERTY_PART_H
20 
21 #include <glib-object.h>
22 #include <gtk/gtk.h>
23 #include <libecal/libecal.h>
24 #include <calendar/gui/e-timezone-entry.h>
25 
26 /* Standard GObject macros */
27 
28 #define E_TYPE_COMP_EDITOR_PROPERTY_PART \
29 	(e_comp_editor_property_part_get_type ())
30 #define E_COMP_EDITOR_PROPERTY_PART(obj) \
31 	(G_TYPE_CHECK_INSTANCE_CAST \
32 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART, ECompEditorPropertyPart))
33 #define E_COMP_EDITOR_PROPERTY_PART_CLASS(cls) \
34 	(G_TYPE_CHECK_CLASS_CAST \
35 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART, ECompEditorPropertyPartClass))
36 #define E_IS_COMP_EDITOR_PROPERTY_PART(obj) \
37 	(G_TYPE_CHECK_INSTANCE_TYPE \
38 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART))
39 #define E_IS_COMP_EDITOR_PROPERTY_PART_CLASS(cls) \
40 	(G_TYPE_CHECK_CLASS_TYPE \
41 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART))
42 #define E_COMP_EDITOR_PROPERTY_PART_GET_CLASS(obj) \
43 	(G_TYPE_INSTANCE_GET_CLASS \
44 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART, ECompEditorPropertyPartClass))
45 
46 /* ************************************************************************* */
47 
48 #define E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING \
49 	(e_comp_editor_property_part_string_get_type ())
50 #define E_COMP_EDITOR_PROPERTY_PART_STRING(obj) \
51 	(G_TYPE_CHECK_INSTANCE_CAST \
52 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING, ECompEditorPropertyPartString))
53 #define E_COMP_EDITOR_PROPERTY_PART_STRING_CLASS(cls) \
54 	(G_TYPE_CHECK_CLASS_CAST \
55 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING, ECompEditorPropertyPartStringClass))
56 #define E_IS_COMP_EDITOR_PROPERTY_PART_STRING(obj) \
57 	(G_TYPE_CHECK_INSTANCE_TYPE \
58 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING))
59 #define E_IS_COMP_EDITOR_PROPERTY_PART_STRING_CLASS(cls) \
60 	(G_TYPE_CHECK_CLASS_TYPE \
61 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING))
62 #define E_COMP_EDITOR_PROPERTY_PART_STRING_GET_CLASS(obj) \
63 	(G_TYPE_INSTANCE_GET_CLASS \
64 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING, ECompEditorPropertyPartStringClass))
65 
66 /* ************************************************************************* */
67 
68 #define E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME \
69 	(e_comp_editor_property_part_datetime_get_type ())
70 #define E_COMP_EDITOR_PROPERTY_PART_DATETIME(obj) \
71 	(G_TYPE_CHECK_INSTANCE_CAST \
72 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME, ECompEditorPropertyPartDatetime))
73 #define E_COMP_EDITOR_PROPERTY_PART_DATETIME_CLASS(cls) \
74 	(G_TYPE_CHECK_CLASS_CAST \
75 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME, ECompEditorPropertyPartDatetimeClass))
76 #define E_IS_COMP_EDITOR_PROPERTY_PART_DATETIME(obj) \
77 	(G_TYPE_CHECK_INSTANCE_TYPE \
78 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME))
79 #define E_IS_COMP_EDITOR_PROPERTY_PART_DATETIME_CLASS(cls) \
80 	(G_TYPE_CHECK_CLASS_TYPE \
81 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME))
82 #define E_COMP_EDITOR_PROPERTY_PART_DATETIME_GET_CLASS(obj) \
83 	(G_TYPE_INSTANCE_GET_CLASS \
84 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME, ECompEditorPropertyPartDatetimeClass))
85 
86 /* ************************************************************************* */
87 
88 #define E_TYPE_COMP_EDITOR_PROPERTY_PART_SPIN \
89 	(e_comp_editor_property_part_spin_get_type ())
90 #define E_COMP_EDITOR_PROPERTY_PART_SPIN(obj) \
91 	(G_TYPE_CHECK_INSTANCE_CAST \
92 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_SPIN, ECompEditorPropertyPartSpin))
93 #define E_COMP_EDITOR_PROPERTY_PART_SPIN_CLASS(cls) \
94 	(G_TYPE_CHECK_CLASS_CAST \
95 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_SPIN, ECompEditorPropertyPartSpinClass))
96 #define E_IS_COMP_EDITOR_PROPERTY_PART_SPIN(obj) \
97 	(G_TYPE_CHECK_INSTANCE_TYPE \
98 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_SPIN))
99 #define E_IS_COMP_EDITOR_PROPERTY_PART_SPIN_CLASS(cls) \
100 	(G_TYPE_CHECK_CLASS_TYPE \
101 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_SPIN))
102 #define E_COMP_EDITOR_PROPERTY_PART_SPIN_GET_CLASS(obj) \
103 	(G_TYPE_INSTANCE_GET_CLASS \
104 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_SPIN, ECompEditorPropertyPartSpinClass))
105 
106 /* ************************************************************************* */
107 
108 #define E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER \
109 	(e_comp_editor_property_part_picker_get_type ())
110 #define E_COMP_EDITOR_PROPERTY_PART_PICKER(obj) \
111 	(G_TYPE_CHECK_INSTANCE_CAST \
112 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER, ECompEditorPropertyPartPicker))
113 #define E_COMP_EDITOR_PROPERTY_PART_PICKER_CLASS(cls) \
114 	(G_TYPE_CHECK_CLASS_CAST \
115 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER, ECompEditorPropertyPartPickerClass))
116 #define E_IS_COMP_EDITOR_PROPERTY_PART_PICKER(obj) \
117 	(G_TYPE_CHECK_INSTANCE_TYPE \
118 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER))
119 #define E_IS_COMP_EDITOR_PROPERTY_PART_PICKER_CLASS(cls) \
120 	(G_TYPE_CHECK_CLASS_TYPE \
121 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER))
122 #define E_COMP_EDITOR_PROPERTY_PART_PICKER_GET_CLASS(obj) \
123 	(G_TYPE_INSTANCE_GET_CLASS \
124 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER, ECompEditorPropertyPartPickerClass))
125 
126 /* ************************************************************************* */
127 
128 #define E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP \
129 	(e_comp_editor_property_part_picker_with_map_get_type ())
130 #define E_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP(obj) \
131 	(G_TYPE_CHECK_INSTANCE_CAST \
132 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP, ECompEditorPropertyPartPickerWithMap))
133 #define E_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP_CLASS(cls) \
134 	(G_TYPE_CHECK_CLASS_CAST \
135 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP, ECompEditorPropertyPartPickerWithMapClass))
136 #define E_IS_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP(obj) \
137 	(G_TYPE_CHECK_INSTANCE_TYPE \
138 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP))
139 #define E_IS_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP_CLASS(cls) \
140 	(G_TYPE_CHECK_CLASS_TYPE \
141 	((cls), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP))
142 #define E_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP_GET_CLASS(obj) \
143 	(G_TYPE_INSTANCE_GET_CLASS \
144 	((obj), E_TYPE_COMP_EDITOR_PROPERTY_PART_PICKER_WITH_MAP, ECompEditorPropertyPartPickerWithMapClass))
145 
146 /* ************************************************************************* */
147 
148 G_BEGIN_DECLS
149 
150 typedef struct _ECompEditorPropertyPart ECompEditorPropertyPart;
151 typedef struct _ECompEditorPropertyPartClass ECompEditorPropertyPartClass;
152 typedef struct _ECompEditorPropertyPartPrivate ECompEditorPropertyPartPrivate;
153 
154 struct _ECompEditorPropertyPart {
155 	GObject parent;
156 
157 	ECompEditorPropertyPartPrivate *priv;
158 };
159 
160 struct _ECompEditorPropertyPartClass {
161 	GObjectClass parent_class;
162 
163 	/* Virtual functions */
164 	void		(* create_widgets)	(ECompEditorPropertyPart *property_part,
165 						 GtkWidget **out_label_widget,
166 						 GtkWidget **out_edit_widget);
167 	void		(* fill_widget)		(ECompEditorPropertyPart *property_part,
168 						 ICalComponent *component);
169 	void		(* fill_component)	(ECompEditorPropertyPart *property_part,
170 						 ICalComponent *component);
171 	void		(* sensitize_widgets)	(ECompEditorPropertyPart *property_part,
172 						 gboolean force_insensitive);
173 
174 	/* Signals */
175 	void		(* changed)		(ECompEditorPropertyPart *property_part);
176 };
177 
178 GType		e_comp_editor_property_part_get_type		(void) G_GNUC_CONST;
179 gboolean	e_comp_editor_property_part_get_visible		(ECompEditorPropertyPart *property_part);
180 void		e_comp_editor_property_part_set_visible		(ECompEditorPropertyPart *property_part,
181 								 gboolean visible);
182 gboolean	e_comp_editor_property_part_get_sensitize_handled
183 								(ECompEditorPropertyPart *property_part);
184 void		e_comp_editor_property_part_set_sensitize_handled
185 								(ECompEditorPropertyPart *property_part,
186 								 gboolean sensitize_handled);
187 void		e_comp_editor_property_part_create_widgets	(ECompEditorPropertyPart *property_part,
188 								 GtkWidget **out_label_widget,
189 								 GtkWidget **out_edit_widget);
190 GtkWidget *	e_comp_editor_property_part_get_label_widget	(ECompEditorPropertyPart *property_part);
191 GtkWidget *	e_comp_editor_property_part_get_edit_widget	(ECompEditorPropertyPart *property_part);
192 void		e_comp_editor_property_part_fill_widget		(ECompEditorPropertyPart *property_part,
193 								 ICalComponent *component);
194 void		e_comp_editor_property_part_fill_component	(ECompEditorPropertyPart *property_part,
195 								 ICalComponent *component);
196 void		e_comp_editor_property_part_sensitize_widgets	(ECompEditorPropertyPart *property_part,
197 								 gboolean force_insensitive);
198 void		e_comp_editor_property_part_emit_changed	(ECompEditorPropertyPart *property_part);
199 
200 /* ************************************************************************* */
201 
202 typedef struct _ECompEditorPropertyPartString ECompEditorPropertyPartString;
203 typedef struct _ECompEditorPropertyPartStringClass ECompEditorPropertyPartStringClass;
204 typedef struct _ECompEditorPropertyPartStringPrivate ECompEditorPropertyPartStringPrivate;
205 
206 struct _ECompEditorPropertyPartString {
207 	ECompEditorPropertyPart parent;
208 
209 	ECompEditorPropertyPartStringPrivate *priv;
210 };
211 
212 struct _ECompEditorPropertyPartStringClass {
213 	ECompEditorPropertyPartClass parent_class;
214 
215 	/* What entry GType (derived from GtkEntry or GtkTextView) should be used;
216 	   the default is the GtkEntry */
217 	GType entry_type;
218 
219 	/* ICal property kind and its manipulation functions */
220 	ICalPropertyKind prop_kind;
221 	ICalProperty *	(* i_cal_new_func)	(const gchar *value);
222 	void		(* i_cal_set_func)	(ICalProperty *prop,
223 						 const gchar *value);
224 	const gchar *	(* i_cal_get_func)	(ICalProperty *prop);
225 
226 	GtkWidget *	(* get_real_edit_widget)(ECompEditorPropertyPartString *part_string);
227 };
228 
229 GType		e_comp_editor_property_part_string_get_type	(void) G_GNUC_CONST;
230 void		e_comp_editor_property_part_string_attach_focus_tracker
231 								(ECompEditorPropertyPartString *part_string,
232 								 EFocusTracker *focus_tracker);
233 void		e_comp_editor_property_part_string_set_is_multivalue
234 								(ECompEditorPropertyPartString *part_string,
235 								 gboolean is_multivalue);
236 gboolean	e_comp_editor_property_part_string_is_multivalue
237 								(ECompEditorPropertyPartString *part_string);
238 GtkWidget *	e_comp_editor_property_part_string_get_real_edit_widget
239 								(ECompEditorPropertyPartString *part_string);
240 
241 /* ************************************************************************* */
242 
243 typedef struct _ECompEditorPropertyPartDatetime ECompEditorPropertyPartDatetime;
244 typedef struct _ECompEditorPropertyPartDatetimeClass ECompEditorPropertyPartDatetimeClass;
245 typedef struct _ECompEditorPropertyPartDatetimePrivate ECompEditorPropertyPartDatetimePrivate;
246 
247 struct _ECompEditorPropertyPartDatetime {
248 	ECompEditorPropertyPart parent;
249 
250 	ECompEditorPropertyPartDatetimePrivate *priv;
251 };
252 
253 struct _ECompEditorPropertyPartDatetimeClass {
254 	ECompEditorPropertyPartClass parent_class;
255 
256 	/* ICal property kind and its manipulation functions */
257 	ICalPropertyKind prop_kind;
258 	ICalProperty *	(* i_cal_new_func)	(ICalTime *value);
259 	void		(* i_cal_set_func)	(ICalProperty *prop,
260 						 ICalTime *value);
261 	ICalTime *	(* i_cal_get_func)	(ICalProperty *prop);
262 };
263 
264 GType		e_comp_editor_property_part_datetime_get_type	(void) G_GNUC_CONST;
265 void		e_comp_editor_property_part_datetime_attach_timezone_entry
266 								(ECompEditorPropertyPartDatetime *part_datetime,
267 								 ETimezoneEntry *timezone_entry);
268 void		e_comp_editor_property_part_datetime_set_date_only
269 								(ECompEditorPropertyPartDatetime *part_datetime,
270 								 gboolean date_only);
271 gboolean	e_comp_editor_property_part_datetime_get_date_only
272 								(ECompEditorPropertyPartDatetime *part_datetime);
273 void		e_comp_editor_property_part_datetime_set_allow_no_date_set
274 								(ECompEditorPropertyPartDatetime *part_datetime,
275 								 gboolean allow_no_date_set);
276 gboolean	e_comp_editor_property_part_datetime_get_allow_no_date_set
277 								(ECompEditorPropertyPartDatetime *part_datetime);
278 void		e_comp_editor_property_part_datetime_set_value	(ECompEditorPropertyPartDatetime *part_datetime,
279 								 const ICalTime *value);
280 ICalTime *	e_comp_editor_property_part_datetime_get_value	(ECompEditorPropertyPartDatetime *part_datetime);
281 gboolean	e_comp_editor_property_part_datetime_check_validity
282 								(ECompEditorPropertyPartDatetime *part_datetime,
283 								 gboolean *out_date_is_valid,
284 								 gboolean *out_time_is_valid);
285 
286 /* ************************************************************************* */
287 
288 typedef struct _ECompEditorPropertyPartSpin ECompEditorPropertyPartSpin;
289 typedef struct _ECompEditorPropertyPartSpinClass ECompEditorPropertyPartSpinClass;
290 typedef struct _ECompEditorPropertyPartSpinPrivate ECompEditorPropertyPartSpinPrivate;
291 
292 struct _ECompEditorPropertyPartSpin {
293 	ECompEditorPropertyPart parent;
294 
295 	ECompEditorPropertyPartSpinPrivate *priv;
296 };
297 
298 struct _ECompEditorPropertyPartSpinClass {
299 	ECompEditorPropertyPartClass parent_class;
300 
301 	/* ICal property kind and its manipulation functions */
302 	ICalPropertyKind prop_kind;
303 	ICalProperty *	(* i_cal_new_func)	(gint value);
304 	void		(* i_cal_set_func)	(ICalProperty *prop,
305 						 gint value);
306 	gint		(* i_cal_get_func)	(ICalProperty *prop);
307 };
308 
309 GType		e_comp_editor_property_part_spin_get_type	(void) G_GNUC_CONST;
310 void		e_comp_editor_property_part_spin_set_range	(ECompEditorPropertyPartSpin *part_spin,
311 								 gint min_value,
312 								 gint max_value);
313 void		e_comp_editor_property_part_spin_get_range	(ECompEditorPropertyPartSpin *part_spin,
314 								 gint *out_min_value,
315 								 gint *out_max_value);
316 
317 /* ************************************************************************* */
318 
319 typedef struct _ECompEditorPropertyPartPicker ECompEditorPropertyPartPicker;
320 typedef struct _ECompEditorPropertyPartPickerClass ECompEditorPropertyPartPickerClass;
321 typedef struct _ECompEditorPropertyPartPickerPrivate ECompEditorPropertyPartPickerPrivate;
322 
323 struct _ECompEditorPropertyPartPicker {
324 	ECompEditorPropertyPart parent;
325 
326 	ECompEditorPropertyPartPickerPrivate *priv;
327 };
328 
329 struct _ECompEditorPropertyPartPickerClass {
330 	ECompEditorPropertyPartClass parent_class;
331 
332 	void		(* get_values)		(ECompEditorPropertyPartPicker *part_picker,
333 						 GSList **out_ids,
334 						 GSList **out_display_names);
335 	gboolean	(* get_from_component)	(ECompEditorPropertyPartPicker *part_picker,
336 						 ICalComponent *component,
337 						 gchar **out_id);
338 	void		(* set_to_component)	(ECompEditorPropertyPartPicker *part_picker,
339 						 const gchar *id,
340 						 ICalComponent *component);
341 };
342 
343 GType		e_comp_editor_property_part_picker_get_type	(void) G_GNUC_CONST;
344 void		e_comp_editor_property_part_picker_get_values	(ECompEditorPropertyPartPicker *part_picker,
345 								 GSList **out_ids,
346 								 GSList **out_display_names);
347 gboolean	e_comp_editor_property_part_picker_get_from_component
348 								(ECompEditorPropertyPartPicker *part_picker,
349 								 ICalComponent *component,
350 								 gchar **out_id);
351 void		e_comp_editor_property_part_picker_set_to_component
352 								(ECompEditorPropertyPartPicker *part_picker,
353 								 const gchar *id,
354 								 ICalComponent *component);
355 const gchar *	e_comp_editor_property_part_picker_get_selected_id
356 								(ECompEditorPropertyPartPicker *part_picker);
357 void		e_comp_editor_property_part_picker_set_selected_id
358 								(ECompEditorPropertyPartPicker *part_picker,
359 								 const gchar *id);
360 
361 /* ************************************************************************* */
362 
363 typedef struct _ECompEditorPropertyPartPickerWithMap ECompEditorPropertyPartPickerWithMap;
364 typedef struct _ECompEditorPropertyPartPickerWithMapClass ECompEditorPropertyPartPickerWithMapClass;
365 typedef struct _ECompEditorPropertyPartPickerWithMapPrivate ECompEditorPropertyPartPickerWithMapPrivate;
366 
367 typedef struct _ECompEditorPropertyPartPickerMap {
368 	gint value; 		  /* ICal enum value */
369 	const gchar *description; /* user visible description of the value */
370 	gboolean delete_prop;	  /* whether to delete property from the component when this one is selected */
371 	gboolean (*matches_func) (gint map_value, gint component_value); /* can be NULL, then 'equal' compare is done */
372 } ECompEditorPropertyPartPickerMap;
373 
374 typedef ICalProperty *	(* ECompEditorPropertyPartPickerMapICalNewFunc)	(gint value);
375 typedef void		(* ECompEditorPropertyPartPickerMapICalSetFunc)	(ICalProperty *prop,
376 									 gint value);
377 typedef gint		(* ECompEditorPropertyPartPickerMapICalGetFunc)	(ICalProperty *prop);
378 
379 struct _ECompEditorPropertyPartPickerWithMap {
380 	ECompEditorPropertyPartPicker parent;
381 
382 	ECompEditorPropertyPartPickerWithMapPrivate *priv;
383 };
384 
385 struct _ECompEditorPropertyPartPickerWithMapClass {
386 	ECompEditorPropertyPartPickerClass parent_class;
387 };
388 
389 GType		e_comp_editor_property_part_picker_with_map_get_type
390 								(void) G_GNUC_CONST;
391 ECompEditorPropertyPart *
392 		e_comp_editor_property_part_picker_with_map_new	(const ECompEditorPropertyPartPickerMap map[],
393 								 gint n_map_elements,
394 								 const gchar *label,
395 								 ICalPropertyKind prop_kind,
396 								 ECompEditorPropertyPartPickerMapICalNewFunc i_cal_new_func,
397 								 ECompEditorPropertyPartPickerMapICalSetFunc i_cal_set_func,
398 								 ECompEditorPropertyPartPickerMapICalGetFunc i_cal_get_func);
399 gint		e_comp_editor_property_part_picker_with_map_get_selected
400 								(ECompEditorPropertyPartPickerWithMap *part_picker_with_map);
401 void		e_comp_editor_property_part_picker_with_map_set_selected
402 								(ECompEditorPropertyPartPickerWithMap *part_picker_with_map,
403 								 gint value);
404 
405 /* ************************************************************************* */
406 
407 G_END_DECLS
408 
409 #endif /* E_COMP_EDITOR_PROPERTY_PART_H */
410