+/* Matches GtkRadioAction values set in empathy-main-window.ui */
+#define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
+#define CONTACT_LIST_NORMAL_SIZE 1
+#define CONTACT_LIST_COMPACT_SIZE 2
+
+static void
+main_window_view_contacts_list_size_cb (GtkRadioAction *action,
+ GtkRadioAction *current,
+ EmpathyMainWindow *window)
+{
+ gint value;
+
+ value = gtk_radio_action_get_current_value (action);
+
+ empathy_conf_set_bool (empathy_conf_get (),
+ EMPATHY_PREFS_UI_SHOW_AVATARS,
+ value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
+ empathy_conf_set_bool (empathy_conf_get (),
+ EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
+ value == CONTACT_LIST_COMPACT_SIZE);
+
+ empathy_contact_list_store_set_show_avatars (window->list_store,
+ value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
+ empathy_contact_list_store_set_is_compact (window->list_store,
+ value == CONTACT_LIST_COMPACT_SIZE);
+}
+
+static void
+main_window_notify_contact_list_size_cb (EmpathyConf *conf,
+ const gchar *key,
+ EmpathyMainWindow *window)
+{
+ gboolean show_avatars;
+ gboolean compact_contact_list;
+ gint value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
+
+ if (empathy_conf_get_bool (conf,
+ EMPATHY_PREFS_UI_SHOW_AVATARS,
+ &show_avatars)
+ && empathy_conf_get_bool (conf,
+ EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
+ &compact_contact_list)) {
+ if (compact_contact_list) {
+ value = CONTACT_LIST_COMPACT_SIZE;
+ } else if (show_avatars) {
+ value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
+ } else {
+ value = CONTACT_LIST_NORMAL_SIZE;
+ }
+ }
+ /* By changing the value of the GtkRadioAction,
+ it emits a signal that calls main_window_view_contacts_list_size_cb
+ which updates the contacts list */
+ gtk_radio_action_set_current_value (window->normal_with_avatars, value);
+}
+
+static void
+main_window_view_show_map_cb (GtkCheckMenuItem *item,
+ EmpathyMainWindow *window)
+{
+#if HAVE_LIBCHAMPLAIN
+ empathy_map_view_show ();
+#endif
+}
+
+static void
+main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
+{
+ EmpathyAccount *account;
+ TpConnection *connection;
+ const gchar *room;
+
+ account = empathy_chatroom_get_account (chatroom);
+ connection = empathy_account_get_connection (account);
+ room = empathy_chatroom_get_room (chatroom);
+
+ if (connection != NULL) {
+ DEBUG ("Requesting channel for '%s'", room);
+ empathy_dispatcher_join_muc (connection, room, NULL, NULL);
+ }
+}
+
+static void
+main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
+ EmpathyChatroom *chatroom)
+{
+ main_window_favorite_chatroom_join (chatroom);
+}
+
+static void
+main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
+ EmpathyChatroom *chatroom)
+{
+ GtkWidget *menu_item;
+ const gchar *name;
+
+ if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
+ return;
+ }
+
+ name = empathy_chatroom_get_name (chatroom);
+ menu_item = gtk_menu_item_new_with_label (name);
+
+ g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
+ g_signal_connect (menu_item, "activate",
+ G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
+ chatroom);
+
+ gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
+ menu_item, 4);
+
+ gtk_widget_show (menu_item);
+}
+
+static void
+main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
+ EmpathyChatroom *chatroom,
+ EmpathyMainWindow *window)
+{
+ main_window_favorite_chatroom_menu_add (window, chatroom);
+ gtk_widget_show (window->room_separator);
+ gtk_action_set_sensitive (window->room_join_favorites, TRUE);
+}
+
+static void
+main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
+ EmpathyChatroom *chatroom,
+ EmpathyMainWindow *window)
+{
+ GtkWidget *menu_item;
+ GList *chatrooms;
+
+ menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
+ g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
+ gtk_widget_destroy (menu_item);
+
+ chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
+ if (chatrooms) {
+ gtk_widget_show (window->room_separator);
+ } else {
+ gtk_widget_hide (window->room_separator);
+ }
+
+ gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
+ g_list_free (chatrooms);
+}
+
+static void
+main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
+{
+ GList *chatrooms, *l;
+ GtkWidget *room;
+
+ window->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
+ chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
+ room = gtk_ui_manager_get_widget (window->ui_manager,
+ "/menubar/room");
+ window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
+ window->room_separator = gtk_ui_manager_get_widget (window->ui_manager,
+ "/menubar/room/room_separator");
+
+ for (l = chatrooms; l; l = l->next) {
+ main_window_favorite_chatroom_menu_add (window, l->data);
+ }
+
+ if (!chatrooms) {
+ gtk_widget_hide (window->room_separator);
+ }
+
+ gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
+
+ g_signal_connect (window->chatroom_manager, "chatroom-added",
+ G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
+ window);
+ g_signal_connect (window->chatroom_manager, "chatroom-removed",
+ G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
+ window);
+
+ g_list_free (chatrooms);
+}
+
+static void
+main_window_room_join_new_cb (GtkAction *action,
+ EmpathyMainWindow *window)
+{
+ empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
+}
+
+static void
+main_window_room_join_favorites_cb (GtkAction *action,
+ EmpathyMainWindow *window)
+{
+ GList *chatrooms, *l;
+
+ chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
+ for (l = chatrooms; l; l = l->next) {
+ main_window_favorite_chatroom_join (l->data);
+ }
+ g_list_free (chatrooms);
+}
+
+static void
+main_window_room_manage_favorites_cb (GtkAction *action,
+ EmpathyMainWindow *window)
+{
+ empathy_chatrooms_window_show (GTK_WINDOW (window->window));
+}
+
+static void
+main_window_edit_cb (GtkAction *action,
+ EmpathyMainWindow *window)
+{
+ GtkWidget *submenu;
+
+ /* FIXME: It should use the UIManager to merge the contact/group submenu */
+ submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
+ if (submenu) {
+ GtkMenuItem *item;
+ GtkWidget *label;
+
+ item = GTK_MENU_ITEM (window->edit_context);