#include <telepathy-glib/account-manager.h>
#include <telepathy-glib/util.h>
#include <telepathy-logger/log-manager.h>
+#include <telepathy-logger/text-event.h>
#include <libempathy/empathy-contact-list.h>
#include <libempathy/empathy-gsettings.h>
+#include <libempathy/empathy-keyring.h>
#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-dispatcher.h>
-#include <libempathy/empathy-marshal.h>
+#include <libempathy/empathy-request-util.h>
+#include <libempathy/empathy-chatroom-manager.h>
#include "empathy-chat.h"
#include "empathy-spell.h"
+#include "empathy-contact-dialogs.h"
#include "empathy-contact-list-store.h"
#include "empathy-contact-list-view.h"
#include "empathy-contact-menu.h"
#include "empathy-input-text-view.h"
#include "empathy-search-bar.h"
#include "empathy-theme-manager.h"
+#include "empathy-theme-adium.h"
#include "empathy-smiley-manager.h"
#include "empathy-ui-utils.h"
#include "empathy-string-parser.h"
guint update_misspelled_words_id;
/* Source func ID for save_paned_pos_timeout () */
guint save_paned_pos_id;
+ /* Source func ID for chat_contacts_visible_timeout_cb () */
+ guint contacts_visible_id;
GtkWidget *widget;
GtkWidget *hpaned;
GtkWidget *search_bar;
guint unread_messages;
+ guint unread_messages_when_offline;
/* TRUE if the pending messages can be displayed. This is to avoid to show
* pending messages *before* messages from logs. (#603980) */
gboolean can_show_pending;
* notified again about the already notified pending messages when the
* messages in tab will be properly shown */
gboolean retrieving_backlogs;
+ gboolean sms_channel;
+
+ /* we need to know whether populate-popup happened in response to
+ * the keyboard or the mouse. We can't ask GTK for the most recent
+ * event, because it will be a notify event. Instead we track it here */
+ GdkEventType most_recent_event_type;
};
typedef struct {
enum {
COMPOSING,
NEW_MESSAGE,
+ PART_COMMAND_ENTERED,
LAST_SIGNAL
};
PROP_SUBJECT,
PROP_REMOTE_CONTACT,
PROP_SHOW_CONTACTS,
+ PROP_SMS_CHANNEL,
+ PROP_N_MESSAGES_SENDING,
+ PROP_NB_UNREAD_MESSAGES,
};
static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
+G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BOX);
static gboolean update_misspelled_words (gpointer data);
g_value_set_object (value, priv->account);
break;
case PROP_NAME:
- g_value_set_string (value, empathy_chat_get_name (chat));
+ g_value_take_string (value, empathy_chat_dup_name (chat));
break;
case PROP_ID:
g_value_set_string (value, priv->id);
case PROP_SHOW_CONTACTS:
g_value_set_boolean (value, priv->show_contacts);
break;
+ case PROP_SMS_CHANNEL:
+ g_value_set_boolean (value, priv->sms_channel);
+ break;
+ case PROP_N_MESSAGES_SENDING:
+ g_value_set_uint (value,
+ empathy_chat_get_n_messages_sending (chat));
+ break;
+ case PROP_NB_UNREAD_MESSAGES:
+ g_value_set_uint (value,
+ empathy_chat_get_nb_unread_messages (chat));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
* https://bugs.freedesktop.org/show_bug.cgi?id=13422 */
switch (priv->handle_type) {
case TP_HANDLE_TYPE_CONTACT:
- empathy_dispatcher_chat_with_contact_id (
- account, priv->id, TP_USER_ACTION_TIME_NOT_USER_ACTION);
+ if (priv->sms_channel)
+ empathy_sms_contact_id (
+ account, priv->id,
+ TP_USER_ACTION_TIME_NOT_USER_ACTION);
+ else
+ empathy_chat_with_contact_id (
+ account, priv->id,
+ TP_USER_ACTION_TIME_NOT_USER_ACTION);
break;
case TP_HANDLE_TYPE_ROOM:
- empathy_dispatcher_join_muc (account, priv->id,
+ empathy_join_muc (account, priv->id,
TP_USER_ACTION_TIME_NOT_USER_ACTION);
break;
case TP_HANDLE_TYPE_NONE:
EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- TpConnection *connection;
if (new_status != TP_CONNECTION_STATUS_CONNECTED)
return;
- connection = tp_account_get_connection (account);
-
if (priv->tp_chat != NULL || account != priv->account ||
priv->handle_type == TP_HANDLE_TYPE_NONE ||
EMP_STR_EMPTY (priv->id))
}
}
+static void
+set_chate_state_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error = NULL;
+
+ if (!tp_text_channel_set_chat_state_finish (TP_TEXT_CHANNEL (source), result,
+ &error)) {
+ DEBUG ("Failed to set chat state: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+set_chat_state (EmpathyChat *self,
+ TpChannelChatState state)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ if (!tp_proxy_has_interface_by_id (priv->tp_chat,
+ TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE))
+ return;
+
+ tp_text_channel_set_chat_state_async (TP_TEXT_CHANNEL (priv->tp_chat), state,
+ set_chate_state_cb, self);
+}
+
static gboolean
chat_composing_stop_timeout_cb (EmpathyChat *chat)
{
priv = GET_PRIV (chat);
priv->composing_stop_timeout_id = 0;
- empathy_tp_chat_set_state (priv->tp_chat,
- TP_CHANNEL_CHAT_STATE_PAUSED);
+ set_chat_state (chat, TP_CHANNEL_CHAT_STATE_PAUSED);
return FALSE;
}
/* Just restart the timeout */
chat_composing_remove_timeout (chat);
} else {
- empathy_tp_chat_set_state (priv->tp_chat,
- TP_CHANNEL_CHAT_STATE_COMPOSING);
+ set_chat_state (chat, TP_CHANNEL_CHAT_STATE_COMPOSING);
}
priv->composing_stop_timeout_id = g_timeout_add_seconds (
static void
chat_composing_stop (EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
-
- priv = GET_PRIV (chat);
-
chat_composing_remove_timeout (chat);
- empathy_tp_chat_set_state (priv->tp_chat,
- TP_CHANNEL_CHAT_STATE_ACTIVE);
+ set_chat_state (chat, TP_CHANNEL_CHAT_STATE_ACTIVE);
}
static gint
gchar *message;
} ChatCommandMsgData;
-#if 0
static void
-chat_command_msg_cb (EmpathyDispatchOperation *dispatch,
- const GError *error,
+chat_command_msg_cb (GObject *source,
+ GAsyncResult *result,
gpointer user_data)
{
ChatCommandMsgData *data = user_data;
+ GError *error = NULL;
+ TpChannel *channel;
+
+ channel = tp_account_channel_request_ensure_and_observe_channel_finish (
+ TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error);
+
+ if (channel == NULL) {
+ DEBUG ("Failed to get channel: %s", error->message);
+ g_error_free (error);
- if (error != NULL) {
empathy_chat_view_append_event (data->chat->view,
_("Failed to open private chat"));
goto OUT;
}
- if (!EMP_STR_EMPTY (data->message)) {
- EmpathyTpChat *tpchat;
- EmpathyMessage *message;
+ if (!EMP_STR_EMPTY (data->message) && TP_IS_TEXT_CHANNEL (channel)) {
+ TpTextChannel *text = (TpTextChannel *) channel;
+ TpMessage *msg;
- tpchat = EMPATHY_TP_CHAT (
- empathy_dispatch_operation_get_channel_wrapper (dispatch));
+ msg = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ data->message);
- message = empathy_message_new (data->message);
- empathy_tp_chat_send (tpchat, message);
- g_object_unref (message);
+ tp_text_channel_send_message_async (text, msg, 0, NULL, NULL);
+
+ g_object_unref (msg);
}
+ g_object_unref (channel);
+
OUT:
g_free (data->message);
g_slice_free (ChatCommandMsgData, data);
}
-#endif
static gboolean
nick_command_supported (EmpathyChat *chat)
EmpathyChatPriv * priv = GET_PRIV (chat);
TpConnection *connection;
- connection = empathy_tp_chat_get_connection (priv->tp_chat);
+ connection = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
return tp_proxy_has_interface_by_id (connection,
EMP_IFACE_QUARK_CONNECTION_INTERFACE_RENAMING);
}
+static gboolean
+part_command_supported (EmpathyChat *chat)
+{
+ EmpathyChatPriv * priv = GET_PRIV (chat);
+
+ return tp_proxy_has_interface_by_id (priv->tp_chat,
+ TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);
+}
+
static void
chat_command_clear (EmpathyChat *chat,
GStrv strv)
g_value_unset (&value);
}
+void
+empathy_chat_join_muc (EmpathyChat *chat,
+ const gchar *room)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ empathy_join_muc (priv->account, room,
+ empathy_get_current_action_time ());
+}
+
static void
chat_command_join (EmpathyChat *chat,
GStrv strv)
{
guint i = 0;
- EmpathyChatPriv *priv = GET_PRIV (chat);
GStrv rooms = g_strsplit_set (strv[1], ", ", -1);
while (rooms[i] != NULL) {
/* ignore empty strings */
if (!EMP_STR_EMPTY (rooms[i])) {
- TpConnection *connection;
-
- connection = empathy_tp_chat_get_connection (priv->tp_chat);
- empathy_dispatcher_join_muc (priv->account, rooms[i],
- gtk_get_current_event_time ());
+ empathy_chat_join_muc (chat, rooms[i]);
}
i++;
}
g_strfreev (rooms);
}
-#if 0
+static void
+chat_command_part (EmpathyChat *chat,
+ GStrv strv)
+{
+ g_signal_emit (chat, signals[PART_COMMAND_ENTERED], 0, strv);
+}
+
static void
chat_command_msg_internal (EmpathyChat *chat,
const gchar *contact_id,
const gchar *message)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- TpConnection *connection;
ChatCommandMsgData *data;
+ TpAccountChannelRequest *req;
+ GHashTable *request;
+
+ request = tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
+ TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id,
+ NULL);
+
+ req = tp_account_channel_request_new (priv->account, request,
+ empathy_get_current_action_time ());
/* FIXME: We should probably search in members alias. But this
* is enough for IRC */
data = g_slice_new (ChatCommandMsgData);
data->chat = chat;
data->message = g_strdup (message);
- connection = empathy_tp_chat_get_connection (priv->tp_chat);
- empathy_dispatcher_chat_with_contact_id (connection, contact_id,
- gtk_get_current_event_time (),
- chat_command_msg_cb,
- data);
+
+ tp_account_channel_request_ensure_and_observe_channel_async (req,
+ EMPATHY_CHAT_BUS_NAME, NULL, chat_command_msg_cb, data);
+
+ g_object_unref (req);
+ g_hash_table_unref (request);
}
static void
{
chat_command_msg_internal (chat, strv[1], strv[2]);
}
-#endif
static void
-callback_for_request_rename(TpProxy *proxy,
+callback_for_request_rename (TpProxy *proxy,
const GError *error,
gpointer user_data,
GObject *weak_object)
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyMessage *message;
+ TpMessage *message;
+ TpTextChannel *channel;
+
+ channel = (TpTextChannel *) (priv->tp_chat);
+
+ if (!tp_text_channel_supports_message_type (channel,
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION)) {
+ /* Action message are not supported, 'simulate' the action */
+ EmpathyContact *self_contact;
+ gchar *tmp;
+
+ self_contact = empathy_tp_chat_get_self_contact (priv->tp_chat);
+ /* The TpChat can't be ready if it doesn't have the self contact */
+ g_assert (self_contact != NULL);
+
+ tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact),
+ strv[1]);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ tmp);
+ g_free (tmp);
+ }
+ else {
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+ strv[1]);
+ }
- message = empathy_message_new (strv[1]);
- empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyMessage *message;
+ TpMessage *message;
+
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ strv[1]);
+ empathy_tp_chat_send (priv->tp_chat, message);
+ g_object_unref (message);
+}
+
+static void
+whois_got_contact_cb (TpConnection *connection,
+ guint n_contacts,
+ TpContact * const *contacts,
+ const gchar * const *requested_ids,
+ GHashTable *failed_id_errors,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ EmpathyChat *chat = EMPATHY_CHAT (weak_object);
+
+ g_return_if_fail (n_contacts <= 1);
+
+ if (n_contacts == 0) {
+ GHashTableIter iter;
+ gpointer key = NULL, value = NULL;
+ gchar *id;
+ GError *id_error;
+
+ /* tp-glib guarantees that the contacts you requested will be
+ * in failed_id_errors regardless of whether the individual
+ * contact was invalid or the whole operation failed.
+ */
+ g_hash_table_iter_init (&iter, failed_id_errors);
+ g_hash_table_iter_next (&iter, &key, &value);
+ id = key;
+ id_error = value;
+
+ DEBUG ("Error getting TpContact for '%s': %s %u %s",
+ id, g_quark_to_string (id_error->domain),
+ id_error->code, id_error->message);
+
+ if (error == NULL) {
+ /* The specific ID failed. */
+ gchar *event = g_strdup_printf (
+ _("“%s” is not a valid contact ID"), id);
+ empathy_chat_view_append_event (chat->view, event);
+ g_free (event);
+ }
+ /* Otherwise we're disconnected or something; so the window
+ * will already say ‘Disconnected’, so let's not show anything.
+ */
+ } else {
+ EmpathyContact *empathy_contact;
+ GtkWidget *window;
+
+ g_return_if_fail (contacts[0] != NULL);
+ empathy_contact = empathy_contact_dup_from_tp_contact (
+ contacts[0]);
+
+ window = gtk_widget_get_toplevel (GTK_WIDGET (chat));
+ /* If we're alive and this command is running, we'd better be
+ * in a window. */
+ g_return_if_fail (window != NULL);
+ g_return_if_fail (gtk_widget_is_toplevel (window));
+ empathy_contact_information_dialog_show (empathy_contact,
+ GTK_WINDOW (window));
+ g_object_unref (empathy_contact);
+ }
+}
+
+static void
+chat_command_whois (EmpathyChat *chat,
+ GStrv strv)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ TpConnection *conn;
+
+ conn = tp_channel_borrow_connection ((TpChannel *) priv->tp_chat);
+ tp_connection_get_contacts_by_id (conn,
+ /* Element 0 of 'strv' is "whois"; element 1 is the contact ID
+ * entered by the user (including spaces, if any). */
+ 1, (const gchar * const *) strv + 1,
+ 0, NULL,
+ whois_got_contact_cb, NULL, NULL, G_OBJECT (chat));
+}
+
+static void
+chat_command_whale (EmpathyChat *chat,
+ GStrv strv)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ TpMessage *message;
+
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ "\n\n\n"
+ "•_______________•");
+ empathy_tp_chat_send (priv->tp_chat, message);
+ g_object_unref (message);
+}
- message = empathy_message_new (strv[1]);
+static void
+chat_command_babywhale (EmpathyChat *chat,
+ GStrv strv)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ TpMessage *message;
+
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ "\n"
+ "•_____•");
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
+static void
+chat_command_inspector (EmpathyChat *chat,
+ GStrv strv)
+{
+ if (EMPATHY_IS_THEME_ADIUM (chat->view)) {
+ empathy_theme_adium_show_inspector (
+ EMPATHY_THEME_ADIUM (chat->view));
+ }
+}
+
static void chat_command_help (EmpathyChat *chat, GStrv strv);
typedef void (*ChatCommandFunc) (EmpathyChat *chat, GStrv strv);
{"j", 2, 2, chat_command_join, NULL,
N_("/j <chat room ID>: join a new chat room")},
-#if 0
-/* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=623682 */
+ /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=643295 */
+ {"part", 1, 3, chat_command_part, part_command_supported,
+ N_("/part [<chat room ID>] [<reason>]: leave the chat room, "
+ "by default the current one")},
+
{"query", 2, 3, chat_command_query, NULL,
N_("/query <contact ID> [<message>]: open a private chat")},
{"msg", 3, 3, chat_command_msg, NULL,
N_("/msg <contact ID> <message>: open a private chat")},
-#endif
{"nick", 2, 2, chat_command_nick, nick_command_supported,
N_("/nick <nickname>: change your nickname on the current server")},
"This is used to send a message starting with a '/'. For example: "
"\"/say /join is used to join a new chat room\"")},
+ {"whois", 2, 2, chat_command_whois, NULL,
+ N_("/whois <contact ID>: display information about a contact")},
+
{"help", 1, 2, chat_command_help, NULL,
N_("/help [<command>]: show all supported commands. "
"If <command> is defined, show its usage.")},
+
+ {"inspector", 1, 1, chat_command_inspector, NULL, NULL},
+
+ {"whale", 1, 1, chat_command_whale, NULL, NULL},
+ {"babywhale", 1, 1, chat_command_babywhale, NULL, NULL},
};
static void
{
gchar *str;
+ if (item->help == NULL) {
+ return;
+ }
+
str = g_strdup_printf (_("Usage: %s"), _(item->help));
empathy_chat_view_append_event (chat->view, str);
g_free (str);
chat_command_help (EmpathyChat *chat,
GStrv strv)
{
- EmpathyChatPriv *priv;
guint i;
- priv = GET_PRIV (chat);
-
/* If <command> part is not defined,
* strv[1] will be the terminal NULL */
if (strv[1] == NULL) {
continue;
}
}
- empathy_chat_view_append_event (chat->view,
- _(commands[i].help));
+ if (commands[i].help == NULL) {
+ continue;
+ }
+ empathy_chat_view_append_event (chat->view,
+ _(commands[i].help));
}
return;
}
break;
}
}
+ if (commands[i].help == NULL) {
+ break;
+ }
chat_command_show_help (chat, &commands[i]);
return;
}
const gchar *msg)
{
EmpathyChatPriv *priv;
- EmpathyMessage *message;
+ TpMessage *message;
guint i;
if (EMP_STR_EMPTY (msg)) {
}
}
- message = empathy_message_new (msg);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ msg);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
static void
chat_input_text_view_send (EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
GtkTextBuffer *buffer;
GtkTextIter start, end;
gchar *msg;
- priv = GET_PRIV (chat);
-
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
gtk_text_buffer_get_bounds (buffer, &start, &end);
sender = empathy_message_get_sender (message);
- DEBUG ("Appending new message from %s (%d)",
- empathy_contact_get_alias (sender),
- empathy_contact_get_handle (sender));
+ if (empathy_message_is_edit (message)) {
+ DEBUG ("Editing message '%s' to '%s'",
+ empathy_message_get_supersedes (message),
+ empathy_message_get_body (message));
- empathy_chat_view_append_message (chat->view, message);
+ empathy_chat_view_edit_message (chat->view, message);
+ } else {
+ DEBUG ("Appending new message '%s' from %s (%d)",
+ empathy_message_get_token (message),
+ empathy_contact_get_alias (sender),
+ empathy_contact_get_handle (sender));
+
+ empathy_chat_view_append_message (chat->view, message);
- /* We received a message so the contact is no longer composing */
+ if (empathy_message_is_incoming (message)) {
+ priv->unread_messages++;
+ g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+ }
+
+ g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, pending);
+ }
+
+ /* We received a message so the contact is no longer
+ * composing */
chat_state_changed_cb (priv->tp_chat, sender,
TP_CHANNEL_CHAT_STATE_ACTIVE,
chat);
-
- priv->unread_messages++;
- g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, pending);
}
static void
chat_message_received (chat, message, FALSE);
}
+static void
+chat_message_acknowledged_cb (EmpathyTpChat *tp_chat,
+ EmpathyMessage *message,
+ EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ empathy_chat_view_message_acknowledged (chat->view,
+ message);
+
+ if (!empathy_message_is_edit (message)) {
+ priv->unread_messages--;
+ g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+ }
+}
+
+static void
+append_balance_error (EmpathyChat *chat,
+ const gchar *message_body)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ TpConnection *conn = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
+ const gchar *uri = tp_connection_get_balance_uri (conn);
+ const gchar *error = _("insufficient balance to send message");
+ gchar *str, *str_markup = NULL;
+
+ if (message_body != NULL) {
+ str = g_strdup_printf (_("Error sending message '%s': %s"), message_body, error);
+ } else {
+ str = g_strdup_printf (_("Error sending message: %s"), error);
+ }
+
+ if (!tp_str_empty (uri)) {
+ /* translators: error used when user doesn't have enough credit on his
+ * account to send the message. */
+ gchar *markup_error = g_strdup_printf (_("insufficient balance to send message."
+ " <a href='%s'>Top up</a>."), uri);
+
+ if (message_body != NULL) {
+ gchar *escaped_body = g_markup_escape_text (message_body, -1);
+
+ str_markup = g_strdup_printf (_("Error sending message '%s': %s"),
+ escaped_body, markup_error);
+
+ g_free (escaped_body);
+ } else {
+ str_markup = g_strdup_printf (_("Error sending message: %s"), markup_error);
+ }
+
+ g_free (markup_error);
+ }
+
+ if (str_markup != NULL)
+ empathy_chat_view_append_event_markup (chat->view, str_markup, str);
+ else
+ empathy_chat_view_append_event (chat->view, str);
+
+ g_free (str);
+ g_free (str_markup);
+}
+
static void
chat_send_error_cb (EmpathyTpChat *tp_chat,
const gchar *message_body,
TpChannelTextSendError error_code,
+ const gchar *dbus_error,
EmpathyChat *chat)
{
- const gchar *error;
+ const gchar *error = NULL;
gchar *str;
- switch (error_code) {
- case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
- error = _("offline");
- break;
- case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
- error = _("invalid contact");
- break;
- case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
- error = _("permission denied");
- break;
- case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
- error = _("too long message");
- break;
- case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
- error = _("not implemented");
- break;
- case TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN:
- default:
- error = _("unknown");
- break;
+ if (!tp_strdiff (dbus_error, TP_ERROR_STR_INSUFFICIENT_BALANCE)) {
+ append_balance_error (chat, message_body);
+ return;
+ } else if (!tp_strdiff (dbus_error, TP_ERROR_STR_NOT_CAPABLE)) {
+ error = _("not capable");
+ }
+
+ if (error == NULL) {
+ /* if we didn't find a dbus-error, try the old error */
+ switch (error_code) {
+ case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
+ error = _("offline");
+ break;
+ case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
+ error = _("invalid contact");
+ break;
+ case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
+ error = _("permission denied");
+ break;
+ case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
+ error = _("too long message");
+ break;
+ case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
+ error = _("not implemented");
+ break;
+ case TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN:
+ default:
+ error = _("unknown");
+ break;
+ }
+ }
+
+ if (message_body != NULL) {
+ str = g_strdup_printf (_("Error sending message '%s': %s"),
+ message_body, error);
+ }
+ else {
+ str = g_strdup_printf (_("Error sending message: %s"), error);
}
- str = g_strdup_printf (_("Error sending message '%s': %s"),
- message_body,
- error);
empathy_chat_view_append_event (chat->view, str);
g_free (str);
}
priv = GET_PRIV (chat);
+ priv->most_recent_event_type = event->type;
+
/* Catch ctrl+up/down so we can traverse messages we sent */
if ((event->state & GDK_CONTROL_MASK) &&
(event->keyval == GDK_KEY_Up ||
}
}
+static void
+chat_input_has_focus_notify_cb (GtkWidget *widget,
+ GParamSpec *pspec,
+ EmpathyChat *chat)
+{
+ empathy_chat_view_focus_toggled (chat->view, gtk_widget_has_focus (widget));
+}
+
static void
chat_insert_smiley_activate_cb (EmpathySmileyManager *manager,
EmpathySmiley *smiley,
chat_input_text_view_send (chat);
}
+static gboolean
+chat_input_button_press_event_cb (GtkTextView *view,
+ GdkEventButton *event,
+ EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ priv->most_recent_event_type = event->type;
+
+ return FALSE;
+}
+
static void
chat_input_populate_popup_cb (GtkTextView *view,
GtkMenu *menu,
EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
+ EmpathyChatPriv *priv = GET_PRIV (chat);
GtkTextBuffer *buffer;
GtkTextTagTable *table;
GtkTextTag *tag;
GtkWidget *smiley_menu;
GtkWidget *image;
- priv = GET_PRIV (chat);
buffer = gtk_text_view_get_buffer (view);
/* Add the emoticon menu. */
/* Add the spell check menu item. */
table = gtk_text_buffer_get_tag_table (buffer);
tag = gtk_text_tag_table_lookup (table, "misspelled");
- gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
- GTK_TEXT_WINDOW_WIDGET,
- x, y,
- &x, &y);
- gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
+
+ switch (priv->most_recent_event_type) {
+ case GDK_BUTTON_PRESS:
+ /* get the location from the pointer */
+ gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+ gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
+ GTK_TEXT_WINDOW_WIDGET,
+ x, y,
+ &x, &y);
+ gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view),
+ &iter, x, y);
+ break;
+
+ default:
+ g_warn_if_reached ();
+ /* assume the KEY_PRESS case */
+
+ case GDK_KEY_PRESS:
+ /* get the location from the cursor */
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter,
+ gtk_text_buffer_get_insert (buffer));
+ break;
+
+ }
+
start = end = iter;
if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
static gboolean
-chat_log_filter (TplEntry *log,
+chat_log_filter (TplEvent *event,
gpointer user_data)
{
EmpathyChat *chat = user_data;
EmpathyChatPriv *priv = GET_PRIV (chat);
const GList *pending;
- g_return_val_if_fail (TPL_IS_ENTRY (log), FALSE);
+ g_return_val_if_fail (TPL_IS_EVENT (event), FALSE);
g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
- message = empathy_message_from_tpl_log_entry (log);
+ message = empathy_message_from_tpl_log_event (event);
for (; pending; pending = g_list_next (pending)) {
if (empathy_message_equal (message, pending->data)) {
EmpathyChatPriv *priv = GET_PRIV (chat);
GError *error = NULL;
- if (!tpl_log_manager_get_filtered_messages_finish (TPL_LOG_MANAGER (manager),
+ if (!tpl_log_manager_get_filtered_events_finish (TPL_LOG_MANAGER (manager),
result, &messages, &error)) {
DEBUG ("%s. Aborting.", error->message);
empathy_chat_view_append_event (chat->view,
for (l = messages; l; l = g_list_next (l)) {
EmpathyMessage *message;
- g_assert (TPL_IS_ENTRY (l->data));
- message = empathy_message_from_tpl_log_entry (l->data);
+ g_assert (TPL_IS_EVENT (l->data));
+
+ message = empathy_message_from_tpl_log_event (l->data);
g_object_unref (l->data);
- empathy_chat_view_append_message (chat->view, message);
+ if (empathy_message_is_edit (message)) {
+ /* this is an edited message, create a synthetic event
+ * using the supersedes token and
+ * original-message-sent timestamp, that we can then
+ * replace */
+ EmpathyMessage *syn_msg = g_object_new (
+ EMPATHY_TYPE_MESSAGE,
+ "body", "",
+ "token", empathy_message_get_supersedes (message),
+ "type", empathy_message_get_tptype (message),
+ "timestamp", empathy_message_get_original_timestamp (message),
+ "incoming", empathy_message_is_incoming (message),
+ "is-backlog", TRUE,
+ "receiver", empathy_message_get_receiver (message),
+ "sender", empathy_message_get_sender (message),
+ NULL);
+
+ empathy_chat_view_append_message (chat->view, syn_msg);
+ empathy_chat_view_edit_message (chat->view, message);
+
+ g_object_unref (syn_msg);
+ } else {
+ /* append the latest message */
+ empathy_chat_view_append_message (chat->view, message);
+ }
+
g_object_unref (message);
}
g_list_free (messages);
chat_add_logs (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- gboolean is_chatroom;
+ TplEntity *target;
if (!priv->id) {
return;
empathy_chat_view_scroll (chat->view, FALSE);
/* Add messages from last conversation */
- is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
+ if (priv->handle_type == TP_HANDLE_TYPE_ROOM)
+ target = tpl_entity_new_from_room_id (priv->id);
+ else
+ target = tpl_entity_new (priv->id, TPL_ENTITY_CONTACT, NULL, NULL);
priv->retrieving_backlogs = TRUE;
- tpl_log_manager_get_filtered_messages_async (priv->log_manager,
- priv->account,
- priv->id,
- is_chatroom,
- 5,
- chat_log_filter,
- chat,
- got_filtered_messages_cb,
- (gpointer) chat);
+ tpl_log_manager_get_filtered_events_async (priv->log_manager,
+ priv->account,
+ target,
+ TPL_EVENT_MASK_TEXT,
+ 5,
+ chat_log_filter,
+ chat,
+ got_filtered_messages_cb,
+ (gpointer) chat);
+
+ g_object_unref (target);
}
static gint
}
static gboolean
-chat_reset_size_request (gpointer widget)
+chat_contacts_visible_timeout_cb (gpointer chat)
{
- gtk_widget_set_size_request (widget, -1, -1);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ /* Relax the size request */
+ gtk_widget_set_size_request (priv->vbox_left, -1, -1);
+
+ /* Set the position of the slider. This must be done here because
+ * GtkPaned need to know its size allocation and it will be settled only
+ * after the gtk_window_resize () tough effect. */
+ if (priv->contacts_width > 0) {
+ gtk_paned_set_position (GTK_PANED (priv->hpaned),
+ priv->contacts_width);
+ }
+
+ priv->contacts_visible_id = 0;
return FALSE;
}
gboolean show)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- GtkAllocation allocation;
if (!priv->scrolled_window_contacts) {
return;
if (show && priv->contact_list_view == NULL) {
EmpathyContactListStore *store;
gint min_width;
+ GtkAllocation allocation;
/* We are adding the contact list to the chat, we don't want the
* chat view to become too small. If the chat view is already
gtk_widget_get_allocation (priv->vbox_left, &allocation);
min_width = MIN (allocation.width, 250);
gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
- g_idle_add (chat_reset_size_request, priv->vbox_left);
- if (priv->contacts_width > 0) {
- gtk_paned_set_position (GTK_PANED (priv->hpaned),
- priv->contacts_width);
- }
+ /* There is no way to know when the window resize will happen
+ * since it is WM's decision. Let's hope it won't be longer. */
+ if (priv->contacts_visible_id != 0)
+ g_source_remove (priv->contacts_visible_id);
+ priv->contacts_visible_id = g_timeout_add (500,
+ chat_contacts_visible_timeout_cb, chat);
store = empathy_contact_list_store_new (
EMPATHY_CONTACT_LIST (priv->tp_chat));
priv->handle_type = TP_HANDLE_TYPE_CONTACT;
}
else if (priv->tp_chat != NULL) {
- TpChannel *channel;
-
- channel = empathy_tp_chat_get_channel (priv->tp_chat);
- g_object_get (channel, "handle-type", &priv->handle_type, NULL);
+ tp_channel_get_handle ((TpChannel *) priv->tp_chat, &priv->handle_type);
}
chat_update_contacts_visibility (chat, priv->show_contacts);
}
static void
-chat_destroy_cb (EmpathyTpChat *tp_chat,
+chat_invalidated_cb (EmpathyTpChat *tp_chat,
+ guint domain,
+ gint code,
+ gchar *message,
EmpathyChat *chat)
{
EmpathyChatPriv *priv;
gtk_widget_set_sensitive (chat->input_text_view, FALSE);
chat_update_contacts_visibility (chat, FALSE);
+
+ priv->unread_messages_when_offline = priv->unread_messages;
}
static gboolean
GList *list = NULL;
gchar *filename;
GtkTextBuffer *buffer;
- gint paned_pos;
+ EmpathyThemeManager *theme_mgr;
filename = empathy_file_lookup ("empathy-chat.ui",
"libempathy-gtk");
g_free (filename);
/* Add message view. */
- chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
+ theme_mgr = empathy_theme_manager_dup_singleton ();
+ chat->view = empathy_theme_manager_create_view (theme_mgr);
+ g_object_unref (theme_mgr);
/* If this is a GtkTextView, it's set as a drag destination for text/plain
and other types, even though it's non-editable and doesn't accept any
drags. This steals drag motion for anything inside the scrollbars,
/* Add input GtkTextView */
chat->input_text_view = empathy_input_text_view_new ();
-
+ g_signal_connect (chat->input_text_view, "notify::has-focus",
+ G_CALLBACK (chat_input_has_focus_notify_cb),
+ chat);
g_signal_connect (chat->input_text_view, "key-press-event",
G_CALLBACK (chat_input_key_press_event_cb),
chat);
g_signal_connect (chat->input_text_view, "realize",
G_CALLBACK (chat_input_realize_cb),
chat);
+ g_signal_connect (chat->input_text_view, "button-press-event",
+ G_CALLBACK (chat_input_button_press_event_cb),
+ chat);
g_signal_connect (chat->input_text_view, "populate-popup",
G_CALLBACK (chat_input_populate_popup_cb),
chat);
G_CALLBACK (chat_hpaned_pos_changed_cb),
chat);
- /* Load the paned position */
- paned_pos = g_settings_get_int (priv->gsettings_ui,
- EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
- if (paned_pos != 0)
- gtk_paned_set_position (GTK_PANED(priv->hpaned), paned_pos);
-
/* Set widget focus order */
list = g_list_append (NULL, priv->search_bar);
list = g_list_append (list, priv->scrolled_window_input);
g_list_free (list);
/* Add the main widget in the chat widget */
- gtk_container_add (GTK_CONTAINER (chat), priv->widget);
+ gtk_box_pack_start (GTK_BOX (chat), priv->widget, TRUE, TRUE, 0);
g_object_unref (gui);
}
-static void
-chat_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkBin *bin = GTK_BIN (widget);
- GtkAllocation child_allocation;
- GtkWidget *child;
-
- gtk_widget_set_allocation (widget, allocation);
-
- child = gtk_bin_get_child (bin);
-
- if (child && gtk_widget_get_visible (child))
- {
- child_allocation.x = allocation->x + gtk_container_get_border_width (GTK_CONTAINER (widget));
- child_allocation.y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (widget));
- child_allocation.width = MAX (allocation->width - gtk_container_get_border_width (GTK_CONTAINER (widget)) * 2, 0);
- child_allocation.height = MAX (allocation->height - gtk_container_get_border_width (GTK_CONTAINER (widget)) * 2, 0);
-
- gtk_widget_size_allocate (child, &child_allocation);
- }
-}
-
static void
chat_finalize (GObject *object)
{
if (priv->save_paned_pos_id != 0)
g_source_remove (priv->save_paned_pos_id);
+ if (priv->contacts_visible_id != 0)
+ g_source_remove (priv->contacts_visible_id);
+
g_object_unref (priv->gsettings_chat);
g_object_unref (priv->gsettings_ui);
if (priv->tp_chat) {
g_signal_handlers_disconnect_by_func (priv->tp_chat,
- chat_destroy_cb, chat);
+ chat_invalidated_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_message_received_cb, chat);
+ g_signal_handlers_disconnect_by_func (priv->tp_chat,
+ chat_message_acknowledged_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_send_error_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_members_changed_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_remote_contact_changed_cb, chat);
- empathy_tp_chat_leave (priv->tp_chat);
+ empathy_tp_chat_leave (priv->tp_chat, "");
g_object_unref (priv->tp_chat);
}
if (priv->account) {
static void
empathy_chat_class_init (EmpathyChatClass *klass)
{
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = chat_finalize;
object_class->set_property = chat_set_property;
object_class->constructed = chat_constructed;
- widget_class->size_allocate = chat_size_allocate;
-
g_object_class_install_property (object_class,
PROP_TP_CHAT,
g_param_spec_object ("tp-chat",
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_SMS_CHANNEL,
+ g_param_spec_boolean ("sms-channel",
+ "SMS Channel",
+ "TRUE if this channel is for sending SMSes",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_N_MESSAGES_SENDING,
+ g_param_spec_uint ("n-messages-sending",
+ "Num Messages Sending",
+ "The number of messages being sent",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_NB_UNREAD_MESSAGES,
+ g_param_spec_uint ("nb-unread-messages",
+ "Num Unread Messages",
+ "The number of unread messages",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
signals[COMPOSING] =
g_signal_new ("composing",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
1, G_TYPE_BOOLEAN);
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- _empathy_marshal_VOID__OBJECT_BOOLEAN,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
2, EMPATHY_TYPE_MESSAGE, G_TYPE_BOOLEAN);
+ signals[PART_COMMAND_ENTERED] =
+ g_signal_new ("part-command-entered",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1, G_TYPE_STRV);
+
g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
}
EmpathyChat *chat = user_data;
GError *error = NULL;
- if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
+ if (!tp_proxy_prepare_finish (account_manager, result, &error)) {
DEBUG ("Failed to prepare the account manager: %s", error->message);
g_error_free (error);
return;
priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
- priv->contacts_width = -1;
+ priv->contacts_width = g_settings_get_int (priv->gsettings_ui,
+ EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
priv->input_history = NULL;
priv->input_history_current = NULL;
priv->account_manager = tp_account_manager_dup ();
- tp_account_manager_prepare_async (priv->account_manager, NULL,
+ tp_proxy_prepare_async (priv->account_manager, NULL,
account_manager_prepared_cb, chat);
priv->show_contacts = g_settings_get_boolean (priv->gsettings_chat,
return priv->tp_chat;
}
-static void display_password_info_bar (EmpathyChat *self,
- gboolean retry);
+typedef struct
+{
+ EmpathyChat *self;
+ GtkWidget *info_bar;
+ gulong response_id;
+ GtkWidget *button;
+ GtkWidget *label;
+ GtkWidget *entry;
+ GtkWidget *spinner;
+ gchar *password;
+} PasswordData;
+
+static void
+passwd_remember_button_cb (GtkButton *button,
+ PasswordData *data)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
+}
+
+static void
+passwd_not_now_button_cb (GtkButton *button,
+ PasswordData *data)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_NO);
+}
+
+static void
+remember_password_infobar_response_cb (GtkWidget *info_bar,
+ gint response_id,
+ PasswordData *data)
+{
+ EmpathyChatPriv *priv = GET_PRIV (data->self);
+
+ if (response_id == GTK_RESPONSE_OK) {
+ DEBUG ("Saving room password");
+ empathy_keyring_set_room_password_async (priv->account,
+ empathy_tp_chat_get_id (priv->tp_chat),
+ data->password,
+ NULL, NULL);
+ }
+
+ gtk_widget_destroy (info_bar);
+ g_free (data->password);
+ g_slice_free (PasswordData, data);
+}
+
+static void
+chat_prompt_to_save_password (EmpathyChat *self,
+ PasswordData *data)
+{
+ GtkWidget *content_area;
+ GtkWidget *hbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *alig;
+ GtkWidget *button;
+
+ /* save the password in case it needs to be saved */
+ data->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->entry)));
+
+ /* Remove all previous widgets */
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (data->info_bar));
+ gtk_container_forall (GTK_CONTAINER (content_area),
+ (GtkCallback) gtk_widget_destroy, NULL);
+ data->button = NULL;
+ data->label = NULL;
+ data->entry = NULL;
+ data->spinner = NULL;
+
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (data->info_bar),
+ GTK_MESSAGE_QUESTION);
+
+ hbox = gtk_hbox_new (FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
+
+ /* Add image */
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+ /* Add message */
+ label = gtk_label_new (_("Would you like to store this password?"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ /* Add 'Remember' button */
+ alig = gtk_alignment_new (0, 0.5, 1, 0);
+
+ button = gtk_button_new_with_label (_("Remember"));
+ gtk_container_add (GTK_CONTAINER (alig), button);
+ gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
+
+ g_signal_connect (button, "clicked", G_CALLBACK (passwd_remember_button_cb),
+ data);
+
+ /* Add 'Not now' button */
+ alig = gtk_alignment_new (0, 0.5, 1, 0);
+
+ button = gtk_button_new_with_label (_("Not now"));
+ gtk_container_add (GTK_CONTAINER (alig), button);
+ gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
+
+ g_signal_connect (button, "clicked", G_CALLBACK (passwd_not_now_button_cb),
+ data);
+
+ /* go! */
+ g_signal_handler_disconnect (data->info_bar, data->response_id);
+ g_signal_connect (data->info_bar, "response",
+ G_CALLBACK (remember_password_infobar_response_cb), data);
+
+ gtk_widget_show_all (data->info_bar);
+}
static void
provide_password_cb (GObject *tp_chat,
GAsyncResult *res,
gpointer user_data)
{
- EmpathyChat *self = EMPATHY_CHAT (user_data);
+ PasswordData *data = user_data;
+ EmpathyChat *self = data->self;
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?
* Display the raw D-Bus error to the user isn't very useful */
- if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED))
- display_password_info_bar (self, TRUE);
+ if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED)) {
+ /* entry */
+ gtk_entry_set_text (GTK_ENTRY (data->entry), "");
+ gtk_widget_set_sensitive (data->entry, TRUE);
+ gtk_widget_grab_focus (data->entry);
+
+ /* info bar */
+ gtk_info_bar_set_message_type (
+ GTK_INFO_BAR (data->info_bar),
+ GTK_MESSAGE_ERROR);
+
+ /* button */
+ gtk_widget_set_sensitive (data->button, TRUE);
+ gtk_button_set_label (GTK_BUTTON (data->button),
+ _("Retry"));
+
+ /* label */
+ gtk_label_set_text (GTK_LABEL (data->label),
+ _("Wrong password; please try again:"));
+
+ /* spinner */
+ gtk_spinner_stop (GTK_SPINNER (data->spinner));
+ gtk_widget_hide (data->spinner);
+ }
g_error_free (error);
return;
}
+ if (empathy_keyring_is_available ()) {
+ /* ask whether they want to save the password */
+ chat_prompt_to_save_password (self, data);
+ } else {
+ /* Get rid of the password info bar finally */
+ gtk_widget_destroy (data->info_bar);
+ g_slice_free (PasswordData, data);
+ }
+
/* Room joined */
gtk_widget_set_sensitive (priv->hpaned, TRUE);
+ gtk_widget_set_sensitive (self->input_text_view, TRUE);
gtk_widget_grab_focus (self->input_text_view);
}
static void
password_infobar_response_cb (GtkWidget *info_bar,
gint response_id,
- EmpathyChat *self)
+ PasswordData *data)
{
- EmpathyChatPriv *priv = GET_PRIV (self);
- GtkWidget *entry;
+ EmpathyChatPriv *priv = GET_PRIV (data->self);
const gchar *password;
- if (response_id != GTK_RESPONSE_OK)
- goto out;
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (info_bar);
+ g_slice_free (PasswordData, data);
+ return;
+ }
- entry = g_object_get_data (G_OBJECT (info_bar), "password-entry");
- g_assert (entry != NULL);
+ password = gtk_entry_get_text (GTK_ENTRY (data->entry));
- password = gtk_entry_get_text (GTK_ENTRY (entry));
+ tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
+ provide_password_cb, data);
- empathy_tp_chat_provide_password_async (priv->tp_chat, password,
- provide_password_cb, self);
+ gtk_widget_set_sensitive (data->button, FALSE);
+ gtk_widget_set_sensitive (data->entry, FALSE);
- out:
- gtk_widget_destroy (info_bar);
+ gtk_spinner_start (GTK_SPINNER (data->spinner));
+ gtk_widget_show (data->spinner);
}
static void
password_entry_activate_cb (GtkWidget *entry,
- GtkWidget *info_bar)
+ PasswordData *data)
{
- gtk_info_bar_response (GTK_INFO_BAR (info_bar), GTK_RESPONSE_OK);
+ gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
}
static void
passwd_join_button_cb (GtkButton *button,
- GtkWidget *info_bar)
+ PasswordData *data)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
+}
+
+static void
+clear_icon_released_cb (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos,
+ GdkEvent *event,
+ PasswordData *data)
+{
+ gtk_entry_set_text (entry, "");
+}
+
+static void
+password_entry_changed_cb (GtkEditable *entry,
+ PasswordData *data)
+{
+ const gchar *str;
+
+ str = gtk_entry_get_text (GTK_ENTRY (entry));
+
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
+}
+
+static void
+infobar_chat_invalidated_cb (TpProxy *proxy,
+ guint domain,
+ gint code,
+ gchar *message,
+ gpointer password_infobar)
{
- gtk_info_bar_response (GTK_INFO_BAR (info_bar), GTK_RESPONSE_OK);
+ /* Destroy the password infobar whenever a channel is invalidated
+ * so we don't have multiple infobars when the MUC is rejoined */
+ gtk_widget_destroy (GTK_WIDGET (password_infobar));
}
static void
-display_password_info_bar (EmpathyChat *self,
- gboolean retry)
+display_password_info_bar (EmpathyChat *self)
{
EmpathyChatPriv *priv = GET_PRIV (self);
GtkWidget *info_bar;
GtkWidget *entry;
GtkWidget *alig;
GtkWidget *button;
- GtkMessageType type;
- const gchar *msg, *button_label;
+ GtkWidget *spinner;
+ PasswordData *data;
- if (retry) {
- /* Previous password was wrong */
- type = GTK_MESSAGE_ERROR;
- msg = _("Wrong password; please try again:");
- button_label = _("Retry");
- }
- else {
- /* First time we're trying to join */
- type = GTK_MESSAGE_QUESTION;
- msg = _("This room is protected by a password:");
- button_label = _("Join");
- }
+ data = g_slice_new0 (PasswordData);
info_bar = gtk_info_bar_new ();
- gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), type);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
+ GTK_MESSAGE_QUESTION);
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
- hbox = gtk_hbox_new (FALSE, 3);
- gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ hbox = gtk_hbox_new (FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
/* Add image */
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
/* Add message */
- label = gtk_label_new (msg);
+ label = gtk_label_new (_("This room is protected by a password:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
/* Add password entry */
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY, FALSE);
+
+ g_signal_connect (entry, "icon-release",
+ G_CALLBACK (clear_icon_released_cb), data);
+ g_signal_connect (entry, "changed",
+ G_CALLBACK (password_entry_changed_cb), data);
+
g_signal_connect (entry, "activate",
- G_CALLBACK (password_entry_activate_cb), info_bar);
+ G_CALLBACK (password_entry_activate_cb), data);
/* Focus the password entry once it's realized */
g_signal_connect (entry, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
/* Add 'Join' button */
- alig = gtk_alignment_new (0, 0.5, 0, 0);
+ alig = gtk_alignment_new (0, 0.5, 1, 0);
- button = gtk_button_new_with_label (button_label);
+ button = gtk_button_new_with_label (_("Join"));
gtk_container_add (GTK_CONTAINER (alig), button);
gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
g_signal_connect (button, "clicked", G_CALLBACK (passwd_join_button_cb),
- info_bar);
+ data);
- g_object_set_data (G_OBJECT (info_bar), "password-entry", entry);
+ /* Add spinner */
+ spinner = gtk_spinner_new ();
+ gtk_box_pack_end (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
+
+ /* Save some data for messing around with later */
+ data->self = self;
+ data->info_bar = info_bar;
+ data->button = button;
+ data->label = label;
+ data->entry = entry;
+ data->spinner = spinner;
gtk_box_pack_start (GTK_BOX (priv->info_bar_vbox), info_bar,
- FALSE, FALSE, 3);
+ TRUE, TRUE, 3);
gtk_widget_show_all (hbox);
- g_signal_connect (info_bar, "response",
- G_CALLBACK (password_infobar_response_cb), self);
+ tp_g_signal_connect_object (priv->tp_chat,
+ "invalidated", G_CALLBACK (infobar_chat_invalidated_cb),
+ info_bar, 0);
+
+ data->response_id = g_signal_connect (info_bar, "response",
+ G_CALLBACK (password_infobar_response_cb), data);
gtk_widget_show_all (info_bar);
+ /* ... but hide the spinner */
+ gtk_widget_hide (spinner);
+
+ /* prevent the user from typing anything */
+ gtk_widget_set_sensitive (self->input_text_view, FALSE);
}
static void
-chat_password_needed_changed_cb (EmpathyChat *self)
+provide_saved_password_cb (GObject *tp_chat,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ EmpathyChat *self = user_data;
+ EmpathyChatPriv *priv = GET_PRIV (self);
+ GError *error = NULL;
+
+ 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?
+ * Display the raw D-Bus error to the user isn't very useful */
+ if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED)) {
+ display_password_info_bar (self);
+ gtk_widget_set_sensitive (priv->hpaned, FALSE);
+ }
+ g_error_free (error);
+ return;
+ }
+
+ /* Room joined */
+ gtk_widget_set_sensitive (priv->hpaned, TRUE);
+ gtk_widget_grab_focus (self->input_text_view);
+}
+
+static void
+chat_room_got_password_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
+ EmpathyChat *self = user_data;
EmpathyChatPriv *priv = GET_PRIV (self);
+ const gchar *password;
+ GError *error = NULL;
+
+ password = empathy_keyring_get_room_password_finish (priv->account,
+ result, &error);
- if (empathy_tp_chat_password_needed (priv->tp_chat)) {
- display_password_info_bar (self, FALSE);
+ if (error != NULL) {
+ DEBUG ("Couldn't get room password: %s\n", error->message);
+ g_clear_error (&error);
+
+ display_password_info_bar (self);
gtk_widget_set_sensitive (priv->hpaned, FALSE);
+ return;
}
+
+ tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
+ provide_saved_password_cb, self);
+}
+
+static void
+chat_password_needed_changed_cb (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ 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);
+ }
+}
+
+static void
+chat_sms_channel_changed_cb (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ priv->sms_channel = tp_text_channel_is_sms_channel (
+ (TpTextChannel *) priv->tp_chat);
+ g_object_notify (G_OBJECT (self), "sms-channel");
+}
+
+static void
+chat_n_messages_sending_changed_cb (EmpathyChat *self)
+{
+ g_object_notify (G_OBJECT (self), "n-messages-sending");
}
void
g_return_if_fail (EMPATHY_IS_CHAT (chat));
g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
- g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
if (priv->tp_chat) {
return;
priv->tp_chat = g_object_ref (tp_chat);
priv->account = g_object_ref (empathy_tp_chat_get_account (priv->tp_chat));
- g_signal_connect (tp_chat, "destroy",
- G_CALLBACK (chat_destroy_cb),
+ g_signal_connect (tp_chat, "invalidated",
+ G_CALLBACK (chat_invalidated_cb),
chat);
- g_signal_connect (tp_chat, "message-received",
+ g_signal_connect (tp_chat, "message-received-empathy",
G_CALLBACK (chat_message_received_cb),
chat);
+ g_signal_connect (tp_chat, "message_acknowledged",
+ G_CALLBACK (chat_message_acknowledged_cb),
+ chat);
g_signal_connect (tp_chat, "send-error",
G_CALLBACK (chat_send_error_cb),
chat);
- g_signal_connect (tp_chat, "chat-state-changed",
+ g_signal_connect (tp_chat, "chat-state-changed-empathy",
G_CALLBACK (chat_state_changed_cb),
chat);
g_signal_connect (tp_chat, "property-changed",
g_signal_connect_swapped (tp_chat, "notify::password-needed",
G_CALLBACK (chat_password_needed_changed_cb),
chat);
+ g_signal_connect_swapped (tp_chat, "notify::is-sms-channel",
+ G_CALLBACK (chat_sms_channel_changed_cb),
+ chat);
+ g_signal_connect_swapped (tp_chat, "notify::n-messages-sending",
+ G_CALLBACK (chat_n_messages_sending_changed_cb),
+ chat);
/* Get initial value of properties */
properties = empathy_tp_chat_get_properties (priv->tp_chat);
}
}
+ chat_sms_channel_changed_cb (chat);
chat_remote_contact_changed_cb (chat);
if (chat->input_text_view) {
return priv->id;
}
-const gchar *
-empathy_chat_get_name (EmpathyChat *chat)
+gchar *
+empathy_chat_dup_name (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
const gchar *ret;
g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
ret = priv->name;
+
if (!ret && priv->remote_contact) {
ret = empathy_contact_get_alias (priv->remote_contact);
}
if (!ret)
ret = priv->id;
- return ret ? ret : _("Conversation");
+ if (!ret)
+ ret = _("Conversation");
+
+ if (priv->sms_channel)
+ /* Translators: this string is a something like
+ * "Escher Cat (SMS)" */
+ return g_strdup_printf (_("%s (SMS)"), ret);
+ else
+ return g_strdup (ret);
}
const gchar *
menu = empathy_contact_menu_new (priv->remote_contact,
EMPATHY_CONTACT_FEATURE_CALL |
EMPATHY_CONTACT_FEATURE_LOG |
- EMPATHY_CONTACT_FEATURE_INFO);
+ EMPATHY_CONTACT_FEATURE_INFO |
+ EMPATHY_CONTACT_FEATURE_BLOCK);
}
return menu;
if (priv->retrieving_backlogs)
return;
- if (priv->tp_chat != NULL ) {
- empathy_tp_chat_acknowledge_all_messages (priv->tp_chat);
+ if (priv->tp_chat != NULL) {
+ tp_text_channel_ack_all_pending_messages_async (
+ TP_TEXT_CHANNEL (priv->tp_chat), NULL, NULL);
+ }
+
+ if (priv->unread_messages_when_offline > 0) {
+ /* We can't ack those as the connection has gone away so just consider
+ * them as read. */
+ priv->unread_messages -= priv->unread_messages_when_offline;
+ g_object_notify (G_OBJECT (self), "nb-unread-messages");
+ priv->unread_messages_when_offline = 0;
}
- priv->unread_messages = 0;
}
/* Return TRUE if on of the contacts in this chat is composing */
{
return chat->priv->compositors != NULL;
}
+
+gboolean
+empathy_chat_is_sms_channel (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
+
+ return priv->sms_channel;
+}
+
+guint
+empathy_chat_get_n_messages_sending (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
+
+ priv = GET_PRIV (self);
+
+ if (priv->tp_chat == NULL) {
+ return 0;
+ } else {
+ guint n_messages;
+
+ g_object_get (priv->tp_chat,
+ "n-messages-sending", &n_messages,
+ NULL);
+
+ return n_messages;
+ }
+}
+
+gchar *
+empathy_chat_dup_text (EmpathyChat *self)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->input_text_view));
+
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+ return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+}
+
+void
+empathy_chat_set_text (EmpathyChat *self,
+ const gchar *text)
+{
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->input_text_view));
+
+ gtk_text_buffer_set_text (buffer, text, -1);
+}