]> git.0d.be Git - empathy.git/blobdiff - src/empathy-chat-window.c
Merge branch 'debug-window'
[empathy.git] / src / empathy-chat-window.c
index f4315f5fa57582ee887f0079dd9cdb7cf17b45fa..5f81ac167b5aade48d4183c40a141192f6ae61e8 100644 (file)
@@ -35,7 +35,6 @@
 #include <libnotify/notification.h>
 
 #include <telepathy-glib/util.h>
-#include <libmissioncontrol/mission-control.h>
 
 #include <libempathy/empathy-contact.h>
 #include <libempathy/empathy-message.h>
@@ -176,7 +175,7 @@ chat_tab_style_set_cb (GtkWidget *hbox,
                "chat-window-tab-close-button");
        context = gtk_widget_get_pango_context (hbox);
 
-       metrics = pango_context_get_metrics (context, hbox->style->font_desc,
+       metrics = pango_context_get_metrics (context, gtk_widget_get_style (hbox)->font_desc,
                pango_context_get_language (context));
        char_width = pango_font_metrics_get_approximate_char_width (metrics);
        pango_font_metrics_unref (metrics);
@@ -557,12 +556,15 @@ chat_window_conv_activate_cb (GtkAction         *action,
        if (is_room) {
                const gchar *room;
                EmpathyAccount   *account;
-               gboolean     found;
+               gboolean     found = FALSE;
+               EmpathyChatroom *chatroom;
 
                room = empathy_chat_get_id (priv->current_chat);
                account = empathy_chat_get_account (priv->current_chat);
-               found = empathy_chatroom_manager_find (priv->chatroom_manager,
-                                                      account, room) != NULL;
+               chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
+                                                      account, room);
+               if (chatroom != NULL)
+                       found = empathy_chatroom_is_favorite (chatroom);
 
                DEBUG ("This room %s favorite", found ? "is" : "is not");
                gtk_toggle_action_set_active (
@@ -613,19 +615,16 @@ chat_window_favorite_toggled_cb (GtkToggleAction   *toggle_action,
        chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
                                                  account, room);
 
-       if (active && !chatroom) {
+       if (chatroom == NULL) {
                const gchar *name;
 
                name = empathy_chat_get_name (priv->current_chat);
                chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
                empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
                g_object_unref (chatroom);
-               return;
-       }
+  }
 
-       if (!active && chatroom) {
-               empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
-       }
+       empathy_chatroom_set_favorite (chatroom, active);
 }
 
 static void
@@ -851,7 +850,7 @@ chat_window_help_contents_activate_cb (GtkAction         *action,
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
 
-       empathy_url_show (priv->dialog, "ghelp:empathy?chat");
+       empathy_url_show (priv->dialog, "ghelp:empathy");
 }
 
 static void
@@ -946,7 +945,6 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
        char *escaped;
        const char *body;
        GdkPixbuf *pixbuf;
-       NotificationData *cb_data;
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
        gboolean res;
 
@@ -960,40 +958,57 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
                }
        }
 
-       cb_data = g_slice_new0 (NotificationData);
-       cb_data->chat = g_object_ref (chat);
-       cb_data->window = window;
-
        sender = empathy_message_get_sender (message);
        header = empathy_contact_get_name (sender);
        body = empathy_message_get_body (message);
        escaped = g_markup_escape_text (body, -1);
 
-       pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
-
        if (priv->notification != NULL) {
                notify_notification_update (priv->notification,
                                            header, escaped, NULL);
-               /* if icon doesn't exist libnotify will crash */
-               if (pixbuf != NULL)
-                       notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
        } else {
+               NotificationData *cb_data = cb_data = g_slice_new0 (NotificationData);
+
+               cb_data->chat = g_object_ref (chat);
+               cb_data->window = window;
+
                priv->notification = notify_notification_new (header, escaped, NULL, NULL);
                notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
-               /* if icon doesn't exist libnotify will crash */
-               if (pixbuf != NULL)
-                       notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
 
                g_signal_connect (priv->notification, "closed",
                                  G_CALLBACK (chat_window_notification_closed_cb), cb_data);
        }
 
+       pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
+
+       if (pixbuf != NULL) {
+               notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+               g_object_unref (pixbuf);
+       }
+
        notify_notification_show (priv->notification, NULL);
 
-       g_object_unref (pixbuf);
        g_free (escaped);
 }
 
+static void
+chat_window_set_highlight_room_tab_label (EmpathyChat *chat)
+{
+       gchar *markup;
+       GtkWidget *widget;
+
+       if (!empathy_chat_is_room (chat))
+               return;
+
+       markup = g_markup_printf_escaped (
+               "<span color=\"red\" weight=\"bold\">%s</span>",
+               empathy_chat_get_name (chat));
+
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
+       gtk_label_set_markup (GTK_LABEL (widget), markup);
+       g_free (markup);
+}
+
 static void
 chat_window_new_message_cb (EmpathyChat       *chat,
                            EmpathyMessage    *message,
@@ -1026,6 +1041,11 @@ chat_window_new_message_cb (EmpathyChat       *chat,
                return;
        }
 
+       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_tab (chat);
+       }
+
        /* If empathy_chat_is_room () returns TRUE, that means it's a named MUC.
         * If empathy_chat_get_remote_contact () returns NULL, that means it's
         * an unamed MUC (msn-like).
@@ -1039,18 +1059,15 @@ chat_window_new_message_cb (EmpathyChat       *chat,
        }
 
        if (needs_urgency) {
-               if (!has_focus)
+               if (!has_focus) {
                        chat_window_set_urgency_hint (window, TRUE);
+                       chat_window_set_highlight_room_tab_label (chat);
+               }
 
                empathy_sound_play (GTK_WIDGET (priv->dialog),
                    EMPATHY_SOUND_MESSAGE_INCOMING);
                chat_window_show_or_update_notification (window, message, chat);
        }
-
-       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_tab (chat);
-       }
 }
 
 static GtkNotebook *
@@ -1242,7 +1259,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
                const gchar           *account_id;
                const gchar           *contact_id;
 
-               id = (const gchar*) selection->data;
+               id = (const gchar*) gtk_selection_data_get_data (selection);
                account_manager = empathy_account_manager_dup_singleton ();
 
                DEBUG ("DND contact from roster with id:'%s'", id);
@@ -1250,7 +1267,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
                strv = g_strsplit (id, "/", 2);
                account_id = strv[0];
                contact_id = strv[1];
-               account = empathy_account_manager_lookup (account_manager, account_id);
+               account = empathy_account_manager_get_account (account_manager, account_id);
                chat = empathy_chat_window_find_chat (account, contact_id);
 
                if (!chat) {
@@ -1263,11 +1280,9 @@ chat_window_drag_data_received (GtkWidget        *widget,
                                        connection, contact_id, NULL, NULL);
                        }
 
-                       g_object_unref (account);
                        g_strfreev (strv);
                        return;
                }
-               g_object_unref (account);
                g_object_unref (account_manager);
                g_strfreev (strv);
 
@@ -1299,7 +1314,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
 
                DEBUG ("DND tab");
 
-               chat = (void *) selection->data;
+               chat = (void *) gtk_selection_data_get_data (selection);
                old_window = chat_window_find_chat (*chat);
 
                if (old_window) {
@@ -1759,7 +1774,7 @@ empathy_chat_window_find_chat (EmpathyAccount   *account,
 
                        chat = ll->data;
 
-                       if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
+                       if (account == empathy_chat_get_account (chat) &&
                            !tp_strdiff (id, empathy_chat_get_id (chat))) {
                                return chat;
                        }