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>
30 #include <canberra-gtk.h>
32 #include <libempathy/empathy-contact.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-account-manager.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 "empathy-accounts-dialog.h"
54 #include "empathy-main-window.h"
55 #include "ephy-spinner.h"
56 #include "empathy-preferences.h"
57 #include "empathy-about-dialog.h"
58 #include "empathy-new-chatroom-dialog.h"
59 #include "empathy-chatrooms-window.h"
60 #include "empathy-event-manager.h"
62 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
63 #include <libempathy/empathy-debug.h>
65 /* Flashing delay for icons (milliseconds). */
66 #define FLASH_TIMEOUT 500
68 /* Minimum width of roster window if something goes wrong. */
71 /* Accels (menu shortcuts) can be configured and saved */
72 #define ACCELS_FILENAME "accels.txt"
74 /* Name in the geometry file */
75 #define GEOMETRY_NAME "main-window"
78 EmpathyContactListView *list_view;
79 EmpathyContactListStore *list_store;
81 EmpathyAccountManager *account_manager;
82 EmpathyChatroomManager *chatroom_manager;
83 EmpathyEventManager *event_manager;
84 guint flash_timeout_id;
90 GtkWidget *presence_toolbar;
91 GtkWidget *presence_chooser;
92 GtkWidget *errors_vbox;
97 GtkWidget *room_join_favorites;
98 GtkWidget *edit_context;
99 GtkWidget *edit_context_separator;
101 guint size_timeout_id;
104 /* Widgets that are enabled when there are connected accounts */
105 GList *widgets_connected;
108 static void main_window_destroy_cb (GtkWidget *widget,
109 EmpathyMainWindow *window);
110 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
111 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
112 EmpathyChatroom *chatroom,
113 EmpathyMainWindow *window);
114 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
115 EmpathyChatroom *chatroom,
116 EmpathyMainWindow *window);
117 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
118 EmpathyChatroom *chatroom);
119 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
120 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
121 EmpathyChatroom *chatroom);
122 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
123 static void main_window_chat_quit_cb (GtkWidget *widget,
124 EmpathyMainWindow *window);
125 static void main_window_chat_new_message_cb (GtkWidget *widget,
126 EmpathyMainWindow *window);
127 static void main_window_chat_history_cb (GtkWidget *widget,
128 EmpathyMainWindow *window);
129 static void main_window_room_join_new_cb (GtkWidget *widget,
130 EmpathyMainWindow *window);
131 static void main_window_room_join_favorites_cb (GtkWidget *widget,
132 EmpathyMainWindow *window);
133 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
134 EmpathyMainWindow *window);
135 static void main_window_chat_add_contact_cb (GtkWidget *widget,
136 EmpathyMainWindow *window);
137 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
138 EmpathyMainWindow *window);
139 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
140 GdkEventButton *event,
141 EmpathyMainWindow *window);
142 static void main_window_edit_accounts_cb (GtkWidget *widget,
143 EmpathyMainWindow *window);
144 static void main_window_edit_personal_information_cb (GtkWidget *widget,
145 EmpathyMainWindow *window);
146 static void main_window_edit_preferences_cb (GtkWidget *widget,
147 EmpathyMainWindow *window);
148 static void main_window_help_about_cb (GtkWidget *widget,
149 EmpathyMainWindow *window);
150 static void main_window_help_contents_cb (GtkWidget *widget,
151 EmpathyMainWindow *window);
152 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
153 GdkEventButton *event,
154 EmpathyMainWindow *window);
155 static void main_window_update_status (EmpathyMainWindow *window,
156 EmpathyAccountManager *manager);
157 static void main_window_error_display (EmpathyMainWindow *window,
159 const gchar *message);
160 static void main_window_accels_load (void);
161 static void main_window_accels_save (void);
162 static void main_window_connection_items_setup (EmpathyMainWindow *window,
164 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
165 static gboolean main_window_configure_event_cb (GtkWidget *widget,
166 GdkEventConfigure *event,
167 EmpathyMainWindow *window);
168 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
170 gpointer check_menu_item);
171 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
173 EmpathyMainWindow *window);
174 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
176 EmpathyMainWindow *window);
177 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
179 EmpathyMainWindow *window);
182 main_window_flash_stop (EmpathyMainWindow *window)
184 if (window->flash_timeout_id == 0) {
188 DEBUG ("Stop flashing");
189 g_source_remove (window->flash_timeout_id);
190 window->flash_timeout_id = 0;
191 window->flash_on = FALSE;
200 main_window_flash_foreach (GtkTreeModel *model,
205 FlashForeachData *data = (FlashForeachData*) user_data;
206 EmpathyContact *contact;
207 const gchar *icon_name;
208 GtkTreePath *parent_path = NULL;
209 GtkTreeIter parent_iter;
211 /* To be used with gtk_tree_model_foreach, update the status icon
212 * of the contact to show the event icon (on=TRUE) or the presence
214 gtk_tree_model_get (model, iter,
215 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
218 if (contact != data->event->contact) {
220 g_object_unref (contact);
226 icon_name = data->event->icon_name;
228 icon_name = empathy_icon_name_for_contact (contact);
231 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
232 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, icon_name,
235 /* To make sure the parent is shown correctly, we emit
236 * the row-changed signal on the parent so it prompts
237 * it to be refreshed by the filter func.
239 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
240 parent_path = gtk_tree_model_get_path (model, &parent_iter);
243 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
244 gtk_tree_path_free (parent_path);
247 g_object_unref (contact);
253 main_window_flash_cb (EmpathyMainWindow *window)
257 gboolean found_event = FALSE;
258 FlashForeachData data;
260 window->flash_on = !window->flash_on;
261 data.on = window->flash_on;
262 model = GTK_TREE_MODEL (window->list_store);
264 events = empathy_event_manager_get_events (window->event_manager);
265 for (l = events; l; l = l->next) {
266 data.event = l->data;
267 if (!data.event->contact) {
272 gtk_tree_model_foreach (model,
273 main_window_flash_foreach,
278 main_window_flash_stop (window);
285 main_window_flash_start (EmpathyMainWindow *window)
287 if (empathy_sound_pref_is_enabled (EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION)) {
288 ca_gtk_play_for_widget (GTK_WIDGET (window->window), 0,
289 CA_PROP_EVENT_ID, "message-new-instant",
290 CA_PROP_EVENT_DESCRIPTION, _("Incoming chat request"),
294 if (window->flash_timeout_id != 0) {
298 DEBUG ("Start flashing");
299 window->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
300 (GSourceFunc) main_window_flash_cb,
302 main_window_flash_cb (window);
306 main_window_event_added_cb (EmpathyEventManager *manager,
308 EmpathyMainWindow *window)
310 if (event->contact) {
311 main_window_flash_start (window);
316 main_window_event_removed_cb (EmpathyEventManager *manager,
318 EmpathyMainWindow *window)
320 FlashForeachData data;
322 if (!event->contact) {
328 gtk_tree_model_foreach (GTK_TREE_MODEL (window->list_store),
329 main_window_flash_foreach,
334 main_window_row_activated_cb (EmpathyContactListView *view,
336 GtkTreeViewColumn *col,
337 EmpathyMainWindow *window)
339 EmpathyContact *contact;
344 model = GTK_TREE_MODEL (window->list_store);
345 gtk_tree_model_get_iter (model, &iter, path);
346 gtk_tree_model_get (model, &iter,
347 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
354 /* If the contact has an event activate it, otherwise the
355 * default handler of row-activated will be called. */
356 events = empathy_event_manager_get_events (window->event_manager);
357 for (l = events; l; l = l->next) {
358 EmpathyEvent *event = l->data;
360 if (event->contact == contact) {
361 DEBUG ("Activate event");
362 empathy_event_activate (event);
364 /* We don't want the default handler of this signal
365 * (e.g. open a chat) */
366 g_signal_stop_emission_by_name (view, "row-activated");
371 g_object_unref (contact);
375 main_window_connection_changed_cb (EmpathyAccountManager *manager,
377 TpConnectionStatusReason reason,
378 TpConnectionStatus current,
379 TpConnectionStatus previous,
380 EmpathyMainWindow *window)
382 main_window_update_status (window, manager);
384 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
385 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
386 const gchar *message;
389 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
390 message = _("No error specified");
392 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
393 message = _("Network error");
395 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
396 message = _("Authentication failed");
398 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
399 message = _("Encryption error");
401 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
402 message = _("Name in use");
404 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
405 message = _("Certificate not provided");
407 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
408 message = _("Certificate untrusted");
410 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
411 message = _("Certificate expired");
413 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
414 message = _("Certificate not activated");
416 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
417 message = _("Certificate hostname mismatch");
419 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
420 message = _("Certificate fingerprint mismatch");
422 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
423 message = _("Certificate self-signed");
425 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
426 message = _("Certificate error");
429 message = _("Unknown error");
433 main_window_error_display (window, account, message);
436 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
437 empathy_sound_pref_is_enabled (EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT)) {
438 ca_gtk_play_for_widget (GTK_WIDGET (window->window), 0,
439 CA_PROP_EVENT_ID, "service-logout",
440 CA_PROP_EVENT_DESCRIPTION, _("Disconnected from server"),
444 if (current == TP_CONNECTION_STATUS_CONNECTED) {
445 GtkWidget *error_widget;
447 if (empathy_sound_pref_is_enabled (EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN)) {
448 ca_gtk_play_for_widget (GTK_WIDGET (window->window), 0,
449 CA_PROP_EVENT_ID, "service-login",
450 CA_PROP_EVENT_DESCRIPTION, _("Connected to server"),
454 /* Account connected without error, remove error message if any */
455 error_widget = g_hash_table_lookup (window->errors, account);
457 gtk_widget_destroy (error_widget);
458 g_hash_table_remove (window->errors, account);
464 empathy_main_window_show (void)
466 static EmpathyMainWindow *window = NULL;
467 EmpathyContactList *list_iface;
471 GtkWidget *show_offline_widget;
474 gboolean show_offline;
475 gboolean show_avatars;
476 gboolean compact_contact_list;
482 empathy_window_present (GTK_WINDOW (window->window), TRUE);
483 return window->window;
486 window = g_new0 (EmpathyMainWindow, 1);
488 /* Set up interface */
489 filename = empathy_file_lookup ("empathy-main-window.glade", "src");
490 glade = empathy_glade_get_file (filename,
493 "main_window", &window->window,
494 "main_vbox", &window->main_vbox,
495 "errors_vbox", &window->errors_vbox,
496 "chat_show_offline", &show_offline_widget,
497 "room", &window->room,
498 "room_sep", &window->room_sep,
499 "room_join_favorites", &window->room_join_favorites,
500 "edit_context", &window->edit_context,
501 "edit_context_separator", &window->edit_context_separator,
502 "presence_toolbar", &window->presence_toolbar,
503 "roster_scrolledwindow", &sw,
507 empathy_glade_connect (glade,
509 "main_window", "destroy", main_window_destroy_cb,
510 "main_window", "configure_event", main_window_configure_event_cb,
511 "chat_quit", "activate", main_window_chat_quit_cb,
512 "chat_new_message", "activate", main_window_chat_new_message_cb,
513 "chat_history", "activate", main_window_chat_history_cb,
514 "room_join_new", "activate", main_window_room_join_new_cb,
515 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
516 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
517 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
518 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
519 "edit", "button-press-event", main_window_edit_button_press_event_cb,
520 "edit_accounts", "activate", main_window_edit_accounts_cb,
521 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
522 "edit_preferences", "activate", main_window_edit_preferences_cb,
523 "help_about", "activate", main_window_help_about_cb,
524 "help_contents", "activate", main_window_help_contents_cb,
527 /* Set up connection related widgets. */
528 main_window_connection_items_setup (window, glade);
529 g_object_unref (glade);
531 window->mc = empathy_mission_control_new ();
532 window->account_manager = empathy_account_manager_new ();
534 g_signal_connect (window->account_manager,
535 "account-connection-changed",
536 G_CALLBACK (main_window_connection_changed_cb), window);
538 window->errors = g_hash_table_new_full (empathy_account_hash,
539 empathy_account_equal,
544 main_window_favorite_chatroom_menu_setup (window);
546 gtk_widget_hide (window->edit_context);
547 gtk_widget_hide (window->edit_context_separator);
549 /* Set up presence chooser */
550 window->presence_chooser = empathy_presence_chooser_new ();
551 gtk_widget_show (window->presence_chooser);
552 item = gtk_tool_item_new ();
553 gtk_widget_show (GTK_WIDGET (item));
554 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
555 gtk_tool_item_set_is_important (item, TRUE);
556 gtk_tool_item_set_expand (item, TRUE);
557 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
559 /* Set up the throbber */
560 ebox = gtk_event_box_new ();
561 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
562 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
563 g_signal_connect (ebox,
564 "button-press-event",
565 G_CALLBACK (main_window_throbber_button_press_event_cb),
567 gtk_widget_show (ebox);
569 window->throbber = ephy_spinner_new ();
570 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
571 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
572 gtk_widget_show (window->throbber);
574 item = gtk_tool_item_new ();
575 gtk_container_add (GTK_CONTAINER (item), ebox);
576 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
577 gtk_widget_show (GTK_WIDGET (item));
579 /* Set up contact list. */
580 empathy_status_presets_get_all ();
582 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
583 window->list_store = empathy_contact_list_store_new (list_iface);
584 window->list_view = empathy_contact_list_view_new (window->list_store,
585 EMPATHY_CONTACT_LIST_FEATURE_ALL,
586 EMPATHY_CONTACT_FEATURE_ALL);
587 g_object_unref (list_iface);
589 gtk_widget_show (GTK_WIDGET (window->list_view));
590 gtk_container_add (GTK_CONTAINER (sw),
591 GTK_WIDGET (window->list_view));
592 g_signal_connect (window->list_view, "row-activated",
593 G_CALLBACK (main_window_row_activated_cb),
596 /* Load user-defined accelerators. */
597 main_window_accels_load ();
599 /* Set window size. */
600 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
602 if (w >= 1 && h >= 1) {
603 /* Use the defaults from the glade file if we
604 * don't have good w, h geometry.
606 DEBUG ("Configuring window default size w:%d, h:%d", w, h);
607 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
610 if (x >= 0 && y >= 0) {
611 /* Let the window manager position it if we
612 * don't have good x, y coordinates.
614 DEBUG ("Configuring window default position x:%d, y:%d", x, y);
615 gtk_window_move (GTK_WINDOW (window->window), x, y);
618 /* Enable event handling */
619 window->event_manager = empathy_event_manager_new ();
620 g_signal_connect (window->event_manager, "event-added",
621 G_CALLBACK (main_window_event_added_cb),
623 g_signal_connect (window->event_manager, "event-removed",
624 G_CALLBACK (main_window_event_removed_cb),
627 l = empathy_event_manager_get_events (window->event_manager);
629 main_window_event_added_cb (window->event_manager,
634 conf = empathy_conf_get ();
637 empathy_conf_get_bool (conf,
638 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
640 empathy_conf_notify_add (conf,
641 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
642 main_window_notify_show_offline_cb,
643 show_offline_widget);
645 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
649 empathy_conf_get_bool (conf,
650 EMPATHY_PREFS_UI_SHOW_AVATARS,
652 empathy_conf_notify_add (conf,
653 EMPATHY_PREFS_UI_SHOW_AVATARS,
654 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
656 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
659 empathy_conf_get_bool (conf,
660 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
661 &compact_contact_list);
662 empathy_conf_notify_add (conf,
663 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
664 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
666 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
669 empathy_conf_notify_add (conf,
670 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
671 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
673 main_window_notify_sort_criterium_cb (conf,
674 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
677 main_window_update_status (window, window->account_manager);
679 return window->window;
683 main_window_destroy_cb (GtkWidget *widget,
684 EmpathyMainWindow *window)
686 /* Save user-defined accelerators. */
687 main_window_accels_save ();
689 g_signal_handlers_disconnect_by_func (window->account_manager,
690 main_window_connection_changed_cb,
693 if (window->size_timeout_id) {
694 g_source_remove (window->size_timeout_id);
697 g_list_free (window->widgets_connected);
699 g_object_unref (window->mc);
700 g_object_unref (window->account_manager);
701 g_object_unref (window->list_store);
702 g_hash_table_destroy (window->errors);
704 g_signal_handlers_disconnect_by_func (window->event_manager,
705 main_window_event_added_cb,
707 g_signal_handlers_disconnect_by_func (window->event_manager,
708 main_window_event_removed_cb,
710 g_object_unref (window->event_manager);
716 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
718 GList *chatrooms, *l;
720 window->chatroom_manager = empathy_chatroom_manager_new (NULL);
721 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
722 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
724 for (l = chatrooms; l; l = l->next) {
725 main_window_favorite_chatroom_menu_add (window, l->data);
729 gtk_widget_hide (window->room_sep);
732 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
734 g_signal_connect (window->chatroom_manager, "chatroom-added",
735 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
737 g_signal_connect (window->chatroom_manager, "chatroom-removed",
738 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
741 g_list_free (chatrooms);
745 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
746 EmpathyChatroom *chatroom,
747 EmpathyMainWindow *window)
749 main_window_favorite_chatroom_menu_add (window, chatroom);
750 gtk_widget_show (window->room_sep);
751 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
755 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
756 EmpathyChatroom *chatroom,
757 EmpathyMainWindow *window)
759 GtkWidget *menu_item;
761 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
763 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
764 gtk_widget_destroy (menu_item);
766 main_window_favorite_chatroom_menu_update (window);
770 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
771 EmpathyChatroom *chatroom)
773 main_window_favorite_chatroom_join (chatroom);
777 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
781 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
784 gtk_widget_show (window->room_sep);
786 gtk_widget_hide (window->room_sep);
789 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
790 g_list_free (chatrooms);
794 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
795 EmpathyChatroom *chatroom)
797 GtkWidget *menu_item;
800 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
804 name = empathy_chatroom_get_name (chatroom);
805 menu_item = gtk_menu_item_new_with_label (name);
807 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
808 g_signal_connect (menu_item, "activate",
809 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
812 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
815 gtk_widget_show (menu_item);
819 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
823 TpConnection *connection;
826 mc = empathy_mission_control_new ();
827 account = empathy_chatroom_get_account (chatroom);
828 room = empathy_chatroom_get_room (chatroom);
830 DEBUG ("Requesting channel for '%s'", room);
832 connection = mission_control_get_tpconnection (mc, account, NULL);
834 tp_connection_run_until_ready (connection, TRUE, NULL, NULL);
835 empathy_connection_request_channel (connection, -1,
836 TP_IFACE_CHANNEL_TYPE_TEXT,
839 NULL, NULL, NULL, NULL);
840 g_object_unref (connection);
846 main_window_chat_quit_cb (GtkWidget *widget,
847 EmpathyMainWindow *window)
853 main_window_chat_new_message_cb (GtkWidget *widget,
854 EmpathyMainWindow *window)
856 empathy_new_message_dialog_show (GTK_WINDOW (window->window));
860 main_window_chat_history_cb (GtkWidget *widget,
861 EmpathyMainWindow *window)
863 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
867 main_window_room_join_new_cb (GtkWidget *widget,
868 EmpathyMainWindow *window)
870 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
874 main_window_room_join_favorites_cb (GtkWidget *widget,
875 EmpathyMainWindow *window)
877 GList *chatrooms, *l;
879 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
880 for (l = chatrooms; l; l = l->next) {
881 main_window_favorite_chatroom_join (l->data);
883 g_list_free (chatrooms);
887 main_window_room_manage_favorites_cb (GtkWidget *widget,
888 EmpathyMainWindow *window)
890 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
894 main_window_chat_add_contact_cb (GtkWidget *widget,
895 EmpathyMainWindow *window)
897 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
901 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
902 EmpathyMainWindow *window)
906 current = gtk_check_menu_item_get_active (item);
908 empathy_conf_set_bool (empathy_conf_get (),
909 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
912 /* Turn off sound just while we alter the contact list. */
913 // FIXME: empathy_sound_set_enabled (FALSE);
914 empathy_contact_list_store_set_show_offline (window->list_store, current);
915 //empathy_sound_set_enabled (TRUE);
919 main_window_edit_button_press_event_cb (GtkWidget *widget,
920 GdkEventButton *event,
921 EmpathyMainWindow *window)
925 if (!event->button == 1) {
929 submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
934 item = GTK_MENU_ITEM (window->edit_context);
935 label = gtk_bin_get_child (GTK_BIN (item));
936 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
938 gtk_widget_show (window->edit_context);
939 gtk_widget_show (window->edit_context_separator);
941 gtk_menu_item_set_submenu (item, submenu);
946 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
951 item = GTK_MENU_ITEM (window->edit_context);
952 label = gtk_bin_get_child (GTK_BIN (item));
953 gtk_label_set_text (GTK_LABEL (label), _("Group"));
955 gtk_widget_show (window->edit_context);
956 gtk_widget_show (window->edit_context_separator);
958 gtk_menu_item_set_submenu (item, submenu);
963 gtk_widget_hide (window->edit_context);
964 gtk_widget_hide (window->edit_context_separator);
970 main_window_edit_accounts_cb (GtkWidget *widget,
971 EmpathyMainWindow *window)
973 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
977 main_window_edit_personal_information_cb (GtkWidget *widget,
978 EmpathyMainWindow *window)
982 accounts = mission_control_get_online_connections (window->mc, NULL);
984 EmpathyContactFactory *factory;
985 EmpathyContact *contact;
988 account = accounts->data;
989 factory = empathy_contact_factory_new ();
990 contact = empathy_contact_factory_get_user (factory, account);
991 empathy_contact_run_until_ready (contact,
992 EMPATHY_CONTACT_READY_HANDLE |
993 EMPATHY_CONTACT_READY_ID,
996 empathy_contact_information_dialog_show (contact,
997 GTK_WINDOW (window->window),
1000 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
1001 g_slist_free (accounts);
1002 g_object_unref (factory);
1003 g_object_unref (contact);
1008 main_window_edit_preferences_cb (GtkWidget *widget,
1009 EmpathyMainWindow *window)
1011 empathy_preferences_show (GTK_WINDOW (window->window));
1015 main_window_help_about_cb (GtkWidget *widget,
1016 EmpathyMainWindow *window)
1018 empathy_about_dialog_new (GTK_WINDOW (window->window));
1022 main_window_help_contents_cb (GtkWidget *widget,
1023 EmpathyMainWindow *window)
1025 empathy_url_show (widget, "ghelp:empathy");
1029 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
1030 GdkEventButton *event,
1031 EmpathyMainWindow *window)
1033 if (event->type != GDK_BUTTON_PRESS ||
1034 event->button != 1) {
1038 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
1044 main_window_error_edit_clicked_cb (GtkButton *button,
1045 EmpathyMainWindow *window)
1048 GtkWidget *error_widget;
1050 account = g_object_get_data (G_OBJECT (button), "account");
1051 empathy_accounts_dialog_show (GTK_WINDOW (window->window), account);
1053 error_widget = g_hash_table_lookup (window->errors, account);
1054 gtk_widget_destroy (error_widget);
1055 g_hash_table_remove (window->errors, account);
1059 main_window_error_clear_clicked_cb (GtkButton *button,
1060 EmpathyMainWindow *window)
1063 GtkWidget *error_widget;
1065 account = g_object_get_data (G_OBJECT (button), "account");
1066 error_widget = g_hash_table_lookup (window->errors, account);
1067 gtk_widget_destroy (error_widget);
1068 g_hash_table_remove (window->errors, account);
1072 main_window_error_display (EmpathyMainWindow *window,
1074 const gchar *message)
1079 GtkWidget *button_edit;
1080 GtkWidget *alignment;
1085 GtkWidget *button_close;
1088 child = g_hash_table_lookup (window->errors, account);
1090 label = g_object_get_data (G_OBJECT (child), "label");
1092 /* Just set the latest error and return */
1093 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1094 mc_account_get_display_name (account),
1096 gtk_label_set_markup (GTK_LABEL (label), str);
1102 child = gtk_vbox_new (FALSE, 0);
1103 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
1104 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
1105 gtk_widget_show (child);
1107 table = gtk_table_new (2, 4, FALSE);
1108 gtk_widget_show (table);
1109 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
1110 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
1111 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
1113 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
1114 gtk_widget_show (image);
1115 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
1116 (GtkAttachOptions) (GTK_FILL),
1117 (GtkAttachOptions) (GTK_FILL), 0, 0);
1118 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
1120 button_edit = gtk_button_new ();
1121 gtk_widget_show (button_edit);
1122 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
1123 (GtkAttachOptions) (GTK_FILL),
1124 (GtkAttachOptions) (0), 0, 0);
1126 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
1127 gtk_widget_show (alignment);
1128 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
1130 hbox = gtk_hbox_new (FALSE, 2);
1131 gtk_widget_show (hbox);
1132 gtk_container_add (GTK_CONTAINER (alignment), hbox);
1134 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
1135 gtk_widget_show (image);
1136 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1138 label = gtk_label_new_with_mnemonic (_("_Edit account"));
1139 gtk_widget_show (label);
1140 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1142 fixed = gtk_fixed_new ();
1143 gtk_widget_show (fixed);
1144 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
1145 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1146 (GtkAttachOptions) (GTK_FILL), 0, 0);
1148 vbox = gtk_vbox_new (FALSE, 6);
1149 gtk_widget_show (vbox);
1150 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
1151 (GtkAttachOptions) (GTK_FILL),
1152 (GtkAttachOptions) (GTK_FILL), 0, 0);
1154 button_close = gtk_button_new ();
1155 gtk_widget_show (button_close);
1156 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
1157 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
1160 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
1161 gtk_widget_show (image);
1162 gtk_container_add (GTK_CONTAINER (button_close), image);
1164 label = gtk_label_new ("");
1165 gtk_widget_show (label);
1166 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
1167 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
1168 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
1169 gtk_widget_set_size_request (label, 175, -1);
1170 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1171 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1172 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1174 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1175 mc_account_get_display_name (account),
1177 gtk_label_set_markup (GTK_LABEL (label), str);
1180 g_object_set_data (G_OBJECT (child), "label", label);
1181 g_object_set_data_full (G_OBJECT (button_edit),
1182 "account", g_object_ref (account),
1184 g_object_set_data_full (G_OBJECT (button_close),
1185 "account", g_object_ref (account),
1188 g_signal_connect (button_edit, "clicked",
1189 G_CALLBACK (main_window_error_edit_clicked_cb),
1192 g_signal_connect (button_close, "clicked",
1193 G_CALLBACK (main_window_error_clear_clicked_cb),
1196 gtk_widget_show (window->errors_vbox);
1198 g_hash_table_insert (window->errors, g_object_ref (account), child);
1202 main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *manager)
1208 /* Count number of connected/connecting/disconnected accounts */
1209 connected = empathy_account_manager_get_connected_accounts (manager);
1210 connecting = empathy_account_manager_get_connecting_accounts (manager);
1212 /* Update the spinner state */
1213 if (connecting > 0) {
1214 ephy_spinner_start (EPHY_SPINNER (window->throbber));
1216 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
1219 /* Update widgets sensibility */
1220 for (l = window->widgets_connected; l; l = l->next) {
1221 gtk_widget_set_sensitive (l->data, (connected > 0));
1229 main_window_accels_load (void)
1233 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1234 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1235 DEBUG ("Loading from:'%s'", filename);
1236 gtk_accel_map_load (filename);
1243 main_window_accels_save (void)
1246 gchar *file_with_path;
1248 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1249 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1250 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1253 DEBUG ("Saving to:'%s'", file_with_path);
1254 gtk_accel_map_save (file_with_path);
1256 g_free (file_with_path);
1260 main_window_connection_items_setup (EmpathyMainWindow *window,
1266 const gchar *widgets_connected[] = {
1270 "edit_personal_information"
1273 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1274 w = glade_xml_get_widget (glade, widgets_connected[i]);
1275 list = g_list_prepend (list, w);
1278 window->widgets_connected = list;
1282 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1286 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1287 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1289 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1291 window->size_timeout_id = 0;
1297 main_window_configure_event_cb (GtkWidget *widget,
1298 GdkEventConfigure *event,
1299 EmpathyMainWindow *window)
1301 if (window->size_timeout_id) {
1302 g_source_remove (window->size_timeout_id);
1305 window->size_timeout_id = g_timeout_add_seconds (1,
1306 (GSourceFunc) main_window_configure_event_timeout_cb,
1313 main_window_notify_show_offline_cb (EmpathyConf *conf,
1315 gpointer check_menu_item)
1317 gboolean show_offline;
1319 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1320 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1326 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1328 EmpathyMainWindow *window)
1330 gboolean show_avatars;
1332 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1333 empathy_contact_list_store_set_show_avatars (window->list_store,
1339 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1341 EmpathyMainWindow *window)
1343 gboolean compact_contact_list;
1345 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1346 empathy_contact_list_store_set_is_compact (window->list_store,
1347 compact_contact_list);
1352 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1354 EmpathyMainWindow *window)
1358 if (empathy_conf_get_string (conf, key, &str) && str) {
1360 GEnumClass *enum_class;
1361 GEnumValue *enum_value;
1363 type = empathy_contact_list_store_sort_get_type ();
1364 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1365 enum_value = g_enum_get_value_by_nick (enum_class, str);
1369 empathy_contact_list_store_set_sort_criterium (window->list_store,