~ubuntu-branches/ubuntu/precise/telepathy-glib/precise-201111172307

« back to all changes in this revision

Viewing changes to telepathy-glib/contact.c

  • Committer: Ken VanDine
  • Date: 2011-11-17 20:53:21 UTC
  • mfrom: (1.6.34 upstream)
  • Revision ID: ken.vandine@canonical.com-20111117205321-l704j7kr1zgw5v9h
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <telepathy-glib/util.h>
31
31
 
32
32
#define DEBUG_FLAG TP_DEBUG_CONTACTS
 
33
#include "telepathy-glib/connection-contact-list.h"
33
34
#include "telepathy-glib/connection-internal.h"
34
35
#include "telepathy-glib/contact-internal.h"
35
36
#include "telepathy-glib/debug-internal.h"
109
110
 *  interface. (available since 0.13.12)
110
111
 * @TP_CONTACT_FEATURE_CONTACT_GROUPS: #TpContact:contact-groups
111
112
 *  (available since 0.13.14)
 
113
 * @TP_CONTACT_FEATURE_CONTACT_BLOCKING: #TpContact:is-blocking. Require
 
114
 *  Connection implementing the %TP_IFACE_CONNECTION_INTERFACE_CONTACT_BLOCKING
 
115
 *  interface. (available since 0.17.0)
112
116
 *
113
117
 * Enumeration representing the features a #TpContact can optionally support.
114
118
 * When requesting a #TpContact, library users specify the desired features;
169
173
    PROP_PUBLISH_STATE,
170
174
    PROP_PUBLISH_REQUEST,
171
175
    PROP_CONTACT_GROUPS,
 
176
    PROP_IS_BLOCKED,
172
177
    N_PROPS
173
178
};
174
179
 
194
199
    CONTACT_FEATURE_FLAG_CLIENT_TYPES = 1 << TP_CONTACT_FEATURE_CLIENT_TYPES,
195
200
    CONTACT_FEATURE_FLAG_STATES = 1 << TP_CONTACT_FEATURE_SUBSCRIPTION_STATES,
196
201
    CONTACT_FEATURE_FLAG_CONTACT_GROUPS = 1 << TP_CONTACT_FEATURE_CONTACT_GROUPS,
 
202
    CONTACT_FEATURE_FLAG_CONTACT_BLOCKING = 1 << TP_CONTACT_FEATURE_CONTACT_BLOCKING,
197
203
} ContactFeatureFlags;
198
204
 
199
205
struct _TpContactPrivate {
236
242
    /* ContactGroups */
237
243
    /* array of dupped strings */
238
244
    GPtrArray *contact_groups;
 
245
 
 
246
    /* ContactBlocking */
 
247
    gboolean is_blocked;
239
248
};
240
249
 
241
250
 
913
922
      g_value_set_boxed (value, tp_contact_get_contact_groups (self));
914
923
      break;
915
924
 
 
925
    case PROP_IS_BLOCKED:
 
926
      g_value_set_boolean (value, tp_contact_is_blocked (self));
 
927
      break;
 
928
 
916
929
    default:
917
930
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
918
931
      break;
1288
1301
  g_object_class_install_property (object_class, PROP_CONTACT_GROUPS,
1289
1302
      param_spec);
1290
1303
 
 
1304
/**
 
1305
   * TpContact:is-blocked:
 
1306
   *
 
1307
   * %TRUE if the contact has been blocked.
 
1308
   *
 
1309
   * This is set to %FALSE if %TP_CONTACT_FEATURE_CONTACT_BLOCKING is not
 
1310
   * prepared on this contact, or if the connection does not implement
 
1311
   * ContactBlocking interface.
 
1312
   *
 
1313
   * Since: 0.17.0
 
1314
   */
 
1315
  param_spec = g_param_spec_boolean ("is-blocked",
 
1316
      "is blocked",
 
1317
      "TRUE if contact is blocked",
 
1318
      FALSE,
 
1319
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
1320
  g_object_class_install_property (object_class, PROP_IS_BLOCKED, param_spec);
 
1321
 
1291
1322
  /**
1292
1323
   * TpContact::contact-groups-changed:
1293
1324
   * @contact: A #TpContact
3716
3747
      G_TYPE_STRV);
3717
3748
  contact_maybe_set_contact_groups (contact, boxed);
3718
3749
 
 
3750
  /* ContactBlocking */
 
3751
  if (wanted & CONTACT_FEATURE_FLAG_CONTACT_BLOCKING)
 
3752
    {
 
3753
      gboolean is_blocked, valid;
 
3754
 
 
3755
      is_blocked = tp_asv_get_boolean (asv,
 
3756
          TP_TOKEN_CONNECTION_INTERFACE_CONTACT_BLOCKING_BLOCKED, &valid);
 
3757
 
 
3758
      if (valid)
 
3759
        _tp_contact_set_is_blocked (contact, is_blocked);
 
3760
    }
 
3761
 
3719
3762
  return TRUE;
3720
3763
}
3721
3764
 
3919
3962
              contacts_bind_to_contact_groups_changed (connection);
3920
3963
            }
3921
3964
        }
 
3965
      else if (q == TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)
 
3966
        {
 
3967
          if ((wanted & CONTACT_FEATURE_FLAG_CONTACT_BLOCKING) != 0)
 
3968
            {
 
3969
              GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_BLOCKING, 0 };
 
3970
 
 
3971
              g_ptr_array_add (array,
 
3972
                  TP_IFACE_CONNECTION_INTERFACE_CONTACT_BLOCKING);
 
3973
 
 
3974
              /* The BlockedContactsChanged signal is already handled by
 
3975
               * connection-contact-list.c so we just have to prepare
 
3976
               * TP_CONNECTION_FEATURE_CONTACT_BLOCKING to make sure it's
 
3977
               * connected. */
 
3978
              if (!tp_proxy_is_prepared (connection,
 
3979
                    TP_CONNECTION_FEATURE_CONTACT_BLOCKING))
 
3980
                {
 
3981
                  tp_proxy_prepare_async (connection, features, NULL, NULL);
 
3982
                }
 
3983
            }
 
3984
        }
3922
3985
    }
3923
3986
 
3924
3987
  g_ptr_array_add (array, NULL);
4482
4545
      contacts_requested_handles, context, contacts_context_unref,
4483
4546
      weak_object);
4484
4547
}
 
4548
 
 
4549
void
 
4550
_tp_contact_set_is_blocked (TpContact *self,
 
4551
    gboolean is_blocked)
 
4552
{
 
4553
  if (self == NULL)
 
4554
    return;
 
4555
 
 
4556
  self->priv->has_features |= CONTACT_FEATURE_FLAG_CONTACT_BLOCKING;
 
4557
 
 
4558
  if (self->priv->is_blocked == is_blocked)
 
4559
    return;
 
4560
 
 
4561
  self->priv->is_blocked = is_blocked;
 
4562
 
 
4563
  g_object_notify ((GObject *) self, "is-blocked");
 
4564
}
 
4565
 
 
4566
/**
 
4567
 * tp_contact_is_blocked:
 
4568
 * @self: a #TpContact
 
4569
 *
 
4570
 * <!-- -->
 
4571
 
 
4572
 * Returns: the value of #TpContact:is-blocked.
 
4573
 *
 
4574
 * Since: 0.17.0
 
4575
 */
 
4576
gboolean
 
4577
tp_contact_is_blocked (TpContact *self)
 
4578
{
 
4579
  g_return_val_if_fail (TP_IS_CONTACT (self), FALSE);
 
4580
 
 
4581
  return self->priv->is_blocked;
 
4582
}