#include <telepathy-glib/telepathy-glib.h>
+#include <libempathy/empathy-client-factory.h>
#include <libempathy/empathy-contact.h>
#include <libempathy/empathy-message.h>
#include <libempathy/empathy-chatroom-manager.h>
return NULL;
}
+static void
+remove_all_chats (EmpathyChatWindow *window)
+{
+ EmpathyChatWindowPriv *priv;
+
+ priv = GET_PRIV (window);
+ g_object_ref (window);
+
+ while (priv->chats) {
+ empathy_chat_window_remove_chat (window, priv->chats->data);
+ }
+
+ g_object_unref (window);
+}
+
+static void
+confirm_close_response_cb (GtkWidget *dialog,
+ int response,
+ EmpathyChatWindow *window)
+{
+ EmpathyChat *chat;
+
+ chat = g_object_get_data (G_OBJECT (dialog), "chat");
+
+ gtk_widget_destroy (dialog);
+
+ if (response != GTK_RESPONSE_ACCEPT)
+ return;
+
+ if (chat != NULL) {
+ empathy_chat_window_remove_chat (window, chat);
+ } else {
+ remove_all_chats (window);
+ }
+}
+
+static void
+confirm_close (EmpathyChatWindow *window,
+ gboolean close_window,
+ guint n_rooms,
+ EmpathyChat *chat)
+{
+ EmpathyChatWindowPriv *priv;
+ GtkWidget *dialog;
+ gchar *primary, *secondary;
+
+ g_return_if_fail (n_rooms > 0);
+
+ if (n_rooms > 1) {
+ g_return_if_fail (chat == NULL);
+ } else {
+ g_return_if_fail (chat != NULL);
+ }
+
+ priv = GET_PRIV (window);
+
+ /* If there are no chats in this window, how could we possibly have got
+ * here?
+ */
+ g_return_if_fail (priv->chats != NULL);
+
+ /* Treat closing a window which only has one tab exactly like closing
+ * that tab.
+ */
+ if (close_window && priv->chats->next == NULL) {
+ close_window = FALSE;
+ chat = priv->chats->data;
+ }
+
+ if (close_window) {
+ primary = g_strdup (_("Close this window?"));
+
+ if (n_rooms == 1) {
+ gchar *chat_name = empathy_chat_dup_name (chat);
+ secondary = g_strdup_printf (
+ _("Closing this window will leave %s. You will "
+ "not receive any further messages until you "
+ "rejoin it."),
+ chat_name);
+ g_free (chat_name);
+ } else {
+ secondary = g_strdup_printf (
+ /* Note to translators: the number of chats will
+ * always be at least 2.
+ */
+ ngettext (
+ "Closing this window will leave a chat room. You will "
+ "not receive any further messages until you rejoin it.",
+ "Closing this window will leave %u chat rooms. You will "
+ "not receive any further messages until you rejoin them.",
+ n_rooms),
+ n_rooms);
+ }
+ } else {
+ gchar *chat_name = empathy_chat_dup_name (chat);
+ primary = g_strdup_printf (_("Leave %s?"), chat_name);
+ secondary = g_strdup (_("You will not receive any further messages from this chat "
+ "room until you rejoin it."));
+ g_free (chat_name);
+ }
+
+ dialog = gtk_message_dialog_new (
+ GTK_WINDOW (priv->dialog),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_CANCEL,
+ "%s", primary);
+
+ gtk_window_set_title (GTK_WINDOW (dialog), "");
+ g_object_set (dialog, "secondary-text", secondary, NULL);
+
+ g_free (primary);
+ g_free (secondary);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ close_window ? _("Close window") : _("Leave room"),
+ GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_ACCEPT);
+
+ if (!close_window) {
+ g_object_set_data (G_OBJECT (dialog), "chat", chat);
+ }
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (confirm_close_response_cb), window);
+
+ gtk_window_present (GTK_WINDOW (dialog));
+}
+
+/* Returns TRUE if we should check if the user really wants to leave. If it's
+ * a multi-user chat, and it has a TpChat (so there's an underlying channel, so
+ * the user is actually in the room as opposed to having been kicked or gone
+ * offline or something), then we should check.
+ */
+static gboolean
+chat_needs_close_confirmation (EmpathyChat *chat)
+{
+ return (empathy_chat_is_room (chat)
+ && empathy_chat_get_tp_chat (chat) != NULL);
+}
+
+static void
+maybe_close_chat (EmpathyChatWindow *window,
+ EmpathyChat *chat)
+{
+ g_return_if_fail (chat != NULL);
+
+ if (chat_needs_close_confirmation (chat)) {
+ confirm_close (window, FALSE, 1, chat);
+ } else {
+ empathy_chat_window_remove_chat (window, chat);
+ }
+}
+
static void
chat_window_close_clicked_cb (GtkAction *action,
EmpathyChat *chat)
EmpathyChatWindow *window;
window = chat_window_find_chat (chat);
- empathy_chat_window_remove_chat (window, chat);
+ maybe_close_chat (window, chat);
}
static void
PangoAttribute *attr;
/* The spacing between the button and the label. */
- hbox = gtk_hbox_new (FALSE, 0);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
status_image = gtk_image_new ();
/* Spacing between the icon and label. */
- event_box_hbox = gtk_hbox_new (FALSE, 0);
+ event_box_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (event_box_hbox), status_image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (event_box_hbox), name_label, TRUE, TRUE, 0);
tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
if (tp_chat != NULL) {
- connection = empathy_tp_chat_get_connection (tp_chat);
+ connection = tp_channel_borrow_connection (TP_CHANNEL (tp_chat));
sensitive = empathy_tp_chat_can_add_contact (tp_chat) &&
(tp_connection_get_status (connection, NULL) ==
EmpathyChatWindowPriv *priv;
GtkWidget *dialog;
EmpathyTpChat *tp_chat;
- TpChannel *channel;
int response;
- TpAccount *account;
priv = GET_PRIV (window);
g_return_if_fail (priv->current_chat != NULL);
tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
- channel = empathy_tp_chat_get_channel (tp_chat);
- account = empathy_chat_get_account (priv->current_chat);
dialog = empathy_invite_participant_dialog_new (
GTK_WINDOW (priv->dialog), tp_chat);
g_return_if_fail (priv->current_chat != NULL);
- empathy_chat_window_remove_chat (window, priv->current_chat);
+ maybe_close_chat (window, priv->current_chat);
}
static void
EmpathyChatWindow *window)
{
EmpathyChatWindowPriv *priv = GET_PRIV (window);
- empathy_chat_manager_undo_closed_chat (priv->chat_manager);
+ empathy_chat_manager_undo_closed_chat (priv->chat_manager,
+ empathy_get_current_action_time ());
}
static void
EmpathyChatWindow *window)
{
EmpathyChatWindowPriv *priv = GET_PRIV (window);
+ EmpathyChat *chat = NULL;
+ guint n_rooms = 0;
+ GList *l;
DEBUG ("Delete event received");
- g_object_ref (window);
- while (priv->chats) {
- empathy_chat_window_remove_chat (window, priv->chats->data);
+ for (l = priv->chats; l != NULL; l = l->next) {
+ if (chat_needs_close_confirmation (l->data)) {
+ chat = l->data;
+ n_rooms++;
+ }
+ }
+
+ if (n_rooms > 0) {
+ confirm_close (window, TRUE, n_rooms,
+ (n_rooms == 1 ? chat : NULL));
+ } else {
+ remove_all_chats (window);
}
- g_object_unref (window);
return TRUE;
}
notify_notification_set_hint_string (notification,
EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND, "1");
}
+
+ notify_notification_set_hint (notification,
+ EMPATHY_NOTIFY_MANAGER_CAP_CATEGORY,
+ g_variant_new_string ("im.received"));
}
pixbuf = empathy_notify_manager_get_pixbuf_for_notification (priv->notify_mgr,
chat_window_new_message_cb (EmpathyChat *chat,
EmpathyMessage *message,
gboolean pending,
+ gboolean should_highlight,
EmpathyChatWindow *window)
{
EmpathyChatWindowPriv *priv;
* a) the chatroom's always_urgent property is TRUE
* b) the message contains our alias
*/
- if (empathy_chat_is_room (chat) ||
- empathy_chat_get_remote_contact (chat) == NULL) {
+ if (empathy_chat_is_room (chat)) {
TpAccount *account;
const gchar *room;
EmpathyChatroom *chatroom;
if (chatroom != NULL && empathy_chatroom_is_always_urgent (chatroom)) {
needs_urgency = TRUE;
} else {
- needs_urgency = empathy_message_should_highlight (message);
+ needs_urgency = should_highlight;
}
} else {
needs_urgency = TRUE;
EmpathyChat *chat = NULL;
EmpathyChatWindow *old_window;
TpAccount *account = NULL;
- TpAccountManager *account_manager;
+ EmpathyClientFactory *factory;
const gchar *id;
gchar **strv;
const gchar *account_id;
id = (const gchar*) gtk_selection_data_get_data (selection);
- /* FIXME: Perhaps should be sure that the account manager is
- * prepared before calling _ensure_account on it. */
- account_manager = tp_account_manager_dup ();
+ factory = empathy_client_factory_dup ();
DEBUG ("DND contact from roster with id:'%s'", id);
account_id = strv[0];
contact_id = strv[1];
account =
- tp_account_manager_ensure_account (account_manager, account_id);
+ tp_simple_client_factory_ensure_account (
+ TP_SIMPLE_CLIENT_FACTORY (factory), account_id,
+ NULL, NULL);
+
+ g_object_unref (factory);
if (account != NULL)
chat = empathy_chat_window_find_chat (account, contact_id, FALSE);
}
if (!chat) {
empathy_chat_with_contact_id (
- account, contact_id, empathy_get_current_action_time ());
+ account, contact_id,
+ empathy_get_current_action_time (),
+ NULL, NULL);
g_strfreev (strv);
return;
}
- g_object_unref (account_manager);
g_strfreev (strv);
old_window = chat_window_find_chat (chat);
window);
}
-static GtkWidget *
-empathy_chat_window_get_dialog (EmpathyChatWindow *window)
-{
- EmpathyChatWindowPriv *priv;
-
- g_return_val_if_fail (window != NULL, NULL);
-
- priv = GET_PRIV (window);
-
- return priv->dialog;
-}
-
/* Returns the window to open a new tab in if there is a suitable window,
* otherwise, returns NULL indicating that a new window should be added.
*/
for (l = chat_windows; l; l = l->next) {
EmpathyChatWindow *chat_window;
- GtkWidget *dialog;
guint nb_rooms, nb_private;
chat_window = l->data;
- dialog = empathy_chat_window_get_dialog (chat_window);
-
empathy_chat_window_get_nb_chats (chat_window, &nb_rooms, &nb_private);
/* Skip the window if there aren't any rooms in it */
if (!room && nb_private == 0)
continue;
- /* Found a window on this desktop, make it visible if necessary */
- if (!empathy_window_get_is_visible (GTK_WINDOW (dialog)))
- empathy_window_present (GTK_WINDOW (dialog));
return chat_window;
}
}
empathy_chat_window_switch_to_chat (window, chat);
- empathy_window_present_with_time (GTK_WINDOW (priv->dialog),
- x_timestamp);
+
+ /* Don't use empathy_window_present_with_time () which would move the window
+ * to our current desktop but move to the window's desktop instead. This is
+ * more coherent with Shell's 'app is ready' notication which moves the view
+ * to the app desktop rather than moving the app itself. */
+ empathy_move_to_window_desktop (GTK_WINDOW (priv->dialog), x_timestamp);
gtk_widget_grab_focus (chat->input_text_view);
}