]> git.0d.be Git - empathy.git/blob - libempathy/empathy-utils.h
UOA: Do not segfault when "Done" or "Cancel" button clicked but widget is not ready yet
[empathy.git] / libempathy / empathy-utils.h
1 /*
2  * Copyright (C) 2003-2007 Imendio AB
3  * Copyright (C) 2007-2011 Collabora Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors: Richard Hult <richard@imendio.com>
21  *          Martyn Russell <martyn@imendio.com>
22  *          Xavier Claessens <xclaesse@gmail.com>
23  */
24
25 #ifndef __EMPATHY_UTILS_H__
26 #define __EMPATHY_UTILS_H__
27
28 #include <glib.h>
29 #include <glib-object.h>
30
31 #include <gnutls/x509.h>
32 #include <libxml/tree.h>
33 #include <folks/folks.h>
34 #include <folks/folks-telepathy.h>
35 #include <telepathy-glib/telepathy-glib.h>
36
37 #include "empathy-contact.h"
38
39 #define EMPATHY_GET_PRIV(obj,type) ((type##Priv *) ((type *) obj)->priv)
40 #define EMP_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0')
41
42 G_BEGIN_DECLS
43
44 void empathy_init (void);
45
46 /* XML */
47 gboolean empathy_xml_validate (xmlDoc *doc,
48     const gchar *dtd_filename);
49 xmlNodePtr empathy_xml_node_get_child (xmlNodePtr node,
50     const gchar *child_name);
51 xmlChar * empathy_xml_node_get_child_content (xmlNodePtr node,
52     const gchar *child_name);
53 xmlNodePtr empathy_xml_node_find_child_prop_value (xmlNodePtr node,
54     const gchar *prop_name,
55     const gchar *prop_value);
56
57 /* Others */
58 const gchar * empathy_presence_get_default_message (
59     TpConnectionPresenceType presence);
60 const gchar * empathy_presence_to_str (TpConnectionPresenceType presence);
61 TpConnectionPresenceType empathy_presence_from_str (const gchar *str);
62 gchar * empathy_file_lookup (const gchar *filename,
63     const gchar *subdir);
64 gboolean empathy_check_available_state (void);
65 gint empathy_uint_compare (gconstpointer a,
66     gconstpointer b);
67
68 const gchar * empathy_account_get_error_message (TpAccount *account,
69     gboolean *user_requested);
70
71 gchar *empathy_protocol_icon_name (const gchar *protocol);
72 const gchar *empathy_protocol_name_to_display_name (const gchar *proto_name);
73 const gchar *empathy_service_name_to_display_name (const gchar *proto_name);
74
75 #define EMPATHY_ARRAY_TYPE_OBJECT (empathy_type_dbus_ao ())
76 GType empathy_type_dbus_ao (void);
77
78 gboolean empathy_account_manager_get_accounts_connected (gboolean *connecting);
79
80 void empathy_connect_new_account (TpAccount *account,
81     TpAccountManager *account_manager);
82
83 TpConnectionPresenceType empathy_folks_presence_type_to_tp (
84     FolksPresenceType type);
85 gboolean empathy_folks_individual_contains_contact (
86     FolksIndividual *individual);
87 EmpathyContact * empathy_contact_dup_from_folks_individual (
88     FolksIndividual *individual);
89 TpChannelGroupChangeReason tp_channel_group_change_reason_from_folks_groups_change_reason (
90     FolksGroupDetailsChangeReason reason);
91 TpfPersonaStore * empathy_dup_persona_store_for_connection (
92     TpConnection *connection);
93 gboolean empathy_connection_can_add_personas (TpConnection *connection);
94 gboolean empathy_connection_can_alias_personas (TpConnection *connection,
95                                                 FolksIndividual *individual);
96 gboolean empathy_connection_can_group_personas (TpConnection *connection,
97                                                 FolksIndividual *individual);
98 gboolean empathy_folks_persona_is_interesting (FolksPersona *persona);
99
100 gchar * empathy_get_x509_certificate_hostname (gnutls_x509_crt_t cert);
101
102 gchar *empathy_format_currency (gint amount,
103     guint scale,
104     const gchar *currency);
105
106 gboolean empathy_account_has_uri_scheme_tel (TpAccount *account);
107
108 TpContact * empathy_get_tp_contact_for_individual (FolksIndividual *individual,
109     TpConnection *conn);
110
111 void empathy_individual_can_audio_video_call (FolksIndividual *individual,
112     gboolean *can_audio_call,
113     gboolean *can_video_call,
114     EmpathyContact **out_contact);
115
116 gboolean empathy_client_types_contains_mobile_device (
117     const GStrv types);
118
119 FolksIndividual * empathy_create_individual_from_tp_contact (
120     TpContact *contact);
121
122 FolksIndividual * empathy_ensure_individual_from_tp_contact (
123     TpContact *contact);
124
125 const gchar * const * empathy_individual_get_client_types (
126     FolksIndividual *individual);
127
128 GVariant * empathy_asv_to_vardict (const GHashTable *asv);
129
130 GVariant * empathy_boxed_to_variant (GType gtype,
131     const gchar *variant_type,
132     gpointer boxed);
133
134 /* Copied from wocky/wocky-utils.h */
135
136 #define empathy_implement_finish_void(source, tag) \
137     if (g_simple_async_result_propagate_error (\
138       G_SIMPLE_ASYNC_RESULT (result), error)) \
139       return FALSE; \
140     g_return_val_if_fail (g_simple_async_result_is_valid (result, \
141             G_OBJECT(source), tag), \
142         FALSE); \
143     return TRUE;
144
145 #define empathy_implement_finish_copy_pointer(source, tag, copy_func, \
146     out_param) \
147     GSimpleAsyncResult *_simple; \
148     _simple = (GSimpleAsyncResult *) result; \
149     if (g_simple_async_result_propagate_error (_simple, error)) \
150       return FALSE; \
151     g_return_val_if_fail (g_simple_async_result_is_valid (result, \
152             G_OBJECT (source), tag), \
153         FALSE); \
154     if (out_param != NULL) \
155       *out_param = copy_func ( \
156           g_simple_async_result_get_op_res_gpointer (_simple)); \
157     return TRUE;
158
159 #define empathy_implement_finish_return_copy_pointer(source, tag, copy_func) \
160     GSimpleAsyncResult *_simple; \
161     _simple = (GSimpleAsyncResult *) result; \
162     if (g_simple_async_result_propagate_error (_simple, error)) \
163       return NULL; \
164     g_return_val_if_fail (g_simple_async_result_is_valid (result, \
165             G_OBJECT (source), tag), \
166         NULL); \
167     return copy_func (g_simple_async_result_get_op_res_gpointer (_simple));
168
169 #define empathy_implement_finish_return_pointer(source, tag) \
170     GSimpleAsyncResult *_simple; \
171     _simple = (GSimpleAsyncResult *) result; \
172     if (g_simple_async_result_propagate_error (_simple, error)) \
173       return NULL; \
174     g_return_val_if_fail (g_simple_async_result_is_valid (result, \
175             G_OBJECT (source), tag), \
176         NULL); \
177     return g_simple_async_result_get_op_res_gpointer (_simple);
178
179 G_END_DECLS
180
181 #endif /*  __EMPATHY_UTILS_H__ */