account-settings: early return if SASL earlier
[empathy-mirror.git] / libempathy / empathy-request-util.c
blob196925b54be4d6502424619f98259fa5a4c5fe48
1 /* * Copyright (C) 2007-2010 Collabora Ltd.
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.
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.
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
17 * Authors: Xavier Claessens <xclaesse@gmail.com>
18 * Sjoerd Simons <sjoerd.simons@collabora.co.uk>
19 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
22 #include <config.h>
24 #include <string.h>
26 #include <glib/gi18n-lib.h>
28 #include "empathy-request-util.h"
29 #include "empathy-utils.h"
30 #include "empathy-utils.h"
32 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
33 #include <libempathy/empathy-debug.h>
35 void
36 empathy_chat_with_contact (EmpathyContact *contact,
37 gint64 timestamp)
39 empathy_chat_with_contact_id (
40 empathy_contact_get_account (contact), empathy_contact_get_id (contact),
41 timestamp, NULL, NULL);
44 static void
45 ensure_text_channel_cb (GObject *source,
46 GAsyncResult *result,
47 gpointer user_data)
49 GError *error = NULL;
51 if (!tp_account_channel_request_ensure_channel_finish (
52 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
54 DEBUG ("Failed to ensure text channel: %s", error->message);
55 g_error_free (error);
59 static void
60 create_text_channel (TpAccount *account,
61 TpHandleType target_handle_type,
62 const gchar *target_id,
63 gboolean sms_channel,
64 gint64 timestamp,
65 GAsyncReadyCallback callback,
66 gpointer user_data)
68 GHashTable *request;
69 TpAccountChannelRequest *req;
71 request = tp_asv_new (
72 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
73 TP_IFACE_CHANNEL_TYPE_TEXT,
74 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, target_handle_type,
75 TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, target_id,
76 NULL);
78 if (sms_channel)
79 tp_asv_set_boolean (request,
80 TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, TRUE);
82 req = tp_account_channel_request_new (account, request, timestamp);
83 tp_account_channel_request_set_delegate_to_preferred_handler (req, TRUE);
85 tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_BUS_NAME,
86 NULL, callback ? callback : ensure_text_channel_cb, user_data);
88 g_hash_table_unref (request);
89 g_object_unref (req);
92 /* @callback is optional, but if it's provided, it should call the right
93 * _finish() func that we call in ensure_text_channel_cb() */
94 void
95 empathy_chat_with_contact_id (TpAccount *account,
96 const gchar *contact_id,
97 gint64 timestamp,
98 GAsyncReadyCallback callback,
99 gpointer user_data)
101 create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
102 contact_id, FALSE, timestamp, callback, user_data);
105 void
106 empathy_join_muc (TpAccount *account,
107 const gchar *room_name,
108 gint64 timestamp)
110 create_text_channel (account, TP_HANDLE_TYPE_ROOM,
111 room_name, FALSE, timestamp, NULL, NULL);
114 /* @callback is optional, but if it's provided, it should call the right
115 * _finish() func that we call in ensure_text_channel_cb() */
116 void
117 empathy_sms_contact_id (TpAccount *account,
118 const gchar *contact_id,
119 gint64 timestamp,
120 GAsyncReadyCallback callback,
121 gpointer user_data)
123 create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
124 contact_id, TRUE, timestamp, callback, user_data);