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-account-manager.h>
34 #include <libempathy/empathy-dispatcher.h>
35 #include <libempathy/empathy-chatroom-manager.h>
36 #include <libempathy/empathy-chatroom.h>
37 #include <libempathy/empathy-contact-list.h>
38 #include <libempathy/empathy-contact-manager.h>
39 #include <libempathy/empathy-contact-factory.h>
40 #include <libempathy/empathy-status-presets.h>
42 #include <libempathy-gtk/empathy-contact-dialogs.h>
43 #include <libempathy-gtk/empathy-contact-list-store.h>
44 #include <libempathy-gtk/empathy-contact-list-view.h>
45 #include <libempathy-gtk/empathy-presence-chooser.h>
46 #include <libempathy-gtk/empathy-ui-utils.h>
47 #include <libempathy-gtk/empathy-geometry.h>
48 #include <libempathy-gtk/empathy-conf.h>
49 #include <libempathy-gtk/empathy-log-window.h>
50 #include <libempathy-gtk/empathy-new-message-dialog.h>
51 #include <libempathy-gtk/empathy-gtk-enum-types.h>
53 #include <libmissioncontrol/mission-control.h>
55 #include "empathy-accounts-dialog.h"
56 #include "empathy-main-window.h"
57 #include "ephy-spinner.h"
58 #include "empathy-preferences.h"
59 #include "empathy-about-dialog.h"
60 #include "empathy-new-chatroom-dialog.h"
61 #include "empathy-chatrooms-window.h"
62 #include "empathy-event-manager.h"
64 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
65 #include <libempathy/empathy-debug.h>
67 /* Flashing delay for icons (milliseconds). */
68 #define FLASH_TIMEOUT 500
70 /* Minimum width of roster window if something goes wrong. */
73 /* Accels (menu shortcuts) can be configured and saved */
74 #define ACCELS_FILENAME "accels.txt"
76 /* Name in the geometry file */
77 #define GEOMETRY_NAME "main-window"
80 EmpathyContactListView *list_view;
81 EmpathyContactListStore *list_store;
83 EmpathyAccountManager *account_manager;
84 EmpathyChatroomManager *chatroom_manager;
85 EmpathyEventManager *event_manager;
86 guint flash_timeout_id;
92 GtkWidget *presence_toolbar;
93 GtkWidget *presence_chooser;
94 GtkWidget *errors_vbox;
99 GtkWidget *room_join_favorites;
100 GtkWidget *edit_context;
101 GtkWidget *edit_context_separator;
103 guint size_timeout_id;
106 /* Widgets that are enabled when there are connected accounts */
107 GList *widgets_connected;
110 static void main_window_destroy_cb (GtkWidget *widget,
111 EmpathyMainWindow *window);
112 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
113 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
114 EmpathyChatroom *chatroom,
115 EmpathyMainWindow *window);
116 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
117 EmpathyChatroom *chatroom,
118 EmpathyMainWindow *window);
119 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
120 EmpathyChatroom *chatroom);
121 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
122 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
123 EmpathyChatroom *chatroom);
124 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
125 static void main_window_chat_quit_cb (GtkWidget *widget,
126 EmpathyMainWindow *window);
127 static void main_window_chat_new_message_cb (GtkWidget *widget,
128 EmpathyMainWindow *window);
129 static void main_window_chat_history_cb (GtkWidget *widget,
130 EmpathyMainWindow *window);
131 static void main_window_room_join_new_cb (GtkWidget *widget,
132 EmpathyMainWindow *window);
133 static void main_window_room_join_favorites_cb (GtkWidget *widget,
134 EmpathyMainWindow *window);
135 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
136 EmpathyMainWindow *window);
137 static void main_window_chat_add_contact_cb (GtkWidget *widget,
138 EmpathyMainWindow *window);
139 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
140 EmpathyMainWindow *window);
141 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
142 GdkEventButton *event,
143 EmpathyMainWindow *window);
144 static void main_window_edit_accounts_cb (GtkWidget *widget,
145 EmpathyMainWindow *window);
146 static void main_window_edit_personal_information_cb (GtkWidget *widget,
147 EmpathyMainWindow *window);
148 static void main_window_edit_preferences_cb (GtkWidget *widget,
149 EmpathyMainWindow *window);
150 static void main_window_help_about_cb (GtkWidget *widget,
151 EmpathyMainWindow *window);
152 static void main_window_help_contents_cb (GtkWidget *widget,
153 EmpathyMainWindow *window);
154 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
155 GdkEventButton *event,
156 EmpathyMainWindow *window);
157 static void main_window_update_status (EmpathyMainWindow *window,
158 EmpathyAccountManager *manager);
159 static void main_window_error_display (EmpathyMainWindow *window,
161 const gchar *message);
162 static void main_window_accels_load (void);
163 static void main_window_accels_save (void);
164 static void main_window_connection_items_setup (EmpathyMainWindow *window,
166 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
167 static gboolean main_window_configure_event_cb (GtkWidget *widget,
168 GdkEventConfigure *event,
169 EmpathyMainWindow *window);
170 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
172 gpointer check_menu_item);
173 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
175 EmpathyMainWindow *window);
176 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
178 EmpathyMainWindow *window);
179 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
181 EmpathyMainWindow *window);
184 main_window_flash_stop (EmpathyMainWindow *window)
186 if (window->flash_timeout_id == 0) {
190 DEBUG ("Stop flashing");
191 g_source_remove (window->flash_timeout_id);
192 window->flash_timeout_id = 0;
193 window->flash_on = FALSE;
202 main_window_flash_foreach (GtkTreeModel *model,
207 FlashForeachData *data = (FlashForeachData*) user_data;
208 EmpathyContact *contact;
209 const gchar *icon_name;
210 GtkTreePath *parent_path = NULL;
211 GtkTreeIter parent_iter;
213 /* To be used with gtk_tree_model_foreach, update the status icon
214 * of the contact to show the event icon (on=TRUE) or the presence
216 gtk_tree_model_get (model, iter,
217 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
220 if (contact != data->event->contact) {
222 g_object_unref (contact);
228 icon_name = data->event->icon_name;
230 icon_name = empathy_icon_name_for_contact (contact);
233 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
234 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, icon_name,
237 /* To make sure the parent is shown correctly, we emit
238 * the row-changed signal on the parent so it prompts
239 * it to be refreshed by the filter func.
241 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
242 parent_path = gtk_tree_model_get_path (model, &parent_iter);
245 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
246 gtk_tree_path_free (parent_path);
249 g_object_unref (contact);
255 main_window_flash_cb (EmpathyMainWindow *window)
259 gboolean found_event = FALSE;
260 FlashForeachData data;
262 window->flash_on = !window->flash_on;
263 data.on = window->flash_on;
264 model = GTK_TREE_MODEL (window->list_store);
266 events = empathy_event_manager_get_events (window->event_manager);
267 for (l = events; l; l = l->next) {
268 data.event = l->data;
269 if (!data.event->contact) {
274 gtk_tree_model_foreach (model,
275 main_window_flash_foreach,
280 main_window_flash_stop (window);
287 main_window_flash_start (EmpathyMainWindow *window)
289 empathy_sound_play (GTK_WIDGET (window->window),
290 EMPATHY_SOUND_CONVERSATION_NEW);
292 if (window->flash_timeout_id != 0) {
296 DEBUG ("Start flashing");
297 window->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
298 (GSourceFunc) main_window_flash_cb,
300 main_window_flash_cb (window);
304 main_window_event_added_cb (EmpathyEventManager *manager,
306 EmpathyMainWindow *window)
308 if (event->contact) {
309 main_window_flash_start (window);
314 main_window_event_removed_cb (EmpathyEventManager *manager,
316 EmpathyMainWindow *window)
318 FlashForeachData data;
320 if (!event->contact) {
326 gtk_tree_model_foreach (GTK_TREE_MODEL (window->list_store),
327 main_window_flash_foreach,
332 main_window_row_activated_cb (EmpathyContactListView *view,
334 GtkTreeViewColumn *col,
335 EmpathyMainWindow *window)
337 EmpathyContact *contact;
342 model = GTK_TREE_MODEL (window->list_store);
343 gtk_tree_model_get_iter (model, &iter, path);
344 gtk_tree_model_get (model, &iter,
345 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
352 /* If the contact has an event activate it, otherwise the
353 * default handler of row-activated will be called. */
354 events = empathy_event_manager_get_events (window->event_manager);
355 for (l = events; l; l = l->next) {
356 EmpathyEvent *event = l->data;
358 if (event->contact == contact) {
359 DEBUG ("Activate event");
360 empathy_event_activate (event);
362 /* We don't want the default handler of this signal
363 * (e.g. open a chat) */
364 g_signal_stop_emission_by_name (view, "row-activated");
369 g_object_unref (contact);
373 main_window_connection_changed_cb (EmpathyAccountManager *manager,
375 TpConnectionStatusReason reason,
376 TpConnectionStatus current,
377 TpConnectionStatus previous,
378 EmpathyMainWindow *window)
380 main_window_update_status (window, manager);
382 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
383 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
384 const gchar *message;
387 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
388 message = _("No error specified");
390 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
391 message = _("Network error");
393 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
394 message = _("Authentication failed");
396 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
397 message = _("Encryption error");
399 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
400 message = _("Name in use");
402 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
403 message = _("Certificate not provided");
405 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
406 message = _("Certificate untrusted");
408 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
409 message = _("Certificate expired");
411 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
412 message = _("Certificate not activated");
414 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
415 message = _("Certificate hostname mismatch");
417 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
418 message = _("Certificate fingerprint mismatch");
420 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
421 message = _("Certificate self-signed");
423 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
424 message = _("Certificate error");
427 message = _("Unknown error");
431 main_window_error_display (window, account, message);
434 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
435 empathy_sound_play (GTK_WIDGET (window->window),
436 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
439 if (current == TP_CONNECTION_STATUS_CONNECTED) {
440 GtkWidget *error_widget;
442 empathy_sound_play (GTK_WIDGET (window->window),
443 EMPATHY_SOUND_ACCOUNT_CONNECTED);
445 /* Account connected without error, remove error message if any */
446 error_widget = g_hash_table_lookup (window->errors, account);
448 gtk_widget_destroy (error_widget);
449 g_hash_table_remove (window->errors, account);
455 main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor,
456 EmpathyContact *contact,
459 EmpathyMainWindow *window)
462 gboolean should_play;
464 account = empathy_contact_get_account (contact);
465 should_play = !empathy_account_manager_is_account_just_connected (window->account_manager, account);
471 if (previous < MC_PRESENCE_AVAILABLE && current > MC_PRESENCE_OFFLINE) {
472 /* someone is logging in */
473 empathy_sound_play (GTK_WIDGET (window->window),
474 EMPATHY_SOUND_CONTACT_CONNECTED);
478 if (previous > MC_PRESENCE_OFFLINE && current < MC_PRESENCE_AVAILABLE) {
479 /* someone is logging off */
480 empathy_sound_play (GTK_WIDGET (window->window),
481 EMPATHY_SOUND_CONTACT_DISCONNECTED);
486 empathy_main_window_show (void)
488 static EmpathyMainWindow *window = NULL;
489 EmpathyContactList *list_iface;
490 EmpathyContactMonitor *monitor;
494 GtkWidget *show_offline_widget;
497 gboolean show_offline;
498 gboolean show_avatars;
499 gboolean compact_contact_list;
505 empathy_window_present (GTK_WINDOW (window->window), TRUE);
506 return window->window;
509 window = g_new0 (EmpathyMainWindow, 1);
511 /* Set up interface */
512 filename = empathy_file_lookup ("empathy-main-window.glade", "src");
513 glade = empathy_glade_get_file (filename,
516 "main_window", &window->window,
517 "main_vbox", &window->main_vbox,
518 "errors_vbox", &window->errors_vbox,
519 "chat_show_offline", &show_offline_widget,
520 "room", &window->room,
521 "room_sep", &window->room_sep,
522 "room_join_favorites", &window->room_join_favorites,
523 "edit_context", &window->edit_context,
524 "edit_context_separator", &window->edit_context_separator,
525 "presence_toolbar", &window->presence_toolbar,
526 "roster_scrolledwindow", &sw,
530 empathy_glade_connect (glade,
532 "main_window", "destroy", main_window_destroy_cb,
533 "main_window", "configure_event", main_window_configure_event_cb,
534 "chat_quit", "activate", main_window_chat_quit_cb,
535 "chat_new_message", "activate", main_window_chat_new_message_cb,
536 "chat_history", "activate", main_window_chat_history_cb,
537 "room_join_new", "activate", main_window_room_join_new_cb,
538 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
539 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
540 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
541 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
542 "edit", "button-press-event", main_window_edit_button_press_event_cb,
543 "edit_accounts", "activate", main_window_edit_accounts_cb,
544 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
545 "edit_preferences", "activate", main_window_edit_preferences_cb,
546 "help_about", "activate", main_window_help_about_cb,
547 "help_contents", "activate", main_window_help_contents_cb,
550 /* Set up connection related widgets. */
551 main_window_connection_items_setup (window, glade);
552 g_object_unref (glade);
554 window->mc = empathy_mission_control_new ();
555 window->account_manager = empathy_account_manager_dup_singleton ();
557 g_signal_connect (window->account_manager,
558 "account-connection-changed",
559 G_CALLBACK (main_window_connection_changed_cb), window);
561 window->errors = g_hash_table_new_full (empathy_account_hash,
562 empathy_account_equal,
567 main_window_favorite_chatroom_menu_setup (window);
569 gtk_widget_hide (window->edit_context);
570 gtk_widget_hide (window->edit_context_separator);
572 /* Set up presence chooser */
573 window->presence_chooser = empathy_presence_chooser_new ();
574 gtk_widget_show (window->presence_chooser);
575 item = gtk_tool_item_new ();
576 gtk_widget_show (GTK_WIDGET (item));
577 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
578 gtk_tool_item_set_is_important (item, TRUE);
579 gtk_tool_item_set_expand (item, TRUE);
580 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
582 /* Set up the throbber */
583 ebox = gtk_event_box_new ();
584 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
585 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
586 g_signal_connect (ebox,
587 "button-press-event",
588 G_CALLBACK (main_window_throbber_button_press_event_cb),
590 gtk_widget_show (ebox);
592 window->throbber = ephy_spinner_new ();
593 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
594 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
595 gtk_widget_show (window->throbber);
597 item = gtk_tool_item_new ();
598 gtk_container_add (GTK_CONTAINER (item), ebox);
599 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
600 gtk_widget_show (GTK_WIDGET (item));
602 /* Set up contact list. */
603 empathy_status_presets_get_all ();
605 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
606 monitor = empathy_contact_list_get_monitor (list_iface);
607 window->list_store = empathy_contact_list_store_new (list_iface);
608 window->list_view = empathy_contact_list_view_new (window->list_store,
609 EMPATHY_CONTACT_LIST_FEATURE_ALL,
610 EMPATHY_CONTACT_FEATURE_ALL);
611 g_signal_connect (monitor, "contact-presence-changed",
612 G_CALLBACK (main_window_contact_presence_changed_cb), window);
613 g_object_unref (list_iface);
615 gtk_widget_show (GTK_WIDGET (window->list_view));
616 gtk_container_add (GTK_CONTAINER (sw),
617 GTK_WIDGET (window->list_view));
618 g_signal_connect (window->list_view, "row-activated",
619 G_CALLBACK (main_window_row_activated_cb),
622 /* Load user-defined accelerators. */
623 main_window_accels_load ();
625 /* Set window size. */
626 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
628 if (w >= 1 && h >= 1) {
629 /* Use the defaults from the glade file if we
630 * don't have good w, h geometry.
632 DEBUG ("Configuring window default size w:%d, h:%d", w, h);
633 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
636 if (x >= 0 && y >= 0) {
637 /* Let the window manager position it if we
638 * don't have good x, y coordinates.
640 DEBUG ("Configuring window default position x:%d, y:%d", x, y);
641 gtk_window_move (GTK_WINDOW (window->window), x, y);
644 /* Enable event handling */
645 window->event_manager = empathy_event_manager_dup_singleton ();
646 g_signal_connect (window->event_manager, "event-added",
647 G_CALLBACK (main_window_event_added_cb),
649 g_signal_connect (window->event_manager, "event-removed",
650 G_CALLBACK (main_window_event_removed_cb),
653 l = empathy_event_manager_get_events (window->event_manager);
655 main_window_event_added_cb (window->event_manager,
660 conf = empathy_conf_get ();
663 empathy_conf_get_bool (conf,
664 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
666 empathy_conf_notify_add (conf,
667 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
668 main_window_notify_show_offline_cb,
669 show_offline_widget);
671 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
675 empathy_conf_get_bool (conf,
676 EMPATHY_PREFS_UI_SHOW_AVATARS,
678 empathy_conf_notify_add (conf,
679 EMPATHY_PREFS_UI_SHOW_AVATARS,
680 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
682 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
685 empathy_conf_get_bool (conf,
686 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
687 &compact_contact_list);
688 empathy_conf_notify_add (conf,
689 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
690 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
692 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
695 empathy_conf_notify_add (conf,
696 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
697 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
699 main_window_notify_sort_criterium_cb (conf,
700 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
703 main_window_update_status (window, window->account_manager);
705 return window->window;
709 main_window_destroy_cb (GtkWidget *widget,
710 EmpathyMainWindow *window)
712 /* Save user-defined accelerators. */
713 main_window_accels_save ();
715 g_signal_handlers_disconnect_by_func (window->account_manager,
716 main_window_connection_changed_cb,
719 if (window->size_timeout_id) {
720 g_source_remove (window->size_timeout_id);
723 g_list_free (window->widgets_connected);
725 g_object_unref (window->mc);
726 g_object_unref (window->account_manager);
727 g_object_unref (window->list_store);
728 g_hash_table_destroy (window->errors);
730 g_signal_handlers_disconnect_by_func (window->event_manager,
731 main_window_event_added_cb,
733 g_signal_handlers_disconnect_by_func (window->event_manager,
734 main_window_event_removed_cb,
736 g_object_unref (window->event_manager);
742 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
744 GList *chatrooms, *l;
746 window->chatroom_manager = empathy_chatroom_manager_new (NULL);
747 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
748 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
750 for (l = chatrooms; l; l = l->next) {
751 main_window_favorite_chatroom_menu_add (window, l->data);
755 gtk_widget_hide (window->room_sep);
758 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
760 g_signal_connect (window->chatroom_manager, "chatroom-added",
761 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
763 g_signal_connect (window->chatroom_manager, "chatroom-removed",
764 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
767 g_list_free (chatrooms);
771 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
772 EmpathyChatroom *chatroom,
773 EmpathyMainWindow *window)
775 main_window_favorite_chatroom_menu_add (window, chatroom);
776 gtk_widget_show (window->room_sep);
777 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
781 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
782 EmpathyChatroom *chatroom,
783 EmpathyMainWindow *window)
785 GtkWidget *menu_item;
787 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
789 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
790 gtk_widget_destroy (menu_item);
792 main_window_favorite_chatroom_menu_update (window);
796 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
797 EmpathyChatroom *chatroom)
799 main_window_favorite_chatroom_join (chatroom);
803 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
807 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
810 gtk_widget_show (window->room_sep);
812 gtk_widget_hide (window->room_sep);
815 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
816 g_list_free (chatrooms);
820 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
821 EmpathyChatroom *chatroom)
823 GtkWidget *menu_item;
826 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
830 name = empathy_chatroom_get_name (chatroom);
831 menu_item = gtk_menu_item_new_with_label (name);
833 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
834 g_signal_connect (menu_item, "activate",
835 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
838 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
841 gtk_widget_show (menu_item);
845 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
851 mc = empathy_mission_control_new ();
852 account = empathy_chatroom_get_account (chatroom);
853 room = empathy_chatroom_get_room (chatroom);
855 if (mission_control_get_connection_status (mc, account, NULL) !=
856 TP_CONNECTION_STATUS_CONNECTED) {
860 DEBUG ("Requesting channel for '%s'", room);
861 empathy_dispatcher_join_muc (account, room, NULL, NULL);
867 main_window_chat_quit_cb (GtkWidget *widget,
868 EmpathyMainWindow *window)
874 main_window_chat_new_message_cb (GtkWidget *widget,
875 EmpathyMainWindow *window)
877 empathy_new_message_dialog_show (GTK_WINDOW (window->window));
881 main_window_chat_history_cb (GtkWidget *widget,
882 EmpathyMainWindow *window)
884 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
888 main_window_room_join_new_cb (GtkWidget *widget,
889 EmpathyMainWindow *window)
891 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
895 main_window_room_join_favorites_cb (GtkWidget *widget,
896 EmpathyMainWindow *window)
898 GList *chatrooms, *l;
900 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
901 for (l = chatrooms; l; l = l->next) {
902 main_window_favorite_chatroom_join (l->data);
904 g_list_free (chatrooms);
908 main_window_room_manage_favorites_cb (GtkWidget *widget,
909 EmpathyMainWindow *window)
911 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
915 main_window_chat_add_contact_cb (GtkWidget *widget,
916 EmpathyMainWindow *window)
918 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
922 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
923 EmpathyMainWindow *window)
927 current = gtk_check_menu_item_get_active (item);
929 empathy_conf_set_bool (empathy_conf_get (),
930 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
933 /* Turn off sound just while we alter the contact list. */
934 // FIXME: empathy_sound_set_enabled (FALSE);
935 empathy_contact_list_store_set_show_offline (window->list_store, current);
936 //empathy_sound_set_enabled (TRUE);
940 main_window_edit_button_press_event_cb (GtkWidget *widget,
941 GdkEventButton *event,
942 EmpathyMainWindow *window)
946 if (!event->button == 1) {
950 submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
955 item = GTK_MENU_ITEM (window->edit_context);
956 label = gtk_bin_get_child (GTK_BIN (item));
957 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
959 gtk_widget_show (window->edit_context);
960 gtk_widget_show (window->edit_context_separator);
962 gtk_menu_item_set_submenu (item, submenu);
967 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
972 item = GTK_MENU_ITEM (window->edit_context);
973 label = gtk_bin_get_child (GTK_BIN (item));
974 gtk_label_set_text (GTK_LABEL (label), _("Group"));
976 gtk_widget_show (window->edit_context);
977 gtk_widget_show (window->edit_context_separator);
979 gtk_menu_item_set_submenu (item, submenu);
984 gtk_widget_hide (window->edit_context);
985 gtk_widget_hide (window->edit_context_separator);
991 main_window_edit_accounts_cb (GtkWidget *widget,
992 EmpathyMainWindow *window)
994 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
998 main_window_edit_personal_information_cb (GtkWidget *widget,
999 EmpathyMainWindow *window)
1003 accounts = mission_control_get_online_connections (window->mc, NULL);
1005 EmpathyContactFactory *factory;
1006 EmpathyContact *contact;
1009 account = accounts->data;
1010 factory = empathy_contact_factory_dup_singleton ();
1011 contact = empathy_contact_factory_get_user (factory, account);
1012 empathy_contact_run_until_ready (contact,
1013 EMPATHY_CONTACT_READY_HANDLE |
1014 EMPATHY_CONTACT_READY_ID,
1017 empathy_contact_information_dialog_show (contact,
1018 GTK_WINDOW (window->window),
1021 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
1022 g_slist_free (accounts);
1023 g_object_unref (factory);
1024 g_object_unref (contact);
1029 main_window_edit_preferences_cb (GtkWidget *widget,
1030 EmpathyMainWindow *window)
1032 empathy_preferences_show (GTK_WINDOW (window->window));
1036 main_window_help_about_cb (GtkWidget *widget,
1037 EmpathyMainWindow *window)
1039 empathy_about_dialog_new (GTK_WINDOW (window->window));
1043 main_window_help_contents_cb (GtkWidget *widget,
1044 EmpathyMainWindow *window)
1046 empathy_url_show (widget, "ghelp:empathy");
1050 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
1051 GdkEventButton *event,
1052 EmpathyMainWindow *window)
1054 if (event->type != GDK_BUTTON_PRESS ||
1055 event->button != 1) {
1059 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
1065 main_window_error_edit_clicked_cb (GtkButton *button,
1066 EmpathyMainWindow *window)
1069 GtkWidget *error_widget;
1071 account = g_object_get_data (G_OBJECT (button), "account");
1072 empathy_accounts_dialog_show (GTK_WINDOW (window->window), account);
1074 error_widget = g_hash_table_lookup (window->errors, account);
1075 gtk_widget_destroy (error_widget);
1076 g_hash_table_remove (window->errors, account);
1080 main_window_error_clear_clicked_cb (GtkButton *button,
1081 EmpathyMainWindow *window)
1084 GtkWidget *error_widget;
1086 account = g_object_get_data (G_OBJECT (button), "account");
1087 error_widget = g_hash_table_lookup (window->errors, account);
1088 gtk_widget_destroy (error_widget);
1089 g_hash_table_remove (window->errors, account);
1093 main_window_error_display (EmpathyMainWindow *window,
1095 const gchar *message)
1100 GtkWidget *button_edit;
1101 GtkWidget *alignment;
1106 GtkWidget *button_close;
1109 child = g_hash_table_lookup (window->errors, account);
1111 label = g_object_get_data (G_OBJECT (child), "label");
1113 /* Just set the latest error and return */
1114 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1115 mc_account_get_display_name (account),
1117 gtk_label_set_markup (GTK_LABEL (label), str);
1123 child = gtk_vbox_new (FALSE, 0);
1124 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
1125 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
1126 gtk_widget_show (child);
1128 table = gtk_table_new (2, 4, FALSE);
1129 gtk_widget_show (table);
1130 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
1131 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
1132 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
1134 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
1135 gtk_widget_show (image);
1136 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
1137 (GtkAttachOptions) (GTK_FILL),
1138 (GtkAttachOptions) (GTK_FILL), 0, 0);
1139 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
1141 button_edit = gtk_button_new ();
1142 gtk_widget_show (button_edit);
1143 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
1144 (GtkAttachOptions) (GTK_FILL),
1145 (GtkAttachOptions) (0), 0, 0);
1147 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
1148 gtk_widget_show (alignment);
1149 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
1151 hbox = gtk_hbox_new (FALSE, 2);
1152 gtk_widget_show (hbox);
1153 gtk_container_add (GTK_CONTAINER (alignment), hbox);
1155 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
1156 gtk_widget_show (image);
1157 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1159 label = gtk_label_new_with_mnemonic (_("_Edit account"));
1160 gtk_widget_show (label);
1161 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1163 fixed = gtk_fixed_new ();
1164 gtk_widget_show (fixed);
1165 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
1166 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1167 (GtkAttachOptions) (GTK_FILL), 0, 0);
1169 vbox = gtk_vbox_new (FALSE, 6);
1170 gtk_widget_show (vbox);
1171 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
1172 (GtkAttachOptions) (GTK_FILL),
1173 (GtkAttachOptions) (GTK_FILL), 0, 0);
1175 button_close = gtk_button_new ();
1176 gtk_widget_show (button_close);
1177 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
1178 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
1181 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
1182 gtk_widget_show (image);
1183 gtk_container_add (GTK_CONTAINER (button_close), image);
1185 label = gtk_label_new ("");
1186 gtk_widget_show (label);
1187 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
1188 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
1189 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
1190 gtk_widget_set_size_request (label, 175, -1);
1191 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1192 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1193 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1195 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1196 mc_account_get_display_name (account),
1198 gtk_label_set_markup (GTK_LABEL (label), str);
1201 g_object_set_data (G_OBJECT (child), "label", label);
1202 g_object_set_data_full (G_OBJECT (button_edit),
1203 "account", g_object_ref (account),
1205 g_object_set_data_full (G_OBJECT (button_close),
1206 "account", g_object_ref (account),
1209 g_signal_connect (button_edit, "clicked",
1210 G_CALLBACK (main_window_error_edit_clicked_cb),
1213 g_signal_connect (button_close, "clicked",
1214 G_CALLBACK (main_window_error_clear_clicked_cb),
1217 gtk_widget_show (window->errors_vbox);
1219 g_hash_table_insert (window->errors, g_object_ref (account), child);
1223 main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *manager)
1229 /* Count number of connected/connecting/disconnected accounts */
1230 connected = empathy_account_manager_get_connected_accounts (manager);
1231 connecting = empathy_account_manager_get_connecting_accounts (manager);
1233 /* Update the spinner state */
1234 if (connecting > 0) {
1235 ephy_spinner_start (EPHY_SPINNER (window->throbber));
1237 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
1240 /* Update widgets sensibility */
1241 for (l = window->widgets_connected; l; l = l->next) {
1242 gtk_widget_set_sensitive (l->data, (connected > 0));
1250 main_window_accels_load (void)
1254 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1255 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1256 DEBUG ("Loading from:'%s'", filename);
1257 gtk_accel_map_load (filename);
1264 main_window_accels_save (void)
1267 gchar *file_with_path;
1269 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1270 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1271 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1274 DEBUG ("Saving to:'%s'", file_with_path);
1275 gtk_accel_map_save (file_with_path);
1277 g_free (file_with_path);
1281 main_window_connection_items_setup (EmpathyMainWindow *window,
1287 const gchar *widgets_connected[] = {
1291 "edit_personal_information"
1294 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1295 w = glade_xml_get_widget (glade, widgets_connected[i]);
1296 list = g_list_prepend (list, w);
1299 window->widgets_connected = list;
1303 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1307 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1308 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1310 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1312 window->size_timeout_id = 0;
1318 main_window_configure_event_cb (GtkWidget *widget,
1319 GdkEventConfigure *event,
1320 EmpathyMainWindow *window)
1322 if (window->size_timeout_id) {
1323 g_source_remove (window->size_timeout_id);
1326 window->size_timeout_id = g_timeout_add_seconds (1,
1327 (GSourceFunc) main_window_configure_event_timeout_cb,
1334 main_window_notify_show_offline_cb (EmpathyConf *conf,
1336 gpointer check_menu_item)
1338 gboolean show_offline;
1340 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1341 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1347 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1349 EmpathyMainWindow *window)
1351 gboolean show_avatars;
1353 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1354 empathy_contact_list_store_set_show_avatars (window->list_store,
1360 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1362 EmpathyMainWindow *window)
1364 gboolean compact_contact_list;
1366 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1367 empathy_contact_list_store_set_is_compact (window->list_store,
1368 compact_contact_list);
1373 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1375 EmpathyMainWindow *window)
1379 if (empathy_conf_get_string (conf, key, &str) && str) {
1381 GEnumClass *enum_class;
1382 GEnumValue *enum_value;
1384 type = empathy_contact_list_store_sort_get_type ();
1385 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1386 enum_value = g_enum_get_value_by_nick (enum_class, str);
1390 empathy_contact_list_store_set_sort_criterium (window->list_store,