Example #1
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);
        }
    }
}
Example #2
0
FolksIndividual *
empathy_create_individual_from_tp_contact (TpContact *contact)
{
  GeeSet *personas;
  TpfPersona *persona;
  FolksIndividual *individual;

  persona = tpf_persona_dup_for_contact (contact);
  if (persona == NULL)
    {
      DEBUG ("Failed to get a persona for %s",
          tp_contact_get_identifier (contact));
      return NULL;
    }

  personas = GEE_SET (
      gee_hash_set_new (FOLKS_TYPE_PERSONA, g_object_ref, g_object_unref,
      g_direct_hash, g_direct_equal));

  gee_collection_add (GEE_COLLECTION (personas), persona);

  individual = folks_individual_new (personas);

  g_clear_object (&persona);
  g_clear_object (&personas);

  return individual;
}
Example #3
0
static void
show_dialog (
    TpSimpleApprover *self,
    TpChannelDispatchOperation *cdo,
    TpContact *target)
{
    GFile *avatar_file = tp_contact_get_avatar_file (target);
    GtkWidget *dialog = gtk_message_dialog_new_with_markup (NULL,
        0, /* flags */
        GTK_MESSAGE_QUESTION,
        GTK_BUTTONS_NONE,
        "<b>%s</b> (<i>%s</i>) would like to edit a spreadsheet in LibreOffice "
        "with you.",
        tp_contact_get_alias (target),
        tp_contact_get_identifier (target));

    if (avatar_file != NULL)
    {
        GtkWidget *avatar = gtk_image_new_from_file (g_file_get_path (avatar_file));

        gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), avatar);
    }

    gtk_dialog_add_buttons (GTK_DIALOG (dialog),
        "_Reject", GTK_RESPONSE_REJECT,
        "_Accept", GTK_RESPONSE_ACCEPT,
        NULL);

    g_object_set_data_full (G_OBJECT (dialog), "client", g_object_ref (self), g_object_unref);
    g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), g_object_ref (cdo));

    gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);

    gtk_widget_show_all (dialog);
}
static char *
contact_pretty_name (TpContact *contact)
{
  const char *alias = tp_contact_get_alias (contact);
  const char *identifier = tp_contact_get_identifier (contact);

  if (tp_strdiff (alias, identifier))
    return g_strdup_printf ("%s (%s)", alias, identifier);
  else
    return g_strdup (alias);
}
/*
 * Create a new TpSignalledMessage.
 *
 * Any message-sender and message-sender-id in parts[0] will be ignored
 * completely: the caller is responsible for interpreting those fields
 * and providing a suitable @sender.
 *
 * The message-sender will be removed from the header, and the
 * message-sender-id will be set to match the #TpContact:identifier of @sender.
 *
 * @sender may be %NULL, which means the message wasn't sent by a contact
 * (this could be used for administrative messages from a chatroom or the
 * server) or we have no idea who sent it.
 */
TpMessage *
_tp_signalled_message_new (const GPtrArray *parts,
    TpContact *sender)
{
  TpMessage *self;
  guint i;

  g_return_val_if_fail (parts != NULL, NULL);
  g_return_val_if_fail (parts->len > 0, NULL);
  g_return_val_if_fail (sender == NULL || TP_IS_CONTACT (sender), NULL);

  self = g_object_new (TP_TYPE_SIGNALLED_MESSAGE,
      "sender", sender,
      NULL);

  for (i = 0; i < parts->len; i++)
    {
      /* First part is automatically created */
      if (i != 0)
        tp_message_append_part (self);

      tp_g_hash_table_update (g_ptr_array_index (self->parts, i),
          g_ptr_array_index (parts, i),
          (GBoxedCopyFunc) g_strdup,
          (GBoxedCopyFunc) tp_g_value_slice_dup);
    }

  /* This handle may not be persistent, user should use the TpContact
   * directly */
  tp_message_delete_key (self, 0, "message-sender");

  /* override any message-sender-id that the message might have had */
  if (sender == NULL)
    {
      tp_message_delete_key (self, 0, "message-sender-id");
    }
  else
    {
      tp_message_set_string (self, 0, "message-sender-id",
          tp_contact_get_identifier (sender));
    }

  _tp_message_set_immutable (self);

  return self;
}
Example #6
0
FolksIndividual *
empathy_create_individual_from_tp_contact (TpContact *contact)
{
  TpfPersona *persona;
  FolksIndividual *individual;

  persona = tpf_persona_dup_for_contact (contact);
  if (persona == NULL)
    {
      DEBUG ("Failed to get a persona for %s",
          tp_contact_get_identifier (contact));
      return NULL;
    }

  individual = create_individual_from_persona (FOLKS_PERSONA (persona));

  g_object_unref (persona);
  return individual;
}
Example #7
0
File: msg.c Project: keis/charlatan
static void
contact_cb (ChVisitor *visitor,
            TpContact *contact)
{
    (void) visitor;
    const gchar *status;

    if (list_messages) {
        printf ("%s\t%s\n",
                tp_contact_get_alias (contact),
                tp_contact_get_identifier (contact));
    }

    if (send_message) {
        status = tp_contact_get_presence_status (contact);
        if (contact_status_ok (status)) {
            ch_visitor_visit_contact_channel (visitor, contact);
        }
    }
}
static void
contact_blocking_dialog_add_blocked (
    EmpathyContactBlockingDialog *self,
    GPtrArray *blocked)
{
  EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
  guint i;

  if (blocked == NULL)
    return;

  for (i = 0; i < blocked->len; i++)
    {
      TpContact *contact = g_ptr_array_index (blocked, i);

      gtk_list_store_insert_with_values (priv->blocked_contacts, NULL, -1,
          COL_BLOCKED_IDENTIFIER, tp_contact_get_identifier (contact),
          COL_BLOCKED_CONTACT, contact,
          -1);
    }
}
Example #9
0
static void
visit_contact_channel (GObject      *source,
                       GAsyncResult *result,
                       gpointer      user_data)
{
    ChChannelRequest *chreq = (ChChannelRequest*) user_data;
    ChVisitor *self = chreq->self;
    TpContact *contact = chreq->contact;
    g_free (chreq);

    const char *ident, *contact_ident;
    GError *error = NULL;
    GPtrArray *channels;

    if (!list_channels_finish (source, result, &channels, &error)) {
        g_printerr ("error listing channels: %s\n", error->message);
        return;
    }

    contact_ident = tp_contact_get_identifier (contact);

    // Try to find a matching channel among the already established channels
    for (unsigned int i = 0; i < channels->len; i++) {
        TpChannel *channel = g_ptr_array_index (channels, i);
        ident = tp_channel_get_identifier (channel);

        if (!strcmp (ident, contact_ident)) {
            self->visit_channel (self, channel);
            goto done;
        }
    }

    // Request a new channel
    request_channel (self, contact);

done:
    g_ptr_array_free (channels, TRUE);
    ch_visitor_decref (self);
}
static void
_new_remote_connection_with_contact (TpConnection *conn,
    guint n_contacts,
    TpContact * const *contacts,
    guint n_failed,
    const TpHandle *failed,
    const GError *in_error,
    gpointer user_data,
    GObject *obj)
{
  TpStreamTubeChannel *self = (TpStreamTubeChannel *) obj;
  TpContact *contact;
  TpStreamTubeConnection *tube_conn = user_data;

  if (in_error != NULL)
    {
      DEBUG ("Failed to prepare TpContact: %s", in_error->message);
      return;
    }

  if (n_failed > 0)
    {
      DEBUG ("Failed to prepare TpContact (InvalidHandle)");
      return;
    }

  contact = contacts[0];

  _tp_stream_tube_connection_set_contact (tube_conn, contact);

  DEBUG ("Accepting incoming GIOStream from %s",
      tp_contact_get_identifier (contact));

  g_signal_emit (self, _signals[INCOMING], 0, tube_conn);

  /* anyone receiving the signal is required to hold their own reference */
}
Example #11
0
File: msg.c Project: keis/charlatan
static void
message_cb (TpMessage *message)
{
    TpContact *sender = tp_signalled_message_get_sender (message);
    GDateTime *received = g_date_time_new_from_unix_utc (
        tp_message_get_received_timestamp (message));
    gchar *timestamp = g_date_time_format (received, "%Y-%m-%d %H:%M:%S");
    const gchar *sender_identifier = tp_contact_get_identifier (sender);
    const gchar *sender_alias = tp_contact_get_alias (sender);

    if (!writer.first) {
        g_print ("\n\n");
    } else {
        writer.first = 0;
    }

    printf ("Message-Token: %s\n", tp_message_get_token (message));
    printf ("From: \"%s\" <%s>\n", sender_alias, sender_identifier);
    printf ("Date: %s\n\n", timestamp);

    g_free (timestamp);

    unsigned int parts = tp_message_count_parts (message);
    for (unsigned int i = 1; i < parts; i++) {
        const GHashTable *part = tp_message_peek (message, i);
        const gchar *content_type = g_value_get_string (
            g_hash_table_lookup ((GHashTable*)part, "content-type"));
        const gchar *content = g_value_get_string (
            g_hash_table_lookup ((GHashTable*)part, "content"));

        if (verbose) {
            printf ("- #%d %s\n", i, content_type);
        }
        printf ("%s\n", content);
    }
}
static void
contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
    EmpathyContactBlockingDialog *self)
{
  TpConnection *conn = empathy_account_chooser_get_connection (
      EMPATHY_ACCOUNT_CHOOSER (account_chooser));
  GPtrArray *blocked;
  GPtrArray *members;
  guint i;

  if (self->priv->block_account_changed > 0)
    return;

  if (conn == self->priv->current_conn)
    return;

  /* clear the lists of contacts */
  gtk_list_store_clear (self->priv->blocked_contacts);
  gtk_list_store_clear (self->priv->completion_contacts);

  if (self->priv->current_conn != NULL)
    {
      g_signal_handlers_disconnect_by_func (self->priv->current_conn,
          blocked_contacts_changed_cb, self);

      g_clear_object (&self->priv->current_conn);
    }

  if (conn == NULL)
    return;

  DEBUG ("Account changed: %s", get_pretty_conn_name (conn));

  self->priv->current_conn = g_object_ref (conn);

  tp_g_signal_connect_object (conn, "blocked-contacts-changed",
      G_CALLBACK (blocked_contacts_changed_cb), self, 0);

  blocked = tp_connection_get_blocked_contacts (conn);

  DEBUG ("%u contacts blocked on %s",
      blocked != NULL ? blocked->len : 0, get_pretty_conn_name (conn));

  contact_blocking_dialog_add_blocked (self, blocked);

  DEBUG ("Loading contacts");

  members = tp_connection_dup_contact_list (conn);

  for (i = 0; i < members->len; i++)
    {
      TpContact *contact = g_ptr_array_index (members, i);
      gchar *tmpstr;

      tmpstr = g_strdup_printf ("%s (%s)",
          tp_contact_get_alias (contact),
          tp_contact_get_identifier (contact));

      gtk_list_store_insert_with_values (self->priv->completion_contacts,
          NULL, -1,
          COL_COMPLETION_IDENTIFIER, tp_contact_get_identifier (contact),
          COL_COMPLETION_TEXT, tmpstr,
          -1);

      g_free (tmpstr);
    }

  g_ptr_array_unref (members);
}