return hbox;
}
-static void
-chat_window_update_menu (EmpathyChatWindow *window)
+static const gchar *
+chat_window_get_chat_name (EmpathyChat *chat)
{
- EmpathyChatWindowPriv *priv;
- gboolean first_page;
- gboolean last_page;
- gboolean is_connected;
- gint num_pages;
- gint page_num;
+ EmpathyContact *remote_contact = NULL;
+ const gchar *name = NULL;
- priv = GET_PRIV (window);
+ name = empathy_chat_get_name (chat);
+ if (!name) {
+ remote_contact = empathy_chat_get_remote_contact (chat);
+ if (remote_contact) {
+ name = empathy_contact_get_name (remote_contact);
+ } else {
+ name = _("Conversation");
+ }
+ }
+
+ return name;
+}
- /* Notebook pages */
+static void
+chat_window_update (EmpathyChatWindow *window)
+{
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
+ gboolean first_page;
+ gboolean last_page;
+ gboolean is_connected;
+ gint num_pages;
+ gint page_num;
+ const gchar *name;
+ guint n_chats;
+
+ /* Get information */
page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
first_page = (page_num == 0);
last_page = (page_num == (num_pages - 1));
+ is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
+ name = chat_window_get_chat_name (priv->current_chat);
+ n_chats = g_list_length (priv->chats);
+ empathy_debug (DEBUG_DOMAIN, "Update window");
+
+ /* Update menu */
gtk_widget_set_sensitive (priv->menu_tabs_next, !last_page);
gtk_widget_set_sensitive (priv->menu_tabs_prev, !first_page);
gtk_widget_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
gtk_widget_set_sensitive (priv->menu_tabs_left, !first_page);
gtk_widget_set_sensitive (priv->menu_tabs_right, !last_page);
-
- is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
-}
-
-static void
-chat_window_update_title (EmpathyChatWindow *window)
-{
- EmpathyChatWindowPriv *priv = GET_PRIV (window);
- EmpathyTpChat *tp_chat;
- EmpathyContact *remote_contact;
- const gchar *name;
- guint n_chats;
-
- /* Get chat's name */
- name = empathy_chat_get_name (priv->current_chat);
- tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
- if (!name && tp_chat) {
- remote_contact = empathy_tp_chat_get_remote_contact (tp_chat);
- if (remote_contact) {
- name = empathy_contact_get_name (remote_contact);
- }
- }
/* Update window title */
- n_chats = g_list_length (priv->chats);
if (n_chats == 1) {
gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
} else {
gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
g_free (title);
}
+
+ /* Update window icon */
if (priv->chats_new_msg) {
gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
EMPATHY_IMAGE_MESSAGE);
}
static void
-chat_window_update_chat (EmpathyChat *chat)
+chat_window_update_chat_tab (EmpathyChat *chat)
{
EmpathyChatWindow *window;
EmpathyChatWindowPriv *priv;
- EmpathyTpChat *tp_chat;
- EmpathyContact *remote_contact = NULL;
+ EmpathyContact *remote_contact;
const gchar *name;
const gchar *subject;
GtkWidget *widget;
const gchar *icon_name;
window = chat_window_find_chat (chat);
+ if (!window) {
+ return;
+ }
priv = GET_PRIV (window);
/* Get information */
- name = empathy_chat_get_name (chat);
+ name = chat_window_get_chat_name (chat);
subject = empathy_chat_get_subject (chat);
- tp_chat = empathy_chat_get_tp_chat (chat);
- if (tp_chat) {
- remote_contact = empathy_tp_chat_get_remote_contact (tp_chat);
- }
- if (!name && remote_contact) {
- name = empathy_contact_get_name (remote_contact);
- }
+ remote_contact = empathy_chat_get_remote_contact (chat);
+
+ empathy_debug (DEBUG_DOMAIN, "Updating chat tab, name=%s, subject=%s, "
+ "remote_contact=%p", name, subject, remote_contact);
/* Update tab image */
if (g_list_find (priv->chats_new_msg, chat)) {
g_string_append_printf (tooltip, "%s\n%s",
empathy_contact_get_id (remote_contact),
empathy_contact_get_status (remote_contact));
- } else {
+ }
+ else {
g_string_append (tooltip, name);
}
if (subject) {
widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
gtk_label_set_text (GTK_LABEL (widget), name);
- /* Update window title? */
+ /* Update the window if it's the current chat */
if (priv->current_chat == chat) {
- chat_window_update_title (window);
+ chat_window_update (window);
}
}
static void
-chat_window_remote_contact_notify_cb (EmpathyChat *chat)
+chat_window_chat_notify_cb (EmpathyChat *chat)
{
- EmpathyTpChat *tp_chat;
EmpathyContact *old_remote_contact;
EmpathyContact *remote_contact = NULL;
old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
- tp_chat = empathy_chat_get_tp_chat (chat);
- if (tp_chat) {
- remote_contact = empathy_tp_chat_get_remote_contact (tp_chat);
- }
+ remote_contact = empathy_chat_get_remote_contact (chat);
if (old_remote_contact != remote_contact) {
/* The remote-contact associated with the chat changed, we need
* window each time. */
if (remote_contact) {
g_signal_connect_swapped (remote_contact, "notify",
- G_CALLBACK (chat_window_update_chat),
+ G_CALLBACK (chat_window_update_chat_tab),
chat);
}
if (old_remote_contact) {
g_signal_handlers_disconnect_by_func (old_remote_contact,
- chat_window_update_chat,
+ chat_window_update_chat_tab,
chat);
}
g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
remote_contact);
-
- chat_window_update_chat (chat);
}
-}
-static void
-chat_window_weak_ref_cb (gpointer data,
- GObject *chat)
-{
- EmpathyTpChat *tp_chat;
- EmpathyContact *remote_contact;
-
- tp_chat = g_object_get_data (chat, "chat-window-tp-chat");
- if (tp_chat) {
- g_signal_handlers_disconnect_by_func (tp_chat,
- chat_window_remote_contact_notify_cb,
- chat);
- }
-
- remote_contact = g_object_get_data (chat, "chat-window-remote-contact");
- if (remote_contact) {
- g_signal_handlers_disconnect_by_func (remote_contact,
- chat_window_update_chat,
- chat);
- }
-}
-
-static void
-chat_window_chat_notify_cb (EmpathyChat *chat)
-{
- EmpathyTpChat *tp_chat;
- EmpathyTpChat *old_tp_chat;
-
- old_tp_chat = g_object_get_data (G_OBJECT (chat), "chat-window-tp-chat");
- tp_chat = empathy_chat_get_tp_chat (chat);
-
- if (old_tp_chat != tp_chat) {
- /* The TpChat associated with the chat has changed, we need to
- * keep track of it's remote-contact if there is one. */
- if (tp_chat) {
- g_signal_connect_swapped (tp_chat, "notify::remote-contact",
- G_CALLBACK (chat_window_remote_contact_notify_cb),
- chat);
- g_object_weak_ref (G_OBJECT (chat),
- chat_window_weak_ref_cb,
- NULL);
- }
- if (old_tp_chat) {
- g_signal_handlers_disconnect_by_func (old_tp_chat,
- chat_window_remote_contact_notify_cb,
- chat);
- }
- g_object_set_data (G_OBJECT (chat), "chat-window-tp-chat", tp_chat);
-
- /* This will call chat_window_update_chat() if the remote-contact
- * changed, so we don't have to call it again. That's why we
- * return here. */
- chat_window_remote_contact_notify_cb (chat);
- return;
- }
-
- chat_window_update_chat (chat);
+ chat_window_update_chat_tab (chat);
}
static void
priv->chats_composing = g_list_remove (priv->chats_composing, chat);
}
- chat_window_update_chat (chat);
+ chat_window_update_chat_tab (chat);
}
static void
priv = GET_PRIV (window);
has_focus = empathy_chat_window_has_focus (window);
-
+
if (has_focus && priv->current_chat == chat) {
return;
}
- needs_urgency = empathy_message_should_highlight (message);
+ if (empathy_chat_get_members_count (chat) > 2) {
+ needs_urgency = empathy_message_should_highlight (message);
+ } else {
+ needs_urgency = TRUE;
+ }
if (needs_urgency && !has_focus) {
chat_window_set_urgency_hint (window, TRUE);
if (!g_list_find (priv->chats_new_msg, chat)) {
priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
- chat_window_update_chat (chat);
+ chat_window_update_chat_tab (chat);
}
}
priv->current_chat = chat;
priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
- chat_window_update_menu (window);
- chat_window_update_title (window);
-}
-
-static void
-chat_window_page_reordered_cb (GtkNotebook *notebook,
- GtkWidget *widget,
- guint page_num,
- EmpathyChatWindow *window)
-{
- empathy_debug (DEBUG_DOMAIN, "Page reordered");
-
- chat_window_update_menu (window);
- chat_window_update_title (window);
+ chat_window_update_chat_tab (chat);
}
static void
/* Get list of chats up to date */
priv->chats = g_list_append (priv->chats, chat);
+
+ chat_window_update_chat_tab (chat);
}
static void
if (priv->chats == NULL) {
g_object_unref (window);
} else {
- chat_window_update_chat (chat);
+ chat_window_update (window);
}
}
chat_window_set_urgency_hint (window, FALSE);
/* Update the title, since we now mark all unread messages as read. */
- chat_window_update_chat (priv->current_chat);
+ chat_window_update_chat_tab (priv->current_chat);
return FALSE;
}
EmpathyChat *chat;
EmpathyChatWindow *old_window;
McAccount *account;
- const gchar *id = NULL;
+ const gchar *id;
gchar **strv;
- if (selection) {
- id = (const gchar*) selection->data;
- }
+ id = (const gchar*) selection->data;
empathy_debug (DEBUG_DOMAIN, "DND contact from roster with id:'%s'", id);
gtk_drag_finish (context, TRUE, FALSE, time);
}
else if (info == DND_DRAG_TYPE_TAB) {
- EmpathyChat *chat = NULL;
- EmpathyChatWindow *old_window;
- GtkWidget **child = NULL;
+ EmpathyChat **chat;
+ EmpathyChatWindow *old_window = NULL;
empathy_debug (DEBUG_DOMAIN, "DND tab");
- if (selection) {
- child = (void*) selection->data;
- }
-
- if (child) {
- chat = EMPATHY_CHAT (child);
- }
+ chat = (void*) selection->data;
+ old_window = chat_window_find_chat (*chat);
- old_window = chat_window_find_chat (chat);
if (old_window) {
EmpathyChatWindowPriv *priv;
"switch_page",
G_CALLBACK (chat_window_page_switched_cb),
window);
- g_signal_connect (priv->notebook,
- "page_reordered",
- G_CALLBACK (chat_window_page_reordered_cb),
- window);
g_signal_connect (priv->notebook,
"page_added",
G_CALLBACK (chat_window_page_added_cb),
child = GTK_WIDGET (chat);
label = chat_window_create_label (window, chat);
+ gtk_widget_show (child);
- g_signal_connect_swapped (chat, "notify::name",
- G_CALLBACK (chat_window_chat_notify_cb),
- window);
- g_signal_connect_swapped (chat, "notify::subject",
- G_CALLBACK (chat_window_chat_notify_cb),
- window);
- g_signal_connect_swapped (chat, "notify::tp-chat",
- G_CALLBACK (chat_window_chat_notify_cb),
- window);
+ g_signal_connect (chat, "notify::name",
+ G_CALLBACK (chat_window_chat_notify_cb),
+ NULL);
+ g_signal_connect (chat, "notify::subject",
+ G_CALLBACK (chat_window_chat_notify_cb),
+ NULL);
+ g_signal_connect (chat, "notify::remote-contact",
+ G_CALLBACK (chat_window_chat_notify_cb),
+ NULL);
chat_window_chat_notify_cb (chat);
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
TRUE, TRUE, GTK_PACK_START);
- gtk_widget_show (child);
empathy_debug (DEBUG_DOMAIN,
"Chat added (%d references)",
EmpathyChat *chat)
{
EmpathyChatWindowPriv *priv;
- gint position;
+ gint position;
+ EmpathyContact *remote_contact;
g_return_if_fail (window != NULL);
g_return_if_fail (EMPATHY_IS_CHAT (chat));
priv = GET_PRIV (window);
+ g_signal_handlers_disconnect_by_func (chat,
+ chat_window_chat_notify_cb,
+ NULL);
+ remote_contact = g_object_get_data (G_OBJECT (chat),
+ "chat-window-remote-contact");
+ if (remote_contact) {
+ g_signal_handlers_disconnect_by_func (remote_contact,
+ chat_window_update_chat_tab,
+ chat);
+ }
+
position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
GTK_WIDGET (chat));
gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
- g_signal_handlers_disconnect_by_func (chat,
- chat_window_chat_notify_cb,
- window);
-
empathy_debug (DEBUG_DOMAIN,
"Chat removed (%d references)",
G_OBJECT (chat)->ref_count - 1);