X-Git-Url: https://git.0d.be/?p=empathy.git;a=blobdiff_plain;f=src%2Fempathy-main-window.c;h=8fb127b90c2a6b2a93f653724af3e86d5373d1fa;hp=5cbf877e5b739a8b38931bec4ee45625c2af159b;hb=1669cc99bae84e2506bb6b671843bd980f16b2bc;hpb=ebfb5e83604b4a48482e3126e5797f05ff99b3b1 diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 5cbf877e..8fb127b9 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -15,9 +15,9 @@ * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * * Authors: Xavier Claessens */ @@ -37,25 +37,26 @@ #include #include +#include #include #include #include -#include -#include #include -#include -#include -#include #include - -#include +#include +#include +#include +#include +#include #include "empathy-accounts-dialog.h" #include "empathy-main-window.h" #include "ephy-spinner.h" #include "empathy-preferences.h" #include "empathy-about-dialog.h" +#include "empathy-debug-window.h" #include "empathy-new-chatroom-dialog.h" +#include "empathy-map-view.h" #include "empathy-chatrooms-window.h" #include "empathy-event-manager.h" #include "empathy-ft-manager.h" @@ -78,7 +79,6 @@ typedef struct { EmpathyContactListView *list_view; EmpathyContactListStore *list_store; - MissionControl *mc; EmpathyAccountManager *account_manager; EmpathyChatroomManager *chatroom_manager; EmpathyEventManager *event_manager; @@ -92,8 +92,14 @@ typedef struct { GtkWidget *presence_chooser; GtkWidget *errors_vbox; + GtkRadioAction *sort_by_name; + GtkRadioAction *sort_by_status; + GtkRadioAction *normal_with_avatars; + GtkRadioAction *normal_size; + GtkRadioAction *compact_size; + GtkUIManager *ui_manager; - GtkAction *chat_history; + GtkAction *view_history; GtkAction *room_join_favorites; GtkWidget *room_menu; GtkWidget *room_separator; @@ -133,7 +139,7 @@ main_window_flash_foreach (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { - FlashForeachData *data = (FlashForeachData*) user_data; + FlashForeachData *data = (FlashForeachData *) user_data; EmpathyContact *contact; const gchar *icon_name; GtkTreePath *parent_path = NULL; @@ -165,7 +171,7 @@ main_window_flash_foreach (GtkTreeModel *model, /* To make sure the parent is shown correctly, we emit * the row-changed signal on the parent so it prompts - * it to be refreshed by the filter func. + * it to be refreshed by the filter func. */ if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) { parent_path = gtk_tree_model_get_path (model, &parent_iter); @@ -195,7 +201,7 @@ main_window_flash_cb (EmpathyMainWindow *window) events = empathy_event_manager_get_events (window->event_manager); for (l = events; l; l = l->next) { data.event = l->data; - if (!data.event->contact) { + if (!data.event->contact || !data.event->must_ack) { continue; } @@ -299,7 +305,7 @@ static void main_window_error_edit_clicked_cb (GtkButton *button, EmpathyMainWindow *window) { - McAccount *account; + EmpathyAccount *account; GtkWidget *error_widget; account = g_object_get_data (G_OBJECT (button), "account"); @@ -314,7 +320,7 @@ static void main_window_error_clear_clicked_cb (GtkButton *button, EmpathyMainWindow *window) { - McAccount *account; + EmpathyAccount *account; GtkWidget *error_widget; account = g_object_get_data (G_OBJECT (button), "account"); @@ -325,7 +331,7 @@ main_window_error_clear_clicked_cb (GtkButton *button, static void main_window_error_display (EmpathyMainWindow *window, - McAccount *account, + EmpathyAccount *account, const gchar *message) { GtkWidget *child; @@ -346,7 +352,7 @@ main_window_error_display (EmpathyMainWindow *window, /* Just set the latest error and return */ str = g_markup_printf_escaped ("%s\n%s", - mc_account_get_display_name (account), + empathy_account_get_display_name (account), message); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); @@ -427,7 +433,7 @@ main_window_error_display (EmpathyMainWindow *window, gtk_misc_set_alignment (GTK_MISC (label), 0, 0); str = g_markup_printf_escaped ("%s\n%s", - mc_account_get_display_name (account), + empathy_account_get_display_name (account), message); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); @@ -479,7 +485,7 @@ main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *man static void main_window_connection_changed_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, TpConnectionStatusReason reason, TpConnectionStatus current, TpConnectionStatus previous, @@ -562,32 +568,39 @@ main_window_connection_changed_cb (EmpathyAccountManager *manager, static void main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor, EmpathyContact *contact, - McPresence current, - McPresence previous, + TpConnectionPresenceType current, + TpConnectionPresenceType previous, EmpathyMainWindow *window) { - McAccount *account; + EmpathyAccount *account; gboolean should_play; account = empathy_contact_get_account (contact); - should_play = !empathy_account_manager_is_account_just_connected (window->account_manager, account); + should_play = !empathy_account_is_just_connected (account); if (!should_play) { return; } - if (previous < MC_PRESENCE_AVAILABLE && current > MC_PRESENCE_OFFLINE) { - /* someone is logging in */ - empathy_sound_play (GTK_WIDGET (window->window), - EMPATHY_SOUND_CONTACT_CONNECTED); - return; - } - - if (previous > MC_PRESENCE_OFFLINE && current < MC_PRESENCE_AVAILABLE) { - /* someone is logging off */ - empathy_sound_play (GTK_WIDGET (window->window), - EMPATHY_SOUND_CONTACT_DISCONNECTED); - } + if (tp_connection_presence_type_cmp_availability (previous, + TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0) + { + /* contact was online */ + if (tp_connection_presence_type_cmp_availability (current, + TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) + /* someone is logging off */ + empathy_sound_play (GTK_WIDGET (window->window), + EMPATHY_SOUND_CONTACT_DISCONNECTED); + } + else + { + /* contact was offline */ + if (tp_connection_presence_type_cmp_availability (current, + TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0) + /* someone is logging in */ + empathy_sound_play (GTK_WIDGET (window->window), + EMPATHY_SOUND_CONTACT_CONNECTED); + } } static void @@ -595,7 +608,7 @@ main_window_accels_load (void) { gchar *filename; - filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL); + filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL); if (g_file_test (filename, G_FILE_TEST_EXISTS)) { DEBUG ("Loading from:'%s'", filename); gtk_accel_map_load (filename); @@ -610,7 +623,7 @@ main_window_accels_save (void) gchar *dir; gchar *file_with_path; - dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); + dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL); g_free (dir); @@ -638,7 +651,6 @@ main_window_destroy_cb (GtkWidget *widget, g_list_free (window->actions_connected); - g_object_unref (window->mc); g_object_unref (window->account_manager); g_object_unref (window->list_store); g_hash_table_destroy (window->errors); @@ -663,7 +675,7 @@ main_window_chat_quit_cb (GtkAction *action, } static void -main_window_chat_history_cb (GtkAction *action, +main_window_view_history_cb (GtkAction *action, EmpathyMainWindow *window) { empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window)); @@ -684,21 +696,14 @@ main_window_chat_add_contact_cb (GtkAction *action, } static void -main_window_chat_show_ft_manager (GtkAction *action, +main_window_view_show_ft_manager (GtkAction *action, EmpathyMainWindow *window) { - EmpathyFTManager *manager; - GtkWidget *dialog; - - manager = empathy_ft_manager_dup_singleton (); - dialog = empathy_ft_manager_get_dialog (manager); - - gtk_window_present (GTK_WINDOW (dialog)); - g_object_unref (manager); + empathy_ft_manager_show (); } static void -main_window_chat_show_offline_cb (GtkToggleAction *action, +main_window_view_show_offline_cb (GtkToggleAction *action, EmpathyMainWindow *window) { gboolean current; @@ -714,19 +719,139 @@ main_window_chat_show_offline_cb (GtkToggleAction *action, //empathy_sound_set_enabled (TRUE); } +static void +main_window_notify_sort_contact_cb (EmpathyConf *conf, + const gchar *key, + EmpathyMainWindow *window) +{ + gchar *str = NULL; + + if (empathy_conf_get_string (conf, key, &str) && str) { + GType type; + GEnumClass *enum_class; + GEnumValue *enum_value; + + type = empathy_contact_list_store_sort_get_type (); + enum_class = G_ENUM_CLASS (g_type_class_peek (type)); + enum_value = g_enum_get_value_by_nick (enum_class, str); + if (enum_value) { + /* By changing the value of the GtkRadioAction, + it emits a signal that calls main_window_view_sort_contacts_cb + which updates the contacts list */ + gtk_radio_action_set_current_value (window->sort_by_name, + enum_value->value); + } else { + g_warning ("Wrong value for sort_criterium configuration : %s", str); + } + g_free (str); + } +} + +static void +main_window_view_sort_contacts_cb (GtkRadioAction *action, + GtkRadioAction *current, + EmpathyMainWindow *window) +{ + EmpathyContactListStoreSort value; + GSList *group; + GType type; + GEnumClass *enum_class; + GEnumValue *enum_value; + + value = gtk_radio_action_get_current_value (action); + group = gtk_radio_action_get_group (action); + + /* Get string from index */ + type = empathy_contact_list_store_sort_get_type (); + enum_class = G_ENUM_CLASS (g_type_class_peek (type)); + enum_value = g_enum_get_value (enum_class, g_slist_index (group, current)); + + if (!enum_value) { + g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d", + g_slist_index (group, action)); + } else { + empathy_conf_set_string (empathy_conf_get (), + EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, + enum_value->value_nick); + } + empathy_contact_list_store_set_sort_criterium (window->list_store, value); +} + +/* Matches GtkRadioAction values set in empathy-main-window.ui */ +#define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0 +#define CONTACT_LIST_NORMAL_SIZE 1 +#define CONTACT_LIST_COMPACT_SIZE 2 + +static void +main_window_view_contacts_list_size_cb (GtkRadioAction *action, + GtkRadioAction *current, + EmpathyMainWindow *window) +{ + gint value; + + value = gtk_radio_action_get_current_value (action); + + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_UI_SHOW_AVATARS, + value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS); + empathy_conf_set_bool (empathy_conf_get (), + EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST, + value == CONTACT_LIST_COMPACT_SIZE); + + empathy_contact_list_store_set_show_avatars (window->list_store, + value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS); + empathy_contact_list_store_set_is_compact (window->list_store, + value == CONTACT_LIST_COMPACT_SIZE); +} + +static void +main_window_notify_contact_list_size_cb (EmpathyConf *conf, + const gchar *key, + EmpathyMainWindow *window) +{ + gboolean show_avatars; + gboolean compact_contact_list; + gint value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS; + + if (empathy_conf_get_bool (conf, + EMPATHY_PREFS_UI_SHOW_AVATARS, + &show_avatars) + && empathy_conf_get_bool (conf, + EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST, + &compact_contact_list)) { + if (compact_contact_list) { + value = CONTACT_LIST_COMPACT_SIZE; + } else if (show_avatars) { + value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS; + } else { + value = CONTACT_LIST_NORMAL_SIZE; + } + } + /* By changing the value of the GtkRadioAction, + it emits a signal that calls main_window_view_contacts_list_size_cb + which updates the contacts list */ + gtk_radio_action_set_current_value (window->normal_with_avatars, value); +} + +static void +main_window_view_show_map_cb (GtkCheckMenuItem *item, + EmpathyMainWindow *window) +{ +#if HAVE_LIBCHAMPLAIN + empathy_map_view_show (); +#endif +} + static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom) { - EmpathyAccountManager *manager; - McAccount *account; + EmpathyAccount *account; TpConnection *connection; const gchar *room; - manager = empathy_account_manager_dup_singleton (); account = empathy_chatroom_get_account (chatroom); - connection = empathy_account_manager_get_connection (manager, account); + connection = empathy_account_get_connection (account); room = empathy_chatroom_get_room (chatroom); - g_object_unref (manager); if (connection != NULL) { DEBUG ("Requesting channel for '%s'", room); @@ -935,6 +1060,13 @@ main_window_help_about_cb (GtkAction *action, empathy_about_dialog_new (GTK_WINDOW (window->window)); } +static void +main_window_help_debug_cb (GtkAction *action, + EmpathyMainWindow *window) +{ + empathy_debug_window_new (GTK_WINDOW (window->window)); +} + static void main_window_help_contents_cb (GtkAction *action, EmpathyMainWindow *window) @@ -990,10 +1122,10 @@ main_window_configure_event_cb (GtkWidget *widget, static void main_window_account_created_or_deleted_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, EmpathyMainWindow *window) { - gtk_action_set_sensitive (window->chat_history, + gtk_action_set_sensitive (window->view_history, empathy_account_manager_get_count (manager) > 0); } @@ -1009,56 +1141,6 @@ main_window_notify_show_offline_cb (EmpathyConf *conf, } } -static void -main_window_notify_show_avatars_cb (EmpathyConf *conf, - const gchar *key, - EmpathyMainWindow *window) -{ - gboolean show_avatars; - - if (empathy_conf_get_bool (conf, key, &show_avatars)) { - empathy_contact_list_store_set_show_avatars (window->list_store, - show_avatars); - } -} - -static void -main_window_notify_compact_contact_list_cb (EmpathyConf *conf, - const gchar *key, - EmpathyMainWindow *window) -{ - gboolean compact_contact_list; - - if (empathy_conf_get_bool (conf, key, &compact_contact_list)) { - empathy_contact_list_store_set_is_compact (window->list_store, - compact_contact_list); - } -} - -static void -main_window_notify_sort_criterium_cb (EmpathyConf *conf, - const gchar *key, - EmpathyMainWindow *window) -{ - gchar *str = NULL; - - if (empathy_conf_get_string (conf, key, &str) && str) { - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = empathy_contact_list_store_sort_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_peek (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - g_free (str); - - if (enum_value) { - empathy_contact_list_store_set_sort_criterium (window->list_store, - enum_value->value); - } - } -} - static void main_window_connection_items_setup (EmpathyMainWindow *window, GtkBuilder *gui) @@ -1097,10 +1179,9 @@ empathy_main_window_show (void) GtkWidget *sw; GtkToggleAction *show_offline_widget; GtkWidget *ebox; + GtkAction *show_map_widget; GtkToolItem *item; gboolean show_offline; - gboolean show_avatars; - gboolean compact_contact_list; gint x, y, w, h; gchar *filename; GSList *l; @@ -1119,8 +1200,14 @@ empathy_main_window_show (void) "main_vbox", &window->main_vbox, "errors_vbox", &window->errors_vbox, "ui_manager", &window->ui_manager, - "chat_show_offline", &show_offline_widget, - "chat_history", &window->chat_history, + "view_show_offline", &show_offline_widget, + "view_sort_by_name", &window->sort_by_name, + "view_sort_by_status", &window->sort_by_status, + "view_normal_size_with_avatars", &window->normal_with_avatars, + "view_normal_size", &window->normal_size, + "view_compact_size", &window->compact_size, + "view_history", &window->view_history, + "view_show_map", &show_map_widget, "room_join_favorites", &window->room_join_favorites, "presence_toolbar", &window->presence_toolbar, "roster_scrolledwindow", &sw, @@ -1132,18 +1219,22 @@ empathy_main_window_show (void) "main_window", "configure_event", main_window_configure_event_cb, "chat_quit", "activate", main_window_chat_quit_cb, "chat_new_message", "activate", main_window_chat_new_message_cb, - "chat_history", "activate", main_window_chat_history_cb, + "view_history", "activate", main_window_view_history_cb, "room_join_new", "activate", main_window_room_join_new_cb, "room_join_favorites", "activate", main_window_room_join_favorites_cb, "room_manage_favorites", "activate", main_window_room_manage_favorites_cb, "chat_add_contact", "activate", main_window_chat_add_contact_cb, - "chat_show_ft_manager", "activate", main_window_chat_show_ft_manager, - "chat_show_offline", "toggled", main_window_chat_show_offline_cb, + "view_show_ft_manager", "activate", main_window_view_show_ft_manager, + "view_show_offline", "toggled", main_window_view_show_offline_cb, + "view_sort_by_name", "changed", main_window_view_sort_contacts_cb, + "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb, + "view_show_map", "activate", main_window_view_show_map_cb, "edit", "activate", main_window_edit_cb, "edit_accounts", "activate", main_window_edit_accounts_cb, "edit_personal_information", "activate", main_window_edit_personal_information_cb, "edit_preferences", "activate", main_window_edit_preferences_cb, "help_about", "activate", main_window_help_about_cb, + "help_debug", "activate", main_window_help_debug_cb, "help_contents", "activate", main_window_help_contents_cb, NULL); @@ -1153,15 +1244,18 @@ empathy_main_window_show (void) g_object_ref (window->ui_manager); g_object_unref (gui); - window->mc = empathy_mission_control_dup_singleton (); +#if !HAVE_LIBCHAMPLAIN + gtk_action_set_visible (show_map_widget, FALSE); +#endif + window->account_manager = empathy_account_manager_dup_singleton (); g_signal_connect (window->account_manager, "account-connection-changed", G_CALLBACK (main_window_connection_changed_cb), window); - window->errors = g_hash_table_new_full (empathy_account_hash, - empathy_account_equal, + window->errors = g_hash_table_new_full (g_direct_hash, + g_direct_equal, g_object_unref, NULL); @@ -1284,37 +1378,34 @@ empathy_main_window_show (void) gtk_toggle_action_set_active (show_offline_widget, show_offline); - /* Show avatars ? */ - empathy_conf_get_bool (conf, - EMPATHY_PREFS_UI_SHOW_AVATARS, - &show_avatars); + /* Sort by name / by status ? */ empathy_conf_notify_add (conf, - EMPATHY_PREFS_UI_SHOW_AVATARS, - (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb, - window); - empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars); + EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, + (EmpathyConfNotifyFunc) main_window_notify_sort_contact_cb, + window); - /* Is compact ? */ - empathy_conf_get_bool (conf, - EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST, - &compact_contact_list); - empathy_conf_notify_add (conf, - EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST, - (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb, - window); - empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list); + main_window_notify_sort_contact_cb (conf, + EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, + window); - /* Sort criterium */ + /* Contacts list size */ empathy_conf_notify_add (conf, - EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, - (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb, - window); - main_window_notify_sort_criterium_cb (conf, - EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, - window); + EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST, + (EmpathyConfNotifyFunc) main_window_notify_contact_list_size_cb, + window); + empathy_conf_notify_add (conf, + EMPATHY_PREFS_UI_SHOW_AVATARS, + (EmpathyConfNotifyFunc) main_window_notify_contact_list_size_cb, + window); + + main_window_notify_contact_list_size_cb (conf, + EMPATHY_PREFS_UI_SHOW_AVATARS, + window); main_window_update_status (window, window->account_manager); + gtk_widget_show (window->window); + return window->window; }