1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4 *
5 * This library is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Chris Toshok (toshok@ximian.com)
18 */
19
20 /**
21 * SECTION: e-cal-backend-factory
22 * @include: libedata-cal/libedata-cal.h
23 * @short_description: The factory for creating new calendars
24 *
25 * This class handles creation of new calendars of various
26 * backend types.
27 **/
28
29 #include "evolution-data-server-config.h"
30
31 #include <string.h>
32
33 #include "e-cal-backend.h"
34 #include "e-cal-backend-factory.h"
35 #include "e-data-cal-factory.h"
36
G_DEFINE_ABSTRACT_TYPE(ECalBackendFactory,e_cal_backend_factory,E_TYPE_BACKEND_FACTORY)37 G_DEFINE_ABSTRACT_TYPE (
38 ECalBackendFactory,
39 e_cal_backend_factory,
40 E_TYPE_BACKEND_FACTORY)
41
42 static EDataCalFactory *
43 cal_backend_factory_get_data_factory (EBackendFactory *factory)
44 {
45 EExtensible *extensible;
46
47 extensible = e_extension_get_extensible (E_EXTENSION (factory));
48
49 return E_DATA_CAL_FACTORY (extensible);
50 }
51
52 static const gchar *
cal_backend_factory_get_hash_key(EBackendFactory * factory)53 cal_backend_factory_get_hash_key (EBackendFactory *factory)
54 {
55 ECalBackendFactoryClass *class;
56 const gchar *component_name;
57 gchar *hash_key;
58 gsize length;
59
60 class = E_CAL_BACKEND_FACTORY_GET_CLASS (factory);
61 g_return_val_if_fail (class->factory_name != NULL, NULL);
62
63 switch (class->component_kind) {
64 case I_CAL_VEVENT_COMPONENT:
65 component_name = E_SOURCE_EXTENSION_CALENDAR;
66 break;
67 case I_CAL_VTODO_COMPONENT:
68 component_name = E_SOURCE_EXTENSION_TASK_LIST;
69 break;
70 case I_CAL_VJOURNAL_COMPONENT:
71 component_name = E_SOURCE_EXTENSION_MEMO_LIST;
72 break;
73 default:
74 g_return_val_if_reached (NULL);
75 }
76
77 /* Hash Key: FACTORY_NAME ':' COMPONENT_NAME */
78 length = strlen (class->factory_name) + strlen (component_name) + 2;
79 hash_key = g_alloca (length);
80 g_snprintf (
81 hash_key, length, "%s:%s",
82 class->factory_name, component_name);
83
84 return g_intern_string (hash_key);
85 }
86
87 static EBackend *
cal_backend_factory_new_backend(EBackendFactory * factory,ESource * source)88 cal_backend_factory_new_backend (EBackendFactory *factory,
89 ESource *source)
90 {
91 ECalBackendFactoryClass *class;
92 EDataCalFactory *data_factory;
93 ESourceRegistry *registry;
94
95 class = E_CAL_BACKEND_FACTORY_GET_CLASS (factory);
96 g_return_val_if_fail (g_type_is_a (
97 class->backend_type, E_TYPE_CAL_BACKEND), NULL);
98
99 data_factory = cal_backend_factory_get_data_factory (factory);
100 registry = e_data_factory_get_registry (E_DATA_FACTORY (data_factory));
101
102 return g_object_new (
103 class->backend_type,
104 "kind", class->component_kind,
105 "registry", registry,
106 "source", source, NULL);
107 }
108
109 static void
e_cal_backend_factory_class_init(ECalBackendFactoryClass * class)110 e_cal_backend_factory_class_init (ECalBackendFactoryClass *class)
111 {
112 EExtensionClass *extension_class;
113 EBackendFactoryClass *factory_class;
114
115 extension_class = E_EXTENSION_CLASS (class);
116 extension_class->extensible_type = E_TYPE_DATA_CAL_FACTORY;
117
118 factory_class = E_BACKEND_FACTORY_CLASS (class);
119 factory_class->get_hash_key = cal_backend_factory_get_hash_key;
120 factory_class->new_backend = cal_backend_factory_new_backend;
121 }
122
123 static void
e_cal_backend_factory_init(ECalBackendFactory * factory)124 e_cal_backend_factory_init (ECalBackendFactory *factory)
125 {
126 }
127