[empathy: 2/4] Add EmpathyChatManager::chats-changed signal and make the chat window listen to it.
- From: Jonny Lamb <jonnylamb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy: 2/4] Add EmpathyChatManager::chats-changed signal and make the chat window listen to it.
- Date: Tue, 30 Mar 2010 14:21:48 +0000 (UTC)
commit 7415009e9f118174703834d95b91653f8de4e3f4
Author: Jonny Lamb <jonnylamb gnome org>
Date: Mon Mar 1 11:31:52 2010 +0000
Add EmpathyChatManager::chats-changed signal and make the chat window listen to it.
Signed-off-by: Jonny Lamb <jonnylamb gnome org>
src/empathy-chat-manager.c | 31 +++++++++++++++++++++++++++++++
src/empathy-chat-manager.h | 1 +
src/empathy-chat-window.c | 42 +++++++++++++++++++++++++++++++++++-------
3 files changed, 67 insertions(+), 7 deletions(-)
---
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
index 051d07b..087077c 100644
--- a/src/empathy-chat-manager.c
+++ b/src/empathy-chat-manager.c
@@ -24,6 +24,13 @@
#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 */
@@ -96,6 +103,16 @@ empathy_chat_manager_class_init (
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));
}
@@ -115,6 +132,9 @@ empathy_chat_manager_closed_chat (EmpathyChatManager *self,
DEBUG ("Adding contact to queue: %s", empathy_contact_get_id (contact));
g_queue_push_tail (priv->queue, g_object_ref (contact));
+
+ g_signal_emit (self, signals[CHATS_CHANGED], 0,
+ g_queue_get_length (priv->queue));
}
void
@@ -134,4 +154,15 @@ empathy_chat_manager_undo_closed_chat (EmpathyChatManager *self)
empathy_dispatcher_chat_with_contact (contact, NULL, NULL);
g_object_unref (contact);
+
+ g_signal_emit (self, signals[CHATS_CHANGED], 0,
+ g_queue_get_length (priv->queue));
+}
+
+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
index af4d977..1dc121c 100644
--- a/src/empathy-chat-manager.h
+++ b/src/empathy-chat-manager.h
@@ -63,6 +63,7 @@ EmpathyChatManager *empathy_chat_manager_dup_singleton (void);
void empathy_chat_manager_closed_chat (EmpathyChatManager *self,
EmpathyContact *contact);
void empathy_chat_manager_undo_closed_chat (EmpathyChatManager *self);
+guint empathy_chat_manager_get_num_chats (EmpathyChatManager *self);
G_END_DECLS
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index 50543f2..1df42f1 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -85,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;
@@ -98,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;
@@ -1063,13 +1067,8 @@ static void
chat_window_tabs_undo_close_tab_activate_cb (GtkAction *action,
EmpathyChatWindow *window)
{
- EmpathyChatManager *chat_manager;
-
- chat_manager = empathy_chat_manager_dup_singleton ();
-
- empathy_chat_manager_undo_closed_chat (chat_manager);
-
- g_object_unref (chat_manager);
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
+ empathy_chat_manager_undo_closed_chat (priv->chat_manager);
}
static void
@@ -1754,6 +1753,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;
@@ -1786,6 +1796,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);
@@ -1844,6 +1861,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,
@@ -1972,6 +1990,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 *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]