]> git.0d.be Git - empathy.git/blob - libempathy/empathy-request-util.c
libempathy-gtk: fix uninitialized variable
[empathy.git] / libempathy / empathy-request-util.c
1 /* * Copyright (C) 2007-2010 Collabora Ltd.
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  * Authors: Xavier Claessens <xclaesse@gmail.com>
18  *          Sjoerd Simons <sjoerd.simons@collabora.co.uk>
19  *          Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
20  */
21
22 #include "config.h"
23 #include "empathy-request-util.h"
24
25 #include <telepathy-glib/telepathy-glib-dbus.h>
26
27 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
28 #include "empathy-debug.h"
29
30 void
31 empathy_chat_with_contact (EmpathyContact *contact,
32     gint64 timestamp)
33 {
34   empathy_chat_with_contact_id (
35       empathy_contact_get_account (contact), empathy_contact_get_id (contact),
36       timestamp, NULL, NULL);
37 }
38
39 static void
40 ensure_text_channel_cb (GObject *source,
41     GAsyncResult *result,
42     gpointer user_data)
43 {
44   GError *error = NULL;
45
46   if (!tp_account_channel_request_ensure_channel_finish (
47         TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
48     {
49       DEBUG ("Failed to ensure text channel: %s", error->message);
50       g_error_free (error);
51     }
52 }
53
54 static void
55 create_text_channel (TpAccount *account,
56     TpHandleType target_handle_type,
57     const gchar *target_id,
58     gboolean sms_channel,
59     gint64 timestamp,
60     GAsyncReadyCallback callback,
61     gpointer user_data)
62 {
63   TpAccountChannelRequest *req;
64
65   req = tp_account_channel_request_new_text (account, timestamp);
66   tp_account_channel_request_set_target_id (req, target_handle_type, target_id);
67   tp_account_channel_request_set_delegate_to_preferred_handler (req, TRUE);
68
69   if (sms_channel)
70     tp_account_channel_request_set_sms_channel (req, TRUE);
71
72   tp_account_channel_request_ensure_channel_async (req,
73       EMPATHY_CHAT_TP_BUS_NAME, NULL,
74       callback ? callback : ensure_text_channel_cb, user_data);
75
76   g_object_unref (req);
77 }
78
79 /* @callback is optional, but if it's provided, it should call the right
80  * _finish() func that we call in ensure_text_channel_cb() */
81 void
82 empathy_chat_with_contact_id (TpAccount *account,
83     const gchar *contact_id,
84     gint64 timestamp,
85     GAsyncReadyCallback callback,
86     gpointer user_data)
87 {
88   create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
89       contact_id, FALSE, timestamp, callback, user_data);
90 }
91
92 void
93 empathy_join_muc (TpAccount *account,
94     const gchar *room_name,
95     gint64 timestamp)
96 {
97   create_text_channel (account, TP_HANDLE_TYPE_ROOM,
98       room_name, FALSE, timestamp, NULL, NULL);
99 }
100
101 /* @callback is optional, but if it's provided, it should call the right
102  * _finish() func that we call in ensure_text_channel_cb() */
103 void
104 empathy_sms_contact_id (TpAccount *account,
105     const gchar *contact_id,
106     gint64 timestamp,
107     GAsyncReadyCallback callback,
108     gpointer user_data)
109 {
110   create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
111       contact_id, TRUE, timestamp, callback, user_data);
112 }