]> git.0d.be Git - empathy.git/commitdiff
Add a menu item in chat window to set the room as favorite
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 29 Aug 2008 16:04:51 +0000 (16:04 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 29 Aug 2008 16:04:51 +0000 (16:04 +0000)
svn path=/trunk/; revision=1401

libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-chat.h
src/empathy-chat-window.c
src/empathy-chat-window.glade

index 48aa793d5f8f1bfbe09e412a4d7b4ead5f5b1b17..1dd3908b4047092dd3a110b4d500c8349c1d1b4c 100644 (file)
@@ -1793,3 +1793,13 @@ empathy_chat_correct_word (EmpathyChat  *chat,
                                -1);
 }
 
+gboolean
+empathy_chat_is_room (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
+
+       return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
+}
+
index b7b6968f911ec7c6e6536fb3b725bc11832c3bbc..6b7fcf26e1d0a13a80a0e6a2900e1d0267121a8b 100644 (file)
@@ -82,7 +82,7 @@ void               empathy_chat_correct_word         (EmpathyChat   *chat,
                                                      GtkTextIter   *start,
                                                      GtkTextIter   *end,
                                                      const gchar   *new_word);
-
+gboolean           empathy_chat_is_room              (EmpathyChat   *chat);
 G_END_DECLS
 
 #endif /* __EMPATHY_CHAT_H__ */
index 3780629fcc2c796c04c99176569764a15f36faaf..73c41a9f0222298b07b1bbb2577d3d298ea8785a 100644 (file)
@@ -41,6 +41,7 @@
 #include <libempathy/empathy-contact.h>
 #include <libempathy/empathy-message.h>
 #include <libempathy/empathy-dispatcher.h>
+#include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-utils.h>
 
 #include <libempathy-gtk/empathy-images.h>
@@ -65,6 +66,7 @@ typedef struct {
        gboolean     page_added;
        gboolean     dnd_same_window;
        guint        save_geometry_id;
+       EmpathyChatroomManager *chatroom_manager;
        GtkWidget   *dialog;
        GtkWidget   *notebook;
 
@@ -72,6 +74,7 @@ typedef struct {
        GtkWidget   *menu_conv_clear;
        GtkWidget   *menu_conv_insert_smiley;
        GtkWidget   *menu_conv_contact;
+       GtkWidget   *menu_conv_favorite;
        GtkWidget   *menu_conv_close;
 
        GtkWidget   *menu_edit_cut;
@@ -474,6 +477,7 @@ chat_window_conv_activate_cb (GtkWidget         *menuitem,
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
        GtkWidget             *submenu = NULL;
 
+       /* Contact submenu */
        submenu = empathy_chat_get_contact_menu (priv->current_chat);
        if (submenu) {
                gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_contact),
@@ -483,6 +487,25 @@ chat_window_conv_activate_cb (GtkWidget         *menuitem,
        } else {
                gtk_widget_hide (priv->menu_conv_contact);
        }
+
+       /* Favorite room menu */
+       if (empathy_chat_is_room (priv->current_chat)) {
+               const gchar *room;
+               McAccount   *account;
+               gboolean     found;
+
+               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;
+
+               DEBUG ("This room %s favorite", found ? "is" : "is not");
+               gtk_check_menu_item_set_active (
+                       GTK_CHECK_MENU_ITEM (priv->menu_conv_favorite), found);
+               gtk_widget_show (priv->menu_conv_favorite);
+       } else {
+               gtk_widget_hide (priv->menu_conv_favorite);
+       }
 }
 
 static void
@@ -494,6 +517,30 @@ chat_window_clear_activate_cb (GtkWidget        *menuitem,
        empathy_chat_clear (priv->current_chat);
 }
 
+static void
+chat_window_favorite_activate_cb (GtkWidget         *menuitem,
+                                 EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       McAccount             *account;
+       const gchar           *room;
+       const gchar           *name;
+       EmpathyChatroom       *chatroom;
+
+       account = empathy_chat_get_account (priv->current_chat);
+       room = empathy_chat_get_id (priv->current_chat);
+       name = empathy_chat_get_name (priv->current_chat);
+       chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
+
+       if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (priv->menu_conv_favorite))) {
+               empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
+       } else {
+               empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
+       }
+
+       g_object_unref (chatroom);
+}
+
 static const gchar *
 chat_get_window_id_for_geometry (EmpathyChat *chat)
 {
@@ -1069,6 +1116,7 @@ chat_window_finalize (GObject *object)
 
        DEBUG ("Finalized: %p", object);
 
+       g_object_unref (priv->chatroom_manager);
        if (priv->save_geometry_id != 0) {
                g_source_remove (priv->save_geometry_id);
        }
@@ -1126,6 +1174,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                       "menu_conv_clear", &priv->menu_conv_clear,
                                       "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
                                       "menu_conv_contact", &priv->menu_conv_contact,
+                                      "menu_conv_favorite", &priv->menu_conv_favorite,
                                       "menu_conv_close", &priv->menu_conv_close,
                                       "menu_edit_cut", &priv->menu_edit_cut,
                                       "menu_edit_copy", &priv->menu_edit_copy,
@@ -1145,6 +1194,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                              "chat_window", "configure-event", chat_window_configure_event_cb,
                              "menu_conv", "activate", chat_window_conv_activate_cb,
                              "menu_conv_clear", "activate", chat_window_clear_activate_cb,
+                             "menu_conv_favorite", "activate", chat_window_favorite_activate_cb,
                              "menu_conv_close", "activate", chat_window_close_activate_cb,
                              "menu_edit", "activate", chat_window_edit_activate_cb,
                              "menu_edit_cut", "activate", chat_window_cut_activate_cb,
@@ -1159,6 +1209,8 @@ empathy_chat_window_init (EmpathyChatWindow *window)
 
        g_object_unref (glade);
 
+       priv->chatroom_manager = empathy_chatroom_manager_new ();
+
        priv->notebook = gtk_notebook_new ();
        gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow"); 
        gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
index 2b2e396d4496017604db501e09209d7be9d04ca4..874fe3f4f60acf80e6e15aa2da60ebce0cde54d6 100644 (file)
                         <property name="use_underline">True</property>
                       </widget>
                     </child>
+                    <child>
+                      <widget class="GtkCheckMenuItem" id="menu_conv_favorite">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Favorite Chatroom</property>
+                        <property name="use_underline">True</property>
+                      </widget>
+                    </child>
                     <child>
                       <widget class="GtkSeparatorMenuItem" id="separator7">
                         <property name="visible">True</property>