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