1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2002-2007 Imendio AB
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <glade/glade.h>
29 #include <glib/gi18n.h>
31 #include <libempathy/empathy-contact.h>
32 #include <libempathy/empathy-utils.h>
33 #include <libempathy/empathy-chatroom-manager.h>
34 #include <libempathy/empathy-chatroom.h>
35 #include <libempathy/empathy-contact-list.h>
36 #include <libempathy/empathy-contact-manager.h>
37 #include <libempathy/empathy-contact-factory.h>
38 #include <libempathy/empathy-status-presets.h>
40 #include <libempathy-gtk/empathy-contact-dialogs.h>
41 #include <libempathy-gtk/empathy-contact-list-store.h>
42 #include <libempathy-gtk/empathy-contact-list-view.h>
43 #include <libempathy-gtk/empathy-presence-chooser.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include <libempathy-gtk/empathy-geometry.h>
46 #include <libempathy-gtk/empathy-conf.h>
47 #include <libempathy-gtk/empathy-log-window.h>
48 #include <libempathy-gtk/empathy-new-message-dialog.h>
49 #include <libempathy-gtk/empathy-gtk-enum-types.h>
51 #include "empathy-accounts-dialog.h"
52 #include "empathy-main-window.h"
53 #include "ephy-spinner.h"
54 #include "empathy-preferences.h"
55 #include "empathy-about-dialog.h"
56 #include "empathy-new-chatroom-dialog.h"
57 #include "empathy-chatrooms-window.h"
58 #include "empathy-event-manager.h"
60 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
61 #include <libempathy/empathy-debug.h>
63 /* Flashing delay for icons (milliseconds). */
64 #define FLASH_TIMEOUT 500
66 /* Minimum width of roster window if something goes wrong. */
69 /* Accels (menu shortcuts) can be configured and saved */
70 #define ACCELS_FILENAME "accels.txt"
72 /* Name in the geometry file */
73 #define GEOMETRY_NAME "main-window"
76 EmpathyContactListView *list_view;
77 EmpathyContactListStore *list_store;
79 EmpathyChatroomManager *chatroom_manager;
80 EmpathyEventManager *event_manager;
81 guint flash_timeout_id;
88 GtkWidget *presence_toolbar;
89 GtkWidget *presence_chooser;
90 GtkWidget *errors_vbox;
95 GtkWidget *room_join_favorites;
96 GtkWidget *edit_context;
97 GtkWidget *edit_context_separator;
99 guint size_timeout_id;
102 /* Widgets that are enabled when there is... */
103 GList *widgets_connected; /* ... connected accounts */
104 GList *widgets_disconnected; /* ... disconnected accounts */
107 static void main_window_destroy_cb (GtkWidget *widget,
108 EmpathyMainWindow *window);
109 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
110 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
111 EmpathyChatroom *chatroom,
112 EmpathyMainWindow *window);
113 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
114 EmpathyChatroom *chatroom,
115 EmpathyMainWindow *window);
116 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
117 EmpathyChatroom *chatroom);
118 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
119 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
120 EmpathyChatroom *chatroom);
121 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
122 static void main_window_chat_quit_cb (GtkWidget *widget,
123 EmpathyMainWindow *window);
124 static void main_window_chat_new_message_cb (GtkWidget *widget,
125 EmpathyMainWindow *window);
126 static void main_window_chat_history_cb (GtkWidget *widget,
127 EmpathyMainWindow *window);
128 static void main_window_room_join_new_cb (GtkWidget *widget,
129 EmpathyMainWindow *window);
130 static void main_window_room_join_favorites_cb (GtkWidget *widget,
131 EmpathyMainWindow *window);
132 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
133 EmpathyMainWindow *window);
134 static void main_window_chat_add_contact_cb (GtkWidget *widget,
135 EmpathyMainWindow *window);
136 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
137 EmpathyMainWindow *window);
138 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
139 GdkEventButton *event,
140 EmpathyMainWindow *window);
141 static void main_window_edit_accounts_cb (GtkWidget *widget,
142 EmpathyMainWindow *window);
143 static void main_window_edit_personal_information_cb (GtkWidget *widget,
144 EmpathyMainWindow *window);
145 static void main_window_edit_preferences_cb (GtkWidget *widget,
146 EmpathyMainWindow *window);
147 static void main_window_help_about_cb (GtkWidget *widget,
148 EmpathyMainWindow *window);
149 static void main_window_help_contents_cb (GtkWidget *widget,
150 EmpathyMainWindow *window);
151 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
152 GdkEventButton *event,
153 EmpathyMainWindow *window);
154 static void main_window_status_changed_cb (MissionControl *mc,
155 TpConnectionStatus status,
157 TpConnectionStatusReason reason,
158 const gchar *unique_name,
159 EmpathyMainWindow *window);
160 static void main_window_update_status (EmpathyMainWindow *window);
161 static void main_window_accels_load (void);
162 static void main_window_accels_save (void);
163 static void main_window_connection_items_setup (EmpathyMainWindow *window,
165 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
166 static gboolean main_window_configure_event_cb (GtkWidget *widget,
167 GdkEventConfigure *event,
168 EmpathyMainWindow *window);
169 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
171 gpointer check_menu_item);
172 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
174 EmpathyMainWindow *window);
175 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
177 EmpathyMainWindow *window);
178 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
180 EmpathyMainWindow *window);
183 main_window_flash_stop (EmpathyMainWindow *window)
185 if (window->flash_timeout_id == 0) {
189 DEBUG ("Stop flashing");
190 g_source_remove (window->flash_timeout_id);
191 window->flash_timeout_id = 0;
192 window->flash_on = FALSE;
201 main_window_flash_foreach (GtkTreeModel *model,
206 FlashForeachData *data = (FlashForeachData*) user_data;
207 EmpathyContact *contact;
208 const gchar *icon_name;
209 GtkTreePath *parent_path = NULL;
210 GtkTreeIter parent_iter;
212 /* To be used with gtk_tree_model_foreach, update the status icon
213 * of the contact to show the event icon (on=TRUE) or the presence
215 gtk_tree_model_get (model, iter,
216 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
219 if (contact != data->event->contact) {
221 g_object_unref (contact);
227 icon_name = data->event->icon_name;
229 icon_name = empathy_icon_name_for_contact (contact);
232 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
233 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, icon_name,
236 /* To make sure the parent is shown correctly, we emit
237 * the row-changed signal on the parent so it prompts
238 * it to be refreshed by the filter func.
240 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
241 parent_path = gtk_tree_model_get_path (model, &parent_iter);
244 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
245 gtk_tree_path_free (parent_path);
248 g_object_unref (contact);
254 main_window_flash_cb (EmpathyMainWindow *window)
258 gboolean found_event = FALSE;
259 FlashForeachData data;
261 window->flash_on = !window->flash_on;
262 data.on = window->flash_on;
263 model = GTK_TREE_MODEL (window->list_store);
265 events = empathy_event_manager_get_events (window->event_manager);
266 for (l = events; l; l = l->next) {
267 data.event = l->data;
268 if (!data.event->contact) {
273 gtk_tree_model_foreach (model,
274 main_window_flash_foreach,
279 main_window_flash_stop (window);
286 main_window_flash_start (EmpathyMainWindow *window)
289 if (window->flash_timeout_id != 0) {
293 DEBUG ("Start flashing");
294 window->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
295 (GSourceFunc) main_window_flash_cb,
297 main_window_flash_cb (window);
301 main_window_event_added_cb (EmpathyEventManager *manager,
303 EmpathyMainWindow *window)
305 if (event->contact) {
306 main_window_flash_start (window);
311 main_window_event_removed_cb (EmpathyEventManager *manager,
313 EmpathyMainWindow *window)
315 FlashForeachData data;
317 if (!event->contact) {
323 gtk_tree_model_foreach (GTK_TREE_MODEL (window->list_store),
324 main_window_flash_foreach,
329 main_window_row_activated_cb (EmpathyContactListView *view,
331 GtkTreeViewColumn *col,
332 EmpathyMainWindow *window)
334 EmpathyContact *contact;
339 model = GTK_TREE_MODEL (window->list_store);
340 gtk_tree_model_get_iter (model, &iter, path);
341 gtk_tree_model_get (model, &iter,
342 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
349 /* If the contact has an event activate it, otherwise the
350 * default handler of row-activated will be called. */
351 events = empathy_event_manager_get_events (window->event_manager);
352 for (l = events; l; l = l->next) {
353 EmpathyEvent *event = l->data;
355 if (event->contact == contact) {
356 DEBUG ("Activate event");
357 empathy_event_activate (event);
359 /* We don't want the default handler of this signal
360 * (e.g. open a chat) */
361 g_signal_stop_emission_by_name (view, "row-activated");
366 g_object_unref (contact);
370 empathy_main_window_show (void)
372 static EmpathyMainWindow *window = NULL;
373 EmpathyContactList *list_iface;
377 GtkWidget *show_offline_widget;
380 gboolean show_offline;
381 gboolean show_avatars;
382 gboolean compact_contact_list;
388 empathy_window_present (GTK_WINDOW (window->window), TRUE);
389 return window->window;
392 window = g_new0 (EmpathyMainWindow, 1);
394 /* Set up interface */
395 filename = empathy_file_lookup ("empathy-main-window.glade", "src");
396 glade = empathy_glade_get_file (filename,
399 "main_window", &window->window,
400 "main_vbox", &window->main_vbox,
401 "errors_vbox", &window->errors_vbox,
402 "chat_show_offline", &show_offline_widget,
403 "room", &window->room,
404 "room_sep", &window->room_sep,
405 "room_join_favorites", &window->room_join_favorites,
406 "edit_context", &window->edit_context,
407 "edit_context_separator", &window->edit_context_separator,
408 "presence_toolbar", &window->presence_toolbar,
409 "roster_scrolledwindow", &sw,
413 empathy_glade_connect (glade,
415 "main_window", "destroy", main_window_destroy_cb,
416 "main_window", "configure_event", main_window_configure_event_cb,
417 "chat_quit", "activate", main_window_chat_quit_cb,
418 "chat_new_message", "activate", main_window_chat_new_message_cb,
419 "chat_history", "activate", main_window_chat_history_cb,
420 "room_join_new", "activate", main_window_room_join_new_cb,
421 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
422 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
423 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
424 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
425 "edit", "button-press-event", main_window_edit_button_press_event_cb,
426 "edit_accounts", "activate", main_window_edit_accounts_cb,
427 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
428 "edit_preferences", "activate", main_window_edit_preferences_cb,
429 "help_about", "activate", main_window_help_about_cb,
430 "help_contents", "activate", main_window_help_contents_cb,
433 /* Set up connection related widgets. */
434 main_window_connection_items_setup (window, glade);
435 g_object_unref (glade);
437 window->mc = empathy_mission_control_new ();
438 window->token = empathy_connect_to_account_status_changed (window->mc,
439 G_CALLBACK (main_window_status_changed_cb),
442 window->errors = g_hash_table_new_full (empathy_account_hash,
443 empathy_account_equal,
448 main_window_favorite_chatroom_menu_setup (window);
450 gtk_widget_hide (window->edit_context);
451 gtk_widget_hide (window->edit_context_separator);
453 /* Set up presence chooser */
454 window->presence_chooser = empathy_presence_chooser_new ();
455 gtk_widget_show (window->presence_chooser);
456 item = gtk_tool_item_new ();
457 gtk_widget_show (GTK_WIDGET (item));
458 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
459 gtk_tool_item_set_is_important (item, TRUE);
460 gtk_tool_item_set_expand (item, TRUE);
461 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
463 /* Set up the throbber */
464 ebox = gtk_event_box_new ();
465 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
466 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
467 g_signal_connect (ebox,
468 "button-press-event",
469 G_CALLBACK (main_window_throbber_button_press_event_cb),
471 gtk_widget_show (ebox);
473 window->throbber = ephy_spinner_new ();
474 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
475 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
476 gtk_widget_show (window->throbber);
478 item = gtk_tool_item_new ();
479 gtk_container_add (GTK_CONTAINER (item), ebox);
480 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
481 gtk_widget_show (GTK_WIDGET (item));
483 /* Set up contact list. */
484 empathy_status_presets_get_all ();
486 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
487 window->list_store = empathy_contact_list_store_new (list_iface);
488 window->list_view = empathy_contact_list_view_new (window->list_store,
489 EMPATHY_CONTACT_LIST_FEATURE_ALL,
490 EMPATHY_CONTACT_FEATURE_ALL);
491 g_object_unref (list_iface);
493 gtk_widget_show (GTK_WIDGET (window->list_view));
494 gtk_container_add (GTK_CONTAINER (sw),
495 GTK_WIDGET (window->list_view));
496 g_signal_connect (window->list_view, "row-activated",
497 G_CALLBACK (main_window_row_activated_cb),
500 /* Load user-defined accelerators. */
501 main_window_accels_load ();
503 /* Set window size. */
504 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
506 if (w >= 1 && h >= 1) {
507 /* Use the defaults from the glade file if we
508 * don't have good w, h geometry.
510 DEBUG ("Configuring window default size w:%d, h:%d", w, h);
511 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
514 if (x >= 0 && y >= 0) {
515 /* Let the window manager position it if we
516 * don't have good x, y coordinates.
518 DEBUG ("Configuring window default position x:%d, y:%d", x, y);
519 gtk_window_move (GTK_WINDOW (window->window), x, y);
522 /* Enable event handling */
523 window->event_manager = empathy_event_manager_new ();
524 g_signal_connect (window->event_manager, "event-added",
525 G_CALLBACK (main_window_event_added_cb),
527 g_signal_connect (window->event_manager, "event-removed",
528 G_CALLBACK (main_window_event_removed_cb),
531 l = empathy_event_manager_get_events (window->event_manager);
533 main_window_event_added_cb (window->event_manager,
538 conf = empathy_conf_get ();
541 empathy_conf_get_bool (conf,
542 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
544 empathy_conf_notify_add (conf,
545 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
546 main_window_notify_show_offline_cb,
547 show_offline_widget);
549 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
553 empathy_conf_get_bool (conf,
554 EMPATHY_PREFS_UI_SHOW_AVATARS,
556 empathy_conf_notify_add (conf,
557 EMPATHY_PREFS_UI_SHOW_AVATARS,
558 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
560 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
563 empathy_conf_get_bool (conf,
564 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
565 &compact_contact_list);
566 empathy_conf_notify_add (conf,
567 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
568 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
570 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
573 empathy_conf_notify_add (conf,
574 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
575 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
577 main_window_notify_sort_criterium_cb (conf,
578 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
581 main_window_update_status (window);
583 return window->window;
587 main_window_destroy_cb (GtkWidget *widget,
588 EmpathyMainWindow *window)
590 /* Save user-defined accelerators. */
591 main_window_accels_save ();
593 empathy_disconnect_account_status_changed (window->token);
595 if (window->size_timeout_id) {
596 g_source_remove (window->size_timeout_id);
599 g_list_free (window->widgets_connected);
600 g_list_free (window->widgets_disconnected);
602 g_object_unref (window->mc);
603 g_object_unref (window->list_store);
604 g_hash_table_destroy (window->errors);
606 g_signal_handlers_disconnect_by_func (window->event_manager,
607 main_window_event_added_cb,
609 g_signal_handlers_disconnect_by_func (window->event_manager,
610 main_window_event_removed_cb,
612 g_object_unref (window->event_manager);
618 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
620 GList *chatrooms, *l;
622 window->chatroom_manager = empathy_chatroom_manager_new ();
623 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
624 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
626 for (l = chatrooms; l; l = l->next) {
627 main_window_favorite_chatroom_menu_add (window, l->data);
631 gtk_widget_hide (window->room_sep);
634 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
636 g_signal_connect (window->chatroom_manager, "chatroom-added",
637 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
639 g_signal_connect (window->chatroom_manager, "chatroom-removed",
640 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
643 g_list_free (chatrooms);
647 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
648 EmpathyChatroom *chatroom,
649 EmpathyMainWindow *window)
651 main_window_favorite_chatroom_menu_add (window, chatroom);
652 gtk_widget_show (window->room_sep);
653 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
657 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
658 EmpathyChatroom *chatroom,
659 EmpathyMainWindow *window)
661 GtkWidget *menu_item;
663 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
665 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
666 gtk_widget_destroy (menu_item);
668 main_window_favorite_chatroom_menu_update (window);
672 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
673 EmpathyChatroom *chatroom)
675 main_window_favorite_chatroom_join (chatroom);
679 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
683 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
686 gtk_widget_show (window->room_sep);
688 gtk_widget_hide (window->room_sep);
691 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
692 g_list_free (chatrooms);
696 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
697 EmpathyChatroom *chatroom)
699 GtkWidget *menu_item;
702 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
706 name = empathy_chatroom_get_name (chatroom);
707 menu_item = gtk_menu_item_new_with_label (name);
709 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
710 g_signal_connect (menu_item, "activate",
711 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
714 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
717 gtk_widget_show (menu_item);
721 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
725 TpConnection *connection;
728 mc = empathy_mission_control_new ();
729 account = empathy_chatroom_get_account (chatroom);
730 room = empathy_chatroom_get_room (chatroom);
732 DEBUG ("Requesting channel for '%s'", room);
734 connection = mission_control_get_tpconnection (mc, account, NULL);
735 tp_connection_run_until_ready (connection, TRUE, NULL, NULL);
736 empathy_connection_request_channel (connection, -1,
737 TP_IFACE_CHANNEL_TYPE_TEXT,
740 NULL, NULL, NULL, NULL);
741 g_object_unref (connection);
746 main_window_chat_quit_cb (GtkWidget *widget,
747 EmpathyMainWindow *window)
753 main_window_chat_new_message_cb (GtkWidget *widget,
754 EmpathyMainWindow *window)
756 empathy_new_message_dialog_show (GTK_WINDOW (window->window));
760 main_window_chat_history_cb (GtkWidget *widget,
761 EmpathyMainWindow *window)
763 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
767 main_window_room_join_new_cb (GtkWidget *widget,
768 EmpathyMainWindow *window)
770 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
774 main_window_room_join_favorites_cb (GtkWidget *widget,
775 EmpathyMainWindow *window)
777 GList *chatrooms, *l;
779 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
780 for (l = chatrooms; l; l = l->next) {
781 main_window_favorite_chatroom_join (l->data);
783 g_list_free (chatrooms);
787 main_window_room_manage_favorites_cb (GtkWidget *widget,
788 EmpathyMainWindow *window)
790 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
794 main_window_chat_add_contact_cb (GtkWidget *widget,
795 EmpathyMainWindow *window)
797 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
801 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
802 EmpathyMainWindow *window)
806 current = gtk_check_menu_item_get_active (item);
808 empathy_conf_set_bool (empathy_conf_get (),
809 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
812 /* Turn off sound just while we alter the contact list. */
813 // FIXME: empathy_sound_set_enabled (FALSE);
814 empathy_contact_list_store_set_show_offline (window->list_store, current);
815 //empathy_sound_set_enabled (TRUE);
819 main_window_edit_button_press_event_cb (GtkWidget *widget,
820 GdkEventButton *event,
821 EmpathyMainWindow *window)
825 if (!event->button == 1) {
829 submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
834 item = GTK_MENU_ITEM (window->edit_context);
835 label = gtk_bin_get_child (GTK_BIN (item));
836 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
838 gtk_widget_show (window->edit_context);
839 gtk_widget_show (window->edit_context_separator);
841 gtk_menu_item_set_submenu (item, submenu);
846 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
851 item = GTK_MENU_ITEM (window->edit_context);
852 label = gtk_bin_get_child (GTK_BIN (item));
853 gtk_label_set_text (GTK_LABEL (label), _("Group"));
855 gtk_widget_show (window->edit_context);
856 gtk_widget_show (window->edit_context_separator);
858 gtk_menu_item_set_submenu (item, submenu);
863 gtk_widget_hide (window->edit_context);
864 gtk_widget_hide (window->edit_context_separator);
870 main_window_edit_accounts_cb (GtkWidget *widget,
871 EmpathyMainWindow *window)
873 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
877 main_window_edit_personal_information_cb (GtkWidget *widget,
878 EmpathyMainWindow *window)
882 accounts = mission_control_get_online_connections (window->mc, NULL);
884 EmpathyContactFactory *factory;
885 EmpathyContact *contact;
888 account = accounts->data;
889 factory = empathy_contact_factory_new ();
890 contact = empathy_contact_factory_get_user (factory, account);
891 empathy_contact_run_until_ready (contact,
892 EMPATHY_CONTACT_READY_HANDLE |
893 EMPATHY_CONTACT_READY_ID,
896 empathy_contact_information_dialog_show (contact,
897 GTK_WINDOW (window->window),
900 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
901 g_slist_free (accounts);
902 g_object_unref (factory);
903 g_object_unref (contact);
908 main_window_edit_preferences_cb (GtkWidget *widget,
909 EmpathyMainWindow *window)
911 empathy_preferences_show (GTK_WINDOW (window->window));
915 main_window_help_about_cb (GtkWidget *widget,
916 EmpathyMainWindow *window)
918 empathy_about_dialog_new (GTK_WINDOW (window->window));
922 main_window_help_contents_cb (GtkWidget *widget,
923 EmpathyMainWindow *window)
925 empathy_url_show ("ghelp:empathy");
929 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
930 GdkEventButton *event,
931 EmpathyMainWindow *window)
933 if (event->type != GDK_BUTTON_PRESS ||
934 event->button != 1) {
938 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
944 main_window_error_edit_clicked_cb (GtkButton *button,
945 EmpathyMainWindow *window)
948 GtkWidget *error_widget;
950 account = g_object_get_data (G_OBJECT (button), "account");
951 empathy_accounts_dialog_show (GTK_WINDOW (window->window), account);
953 error_widget = g_hash_table_lookup (window->errors, account);
954 gtk_widget_destroy (error_widget);
955 g_hash_table_remove (window->errors, account);
959 main_window_error_clear_clicked_cb (GtkButton *button,
960 EmpathyMainWindow *window)
963 GtkWidget *error_widget;
965 account = g_object_get_data (G_OBJECT (button), "account");
966 error_widget = g_hash_table_lookup (window->errors, account);
967 gtk_widget_destroy (error_widget);
968 g_hash_table_remove (window->errors, account);
972 main_window_error_display (EmpathyMainWindow *window,
974 const gchar *message)
979 GtkWidget *button_edit;
980 GtkWidget *alignment;
985 GtkWidget *button_close;
988 child = g_hash_table_lookup (window->errors, account);
990 label = g_object_get_data (G_OBJECT (child), "label");
992 /* Just set the latest error and return */
993 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
994 mc_account_get_display_name (account),
996 gtk_label_set_markup (GTK_LABEL (label), str);
1002 child = gtk_vbox_new (FALSE, 0);
1003 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
1004 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
1005 gtk_widget_show (child);
1007 table = gtk_table_new (2, 4, FALSE);
1008 gtk_widget_show (table);
1009 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
1010 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
1011 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
1013 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
1014 gtk_widget_show (image);
1015 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
1016 (GtkAttachOptions) (GTK_FILL),
1017 (GtkAttachOptions) (GTK_FILL), 0, 0);
1018 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
1020 button_edit = gtk_button_new ();
1021 gtk_widget_show (button_edit);
1022 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
1023 (GtkAttachOptions) (GTK_FILL),
1024 (GtkAttachOptions) (0), 0, 0);
1026 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
1027 gtk_widget_show (alignment);
1028 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
1030 hbox = gtk_hbox_new (FALSE, 2);
1031 gtk_widget_show (hbox);
1032 gtk_container_add (GTK_CONTAINER (alignment), hbox);
1034 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
1035 gtk_widget_show (image);
1036 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1038 label = gtk_label_new_with_mnemonic (_("_Edit account"));
1039 gtk_widget_show (label);
1040 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1042 fixed = gtk_fixed_new ();
1043 gtk_widget_show (fixed);
1044 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
1045 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1046 (GtkAttachOptions) (GTK_FILL), 0, 0);
1048 vbox = gtk_vbox_new (FALSE, 6);
1049 gtk_widget_show (vbox);
1050 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
1051 (GtkAttachOptions) (GTK_FILL),
1052 (GtkAttachOptions) (GTK_FILL), 0, 0);
1054 button_close = gtk_button_new ();
1055 gtk_widget_show (button_close);
1056 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
1057 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
1060 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
1061 gtk_widget_show (image);
1062 gtk_container_add (GTK_CONTAINER (button_close), image);
1064 label = gtk_label_new ("");
1065 gtk_widget_show (label);
1066 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
1067 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
1068 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
1069 gtk_widget_set_size_request (label, 175, -1);
1070 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1071 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1072 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1074 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1075 mc_account_get_display_name (account),
1077 gtk_label_set_markup (GTK_LABEL (label), str);
1080 g_object_set_data (G_OBJECT (child), "label", label);
1081 g_object_set_data_full (G_OBJECT (button_edit),
1082 "account", g_object_ref (account),
1084 g_object_set_data_full (G_OBJECT (button_close),
1085 "account", g_object_ref (account),
1088 g_signal_connect (button_edit, "clicked",
1089 G_CALLBACK (main_window_error_edit_clicked_cb),
1092 g_signal_connect (button_close, "clicked",
1093 G_CALLBACK (main_window_error_clear_clicked_cb),
1096 gtk_widget_show (window->errors_vbox);
1098 g_hash_table_insert (window->errors, g_object_ref (account), child);
1102 main_window_status_changed_cb (MissionControl *mc,
1103 TpConnectionStatus status,
1104 McPresence presence,
1105 TpConnectionStatusReason reason,
1106 const gchar *unique_name,
1107 EmpathyMainWindow *window)
1111 main_window_update_status (window);
1113 account = mc_account_lookup (unique_name);
1115 if (status == TP_CONNECTION_STATUS_DISCONNECTED &&
1116 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
1117 const gchar *message;
1120 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
1121 message = _("No error specified");
1123 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
1124 message = _("Network error");
1126 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
1127 message = _("Authentication failed");
1129 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
1130 message = _("Encryption error");
1132 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
1133 message = _("Name in use");
1135 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
1136 message = _("Certificate not provided");
1138 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
1139 message = _("Certificate untrusted");
1141 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
1142 message = _("Certificate expired");
1144 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
1145 message = _("Certificate not activated");
1147 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
1148 message = _("Certificate hostname mismatch");
1150 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
1151 message = _("Certificate fingerprint mismatch");
1153 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
1154 message = _("Certificate self-signed");
1156 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
1157 message = _("Certificate error");
1160 message = _("Unknown error");
1164 main_window_error_display (window, account, message);
1167 if (status == TP_CONNECTION_STATUS_CONNECTED) {
1168 GtkWidget *error_widget;
1170 /* Account connected without error, remove error message if any */
1171 error_widget = g_hash_table_lookup (window->errors, account);
1173 gtk_widget_destroy (error_widget);
1174 g_hash_table_remove (window->errors, account);
1178 g_object_unref (account);
1182 main_window_update_status (EmpathyMainWindow *window)
1184 GList *accounts, *l;
1185 guint connected = 0;
1186 guint connecting = 0;
1187 guint disconnected = 0;
1189 /* Count number of connected/connecting/disconnected accounts */
1190 accounts = mc_accounts_list ();
1191 for (l = accounts; l; l = l->next) {
1197 status = mission_control_get_connection_status (window->mc,
1203 } else if (status == 1) {
1205 } else if (status == 2) {
1209 g_object_unref (account);
1211 g_list_free (accounts);
1213 /* Update the spinner state */
1214 if (connecting > 0) {
1215 ephy_spinner_start (EPHY_SPINNER (window->throbber));
1217 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
1220 /* Update widgets sensibility */
1221 for (l = window->widgets_connected; l; l = l->next) {
1222 gtk_widget_set_sensitive (l->data, (connected > 0));
1225 for (l = window->widgets_disconnected; l; l = l->next) {
1226 gtk_widget_set_sensitive (l->data, (disconnected > 0));
1234 main_window_accels_load (void)
1238 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1239 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1240 DEBUG ("Loading from:'%s'", filename);
1241 gtk_accel_map_load (filename);
1248 main_window_accels_save (void)
1251 gchar *file_with_path;
1253 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1254 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1255 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1258 DEBUG ("Saving to:'%s'", file_with_path);
1259 gtk_accel_map_save (file_with_path);
1261 g_free (file_with_path);
1265 main_window_connection_items_setup (EmpathyMainWindow *window,
1271 const gchar *widgets_connected[] = {
1275 "edit_personal_information"
1277 const gchar *widgets_disconnected[] = {
1280 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1281 w = glade_xml_get_widget (glade, widgets_connected[i]);
1282 list = g_list_prepend (list, w);
1285 window->widgets_connected = list;
1287 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
1288 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
1289 list = g_list_prepend (list, w);
1292 window->widgets_disconnected = list;
1296 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1300 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1301 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1303 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1305 window->size_timeout_id = 0;
1311 main_window_configure_event_cb (GtkWidget *widget,
1312 GdkEventConfigure *event,
1313 EmpathyMainWindow *window)
1315 if (window->size_timeout_id) {
1316 g_source_remove (window->size_timeout_id);
1319 window->size_timeout_id = g_timeout_add_seconds (1,
1320 (GSourceFunc) main_window_configure_event_timeout_cb,
1327 main_window_notify_show_offline_cb (EmpathyConf *conf,
1329 gpointer check_menu_item)
1331 gboolean show_offline;
1333 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1334 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1340 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1342 EmpathyMainWindow *window)
1344 gboolean show_avatars;
1346 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1347 empathy_contact_list_store_set_show_avatars (window->list_store,
1353 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1355 EmpathyMainWindow *window)
1357 gboolean compact_contact_list;
1359 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1360 empathy_contact_list_store_set_is_compact (window->list_store,
1361 compact_contact_list);
1366 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1368 EmpathyMainWindow *window)
1372 if (empathy_conf_get_string (conf, key, &str) && str) {
1374 GEnumClass *enum_class;
1375 GEnumValue *enum_value;
1377 type = empathy_contact_list_store_sort_get_type ();
1378 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1379 enum_value = g_enum_get_value_by_nick (enum_class, str);
1383 empathy_contact_list_store_set_sort_criterium (window->list_store,