EmpathyChatPriv *priv = GET_PRIV (self);
GError *error = NULL;
- if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
+ if (!tp_channel_provide_password_finish (TP_CHANNEL (tp_chat), res,
&error)) {
DEBUG ("error: %s", error->message);
/* FIXME: what should we do if that's another error? Close the channel?
password = gtk_entry_get_text (GTK_ENTRY (data->entry));
- empathy_tp_chat_provide_password_async (priv->tp_chat, password,
+ tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
provide_password_cb, data);
gtk_widget_set_sensitive (data->button, FALSE);
EmpathyChatPriv *priv = GET_PRIV (self);
GError *error = NULL;
- if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
+ if (!tp_channel_provide_password_finish (TP_CHANNEL (tp_chat), res,
&error)) {
DEBUG ("error: %s", error->message);
/* FIXME: what should we do if that's another error? Close the channel?
return;
}
- empathy_tp_chat_provide_password_async (priv->tp_chat, password,
+ tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
provide_saved_password_cb, self);
}
{
EmpathyChatPriv *priv = GET_PRIV (self);
- if (empathy_tp_chat_password_needed (priv->tp_chat)) {
+ if (tp_channel_password_needed (TP_CHANNEL (priv->tp_chat))) {
empathy_keyring_get_room_password_async (priv->account,
empathy_tp_chat_get_id (priv->tp_chat),
chat_room_got_password_cb, self);
GQueue *pending_messages_queue;
gboolean had_properties_list;
GPtrArray *properties;
- TpChannelPasswordFlags password_flags;
- /* TRUE if we fetched the password flag of the channel or if it's not needed
- * (channel doesn't implement the Password interface) */
- gboolean got_password_flags;
gboolean can_upgrade_to_muc;
GHashTable *messages_being_sent;
PROP_0,
PROP_ACCOUNT,
PROP_REMOTE_CONTACT,
- PROP_PASSWORD_NEEDED,
PROP_N_MESSAGES_SENDING,
};
static void
check_almost_ready (EmpathyTpChat *self)
{
+ TpChannel *channel = (TpChannel *) self;
+
if (self->priv->ready_result == NULL)
return;
if (self->priv->user == NULL)
return;
- if (!self->priv->got_password_flags)
- return;
-
/* We need either the members (room) or the remote contact (private chat).
* If the chat is protected by a password we can't get these information so
* consider the chat as ready so it can be presented to the user. */
- if (!empathy_tp_chat_password_needed (self) && self->priv->members == NULL &&
+ if (!tp_channel_password_needed (channel) && self->priv->members == NULL &&
self->priv->remote_contact == NULL)
return;
check_almost_ready (self);
}
-static void
-password_flags_changed_cb (TpChannel *channel,
- guint added,
- guint removed,
- gpointer user_data,
- GObject *weak_object)
-{
- EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
- gboolean was_needed, needed;
-
- was_needed = empathy_tp_chat_password_needed (self);
-
- self->priv->password_flags |= added;
- self->priv->password_flags ^= removed;
-
- needed = empathy_tp_chat_password_needed (self);
-
- if (was_needed != needed)
- g_object_notify (G_OBJECT (self), "password-needed");
-}
-
-static void
-got_password_flags_cb (TpChannel *proxy,
- guint password_flags,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
-{
- EmpathyTpChat *self = EMPATHY_TP_CHAT (weak_object);
-
- self->priv->got_password_flags = TRUE;
- self->priv->password_flags = password_flags;
-
- check_almost_ready (EMPATHY_TP_CHAT (self));
-}
-
static void
tp_chat_get_property (GObject *object,
guint param_id,
case PROP_REMOTE_CONTACT:
g_value_set_object (value, self->priv->remote_contact);
break;
- case PROP_PASSWORD_NEEDED:
- g_value_set_boolean (value, empathy_tp_chat_password_needed (self));
- break;
case PROP_N_MESSAGES_SENDING:
g_value_set_uint (value,
g_hash_table_size (self->priv->messages_being_sent));
EMPATHY_TYPE_CONTACT,
G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_PASSWORD_NEEDED,
- g_param_spec_boolean ("password-needed",
- "password needed",
- "TRUE if a password is needed to join the channel",
- FALSE,
- G_PARAM_READABLE));
-
g_object_class_install_property (object_class,
PROP_N_MESSAGES_SENDING,
g_param_spec_uint ("n-messages-sending",
(GSList *) empathy_tp_chat_get_pending_messages (self));
}
-gboolean
-empathy_tp_chat_password_needed (EmpathyTpChat *self)
-{
- return self->priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE;
-}
-
-static void
-provide_password_cb (TpChannel *channel,
- gboolean correct,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
-{
- GSimpleAsyncResult *result = user_data;
-
- if (error != NULL) {
- g_simple_async_result_set_from_error (result, error);
- }
- else if (!correct) {
- /* The current D-Bus API is a bit weird so re-use the
- * AuthenticationFailed error */
- g_simple_async_result_set_error (result, TP_ERRORS,
- TP_ERROR_AUTHENTICATION_FAILED, "Wrong password");
- }
-
- g_simple_async_result_complete (result);
- g_object_unref (result);
-}
-
-void
-empathy_tp_chat_provide_password_async (EmpathyTpChat *self,
- const gchar *password,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *result;
-
- result = g_simple_async_result_new (G_OBJECT (self),
- callback, user_data,
- empathy_tp_chat_provide_password_finish);
-
- tp_cli_channel_interface_password_call_provide_password
- ((TpChannel *) self, -1, password, provide_password_cb, result,
- NULL, G_OBJECT (self));
-}
-
-gboolean
-empathy_tp_chat_provide_password_finish (EmpathyTpChat *self,
- GAsyncResult *result,
- GError **error)
-{
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
- error))
- return FALSE;
-
- g_return_val_if_fail (g_simple_async_result_is_valid (result,
- G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE);
-
- return TRUE;
-}
-
/**
* empathy_tp_chat_can_add_contact:
*
NULL, NULL,
G_OBJECT (self), NULL);
}
-
- /* Check if the chat is password protected */
- if (tp_proxy_has_interface_by_id (self,
- TP_IFACE_QUARK_CHANNEL_INTERFACE_PASSWORD)) {
- self->priv->got_password_flags = FALSE;
-
- tp_cli_channel_interface_password_connect_to_password_flags_changed
- (channel, password_flags_changed_cb, self, NULL,
- G_OBJECT (self), NULL);
-
- tp_cli_channel_interface_password_call_get_password_flags
- (channel, -1, got_password_flags_cb, self, NULL, G_OBJECT (self));
- } else {
- /* No Password interface, so no need to fetch the password flags */
- self->priv->got_password_flags = TRUE;
- }
}
static void