/**
 * empathy_server_sasl_handler_can_save_response_somewhere:
 * @self:
 *
 * Returns: %TRUE if the response can be saved somewhere, either the keyring
 *   or via Ch.I.CredentialsStorage
 */
gboolean
empathy_server_sasl_handler_can_save_response_somewhere (
    EmpathyServerSASLHandler *self)
{
  EmpathyServerSASLHandlerPriv *priv;
  gboolean may_save_response, may_save_response_valid;
  gboolean has_storage_iface;

  g_return_val_if_fail (EMPATHY_IS_SERVER_SASL_HANDLER (self), FALSE);

  priv = self->priv;

  /* determine if we are permitted to save the password locally */
  may_save_response = tp_asv_get_boolean (
      tp_channel_borrow_immutable_properties (priv->channel),
      TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
      &may_save_response_valid);

  if (!may_save_response_valid)
    {
      DEBUG ("MaySaveResponse unknown, assuming TRUE");
      may_save_response = TRUE;
    }

  has_storage_iface = tp_proxy_has_interface_by_id (priv->channel,
      EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE);

  return may_save_response || has_storage_iface;
}
void
empathy_tp_streamed_media_leave (EmpathyTpStreamedMedia *self)
{
  EmpathyTpStreamedMediaPriv *priv = GET_PRIV (self);
  TpHandle self_handle;
  GArray array = { (gchar *) &self_handle, 1 };

  if (!tp_proxy_has_interface_by_id (priv->channel,
        TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP))
    {
      empathy_tp_streamed_media_close (self);
      return;
    }

  self_handle = tp_channel_group_get_self_handle (priv->channel);
  if (self_handle == 0)
    {
      /* we are not member of the channel */
      empathy_tp_streamed_media_close (self);
      return;
    }

  tp_cli_channel_interface_group_call_remove_members (priv->channel, -1, &array,
      "", leave_remove_members_cb, self, NULL, G_OBJECT (self));
}
コード例 #3
0
static void
conn_ready (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  GError *error = NULL;
  TpConnection *conn = TP_CONNECTION (source);

  if (!tp_proxy_prepare_finish (conn, result, &error))
    {
      g_warning ("%s", error->message);
      g_main_loop_quit (mainloop);
      g_clear_error (&error);
      return;
    }

  if (!tp_proxy_has_interface_by_id (conn,
        EXAMPLE_IFACE_QUARK_CONNECTION_INTERFACE_HATS))
    {
      g_warning ("Connection does not support Hats interface");
      g_main_loop_quit (mainloop);
      return;
    }

  /* Get contact object for someone else */
  tp_connection_dup_contact_by_id_async (conn, "other@server", 0, NULL,
      contact_ready_cb, NULL);
}
コード例 #4
0
gboolean hev_impathy_server_sasl_handler_can_save_response_somewhere(
			HevImpathyServerSASLHandler *self)
{
	HevImpathyServerSASLHandlerPrivate * priv = NULL;
	gboolean may_save_response = FALSE,
			 may_save_response_valid = FALSE;
	gboolean has_storage_iface = FALSE;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	g_return_if_fail(HEV_IS_IMPATHY_SERVER_SASL_HANDLER(self));

	priv = HEV_IMPATHY_SERVER_SASL_HANDLER_GET_PRIVATE(self);

	/* determine if we are permitted to save the password locally */
	may_save_response = tp_asv_get_boolean(
				tp_channel_borrow_immutable_properties(priv->channel),
				TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
				&may_save_response_valid);

	if(!may_save_response_valid)
	{
		may_save_response = TRUE;
	}

#if 0 /* TODO */
	has_storage_iface = tp_proxy_has_interface_by_id(priv->channel,
				EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE);
#endif

	return may_save_response || has_storage_iface;

}
static void
tp_contact_list_add (EmpathyContactList *list,
		     EmpathyContact     *contact,
		     const gchar        *message)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	TpHandle handle;
	GArray handles = {(gchar *) &handle, 1};

	handle = empathy_contact_get_handle (contact);

	if (priv->subscribe) {
		tp_cli_channel_interface_group_call_add_members (priv->subscribe,
			-1, &handles, message, NULL, NULL, NULL, NULL);
	}

	if (priv->publish) {
		TpChannelGroupFlags flags = tp_channel_group_get_flags (priv->subscribe);
		if (flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD ||
		    g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle))) {
			tp_cli_channel_interface_group_call_add_members (priv->publish,
				-1, &handles, message, NULL, NULL, NULL, NULL);
		}
	}

	/* We want to unblock the contact */
	if (tp_proxy_has_interface_by_id (priv->connection,
		TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)) {
		TpContact *tp_contact = empathy_contact_get_tp_contact (contact);

		if (tp_contact != NULL)
			tp_contact_unblock_async (tp_contact, NULL, NULL);
	}
}
コード例 #6
0
static void
contact_blocking_dialog_refilter_account_chooser (
    EmpathyContactBlockingDialog *self)
{
  EmpathyAccountChooser *chooser =
    EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
  TpConnection *conn;
  gboolean enabled;

  DEBUG ("Refiltering account chooser");

  /* set the filter to refilter the account chooser */
  self->priv->block_account_changed++;
  empathy_account_chooser_set_filter (chooser,
      contact_blocking_dialog_filter_account_chooser, self);
  self->priv->block_account_changed--;

  conn = empathy_account_chooser_get_connection (chooser);
  enabled = (empathy_account_chooser_get_account (chooser) != NULL &&
             conn != NULL &&
             tp_proxy_has_interface_by_id (conn,
               TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING));

  if (!enabled)
    DEBUG ("No account selected");

  gtk_widget_set_sensitive (self->priv->add_button, enabled);
  gtk_widget_set_sensitive (self->priv->add_contact_entry, enabled);

  contact_blocking_dialog_account_changed (self->priv->account_chooser, self);
}
コード例 #7
0
void
_mcd_channel_undispatchable (McdChannel *channel)
{
    McdChannelPrivate *priv = MCD_CHANNEL_PRIV (channel);

    if (!_mcd_tp_channel_should_close (priv->tp_chan, "destroying"))
    {
        return;
    }

    DEBUG ("%p: %s", channel, mcd_channel_get_object_path (channel));

    /* Call Destroy() if possible, or Close() */
    if (tp_proxy_has_interface_by_id (priv->tp_chan,
        TP_IFACE_QUARK_CHANNEL_INTERFACE_DESTROYABLE))
    {
        DEBUG ("calling Destroy()");
        tp_cli_channel_interface_destroyable_call_destroy (priv->tp_chan,
                                                           -1, NULL,
                                                           NULL, NULL,
                                                           NULL);
    }
    else
    {
        DEBUG ("calling Close()");
        tp_cli_channel_call_close (priv->tp_chan, -1, NULL, NULL, NULL,
                                   NULL);
    }
}
コード例 #8
0
static void
connection_ready_cb (TpConnection *connection,
				const GError *error,
				gpointer user_data)
{
	EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (user_data);
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);

	if (error != NULL)
		goto out;

	/* FIXME: This should be moved to TpContact */
	tp_cli_connection_interface_avatars_connect_to_avatar_updated (priv->connection,
								       tp_contact_factory_avatar_updated_cb,
								       NULL, NULL,
								       G_OBJECT (tp_factory),
								       NULL);
	tp_cli_connection_interface_avatars_connect_to_avatar_retrieved (priv->connection,
									 tp_contact_factory_avatar_retrieved_cb,
									 NULL, NULL,
									 G_OBJECT (tp_factory),
									 NULL);

	if (tp_proxy_has_interface_by_id (connection,
				TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_CAPABILITIES)) {
		priv->contact_caps_supported = TRUE;

		tp_cli_connection_interface_contact_capabilities_connect_to_contact_capabilities_changed (
			priv->connection, tp_contact_factory_contact_capabilities_changed_cb,
			NULL, NULL, G_OBJECT (tp_factory), NULL);
	}
	else {
		tp_cli_connection_interface_capabilities_connect_to_capabilities_changed (priv->connection,
											  tp_contact_factory_capabilities_changed_cb,
											  NULL, NULL,
											  G_OBJECT (tp_factory),
											  NULL);
	}

	tp_cli_connection_interface_avatars_call_get_avatar_requirements (priv->connection,
									  -1,
									  tp_contact_factory_got_avatar_requirements_cb,
									  NULL, NULL,
									  G_OBJECT (tp_factory));

	if (!priv->contact_caps_supported) {
		tp_cli_dbus_properties_call_get (priv->connection, -1,
			TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
			"RequestableChannelClasses",
			get_requestable_channel_classes_cb, NULL, NULL,
			G_OBJECT (tp_factory));
	}

out:
	g_object_unref (tp_factory);
}
gboolean
empathy_tp_streamed_media_has_dtmf (EmpathyTpStreamedMedia *call)
{
  EmpathyTpStreamedMediaPriv *priv = GET_PRIV (call);

  g_return_val_if_fail (EMPATHY_IS_TP_STREAMED_MEDIA (call), FALSE);

  return tp_proxy_has_interface_by_id (priv->channel,
      TP_IFACE_QUARK_CHANNEL_INTERFACE_DTMF);
}
コード例 #10
0
static void
contact_blocking_dialog_filter_account_chooser (TpAccount *account,
    EmpathyAccountChooserFilterResultCallback callback,
    gpointer callback_data,
    gpointer user_data)
{
  TpConnection *conn = tp_account_get_connection (account);
  gboolean enable;

  enable =
    conn != NULL &&
    tp_proxy_has_interface_by_id (conn,
      TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING);

  callback (enable, callback_data);
}
コード例 #11
0
void
empathy_individual_manager_set_blocked (EmpathyIndividualManager *self,
    FolksIndividual *individual,
    gboolean blocked,
    gboolean abusive)
{
  GeeSet *personas;
  GeeIterator *iter;

  g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));

  personas = folks_individual_get_personas (individual);
  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
  while (gee_iterator_next (iter))
    {
      TpfPersona *persona = gee_iterator_get (iter);

      if (TPF_IS_PERSONA (persona))
        {
          TpContact *tp_contact;
          TpConnection *conn;

          tp_contact = tpf_persona_get_contact (persona);
          if (tp_contact == NULL)
            continue;

          conn = tp_contact_get_connection (tp_contact);

          if (!tp_proxy_has_interface_by_id (conn,
                TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
            continue;

          if (blocked)
            tp_contact_block_async (tp_contact, abusive, NULL, NULL);
          else
            tp_contact_unblock_async (tp_contact, NULL, NULL);
        }
      g_clear_object (&persona);
    }
  g_clear_object (&iter);
}
コード例 #12
0
ファイル: polari-room.c プロジェクト: jwendell/polari
static void
update_icon (PolariRoom *room)
{
  PolariRoomPrivate *priv = room->priv;

  g_clear_object (&priv->icon);

  if (priv->channel)
    {
      const char *icon_name;
      gboolean is_private;

      is_private = !tp_proxy_has_interface_by_id (TP_PROXY (priv->channel),
                                                  TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);
      icon_name = is_private ? "avatar-default-symbolic"
                             : "user-available-symbolic";
      priv->icon = g_themed_icon_new (icon_name);
    }

  g_object_notify_by_pspec (G_OBJECT (room), props[PROP_ICON]);
}
コード例 #13
0
ファイル: polari-room.c プロジェクト: jwendell/polari
void
polari_room_remove_member (PolariRoom *room,
                           TpContact  *member)
{
  TpChannel *channel;

  g_return_if_fail (POLARI_IS_ROOM (room));

  channel = room->priv->channel;

  if (!tp_proxy_has_interface_by_id (TP_PROXY (channel),
                                     TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP))
    return;

  {
    TpHandle handle = tp_contact_get_handle (member);
    GArray handles = { (char *)&handle, 1 };

    tp_cli_channel_interface_group_call_remove_members (channel,
                                   -1, &handles, NULL, NULL, NULL, NULL, NULL);
  }
}
コード例 #14
0
static void
conn_ready (TpConnection	*conn,
            const GError	*in_error,
	    gpointer		 user_data)
{
	char **argv = (char **) user_data;
	GError *error = NULL;

	g_print (" > conn_ready\n");

	handle_error (in_error);

	/* check if the Requests interface is available */
	if (tp_proxy_has_interface_by_id (conn,
		TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS))
	{
		/* we need to ensure a contact list */
		GHashTable *props = tp_asv_new (
			TP_PROP_CHANNEL_CHANNEL_TYPE,
			G_TYPE_STRING,
			TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,

			TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
			G_TYPE_UINT,
			TP_HANDLE_TYPE_LIST,

			TP_PROP_CHANNEL_TARGET_ID,
			G_TYPE_STRING,
			"subscribe",

			NULL);

		tp_cli_connection_interface_requests_call_ensure_channel (
				conn, -1, props,
				create_contact_list_channel_cb,
				argv, NULL, NULL);
		g_hash_table_destroy (props);
	}
}
コード例 #15
0
/**
 * empathy_individual_manager_supports_blocking
 * @self: the #EmpathyIndividualManager
 * @individual: an individual to check
 *
 * Indicates whether any personas of an @individual can be blocked.
 *
 * Returns: %TRUE if any persona supports contact blocking
 */
gboolean
empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self,
    FolksIndividual *individual)
{
  GeeSet *personas;
  GeeIterator *iter;
  gboolean retval = FALSE;

  g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE);

  personas = folks_individual_get_personas (individual);
  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
  while (!retval && gee_iterator_next (iter))
    {
      TpfPersona *persona = gee_iterator_get (iter);
      TpConnection *conn;

      if (TPF_IS_PERSONA (persona))
        {
          TpContact *tp_contact;

          tp_contact = tpf_persona_get_contact (persona);
          if (tp_contact != NULL)
            {
              conn = tp_contact_get_connection (tp_contact);

              if (tp_proxy_has_interface_by_id (conn,
                    TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
                retval = TRUE;
            }
        }
      g_clear_object (&persona);
    }
  g_clear_object (&iter);

  return retval;
}
コード例 #16
0
static void
tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
				EmpathyContact          *contact)
{
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
	TpHandle self_handle;
	TpHandle handle;
	GArray handles = {(gchar *) &handle, 1};
	EmpathyCapabilities caps;

	/* Keep a weak ref to that contact */
	g_object_weak_ref (G_OBJECT (contact),
			   tp_contact_factory_weak_notify,
			   tp_factory);
	priv->contacts = g_list_prepend (priv->contacts, contact);

	/* The contact keeps a ref to its factory */
	g_object_set_data_full (G_OBJECT (contact), "empathy-factory",
				g_object_ref (tp_factory),
				g_object_unref);

	caps = empathy_contact_get_capabilities (contact);

	/* Set the FT capability */
	if (!priv->contact_caps_supported) {
		/* ContactCapabilities is not supported; assume all contacts can do file
		 * transfer if it's implemented in the CM */
		if (priv->can_request_ft) {
			caps |= EMPATHY_CAPABILITIES_FT;
		}

		/* Set the Stream Tube capability */
		if (priv->can_request_st) {
			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;
		}
	}

	empathy_contact_set_capabilities (contact, caps);

	/* Set is-user property. Note that it could still be the handle is
	 * different from the connection's self handle, in the case the handle
	 * comes from a group interface. */
	self_handle = tp_connection_get_self_handle (priv->connection);
	handle = empathy_contact_get_handle (contact);
	empathy_contact_set_is_user (contact, self_handle == handle);

	/* FIXME: This should be done by TpContact */
	if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS)) {
		tp_cli_connection_interface_avatars_call_get_known_avatar_tokens (
			priv->connection, -1, &handles,
			tp_contact_factory_got_known_avatar_tokens, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	if (priv->contact_caps_supported) {
		tp_cli_connection_interface_contact_capabilities_call_get_contact_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_contact_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}
	else if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES)) {
		tp_cli_connection_interface_capabilities_call_get_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	DEBUG ("Contact added: %s (%d)",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact));
}
コード例 #17
0
ファイル: empathy-tp-chat.c プロジェクト: james-w/empathy
static GObject *
tp_chat_constructor (GType                  type,
		     guint                  n_props,
		     GObjectConstructParam *props)
{
	GObject           *chat;
	EmpathyTpChatPriv *priv;
	TpConnection      *connection;
	TpHandle           handle;

	chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);

	priv = GET_PRIV (chat);

	connection = tp_channel_borrow_connection (priv->channel);
	priv->factory = empathy_tp_contact_factory_dup_singleton (connection);
	g_signal_connect (priv->channel, "invalidated",
			  G_CALLBACK (tp_chat_invalidated_cb),
			  chat);

	if (tp_proxy_has_interface_by_id (priv->channel,
					  TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
		const TpIntSet *members;
		GArray *handles;

		/* Get self contact from the group's self handle */
		handle = tp_channel_group_get_self_handle (priv->channel);
		empathy_tp_contact_factory_get_from_handle (priv->factory,
			handle, tp_chat_got_self_contact_cb,
			NULL, NULL, chat);

		/* Get initial member contacts */
		members = tp_channel_group_get_members (priv->channel);
		handles = tp_intset_to_array (members);
		empathy_tp_contact_factory_get_from_handles (priv->factory,
			handles->len, (TpHandle *) handles->data,
			tp_chat_got_added_contacts_cb, NULL, NULL, chat);

		g_signal_connect (priv->channel, "group-members-changed",
			G_CALLBACK (tp_chat_group_members_changed_cb), chat);
	} else {
		/* Get the self contact from the connection's self handle */
		handle = tp_connection_get_self_handle (connection);
		empathy_tp_contact_factory_get_from_handle (priv->factory,
			handle, tp_chat_got_self_contact_cb,
			NULL, NULL, chat);

		/* Get the remote contact */
		handle = tp_channel_get_handle (priv->channel, NULL);
		empathy_tp_contact_factory_get_from_handle (priv->factory,
			handle, tp_chat_got_remote_contact_cb,
			NULL, NULL, chat);
	}

	if (tp_proxy_has_interface_by_id (priv->channel,
					  TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
		tp_cli_properties_interface_call_list_properties (priv->channel, -1,
								  tp_chat_list_properties_cb,
								  NULL, NULL,
								  G_OBJECT (chat));
		tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
									   tp_chat_properties_changed_cb,
									   NULL, NULL,
									   G_OBJECT (chat), NULL);
		tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
									       tp_chat_property_flags_changed_cb,
									       NULL, NULL,
									       G_OBJECT (chat), NULL);
	}

	return chat;
}
コード例 #18
0
void hev_impathy_server_sasl_handler_provide_password(
			HevImpathyServerSASLHandler *self,
			const gchar *password, gboolean remember)
{
	HevImpathyServerSASLHandlerPrivate * priv = NULL;
	GArray *array = NULL;
	gboolean may_save_response = FALSE,
			 may_save_response_valid = FALSE;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	g_return_if_fail(HEV_IS_IMPATHY_SERVER_SASL_HANDLER(self));

	priv = HEV_IMPATHY_SERVER_SASL_HANDLER_GET_PRIVATE(self);

	array = g_array_sized_new(TRUE, FALSE,
				sizeof(gchar), strlen(password));

	g_array_append_vals(array, password, strlen(password));

	tp_cli_channel_interface_sasl_authentication_call_start_mechanism_with_data(
				priv->channel, -1, "X-TELEPATHY-PASSWORD", array,
				start_mechanism_with_data_handler, NULL, NULL, G_OBJECT(self));

	g_array_unref(array);

	/* determine if we are permitted to save the password locally */
	may_save_response = tp_asv_get_boolean(
				tp_channel_borrow_immutable_properties(priv->channel),
				TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
				&may_save_response_valid);

	if(!may_save_response_valid)
	{
		may_save_response = TRUE;
	}

	if(remember)
	{
		if(may_save_response)
		{
			g_free(priv->password);

			/* We'll save the password if we manage to connect */
			priv->password = g_strdup(password);
			priv->save_password = TRUE;
		}
#if 0 /* TODO */
		else if(tp_proxy_has_interface_by_id(priv->channel,
						EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE))
		{
		}
		else
		{
		}
#endif
	}

	if(!may_save_response)
	{
		/* delete any password present, it shouldn't be there */
		hev_impathy_keyring_delete_account_password_async(priv->account,
					NULL, NULL);
	}

#if 0 /* TODO */
	/* Additionally, if we implement Ch.I.CredentialsStorage, inform that
	 * whether we want to remember the password. */
	if(tp_proxy_has_interface_by_id(priv->channel,
					EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE))
	{
		emp_cli_channel_interface_credentials_storage_call_store_credentials(
					TP_PROXY(priv->channel), -1, remember, NULL, NULL, NULL, NULL);
	}
#endif
}
コード例 #19
0
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);
}
void
empathy_server_sasl_handler_provide_password (
    EmpathyServerSASLHandler *handler,
    const gchar *password,
    gboolean remember)
{
  EmpathyServerSASLHandlerPriv *priv;
  GArray *array;
  gboolean may_save_response, may_save_response_valid;

  g_return_if_fail (EMPATHY_IS_SERVER_SASL_HANDLER (handler));

  priv = handler->priv;

  array = g_array_sized_new (TRUE, FALSE,
      sizeof (gchar), strlen (password));

  g_array_append_vals (array, password, strlen (password));

  DEBUG ("Calling StartMechanismWithData with our password");

  tp_cli_channel_interface_sasl_authentication_call_start_mechanism_with_data (
      priv->channel, -1, "X-TELEPATHY-PASSWORD", array,
      start_mechanism_with_data_cb, NULL, NULL, G_OBJECT (handler));

  g_array_unref (array);

  DEBUG ("%sremembering the password", remember ? "" : "not ");

  /* determine if we are permitted to save the password locally */
  may_save_response = tp_asv_get_boolean (
      tp_channel_borrow_immutable_properties (priv->channel),
      TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
      &may_save_response_valid);

  if (!may_save_response_valid)
    {
      DEBUG ("MaySaveResponse unknown, assuming TRUE");
      may_save_response = TRUE;
    }

  if (remember)
    {
      if (may_save_response)
        {
          g_free (priv->password);

          /* We'll save the password if we manage to connect */
          priv->password = g_strdup (password);
          priv->save_password = TRUE;
        }
      else if (tp_proxy_has_interface_by_id (priv->channel,
            EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE))
        {
          DEBUG ("Channel implements Ch.I.CredentialsStorage");
        }
      else
        {
          DEBUG ("Asked to remember password, but doing so is not permitted");
        }
    }

  if (!may_save_response)
    {
      /* delete any password present, it shouldn't be there */
      empathy_keyring_delete_account_password_async (priv->account, NULL, NULL);
    }

  /* Additionally, if we implement Ch.I.CredentialsStorage, inform that
   * whether we want to remember the password */
  if (tp_proxy_has_interface_by_id (priv->channel,
        EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE))
    {
      emp_cli_channel_interface_credentials_storage_call_store_credentials (
          TP_PROXY (priv->channel), -1, remember, NULL, NULL, NULL, NULL);
    }
}
コード例 #21
0
/*
 * Block contact dialog
 */
gboolean
empathy_block_individual_dialog_show (GtkWindow *parent,
    FolksIndividual *individual,
    GdkPixbuf *avatar,
    gboolean *abusive)
{
  GtkWidget *dialog;
  GtkWidget *abusive_check = NULL;
  GeeSet *personas;
  GeeIterator *iter;
  GString *text = g_string_new ("");
  GString *blocked_str = g_string_new ("");
  GString *notblocked_str = g_string_new ("");
  guint npersonas_blocked = 0, npersonas_notblocked = 0;
  gboolean can_report_abuse = FALSE;
  int res;

  dialog = gtk_message_dialog_new (parent,
      GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
      _("Block %s?"),
      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));

  if (avatar != NULL)
    {
      GtkWidget *image = gtk_image_new_from_pixbuf (avatar);
      gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
      gtk_widget_show (image);
    }

  /* build a list of personas that support blocking */
  personas = folks_individual_get_personas (individual);
  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
  while (gee_iterator_next (iter))
    {
      TpfPersona *persona = gee_iterator_get (iter);
      TpContact *contact;
      GString *s;
      char *str;
      TpConnection *conn;

      if (!TPF_IS_PERSONA (persona))
          goto while_finish;

      contact = tpf_persona_get_contact (persona);
      if (contact == NULL)
        goto while_finish;

      conn = tp_contact_get_connection (contact);

      if (tp_proxy_has_interface_by_id (conn,
            TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
        {
          s = blocked_str;
          npersonas_blocked++;
        }
      else
        {
          s = notblocked_str;
          npersonas_notblocked++;
        }

      if (tp_connection_can_report_abusive (conn))
        can_report_abuse = TRUE;

      str = contact_pretty_name (contact);
      g_string_append_printf (s, "\n " BULLET_POINT " %s", str);
      g_free (str);

while_finish:
      g_clear_object (&persona);
    }
  g_clear_object (&iter);

  g_string_append_printf (text,
      _("Are you sure you want to block '%s' from contacting you again?"),
      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));

  if (npersonas_blocked > 0)
    g_string_append_printf (text, "\n\n%s\n%s",
        ngettext ("The following identity will be blocked:",
                  "The following identities will be blocked:",
                  npersonas_blocked),
        blocked_str->str);

  if (npersonas_notblocked > 0)
    g_string_append_printf (text, "\n\n%s\n%s",
        ngettext ("The following identity can not be blocked:",
                  "The following identities can not be blocked:",
                  npersonas_notblocked),
        notblocked_str->str);

  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
    "%s", text->str);

  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      _("_Block"), GTK_RESPONSE_REJECT,
      NULL);

  if (can_report_abuse)
    {
      GtkWidget *vbox;

      vbox = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
      abusive_check = gtk_check_button_new_with_mnemonic (
          ngettext ("_Report this contact as abusive",
                    "_Report these contacts as abusive",
                    npersonas_blocked));

      gtk_box_pack_start (GTK_BOX (vbox), abusive_check, FALSE, TRUE, 0);
      gtk_widget_show (abusive_check);
    }

  g_string_free (text, TRUE);
  g_string_free (blocked_str, TRUE);
  g_string_free (notblocked_str, TRUE);

  res = gtk_dialog_run (GTK_DIALOG (dialog));

  if (abusive != NULL)
    {
      if (abusive_check != NULL)
        *abusive = gtk_toggle_button_get_active (
            GTK_TOGGLE_BUTTON (abusive_check));
      else
        *abusive = FALSE;
    }

  gtk_widget_destroy (dialog);

  return res == GTK_RESPONSE_REJECT;
}
GList *
_mcd_client_registry_list_possible_handlers (McdClientRegistry *self,
    const gchar *preferred_handler,
    GVariant *request_props,
    TpChannel *channel,
    const gchar *must_have_unique_name)
{
  GList *handlers = NULL;
  GList *handlers_iter;
  GHashTableIter client_iter;
  gpointer client_p;

  _mcd_client_registry_init_hash_iter (self, &client_iter);

  while (g_hash_table_iter_next (&client_iter, NULL, &client_p))
    {
      McdClientProxy *client = MCD_CLIENT_PROXY (client_p);
      gsize quality;

      if (must_have_unique_name != NULL &&
          tp_strdiff (must_have_unique_name,
            _mcd_client_proxy_get_unique_name (client)))
        {
          /* we're trying to redispatch to an existing handler, and this is
           * not it */
          continue;
        }

      if (!tp_proxy_has_interface_by_id (client,
            TP_IFACE_QUARK_CLIENT_HANDLER))
        {
            /* not a handler at all */
            continue;
        }

      if (channel == NULL)
        {
          /* We don't know the channel's properties (the next part will not
           * execute), so we must work out the quality of match from the
           * channel request. We can assume that the request will return one
           * channel, with the requested properties, plus Requested == TRUE.
           */
          g_assert (request_props != NULL);
          quality = _mcd_client_match_filters (request_props,
              _mcd_client_proxy_get_handler_filters (client), TRUE);
        }
      else
        {
          GVariant *properties;

          g_assert (TP_IS_CHANNEL (channel));
          properties = tp_channel_dup_immutable_properties (channel);
          quality = _mcd_client_match_filters (properties,
              _mcd_client_proxy_get_handler_filters (client), FALSE);
          g_variant_unref (properties);
        }

      if (quality > 0)
        {
          PossibleHandler *ph = g_slice_new0 (PossibleHandler);

          ph->client = client;
          ph->bypass = _mcd_client_proxy_get_bypass_approval (client);
          ph->quality = quality;

          handlers = g_list_prepend (handlers, ph);
        }
    }

  /* if no handlers can take them all, fail - unless we're operating on
   * a request that specified a preferred handler, in which case assume
   * it's suitable */
  if (handlers == NULL)
    {
      McdClientProxy *client;

      if (preferred_handler == NULL || preferred_handler[0] == '\0')
        {
          return NULL;
        }

      client = _mcd_client_registry_lookup (self, preferred_handler);

      if (client == NULL)
        {
          return NULL;
        }

      return g_list_append (NULL, client);
    }

  /* We have at least one handler that can take the whole batch. Sort
   * the possible handlers, most preferred first (i.e. sort by ascending
   * quality then reverse) */
  handlers = g_list_sort (handlers, possible_handler_cmp);
  handlers = g_list_reverse (handlers);

  /* convert in-place from a list of PossibleHandler to a list of
   * McdClientProxy */
  for (handlers_iter = handlers;
       handlers_iter != NULL;
       handlers_iter = handlers_iter->next)
    {
      PossibleHandler *ph = handlers_iter->data;

      handlers_iter->data = ph->client;
      g_slice_free (PossibleHandler, ph);
    }

  return handlers;
}