aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonnylamb@gnome.org>2010-03-30 21:48:31 +0800
committerJonny Lamb <jonnylamb@gnome.org>2010-03-30 21:48:31 +0800
commit5d6902cc05f95832e06afd88b6d581be68c1a79f (patch)
tree07b3c98b86de4b24e82fb52990f24716e9b0411a
parent62a0fee5ae1749f38e476ba67c0e1f2804ad5ee7 (diff)
parentd8dd568c2c1fed4cb328c2a9afc148186fda12aa (diff)
downloadgsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.tar
gsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.tar.gz
gsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.tar.bz2
gsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.tar.lz
gsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.tar.xz
gsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.tar.zst
gsoc2013-empathy-5d6902cc05f95832e06afd88b6d581be68c1a79f.zip
Merge branch 'undo-close-tab'
-rw-r--r--src/Makefile.am1
-rw-r--r--src/empathy-chat-manager.c253
-rw-r--r--src/empathy-chat-manager.h70
-rw-r--r--src/empathy-chat-window.c48
-rw-r--r--src/empathy-chat-window.ui8
-rw-r--r--src/empathy-main-window.c20
-rw-r--r--src/empathy.c6
7 files changed, 406 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a01b759a1..18edc7f3f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -115,6 +115,7 @@ empathy_handwritten_source = \
empathy-preferences.c empathy-preferences.h \
empathy-sidebar.c empathy-sidebar.h \
empathy-status-icon.c empathy-status-icon.h \
+ empathy-chat-manager.c empathy-chat-manager.h \
empathy.c
empathy_SOURCES = \
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
new file mode 100644
index 000000000..01506f52e
--- /dev/null
+++ b/src/empathy-chat-manager.c
@@ -0,0 +1,253 @@
+/*
+ * empathy-chat-manager.c - Source for EmpathyChatManager
+ * Copyright (C) 2010 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <libempathy/empathy-dispatcher.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
+
+#include "empathy-chat-manager.h"
+
+enum {
+ CHATS_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE(EmpathyChatManager, empathy_chat_manager, G_TYPE_OBJECT)
+
+/* private structure */
+typedef struct _EmpathyChatManagerPriv EmpathyChatManagerPriv;
+
+struct _EmpathyChatManagerPriv
+{
+ GQueue *queue;
+};
+
+#define GET_PRIV(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CHAT_MANAGER, \
+ EmpathyChatManagerPriv))
+
+static EmpathyChatManager *chat_manager_singleton = NULL;
+
+typedef struct
+{
+ TpAccount *account;
+ gchar *id;
+ gboolean room;
+} ChatData;
+
+static ChatData *
+chat_data_new (EmpathyChat *chat)
+{
+ ChatData *data = NULL;
+
+ data = g_slice_new0 (ChatData);
+
+ data->account = g_object_ref (empathy_chat_get_account (chat));
+ data->id = g_strdup (empathy_chat_get_id (chat));
+ data->room = empathy_chat_is_room (chat);
+
+ return data;
+}
+
+static void
+chat_data_free (ChatData *data)
+{
+ if (data->account != NULL)
+ {
+ g_object_unref (data->account);
+ data->account = NULL;
+ }
+
+ if (data->id != NULL)
+ {
+ g_free (data->id);
+ data->id = NULL;
+ }
+
+ g_slice_free (ChatData, data);
+}
+
+static void
+empathy_chat_manager_init (EmpathyChatManager *self)
+{
+ EmpathyChatManagerPriv *priv = GET_PRIV (self);
+
+ priv->queue = g_queue_new ();
+}
+
+static void
+empathy_chat_manager_finalize (GObject *object)
+{
+ EmpathyChatManager *self = EMPATHY_CHAT_MANAGER (object);
+ EmpathyChatManagerPriv *priv = GET_PRIV (self);
+
+ if (priv->queue != NULL)
+ {
+ g_queue_foreach (priv->queue, (GFunc) chat_data_free, NULL);
+ g_queue_free (priv->queue);
+ priv->queue = NULL;
+ }
+
+ G_OBJECT_CLASS (empathy_chat_manager_parent_class)->finalize (object);
+}
+
+static GObject *
+empathy_chat_manager_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *retval;
+
+ if (!chat_manager_singleton)
+ {
+ retval = G_OBJECT_CLASS (empathy_chat_manager_parent_class)->constructor
+ (type, n_construct_params, construct_params);
+
+ chat_manager_singleton = EMPATHY_CHAT_MANAGER (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &chat_manager_singleton);
+ }
+ else
+ {
+ retval = g_object_ref (chat_manager_singleton);
+ }
+
+ return retval;
+}
+
+static void
+empathy_chat_manager_class_init (
+ EmpathyChatManagerClass *empathy_chat_manager_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (empathy_chat_manager_class);
+
+ object_class->finalize = empathy_chat_manager_finalize;
+ object_class->constructor = empathy_chat_manager_constructor;
+
+ signals[CHATS_CHANGED] =
+ g_signal_new ("chats-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE,
+ 1, G_TYPE_UINT, NULL);
+
+ g_type_class_add_private (empathy_chat_manager_class,
+ sizeof (EmpathyChatManagerPriv));
+}
+
+EmpathyChatManager *
+empathy_chat_manager_dup_singleton (void)
+{
+ return g_object_new (EMPATHY_TYPE_CHAT_MANAGER, NULL);
+}
+
+void
+empathy_chat_manager_closed_chat (EmpathyChatManager *self,
+ EmpathyChat *chat)
+{
+ EmpathyChatManagerPriv *priv = GET_PRIV (self);
+ ChatData *data;
+
+ data = chat_data_new (chat);
+
+ DEBUG ("Adding %s to queue: %s", data->room ? "room" : "contact", data->id);
+
+ g_queue_push_tail (priv->queue, data);
+
+ g_signal_emit (self, signals[CHATS_CHANGED], 0,
+ g_queue_get_length (priv->queue));
+}
+
+static void
+connection_ready_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data)
+{
+ ChatData *data = user_data;
+ EmpathyChatManager *self = chat_manager_singleton;
+ EmpathyChatManagerPriv *priv;
+
+ /* Extremely unlikely to happen, but I don't really want to keep refs to the
+ * chat manager in the ChatData structs as it'll then prevent the manager
+ * from being finalized. */
+ if (G_UNLIKELY (self == NULL))
+ goto out;
+
+ priv = GET_PRIV (self);
+
+ if (error == NULL)
+ {
+ if (data->room)
+ empathy_dispatcher_join_muc (connection, data->id, NULL, NULL);
+ else
+ empathy_dispatcher_chat_with_contact_id (connection, data->id,
+ NULL, NULL);
+
+ g_signal_emit (self, signals[CHATS_CHANGED], 0,
+ g_queue_get_length (priv->queue));
+ }
+ else
+ {
+ DEBUG ("Error readying connection, no chat: %s", error->message);
+ }
+
+out:
+ chat_data_free (data);
+}
+
+void
+empathy_chat_manager_undo_closed_chat (EmpathyChatManager *self)
+{
+ EmpathyChatManagerPriv *priv = GET_PRIV (self);
+ ChatData *data;
+ TpConnection *connection;
+
+ data = g_queue_pop_tail (priv->queue);
+
+ if (data == NULL)
+ return;
+
+ DEBUG ("Removing %s from queue and starting a chat with: %s",
+ data->room ? "room" : "contact", data->id);
+
+ connection = tp_account_get_connection (data->account);
+
+ if (connection != NULL)
+ {
+ tp_connection_call_when_ready (connection, connection_ready_cb, data);
+ }
+ else
+ {
+ DEBUG ("No connection, no chat.");
+ chat_data_free (data);
+ }
+}
+
+guint
+empathy_chat_manager_get_num_chats (EmpathyChatManager *self)
+{
+ EmpathyChatManagerPriv *priv = GET_PRIV (self);
+
+ return g_queue_get_length (priv->queue);
+}
diff --git a/src/empathy-chat-manager.h b/src/empathy-chat-manager.h
new file mode 100644
index 000000000..3a20ab826
--- /dev/null
+++ b/src/empathy-chat-manager.h
@@ -0,0 +1,70 @@
+/*
+ * empathy-chat-manager.h - Header for EmpathyChatManager
+ * Copyright (C) 2010 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __EMPATHY_CHAT_MANAGER_H__
+#define __EMPATHY_CHAT_MANAGER_H__
+
+#include <glib-object.h>
+
+#include <libempathy-gtk/empathy-chat.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EmpathyChatManager EmpathyChatManager;
+typedef struct _EmpathyChatManagerClass EmpathyChatManagerClass;
+
+struct _EmpathyChatManagerClass
+{
+ GObjectClass parent_class;
+};
+
+struct _EmpathyChatManager
+{
+ GObject parent;
+};
+
+GType empathy_chat_manager_get_type (void);
+
+/* TYPE MACROS */
+#define EMPATHY_TYPE_CHAT_MANAGER \
+ (empathy_chat_manager_get_type ())
+#define EMPATHY_CHAT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), EMPATHY_TYPE_CHAT_MANAGER, \
+ EmpathyChatManager))
+#define EMPATHY_CHAT_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), EMPATHY_TYPE_CHAT_MANAGER, \
+ EmpathyChatManagerClass))
+#define EMPATHY_IS_CHAT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), EMPATHY_TYPE_CHAT_MANAGER))
+#define EMPATHY_IS_CHAT_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), EMPATHY_TYPE_CHAT_MANAGER))
+#define EMPATHY_CHAT_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_CHAT_MANAGER, \
+ EmpathyChatManagerClass))
+
+EmpathyChatManager *empathy_chat_manager_dup_singleton (void);
+
+void empathy_chat_manager_closed_chat (EmpathyChatManager *self,
+ EmpathyChat *chat);
+void empathy_chat_manager_undo_closed_chat (EmpathyChatManager *self);
+guint empathy_chat_manager_get_num_chats (EmpathyChatManager *self);
+
+G_END_DECLS
+
+#endif /* #ifndef __EMPATHY_CHAT_MANAGER_H__*/
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index 302aa3ac3..e18ae2583 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -54,6 +54,7 @@
#include <libempathy-gtk/empathy-ui-utils.h>
#include <libempathy-gtk/empathy-notify-manager.h>
+#include "empathy-chat-manager.h"
#include "empathy-chat-window.h"
#include "empathy-about-dialog.h"
#include "empathy-invite-participant-dialog.h"
@@ -84,6 +85,9 @@ typedef struct {
GtkTargetList *contact_targets;
GtkTargetList *file_targets;
+ EmpathyChatManager *chat_manager;
+ gulong chat_manager_chats_changed_id;
+
/* Menu items. */
GtkUIManager *ui_manager;
GtkAction *menu_conv_insert_smiley;
@@ -97,6 +101,7 @@ typedef struct {
GtkAction *menu_tabs_next;
GtkAction *menu_tabs_prev;
+ GtkAction *menu_tabs_undo_close_tab;
GtkAction *menu_tabs_left;
GtkAction *menu_tabs_right;
GtkAction *menu_tabs_detach;
@@ -1066,6 +1071,14 @@ chat_window_tabs_previous_activate_cb (GtkAction *action,
}
static void
+chat_window_tabs_undo_close_tab_activate_cb (GtkAction *action,
+ EmpathyChatWindow *window)
+{
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
+ empathy_chat_manager_undo_closed_chat (priv->chat_manager);
+}
+
+static void
chat_window_tabs_left_activate_cb (GtkAction *action,
EmpathyChatWindow *window)
{
@@ -1744,6 +1757,17 @@ chat_window_drag_data_received (GtkWidget *widget,
}
static void
+chat_window_chat_manager_chats_changed_cb (EmpathyChatManager *chat_manager,
+ guint num_chats_in_manager,
+ EmpathyChatWindow *window)
+{
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
+
+ gtk_action_set_sensitive (priv->menu_tabs_undo_close_tab,
+ num_chats_in_manager > 0);
+}
+
+static void
chat_window_finalize (GObject *object)
{
EmpathyChatWindow *window;
@@ -1776,6 +1800,13 @@ chat_window_finalize (GObject *object)
gtk_target_list_unref (priv->file_targets);
}
+ if (priv->chat_manager) {
+ g_signal_handler_disconnect (priv->chat_manager,
+ priv->chat_manager_chats_changed_id);
+ g_object_unref (priv->chat_manager);
+ priv->chat_manager = NULL;
+ }
+
chat_windows = g_list_remove (chat_windows, window);
gtk_widget_destroy (priv->dialog);
@@ -1834,6 +1865,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
"menu_edit_find", &priv->menu_edit_find,
"menu_tabs_next", &priv->menu_tabs_next,
"menu_tabs_prev", &priv->menu_tabs_prev,
+ "menu_tabs_undo_close_tab", &priv->menu_tabs_undo_close_tab,
"menu_tabs_left", &priv->menu_tabs_left,
"menu_tabs_right", &priv->menu_tabs_right,
"menu_tabs_detach", &priv->menu_tabs_detach,
@@ -1854,6 +1886,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
"menu_edit_find", "activate", chat_window_find_activate_cb,
"menu_tabs_next", "activate", chat_window_tabs_next_activate_cb,
"menu_tabs_prev", "activate", chat_window_tabs_previous_activate_cb,
+ "menu_tabs_undo_close_tab", "activate", chat_window_tabs_undo_close_tab_activate_cb,
"menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
"menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
"menu_tabs_detach", "activate", chat_window_detach_activate_cb,
@@ -1961,6 +1994,16 @@ empathy_chat_window_init (EmpathyChatWindow *window)
priv->current_chat = NULL;
priv->notify_mgr = empathy_notify_manager_dup_singleton ();
+
+ priv->chat_manager = empathy_chat_manager_dup_singleton ();
+ priv->chat_manager_chats_changed_id =
+ g_signal_connect (priv->chat_manager, "chats-changed",
+ G_CALLBACK (chat_window_chat_manager_chats_changed_cb),
+ window);
+
+ chat_window_chat_manager_chats_changed_cb (priv->chat_manager,
+ empathy_chat_manager_get_num_chats (priv->chat_manager),
+ window);
}
EmpathyChatWindow *
@@ -2103,6 +2146,7 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
EmpathyChatWindowPriv *priv;
gint position;
EmpathyContact *remote_contact;
+ EmpathyChatManager *chat_manager;
g_return_if_fail (window != NULL);
g_return_if_fail (EMPATHY_IS_CHAT (chat));
@@ -2120,6 +2164,10 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
chat);
}
+ chat_manager = empathy_chat_manager_dup_singleton ();
+ empathy_chat_manager_closed_chat (chat_manager, chat);
+ g_object_unref (chat_manager);
+
position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
GTK_WIDGET (chat));
gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
diff --git a/src/empathy-chat-window.ui b/src/empathy-chat-window.ui
index 32bf89cc0..0c4aba0b4 100644
--- a/src/empathy-chat-window.ui
+++ b/src/empathy-chat-window.ui
@@ -112,6 +112,13 @@
<accelerator key="Page_Down" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
+ <object class="GtkAction" id="menu_tabs_undo_close_tab">
+ <property name="name">menu_tabs_undo_close_tab</property>
+ <property name="label" translatable="yes">_Undo Close Tab</property>
+ </object>
+ <accelerator key="t" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+ </child>
+ <child>
<object class="GtkAction" id="menu_tabs_left">
<property name="name">menu_tabs_left</property>
<property name="label" translatable="yes">Move Tab _Left</property>
@@ -175,6 +182,7 @@
<menu action="menu_tabs">
<menuitem action="menu_tabs_prev"/>
<menuitem action="menu_tabs_next"/>
+ <menuitem action="menu_tabs_undo_close_tab"/>
<separator/>
<menuitem action="menu_tabs_left"/>
<menuitem action="menu_tabs_right"/>
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index 635627e74..031e23d07 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
#include <telepathy-glib/account-manager.h>
@@ -53,6 +54,7 @@
#include <libempathy-gtk/empathy-ui-utils.h>
#include "empathy-accounts-dialog.h"
+#include "empathy-chat-manager.h"
#include "empathy-main-window.h"
#include "ephy-spinner.h"
#include "empathy-preferences.h"
@@ -662,6 +664,23 @@ main_window_destroy_cb (GtkWidget *widget,
g_free (window);
}
+static gboolean
+main_window_key_press_event_cb (GtkWidget *window,
+ GdkEventKey *event,
+ gpointer user_data)
+{
+ EmpathyChatManager *chat_manager;
+
+ if (event->keyval == GDK_T
+ && event->state & GDK_SHIFT_MASK
+ && event->state & GDK_CONTROL_MASK) {
+ chat_manager = empathy_chat_manager_dup_singleton ();
+ empathy_chat_manager_undo_closed_chat (chat_manager);
+ g_object_unref (chat_manager);
+ }
+ return FALSE;
+}
+
static void
main_window_chat_quit_cb (GtkAction *action,
EmpathyMainWindow *window)
@@ -1338,6 +1357,7 @@ empathy_main_window_show (void)
empathy_builder_connect (gui, window,
"main_window", "destroy", main_window_destroy_cb,
+ "main_window", "key-press-event", main_window_key_press_event_cb,
"chat_quit", "activate", main_window_chat_quit_cb,
"chat_new_message", "activate", main_window_chat_new_message_cb,
"chat_new_call", "activate", main_window_chat_new_call_cb,
diff --git a/src/empathy.c b/src/empathy.c
index b92f58d26..637778d47 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -72,6 +72,7 @@
#include "empathy-import-mc4-accounts.h"
#include "empathy-accounts-common.h"
#include "empathy-accounts-dialog.h"
+#include "empathy-chat-manager.h"
#include "empathy-status-icon.h"
#include "empathy-call-window.h"
#include "empathy-chat-window.h"
@@ -581,6 +582,7 @@ main (int argc, char *argv[])
GtkWidget *window;
EmpathyIdle *idle;
EmpathyConnectivity *connectivity;
+ EmpathyChatManager *chat_manager;
GError *error = NULL;
UniqueApp *unique_app;
gboolean chatroom_manager_ready;
@@ -686,6 +688,9 @@ main (int argc, char *argv[])
window = empathy_main_window_show ();
icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
+ /* Chat manager */
+ chat_manager = empathy_chat_manager_dup_singleton ();
+
g_signal_connect (unique_app, "message-received",
G_CALLBACK (unique_app_message_cb), window);
@@ -735,6 +740,7 @@ main (int argc, char *argv[])
g_object_unref (debug_sender);
#endif
+ g_object_unref (chat_manager);
g_object_unref (idle);
g_object_unref (connectivity);
g_object_unref (icon);