summaryrefslogtreecommitdiff
path: root/telepathy-glib/room-info.c
blob: 10942dcf665266de404a3f44365882ae2675f170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
 * room-info.c
 *
 * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"

#include "room-info.h"
#include "room-info-internal.h"

#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/util.h>

/**
 * SECTION: room-info
 * @title: TpRoomInfo
 * @short_description: a room found by #TpRoomList
 *
 * #TpRoomInfo represents a room found during a room listing using
 * #TpRoomList.
 *
 * See also: #TpRoomList
 */

/**
 * TpRoomInfo:
 *
 * Data structure representing a #TpRoomInfo.
 *
 * Since: 0.19.0
 */

/**
 * TpRoomInfoClass:
 *
 * The class of a #TpRoomInfo.
 *
 * Since: 0.19.0
 */

G_DEFINE_TYPE (TpRoomInfo, tp_room_info, G_TYPE_OBJECT)

struct _TpRoomInfoPriv {
  TpHandle handle;
  gchar *channel_type;
  GHashTable *info;
};

static void
tp_room_info_finalize (GObject *object)
{
  TpRoomInfo *self = TP_ROOM_INFO (object);
  void (*chain_up) (GObject *) =
      ((GObjectClass *) tp_room_info_parent_class)->finalize;

  g_free (self->priv->channel_type);
  g_hash_table_unref (self->priv->info);

  if (chain_up != NULL)
    chain_up (object);
}

static void
tp_room_info_class_init (
    TpRoomInfoClass *klass)
{
  GObjectClass *oclass = G_OBJECT_CLASS (klass);

  oclass->finalize = tp_room_info_finalize;

  g_type_class_add_private (klass, sizeof (TpRoomInfoPriv));
}

static void
tp_room_info_init (TpRoomInfo *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      TP_TYPE_ROOM_INFO, TpRoomInfoPriv);
}

TpRoomInfo *
_tp_room_info_new (GValueArray *dbus_struct)
{
  TpRoomInfo *room;
  const gchar *channel_type;
  GHashTable *info;

  g_return_val_if_fail (dbus_struct != NULL, NULL);
  g_return_val_if_fail (dbus_struct->n_values == 3, NULL);

  /* We don't want to expose the GValueArray in the API so it's not
   * a GObject property. */
  room = g_object_new (TP_TYPE_ROOM_INFO,
      NULL);

  tp_value_array_unpack (dbus_struct, 3,
      &room->priv->handle,
      &channel_type,
      &info);
  room->priv->channel_type = g_strdup (channel_type);
  room->priv->info = g_hash_table_new_full (g_str_hash, g_str_equal,
      g_free, (GDestroyNotify) tp_g_value_slice_free);
  tp_g_hash_table_update (room->priv->info, info,
      (GBoxedCopyFunc) g_strdup,
      (GBoxedCopyFunc) tp_g_value_slice_dup);

  return room;
}

/**
 * tp_room_info_get_handle:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: the #TpHandle of the room
 *
 * Since: 0.19.0
 */
TpHandle
tp_room_info_get_handle (TpRoomInfo *self)
{
  return self->priv->handle;
}

/**
 * tp_room_info_get_channel_type:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: a string representing the D-Bus interface name of
 * the channel type of the room
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_channel_type (TpRoomInfo *self)
{
  return self->priv->channel_type;
}

/**
 * tp_room_info_get_handle_name:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: the identifier of the room (as would be returned
 * by inspecting the #TpHandle returned by tp_room_info_get_handle())
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_handle_name (TpRoomInfo *self)
{
  return tp_asv_get_string (self->priv->info, "handle-name");
}

/**
 * tp_room_info_get_name:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: the human-readable name of the room if different
 * from the handle
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_name (TpRoomInfo *self)
{
  return tp_asv_get_string (self->priv->info, "name");
}

/**
 * tp_room_info_get_description:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: a description of the room's overall purpose
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_description (TpRoomInfo *self)
{
  return tp_asv_get_string (self->priv->info, "description");
}

/**
 * tp_room_info_get_subject:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: the current subject of conversation in the room
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_subject (TpRoomInfo *self)
{
  return tp_asv_get_string (self->priv->info, "subject");
}

/**
 * tp_room_info_get_members_count:
 * @self: a #TpRoomInfo
 * @known: either %NULL, or a location in which to store %TRUE if the
 * returned value is meaningful
 *
 * <!-- -->
 *
 * Returns: the number of members in the room
 *
 * Since: 0.19.0
 */
guint
tp_room_info_get_members_count (TpRoomInfo *self,
    gboolean *known)
{
  return tp_asv_get_uint32 (self->priv->info, "members", known);
}

/**
 * tp_room_info_get_requires_password:
 * @self: a #TpRoomInfo
 * @known: either %NULL, or a location in which to store %TRUE if the
 * returned value is meaningful
 *
 * <!-- -->
 *
 * Returns: %TRUE if the room requires a password to enter
 *
 * Since: 0.19.0
 */
gboolean
tp_room_info_get_requires_password (TpRoomInfo *self,
    gboolean *known)
{
  return tp_asv_get_boolean (self->priv->info, "password", known);
}

/**
 * tp_room_info_get_invite_only:
 * @self: a #TpRoomInfo
 * @known: either %NULL, or a location in which to store %TRUE if the
 * returned value is meaningful
 *
 * <!-- -->
 *
 * Returns: %TRUE if you cannot join the room, but must be invited
 *
 * Since: 0.19.0
 */
gboolean
tp_room_info_get_invite_only (TpRoomInfo *self,
    gboolean *known)
{
  return tp_asv_get_boolean (self->priv->info, "invite-only", known);
}

/**
 * tp_room_info_get_room_id:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: the human-readable identifier of the room
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_room_id (TpRoomInfo *self)
{
  return tp_asv_get_string (self->priv->info, "room-id");
}

/**
 * tp_room_info_get_server:
 * @self: a #TpRoomInfo
 *
 * <!-- -->
 *
 * Returns: the DNS name of the server hosting the room
 *
 * Since: 0.19.0
 */
const gchar *
tp_room_info_get_server (TpRoomInfo *self)
{
  return tp_asv_get_string (self->priv->info, "server");
}