aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2007-05-02 05:54:08 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-05-02 05:54:08 +0800
commit8e7b3f45c92b2c7523c824b247308cf74e30b80b (patch)
treea6a4363c43bd12be1ee32f8965ef06345baa5399 /libempathy-gtk
parentf4205e743dac600a40b20cccc87d049f591beda2 (diff)
downloadgsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.tar
gsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.tar.gz
gsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.tar.bz2
gsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.tar.lz
gsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.tar.xz
gsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.tar.zst
gsoc2013-empathy-8e7b3f45c92b2c7523c824b247308cf74e30b80b.zip
[darcs-to-svn @ GossipMainWindow]
svn path=/trunk/; revision=20
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/Makefile.am3
-rw-r--r--libempathy-gtk/empathy-main-window.c835
-rw-r--r--libempathy-gtk/empathy-main-window.glade492
-rw-r--r--libempathy-gtk/empathy-main-window.h34
-rw-r--r--libempathy-gtk/ephy-spinner.c977
-rw-r--r--libempathy-gtk/ephy-spinner.h70
-rw-r--r--libempathy-gtk/gossip-contact-list.c119
7 files changed, 2434 insertions, 96 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index ea1bbe29d..58582bfd6 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -9,6 +9,8 @@ AM_CPPFLAGS = \
noinst_LTLIBRARIES = libempathy-gtk.la
libempathy_gtk_la_SOURCES = \
+ ephy-spinner.c ephy-spinner.h \
+ empathy-main-window.c empathy-main-window.h \
gossip-accounts-dialog.c gossip-accounts-dialog.h \
gossip-account-widget-generic.c gossip-account-widget-generic.h \
gossip-account-widget-jabber.c gossip-account-widget-jabber.h \
@@ -38,6 +40,7 @@ libempathy_gtk_includedir = $(includedir)/empathy/
gladedir = $(datadir)/empathy
glade_DATA = \
+ empathy-main-window.glade \
gossip-accounts-dialog.glade \
gossip-account-widget-jabber.glade \
gossip-chat.glade
diff --git a/libempathy-gtk/empathy-main-window.c b/libempathy-gtk/empathy-main-window.c
new file mode 100644
index 000000000..257ade9bd
--- /dev/null
+++ b/libempathy-gtk/empathy-main-window.c
@@ -0,0 +1,835 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * 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.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ */
+
+#include <config.h>
+
+#include <sys/stat.h>
+#include <gtk/gtk.h>
+#include <glade/glade.h>
+#include <glib/gi18n.h>
+
+#include <libempathy/gossip-conf.h>
+#include <libempathy/gossip-contact.h>
+#include <libempathy/gossip-debug.h>
+
+#include "empathy-main-window.h"
+#include "ephy-spinner.h"
+#include "gossip-contact-list.h"
+#include "gossip-presence-chooser.h"
+#include "gossip-ui-utils.h"
+#include "gossip-status-presets.h"
+#include "gossip-geometry.h"
+#include "gossip-preferences.h"
+
+#define DEBUG_DOMAIN "EmpathyMainWindow"
+
+/* Minimum width of roster window if something goes wrong. */
+#define MIN_WIDTH 50
+
+/* Accels (menu shortcuts) can be configured and saved */
+#define ACCELS_FILENAME "accels.txt"
+
+/* Flashing delay for icons (milliseconds). */
+#define FLASH_TIMEOUT 500
+
+/* Name in the geometry file */
+#define GEOMETRY_NAME "main-window"
+
+typedef struct {
+ GossipContactList *contact_list;
+
+ /* Main widgets */
+ GtkWidget *window;
+ GtkWidget *main_vbox;
+
+ /* Tooltips for all widgets */
+ GtkTooltips *tooltips;
+
+ /* Menu widgets */
+ GtkWidget *chat_connect;
+ GtkWidget *chat_disconnect;
+ GtkWidget *chat_search;
+ GtkWidget *room;
+ GtkWidget *room_menu;
+ GtkWidget *room_sep;
+ GtkWidget *room_join_favorites;
+ GtkWidget *edit_context;
+ GtkWidget *edit_context_separator;
+
+ /* Throbber */
+ GtkWidget *throbber;
+
+ /* Widgets that are enabled when we're connected/disconnected */
+ GList *widgets_connected;
+ GList *widgets_disconnected;
+
+ /* Status popup */
+ GtkWidget *presence_toolbar;
+ GtkWidget *presence_chooser;
+
+ /* Misc */
+ guint size_timeout_id;
+} EmpathyMainWindow;
+
+static void main_window_destroy_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_favorite_chatroom_menu_setup (void);
+static void main_window_chat_quit_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_connect_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_disconnect_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_search_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_new_message_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_history_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_room_join_new_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_room_join_favorites_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_room_manage_favorites_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_add_contact_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
+ EmpathyMainWindow *window);
+static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ EmpathyMainWindow *window);
+static void main_window_edit_accounts_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_edit_personal_information_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_edit_preferences_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_help_about_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static void main_window_help_contents_cb (GtkWidget *widget,
+ EmpathyMainWindow *window);
+static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
+ GdkEventButton *event,
+ gpointer user_data);
+static void main_window_accels_load (void);
+static void main_window_accels_save (void);
+static void main_window_connection_items_setup (EmpathyMainWindow *window,
+ GladeXML *glade);
+//static void main_window_connection_items_update (void);
+static void main_window_presence_chooser_changed_cb (GtkWidget *chooser,
+ GossipPresenceState state,
+ const gchar *status,
+ EmpathyMainWindow *window);
+static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
+static gboolean main_window_configure_event_cb (GtkWidget *widget,
+ GdkEventConfigure *event,
+ EmpathyMainWindow *window);
+static void main_window_notify_show_offline_cb (GossipConf *conf,
+ const gchar *key,
+ gpointer check_menu_item);
+static void main_window_notify_show_avatars_cb (GossipConf *conf,
+ const gchar *key,
+ EmpathyMainWindow *window);
+static void main_window_notify_compact_contact_list_cb (GossipConf *conf,
+ const gchar *key,
+ EmpathyMainWindow *window);
+
+GtkWidget *
+empathy_main_window_new (void)
+{
+ EmpathyMainWindow *window;
+ GladeXML *glade;
+ GossipConf *conf;
+ GtkWidget *sw;
+ GtkWidget *show_offline_widget;
+ GtkWidget *ebox;
+ GtkToolItem *item;
+ gchar *str;
+ gboolean show_offline;
+ gboolean show_avatars;
+ gboolean compact_contact_list;
+ gint x, y, w, h;
+
+ window = g_new0 (EmpathyMainWindow, 1);
+
+ /* Set up interface */
+ glade = gossip_glade_get_file ("empathy-main-window.glade",
+ "main_window",
+ NULL,
+ "main_window", &window->window,
+ "main_vbox", &window->main_vbox,
+ "chat_connect", &window->chat_connect,
+ "chat_disconnect", &window->chat_disconnect,
+ "chat_search", &window->chat_search,
+ "chat_show_offline", &show_offline_widget,
+ "room", &window->room,
+ "room_sep", &window->room_sep,
+ "room_join_favorites", &window->room_join_favorites,
+ "edit_context", &window->edit_context,
+ "edit_context_separator", &window->edit_context_separator,
+ "presence_toolbar", &window->presence_toolbar,
+ "roster_scrolledwindow", &sw,
+ NULL);
+
+ gossip_glade_connect (glade,
+ window,
+ "main_window", "destroy", main_window_destroy_cb,
+ "main_window", "configure_event", main_window_configure_event_cb,
+ "chat_quit", "activate", main_window_chat_quit_cb,
+ "chat_connect", "activate", main_window_chat_connect_cb,
+ "chat_disconnect", "activate", main_window_chat_disconnect_cb,
+ "chat_search", "activate", main_window_chat_search_cb,
+ "chat_new_message", "activate", main_window_chat_new_message_cb,
+ "chat_history", "activate", main_window_chat_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_offline", "toggled", main_window_chat_show_offline_cb,
+ "edit", "button-press-event", main_window_edit_button_press_event_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_contents", "activate", main_window_help_contents_cb,
+ NULL);
+
+ /* Set up connection related widgets. */
+ main_window_connection_items_setup (window, glade);
+ g_object_unref (glade);
+
+ window->tooltips = g_object_ref_sink (gtk_tooltips_new ());
+
+ /* Set up menu */
+ main_window_favorite_chatroom_menu_setup ();
+
+ gtk_widget_hide (window->edit_context);
+ gtk_widget_hide (window->edit_context_separator);
+
+ /* Set up presence chooser */
+ window->presence_chooser = gossip_presence_chooser_new ();
+ gtk_widget_show (window->presence_chooser);
+ gossip_presence_chooser_set_flash_interval (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
+ FLASH_TIMEOUT);
+
+ item = gtk_tool_item_new ();
+ gtk_widget_show (GTK_WIDGET (item));
+ gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
+ gtk_tool_item_set_is_important (item, TRUE);
+ gtk_tool_item_set_expand (item, TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
+
+ g_signal_connect (window->presence_chooser,
+ "changed",
+ G_CALLBACK (main_window_presence_chooser_changed_cb),
+ window);
+
+ window->widgets_connected = g_list_prepend (window->widgets_connected,
+ window->presence_chooser);
+
+ /* Set up the throbber */
+ ebox = gtk_event_box_new ();
+ gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
+
+ window->throbber = ephy_spinner_new ();
+ ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
+
+ item = gtk_tool_item_new ();
+ gtk_container_add (GTK_CONTAINER (item), ebox);
+ gtk_widget_show_all (GTK_WIDGET (item));
+
+ gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
+
+ str = _("Show and edit accounts");
+ gtk_tooltips_set_tip (GTK_TOOLTIPS (window->tooltips),
+ ebox, str, str);
+
+ g_signal_connect (ebox,
+ "button-press-event",
+ G_CALLBACK (main_window_throbber_button_press_event_cb),
+ NULL);
+
+ /* Set up contact list. */
+ gossip_status_presets_get_all ();
+ window->contact_list = gossip_contact_list_new ();
+ gtk_widget_show (GTK_WIDGET (window->contact_list));
+ gtk_container_add (GTK_CONTAINER (sw),
+ GTK_WIDGET (window->contact_list));
+
+ /* Load user-defined accelerators. */
+ main_window_accels_load ();
+
+ /* Set window size. */
+ gossip_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
+
+ if (w >= 1 && h >= 1) {
+ /* Use the defaults from the glade file if we
+ * don't have good w, h geometry.
+ */
+ gossip_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
+ gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
+ }
+
+ if (x >= 0 && y >= 0) {
+ /* Let the window manager position it if we
+ * don't have good x, y coordinates.
+ */
+ gossip_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
+ gtk_window_move (GTK_WINDOW (window->window), x, y);
+ }
+
+ /* Get preferences */
+ conf = gossip_conf_get ();
+ gossip_conf_get_bool (conf,
+ GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
+ &show_offline);
+ gossip_conf_notify_add (conf,
+ GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
+ main_window_notify_show_offline_cb,
+ show_offline_widget);
+
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
+ show_offline);
+
+ gossip_conf_get_bool (conf,
+ GOSSIP_PREFS_UI_SHOW_AVATARS,
+ &show_avatars);
+ gossip_conf_notify_add (conf,
+ GOSSIP_PREFS_UI_SHOW_AVATARS,
+ (GossipConfNotifyFunc) main_window_notify_show_avatars_cb,
+ window);
+ gossip_conf_get_bool (conf,
+ GOSSIP_PREFS_UI_COMPACT_CONTACT_LIST,
+ &compact_contact_list);
+ gossip_conf_notify_add (conf,
+ GOSSIP_PREFS_UI_COMPACT_CONTACT_LIST,
+ (GossipConfNotifyFunc) main_window_notify_compact_contact_list_cb,
+ window);
+
+ g_object_set (window->contact_list,
+ "show-avatars", show_avatars,
+ "is-compact", compact_contact_list,
+ NULL);
+
+ return window->window;
+}
+
+static void
+main_window_destroy_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ /* Save user-defined accelerators. */
+ main_window_accels_save ();
+
+ if (window->size_timeout_id) {
+ g_source_remove (window->size_timeout_id);
+ }
+
+ g_list_free (window->widgets_connected);
+ g_list_free (window->widgets_disconnected);
+
+ g_object_unref (window->tooltips);
+
+ g_free (window);
+}
+
+static void
+main_window_favorite_chatroom_menu_setup (void)
+{
+}
+
+static void
+main_window_chat_quit_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ gtk_widget_destroy (window->window);
+}
+
+static void
+main_window_chat_connect_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+}
+
+static void
+main_window_chat_disconnect_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+}
+
+static void
+main_window_chat_search_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+}
+
+static void
+main_window_chat_new_message_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_new_message_dialog_show (GTK_WINDOW (window->window));
+}
+
+static void
+main_window_chat_history_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_log_window_show (NULL, NULL);
+}
+
+static void
+main_window_room_join_new_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_new_chatroom_dialog_show (GTK_WINDOW (window->window));
+}
+
+static void
+main_window_room_join_favorites_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_session_chatroom_join_favorites (window->session);
+}
+
+static void
+main_window_room_manage_favorites_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_chatrooms_window_show (NULL, FALSE);
+}
+
+static void
+main_window_chat_add_contact_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_add_contact_dialog_show (GTK_WINDOW (window->window), NULL);
+}
+
+static void
+main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
+ EmpathyMainWindow *window)
+{
+ gboolean current;
+
+ current = gtk_check_menu_item_get_active (item);
+
+ gossip_conf_set_bool (gossip_conf_get (),
+ GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
+ current);
+
+ /* Turn off sound just while we alter the contact list. */
+ // FIXME: gossip_sound_set_enabled (FALSE);
+ g_object_set (window->contact_list, "show_offline", current, NULL);
+ //gossip_sound_set_enabled (TRUE);
+}
+
+static gboolean
+main_window_edit_button_press_event_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ EmpathyMainWindow *window)
+{
+ GossipContact *contact;
+ gchar *group;
+
+ if (!event->button == 1) {
+ return FALSE;
+ }
+
+ group = gossip_contact_list_get_selected_group (window->contact_list);
+ if (group) {
+ GtkMenuItem *item;
+ GtkWidget *label;
+ GtkWidget *submenu;
+
+ item = GTK_MENU_ITEM (window->edit_context);
+ label = gtk_bin_get_child (GTK_BIN (item));
+ gtk_label_set_text (GTK_LABEL (label), _("Group"));
+
+ gtk_widget_show (window->edit_context);
+ gtk_widget_show (window->edit_context_separator);
+
+ submenu = gossip_contact_list_get_group_menu (window->contact_list);
+ gtk_menu_item_set_submenu (item, submenu);
+
+ g_free (group);
+
+ return FALSE;
+ }
+
+ contact = gossip_contact_list_get_selected (window->contact_list);
+ if (contact) {
+ GtkMenuItem *item;
+ GtkWidget *label;
+ GtkWidget *submenu;
+
+ item = GTK_MENU_ITEM (window->edit_context);
+ label = gtk_bin_get_child (GTK_BIN (item));
+ gtk_label_set_text (GTK_LABEL (label), _("Contact"));
+
+ gtk_widget_show (window->edit_context);
+ gtk_widget_show (window->edit_context_separator);
+
+ submenu = gossip_contact_list_get_contact_menu (window->contact_list,
+ contact);
+ gtk_menu_item_set_submenu (item, submenu);
+
+ g_object_unref (contact);
+
+ return FALSE;
+ }
+
+ gtk_widget_hide (window->edit_context);
+ gtk_widget_hide (window->edit_context_separator);
+
+ return FALSE;
+}
+
+static void
+main_window_edit_accounts_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_accounts_dialog_show (NULL);
+}
+
+static void
+main_window_edit_personal_information_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_vcard_dialog_show (GTK_WINDOW (window->window));
+}
+
+static void
+main_window_edit_preferences_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_preferences_show ();
+}
+
+static void
+main_window_help_about_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_about_dialog_new (GTK_WINDOW (window->window));
+}
+
+static void
+main_window_help_contents_cb (GtkWidget *widget,
+ EmpathyMainWindow *window)
+{
+ //gossip_help_show ();
+}
+
+static gboolean
+main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ if (event->type != GDK_BUTTON_PRESS ||
+ event->button != 1) {
+ return FALSE;
+ }
+
+ //gossip_accounts_dialog_show (NULL);
+
+ return FALSE;
+}
+#if 0
+static void
+main_window_session_protocol_connecting_cb (GossipSession *session,
+ GossipAccount *account,
+ GossipProtocol *protocol,
+ gpointer user_data)
+{
+ GossipAppPriv *priv;
+ const gchar *name;
+
+ priv = GET_PRIV (app);
+
+ name = gossip_account_get_name (account);
+ gossip_debug (DEBUG_DOMAIN, "Connecting account:'%s'", name);
+
+ ephy_spinner_start (EPHY_SPINNER (window->throbber));
+}
+
+static void
+main_window_session_protocol_connected_cb (GossipSession *session,
+ GossipAccount *account,
+ GossipProtocol *protocol,
+ gpointer user_data)
+{
+ GossipAppPriv *priv;
+ gboolean connecting;
+ const gchar *name;
+
+ priv = GET_PRIV (app);
+
+ name = gossip_account_get_name (account);
+ gossip_debug (DEBUG_DOMAIN, "Connected account:'%s'", name);
+
+ gossip_session_count_accounts (window->session,
+ NULL,
+ &connecting,
+ NULL);
+
+ if (connecting < 1) {
+ ephy_spinner_stop (EPHY_SPINNER (window->throbber));
+ }
+
+ g_hash_table_remove (window->errors, account);
+ g_hash_table_remove (window->reconnects, account);
+
+ app_connection_items_update ();
+ app_favorite_chatroom_menu_update ();
+
+ /* Use saved presence */
+ gossip_app_set_presence (gossip_status_presets_get_default_state (),
+ gossip_status_presets_get_default_status());
+
+ app_presence_updated ();
+}
+
+static void
+main_window_session_protocol_disconnected_cb (GossipSession *session,
+ GossipAccount *account,
+ GossipProtocol *protocol,
+ gint reason,
+ gpointer user_data)
+{
+ GossipAppPriv *priv;
+ gboolean connecting;
+ gboolean should_reconnect;
+ const gchar *name;
+
+ priv = GET_PRIV (app);
+
+ name = gossip_account_get_name (account);
+ gossip_debug (DEBUG_DOMAIN, "Disconnected account:'%s'", name);
+
+ gossip_session_count_accounts (window->session,
+ NULL,
+ &connecting,
+ NULL);
+
+ if (connecting < 1) {
+ ephy_spinner_stop (EPHY_SPINNER (window->throbber));
+ }
+
+ app_connection_items_update ();
+ app_favorite_chatroom_menu_update ();
+ app_presence_updated ();
+
+ should_reconnect = reason != GOSSIP_PROTOCOL_DISCONNECT_ASKED;
+
+
+ should_reconnect &= !g_hash_table_lookup (window->reconnects, account);
+
+ if (should_reconnect) {
+ guint id;
+
+ /* Unexpected disconnection, try to reconnect */
+ id = g_timeout_add (RETRY_CONNECT_TIMEOUT * 1000,
+ (GSourceFunc) app_reconnect_cb,
+ account);
+ g_hash_table_insert (window->reconnects,
+ g_object_ref (account),
+ &id);
+ }
+}
+#endif
+
+/*
+ * Accels
+ */
+static void
+main_window_accels_load (void)
+{
+ gchar *filename;
+
+ filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
+ if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ gossip_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
+ gtk_accel_map_load (filename);
+ }
+
+ g_free (filename);
+}
+
+static void
+main_window_accels_save (void)
+{
+ gchar *dir;
+ gchar *file_with_path;
+
+ dir = g_build_filename (g_get_home_dir (), ".gnome2", 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);
+
+ gossip_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
+ gtk_accel_map_save (file_with_path);
+
+ g_free (file_with_path);
+}
+
+static void
+main_window_connection_items_setup (EmpathyMainWindow *window,
+ GladeXML *glade)
+{
+ GList *list;
+ GtkWidget *w;
+ gint i;
+ const gchar *widgets_connected[] = {
+ "chat_disconnect",
+ "room",
+ "chat_new_message",
+ "chat_add_contact",
+ "edit_personal_information"
+ };
+ const gchar *widgets_disconnected[] = {
+ "chat_connect"
+ };
+
+ for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
+ w = glade_xml_get_widget (glade, widgets_connected[i]);
+ list = g_list_prepend (list, w);
+ }
+
+ window->widgets_connected = list;
+
+ for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
+ w = glade_xml_get_widget (glade, widgets_disconnected[i]);
+ list = g_list_prepend (list, w);
+ }
+
+ window->widgets_disconnected = list;
+}
+
+#if 0
+FIXME:
+static void
+main_window_connection_items_update (void)
+{
+ GList *l;
+ guint connected = 0;
+ guint disconnected = 0;
+
+ /* Get account count for:
+ * - connected and disabled,
+ * - connected and enabled
+ * - disabled and enabled
+ */
+ gossip_session_count_accounts (window->session,
+ &connected,
+ NULL,
+ &disconnected);
+
+ for (l = window->widgets_connected; l; l = l->next) {
+ gtk_widget_set_sensitive (l->data, (connected > 0));
+ }
+
+ for (l = window->widgets_disconnected; l; l = l->next) {
+ gtk_widget_set_sensitive (l->data, (disconnected > 0));
+ }
+}
+#endif
+
+static void
+main_window_presence_chooser_changed_cb (GtkWidget *chooser,
+ GossipPresenceState state,
+ const gchar *status,
+ EmpathyMainWindow *window)
+{
+ gossip_status_presets_set_default (state, status);
+}
+
+static gboolean
+main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
+{
+ gint x, y, w, h;
+
+ gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
+ gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
+
+ gossip_geometry_save (GEOMETRY_NAME, x, y, w, h);
+
+ window->size_timeout_id = 0;
+
+ return FALSE;
+}
+
+static gboolean
+main_window_configure_event_cb (GtkWidget *widget,
+ GdkEventConfigure *event,
+ EmpathyMainWindow *window)
+{
+ if (window->size_timeout_id) {
+ g_source_remove (window->size_timeout_id);
+ }
+
+ window->size_timeout_id = g_timeout_add (500,
+ (GSourceFunc) main_window_configure_event_timeout_cb,
+ window);
+
+ return FALSE;
+}
+
+static void
+main_window_notify_show_offline_cb (GossipConf *conf,
+ const gchar *key,
+ gpointer check_menu_item)
+{
+ gboolean show_offline;
+
+ if (gossip_conf_get_bool (conf, key, &show_offline)) {
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
+ show_offline);
+ }
+}
+
+static void
+main_window_notify_show_avatars_cb (GossipConf *conf,
+ const gchar *key,
+ EmpathyMainWindow *window)
+{
+ gboolean show_avatars;
+
+ if (gossip_conf_get_bool (conf, key, &show_avatars)) {
+ gossip_contact_list_set_show_avatars (window->contact_list,
+ show_avatars);
+ }
+}
+
+static void
+main_window_notify_compact_contact_list_cb (GossipConf *conf,
+ const gchar *key,
+ EmpathyMainWindow *window)
+{
+ gboolean compact_contact_list;
+
+ if (gossip_conf_get_bool (conf, key, &compact_contact_list)) {
+ gossip_contact_list_set_is_compact (window->contact_list,
+ compact_contact_list);
+ }
+}
+
diff --git a/libempathy-gtk/empathy-main-window.glade b/libempathy-gtk/empathy-main-window.glade
new file mode 100644
index 000000000..3dacc2005
--- /dev/null
+++ b/libempathy-gtk/empathy-main-window.glade
@@ -0,0 +1,492 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+
+<widget class="GtkWindow" id="main_window">
+ <property name="title" translatable="yes">Contact List - Empathy</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="modal">False</property>
+ <property name="default_width">225</property>
+ <property name="default_height">325</property>
+ <property name="resizable">True</property>
+ <property name="destroy_with_parent">False</property>
+ <property name="decorated">True</property>
+ <property name="skip_taskbar_hint">False</property>
+ <property name="skip_pager_hint">False</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+ <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+ <property name="focus_on_map">True</property>
+ <property name="urgency_hint">False</property>
+
+ <child>
+ <widget class="GtkVBox" id="main_vbox">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkMenuBar" id="menubar2">
+ <property name="visible">True</property>
+ <property name="pack_direction">GTK_PACK_DIRECTION_LTR</property>
+ <property name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property>
+
+ <child>
+ <widget class="GtkMenuItem" id="chat">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Chat</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="chat_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_connect">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Connect</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image874">
+ <property name="visible">True</property>
+ <property name="stock">gtk-connect</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_disconnect">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Disconnect</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image875">
+ <property name="visible">True</property>
+ <property name="stock">gtk-disconnect</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator1">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_new_message">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_New Message...</property>
+ <property name="use_underline">True</property>
+ <accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image876">
+ <property name="visible">True</property>
+ <property name="pixbuf">gossip-message.png</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_history">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_View Previous Conversations</property>
+ <property name="use_underline">True</property>
+ <accelerator key="F3" modifiers="0" signal="activate"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image877">
+ <property name="visible">True</property>
+ <property name="stock">gtk-justify-left</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator5">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_add_contact">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Add Contact...</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image878">
+ <property name="visible">True</property>
+ <property name="stock">gtk-add</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_search">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Search</property>
+ <property name="use_underline">True</property>
+ <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image879">
+ <property name="visible">True</property>
+ <property name="stock">gtk-find</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator3">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkCheckMenuItem" id="chat_show_offline">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Show _Offline Contacts</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <accelerator key="H" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator6">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="chat_quit">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Quit</property>
+ <property name="use_underline">True</property>
+ <accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image880">
+ <property name="visible">True</property>
+ <property name="stock">gtk-quit</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="room">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Room</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="room_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="room_join_new">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Join _New...</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image881">
+ <property name="visible">True</property>
+ <property name="stock">gtk-new</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="room_join_favorites">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Join _Favorites</property>
+ <property name="use_underline">True</property>
+ <accelerator key="F5" modifiers="0" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="room_sep">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="room_sep2">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="room_manage_favorites">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Manage Favorites...</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image882">
+ <property name="visible">True</property>
+ <property name="pixbuf">gossip-group-message.png</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="edit">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Edit</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="edit_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="edit_context">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Context</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="edit_context_separator">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="edit_accounts">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Accounts</property>
+ <property name="use_underline">True</property>
+ <accelerator key="F4" modifiers="0" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="edit_personal_information">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Personal Information</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator2">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_preferences">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Preferences</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image883">
+ <property name="visible">True</property>
+ <property name="stock">gtk-preferences</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="help">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Help</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="help_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="help_contents">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Contents</property>
+ <property name="use_underline">True</property>
+ <accelerator key="F1" modifiers="0" signal="activate"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image884">
+ <property name="visible">True</property>
+ <property name="stock">gtk-help</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="help_about">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_About</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image885">
+ <property name="visible">True</property>
+ <property name="stock">gtk-about</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkToolbar" id="presence_toolbar">
+ <property name="visible">True</property>
+ <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+ <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
+ <property name="tooltips">True</property>
+ <property name="show_arrow">True</property>
+
+ <child>
+ <placeholder/>
+ </child>
+
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkVBox" id="errors_vbox">
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="roster_scrolledwindow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
+</glade-interface>
diff --git a/libempathy-gtk/empathy-main-window.h b/libempathy-gtk/empathy-main-window.h
new file mode 100644
index 000000000..91d2df205
--- /dev/null
+++ b/libempathy-gtk/empathy-main-window.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * 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.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ */
+
+#ifndef __EMPATHY_MAIN_WINDOW_H__
+#define __EMPATHY_MAIN_WINDOW_H__
+
+#include <gtk/gtkwidget.h>
+
+G_BEGIN_DECLS
+
+GtkWidget *empathy_main_window_new (void);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_MAIN_WINDOW_H__ */
diff --git a/libempathy-gtk/ephy-spinner.c b/libempathy-gtk/ephy-spinner.c
new file mode 100644
index 000000000..a8f371df3
--- /dev/null
+++ b/libempathy-gtk/ephy-spinner.c
@@ -0,0 +1,977 @@
+/*
+ * Copyright © 2000 Eazel, Inc.
+ * Copyright © 2002-2004 Marco Pesenti Gritti
+ * Copyright © 2004, 2006 Christian Persch
+ *
+ * Nautilus is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ *
+ * Author: Andy Hertzfeld <andy@eazel.com>
+ *
+ * Ephy port by Marco Pesenti Gritti <marco@it.gnome.org>
+ *
+ * $Id: ephy-spinner.c 2114 2006-12-25 12:15:00Z mr $
+ */
+
+#include "config.h"
+
+#include "ephy-spinner.h"
+
+/* #include "ephy-debug.h" */
+#define LOG(msg, args...)
+#define START_PROFILER(name)
+#define STOP_PROFILER(name)
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtkicontheme.h>
+#include <gtk/gtkiconfactory.h>
+#include <gtk/gtksettings.h>
+
+/* Spinner cache implementation */
+
+#define EPHY_TYPE_SPINNER_CACHE (ephy_spinner_cache_get_type())
+#define EPHY_SPINNER_CACHE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_SPINNER_CACHE, EphySpinnerCache))
+#define EPHY_SPINNER_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_SPINNER_CACHE, EphySpinnerCacheClass))
+#define EPHY_IS_SPINNER_CACHE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_SPINNER_CACHE))
+#define EPHY_IS_SPINNER_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_SPINNER_CACHE))
+#define EPHY_SPINNER_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_SPINNER_CACHE, EphySpinnerCacheClass))
+
+typedef struct _EphySpinnerCache EphySpinnerCache;
+typedef struct _EphySpinnerCacheClass EphySpinnerCacheClass;
+typedef struct _EphySpinnerCachePrivate EphySpinnerCachePrivate;
+
+struct _EphySpinnerCacheClass
+{
+ GObjectClass parent_class;
+};
+
+struct _EphySpinnerCache
+{
+ GObject parent_object;
+
+ /*< private >*/
+ EphySpinnerCachePrivate *priv;
+};
+
+#define EPHY_SPINNER_CACHE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SPINNER_CACHE, EphySpinnerCachePrivate))
+
+struct _EphySpinnerCachePrivate
+{
+ /* Hash table of GdkScreen -> EphySpinnerCacheData */
+ GHashTable *hash;
+};
+
+typedef struct
+{
+ guint ref_count;
+ GtkIconSize size;
+ int width;
+ int height;
+ GdkPixbuf **animation_pixbufs;
+ guint n_animation_pixbufs;
+} EphySpinnerImages;
+
+#define LAST_ICON_SIZE GTK_ICON_SIZE_DIALOG + 1
+#define SPINNER_ICON_NAME "process-working"
+#define SPINNER_FALLBACK_ICON_NAME "gnome-spinner"
+#define EPHY_SPINNER_IMAGES_INVALID ((EphySpinnerImages *) 0x1)
+
+typedef struct
+{
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme;
+ EphySpinnerImages *images[LAST_ICON_SIZE];
+} EphySpinnerCacheData;
+
+static void ephy_spinner_cache_class_init (EphySpinnerCacheClass *klass);
+static void ephy_spinner_cache_init (EphySpinnerCache *cache);
+
+static GObjectClass *ephy_spinner_cache_parent_class;
+
+static GType
+ephy_spinner_cache_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ const GTypeInfo our_info =
+ {
+ sizeof (EphySpinnerCacheClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) ephy_spinner_cache_class_init,
+ NULL,
+ NULL,
+ sizeof (EphySpinnerCache),
+ 0,
+ (GInstanceInitFunc) ephy_spinner_cache_init
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT,
+ "EphySpinnerCache",
+ &our_info, 0);
+ }
+
+ return type;
+}
+
+static EphySpinnerImages *
+ephy_spinner_images_ref (EphySpinnerImages *images)
+{
+ g_return_val_if_fail (images != NULL, NULL);
+
+ images->ref_count++;
+
+ return images;
+}
+
+static void
+ephy_spinner_images_unref (EphySpinnerImages *images)
+{
+ g_return_if_fail (images != NULL);
+
+ images->ref_count--;
+ if (images->ref_count == 0)
+ {
+ guint i;
+
+ LOG ("Freeing spinner images %p for size %d", images, images->size);
+
+ for (i = 0; i < images->n_animation_pixbufs; ++i)
+ {
+ g_object_unref (images->animation_pixbufs[i]);
+ }
+ g_free (images->animation_pixbufs);
+
+ g_free (images);
+ }
+}
+
+static void
+ephy_spinner_cache_data_unload (EphySpinnerCacheData *data)
+{
+ GtkIconSize size;
+ EphySpinnerImages *images;
+
+ g_return_if_fail (data != NULL);
+
+ LOG ("EphySpinnerDataCache unload for screen %p", data->screen);
+
+ for (size = GTK_ICON_SIZE_INVALID; size < LAST_ICON_SIZE; ++size)
+ {
+ images = data->images[size];
+ data->images[size] = NULL;
+
+ if (images != NULL && images != EPHY_SPINNER_IMAGES_INVALID)
+ {
+ ephy_spinner_images_unref (images);
+ }
+ }
+}
+
+static GdkPixbuf *
+extract_frame (GdkPixbuf *grid_pixbuf,
+ int x,
+ int y,
+ int size)
+{
+ GdkPixbuf *pixbuf;
+
+ if (x + size > gdk_pixbuf_get_width (grid_pixbuf) ||
+ y + size > gdk_pixbuf_get_height (grid_pixbuf))
+ {
+ return NULL;
+ }
+
+ pixbuf = gdk_pixbuf_new_subpixbuf (grid_pixbuf,
+ x, y,
+ size, size);
+ g_return_val_if_fail (pixbuf != NULL, NULL);
+
+ return pixbuf;
+}
+
+static GdkPixbuf *
+scale_to_size (GdkPixbuf *pixbuf,
+ int dw,
+ int dh)
+{
+ GdkPixbuf *result;
+ int pw, ph;
+
+ g_return_val_if_fail (pixbuf != NULL, NULL);
+
+ pw = gdk_pixbuf_get_width (pixbuf);
+ ph = gdk_pixbuf_get_height (pixbuf);
+
+ if (pw != dw || ph != dh)
+ {
+ result = gdk_pixbuf_scale_simple (pixbuf, dw, dh,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ return result;
+ }
+
+ return pixbuf;
+}
+
+static EphySpinnerImages *
+ephy_spinner_images_load (GdkScreen *screen,
+ GtkIconTheme *icon_theme,
+ GtkIconSize icon_size)
+{
+ EphySpinnerImages *images;
+ GdkPixbuf *icon_pixbuf, *pixbuf;
+ GtkIconInfo *icon_info = NULL;
+ int grid_width, grid_height, x, y, requested_size, size, isw, ish, n;
+ const char *icon;
+ GSList *list = NULL, *l;
+
+ LOG ("EphySpinnerCacheData loading for screen %p at size %d", screen, icon_size);
+
+ START_PROFILER ("loading spinner animation")
+
+ if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
+ icon_size, &isw, &ish)) goto loser;
+
+ requested_size = MAX (ish, isw);
+
+ /* Load the animation. The 'rest icon' is the 0th frame */
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme,
+ SPINNER_ICON_NAME,
+ requested_size, 0);
+ if (icon_info == NULL)
+ {
+ g_warning ("Throbber animation not found");
+
+ /* If the icon naming spec compliant name wasn't found, try the old name */
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme,
+ SPINNER_FALLBACK_ICON_NAME,
+ requested_size, 0);
+ if (icon_info == NULL)
+ {
+ g_warning ("Throbber fallback animation not found either");
+ goto loser;
+ }
+ }
+ g_assert (icon_info != NULL);
+
+ size = gtk_icon_info_get_base_size (icon_info);
+ icon = gtk_icon_info_get_filename (icon_info);
+ if (icon == NULL) goto loser;
+
+ icon_pixbuf = gdk_pixbuf_new_from_file (icon, NULL);
+ gtk_icon_info_free (icon_info);
+ icon_info = NULL;
+
+ if (icon_pixbuf == NULL)
+ {
+ g_warning ("Could not load the spinner file");
+ goto loser;
+ }
+
+ grid_width = gdk_pixbuf_get_width (icon_pixbuf);
+ grid_height = gdk_pixbuf_get_height (icon_pixbuf);
+
+ n = 0;
+ for (y = 0; y < grid_height; y += size)
+ {
+ for (x = 0; x < grid_width ; x += size)
+ {
+ pixbuf = extract_frame (icon_pixbuf, x, y, size);
+
+ if (pixbuf)
+ {
+ list = g_slist_prepend (list, pixbuf);
+ ++n;
+ }
+ else
+ {
+ g_warning ("Cannot extract frame (%d, %d) from the grid\n", x, y);
+ }
+ }
+ }
+
+ g_object_unref (icon_pixbuf);
+
+ if (list == NULL) goto loser;
+ g_assert (n > 0);
+
+ if (size > requested_size)
+ {
+ for (l = list; l != NULL; l = l->next)
+ {
+ l->data = scale_to_size (l->data, isw, ish);
+ }
+ }
+
+ /* Now we've successfully got all the data */
+ images = g_new (EphySpinnerImages, 1);
+ images->ref_count = 1;
+
+ images->size = icon_size;
+ images->width = images->height = requested_size;
+
+ images->n_animation_pixbufs = n;
+ images->animation_pixbufs = g_new (GdkPixbuf *, n);
+
+ for (l = list; l != NULL; l = l->next)
+ {
+ g_assert (l->data != NULL);
+ images->animation_pixbufs[--n] = l->data;
+ }
+ g_assert (n == 0);
+
+ g_slist_free (list);
+
+ STOP_PROFILER ("loading spinner animation")
+
+ return images;
+
+loser:
+ if (icon_info)
+ {
+ gtk_icon_info_free (icon_info);
+ }
+ g_slist_foreach (list, (GFunc) g_object_unref, NULL);
+
+ STOP_PROFILER ("loading spinner animation")
+
+ return NULL;
+}
+
+static EphySpinnerCacheData *
+ephy_spinner_cache_data_new (GdkScreen *screen)
+{
+ EphySpinnerCacheData *data;
+
+ data = g_new0 (EphySpinnerCacheData, 1);
+
+ data->screen = screen;
+ data->icon_theme = gtk_icon_theme_get_for_screen (screen);
+ g_signal_connect_swapped (data->icon_theme, "changed",
+ G_CALLBACK (ephy_spinner_cache_data_unload),
+ data);
+
+ return data;
+}
+
+static void
+ephy_spinner_cache_data_free (EphySpinnerCacheData *data)
+{
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (data->icon_theme != NULL);
+
+ g_signal_handlers_disconnect_by_func
+ (data->icon_theme,
+ G_CALLBACK (ephy_spinner_cache_data_unload), data);
+
+ ephy_spinner_cache_data_unload (data);
+
+ g_free (data);
+}
+
+static EphySpinnerImages *
+ephy_spinner_cache_get_images (EphySpinnerCache *cache,
+ GdkScreen *screen,
+ GtkIconSize icon_size)
+{
+ EphySpinnerCachePrivate *priv = cache->priv;
+ EphySpinnerCacheData *data;
+ EphySpinnerImages *images;
+
+ LOG ("Getting animation images for screen %p at size %d", screen, icon_size);
+
+ g_return_val_if_fail (icon_size >= 0 && icon_size < LAST_ICON_SIZE, NULL);
+
+ /* Backward compat: "invalid" meant "native" size which doesn't exist anymore */
+ if (icon_size == GTK_ICON_SIZE_INVALID)
+ {
+ icon_size = GTK_ICON_SIZE_DIALOG;
+ }
+
+ data = g_hash_table_lookup (priv->hash, screen);
+ if (data == NULL)
+ {
+ data = ephy_spinner_cache_data_new (screen);
+ /* FIXME: think about what happens when the screen's display is closed later on */
+ g_hash_table_insert (priv->hash, screen, data);
+ }
+
+ images = data->images[icon_size];
+ if (images == EPHY_SPINNER_IMAGES_INVALID)
+ {
+ /* Load failed, but don't try endlessly again! */
+ return NULL;
+ }
+
+ if (images != NULL)
+ {
+ /* Return cached data */
+ return ephy_spinner_images_ref (images);
+ }
+
+ images = ephy_spinner_images_load (screen, data->icon_theme, icon_size);
+
+ if (images == NULL)
+ {
+ /* Mark as failed-to-load */
+ data->images[icon_size] = EPHY_SPINNER_IMAGES_INVALID;
+
+ return NULL;
+ }
+
+ data->images[icon_size] = images;
+
+ return ephy_spinner_images_ref (images);
+}
+
+static void
+ephy_spinner_cache_init (EphySpinnerCache *cache)
+{
+ EphySpinnerCachePrivate *priv;
+
+ priv = cache->priv = EPHY_SPINNER_CACHE_GET_PRIVATE (cache);
+
+ LOG ("EphySpinnerCache initialising");
+
+ priv->hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL,
+ (GDestroyNotify) ephy_spinner_cache_data_free);
+}
+
+static void
+ephy_spinner_cache_finalize (GObject *object)
+{
+ EphySpinnerCache *cache = EPHY_SPINNER_CACHE (object);
+ EphySpinnerCachePrivate *priv = cache->priv;
+
+ g_hash_table_destroy (priv->hash);
+
+ LOG ("EphySpinnerCache finalised");
+
+ G_OBJECT_CLASS (ephy_spinner_cache_parent_class)->finalize (object);
+}
+
+static void
+ephy_spinner_cache_class_init (EphySpinnerCacheClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ ephy_spinner_cache_parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = ephy_spinner_cache_finalize;
+
+ g_type_class_add_private (object_class, sizeof (EphySpinnerCachePrivate));
+}
+
+static EphySpinnerCache *spinner_cache = NULL;
+
+static EphySpinnerCache *
+ephy_spinner_cache_ref (void)
+{
+ if (spinner_cache == NULL)
+ {
+ EphySpinnerCache **cache_ptr;
+
+ spinner_cache = g_object_new (EPHY_TYPE_SPINNER_CACHE, NULL);
+ cache_ptr = &spinner_cache;
+ g_object_add_weak_pointer (G_OBJECT (spinner_cache),
+ (gpointer *) cache_ptr);
+
+ return spinner_cache;
+ }
+
+ return g_object_ref (spinner_cache);
+}
+
+/* Spinner implementation */
+
+#define SPINNER_TIMEOUT 125 /* ms */
+
+#define EPHY_SPINNER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SPINNER, EphySpinnerDetails))
+
+struct _EphySpinnerDetails
+{
+ GtkIconTheme *icon_theme;
+ EphySpinnerCache *cache;
+ GtkIconSize size;
+ EphySpinnerImages *images;
+ guint current_image;
+ guint timeout;
+ guint timer_task;
+ guint spinning : 1;
+ guint need_load : 1;
+};
+
+static void ephy_spinner_class_init (EphySpinnerClass *class);
+static void ephy_spinner_init (EphySpinner *spinner);
+
+static GObjectClass *parent_class;
+
+GType
+ephy_spinner_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ const GTypeInfo our_info =
+ {
+ sizeof (EphySpinnerClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) ephy_spinner_class_init,
+ NULL,
+ NULL, /* class_data */
+ sizeof (EphySpinner),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) ephy_spinner_init
+ };
+
+ type = g_type_register_static (GTK_TYPE_WIDGET,
+ "EphySpinner",
+ &our_info, 0);
+ }
+
+ return type;
+}
+
+static gboolean
+ephy_spinner_load_images (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ if (details->need_load)
+ {
+ START_PROFILER ("ephy_spinner_load_images")
+
+ details->images =
+ ephy_spinner_cache_get_images
+ (details->cache,
+ gtk_widget_get_screen (GTK_WIDGET (spinner)),
+ details->size);
+
+ STOP_PROFILER ("ephy_spinner_load_images")
+
+ details->current_image = 0; /* 'rest' icon */
+ details->need_load = FALSE;
+ }
+
+ return details->images != NULL;
+}
+
+static void
+ephy_spinner_unload_images (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ if (details->images != NULL)
+ {
+ ephy_spinner_images_unref (details->images);
+ details->images = NULL;
+ }
+
+ details->current_image = 0;
+ details->need_load = TRUE;
+}
+
+static void
+icon_theme_changed_cb (GtkIconTheme *icon_theme,
+ EphySpinner *spinner)
+{
+ ephy_spinner_unload_images (spinner);
+ gtk_widget_queue_resize (GTK_WIDGET (spinner));
+}
+
+static void
+ephy_spinner_init (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details;
+
+ details = spinner->details = EPHY_SPINNER_GET_PRIVATE (spinner);
+
+ GTK_WIDGET_SET_FLAGS (GTK_WIDGET (spinner), GTK_NO_WINDOW);
+
+ details->cache = ephy_spinner_cache_ref ();
+ details->size = GTK_ICON_SIZE_DIALOG;
+ details->spinning = FALSE;
+ details->timeout = SPINNER_TIMEOUT;
+ details->need_load = TRUE;
+}
+
+static int
+ephy_spinner_expose (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ EphySpinner *spinner = EPHY_SPINNER (widget);
+ EphySpinnerDetails *details = spinner->details;
+ EphySpinnerImages *images;
+ GdkPixbuf *pixbuf;
+ GdkGC *gc;
+ int x_offset, y_offset, width, height;
+ GdkRectangle pix_area, dest;
+
+ if (!GTK_WIDGET_DRAWABLE (spinner))
+ {
+ return FALSE;
+ }
+
+ if (details->need_load &&
+ !ephy_spinner_load_images (spinner))
+ {
+ return FALSE;
+ }
+
+ images = details->images;
+ if (images == NULL)
+ {
+ return FALSE;
+ }
+
+ /* Otherwise |images| will be NULL anyway */
+ g_assert (images->n_animation_pixbufs > 0);
+
+ g_assert (details->current_image >= 0 &&
+ details->current_image < images->n_animation_pixbufs);
+
+ pixbuf = images->animation_pixbufs[details->current_image];
+
+ g_assert (pixbuf != NULL);
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ /* Compute the offsets for the image centered on our allocation */
+ x_offset = (widget->allocation.width - width) / 2;
+ y_offset = (widget->allocation.height - height) / 2;
+
+ pix_area.x = x_offset + widget->allocation.x;
+ pix_area.y = y_offset + widget->allocation.y;
+ pix_area.width = width;
+ pix_area.height = height;
+
+ if (!gdk_rectangle_intersect (&event->area, &pix_area, &dest))
+ {
+ return FALSE;
+ }
+
+ gc = gdk_gc_new (widget->window);
+ gdk_draw_pixbuf (widget->window, gc, pixbuf,
+ dest.x - x_offset - widget->allocation.x,
+ dest.y - y_offset - widget->allocation.y,
+ dest.x, dest.y,
+ dest.width, dest.height,
+ GDK_RGB_DITHER_MAX, 0, 0);
+ g_object_unref (gc);
+
+ return FALSE;
+}
+
+static gboolean
+bump_spinner_frame_cb (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ /* This can happen when we've unloaded the images on a theme
+ * change, but haven't been in the queued size request yet.
+ * Just skip this update.
+ */
+ if (details->images == NULL) return TRUE;
+
+ details->current_image++;
+ if (details->current_image >= details->images->n_animation_pixbufs)
+ {
+ /* the 0th frame is the 'rest' icon */
+ details->current_image = MIN (1, details->images->n_animation_pixbufs);
+ }
+
+ gtk_widget_queue_draw (GTK_WIDGET (spinner));
+
+ /* run again */
+ return TRUE;
+}
+
+/**
+ * ephy_spinner_start:
+ * @spinner: a #EphySpinner
+ *
+ * Start the spinner animation.
+ **/
+void
+ephy_spinner_start (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ details->spinning = TRUE;
+
+ if (GTK_WIDGET_MAPPED (GTK_WIDGET (spinner)) &&
+ details->timer_task == 0 &&
+ ephy_spinner_load_images (spinner))
+ {
+ /* the 0th frame is the 'rest' icon */
+ details->current_image = MIN (1, details->images->n_animation_pixbufs);
+
+ details->timer_task =
+ g_timeout_add_full (G_PRIORITY_LOW,
+ details->timeout,
+ (GSourceFunc) bump_spinner_frame_cb,
+ spinner,
+ NULL);
+ }
+}
+
+static void
+ephy_spinner_remove_update_callback (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ if (details->timer_task != 0)
+ {
+ g_source_remove (details->timer_task);
+ details->timer_task = 0;
+ }
+}
+
+/**
+ * ephy_spinner_stop:
+ * @spinner: a #EphySpinner
+ *
+ * Stop the spinner animation.
+ **/
+void
+ephy_spinner_stop (EphySpinner *spinner)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ details->spinning = FALSE;
+ details->current_image = 0;
+
+ if (details->timer_task != 0)
+ {
+ ephy_spinner_remove_update_callback (spinner);
+
+ if (GTK_WIDGET_MAPPED (GTK_WIDGET (spinner)))
+ {
+ gtk_widget_queue_draw (GTK_WIDGET (spinner));
+ }
+ }
+}
+
+/*
+ * ephy_spinner_set_size:
+ * @spinner: a #EphySpinner
+ * @size: the size of type %GtkIconSize
+ *
+ * Set the size of the spinner.
+ **/
+void
+ephy_spinner_set_size (EphySpinner *spinner,
+ GtkIconSize size)
+{
+ if (size == GTK_ICON_SIZE_INVALID)
+ {
+ size = GTK_ICON_SIZE_DIALOG;
+ }
+
+ if (size != spinner->details->size)
+ {
+ ephy_spinner_unload_images (spinner);
+
+ spinner->details->size = size;
+
+ gtk_widget_queue_resize (GTK_WIDGET (spinner));
+ }
+}
+
+#if 0
+/*
+ * ephy_spinner_set_timeout:
+ * @spinner: a #EphySpinner
+ * @timeout: time delay between updates to the spinner.
+ *
+ * Sets the timeout delay for spinner updates.
+ **/
+void
+ephy_spinner_set_timeout (EphySpinner *spinner,
+ guint timeout)
+{
+ EphySpinnerDetails *details = spinner->details;
+
+ if (timeout != details->timeout)
+ {
+ ephy_spinner_stop (spinner);
+
+ details->timeout = timeout;
+
+ if (details->spinning)
+ {
+ ephy_spinner_start (spinner);
+ }
+ }
+}
+#endif
+
+static void
+ephy_spinner_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EphySpinner *spinner = EPHY_SPINNER (widget);
+ EphySpinnerDetails *details = spinner->details;
+
+ if ((details->need_load &&
+ !ephy_spinner_load_images (spinner)) ||
+ details->images == NULL)
+ {
+ requisition->width = requisition->height = 0;
+ gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
+ details->size,
+ &requisition->width,
+ &requisition->height);
+ return;
+ }
+
+ requisition->width = details->images->width;
+ requisition->height = details->images->height;
+
+ /* FIXME fix this hack */
+ /* allocate some extra margin so we don't butt up against toolbar edges */
+ if (details->size != GTK_ICON_SIZE_MENU)
+ {
+ requisition->width += 2;
+ requisition->height += 2;
+ }
+}
+
+static void
+ephy_spinner_map (GtkWidget *widget)
+{
+ EphySpinner *spinner = EPHY_SPINNER (widget);
+ EphySpinnerDetails *details = spinner->details;
+
+ GTK_WIDGET_CLASS (parent_class)->map (widget);
+
+ if (details->spinning)
+ {
+ ephy_spinner_start (spinner);
+ }
+}
+
+static void
+ephy_spinner_unmap (GtkWidget *widget)
+{
+ EphySpinner *spinner = EPHY_SPINNER (widget);
+
+ ephy_spinner_remove_update_callback (spinner);
+
+ GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+}
+
+static void
+ephy_spinner_dispose (GObject *object)
+{
+ EphySpinner *spinner = EPHY_SPINNER (object);
+
+ g_signal_handlers_disconnect_by_func
+ (spinner->details->icon_theme,
+ G_CALLBACK (icon_theme_changed_cb), spinner);
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+ephy_spinner_finalize (GObject *object)
+{
+ EphySpinner *spinner = EPHY_SPINNER (object);
+
+ ephy_spinner_remove_update_callback (spinner);
+ ephy_spinner_unload_images (spinner);
+
+ g_object_unref (spinner->details->cache);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+ephy_spinner_screen_changed (GtkWidget *widget,
+ GdkScreen *old_screen)
+{
+ EphySpinner *spinner = EPHY_SPINNER (widget);
+ EphySpinnerDetails *details = spinner->details;
+ GdkScreen *screen;
+
+ if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
+ {
+ GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, old_screen);
+ }
+
+ screen = gtk_widget_get_screen (widget);
+
+ /* FIXME: this seems to be happening when then spinner is destroyed!? */
+ if (old_screen == screen) return;
+
+ /* We'll get mapped again on the new screen, but not unmapped from
+ * the old screen, so remove timeout here.
+ */
+ ephy_spinner_remove_update_callback (spinner);
+
+ ephy_spinner_unload_images (spinner);
+
+ if (old_screen != NULL)
+ {
+ g_signal_handlers_disconnect_by_func
+ (gtk_icon_theme_get_for_screen (old_screen),
+ G_CALLBACK (icon_theme_changed_cb), spinner);
+ }
+
+ details->icon_theme = gtk_icon_theme_get_for_screen (screen);
+ g_signal_connect (details->icon_theme, "changed",
+ G_CALLBACK (icon_theme_changed_cb), spinner);
+}
+
+static void
+ephy_spinner_class_init (EphySpinnerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ parent_class = g_type_class_peek_parent (class);
+
+ object_class->dispose = ephy_spinner_dispose;
+ object_class->finalize = ephy_spinner_finalize;
+
+ widget_class->expose_event = ephy_spinner_expose;
+ widget_class->size_request = ephy_spinner_size_request;
+ widget_class->map = ephy_spinner_map;
+ widget_class->unmap = ephy_spinner_unmap;
+ widget_class->screen_changed = ephy_spinner_screen_changed;
+
+ g_type_class_add_private (object_class, sizeof (EphySpinnerDetails));
+}
+
+/*
+ * ephy_spinner_new:
+ *
+ * Create a new #EphySpinner. The spinner is a widget
+ * that gives the user feedback about network status with
+ * an animated image.
+ *
+ * Return Value: the spinner #GtkWidget
+ **/
+GtkWidget *
+ephy_spinner_new (void)
+{
+ return GTK_WIDGET (g_object_new (EPHY_TYPE_SPINNER, NULL));
+}
diff --git a/libempathy-gtk/ephy-spinner.h b/libempathy-gtk/ephy-spinner.h
new file mode 100644
index 000000000..4435fe371
--- /dev/null
+++ b/libempathy-gtk/ephy-spinner.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Copyright © 2000 Eazel, Inc.
+ * Copyright © 2004, 2006 Christian Persch
+ *
+ * Nautilus is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ *
+ * Author: Andy Hertzfeld <andy@eazel.com>
+ *
+ * $Id: ephy-spinner.h 2114 2006-12-25 12:15:00Z mr $
+ */
+
+#ifndef EPHY_SPINNER_H
+#define EPHY_SPINNER_H
+
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkenums.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_SPINNER (ephy_spinner_get_type ())
+#define EPHY_SPINNER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_SPINNER, EphySpinner))
+#define EPHY_SPINNER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_SPINNER, EphySpinnerClass))
+#define EPHY_IS_SPINNER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_SPINNER))
+#define EPHY_IS_SPINNER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_SPINNER))
+#define EPHY_SPINNER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_SPINNER, EphySpinnerClass))
+
+typedef struct _EphySpinner EphySpinner;
+typedef struct _EphySpinnerClass EphySpinnerClass;
+typedef struct _EphySpinnerDetails EphySpinnerDetails;
+
+struct _EphySpinner
+{
+ GtkWidget parent;
+
+ /*< private >*/
+ EphySpinnerDetails *details;
+};
+
+struct _EphySpinnerClass
+{
+ GtkWidgetClass parent_class;
+};
+
+GType ephy_spinner_get_type (void);
+
+GtkWidget *ephy_spinner_new (void);
+
+void ephy_spinner_start (EphySpinner *throbber);
+
+void ephy_spinner_stop (EphySpinner *throbber);
+
+void ephy_spinner_set_size (EphySpinner *spinner,
+ GtkIconSize size);
+
+G_END_DECLS
+
+#endif /* EPHY_SPINNER_H */
diff --git a/libempathy-gtk/gossip-contact-list.c b/libempathy-gtk/gossip-contact-list.c
index c5a49ceec..8e7288e6f 100644
--- a/libempathy-gtk/gossip-contact-list.c
+++ b/libempathy-gtk/gossip-contact-list.c
@@ -29,7 +29,10 @@
#include <gtk/gtk.h>
#include <glade/glade.h>
+#include <libtelepathy/tp-helpers.h>
+
#include <libmissioncontrol/mc-account.h>
+#include <libmissioncontrol/mission-control.h>
#include <libempathy/empathy-contact-manager.h>
#include <libempathy/gossip-debug.h>
@@ -247,23 +250,12 @@ static gboolean contact_list_find_contact_foreach (GtkTreeModel
FindContact *fc);
static void contact_list_action_cb (GtkAction *action,
GossipContactList *list);
+static void contact_list_action_activated (GossipContactList *list,
+ GossipContact *contact);
static gboolean contact_list_update_list_mode_foreach (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
GossipContactList *list);
-enum {
- CONTACT_CHAT,
- CONTACT_INFORMATION,
- CONTACT_EDIT,
- CONTACT_REMOVE,
- CONTACT_INVITE,
- CONTACT_SEND_FILE,
- CONTACT_LOG,
- GROUP_RENAME,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
enum {
COL_PIXBUF_STATUS,
@@ -383,80 +375,6 @@ gossip_contact_list_class_init (GossipContactListClass *klass)
object_class->get_property = contact_list_get_property;
object_class->set_property = contact_list_set_property;
- signals[CONTACT_CHAT] =
- g_signal_new ("contact-chat",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[CONTACT_INFORMATION] =
- g_signal_new ("contact-information",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[CONTACT_EDIT] =
- g_signal_new ("contact-edit",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[CONTACT_REMOVE] =
- g_signal_new ("contact-remove",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[CONTACT_INVITE] =
- g_signal_new ("contact-invite",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[CONTACT_SEND_FILE] =
- g_signal_new ("contact-send-file",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[CONTACT_LOG] =
- g_signal_new ("contact-log",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1, GOSSIP_TYPE_CONTACT);
- signals[GROUP_RENAME] =
- g_signal_new ("group-rename",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE,
- 1, G_TYPE_STRING);
-
-
g_object_class_install_property (object_class,
PROP_SHOW_OFFLINE,
g_param_spec_boolean ("show-offline",
@@ -2205,7 +2123,7 @@ contact_list_row_activated_cb (GossipContactList *list,
gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
if (contact) {
- g_signal_emit (list, signals[CONTACT_CHAT], 0, contact);
+ contact_list_action_activated (list, contact);
g_object_unref (contact);
}
}
@@ -2485,28 +2403,21 @@ contact_list_action_cb (GtkAction *action,
group = gossip_contact_list_get_selected_group (list);
if (contact && strcmp (name, "Chat") == 0) {
- g_signal_emit (list, signals[CONTACT_CHAT], 0, contact);
+ contact_list_action_activated (list, contact);
}
else if (contact && strcmp (name, "Information") == 0) {
- g_signal_emit (list, signals[CONTACT_INFORMATION], 0, contact);
}
else if (contact && strcmp (name, "Edit") == 0) {
- g_signal_emit (list, signals[CONTACT_EDIT], 0, contact);
}
else if (contact && strcmp (name, "Remove") == 0) {
- g_signal_emit (list, signals[CONTACT_REMOVE], 0, contact);
}
else if (contact && strcmp (name, "Invite") == 0) {
- g_signal_emit (list, signals[CONTACT_INVITE], 0, contact);
}
else if (contact && strcmp (name, "SendFile") == 0) {
- g_signal_emit (list, signals[CONTACT_SEND_FILE], 0, contact);
}
else if (contact && strcmp (name, "Log") == 0) {
- g_signal_emit (list, signals[CONTACT_LOG], 0, contact);
}
else if (group && strcmp (name, "Rename") == 0) {
- g_signal_emit (list, signals[GROUP_RENAME], 0, group);
}
g_free (group);
@@ -2515,6 +2426,22 @@ contact_list_action_cb (GtkAction *action,
}
}
+static void
+contact_list_action_activated (GossipContactList *list,
+ GossipContact *contact)
+{
+ MissionControl *mc;
+
+ mc = mission_control_new (tp_get_bus ());
+ mission_control_request_channel (mc,
+ gossip_contact_get_account (contact),
+ TP_IFACE_CHANNEL_TYPE_TEXT,
+ gossip_contact_get_handle (contact),
+ TP_HANDLE_TYPE_CONTACT,
+ NULL, NULL);
+ g_object_unref (mc);
+}
+
static gboolean
contact_list_update_list_mode_foreach (GtkTreeModel *model,
GtkTreePath *path,