1 /* vi: set et sw=4 ts=8 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
3 /*
4 * This file is part of mission-control
5 *
6 * Copyright (C) 2007-2009 Nokia Corporation.
7 * Copyright (C) 2009 Collabora Ltd.
8 *
9 * Contact: Naba Kumar <naba.kumar@nokia.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * version 2.1 as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 * 02110-1301 USA
24 *
25 */
26
27 #include "config.h"
28
29 #include "channel-utils.h"
30
31 #include <telepathy-glib/telepathy-glib.h>
32 #include <telepathy-glib/telepathy-glib-dbus.h>
33
34 #include "mcd-channel.h"
35 #include "mcd-debug.h"
36
37 gboolean
_mcd_tp_channel_should_close(TpChannel * channel,const gchar * verb)38 _mcd_tp_channel_should_close (TpChannel *channel,
39 const gchar *verb)
40 {
41 const GError *invalidated;
42 const gchar *object_path;
43 GQuark channel_type;
44
45 if (channel == NULL)
46 {
47 DEBUG ("Not %s NULL channel", verb);
48 return FALSE;
49 }
50
51 invalidated = tp_proxy_get_invalidated (channel);
52 object_path = tp_proxy_get_object_path (channel);
53
54 if (invalidated != NULL)
55 {
56 DEBUG ("Not %s %p:%s, already invalidated: %s %d: %s",
57 verb, channel, object_path,
58 g_quark_to_string (invalidated->domain),
59 invalidated->code, invalidated->message);
60 return FALSE;
61 }
62
63 channel_type = tp_channel_get_channel_type_id (channel);
64
65 if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_CONTACT_LIST)
66 {
67 DEBUG ("Not %s %p:%s, it's a ContactList", verb, channel, object_path);
68 return FALSE;
69 }
70
71 if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TUBES)
72 {
73 DEBUG ("Not %s %p:%s, it's an old Tubes channel", verb, channel,
74 object_path);
75 return FALSE;
76 }
77
78 return TRUE;
79 }
80
81 static void
_channel_details_array_append(GPtrArray * channel_array,TpChannel * channel)82 _channel_details_array_append (GPtrArray *channel_array, TpChannel *channel)
83 {
84 GType type = TP_STRUCT_TYPE_CHANNEL_DETAILS;
85 GValue channel_val = G_VALUE_INIT;
86 GVariant *pair[2];
87 GVariant *tuple;
88
89 pair[0] = g_variant_new_object_path (tp_proxy_get_object_path (channel));
90 pair[1] = tp_channel_dup_immutable_properties (channel);
91 /* takes ownership of floating pair[0] */
92 tuple = g_variant_new_tuple (pair, 2);
93 dbus_g_value_parse_g_variant (tuple, &channel_val);
94 g_variant_unref (pair[1]);
95 g_variant_unref (tuple);
96 g_assert (G_VALUE_HOLDS (&channel_val, type));
97
98 g_ptr_array_add (channel_array, g_value_get_boxed (&channel_val));
99 }
100
101 /*
102 * _mcd_tp_channel_details_build_from_list:
103 * @channels: a #GList of #McdChannel elements.
104 *
105 * Returns: a #GPtrArray of Channel_Details, ready to be sent over D-Bus. Free
106 * with _mcd_tp_channel_details_free().
107 */
108 GPtrArray *
_mcd_tp_channel_details_build_from_list(const GList * channels)109 _mcd_tp_channel_details_build_from_list (const GList *channels)
110 {
111 GPtrArray *channel_array;
112 const GList *list;
113
114 channel_array = g_ptr_array_sized_new (g_list_length ((GList *) channels));
115
116 for (list = channels; list != NULL; list = list->next)
117 {
118 _channel_details_array_append (channel_array,
119 mcd_channel_get_tp_channel (MCD_CHANNEL (list->data)));
120 }
121
122 return channel_array;
123 }
124
125 /*
126 * _mcd_tp_channel_details_build_from_tp_chan:
127 * @channel: a #TpChannel
128 *
129 * Returns: a #GPtrArray of Channel_Details, ready to be sent over D-Bus. Free
130 * with _mcd_tp_channel_details_free().
131 */
132 GPtrArray *
_mcd_tp_channel_details_build_from_tp_chan(TpChannel * channel)133 _mcd_tp_channel_details_build_from_tp_chan (TpChannel *channel)
134 {
135 GPtrArray *channel_array = g_ptr_array_sized_new (1);
136
137 _channel_details_array_append (channel_array, channel);
138 return channel_array;
139 }
140
141 /*
142 * _mcd_tp_channel_details_free:
143 * @channels: a #GPtrArray of Channel_Details.
144 *
145 * Frees the memory used by @channels.
146 */
147 void
_mcd_tp_channel_details_free(GPtrArray * channels)148 _mcd_tp_channel_details_free (GPtrArray *channels)
149 {
150 g_boxed_free (TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST, channels);
151 }
152
153
154