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
|
/*
* e-timezone-cache.c
*
* This library is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This library 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* SECTION: e-timezone-cache
* @include: libecal/libecal.h
* @short_description: An interface for caching time zone data
*
* Several classes (both client-side and server-side) cache #icaltimezone
* instances internally, indexed by their TZID strings. Classes which do
* this should implement #ETimezoneCacheInterface to provide a consistent
* API for accessing time zone data.
**/
#include "e-timezone-cache.h"
G_DEFINE_INTERFACE (
ETimezoneCache,
e_timezone_cache,
G_TYPE_OBJECT)
static void
e_timezone_cache_default_init (ETimezoneCacheInterface *iface)
{
/**
* ETimezoneCache::timezone-added:
* @cache: the #ETimezoneCache which emitted the signal
* @zone: the newly-added #icaltimezone
*
* Emitted when a new #icaltimezone is added to @cache.
**/
g_signal_new (
"timezone-added",
G_OBJECT_CLASS_TYPE (iface),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (ETimezoneCacheInterface, timezone_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
}
/**
* e_timezone_cache_add_timezone:
* @cache: an #ETimezoneCache
* @zone: an #icaltimezone
*
* Adds a copy of @zone to @cache and emits a
* #ETimezoneCache::timezone-added signal. The @cache will use the TZID
* string returned by icaltimezone_get_tzid() as the lookup key, which can
* be passed to e_timezone_cache_get_timezone() to obtain @zone again.
*
* If the @cache already has an #icaltimezone with the same TZID string
* as @zone, the @cache will remain unchanged to avoid invalidating any
* #icaltimezone pointers which may have already been returned through
* e_timezone_cache_get_timezone().
*
* Since: 3.8
**/
void
e_timezone_cache_add_timezone (ETimezoneCache *cache,
icaltimezone *zone)
{
ETimezoneCacheInterface *iface;
g_return_if_fail (E_IS_TIMEZONE_CACHE (cache));
g_return_if_fail (zone != NULL);
iface = E_TIMEZONE_CACHE_GET_INTERFACE (cache);
g_return_if_fail (iface->add_timezone != NULL);
iface->add_timezone (cache, zone);
}
/**
* e_timezone_cache_get_timezone:
* @cache: an #ETimezoneCache
* @tzid: the TZID of a timezone
*
* Obtains an #icaltimezone by its TZID string. If no match is found,
* the function returns %NULL. The returned #icaltimezone is owned by
* the @cache and should not be modified or freed.
*
* Returns: an #icaltimezone, or %NULL
*
* Since: 3.8
**/
icaltimezone *
e_timezone_cache_get_timezone (ETimezoneCache *cache,
const gchar *tzid)
{
ETimezoneCacheInterface *iface;
g_return_val_if_fail (E_IS_TIMEZONE_CACHE (cache), NULL);
g_return_val_if_fail (tzid != NULL, NULL);
iface = E_TIMEZONE_CACHE_GET_INTERFACE (cache);
g_return_val_if_fail (iface->get_timezone != NULL, NULL);
return iface->get_timezone (cache, tzid);
}
/**
* e_timezone_cache_list_timezones:
* @cache: an #ETimezoneCache
*
* Returns a list of #icaltimezone instances that were explicitly added to
* the @cache through e_timezone_cache_add_timezone(). In particular, any
* built-in time zone data that e_timezone_cache_get_timezone() may use to
* match a TZID string is excluded from the returned list.
*
* Free the returned list with g_list_free(). The list elements are owned
* by the @cache and should not be modified or freed.
*
* Returns: (transfer container) (element-type icaltimezone): a #GList of
* #icaltimezone instances
*
* Since: 3.8
**/
GList *
e_timezone_cache_list_timezones (ETimezoneCache *cache)
{
ETimezoneCacheInterface *iface;
g_return_val_if_fail (E_IS_TIMEZONE_CACHE (cache), NULL);
iface = E_TIMEZONE_CACHE_GET_INTERFACE (cache);
g_return_val_if_fail (iface->list_timezones != NULL, NULL);
return iface->list_timezones (cache);
}
|