static void
get_contact_cb (TpConnection *connection,
    guint n_contacts,
    TpContact * const *contacts,
    guint n_failed,
    const TpHandle *failed,
    const GError *error,
    gpointer user_data,
    GObject *weak_object)
{
  EmpathyCallObserver *self = (EmpathyCallObserver *) weak_object;
  NotifyNotification *notification;
  TpContact *contact;
  gchar *summary, *body;
  EmpathyContact *emp_contact;
  GdkPixbuf *pixbuf;

  if (n_contacts != 1)
    {
      DEBUG ("Failed to get TpContact; ignoring notification bubble");
      return;
    }

  contact = contacts[0];

  summary = g_strdup_printf (_("Missed call from %s"),
      tp_contact_get_alias (contact));
  body = g_strdup_printf (
      _("%s just tried to call you, but you were in another call."),
      tp_contact_get_alias (contact));

  notification = notify_notification_new (summary, body, NULL);

  emp_contact = empathy_contact_dup_from_tp_contact (contact);
  pixbuf = empathy_notify_manager_get_pixbuf_for_notification (
      self->priv->notify_mgr, emp_contact, EMPATHY_IMAGE_AVATAR_DEFAULT);

  if (pixbuf != NULL)
    {
      notify_notification_set_icon_from_pixbuf (notification, pixbuf);
      g_object_unref (pixbuf);
    }

  notify_notification_show (notification, NULL);

  g_object_unref (notification);
  g_free (summary);
  g_free (body);
  g_object_unref (emp_contact);
}
static void
mex_telepathy_channel_on_contact_fetched (TpConnection     *connection,
                                          guint             n_contacts,
                                          TpContact *const *contacts,
                                          guint             n_failed,
                                          const TpHandle   *failed,
                                          const GError     *fetched_error,
                                          gpointer          user_data,
                                          GObject          *weak_object)
{
  MexTelepathyChannel *self = MEX_TELEPATHY_CHANNEL (user_data);

  int i = 0;

  if (self->priv->channel)
    {
      for (i = 0; i < n_contacts; ++i)
        {
          gchar *text;
          const gchar *alias;
          TpContact *current;
          GFile *file;

          // Get the contacts.
          current = contacts[i];

          // Connect to alias change signal.
          // Add the alias to the label.
          alias = tp_contact_get_alias (current);
          mx_label_set_text (MX_LABEL (self->priv->title_label),
                             alias);

          if (tp_channel_get_requested(self->priv->channel))
            text = g_strdup_printf ("Calling %s", alias);
          else
            text = g_strdup_printf ("Setting up call with %s", alias);
          mx_label_set_text (MX_LABEL (self->priv->busy_label), text);
          g_free (text);

          file = tp_contact_get_avatar_file (current);
          if (file)
            {
              gchar *filename = g_file_get_path (file);
              GError *error = NULL;
              MEX_DEBUG ("setting new avatar filename to %s", filename);
              mx_image_set_from_file (MX_IMAGE(self->priv->avatar_image),
                                      filename,
                                      &error);
              if (error)
                {
                  MEX_ERROR ("ERROR %s loading avatar from file %s\n",
                             error->message, filename);
                  g_clear_error (&error);
                }
              if (filename)
                g_free (filename);
            }
        }
    }
}
示例#3
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;
}
示例#4
0
文件: approver.c 项目: CaoMomo/core
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 void
list_contacts_for_connection_cb(TpConnection* /*connection*/,
						guint n_contacts,
						TpContact * const *contacts,
						guint /*n_invalid*/,
						const TpHandle* /*invalid*/,
						const GError* error,
						gpointer user_data,
						GObject* /*weak_object*/)
{
	UT_DEBUGMSG(("list_contacts_for_connection_cb()\n"));
	UT_return_if_fail(!error);

	TelepathyAccountHandler* pHandler = reinterpret_cast<TelepathyAccountHandler*>(user_data);
	UT_return_if_fail(pHandler);

	UT_DEBUGMSG(("Got %d contacts!\n", n_contacts));
	for (UT_uint32 i = 0; i < n_contacts; i++)
	{
		TpContact* contact = contacts[i];
		UT_continue_if_fail(contact);
		UT_DEBUGMSG(("Alias: '%s'\n", tp_contact_get_alias(contact)));

		pHandler->addContact(contact);
	}
}
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);
}
static void
chat_conversations_list_add_row_avatar (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  ChatConversationsList *self = CHAT_CONVERSATIONS_LIST (user_data);
  TpContact *contact = TP_CONTACT (source_object);
  GError *error;
  GtkWidget *grid;
  GtkWidget *image;
  GtkWidget *label;
  GtkWidget *row;
  TplEvent *event;
  const gchar *alias;
  const gchar *message;
  gchar *markup;

  event = TPL_EVENT (g_object_get_data (G_OBJECT (contact), "chat-conversations-list-last-event"));
  alias = tp_contact_get_alias (contact);

  error = NULL;
  image = GTK_WIDGET (chat_utils_get_contact_avatar_finish (contact, res, &error));
  if (error != NULL)
    {
      image = GTK_WIDGET (chat_utils_get_contact_avatar_default ());
      g_warning ("Unable to get avatar for %s: %s", alias, error->message);
      g_error_free (error);
    }

  row = gtk_list_box_row_new ();
  g_object_set_data_full (G_OBJECT (row), "chat-conversations-list-contact", g_object_ref (contact), g_object_unref);
  gtk_container_add (GTK_CONTAINER (self), row);

  grid = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_HORIZONTAL);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
  gtk_container_add (GTK_CONTAINER (row), grid);

  gtk_widget_set_hexpand (image, FALSE);
  gtk_container_add (GTK_CONTAINER (grid), image);

  message = tpl_text_event_get_message (TPL_TEXT_EVENT (event));
  markup = g_markup_printf_escaped ("<b>%s</b>\n%s", alias, message);
  label = gtk_label_new (NULL);
  gtk_widget_set_halign (label, GTK_ALIGN_START);
  gtk_widget_set_hexpand (label, TRUE);
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
  gtk_label_set_markup (GTK_LABEL (label), markup);
  gtk_container_add (GTK_CONTAINER (grid), label);
  g_free (markup);

  gtk_widget_show_all (row);

  g_object_set_data (G_OBJECT (contact), "chat-conversations-list-last-event", NULL);
  g_object_unref (self);
}
示例#8
0
文件: msg.c 项目: 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);
        }
    }
}
示例#9
0
文件: msg.c 项目: 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);
}
示例#11
0
static void remmina_tp_channel_handler_get_contacts(TpConnection *connection, guint n_contacts, TpContact * const *contacts,
		guint n_failed, const TpHandle *failed, const GError *error, gpointer user_data, GObject *weak_object)
{
	RemminaTpChannelHandler *chandler = (RemminaTpChannelHandler *) user_data;
	TpContact *contact;
	gchar *token;
	gchar *cm;
	gchar *protocol;
	gchar *filename;
	GdkPixbuf *pixbuf;
	GtkWidget *image;
	GtkWidget *dialog;

	if (error != NULL)
	{
		g_print("remmina_tp_channel_handler_get_contacts: %s", error->message);
		remmina_tp_channel_handler_free(chandler);
		return;
	}
	if (n_contacts <= 0)
	{
		g_print("remmina_tp_channel_handler_get_contacts: no contacts\n");
		remmina_tp_channel_handler_free(chandler);
		return;
	}
	contact = contacts[0];
	chandler->alias = g_strdup(tp_contact_get_alias(contact));

	dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
			_("%s wants to share his/her desktop.\nDo you accept the invitation?"), chandler->alias);
	g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(remmina_tp_channel_handler_on_response), chandler);
	g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy), NULL);
	gtk_window_set_title(GTK_WINDOW(dialog), _("Desktop sharing invitation"));
	remmina_plugin_telepathy_service->ui_register(dialog);
	gtk_widget_show(dialog);

	token = (gchar *) tp_contact_get_avatar_token(contact);
	if (token == NULL)
	{
		return;
	}
	if (!tp_connection_parse_object_path(chandler->connection, &protocol, &cm))
	{
		g_print("tp_connection_parse_object_path: failed\n");
		return;
	}
	token = tp_escape_as_identifier(token);
	filename = g_build_filename(g_get_user_cache_dir(), "telepathy", "avatars", cm, protocol, token, NULL);
	g_free(cm);
	g_free(protocol);
	g_free(token);
	if (g_file_test(filename, G_FILE_TEST_EXISTS))
	{
		pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
		if (pixbuf)
		{
			image = gtk_image_new_from_pixbuf(pixbuf);
			gtk_widget_show(image);
			g_object_unref(pixbuf);
			gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog), image);
		}
	}
	g_free(filename);
}
示例#12
0
static void
chat_conversations_list_connection_prepare (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  ChatConversationsList *self = CHAT_CONVERSATIONS_LIST (user_data);
  ChatConversationsListPrivate *priv = self->priv;
  GError *error;
  GList *contacts = NULL;
  GPtrArray *contact_list = NULL;
  TpAccount *account;
  TpConnection *conn = TP_CONNECTION (source_object);
  TpContactListState state;
  guint i;

  error = NULL;
  if (!tp_proxy_prepare_finish (source_object, res, &error))
    {
      g_warning ("Unable to prepare the connection: %s", error->message);
      g_error_free (error);
      goto out;
    }

  state = tp_connection_get_contact_list_state (conn);
  if (state != TP_CONTACT_LIST_STATE_SUCCESS)
    {
      g_warning ("Value of connection:contact-list-state %p was %d", conn, state);
      goto out;
    }

  account = tp_connection_get_account (conn);
  contact_list = tp_connection_dup_contact_list (conn);
  for (i = 0; i < contact_list->len; i++)
    {
      ChatConversationsListGetFilteredEventsData *data;
      TpContact *contact;
      TplEntity *entity;

      contact = TP_CONTACT (g_ptr_array_index (contact_list, i));
      entity = tpl_entity_new_from_tp_contact (contact, TPL_ENTITY_CONTACT);
      if (tpl_log_manager_exists (priv->lm, account, entity, TPL_EVENT_MASK_TEXT))
        {
          g_message ("%s", tp_contact_get_alias (contact));
          contacts = g_list_prepend (contacts, g_object_ref (contact));

          data = chat_conversations_list_get_filtered_events_data_new (self, contact);
          tpl_log_manager_get_filtered_events_async (priv->lm,
                                                     account,
                                                     entity,
                                                     TPL_EVENT_MASK_TEXT,
                                                     1,
                                                     NULL,
                                                     NULL,
                                                     chat_conversations_list_get_filtered_events,
                                                     data);
        }

      g_object_unref (entity);
    }

  g_hash_table_insert (priv->accounts, g_object_ref (account), contacts);

 out:
  if (contact_list != NULL)
    g_ptr_array_unref (contact_list);
  g_object_unref (self);
}