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  * Copyright (C) 2012 Intel Corporation
5  *
6  * This library is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Authors: Rodrigo Moya <rodrigo@ximian.com>
19  *          Tristan Van Berkom <tristanvb@openismus.com>
20  */
21 
22 #if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION)
23 #error "Only <libedataserver/libedataserver.h> should be included directly."
24 #endif
25 
26 #ifndef E_DATA_SERVER_UTIL_H
27 #define E_DATA_SERVER_UTIL_H
28 
29 #include <sys/types.h>
30 #include <gio/gio.h>
31 
32 #include <libedataserver/e-source-enums.h>
33 
34 G_BEGIN_DECLS
35 
36 struct tm;
37 struct _ESource;
38 struct _ESourceRegistry;
39 
40 const gchar *	e_get_user_cache_dir		(void);
41 const gchar *	e_get_user_config_dir		(void);
42 const gchar *	e_get_user_data_dir		(void);
43 
44 gboolean	e_util_strv_equal		(gconstpointer v1,
45 						 gconstpointer v2);
46 gchar *		e_util_strdup_strip		(const gchar *string);
47 gint		e_util_strcmp0			(const gchar *str1,
48 						 const gchar *str2);
49 gchar *		e_util_strstrcase		(const gchar *haystack,
50 						 const gchar *needle);
51 gchar *		e_util_unicode_get_utf8		(const gchar *text,
52 						 gunichar *out);
53 const gchar *	e_util_utf8_strstrcase		(const gchar *haystack,
54 						 const gchar *needle);
55 const gchar *	e_util_utf8_strstrcasedecomp	(const gchar *haystack,
56 						 const gchar *needle);
57 gint		e_util_utf8_strcasecmp		(const gchar *s1,
58 						 const gchar *s2);
59 gchar *		e_util_utf8_remove_accents	(const gchar *str);
60 gchar *		e_util_utf8_decompose		(const gchar *text);
61 gchar *		e_util_utf8_make_valid		(const gchar *str);
62 gchar *		e_util_utf8_data_make_valid	(const gchar *data,
63 						 gsize data_bytes);
64 gchar *         e_util_utf8_normalize           (const gchar *str);
65 const gchar *   e_util_ensure_gdbus_string	(const gchar *str,
66 						 gchar **gdbus_str);
67 guint64		e_util_gthread_id		(GThread *thread);
68 void		e_filename_make_safe		(gchar *string);
69 gchar *		e_filename_mkdir_encoded	(const gchar *basepath,
70 						 const gchar *fileprefix,
71 						 const gchar *filename,
72 						 gint fileindex);
73 
74 gsize		e_utf8_strftime			(gchar *string,
75 						 gsize max,
76 						 const gchar *fmt,
77 						 const struct tm *tm);
78 gsize		e_strftime			(gchar *string,
79 						 gsize max,
80 						 const gchar *fmt,
81 						 const struct tm *tm);
82 
83 gchar **	e_util_slist_to_strv		(const GSList *strings);
84 GSList *	e_util_strv_to_slist		(const gchar * const *strv);
85 void		e_util_free_nullable_object_slist
86 						(GSList *objects);
87 void		e_util_safe_free_string		(gchar *str);
88 
89 void		e_queue_transfer		(GQueue *src_queue,
90 						 GQueue *dst_queue);
91 GWeakRef *	e_weak_ref_new			(gpointer object);
92 void		e_weak_ref_free			(GWeakRef *weak_ref);
93 
94 gboolean	e_file_recursive_delete_sync	(GFile *file,
95 						 GCancellable *cancellable,
96 						 GError **error);
97 void		e_file_recursive_delete		(GFile *file,
98 						 gint io_priority,
99 						 GCancellable *cancellable,
100 						 GAsyncReadyCallback callback,
101 						 gpointer user_data);
102 gboolean	e_file_recursive_delete_finish	(GFile *file,
103 						 GAsyncResult *result,
104 						 GError **error);
105 
106 GBinding *	e_binding_bind_property		(gpointer source,
107 						 const gchar *source_property,
108 						 gpointer target,
109 						 const gchar *target_property,
110 						 GBindingFlags flags);
111 GBinding *	e_binding_bind_property_full	(gpointer source,
112 						 const gchar *source_property,
113 						 gpointer target,
114 						 const gchar *target_property,
115 						 GBindingFlags flags,
116 						 GBindingTransformFunc transform_to,
117 						 GBindingTransformFunc transform_from,
118 						 gpointer user_data,
119 						 GDestroyNotify notify);
120 GBinding *	e_binding_bind_property_with_closures
121 						(gpointer source,
122 						 const gchar *source_property,
123 						 gpointer target,
124 						 const gchar *target_property,
125 						 GBindingFlags flags,
126 						 GClosure *transform_to,
127 						 GClosure *transform_from);
128 /* Useful GBinding transform functions */
129 gboolean	e_binding_transform_enum_value_to_nick
130 						(GBinding *binding,
131 						 const GValue *source_value,
132 						 GValue *target_value,
133 						 gpointer not_used);
134 gboolean	e_binding_transform_enum_nick_to_value
135 						(GBinding *binding,
136 						 const GValue *source_value,
137 						 GValue *target_value,
138 						 gpointer not_used);
139 
140 gboolean	e_enum_from_string		(GType enum_type,
141 						 const gchar *string,
142 						 gint *enum_value);
143 const gchar *	e_enum_to_string		(GType enum_type,
144 						 gint enum_value);
145 
146 typedef struct _EAsyncClosure EAsyncClosure;
147 
148 EAsyncClosure *	e_async_closure_new		(void);
149 EAsyncClosure *	e_async_closure_new_with_context(GMainContext *context);
150 GAsyncResult *	e_async_closure_wait		(EAsyncClosure *closure);
151 void		e_async_closure_free		(EAsyncClosure *closure);
152 void		e_async_closure_callback	(GObject *object,
153 						 GAsyncResult *result,
154 						 gpointer closure);
155 
156 #ifdef G_OS_WIN32
157 const gchar *	e_util_get_prefix		(void) G_GNUC_CONST;
158 const gchar *	e_util_get_cp_prefix		(void) G_GNUC_CONST;
159 const gchar *	e_util_get_localedir		(void) G_GNUC_CONST;
160 gchar *		e_util_replace_prefix		(const gchar *configure_time_prefix,
161 						 const gchar *runtime_prefix,
162 						 const gchar *configure_time_path);
163 void		e_util_win32_initialize		(void);
164 #endif
165 
166 /* utility functions for easier processing of named parameters */
167 
168 /**
169  * ENamedParameters:
170  *
171  * Since: 3.8
172  **/
173 struct _ENamedParameters;
174 typedef struct _ENamedParameters ENamedParameters;
175 
176 #define E_TYPE_NAMED_PARAMETERS (e_named_parameters_get_type ())
177 
178 GType           e_named_parameters_get_type     (void) G_GNUC_CONST;
179 ENamedParameters *
180 		e_named_parameters_new		(void);
181 ENamedParameters *
182 		e_named_parameters_new_strv	(const gchar * const *strv);
183 ENamedParameters *
184 		e_named_parameters_new_string	(const gchar *str);
185 ENamedParameters *
186 		e_named_parameters_new_clone	(const ENamedParameters *parameters);
187 void		e_named_parameters_free		(ENamedParameters *parameters);
188 void		e_named_parameters_clear	(ENamedParameters *parameters);
189 void		e_named_parameters_assign	(ENamedParameters *parameters,
190 						 const ENamedParameters *from);
191 void		e_named_parameters_set		(ENamedParameters *parameters,
192 						 const gchar *name,
193 						 const gchar *value);
194 const gchar *	e_named_parameters_get		(const ENamedParameters *parameters,
195 						 const gchar *name);
196 gchar **	e_named_parameters_to_strv	(const ENamedParameters *parameters);
197 gchar *		e_named_parameters_to_string	(const ENamedParameters *parameters);
198 gboolean	e_named_parameters_test		(const ENamedParameters *parameters,
199 						 const gchar *name,
200 						 const gchar *value,
201 						 gboolean case_sensitively);
202 gboolean	e_named_parameters_exists	(const ENamedParameters *parameters,
203 						 const gchar *name);
204 guint		e_named_parameters_count	(const ENamedParameters *parameters);
205 gchar *		e_named_parameters_get_name	(const ENamedParameters *parameters,
206 						 gint index);
207 
208 #define e_named_timeout_add(interval, function, data) \
209 	(e_timeout_add_with_name ( \
210 		G_PRIORITY_DEFAULT, (interval), \
211 		"[" PACKAGE "] " G_STRINGIFY (function), \
212 		(function), (data), NULL))
213 
214 #define e_named_timeout_add_full(priority, interval, function, data, notify) \
215 	(e_timeout_add_with_name ( \
216 		(priority), (interval), \
217 		"[" PACKAGE "] " G_STRINGIFY (function), \
218 		(function), (data), (notify)))
219 
220 #define e_named_timeout_add_seconds(interval, function, data) \
221 	(e_timeout_add_seconds_with_name ( \
222 		G_PRIORITY_DEFAULT, (interval), \
223 		"[" PACKAGE "] " G_STRINGIFY (function), \
224 		(function), (data), NULL))
225 
226 #define e_named_timeout_add_seconds_full(priority, interval, function, data, notify) \
227 	(e_timeout_add_seconds_with_name ( \
228 		(priority), (interval), \
229 		"[" PACKAGE "] " G_STRINGIFY (function), \
230 		(function), (data), (notify)))
231 
232 guint		e_timeout_add_with_name		(gint priority,
233 						 guint interval,
234 						 const gchar *name,
235 						 GSourceFunc function,
236 						 gpointer data,
237 						 GDestroyNotify notify);
238 guint		e_timeout_add_seconds_with_name	(gint priority,
239 						 guint interval,
240 						 const gchar *name,
241 						 GSourceFunc function,
242 						 gpointer data,
243 						 GDestroyNotify notify);
244 
245 #ifndef EDS_DISABLE_DEPRECATED
246 void		e_util_free_string_slist	(GSList *strings);
247 void		e_util_free_object_slist	(GSList *objects);
248 GSList *	e_util_copy_string_slist	(GSList *copy_to,
249 						 const GSList *strings);
250 GSList *	e_util_copy_object_slist	(GSList *copy_to,
251 						 const GSList *objects);
252 gint		e_data_server_util_get_dbus_call_timeout
253 						(void);
254 void		e_data_server_util_set_dbus_call_timeout
255 						(gint timeout_msec);
256 
257 #endif /* EDS_DISABLE_DEPRECATED */
258 
259 gboolean	e_source_registry_debug_enabled	(void);
260 void		e_source_registry_debug_print	(const gchar *format,
261 						 ...) G_GNUC_PRINTF (1, 2);
262 void		e_util_debug_print		(const gchar *domain,
263 						 const gchar *format,
264 						 ...) G_GNUC_PRINTF (2, 3);
265 void		e_util_debug_printv		(const gchar *domain,
266 						 const gchar *format,
267 						 va_list args);
268 
269 /**
270  * ETypeFunc:
271  * @type: a #GType
272  * @user_data: user data passed to e_type_traverse()
273  *
274  * Specifies the type of functions passed to e_type_traverse().
275  *
276  * Since: 3.4
277  **/
278 typedef void	(*ETypeFunc)			(GType type,
279 						 gpointer user_data);
280 void		e_type_traverse			(GType parent_type,
281 						 ETypeFunc func,
282 						 gpointer user_data);
283 
284 gchar *		e_util_get_source_full_name	(struct _ESourceRegistry *registry,
285 						 struct _ESource *source);
286 
287 void		e_util_unref_in_thread		(gpointer object);
288 
289 gchar *		e_util_generate_uid		(void);
290 
291 gboolean	e_util_identity_can_send	(struct _ESourceRegistry *registry,
292 						 struct _ESource *identity_source);
293 gboolean	e_util_can_use_collection_as_credential_source
294 						(struct _ESource *collection_source,
295 						 struct _ESource *child_source);
296 gint		e_util_source_compare_for_sort	(struct _ESource *source_a,
297 						 struct _ESource *source_b);
298 GPtrArray *	e_util_get_directory_variants	(const gchar *main_path,
299 						 const gchar *replace_prefix,
300 						 gboolean with_modules_dir);
301 
302 G_END_DECLS
303 
304 #endif /* E_DATA_SERVER_UTIL_H */
305