~ubuntu-branches/ubuntu/wily/telepathy-glib/wily

« back to all changes in this revision

Viewing changes to examples/cm/channelspecific/room.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon McVittie
  • Date: 2009-03-24 22:06:52 UTC
  • mfrom: (1.3.1 upstream) (17.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20090324220652-c8dvom0nsqomp23d
Tags: 0.7.28-1
* New upstream version (ABI, API added)
* Put the -dbg package in section debug, as per recent archive changes
* Remove obsolete Conflicts/Replaces with libtelepathy-glib-static-dev, which
  was never in a stable release (and probably never in Debian at all)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
      tp_group_mixin_iface_init);
31
31
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
32
32
      tp_dbus_properties_mixin_iface_init);
 
33
    G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL);
33
34
    G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL))
34
35
 
35
36
/* type definition stuff */
40
41
  PROP_CHANNEL_TYPE,
41
42
  PROP_HANDLE_TYPE,
42
43
  PROP_HANDLE,
 
44
  PROP_TARGET_ID,
 
45
  PROP_REQUESTED,
 
46
  PROP_INITIATOR_HANDLE,
 
47
  PROP_INITIATOR_ID,
43
48
  PROP_CONNECTION,
44
49
  PROP_INTERFACES,
 
50
  PROP_CHANNEL_DESTROYED,
 
51
  PROP_CHANNEL_PROPERTIES,
45
52
  N_PROPS
46
53
};
47
54
 
50
57
  TpBaseConnection *conn;
51
58
  gchar *object_path;
52
59
  TpHandle handle;
 
60
  TpHandle initiator;
53
61
 
54
 
  gboolean closed:1;
55
 
  gboolean disposed:1;
 
62
  /* These are really booleans, but gboolean is signed. Thanks, GLib */
 
63
  unsigned closed:1;
 
64
  unsigned disposed:1;
56
65
};
57
66
 
58
67
 
249
258
 
250
259
  tp_handle_ref (room_repo, self->priv->handle);
251
260
 
 
261
  if (self->priv->initiator != 0)
 
262
    tp_handle_ref (contact_repo, self->priv->initiator);
 
263
 
252
264
  bus = tp_get_bus ();
253
265
  dbus_g_connection_register_g_object (bus, self->priv->object_path, object);
254
266
 
304
316
    case PROP_HANDLE:
305
317
      g_value_set_uint (value, self->priv->handle);
306
318
      break;
 
319
    case PROP_TARGET_ID:
 
320
        {
 
321
          TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
 
322
              self->priv->conn, TP_HANDLE_TYPE_ROOM);
 
323
 
 
324
          g_value_set_string (value,
 
325
              tp_handle_inspect (room_repo, self->priv->handle));
 
326
        }
 
327
      break;
 
328
    case PROP_REQUESTED:
 
329
      /* this example CM doesn't yet support being invited into a chatroom,
 
330
       * so the only way a channel can exist is if the user asked for it */
 
331
      g_value_set_boolean (value, TRUE);
 
332
      break;
 
333
    case PROP_INITIATOR_HANDLE:
 
334
      g_value_set_uint (value, self->priv->initiator);
 
335
      break;
 
336
    case PROP_INITIATOR_ID:
 
337
        {
 
338
          TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
 
339
              self->priv->conn, TP_HANDLE_TYPE_CONTACT);
 
340
 
 
341
          g_value_set_string (value,
 
342
              self->priv->initiator == 0
 
343
                  ? ""
 
344
                  : tp_handle_inspect (contact_repo, self->priv->initiator));
 
345
        }
 
346
      break;
307
347
    case PROP_CONNECTION:
308
348
      g_value_set_object (value, self->priv->conn);
309
349
      break;
310
350
    case PROP_INTERFACES:
311
351
      g_value_set_boxed (value, example_csh_room_channel_interfaces);
312
352
      break;
 
353
    case PROP_CHANNEL_DESTROYED:
 
354
      g_value_set_boolean (value, self->priv->closed);
 
355
      break;
 
356
    case PROP_CHANNEL_PROPERTIES:
 
357
      g_value_take_boxed (value,
 
358
          tp_dbus_properties_mixin_make_properties_hash (object,
 
359
              TP_IFACE_CHANNEL, "ChannelType",
 
360
              TP_IFACE_CHANNEL, "TargetHandleType",
 
361
              TP_IFACE_CHANNEL, "TargetHandle",
 
362
              TP_IFACE_CHANNEL, "TargetID",
 
363
              TP_IFACE_CHANNEL, "InitiatorHandle",
 
364
              TP_IFACE_CHANNEL, "InitiatorID",
 
365
              TP_IFACE_CHANNEL, "Requested",
 
366
              TP_IFACE_CHANNEL, "Interfaces",
 
367
              NULL));
 
368
      break;
313
369
    default:
314
370
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
315
371
      break;
336
392
       */
337
393
      self->priv->handle = g_value_get_uint (value);
338
394
      break;
 
395
    case PROP_INITIATOR_HANDLE:
 
396
      /* similarly, we don't yet have the contact repo */
 
397
      self->priv->initiator = g_value_get_uint (value);
 
398
      break;
339
399
    case PROP_HANDLE_TYPE:
340
400
    case PROP_CHANNEL_TYPE:
341
401
      /* these properties are writable in the interface, but not actually
351
411
}
352
412
 
353
413
static void
 
414
example_csh_room_channel_close (ExampleCSHRoomChannel *self)
 
415
{
 
416
  if (!self->priv->closed)
 
417
    {
 
418
      self->priv->closed = TRUE;
 
419
      tp_svc_channel_emit_closed (self);
 
420
    }
 
421
}
 
422
 
 
423
static void
354
424
dispose (GObject *object)
355
425
{
356
426
  ExampleCSHRoomChannel *self = EXAMPLE_CSH_ROOM_CHANNEL (object);
360
430
 
361
431
  self->priv->disposed = TRUE;
362
432
 
363
 
  if (!self->priv->closed)
364
 
    {
365
 
      tp_svc_channel_emit_closed (self);
366
 
    }
 
433
  example_csh_room_channel_close (self);
367
434
 
368
435
  ((GObjectClass *) example_csh_room_channel_parent_class)->dispose (object);
369
436
}
372
439
finalize (GObject *object)
373
440
{
374
441
  ExampleCSHRoomChannel *self = EXAMPLE_CSH_ROOM_CHANNEL (object);
 
442
  TpHandleRepoIface *contact_handles = tp_base_connection_get_handles
 
443
      (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
375
444
  TpHandleRepoIface *room_handles = tp_base_connection_get_handles
376
445
      (self->priv->conn, TP_HANDLE_TYPE_ROOM);
377
446
 
 
447
  if (self->priv->initiator != 0)
 
448
    tp_handle_unref (contact_handles, self->priv->initiator);
 
449
 
378
450
  tp_handle_unref (room_handles, self->priv->handle);
379
451
  g_free (self->priv->object_path);
380
452
 
396
468
  return TRUE;
397
469
}
398
470
 
 
471
static gboolean
 
472
remove_member_with_reason (GObject *object,
 
473
                           TpHandle handle,
 
474
                           const gchar *message,
 
475
                           guint reason,
 
476
                           GError **error)
 
477
{
 
478
  ExampleCSHRoomChannel *self = EXAMPLE_CSH_ROOM_CHANNEL (object);
 
479
 
 
480
  if (handle == self->group.self_handle)
 
481
    {
 
482
      /* TODO: if simulating a channel where the user is an operator, let them
 
483
       * kick themselves (like in IRC), resulting in different "network"
 
484
       * messages */
 
485
 
 
486
      example_csh_room_channel_close (self);
 
487
      return TRUE;
 
488
    }
 
489
  else
 
490
    {
 
491
      /* TODO: also simulate some channels where the user is an operator and
 
492
       * can kick people */
 
493
      g_set_error (error, TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
 
494
          "You can't eject other users from this channel");
 
495
      return FALSE;
 
496
    }
 
497
}
399
498
 
400
499
static void
401
500
example_csh_room_channel_class_init (ExampleCSHRoomChannelClass *klass)
405
504
      { "TargetHandle", "handle", NULL },
406
505
      { "ChannelType", "channel-type", NULL },
407
506
      { "Interfaces", "interfaces", NULL },
 
507
      { "TargetID", "target-id", NULL },
 
508
      { "Requested", "requested", NULL },
 
509
      { "InitiatorHandle", "initiator-handle", NULL },
 
510
      { "InitiatorID", "initiator-id", NULL },
408
511
      { NULL }
409
512
  };
410
513
  static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
434
537
      "handle-type");
435
538
  g_object_class_override_property (object_class, PROP_HANDLE, "handle");
436
539
 
 
540
  g_object_class_override_property (object_class, PROP_CHANNEL_DESTROYED,
 
541
      "channel-destroyed");
 
542
  g_object_class_override_property (object_class, PROP_CHANNEL_PROPERTIES,
 
543
      "channel-properties");
 
544
 
437
545
  param_spec = g_param_spec_object ("connection", "TpBaseConnection object",
438
546
      "Connection object that owns this channel",
439
547
      TP_TYPE_BASE_CONNECTION,
440
 
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
441
 
      G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
 
548
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
442
549
  g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
443
550
 
444
551
  param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
445
552
      "Additional Channel.Interface.* interfaces",
446
553
      G_TYPE_STRV,
447
 
      G_PARAM_READABLE |
448
 
      G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
 
554
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
449
555
  g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
450
556
 
 
557
  param_spec = g_param_spec_string ("target-id", "Chatroom's ID",
 
558
      "The string obtained by inspecting the MUC's handle",
 
559
      NULL,
 
560
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
561
  g_object_class_install_property (object_class, PROP_TARGET_ID, param_spec);
 
562
 
 
563
  param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
 
564
      "The contact who initiated the channel",
 
565
      0, G_MAXUINT32, 0,
 
566
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
567
  g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
 
568
      param_spec);
 
569
 
 
570
  param_spec = g_param_spec_string ("initiator-id", "Initiator's ID",
 
571
      "The string obtained by inspecting the initiator-handle",
 
572
      NULL,
 
573
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
574
  g_object_class_install_property (object_class, PROP_INITIATOR_ID,
 
575
      param_spec);
 
576
 
 
577
  param_spec = g_param_spec_boolean ("requested", "Requested?",
 
578
      "True if this channel was requested by the local user",
 
579
      FALSE,
 
580
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
581
  g_object_class_install_property (object_class, PROP_REQUESTED, param_spec);
 
582
 
451
583
  tp_text_mixin_class_init (object_class,
452
584
      G_STRUCT_OFFSET (ExampleCSHRoomChannelClass, text_class));
453
585
 
459
591
      G_STRUCT_OFFSET (ExampleCSHRoomChannelClass, group_class),
460
592
      add_member,
461
593
      NULL);
 
594
  tp_group_mixin_class_allow_self_removal (object_class);
 
595
  tp_group_mixin_class_set_remove_with_reason_func (object_class,
 
596
      remove_member_with_reason);
462
597
  tp_group_mixin_init_dbus_properties (object_class);
463
598
}
464
599
 
469
604
{
470
605
  ExampleCSHRoomChannel *self = EXAMPLE_CSH_ROOM_CHANNEL (iface);
471
606
 
472
 
  if (!self->priv->closed)
473
 
    {
474
 
      self->priv->closed = TRUE;
475
 
      tp_svc_channel_emit_closed (self);
476
 
    }
 
607
  example_csh_room_channel_close (self);
477
608
 
478
609
  tp_svc_channel_return_from_close (context);
479
610
}