1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/* Evolution calendar - Configuration values for the alarm notification daemon
*
* Copyright (C) 2001 Ximian, Inc.
*
* Authors: Federico Mena-Quintero <federico@ximian.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIOH
#include <config.h>
#endif
#include <libedataserver/e-source-list.h>
#include "config-data.h"
#include "save.h"
/* Whether we have initied ourselves by reading the data from the configuration engine */
static gboolean inited = FALSE;
static GConfClient *conf_client = NULL;
static ESourceList *calendar_source_list = NULL, *tasks_source_list = NULL;
/* Copied from ../calendar-config.c; returns whether the locale has 'am' and
* 'pm' strings defined.
*/
static gboolean
locale_supports_12_hour_format (void)
{
char s[16];
time_t t = 0;
strftime (s, sizeof s, "%p", gmtime (&t));
return s[0] != '\0';
}
static void
do_cleanup (void)
{
if (calendar_source_list) {
g_object_unref (calendar_source_list);
calendar_source_list = NULL;
}
if (tasks_source_list) {
g_object_unref (tasks_source_list);
tasks_source_list = NULL;
}
g_object_unref (conf_client);
conf_client = NULL;
inited = FALSE;
}
/* Ensures that the configuration values have been read */
static void
ensure_inited (void)
{
if (inited)
return;
inited = TRUE;
conf_client = gconf_client_get_default ();
if (!GCONF_IS_CLIENT (conf_client)) {
inited = FALSE;
return;
}
g_atexit ((GVoidFunc) do_cleanup);
/* load the sources for calendars and tasks */
calendar_source_list = e_source_list_new_for_gconf (conf_client,
"/apps/evolution/calendar/sources");
tasks_source_list = e_source_list_new_for_gconf (conf_client,
"/apps/evolution/tasks/sources");
}
GConfClient *
config_data_get_listener (void)
{
ensure_inited ();
return conf_client;
}
icaltimezone *
config_data_get_timezone (void)
{
char *location;
icaltimezone *local_timezone;
ensure_inited ();
location = gconf_client_get_string (conf_client,
"/apps/evolution/calendar/display/timezone",
NULL);
if (location && location[0]) {
local_timezone = icaltimezone_get_builtin_timezone (location);
} else {
local_timezone = icaltimezone_get_utc_timezone ();
}
g_free (location);
return local_timezone;
}
gboolean
config_data_get_24_hour_format (void)
{
ensure_inited ();
if (locale_supports_12_hour_format ()) {
return gconf_client_get_bool (conf_client,
"/apps/evolution/calendar/display/use_24hour_format",
NULL);
}
return TRUE;
}
GPtrArray *
config_data_get_calendars_to_load (void)
{
GPtrArray *cals;
GSList *groups, *gl, *sources, *sl;
ensure_inited ();
/* create the array to be returned */
cals = g_ptr_array_new ();
/* process calendar sources */
groups = e_source_list_peek_groups (calendar_source_list);
for (gl = groups; gl != NULL; gl = gl->next) {
sources = e_source_group_peek_sources (E_SOURCE_GROUP (gl->data));
for (sl = sources; sl != NULL; sl = sl->next) {
g_ptr_array_add (cals, sl->data);
}
}
/* process tasks sources */
groups = e_source_list_peek_groups (tasks_source_list);
for (gl = groups; gl != NULL; gl = gl->next) {
sources = e_source_group_peek_sources (E_SOURCE_GROUP (gl->data));
for (sl = sources; sl != NULL; sl = sl->next) {
g_ptr_array_add (cals, sl->data);
}
}
return cals;
}
|