Example #1
0
gboolean
polari_room_should_highlight_message (PolariRoom *room,
                                      TpMessage *message)
{
  PolariRoomPrivate *priv;
  TpConnection *conn;
  TpContact *sender, *self;
  char *text;
  gboolean result;

  g_return_val_if_fail (POLARI_IS_ROOM (room), FALSE);

  priv = room->priv;

  if (!priv->channel)
    return FALSE;

  conn = tp_channel_get_connection (room->priv->channel);
  self = tp_connection_get_self_contact (conn);

  if (tp_signalled_message_get_sender (message) == self)
    return FALSE;

  text = tp_message_to_text (message, NULL);
  result = strstr(text, tp_contact_get_alias (self)) != NULL;
  g_free (text);

  return result;
}
static void
contact_ready_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TpConnection *conn = (TpConnection *) object;
  GHashTable *asv;
  ContactPair *pair;
  GError *error = NULL;

  pair = g_slice_new0 (ContactPair);
  pair->contacts[0] = tp_connection_dup_contact_by_id_finish (conn,
      result, &error);
  pair->contacts[1] = g_object_ref (tp_connection_get_self_contact (conn));

  if (die_if (error, "tp_connection_dup_contact_by_id_async()"))
    {
      g_clear_error (&error);
      contact_pair_free (pair);
      return;
    }

  asv = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
      (GDestroyNotify) tp_g_value_slice_free);
  g_hash_table_insert (asv, "previous-owner",
      tp_g_value_slice_new_static_string ("Shadowman"));

  example_cli_connection_interface_hats_call_set_hat (conn, -1,
      "red", EXAMPLE_HAT_STYLE_FEDORA, asv,
      set_hat_cb, pair, contact_pair_free, NULL);

  g_hash_table_unref (asv);
}
Example #3
0
File: msg.c Project: keis/charlatan
static void
connection_cb (ChVisitor    *visitor,
               TpConnection *connection,
               guint         status)
{
    (void) visitor;
    char **userit;

    TpContact *self;
    if (status == 0) {
        if (verbose > 0) {
            self = tp_connection_get_self_contact (connection);

            g_printerr ("connection ready: %s/%s (%s)\n",
                        tp_connection_get_cm_name (connection),
                        tp_connection_get_protocol_name(connection),
                        self ? tp_contact_get_identifier (self) : "n/a");
        }

        if (send_message) {
            for (userit = users; *userit; userit += 1) {
                ch_visitor_visit_connection_contact (visitor,
                                                     connection,
                                                     *userit);
            }
        } else {
            ch_visitor_visit_channels (visitor, connection);
        }
    }
}
/**
 * shell_get_self_contact_features:
 * @self: A connection, which must be ready
 * @n_features: Number of features in features
 * @features: (array length=n_features) (allow-none) (element-type uint):
 *  Array of features
 * @callback: (scope async): User callback to run when the contact is ready
 *
 * Wrap tp_connection_upgrade_contacts due to the lack of support for
 * proper arrays arguments in GJS.
 */
void
shell_get_self_contact_features (TpConnection *self,
                                 guint n_features,
                                 const TpContactFeature *features,
                                 ShellGetSelfContactFeaturesCb callback)
{
  TpContact *self_contact = tp_connection_get_self_contact (self);

  tp_connection_upgrade_contacts (self, 1, &self_contact,
                                  n_features, features,
                                  shell_global_get_self_contact_features_cb,
                                  callback, NULL, NULL);
}
static void
reload_contact_info (TpawUserInfo *self)
{
  TpConnection *connection;
  TpContact *contact = NULL;
  TpContactInfoFlags flags;

  /* Cancel previous RequestContactInfo, if any */
  if (self->priv->details_cancellable != NULL)
    g_cancellable_cancel (self->priv->details_cancellable);
  g_clear_object (&self->priv->details_cancellable);

  /* Remove current contact info widgets, if any */
  gtk_container_foreach (GTK_CONTAINER (self), grid_foreach_cb, NULL);
  gtk_widget_hide (self->priv->details_label);
  gtk_widget_hide (self->priv->details_spinner);

  tp_clear_pointer (&self->priv->details_to_set, tp_contact_info_list_free);
  self->priv->details_changed = FALSE;

  connection = tp_account_get_connection (self->priv->account);
  if (connection != NULL)
    {
      contact = tp_connection_get_self_contact (connection);

      /* FIXME: we should rely on the factory to do this, see bgo#706892 */
      if (!tp_proxy_is_prepared (connection,
            TP_CONNECTION_FEATURE_CONTACT_INFO) &&
          !self->priv->tried_preparing_contact_info)
        {
          GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };

          /* Prevent an infinite loop if the connection doesn't implement
           * ContactInfo, see bgo#709677 */
          self->priv->tried_preparing_contact_info = TRUE;

          tp_proxy_prepare_async (connection, features,
              connection_contact_info_prepared_cb, g_object_ref (self));
        }
    }

  /* Display infobar if we don't have a self contact (probably offline) */
  if (contact == NULL)
    {
      GtkWidget *infobar;
      GtkWidget *content;
      GtkWidget *label;

      infobar = gtk_info_bar_new ();
      gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
      content = gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar));
      label = gtk_label_new (_("Go online to edit your personal information."));
      gtk_container_add (GTK_CONTAINER (content), label);
      gtk_widget_show (label);

      gtk_grid_attach_next_to ((GtkGrid *) self, infobar,
          NULL, GTK_POS_BOTTOM, 3, 1);
      gtk_widget_show (infobar);

      g_object_set_data (G_OBJECT (infobar),
          DATA_IS_CONTACT_INFO, (gpointer) TRUE);
      return;
    }

  if (!tp_proxy_has_interface_by_id (connection,
          TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
    return;

  flags = tp_connection_get_contact_info_flags (connection);
  if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0)
    return;

  /* Request the contact's info */
  gtk_widget_show (self->priv->details_spinner);
  gtk_spinner_start (GTK_SPINNER (self->priv->details_spinner));

  g_assert (self->priv->details_cancellable == NULL);
  self->priv->details_cancellable = g_cancellable_new ();
  tp_contact_request_contact_info_async (contact,
      self->priv->details_cancellable, request_contact_info_cb,
      self);
}
static guint
fill_contact_info_grid (TpawUserInfo *self)
{
  TpConnection *connection;
  TpContact *contact;
  GList *specs, *l;
  guint n_rows = 0;
  GList *info;
  const char **field_names = tpaw_contact_info_get_field_names (NULL);
  guint i;

  g_assert (self->priv->details_to_set == NULL);

  connection = tp_account_get_connection (self->priv->account);
  contact = tp_connection_get_self_contact (connection);
  specs = tp_connection_dup_contact_info_supported_fields (connection);
  info = tp_contact_dup_contact_info (contact);

  /* Look at the fields set in our vCard */
  for (l = info; l != NULL; l = l->next)
    {
      TpContactInfoField *field = l->data;

      /* For some reason it can happen that the vCard contains fields the CM
       * claims to be not supported. This is a workaround for gabble bug
       * https://bugs.freedesktop.org/show_bug.cgi?id=64319. But we shouldn't
       * crash on buggy CM anyway. */
      if (get_spec_from_list (specs, field->field_name) == NULL)
        {
          DEBUG ("Buggy CM: self's vCard contains %s field but it is not in "
              "Connection' supported fields", field->field_name);
          continue;
        }

      /* make a copy for the details_to_set list */
      field = tp_contact_info_field_copy (field);
      DEBUG ("Field %s is in our vCard", field->field_name);

      self->priv->details_to_set = g_list_prepend (self->priv->details_to_set,
          field);
    }

  /* Add fields which are supported but not in the vCard */
  for (i = 0; field_names[i] != NULL; i++)
    {
      TpContactInfoFieldSpec *spec;
      TpContactInfoField *field;

      /* Check if the field was in the vCard */
      if (field_name_in_field_list (self->priv->details_to_set,
            field_names[i]))
        continue;

      /* Check if the CM supports the field */
      spec = get_spec_from_list (specs, field_names[i]);
      if (spec == NULL)
        continue;

      /* add an empty field so user can set a value */
      field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);

      self->priv->details_to_set = g_list_prepend (self->priv->details_to_set,
          field);
    }

  /* Add widgets for supported fields */
  self->priv->details_to_set = g_list_sort (self->priv->details_to_set,
      (GCompareFunc) tpaw_contact_info_field_spec_cmp);

  for (l = self->priv->details_to_set; l != NULL; l= g_list_next (l))
    {
      TpContactInfoField *field = l->data;
      GtkWidget *label, *w;
      TpContactInfoFieldSpec *spec;
      gboolean has_field;
      char *title;

      has_field = tpaw_contact_info_lookup_field (field->field_name,
          NULL, NULL);
      if (!has_field)
        {
          /* We don't display this field so we can't change it.
           * But we put it in the details_to_set list so it won't be erased
           * when calling SetContactInfo (bgo #630427) */
          DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
          continue;
        }

      spec = get_spec_from_list (specs, field->field_name);
      /* We shouldn't have added the field to details_to_set if it's not
       * supported by the CM */
      g_assert (spec != NULL);

      if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
        {
          DEBUG ("Ignoring field '%s' due it to having the "
              "Overwritten_By_Nickname flag", field->field_name);
          continue;
        }

      /* Add Title */
      title = tpaw_contact_info_field_label (field->field_name,
          field->parameters,
          (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT));
      label = gtk_label_new (title);
      g_free (title);

      /* TODO: if TP_CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT is not set we
       * should allow user to tag the vCard fields (bgo#672034) */

      /* Add Value */
      if (!tp_strdiff (field->field_name, "bday"))
        {
          w = tpaw_calendar_button_new ();

          if (field->field_value[0])
            {
              GDate date;

              g_date_set_parse (&date, field->field_value[0]);
              if (g_date_valid (&date))
                {
                  tpaw_calendar_button_set_date (TPAW_CALENDAR_BUTTON (w),
                      &date);
                }
            }

          g_signal_connect (w, "date-changed",
            G_CALLBACK (bday_changed_cb), self);
        }
      else
        {
          w = gtk_entry_new ();
          gtk_entry_set_text (GTK_ENTRY (w),
              field->field_value[0] ? field->field_value[0] : "");
          g_signal_connect (w, "changed",
            G_CALLBACK (contact_info_changed_cb), self);
        }

      add_row (GTK_GRID (self), label, w, TRUE);

      g_object_set_data ((GObject *) w, DATA_FIELD, field);

      n_rows++;
    }

  tp_contact_info_spec_list_free (specs);
  tp_contact_info_list_free (info);

  return n_rows;
}