diff options
Diffstat (limited to 'libempathy-gtk')
37 files changed, 1676 insertions, 757 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 2a4438e57..10931012a 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -54,6 +54,7 @@ libempathy_gtk_handwritten_source = \ empathy-presence-chooser.c \ empathy-profile-chooser.c \ empathy-smiley-manager.c \ + empathy-sound.c \ empathy-spell.c \ empathy-status-preset-dialog.c \ empathy-theme-boxes.c \ @@ -113,6 +114,7 @@ libempathy_gtk_headers = \ empathy-presence-chooser.h \ empathy-profile-chooser.h \ empathy-smiley-manager.h \ + empathy-sound.h \ empathy-spell.h \ empathy-status-preset-dialog.h \ empathy-theme-boxes.h \ @@ -226,11 +228,15 @@ endif if HAVE_WEBKIT libempathy_gtk_handwritten_source += \ + empathy-plist.c \ empathy-theme-adium.c libempathy_gtk_headers += \ + empathy-plist.h \ empathy-theme-adium.h else EXTRA_DIST += \ + empathy-plist.c \ + empathy-plist.h \ empathy-theme-adium.c \ empathy-theme-adium.h endif diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index 915b37b23..7dccb2179 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -65,7 +65,7 @@ typedef struct { typedef struct { EmpathyAccountChooser *chooser; - McAccount *account; + EmpathyAccount *account; gboolean set; } SetAccountData; @@ -88,19 +88,19 @@ static void account_chooser_set_property (GObject GParamSpec *pspec); static void account_chooser_setup (EmpathyAccountChooser *chooser); static void account_chooser_account_created_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, EmpathyAccountChooser *chooser); -static void account_chooser_account_add_foreach (McAccount *account, +static void account_chooser_account_add_foreach (EmpathyAccount *account, EmpathyAccountChooser *chooser); static void account_chooser_account_deleted_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, EmpathyAccountChooser *chooser); -static void account_chooser_account_remove_foreach (McAccount *account, +static void account_chooser_account_remove_foreach (EmpathyAccount *account, EmpathyAccountChooser *chooser); static void account_chooser_update_iter (EmpathyAccountChooser *chooser, GtkTreeIter *iter); static void account_chooser_connection_changed_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, TpConnectionStatusReason reason, TpConnectionStatus new_status, TpConnectionStatus old_status, @@ -253,16 +253,16 @@ empathy_account_chooser_new (void) * @chooser: an #EmpathyAccountChooser * * Returns the account which is currently selected in the chooser or %NULL - * if there is no account selected. The #McAccount returned should be + * if there is no account selected. The #EmpathyAccount returned should be * unrefed with g_object_unref() when finished with. * - * Return value: a new ref to the #McAccount currently selected, or %NULL. + * Return value: a new ref to the #EmpathyAccount currently selected, or %NULL. */ -McAccount * +EmpathyAccount * empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser) { EmpathyAccountChooserPriv *priv; - McAccount *account; + EmpathyAccount *account; GtkTreeModel *model; GtkTreeIter iter; @@ -295,7 +295,7 @@ TpConnection * empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) { EmpathyAccountChooserPriv *priv; - McAccount *account; + EmpathyAccount *account; TpConnection *connection; g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), NULL); @@ -303,7 +303,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) priv = GET_PRIV (chooser); account = empathy_account_chooser_dup_account (chooser); - connection = empathy_account_manager_get_connection (priv->manager, account); + connection = empathy_account_get_connection (account); g_object_unref (account); return connection; @@ -312,7 +312,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) /** * empathy_account_chooser_set_account: * @chooser: an #EmpathyAccountChooser - * @account: an #McAccount + * @account: an #EmpathyAccount * * Sets the currently selected account to @account, if it exists in the list. * @@ -320,7 +320,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser) */ gboolean empathy_account_chooser_set_account (EmpathyAccountChooser *chooser, - McAccount *account) + EmpathyAccount *account) { GtkComboBox *combobox; GtkTreeModel *model; @@ -361,7 +361,7 @@ empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *chooser) g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), FALSE); priv = GET_PRIV (chooser); - + return priv->has_all_option; } @@ -457,7 +457,7 @@ account_chooser_setup (EmpathyAccountChooser *chooser) G_TYPE_STRING, /* Image */ G_TYPE_STRING, /* Name */ G_TYPE_BOOLEAN, /* Enabled */ - MC_TYPE_ACCOUNT); + EMPATHY_TYPE_ACCOUNT); gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store)); @@ -477,25 +477,25 @@ account_chooser_setup (EmpathyAccountChooser *chooser) NULL); /* Populate accounts */ - accounts = mc_accounts_list (); + accounts = empathy_account_manager_dup_accounts (priv->manager); g_list_foreach (accounts, (GFunc) account_chooser_account_add_foreach, chooser); - mc_accounts_list_free (accounts); + g_list_free (accounts); g_object_unref (store); } static void account_chooser_account_created_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, EmpathyAccountChooser *chooser) { account_chooser_account_add_foreach (account, chooser); } static void -account_chooser_account_add_foreach (McAccount *account, +account_chooser_account_add_foreach (EmpathyAccount *account, EmpathyAccountChooser *chooser) { GtkListStore *store; @@ -511,18 +511,20 @@ account_chooser_account_add_foreach (McAccount *account, COL_ACCOUNT_POINTER, account, -1); account_chooser_update_iter (chooser, &iter); + /* We got a reffed account and it was reffed by the liststore as well */ + g_object_unref (account); } static void account_chooser_account_deleted_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, EmpathyAccountChooser *chooser) { account_chooser_account_remove_foreach (account, chooser); } typedef struct { - McAccount *account; + EmpathyAccount *account; GtkTreeIter *iter; gboolean found; } FindAccountData; @@ -534,7 +536,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model, gpointer user_data) { FindAccountData *data = user_data; - McAccount *account; + EmpathyAccount *account; gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1); @@ -553,7 +555,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model, static gboolean account_chooser_find_account (EmpathyAccountChooser *chooser, - McAccount *account, + EmpathyAccount *account, GtkTreeIter *iter) { GtkListStore *store; @@ -573,7 +575,7 @@ account_chooser_find_account (EmpathyAccountChooser *chooser, } static void -account_chooser_account_remove_foreach (McAccount *account, +account_chooser_account_remove_foreach (EmpathyAccount *account, EmpathyAccountChooser *chooser) { GtkListStore *store; @@ -595,7 +597,7 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, EmpathyAccountChooserPriv *priv; GtkListStore *store; GtkComboBox *combobox; - McAccount *account; + EmpathyAccount *account; const gchar *icon_name; gboolean is_enabled = TRUE; @@ -615,7 +617,7 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, gtk_list_store_set (store, iter, COL_ACCOUNT_IMAGE, icon_name, - COL_ACCOUNT_TEXT, mc_account_get_display_name (account), + COL_ACCOUNT_TEXT, empathy_account_get_display_name (account), COL_ACCOUNT_ENABLED, is_enabled, -1); @@ -630,7 +632,7 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser, static void account_chooser_connection_changed_cb (EmpathyAccountManager *manager, - McAccount *account, + EmpathyAccount *account, TpConnectionStatusReason reason, TpConnectionStatus new_status, TpConnectionStatus old_status, @@ -653,11 +655,11 @@ account_chooser_separator_func (GtkTreeModel *model, gboolean is_separator; priv = GET_PRIV (chooser); - + if (!priv->has_all_option) { return FALSE; } - + gtk_tree_model_get (model, iter, COL_ACCOUNT_TEXT, &text, -1); is_separator = text == NULL; g_free (text); @@ -671,7 +673,7 @@ account_chooser_set_account_foreach (GtkTreeModel *model, GtkTreeIter *iter, SetAccountData *data) { - McAccount *account; + EmpathyAccount *account; gboolean equal; gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1); @@ -744,7 +746,7 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, /** * EmpathyAccountChooserFilterFunc: - * @account: an #McAccount + * @account: an #EmpathyAccount * @user_data: user data, or %NULL * * A function which decides whether the account indicated by @account @@ -755,7 +757,7 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, /** * empathy_account_chooser_filter_is_connected: - * @account: an #McAccount + * @account: an #EmpathyAccount * @user_data: user data or %NULL * * A useful #EmpathyAccountChooserFilterFunc that one could pass into @@ -764,17 +766,12 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, * Return value: Whether @account is connected */ gboolean -empathy_account_chooser_filter_is_connected (McAccount *account, +empathy_account_chooser_filter_is_connected (EmpathyAccount *account, gpointer user_data) { - MissionControl *mc; TpConnectionStatus status; - g_return_val_if_fail (MC_IS_ACCOUNT (account), FALSE); - - mc = empathy_mission_control_dup_singleton (); - status = mission_control_get_connection_status (mc, account, NULL); - g_object_unref (mc); + g_object_get (account, "status", &status, NULL); return status == TP_CONNECTION_STATUS_CONNECTED; } diff --git a/libempathy-gtk/empathy-account-chooser.h b/libempathy-gtk/empathy-account-chooser.h index c2105406a..255b6841f 100644 --- a/libempathy-gtk/empathy-account-chooser.h +++ b/libempathy-gtk/empathy-account-chooser.h @@ -27,7 +27,7 @@ #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> +#include <libempathy/empathy-account.h> G_BEGIN_DECLS @@ -38,7 +38,7 @@ G_BEGIN_DECLS #define EMPATHY_IS_ACCOUNT_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_ACCOUNT_CHOOSER)) #define EMPATHY_ACCOUNT_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserClass)) -typedef gboolean (* EmpathyAccountChooserFilterFunc) (McAccount *account, +typedef gboolean (* EmpathyAccountChooserFilterFunc) (EmpathyAccount *account, gpointer user_data); @@ -58,17 +58,17 @@ struct _EmpathyAccountChooserClass { GType empathy_account_chooser_get_type (void) G_GNUC_CONST; GtkWidget * empathy_account_chooser_new (void); -McAccount * empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser); +EmpathyAccount * empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser); TpConnection * empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser); gboolean empathy_account_chooser_set_account (EmpathyAccountChooser *chooser, - McAccount *account); + EmpathyAccount *account); gboolean empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *chooser); void empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser, gboolean has_all_option); void empathy_account_chooser_set_filter (EmpathyAccountChooser *chooser, EmpathyAccountChooserFilterFunc filter, gpointer user_data); -gboolean empathy_account_chooser_filter_is_connected (McAccount *account, +gboolean empathy_account_chooser_filter_is_connected (EmpathyAccount *account, gpointer user_data); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index 1306f517f..688a3e0e6 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -27,7 +27,6 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> #include <libmissioncontrol/mc-protocol.h> #include <libempathy/empathy-utils.h> @@ -44,7 +43,7 @@ #define IRC_NETWORKS_FILENAME "irc-networks.xml" typedef struct { - McAccount *account; + EmpathyAccount *account; EmpathyIrcNetworkManager *network_manager; GtkWidget *vbox_settings; @@ -70,9 +69,9 @@ static void unset_server_params (EmpathyAccountWidgetIrc *settings) { DEBUG ("Unset server, port and use-ssl"); - mc_account_unset_param (settings->account, "server"); - mc_account_unset_param (settings->account, "port"); - mc_account_unset_param (settings->account, "use-ssl"); + empathy_account_unset_param (settings->account, "server"); + empathy_account_unset_param (settings->account, "port"); + empathy_account_unset_param (settings->account, "use-ssl"); } static void @@ -98,7 +97,7 @@ update_server_params (EmpathyAccountWidgetIrc *settings) g_object_get (network, "charset", &charset, NULL); DEBUG ("Setting charset to %s", charset); - mc_account_set_param_string (settings->account, "charset", charset); + empathy_account_set_param_string (settings->account, "charset", charset); g_free (charset); servers = empathy_irc_network_get_servers (network); @@ -117,11 +116,11 @@ update_server_params (EmpathyAccountWidgetIrc *settings) NULL); DEBUG ("Setting server to %s", address); - mc_account_set_param_string (settings->account, "server", address); + empathy_account_set_param_string (settings->account, "server", address); DEBUG ("Setting port to %u", port); - mc_account_set_param_int (settings->account, "port", port); + empathy_account_set_param_int (settings->account, "port", port); DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" ); - mc_account_set_param_boolean (settings->account, "use-ssl", ssl); + empathy_account_set_param_boolean (settings->account, "use-ssl", ssl); g_free (address); } @@ -332,17 +331,17 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) gboolean ssl = FALSE; EmpathyIrcNetwork *network = NULL; - mc_account_get_param_string (settings->account, "account", &nick); - mc_account_get_param_string (settings->account, "fullname", &fullname); - mc_account_get_param_string (settings->account, "server", &server); - mc_account_get_param_string (settings->account, "charset", &charset); - mc_account_get_param_int (settings->account, "port", &port); - mc_account_get_param_boolean (settings->account, "use-ssl", &ssl); + nick = empathy_account_get_param_string (settings->account, "account"); + fullname = empathy_account_get_param_string (settings->account, "fullname"); + server = empathy_account_get_param_string (settings->account, "server"); + charset = empathy_account_get_param_string (settings->account, "charset"); + port = empathy_account_get_param_int (settings->account, "port"); + ssl = empathy_account_get_param_boolean (settings->account, "use-ssl"); if (!nick) { nick = g_strdup (g_get_user_name ()); - mc_account_set_param_string (settings->account, "account", nick); + empathy_account_set_param_string (settings->account, "account", nick); } if (!fullname) @@ -352,7 +351,7 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) { fullname = g_strdup (nick); } - mc_account_set_param_string (settings->account, "fullname", fullname); + empathy_account_set_param_string (settings->account, "fullname", fullname); } if (server != NULL) @@ -414,14 +413,14 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) /** * empathy_account_widget_irc_new: - * @account: the #McAccount to configure + * @account: the #EmpathyAccount to configure * - * Creates a new IRC account widget to configure a given #McAccount + * Creates a new IRC account widget to configure a given #EmpathyAccount * * Returns: The toplevel container of the configuration widget */ GtkWidget * -empathy_account_widget_irc_new (McAccount *account) +empathy_account_widget_irc_new (EmpathyAccount *account) { EmpathyAccountWidgetIrc *settings; gchar *dir, *user_file_with_path, *global_file_with_path; diff --git a/libempathy-gtk/empathy-account-widget-irc.h b/libempathy-gtk/empathy-account-widget-irc.h index a89081fc0..40e58bbc3 100644 --- a/libempathy-gtk/empathy-account-widget-irc.h +++ b/libempathy-gtk/empathy-account-widget-irc.h @@ -22,11 +22,11 @@ #define __EMPATHY_ACCOUNT_WIDGET_IRC_H__ #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> +#include <libempathy/empathy-account.h> G_BEGIN_DECLS -GtkWidget * empathy_account_widget_irc_new (McAccount *account); +GtkWidget * empathy_account_widget_irc_new (EmpathyAccount *account); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c index da6082495..05e917e53 100644 --- a/libempathy-gtk/empathy-account-widget-sip.c +++ b/libempathy-gtk/empathy-account-widget-sip.c @@ -28,7 +28,6 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> #include <libmissioncontrol/mc-protocol.h> #include <libempathy/empathy-utils.h> @@ -38,7 +37,7 @@ #include "empathy-ui-utils.h" typedef struct { - McAccount *account; + EmpathyAccount *account; GtkWidget *vbox_settings; @@ -69,14 +68,14 @@ account_widget_sip_discover_stun_toggled_cb ( /** * empathy_account_widget_sip_new: - * @account: the #McAccount to configure + * @account: the #EmpathyAccount to configure * - * Creates a new SIP account widget to configure a given #McAccount + * Creates a new SIP account widget to configure a given #EmpathyAccount * * Returns: The toplevel container of the configuration widget */ GtkWidget * -empathy_account_widget_sip_new (McAccount *account) +empathy_account_widget_sip_new (EmpathyAccount *account) { EmpathyAccountWidgetSip *settings; GtkBuilder *gui; diff --git a/libempathy-gtk/empathy-account-widget-sip.h b/libempathy-gtk/empathy-account-widget-sip.h index 9187c1e0c..69f60aacc 100644 --- a/libempathy-gtk/empathy-account-widget-sip.h +++ b/libempathy-gtk/empathy-account-widget-sip.h @@ -22,11 +22,11 @@ #define __EMPATHY_ACCOUNT_WIDGET_SIP_H__ #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> +#include <libempathy/empathy-account.h> G_BEGIN_DECLS -GtkWidget * empathy_account_widget_sip_new (McAccount *account); +GtkWidget * empathy_account_widget_sip_new (EmpathyAccount *account); G_END_DECLS diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index 669869a4d..f602cd8bd 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -29,10 +29,10 @@ #include <gtk/gtk.h> #include <glib/gi18n-lib.h> -#include <libmissioncontrol/mc-account.h> #include <libmissioncontrol/mc-protocol.h> #include <libempathy/empathy-utils.h> +#include <libempathy/empathy-account.h> #include "empathy-account-widget.h" #include "empathy-ui-utils.h" @@ -43,7 +43,7 @@ static gboolean account_widget_entry_focus_cb (GtkWidget *widget, GdkEventFocus *event, - McAccount *account) + EmpathyAccount *account) { const gchar *str; const gchar *param_name; @@ -54,8 +54,8 @@ account_widget_entry_focus_cb (GtkWidget *widget, if (EMP_STR_EMPTY (str)) { gchar *value = NULL; - mc_account_unset_param (account, param_name); - mc_account_get_param_string (account, param_name, &value); + empathy_account_unset_param (account, param_name); + value = empathy_account_get_param_string (account, param_name); DEBUG ("Unset %s and restore to %s", param_name, value); gtk_entry_set_text (GTK_ENTRY (widget), value ? value : ""); g_free (value); @@ -64,7 +64,7 @@ account_widget_entry_focus_cb (GtkWidget *widget, const gchar *domain = NULL; gchar *dup_str = NULL; - profile = mc_account_get_profile (account); + profile = empathy_account_get_profile (account); if (mc_profile_get_capabilities (profile) & MC_PROFILE_CAPABILITY_SPLIT_ACCOUNT) { domain = mc_profile_get_default_account_domain (profile); @@ -78,7 +78,7 @@ account_widget_entry_focus_cb (GtkWidget *widget, } DEBUG ("Setting %s to %s", param_name, strstr (param_name, "password") ? "***" : str); - mc_account_set_param_string (account, param_name, str); + empathy_account_set_param_string (account, param_name, str); g_free (dup_str); g_object_unref (profile); } @@ -88,7 +88,7 @@ account_widget_entry_focus_cb (GtkWidget *widget, static void account_widget_int_changed_cb (GtkWidget *widget, - McAccount *account) + EmpathyAccount *account) { const gchar *param_name; gint value; @@ -97,19 +97,19 @@ account_widget_int_changed_cb (GtkWidget *widget, param_name = g_object_get_data (G_OBJECT (widget), "param_name"); if (value == 0) { - mc_account_unset_param (account, param_name); - mc_account_get_param_int (account, param_name, &value); + empathy_account_unset_param (account, param_name); + value = empathy_account_get_param_int (account, param_name); DEBUG ("Unset %s and restore to %d", param_name, value); gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); } else { DEBUG ("Setting %s to %d", param_name, value); - mc_account_set_param_int (account, param_name, value); + empathy_account_set_param_int (account, param_name, value); } } static void account_widget_checkbutton_toggled_cb (GtkWidget *widget, - McAccount *account) + EmpathyAccount *account) { gboolean value; gboolean default_value; @@ -121,14 +121,14 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget, /* FIXME: This is ugly! checkbox don't have a "not-set" value so we * always unset the param and set the value if different from the * default value. */ - mc_account_unset_param (account, param_name); - mc_account_get_param_boolean (account, param_name, &default_value); + empathy_account_unset_param (account, param_name); + default_value = empathy_account_get_param_boolean (account, param_name); if (default_value == value) { DEBUG ("Unset %s and restore to %d", param_name, default_value); } else { DEBUG ("Setting %s to %d", param_name, value); - mc_account_set_param_boolean (account, param_name, value); + empathy_account_set_param_boolean (account, param_name, value); } } @@ -136,14 +136,14 @@ static void account_widget_forget_clicked_cb (GtkWidget *button, GtkWidget *entry) { - McAccount *account; + EmpathyAccount *account; const gchar *param_name; param_name = g_object_get_data (G_OBJECT (entry), "param_name"); account = g_object_get_data (G_OBJECT (entry), "account"); DEBUG ("Unset %s", param_name); - mc_account_unset_param (account, param_name); + empathy_account_unset_param (account, param_name); gtk_entry_set_text (GTK_ENTRY (entry), ""); } @@ -161,13 +161,13 @@ static void account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, GtkWidget *spinbutton_port) { - McAccount *account; + EmpathyAccount *account; gboolean value; gint port = 0; value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl)); account = g_object_get_data (G_OBJECT (spinbutton_port), "account"); - mc_account_get_param_int (account, "port", &port); + port = empathy_account_get_param_int (account, "port"); if (value) { if (port == 5222 || port == 0) { @@ -184,7 +184,7 @@ account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl, static void account_widget_setup_widget (GtkWidget *widget, - McAccount *account, + EmpathyAccount *account, const gchar *param_name) { g_object_set_data_full (G_OBJECT (widget), "param_name", @@ -195,7 +195,7 @@ account_widget_setup_widget (GtkWidget *widget, if (GTK_IS_SPIN_BUTTON (widget)) { gint value = 0; - mc_account_get_param_int (account, param_name, &value); + value = empathy_account_get_param_int (account, param_name); gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); g_signal_connect (widget, "value-changed", @@ -205,7 +205,7 @@ account_widget_setup_widget (GtkWidget *widget, else if (GTK_IS_ENTRY (widget)) { gchar *str = NULL; - mc_account_get_param_string (account, param_name, &str); + str = empathy_account_get_param_string (account, param_name); gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); g_free (str); @@ -220,7 +220,7 @@ account_widget_setup_widget (GtkWidget *widget, else if (GTK_IS_TOGGLE_BUTTON (widget)) { gboolean value = FALSE; - mc_account_get_param_boolean (account, param_name, &value); + value = empathy_account_get_param_boolean (account, param_name); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); g_signal_connect (widget, "toggled", @@ -238,11 +238,11 @@ account_widget_generic_format_param_name (const gchar *param_name) gchar *p; str = g_strdup (param_name); - + if (str && g_ascii_isalpha (str[0])) { str[0] = g_ascii_toupper (str[0]); } - + while ((p = strchr (str, '-')) != NULL) { if (p[1] != '\0' && g_ascii_isalpha (p[1])) { p[0] = ' '; @@ -251,12 +251,12 @@ account_widget_generic_format_param_name (const gchar *param_name) p++; } - + return str; } static void -accounts_widget_generic_setup (McAccount *account, +accounts_widget_generic_setup (EmpathyAccount *account, GtkWidget *table_common_settings, GtkWidget *table_advanced_settings) { @@ -264,7 +264,7 @@ accounts_widget_generic_setup (McAccount *account, McProfile *profile; GSList *params, *l; - profile = mc_account_get_profile (account); + profile = empathy_account_get_profile (account); protocol = mc_profile_get_protocol (profile); if (!protocol) { @@ -400,7 +400,7 @@ accounts_widget_generic_setup (McAccount *account, } static void -account_widget_handle_params_valist (McAccount *account, +account_widget_handle_params_valist (EmpathyAccount *account, GtkBuilder *gui, const gchar *first_widget, va_list args) @@ -424,14 +424,13 @@ account_widget_handle_params_valist (McAccount *account, } void -empathy_account_widget_handle_params (McAccount *account, +empathy_account_widget_handle_params (EmpathyAccount *account, GtkBuilder *gui, const gchar *first_widget, ...) { va_list args; - g_return_if_fail (MC_IS_ACCOUNT (account)); g_return_if_fail (GTK_IS_BUILDER (gui)); va_start (args, first_widget); @@ -440,7 +439,7 @@ empathy_account_widget_handle_params (McAccount *account, } void -empathy_account_widget_add_forget_button (McAccount *account, +empathy_account_widget_add_forget_button (EmpathyAccount *account, GtkBuilder *gui, const gchar *button, const gchar *entry) @@ -448,11 +447,11 @@ empathy_account_widget_add_forget_button (McAccount *account, GtkWidget *button_forget; GtkWidget *entry_password; gchar *password = NULL; - + button_forget = GTK_WIDGET (gtk_builder_get_object (gui, button)); entry_password = GTK_WIDGET (gtk_builder_get_object (gui, entry)); - mc_account_get_param_string (account, "password", &password); + password = empathy_account_get_param_string (account, "password"); gtk_widget_set_sensitive (button_forget, !EMP_STR_EMPTY (password)); g_free (password); @@ -477,7 +476,7 @@ empathy_account_widget_set_default_focus (GtkBuilder *gui, } GtkWidget * -empathy_account_widget_generic_new (McAccount *account) +empathy_account_widget_generic_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -485,8 +484,6 @@ empathy_account_widget_generic_new (McAccount *account) GtkWidget *table_advanced_settings; gchar *filename; - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - filename = empathy_file_lookup ("empathy-account-widget-generic.ui", "libempathy-gtk"); gui = empathy_builder_get_file (filename, @@ -502,7 +499,7 @@ empathy_account_widget_generic_new (McAccount *account) } GtkWidget * -empathy_account_widget_salut_new (McAccount *account) +empathy_account_widget_salut_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -530,7 +527,7 @@ empathy_account_widget_salut_new (McAccount *account) } GtkWidget * -empathy_account_widget_msn_new (McAccount *account) +empathy_account_widget_msn_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -560,7 +557,7 @@ empathy_account_widget_msn_new (McAccount *account) } GtkWidget * -empathy_account_widget_jabber_new (McAccount *account) +empathy_account_widget_jabber_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -603,7 +600,7 @@ empathy_account_widget_jabber_new (McAccount *account) } GtkWidget * -empathy_account_widget_icq_new (McAccount *account) +empathy_account_widget_icq_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -636,7 +633,7 @@ empathy_account_widget_icq_new (McAccount *account) } GtkWidget * -empathy_account_widget_aim_new (McAccount *account) +empathy_account_widget_aim_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -668,7 +665,7 @@ empathy_account_widget_aim_new (McAccount *account) } GtkWidget * -empathy_account_widget_yahoo_new (McAccount *account) +empathy_account_widget_yahoo_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; @@ -702,7 +699,7 @@ empathy_account_widget_yahoo_new (McAccount *account) } GtkWidget * -empathy_account_widget_groupwise_new (McAccount *account) +empathy_account_widget_groupwise_new (EmpathyAccount *account) { GtkBuilder *gui; GtkWidget *widget; diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h index 7287f5675..7a76db9e0 100644 --- a/libempathy-gtk/empathy-account-widget.h +++ b/libempathy-gtk/empathy-account-widget.h @@ -27,28 +27,28 @@ #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> +#include <libempathy/empathy-account.h> G_BEGIN_DECLS -void empathy_account_widget_handle_params (McAccount *account, +void empathy_account_widget_handle_params (EmpathyAccount *account, GtkBuilder *gui, const gchar *first_widget, ...); -void empathy_account_widget_add_forget_button (McAccount *account, +void empathy_account_widget_add_forget_button (EmpathyAccount *account, GtkBuilder *gui, const gchar *button, const gchar *entry); void empathy_account_widget_set_default_focus (GtkBuilder *gui, const gchar *entry); -GtkWidget *empathy_account_widget_generic_new (McAccount *account); -GtkWidget *empathy_account_widget_salut_new (McAccount *account); -GtkWidget *empathy_account_widget_msn_new (McAccount *account); -GtkWidget *empathy_account_widget_jabber_new (McAccount *account); -GtkWidget *empathy_account_widget_icq_new (McAccount *account); -GtkWidget *empathy_account_widget_aim_new (McAccount *account); -GtkWidget *empathy_account_widget_yahoo_new (McAccount *account); -GtkWidget *empathy_account_widget_groupwise_new (McAccount *account); +GtkWidget *empathy_account_widget_generic_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_salut_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_msn_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_jabber_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_icq_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_aim_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_yahoo_new (EmpathyAccount *account); +GtkWidget *empathy_account_widget_groupwise_new (EmpathyAccount *account); G_END_DECLS diff --git a/libempathy-gtk/empathy-avatar-chooser.c b/libempathy-gtk/empathy-avatar-chooser.c index 8c005a029..83475b565 100644 --- a/libempathy-gtk/empathy-avatar-chooser.c +++ b/libempathy-gtk/empathy-avatar-chooser.c @@ -810,14 +810,14 @@ avatar_chooser_drag_data_received_cb (GtkWidget *widget, if (input_stream != NULL) { GFileInfo *info; - + info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL); if (info != NULL) { goffset size; gssize bytes_read; - + size = g_file_info_get_size (info); data = g_malloc (size); @@ -838,7 +838,7 @@ avatar_chooser_drag_data_received_cb (GtkWidget *widget, g_object_unref (input_stream); } - + g_object_unref (file); } diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c index 95e67b714..5ed7c69c3 100644 --- a/libempathy-gtk/empathy-chat-text-view.c +++ b/libempathy-gtk/empathy-chat-text-view.c @@ -34,9 +34,9 @@ #include <gtk/gtk.h> #include <telepathy-glib/util.h> -#include <libmissioncontrol/mc-account.h> #include <libempathy/empathy-utils.h> +#include <libempathy/empathy-account.h> #include "empathy-chat-text-view.h" #include "empathy-chat.h" @@ -103,10 +103,10 @@ chat_text_view_url_event_cb (GtkTextTag *tag, if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end)) { return FALSE; } - + if (event->type == GDK_BUTTON_RELEASE && event->button.button == 1) { start = end = *iter; - + if (gtk_text_iter_backward_to_tag_toggle (&start, tag) && gtk_text_iter_forward_to_tag_toggle (&end, tag)) { str = gtk_text_buffer_get_text (priv->buffer, @@ -118,7 +118,7 @@ chat_text_view_url_event_cb (GtkTextTag *tag, g_free (str); } } - + return FALSE; } @@ -133,31 +133,31 @@ chat_text_view_event_cb (EmpathyChatTextView *view, GtkTextIter iter; GdkWindow *win; gint x, y, buf_x, buf_y; - + type = gtk_text_view_get_window_type (GTK_TEXT_VIEW (view), event->window); - + if (type != GTK_TEXT_WINDOW_TEXT) { return FALSE; } - + /* Get where the pointer really is. */ win = gtk_text_view_get_window (GTK_TEXT_VIEW (view), type); if (!win) { return FALSE; } - + gdk_window_get_pointer (win, &x, &y, NULL); - + /* Get the iter where the cursor is at */ gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view), type, x, y, &buf_x, &buf_y); - + gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, buf_x, buf_y); - + if (gtk_text_iter_has_tag (&iter, tag)) { if (!hand) { hand = gdk_cursor_new (GDK_HAND2); @@ -170,7 +170,7 @@ chat_text_view_event_cb (EmpathyChatTextView *view, } gdk_window_set_cursor (win, beam); } - + return FALSE; } @@ -192,7 +192,7 @@ chat_text_view_create_tags (EmpathyChatTextView *view) g_signal_connect (tag, "event", G_CALLBACK (chat_text_view_url_event_cb), view); - + g_signal_connect (view, "motion-notify-event", G_CALLBACK (chat_text_view_event_cb), tag); @@ -203,7 +203,7 @@ chat_text_view_system_font_update (EmpathyChatTextView *view) { PangoFontDescription *font_description = NULL; gchar *font_name; - + if (empathy_conf_get_string (empathy_conf_get (), "/desktop/gnome/interface/document_font_name", &font_name) && font_name) { @@ -212,9 +212,9 @@ chat_text_view_system_font_update (EmpathyChatTextView *view) } else { font_description = NULL; } - + gtk_widget_modify_font (GTK_WIDGET (view), font_description); - + if (font_description) { pango_font_description_free (font_description); } @@ -226,7 +226,7 @@ chat_text_view_notify_system_font_cb (EmpathyConf *conf, gpointer user_data) { EmpathyChatTextView *view = user_data; - + chat_text_view_system_font_update (view); } @@ -240,10 +240,10 @@ static void chat_text_view_copy_address_cb (GtkMenuItem *menuitem, const gchar *url) { GtkClipboard *clipboard; - + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_text (clipboard, url, -1); - + clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); gtk_clipboard_set_text (clipboard, url, -1); } @@ -260,66 +260,66 @@ chat_text_view_populate_popup (EmpathyChatTextView *view, GtkTextIter iter, start, end; GtkWidget *item; gchar *str = NULL; - + priv = GET_PRIV (view); - + /* Clear menu item */ if (gtk_text_buffer_get_char_count (priv->buffer) > 0) { item = gtk_separator_menu_item_new (); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + g_signal_connect_swapped (item, "activate", G_CALLBACK (empathy_chat_view_clear), view); } - + /* Link context menu items */ table = gtk_text_buffer_get_tag_table (priv->buffer); tag = gtk_text_tag_table_lookup (table, EMPATHY_CHAT_TEXT_VIEW_TAG_LINK); - + gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y); - + gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view), GTK_TEXT_WINDOW_WIDGET, x, y, &x, &y); - + gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y); - + start = end = iter; - + if (gtk_text_iter_backward_to_tag_toggle (&start, tag) && gtk_text_iter_forward_to_tag_toggle (&end, tag)) { str = gtk_text_buffer_get_text (priv->buffer, &start, &end, FALSE); } - + if (EMP_STR_EMPTY (str)) { g_free (str); return; } - + /* NOTE: Set data just to get the string freed when not needed. */ g_object_set_data_full (G_OBJECT (menu), "url", str, (GDestroyNotify) g_free); - + item = gtk_separator_menu_item_new (); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address")); g_signal_connect (item, "activate", G_CALLBACK (chat_text_view_copy_address_cb), str); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + item = gtk_menu_item_new_with_mnemonic (_("_Open Link")); g_signal_connect (item, "activate", G_CALLBACK (chat_text_view_open_address_cb), @@ -332,18 +332,24 @@ static gboolean chat_text_view_is_scrolled_down (EmpathyChatTextView *view) { GtkWidget *sw; - + sw = gtk_widget_get_parent (GTK_WIDGET (view)); if (GTK_IS_SCROLLED_WINDOW (sw)) { GtkAdjustment *vadj; - + gdouble value; + gdouble upper; + gdouble page_size; + vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw)); - - if (vadj->value + vadj->page_size / 2 < vadj->upper - vadj->page_size) { + value = gtk_adjustment_get_value (vadj); + upper = gtk_adjustment_get_upper (vadj); + page_size = gtk_adjustment_get_page_size (vadj); + + if (value < upper - page_size) { return FALSE; } } - + return TRUE; } @@ -356,23 +362,23 @@ chat_text_view_maybe_trim_buffer (EmpathyChatTextView *view) gint remove; GtkTextTagTable *table; GtkTextTag *tag; - + priv = GET_PRIV (view); - + gtk_text_buffer_get_end_iter (priv->buffer, &bottom); line = gtk_text_iter_get_line (&bottom); if (line < MAX_LINES) { return; } - + remove = line - MAX_LINES; gtk_text_buffer_get_start_iter (priv->buffer, &top); - + bottom = top; if (!gtk_text_iter_forward_lines (&bottom, remove)) { return; } - + /* Track backwords to a place where we can safely cut, we don't do it in * the middle of a tag. */ @@ -381,11 +387,11 @@ chat_text_view_maybe_trim_buffer (EmpathyChatTextView *view) if (!tag) { return; } - + if (!gtk_text_iter_forward_to_tag_toggle (&bottom, tag)) { return; } - + if (!gtk_text_iter_equal (&top, &bottom)) { gtk_text_buffer_delete (priv->buffer, &top, &bottom); } @@ -436,7 +442,7 @@ chat_text_view_append_timestamp (EmpathyChatTextView *view, priv->last_timestamp = timestamp; - g_string_free (str, TRUE); + g_string_free (str, TRUE); } static void @@ -461,7 +467,7 @@ chat_text_maybe_append_date_and_time (EmpathyChatTextView *view, append_date = TRUE; append_time = TRUE; } - + g_date_free (last_date); g_date_free (date); @@ -480,14 +486,14 @@ chat_text_view_size_allocate (GtkWidget *widget, GtkAllocation *alloc) { gboolean down; - + down = chat_text_view_is_scrolled_down (EMPATHY_CHAT_TEXT_VIEW (widget)); - + GTK_WIDGET_CLASS (empathy_chat_text_view_parent_class)->size_allocate (widget, alloc); - + if (down) { GtkAdjustment *adj; - + adj = GTK_TEXT_VIEW (widget)->vadjustment; gtk_adjustment_set_value (adj, adj->upper - adj->page_size); } @@ -502,7 +508,7 @@ chat_text_view_drag_motion (GtkWidget *widget, { /* Don't handle drag motion, since we don't want the view to scroll as * the result of dragging something across it. */ - + return FALSE; } @@ -550,14 +556,14 @@ chat_text_view_finalize (GObject *object) { EmpathyChatTextView *view; EmpathyChatTextViewPriv *priv; - + view = EMPATHY_CHAT_TEXT_VIEW (object); priv = GET_PRIV (view); - + DEBUG ("%p", object); - + empathy_conf_notify_remove (empathy_conf_get (), priv->notify_system_fonts_id); - + if (priv->last_contact) { g_object_unref (priv->last_contact); } @@ -568,7 +574,7 @@ chat_text_view_finalize (GObject *object) g_source_remove (priv->scroll_timeout); } g_object_unref (priv->smiley_manager); - + G_OBJECT_CLASS (empathy_chat_text_view_parent_class)->finalize (object); } @@ -577,7 +583,7 @@ empathy_chat_text_view_class_init (EmpathyChatTextViewClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - + object_class->finalize = chat_text_view_finalize; object_class->get_property = chat_text_view_get_property; object_class->set_property = chat_text_view_set_property; @@ -610,18 +616,18 @@ empathy_chat_text_view_init (EmpathyChatTextView *view) EmpathyChatTextViewPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (view, EMPATHY_TYPE_CHAT_TEXT_VIEW, EmpathyChatTextViewPriv); - view->priv = priv; + view->priv = priv; priv->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); priv->last_timestamp = 0; priv->allow_scrolling = TRUE; priv->smiley_manager = empathy_smiley_manager_dup_singleton (); - + g_object_set (view, "wrap-mode", GTK_WRAP_WORD_CHAR, "editable", FALSE, "cursor-visible", FALSE, NULL); - + priv->notify_system_fonts_id = empathy_conf_notify_add (empathy_conf_get (), "/desktop/gnome/interface/document_font_name", @@ -643,13 +649,13 @@ chat_text_view_scroll_cb (EmpathyChatTextView *view) EmpathyChatTextViewPriv *priv; GtkAdjustment *adj; gdouble max_val; - + priv = GET_PRIV (view); adj = GTK_TEXT_VIEW (view)->vadjustment; max_val = adj->upper - adj->page_size; - + g_return_val_if_fail (priv->scroll_time != NULL, FALSE); - + if (g_timer_elapsed (priv->scroll_time, NULL) > MAX_SCROLL_TIME) { /* time's up. jump to the end and kill the timer */ gtk_adjustment_set_value (adj, max_val); @@ -658,7 +664,7 @@ chat_text_view_scroll_cb (EmpathyChatTextView *view) priv->scroll_timeout = 0; return FALSE; } - + /* scroll by 1/3rd the remaining distance */ gtk_adjustment_set_value (adj, gtk_adjustment_get_value (adj) + ((max_val - gtk_adjustment_get_value (adj)) / 3)); return TRUE; @@ -668,9 +674,9 @@ static void chat_text_view_scroll_down (EmpathyChatView *view) { EmpathyChatTextViewPriv *priv = GET_PRIV (view); - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); - + if (!priv->allow_scrolling) { return; } @@ -697,29 +703,29 @@ chat_text_view_append_message (EmpathyChatView *view, EmpathyChatTextViewPriv *priv = GET_PRIV (text_view); gboolean bottom; time_t timestamp; - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); g_return_if_fail (EMPATHY_IS_MESSAGE (msg)); - + if (!empathy_message_get_body (msg)) { return; } - + bottom = chat_text_view_is_scrolled_down (text_view); - + chat_text_view_maybe_trim_buffer (EMPATHY_CHAT_TEXT_VIEW (view)); - + timestamp = empathy_message_get_timestamp (msg); chat_text_maybe_append_date_and_time (text_view, timestamp); if (EMPATHY_CHAT_TEXT_VIEW_GET_CLASS (view)->append_message) { EMPATHY_CHAT_TEXT_VIEW_GET_CLASS (view)->append_message (text_view, msg); } - + if (bottom) { chat_text_view_scroll_down (view); } - + if (priv->last_contact) { g_object_unref (priv->last_contact); } @@ -757,7 +763,7 @@ chat_text_view_append_event (EmpathyChatView *view, if (bottom) { chat_text_view_scroll_down (view); } - + if (priv->last_contact) { g_object_unref (priv->last_contact); priv->last_contact = NULL; @@ -770,9 +776,9 @@ chat_text_view_scroll (EmpathyChatView *view, gboolean allow_scrolling) { EmpathyChatTextViewPriv *priv = GET_PRIV (view); - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); - + DEBUG ("Scrolling %s", allow_scrolling ? "enabled" : "disabled"); priv->allow_scrolling = allow_scrolling; @@ -785,11 +791,11 @@ static gboolean chat_text_view_get_has_selection (EmpathyChatView *view) { GtkTextBuffer *buffer; - + g_return_val_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view), FALSE); - + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - + return gtk_text_buffer_get_has_selection (buffer); } @@ -798,18 +804,18 @@ chat_text_view_clear (EmpathyChatView *view) { GtkTextBuffer *buffer; EmpathyChatTextViewPriv *priv; - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); - + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_set_text (buffer, "", -1); - + /* We set these back to the initial values so we get * timestamps when clearing the window to know when * conversations start. */ priv = GET_PRIV (view); - + priv->last_timestamp = 0; } @@ -825,18 +831,18 @@ chat_text_view_find_previous (EmpathyChatView *view, GtkTextIter iter_match_end; gboolean found; gboolean from_start = FALSE; - + g_return_val_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view), FALSE); g_return_val_if_fail (search_criteria != NULL, FALSE); - + priv = GET_PRIV (view); - + buffer = priv->buffer; - + if (EMP_STR_EMPTY (search_criteria)) { if (priv->find_mark_previous) { gtk_text_buffer_get_start_iter (buffer, &iter_at_mark); - + gtk_text_buffer_move_mark (buffer, priv->find_mark_previous, &iter_at_mark); @@ -850,14 +856,14 @@ chat_text_view_find_previous (EmpathyChatView *view, &iter_at_mark, &iter_at_mark); } - + return FALSE; } - + if (new_search) { from_start = TRUE; } - + if (priv->find_mark_previous) { gtk_text_buffer_get_iter_at_mark (buffer, &iter_at_mark, @@ -866,22 +872,22 @@ chat_text_view_find_previous (EmpathyChatView *view, gtk_text_buffer_get_end_iter (buffer, &iter_at_mark); from_start = TRUE; } - + priv->find_last_direction = FALSE; - + found = empathy_text_iter_backward_search (&iter_at_mark, search_criteria, &iter_match_start, &iter_match_end, NULL); - + if (!found) { gboolean result = FALSE; - + if (from_start) { return result; } - + /* Here we wrap around. */ if (!new_search && !priv->find_wrapped) { priv->find_wrapped = TRUE; @@ -890,10 +896,10 @@ chat_text_view_find_previous (EmpathyChatView *view, FALSE); priv->find_wrapped = FALSE; } - + return result; } - + /* Set new mark and show on screen */ if (!priv->find_mark_previous) { priv->find_mark_previous = gtk_text_buffer_create_mark (buffer, NULL, @@ -904,7 +910,7 @@ chat_text_view_find_previous (EmpathyChatView *view, priv->find_mark_previous, &iter_match_start); } - + if (!priv->find_mark_next) { priv->find_mark_next = gtk_text_buffer_create_mark (buffer, NULL, &iter_match_end, @@ -914,17 +920,17 @@ chat_text_view_find_previous (EmpathyChatView *view, priv->find_mark_next, &iter_match_end); } - + gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view), priv->find_mark_previous, 0.0, TRUE, 0.5, 0.5); - + gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &iter_match_start); gtk_text_buffer_move_mark_by_name (buffer, "insert", &iter_match_end); - + return TRUE; } @@ -940,18 +946,18 @@ chat_text_view_find_next (EmpathyChatView *view, GtkTextIter iter_match_end; gboolean found; gboolean from_start = FALSE; - + g_return_val_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view), FALSE); g_return_val_if_fail (search_criteria != NULL, FALSE); - + priv = GET_PRIV (view); - + buffer = priv->buffer; - + if (EMP_STR_EMPTY (search_criteria)) { if (priv->find_mark_next) { gtk_text_buffer_get_start_iter (buffer, &iter_at_mark); - + gtk_text_buffer_move_mark (buffer, priv->find_mark_next, &iter_at_mark); @@ -965,14 +971,14 @@ chat_text_view_find_next (EmpathyChatView *view, &iter_at_mark, &iter_at_mark); } - + return FALSE; } - + if (new_search) { from_start = TRUE; } - + if (priv->find_mark_next) { gtk_text_buffer_get_iter_at_mark (buffer, &iter_at_mark, @@ -981,22 +987,22 @@ chat_text_view_find_next (EmpathyChatView *view, gtk_text_buffer_get_start_iter (buffer, &iter_at_mark); from_start = TRUE; } - + priv->find_last_direction = TRUE; - + found = empathy_text_iter_forward_search (&iter_at_mark, search_criteria, &iter_match_start, &iter_match_end, NULL); - + if (!found) { gboolean result = FALSE; - + if (from_start) { return result; } - + /* Here we wrap around. */ if (!new_search && !priv->find_wrapped) { priv->find_wrapped = TRUE; @@ -1005,10 +1011,10 @@ chat_text_view_find_next (EmpathyChatView *view, FALSE); priv->find_wrapped = FALSE; } - + return result; } - + /* Set new mark and show on screen */ if (!priv->find_mark_next) { priv->find_mark_next = gtk_text_buffer_create_mark (buffer, NULL, @@ -1019,7 +1025,7 @@ chat_text_view_find_next (EmpathyChatView *view, priv->find_mark_next, &iter_match_end); } - + if (!priv->find_mark_previous) { priv->find_mark_previous = gtk_text_buffer_create_mark (buffer, NULL, &iter_match_start, @@ -1029,17 +1035,17 @@ chat_text_view_find_next (EmpathyChatView *view, priv->find_mark_previous, &iter_match_start); } - + gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view), priv->find_mark_next, 0.0, TRUE, 0.5, 0.5); - + gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &iter_match_start); gtk_text_buffer_move_mark_by_name (buffer, "insert", &iter_match_end); - + return TRUE; } @@ -1054,15 +1060,15 @@ chat_text_view_find_abilities (EmpathyChatView *view, GtkTextIter iter_at_mark; GtkTextIter iter_match_start; GtkTextIter iter_match_end; - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); g_return_if_fail (search_criteria != NULL); g_return_if_fail (can_do_previous != NULL && can_do_next != NULL); - + priv = GET_PRIV (view); - + buffer = priv->buffer; - + if (can_do_previous) { if (priv->find_mark_previous) { gtk_text_buffer_get_iter_at_mark (buffer, @@ -1071,14 +1077,14 @@ chat_text_view_find_abilities (EmpathyChatView *view, } else { gtk_text_buffer_get_start_iter (buffer, &iter_at_mark); } - + *can_do_previous = empathy_text_iter_backward_search (&iter_at_mark, search_criteria, &iter_match_start, &iter_match_end, NULL); } - + if (can_do_next) { if (priv->find_mark_next) { gtk_text_buffer_get_iter_at_mark (buffer, @@ -1087,7 +1093,7 @@ chat_text_view_find_abilities (EmpathyChatView *view, } else { gtk_text_buffer_get_start_iter (buffer, &iter_at_mark); } - + *can_do_next = empathy_text_iter_forward_search (&iter_at_mark, search_criteria, &iter_match_start, @@ -1107,37 +1113,37 @@ chat_text_view_highlight (EmpathyChatView *view, GtkTextIter iter_match_start; GtkTextIter iter_match_end; gboolean found; - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); - + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - + gtk_text_buffer_get_start_iter (buffer, &iter); - + gtk_text_buffer_get_bounds (buffer, &iter_start, &iter_end); gtk_text_buffer_remove_tag_by_name (buffer, EMPATHY_CHAT_TEXT_VIEW_TAG_HIGHLIGHT, &iter_start, &iter_end); - + if (EMP_STR_EMPTY (text)) { return; } - + while (1) { found = empathy_text_iter_forward_search (&iter, text, &iter_match_start, &iter_match_end, NULL); - + if (!found) { break; } - + gtk_text_buffer_apply_tag_by_name (buffer, EMPATHY_CHAT_TEXT_VIEW_TAG_HIGHLIGHT, &iter_match_start, &iter_match_end); - + iter = iter_match_end; gtk_text_iter_forward_char (&iter); } @@ -1148,12 +1154,12 @@ chat_text_view_copy_clipboard (EmpathyChatView *view) { GtkTextBuffer *buffer; GtkClipboard *clipboard; - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); - + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - + gtk_text_buffer_copy_clipboard (buffer, clipboard); } @@ -1177,9 +1183,9 @@ EmpathyContact * empathy_chat_text_view_get_last_contact (EmpathyChatTextView *view) { EmpathyChatTextViewPriv *priv = GET_PRIV (view); - + g_return_val_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view), NULL); - + return priv->last_contact; } @@ -1188,7 +1194,7 @@ empathy_chat_text_view_set_only_if_date (EmpathyChatTextView *view, gboolean only_if_date) { EmpathyChatTextViewPriv *priv = GET_PRIV (view); - + g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); if (only_if_date != priv->only_if_date) { diff --git a/libempathy-gtk/empathy-chat-view.c b/libempathy-gtk/empathy-chat-view.c index e0a7905df..ed5740a8e 100644 --- a/libempathy-gtk/empathy-chat-view.c +++ b/libempathy-gtk/empathy-chat-view.c @@ -31,21 +31,21 @@ GType empathy_chat_view_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo type_info = { sizeof (EmpathyChatViewIface), chat_view_base_init, NULL, }; - + type = g_type_register_static (G_TYPE_INTERFACE, "EmpathyChatView", &type_info, 0); - + g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET); } - + return type; } @@ -53,7 +53,7 @@ static void chat_view_base_init (gpointer klass) { static gboolean initialized = FALSE; - + if (!initialized) { initialized = TRUE; } @@ -64,7 +64,7 @@ empathy_chat_view_append_message (EmpathyChatView *view, EmpathyMessage *msg) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_message) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_message (view, msg); @@ -76,7 +76,7 @@ empathy_chat_view_append_event (EmpathyChatView *view, const gchar *str) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event (view, str); @@ -88,7 +88,7 @@ empathy_chat_view_scroll (EmpathyChatView *view, gboolean allow_scrolling) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll (view, allow_scrolling); @@ -99,7 +99,7 @@ void empathy_chat_view_scroll_down (EmpathyChatView *view) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll_down) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->scroll_down (view); } @@ -109,7 +109,7 @@ gboolean empathy_chat_view_get_has_selection (EmpathyChatView *view) { g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_has_selection) { return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->get_has_selection (view); } @@ -120,7 +120,7 @@ void empathy_chat_view_clear (EmpathyChatView *view) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->clear) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->clear (view); } @@ -132,7 +132,7 @@ empathy_chat_view_find_previous (EmpathyChatView *view, gboolean new_search) { g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_previous) { return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_previous (view, search_criteria, @@ -147,7 +147,7 @@ empathy_chat_view_find_next (EmpathyChatView *view, gboolean new_search) { g_return_val_if_fail (EMPATHY_IS_CHAT_VIEW (view), FALSE); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_next) { return EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_next (view, search_criteria, @@ -164,7 +164,7 @@ empathy_chat_view_find_abilities (EmpathyChatView *view, gboolean *can_do_next) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_abilities) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->find_abilities (view, search_criteria, @@ -178,7 +178,7 @@ empathy_chat_view_highlight (EmpathyChatView *view, const gchar *text) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->highlight) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->highlight (view, text); } @@ -188,7 +188,7 @@ void empathy_chat_view_copy_clipboard (EmpathyChatView *view) { g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view)); - + if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->copy_clipboard) { EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->copy_clipboard (view); } diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index f25734a10..1729e5305 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -64,11 +64,12 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat) typedef struct { EmpathyTpChat *tp_chat; - McAccount *account; + EmpathyAccount *account; gchar *id; gchar *name; gchar *subject; EmpathyContact *remote_contact; + gboolean show_contacts; EmpathyLogManager *log_manager; EmpathyAccountManager *account_manager; @@ -107,6 +108,7 @@ enum { PROP_NAME, PROP_SUBJECT, PROP_REMOTE_CONTACT, + PROP_SHOW_CONTACTS, }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -141,6 +143,9 @@ chat_get_property (GObject *object, case PROP_REMOTE_CONTACT: g_value_set_object (value, priv->remote_contact); break; + case PROP_SHOW_CONTACTS: + g_value_set_boolean (value, priv->show_contacts); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -159,6 +164,9 @@ chat_set_property (GObject *object, case PROP_TP_CHAT: empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value))); break; + case PROP_SHOW_CONTACTS: + empathy_chat_set_show_contacts (chat, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -193,13 +201,13 @@ chat_new_connection_cb (EmpathyAccountManager *manager, EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); - McAccount *account; + EmpathyAccount *account; account = empathy_account_manager_get_account (manager, connection); if (!priv->tp_chat && empathy_account_equal (account, priv->account) && priv->handle_type != TP_HANDLE_TYPE_NONE && !EMP_STR_EMPTY (priv->id)) { - + DEBUG ("Account reconnected, request a new Text channel"); switch (priv->handle_type) { @@ -294,7 +302,7 @@ chat_sent_message_add (EmpathyChat *chat, /* Save the sent message in our repeat buffer */ list = priv->sent_messages; - + /* Remove any other occurances of this msg */ while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) { list = g_slist_remove_link (list, item); @@ -325,7 +333,7 @@ chat_sent_message_get_next (EmpathyChat *chat) { EmpathyChatPriv *priv; gint max; - + priv = GET_PRIV (chat); if (!priv->sent_messages) { @@ -338,7 +346,7 @@ chat_sent_message_get_next (EmpathyChat *chat) if (priv->sent_messages_index < max) { priv->sent_messages_index++; } - + DEBUG ("Returning next message index:%d", priv->sent_messages_index); return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index); @@ -352,7 +360,7 @@ chat_sent_message_get_last (EmpathyChat *chat) g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL); priv = GET_PRIV (chat); - + if (!priv->sent_messages) { DEBUG ("No sent messages, last message is NULL"); return NULL; @@ -1239,15 +1247,18 @@ chat_reset_size_request (gpointer widget) } static void -chat_set_show_contacts (EmpathyChat *chat, gboolean show) +chat_update_contacts_visibility (EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); + gboolean show; + + show = priv->remote_contact == NULL && priv->show_contacts; if (!priv->scrolled_window_contacts) { return; } - if (show) { + if (show && priv->contact_list_view == NULL) { EmpathyContactListStore *store; gint min_width; @@ -1278,34 +1289,47 @@ chat_set_show_contacts (EmpathyChat *chat, gboolean show) gtk_widget_show (priv->contact_list_view); gtk_widget_show (priv->scrolled_window_contacts); g_object_unref (store); - } else { + } else if (!show) { priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned)); gtk_widget_hide (priv->scrolled_window_contacts); - if (priv->contact_list_view) { + if (priv->contact_list_view != NULL) { gtk_widget_destroy (priv->contact_list_view); priv->contact_list_view = NULL; } } } +void +empathy_chat_set_show_contacts (EmpathyChat *chat, + gboolean show) +{ + EmpathyChatPriv *priv = GET_PRIV (chat); + + priv->show_contacts = show; + + chat_update_contacts_visibility (chat); + + g_object_notify (G_OBJECT (chat), "show-contacts"); +} + static void chat_remote_contact_changed_cb (EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); - if (priv->remote_contact) { + if (priv->remote_contact != NULL) { g_object_unref (priv->remote_contact); priv->remote_contact = NULL; } priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat); - if (priv->remote_contact) { + if (priv->remote_contact != NULL) { g_object_ref (priv->remote_contact); priv->handle_type = TP_HANDLE_TYPE_CONTACT; g_free (priv->id); priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact)); } - else if (priv->tp_chat) { + else if (priv->tp_chat != NULL) { TpChannel *channel; channel = empathy_tp_chat_get_channel (priv->tp_chat); @@ -1314,7 +1338,7 @@ chat_remote_contact_changed_cb (EmpathyChat *chat) priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat)); } - chat_set_show_contacts (chat, priv->remote_contact == NULL); + chat_update_contacts_visibility (chat); g_object_notify (G_OBJECT (chat), "remote-contact"); g_object_notify (G_OBJECT (chat), "id"); @@ -1339,7 +1363,7 @@ chat_destroy_cb (EmpathyTpChat *tp_chat, empathy_chat_view_append_event (chat->view, _("Disconnected")); gtk_widget_set_sensitive (chat->input_text_view, FALSE); - chat_set_show_contacts (chat, FALSE); + empathy_chat_set_show_contacts (chat, FALSE); } static void @@ -1424,7 +1448,7 @@ chat_create_ui (EmpathyChat *chat) gtk_widget_show (chat->input_text_view); /* Create contact list */ - chat_set_show_contacts (chat, priv->remote_contact == NULL); + chat_update_contacts_visibility (chat); /* Initialy hide the topic, will be shown if not empty */ gtk_widget_hide (priv->hbox_topic); @@ -1582,42 +1606,56 @@ empathy_chat_class_init (EmpathyChatClass *klass) "The tp chat object", EMPATHY_TYPE_TP_CHAT, G_PARAM_CONSTRUCT | - G_PARAM_READWRITE)); + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ACCOUNT, g_param_spec_object ("account", "Account of the chat", "The account of the chat", - MC_TYPE_ACCOUNT, - G_PARAM_READABLE)); + EMPATHY_TYPE_ACCOUNT, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ID, g_param_spec_string ("id", "Chat's id", "The id of the chat", NULL, - G_PARAM_READABLE)); + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_NAME, g_param_spec_string ("name", "Chat's name", "The name of the chat", NULL, - G_PARAM_READABLE)); + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_SUBJECT, g_param_spec_string ("subject", "Chat's subject", "The subject or topic of the chat", NULL, - G_PARAM_READABLE)); + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_REMOTE_CONTACT, g_param_spec_object ("remote-contact", "The remote contact", "The remote contact is any", EMPATHY_TYPE_CONTACT, - G_PARAM_READABLE)); + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_SHOW_CONTACTS, + g_param_spec_boolean ("show-contacts", + "Contacts' visibility", + "The visibility of the contacts' list", + TRUE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); signals[COMPOSING] = g_signal_new ("composing", @@ -1670,6 +1708,10 @@ empathy_chat_init (EmpathyChat *chat) G_CALLBACK (chat_new_connection_cb), chat); + empathy_conf_get_bool (empathy_conf_get (), + EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS, + &priv->show_contacts); + /* Block events for some time to avoid having "has come online" or * "joined" messages. */ priv->block_events_timeout_id = @@ -1762,7 +1804,7 @@ empathy_chat_set_tp_chat (EmpathyChat *chat, show_pending_messages (chat); } -McAccount * +EmpathyAccount * empathy_chat_get_account (EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); diff --git a/libempathy-gtk/empathy-chat.h b/libempathy-gtk/empathy-chat.h index 12fac9617..c7158759a 100644 --- a/libempathy-gtk/empathy-chat.h +++ b/libempathy-gtk/empathy-chat.h @@ -66,7 +66,7 @@ EmpathyChat * empathy_chat_new (EmpathyTpChat *tp_chat); EmpathyTpChat * empathy_chat_get_tp_chat (EmpathyChat *chat); void empathy_chat_set_tp_chat (EmpathyChat *chat, EmpathyTpChat *tp_chat); -McAccount * empathy_chat_get_account (EmpathyChat *chat); +EmpathyAccount * empathy_chat_get_account (EmpathyChat *chat); const gchar * empathy_chat_get_id (EmpathyChat *chat); const gchar * empathy_chat_get_name (EmpathyChat *chat); const gchar * empathy_chat_get_subject (EmpathyChat *chat); @@ -82,6 +82,8 @@ void empathy_chat_correct_word (EmpathyChat *chat, GtkTextIter *end, const gchar *new_word); gboolean empathy_chat_is_room (EmpathyChat *chat); +void empathy_chat_set_show_contacts (EmpathyChat *chat, + gboolean show); G_END_DECLS #endif /* __EMPATHY_CHAT_H__ */ diff --git a/libempathy-gtk/empathy-conf.h b/libempathy-gtk/empathy-conf.h index 47949139e..937a4bf9c 100644 --- a/libempathy-gtk/empathy-conf.h +++ b/libempathy-gtk/empathy-conf.h @@ -48,6 +48,8 @@ struct _EmpathyConfClass { #define EMPATHY_PREFS_NOTIFICATIONS_ENABLED EMPATHY_PREFS_PATH "/notifications/notifications_enabled" #define EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY EMPATHY_PREFS_PATH "/notifications/notifications_disabled_away" #define EMPATHY_PREFS_NOTIFICATIONS_FOCUS EMPATHY_PREFS_PATH "/notifications/notifications_focus" +#define EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN EMPATHY_PREFS_PATH "/notifications/notifications_contact_signin" +#define EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT EMPATHY_PREFS_PATH "/notifications/notifications_contact_signout" #define EMPATHY_PREFS_SOUNDS_ENABLED EMPATHY_PREFS_PATH "/sounds/sounds_enabled" #define EMPATHY_PREFS_SOUNDS_DISABLED_AWAY EMPATHY_PREFS_PATH "/sounds/sounds_disabled_away" #define EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE EMPATHY_PREFS_PATH "/sounds/sounds_incoming_message" @@ -59,6 +61,7 @@ struct _EmpathyConfClass { #define EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT EMPATHY_PREFS_PATH "/sounds/sounds_contact_logout" #define EMPATHY_PREFS_POPUPS_WHEN_AVAILABLE EMPATHY_PREFS_PATH "/notifications/popups_when_available" #define EMPATHY_PREFS_CHAT_SHOW_SMILEYS EMPATHY_PREFS_PATH "/conversation/graphical_smileys" +#define EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS EMPATHY_PREFS_PATH "/conversation/show_contacts_in_rooms" #define EMPATHY_PREFS_CHAT_THEME EMPATHY_PREFS_PATH "/conversation/theme" #define EMPATHY_PREFS_CHAT_ADIUM_PATH EMPATHY_PREFS_PATH "/conversation/adium_path" #define EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES EMPATHY_PREFS_PATH "/conversation/spell_checker_languages" diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c index 307b0fbb3..c1cca3e2b 100644 --- a/libempathy-gtk/empathy-contact-dialogs.c +++ b/libempathy-gtk/empathy-contact-dialogs.c @@ -328,26 +328,18 @@ empathy_contact_personal_dialog_show (GtkWindow *parent) */ static gboolean -can_add_contact_to_account (McAccount *account, +can_add_contact_to_account (EmpathyAccount *account, gpointer user_data) { - EmpathyAccountManager *account_manager; EmpathyContactManager *contact_manager; TpConnection *connection; gboolean result; - account_manager = empathy_account_manager_dup_singleton (); - connection = empathy_account_manager_get_connection (account_manager, - account); - if (!connection) { - g_object_unref (account_manager); - return FALSE; - } + connection = empathy_account_get_connection (account); contact_manager = empathy_contact_manager_dup_singleton (); result = empathy_contact_manager_can_add (contact_manager, connection); g_object_unref (contact_manager); - g_object_unref (account_manager); return result; } @@ -398,7 +390,7 @@ empathy_new_contact_dialog_show (GtkWindow *parent) button, GTK_RESPONSE_CANCEL); gtk_widget_show (button); - + /* Add button */ button = gtk_button_new_with_label (GTK_STOCK_ADD); gtk_button_set_use_stock (GTK_BUTTON (button), TRUE); diff --git a/libempathy-gtk/empathy-contact-list-store.c b/libempathy-gtk/empathy-contact-list-store.c index 261b2cc60..0e9372be1 100644 --- a/libempathy-gtk/empathy-contact-list-store.c +++ b/libempathy-gtk/empathy-contact-list-store.c @@ -601,7 +601,7 @@ empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *stor EMPATHY_CONTACT_LIST_STORE_COL_STATUS, GTK_SORT_ASCENDING); break; - + case EMPATHY_CONTACT_LIST_STORE_SORT_NAME: gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), EMPATHY_CONTACT_LIST_STORE_COL_NAME, @@ -738,7 +738,7 @@ contact_list_store_setup (EmpathyContactListStore *store) G_TYPE_BOOLEAN, /* Is separator */ G_TYPE_BOOLEAN, /* Can make audio calls */ G_TYPE_BOOLEAN}; /* Can make video calls */ - + priv = GET_PRIV (store); gtk_tree_store_set_column_types (GTK_TREE_STORE (store), @@ -853,7 +853,7 @@ contact_list_store_add_contact (EmpathyContactListStore *store, GList *groups = NULL, *l; priv = GET_PRIV (store); - + if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) || (!priv->show_offline && !empathy_contact_is_online (contact))) { return; @@ -922,7 +922,7 @@ contact_list_store_remove_contact (EmpathyContactListStore *store, if (!iters) { return; } - + /* Clean up model */ model = GTK_TREE_MODEL (store); @@ -1156,7 +1156,7 @@ contact_list_store_contact_active_new (EmpathyContactListStore *store, DEBUG ("Contact:'%s' now active, and %s be removed", empathy_contact_get_name (contact), remove ? "WILL" : "WILL NOT"); - + data = g_slice_new0 (ShowActiveData); data->store = g_object_ref (store); diff --git a/libempathy-gtk/empathy-contact-list-view.c b/libempathy-gtk/empathy-contact-list-view.c index c106653b1..f7b506e7c 100644 --- a/libempathy-gtk/empathy-contact-list-view.c +++ b/libempathy-gtk/empathy-contact-list-view.c @@ -32,7 +32,6 @@ #include <gtk/gtk.h> #include <telepathy-glib/util.h> -#include <libmissioncontrol/mc-account.h> #include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-call-factory.h> @@ -121,7 +120,7 @@ contact_list_view_tooltip_destroy_cb (GtkWidget *widget, EmpathyContactListView *view) { EmpathyContactListViewPriv *priv = GET_PRIV (view); - + if (priv->tooltip_widget) { DEBUG ("Tooltip destroyed"); g_object_unref (priv->tooltip_widget); @@ -230,7 +229,7 @@ contact_list_view_drag_got_contact (EmpathyTpContactFactory *factory, if (data->new_group) { empathy_contact_list_add_to_group (list, contact, data->new_group); } - if (data->old_group && data->action == GDK_ACTION_MOVE) { + if (data->old_group && data->action == GDK_ACTION_MOVE) { empathy_contact_list_remove_from_group (list, contact, data->old_group); } } @@ -247,7 +246,7 @@ contact_list_view_drag_data_received (GtkWidget *view, EmpathyContactListViewPriv *priv; EmpathyAccountManager *account_manager; EmpathyTpContactFactory *factory = NULL; - McAccount *account; + EmpathyAccount *account; GtkTreeModel *model; GtkTreeViewDropPosition position; GtkTreePath *path; @@ -302,19 +301,17 @@ contact_list_view_drag_data_received (GtkWidget *view, strv = g_strsplit (id, "/", 2); account_id = strv[0]; contact_id = strv[1]; - account = mc_account_lookup (account_id); + account_manager = empathy_account_manager_dup_singleton (); + account = empathy_account_manager_lookup (account_manager, account_id); if (account) { TpConnection *connection; - /* FIXME: We assume we have already an account manager */ - account_manager = empathy_account_manager_dup_singleton (); - connection = empathy_account_manager_get_connection (account_manager, - account); + connection = empathy_account_get_connection (account); if (connection) { factory = empathy_tp_contact_factory_dup_singleton (connection); } - g_object_unref (account_manager); } + g_object_unref (account_manager); if (!factory) { DEBUG ("Failed to get factory for account '%s'", account_id); @@ -451,7 +448,7 @@ contact_list_view_drag_data_get (GtkWidget *widget, GtkTreeIter iter; GtkTreeModel *model; EmpathyContact *contact; - McAccount *account; + EmpathyAccount *account; const gchar *contact_id; const gchar *account_id; gchar *str; @@ -481,7 +478,7 @@ contact_list_view_drag_data_get (GtkWidget *widget, } account = empathy_contact_get_account (contact); - account_id = mc_account_get_unique_name (account); + account_id = empathy_account_get_unique_name (account); contact_id = empathy_contact_get_id (contact); g_object_unref (contact); str = g_strconcat (account_id, "/", contact_id, NULL); @@ -1272,7 +1269,7 @@ empathy_contact_list_view_new (EmpathyContactListStore *store, EmpathyContactFeatureFlags contact_features) { g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), NULL); - + return g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, "store", store, "contact-features", contact_features, @@ -1344,7 +1341,7 @@ contact_list_view_remove_dialog_show (GtkWindow *parent, { GtkWidget *dialog; gboolean res; - + dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message); @@ -1446,7 +1443,7 @@ contact_list_view_remove_activate_cb (GtkMenuItem *menuitem, { EmpathyContactListViewPriv *priv = GET_PRIV (view); EmpathyContact *contact; - + contact = empathy_contact_list_view_dup_selected (view); if (contact) { @@ -1455,7 +1452,7 @@ contact_list_view_remove_activate_cb (GtkMenuItem *menuitem, parent = empathy_get_toplevel_window (GTK_WIDGET (view)); text = g_strdup_printf (_("Do you really want to remove the contact '%s'?"), - empathy_contact_get_name (contact)); + empathy_contact_get_name (contact)); if (contact_list_view_remove_dialog_show (parent, _("Removing contact"), text)) { EmpathyContactList *list; diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index fdd9c34a1..2bad5c9fe 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -141,7 +141,7 @@ empathy_contact_chat_menu_item_new (EmpathyContact *contact) g_signal_connect (item, "activate", G_CALLBACK (empathy_contact_chat_menu_item_activated), contact); - + return item; } @@ -244,7 +244,7 @@ empathy_contact_log_menu_item_new (EmpathyContact *contact) g_signal_connect_swapped (item, "activate", G_CALLBACK (contact_log_menu_item_activate_cb), contact); - + return item; } @@ -293,7 +293,7 @@ empathy_contact_info_menu_item_new (EmpathyContact *contact) g_signal_connect_swapped (item, "activate", G_CALLBACK (contact_info_menu_item_activate_cb), contact); - + return item; } @@ -320,7 +320,7 @@ empathy_contact_edit_menu_item_new (EmpathyContact *contact) g_signal_connect_swapped (item, "activate", G_CALLBACK (contact_edit_menu_item_activate_cb), contact); - + return item; } diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 12a139303..7e80d0d65 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -32,7 +32,6 @@ #include <champlain-gtk/champlain-gtk.h> #endif -#include <libmissioncontrol/mc-account.h> #include <telepathy-glib/util.h> #include <libempathy/empathy-tp-contact-factory.h> @@ -41,6 +40,7 @@ #include <libempathy/empathy-location.h> #include <libempathy/empathy-time.h> #include <libempathy/empathy-utils.h> +#include <libempathy/empathy-account.h> #include "empathy-contact-widget.h" #include "empathy-account-chooser.h" @@ -697,7 +697,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information) static void contact_widget_contact_update (EmpathyContactWidget *information) { - McAccount *account = NULL; + EmpathyAccount *account = NULL; const gchar *id = NULL; /* Connect and get info from new contact */ @@ -737,7 +737,7 @@ contact_widget_contact_update (EmpathyContactWidget *information) { const gchar *name; - name = mc_account_get_display_name (account); + name = empathy_account_get_display_name (account); gtk_label_set_label (GTK_LABEL (information->widget_account), name); } } diff --git a/libempathy-gtk/empathy-irc-network-dialog.c b/libempathy-gtk/empathy-irc-network-dialog.c index 63222badc..e6b4a6f7f 100644 --- a/libempathy-gtk/empathy-irc-network-dialog.c +++ b/libempathy-gtk/empathy-irc-network-dialog.c @@ -27,10 +27,10 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> -#include <libmissioncontrol/mc-account.h> #include <libmissioncontrol/mc-protocol.h> #include <libempathy/empathy-utils.h> +#include <libempathy/empathy-account.h> #include <libempathy/empathy-irc-network-manager.h> #include "empathy-ui-utils.h" diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index dc2efa332..f05017c9c 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -31,6 +31,7 @@ #include <gtk/gtk.h> #include <libempathy/empathy-log-manager.h> +#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-chatroom-manager.h> #include <libempathy/empathy-chatroom.h> #include <libempathy/empathy-message.h> @@ -94,11 +95,11 @@ static void log_window_chats_setup (EmpathyLogWindow *wi static void log_window_chats_accounts_changed_cb (GtkWidget *combobox, EmpathyLogWindow *window); static void log_window_chats_set_selected (EmpathyLogWindow *window, - McAccount *account, + EmpathyAccount *account, const gchar *chat_id, gboolean is_chatroom); static gboolean log_window_chats_get_selected (EmpathyLogWindow *window, - McAccount **account, + EmpathyAccount **account, gchar **chat_id, gboolean *is_chatroom); static void log_window_chats_get_messages (EmpathyLogWindow *window, @@ -134,14 +135,14 @@ enum { }; GtkWidget * -empathy_log_window_show (McAccount *account, +empathy_log_window_show (EmpathyAccount *account, const gchar *chat_id, gboolean is_chatroom, GtkWindow *parent) { static EmpathyLogWindow *window = NULL; EmpathyAccountChooser *account_chooser; - GList *accounts; + EmpathyAccountManager *account_manager; gint account_num; GtkBuilder *gui; gchar *filename; @@ -228,9 +229,9 @@ empathy_log_window_show (McAccount *account, window); /* Populate */ - accounts = mc_accounts_list (); - account_num = g_list_length (accounts); - mc_accounts_list_free (accounts); + account_manager = empathy_account_manager_dup_singleton (); + account_num = empathy_account_manager_get_count (account_manager); + g_object_unref (account_manager); if (account_num > 1) { gtk_widget_show (window->vbox_chats); @@ -301,7 +302,7 @@ log_window_find_changed_cb (GtkTreeSelection *selection, GtkTreeView *view; GtkTreeModel *model; GtkTreeIter iter; - McAccount *account; + EmpathyAccount *account; gchar *chat_id; gboolean is_chatroom; gchar *date; @@ -320,7 +321,7 @@ log_window_find_changed_cb (GtkTreeSelection *selection, gtk_widget_set_sensitive (window->button_next, FALSE); empathy_chat_view_clear (window->chatview_find); - + return; } @@ -417,7 +418,7 @@ log_window_find_populate (EmpathyLogWindow *window, } date_readable = empathy_log_manager_get_date_readable (hit->date); - account_name = mc_account_get_display_name (hit->account); + account_name = empathy_account_get_display_name (hit->account); account_icon = empathy_icon_name_from_account (hit->account); gtk_list_store_append (store, &iter); @@ -464,7 +465,7 @@ log_window_find_setup (EmpathyLogWindow *window) store = gtk_list_store_new (COL_FIND_COUNT, G_TYPE_STRING, /* account icon name */ G_TYPE_STRING, /* account name */ - MC_TYPE_ACCOUNT, /* account */ + EMPATHY_TYPE_ACCOUNT, /* account */ G_TYPE_STRING, /* chat name */ G_TYPE_STRING, /* chat id */ G_TYPE_BOOLEAN, /* is chatroom */ @@ -608,7 +609,7 @@ static void log_window_chats_populate (EmpathyLogWindow *window) { EmpathyAccountChooser *account_chooser; - McAccount *account; + EmpathyAccount *account; GList *chats, *l; GtkTreeView *view; @@ -646,7 +647,7 @@ log_window_chats_populate (EmpathyLogWindow *window) gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_CHAT_ICON, "empathy-available", /* FIXME */ - COL_CHAT_NAME, hit->chat_id, + COL_CHAT_NAME, hit->chat_id, COL_CHAT_ACCOUNT, account, COL_CHAT_ID, hit->chat_id, COL_CHAT_IS_CHATROOM, hit->is_chatroom, @@ -684,11 +685,11 @@ log_window_chats_setup (EmpathyLogWindow *window) /* new store */ store = gtk_list_store_new (COL_CHAT_COUNT, - G_TYPE_STRING, /* icon */ - G_TYPE_STRING, /* name */ - MC_TYPE_ACCOUNT, /* account */ - G_TYPE_STRING, /* id */ - G_TYPE_BOOLEAN); /* is chatroom */ + G_TYPE_STRING, /* icon */ + G_TYPE_STRING, /* name */ + EMPATHY_TYPE_ACCOUNT, /* account */ + G_TYPE_STRING, /* id */ + G_TYPE_BOOLEAN); /* is chatroom */ model = GTK_TREE_MODEL (store); sortable = GTK_TREE_SORTABLE (store); @@ -739,7 +740,7 @@ log_window_chats_accounts_changed_cb (GtkWidget *combobox, static void log_window_chats_set_selected (EmpathyLogWindow *window, - McAccount *account, + EmpathyAccount *account, const gchar *chat_id, gboolean is_chatroom) { @@ -763,7 +764,7 @@ log_window_chats_set_selected (EmpathyLogWindow *window, } for (ok = TRUE; ok; ok = gtk_tree_model_iter_next (model, &iter)) { - McAccount *this_account; + EmpathyAccount *this_account; gchar *this_chat_id; gboolean this_is_chatroom; @@ -792,7 +793,7 @@ log_window_chats_set_selected (EmpathyLogWindow *window, static gboolean log_window_chats_get_selected (EmpathyLogWindow *window, - McAccount **account, + EmpathyAccount **account, gchar **chat_id, gboolean *is_chatroom) { @@ -801,7 +802,7 @@ log_window_chats_get_selected (EmpathyLogWindow *window, GtkTreeSelection *selection; GtkTreeIter iter; gchar *id = NULL; - McAccount *acc = NULL; + EmpathyAccount *acc = NULL; gboolean room = FALSE; view = GTK_TREE_VIEW (window->treeview_chats); @@ -839,7 +840,7 @@ static void log_window_chats_get_messages (EmpathyLogWindow *window, const gchar *date_to_show) { - McAccount *account; + EmpathyAccount *account; gchar *chat_id; gboolean is_chatroom; EmpathyMessage *message; @@ -999,7 +1000,7 @@ static void log_window_calendar_chats_month_changed_cb (GtkWidget *calendar, EmpathyLogWindow *window) { - McAccount *account; + EmpathyAccount *account; gchar *chat_id; gboolean is_chatroom; guint year_selected; diff --git a/libempathy-gtk/empathy-log-window.h b/libempathy-gtk/empathy-log-window.h index 6dd8c0303..298d96099 100644 --- a/libempathy-gtk/empathy-log-window.h +++ b/libempathy-gtk/empathy-log-window.h @@ -25,11 +25,11 @@ #ifndef __EMPATHY_LOG_WINDOW_H__ #define __EMPATHY_LOG_WINDOW_H__ -#include <libmissioncontrol/mc-account.h> +#include <libempathy/empathy-account.h> G_BEGIN_DECLS -GtkWidget * empathy_log_window_show (McAccount *account, +GtkWidget * empathy_log_window_show (EmpathyAccount *account, const gchar *chat_id, gboolean chatroom, GtkWindow *parent); diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c index 512cd1ba3..77b368bd9 100644 --- a/libempathy-gtk/empathy-new-message-dialog.c +++ b/libempathy-gtk/empathy-new-message-dialog.c @@ -27,7 +27,6 @@ #include <gtk/gtk.h> #include <glib/gi18n-lib.h> -#include <libmissioncontrol/mc-account.h> #include <libmissioncontrol/mission-control.h> #include <libempathy/empathy-call-factory.h> @@ -35,6 +34,7 @@ #include <libempathy/empathy-contact-manager.h> #include <libempathy/empathy-dispatcher.h> #include <libempathy/empathy-utils.h> +#include <libempathy/empathy-account.h> #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT #include <libempathy/empathy-debug.h> @@ -239,7 +239,7 @@ new_message_change_state_button_cb (GtkEditable *editable, id = gtk_entry_get_text (GTK_ENTRY (editable)); sensitive = !EMP_STR_EMPTY (id); - + gtk_widget_set_sensitive (dialog->button_chat, sensitive); gtk_widget_set_sensitive (dialog->button_call, sensitive); } diff --git a/libempathy-gtk/empathy-plist.c b/libempathy-gtk/empathy-plist.c new file mode 100644 index 000000000..4cc392bec --- /dev/null +++ b/libempathy-gtk/empathy-plist.c @@ -0,0 +1,336 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Christophe Fergeau <teuf@gnome.org> + * Based on itdb_plist parser from the gtkpod project. + * + * The code contained in this file is free software; you can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This file 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this code; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include <string.h> +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <telepathy-glib/util.h> +#include <telepathy-glib/dbus.h> + +#include "empathy-plist.h" + +static GValue *empathy_plist_parse_node (xmlNode *a_node); + +static GValue * +empathy_plist_parse_integer (xmlNode *a_node) +{ + char *str_val; + char *end_ptr; + gint int_val; + + str_val = (char *) xmlNodeGetContent (a_node); + int_val = strtol (str_val, &end_ptr, 0); + if (*end_ptr != '\0') { + xmlFree (str_val); + return NULL; + } + xmlFree (str_val); + + return tp_g_value_slice_new_int (int_val); +} + +static GValue * +empathy_plist_parse_string (xmlNode *a_node) +{ + char *str_val; + GValue *value; + + str_val = (char *) xmlNodeGetContent (a_node); + + value = tp_g_value_slice_new_string (str_val); + + xmlFree (str_val); + + return value; +} + +static GValue * +empathy_plist_parse_real (xmlNode *a_node) +{ + char *str_val; + char *end_ptr; + gdouble double_val; + + str_val = (char *) xmlNodeGetContent (a_node); + double_val = g_ascii_strtod (str_val, &end_ptr); + if (*end_ptr != '\0') { + xmlFree (str_val); + return NULL; + } + xmlFree (str_val); + + return tp_g_value_slice_new_double (double_val); +} + +static GValue * +empathy_plist_parse_boolean (xmlNode *a_node) +{ + gboolean bool_val; + + if (strcmp ((char *) a_node->name, "true") == 0) { + bool_val = TRUE; + } else if (strcmp ((char *) a_node->name, "false") == 0) { + bool_val = FALSE; + } else { + return NULL; + } + + return tp_g_value_slice_new_boolean (bool_val); +} + +static GValue * +empathy_plist_parse_data (xmlNode *a_node) +{ + char *str_val; + guchar *raw_data; + gsize len; + GValue *value; + + str_val = (char *) xmlNodeGetContent (a_node); + raw_data = g_base64_decode (str_val, &len); + xmlFree (str_val); + + value = tp_g_value_slice_new_bytes (len, raw_data); + + g_free (raw_data); + + return value; +} + +static xmlNode * +empathy_plist_parse_one_dict_entry (xmlNode *a_node, GHashTable *dict) +{ + xmlNode *cur_node = a_node; + xmlChar *key_name; + GValue *value; + + while (cur_node && + (xmlStrcmp (cur_node->name, (xmlChar *) "key") != 0)) { + cur_node = cur_node->next; + } + if (!cur_node) { + return NULL; + } + key_name = xmlNodeGetContent (cur_node); + cur_node = cur_node->next; + while (cur_node && xmlIsBlankNode (cur_node)) { + cur_node = cur_node->next; + } + if (!cur_node) { + xmlFree (key_name); + return NULL; + } + + value = empathy_plist_parse_node (cur_node); + if (value) { + g_hash_table_insert (dict, g_strdup ((char *) key_name), value); + } + xmlFree (key_name); + + return cur_node->next; +} + +static GValue * +empathy_plist_parse_dict (xmlNode *a_node) +{ + xmlNode *cur_node = a_node->children; + GHashTable *dict; + + dict = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) tp_g_value_slice_free); + + while (cur_node) { + if (xmlIsBlankNode (cur_node)) { + cur_node = cur_node->next; + } else { + cur_node = empathy_plist_parse_one_dict_entry (cur_node, dict); + } + } + + return tp_g_value_slice_new_take_boxed (G_TYPE_HASH_TABLE, dict); +} + +static GValue * +empathy_plist_parse_array (xmlNode *a_node) +{ + xmlNode *cur_node = a_node->children; + GValueArray *array; + + array = g_value_array_new (4); + + while (cur_node) { + GValue *cur_value; + + cur_value = empathy_plist_parse_node (cur_node); + if (cur_value) { + g_value_array_append (array, cur_value); + tp_g_value_slice_free (cur_value); + } + + /* When an array contains an element enclosed in "unknown" tags (ie + * non-type ones), we silently skip them since early + * SysInfoExtended files used to have <key> values enclosed within + * <array> tags. + */ + cur_node = cur_node->next; + } + + return tp_g_value_slice_new_take_boxed (G_TYPE_VALUE_ARRAY, array); +} + +typedef GValue *(*ParseCallback) (xmlNode *); + +struct Parser { + const char * const type_name; + ParseCallback parser; +}; + +static const struct Parser parsers[] = { {"integer", empathy_plist_parse_integer}, + {"real", empathy_plist_parse_real}, + {"string", empathy_plist_parse_string}, + {"true", empathy_plist_parse_boolean}, + {"false", empathy_plist_parse_boolean}, + {"data", empathy_plist_parse_data}, + {"dict", empathy_plist_parse_dict}, + {"array", empathy_plist_parse_array}, + {NULL, NULL} }; + +static ParseCallback +empathy_plist_get_parser_for_type (const xmlChar *type) +{ + guint i = 0; + + while (parsers[i].type_name) { + if (xmlStrcmp (type, (xmlChar *) parsers[i].type_name) == 0) { + if (parsers[i].parser) { + return parsers[i].parser; + } + } + i++; + } + return NULL; +} + +static GValue * +empathy_plist_parse_node (xmlNode *a_node) +{ + ParseCallback parser; + + g_return_val_if_fail (a_node != NULL, NULL); + parser = empathy_plist_get_parser_for_type (a_node->name); + if (parser) { + return parser (a_node); + } else { + return NULL; + } +} + +static GValue * +empathy_plist_parse (xmlNode * a_node) +{ + xmlNode *cur_node; + + if (!a_node) { + return NULL; + } + if (xmlStrcmp (a_node->name, (xmlChar *) "plist") != 0) { + return NULL; + } + cur_node = a_node->xmlChildrenNode; + while (cur_node && (xmlIsBlankNode (cur_node))) { + cur_node = cur_node->next; + } + if (cur_node) { + return empathy_plist_parse_node (cur_node); + } + + return NULL; +} + +/** + * empathy_plist_parse_from_file: + * @filename: file containing XML plist data to parse + * + * Parses the XML plist file. If an error occurs during the parsing, + * empathy_plist_parse_from_file() will return NULL. + * + * Returns: NULL on error, a newly allocated + * #GValue otherwise. Free it using tp_g_value_slice_free() + */ +GValue * +empathy_plist_parse_from_file (const char *filename) +{ + xmlDoc *doc = NULL; + xmlNode *root_element = NULL; + GValue *parsed_doc; + + doc = xmlReadFile (filename, NULL, 0); + + if (!doc) { + return NULL; + } + + root_element = xmlDocGetRootElement (doc); + + parsed_doc = empathy_plist_parse (root_element); + + xmlFreeDoc (doc); + xmlCleanupParser (); + + return parsed_doc; +} + +/** + * empathy_plist_parse_from_memory: + * @data: memory location containing XML plist data to parse + * @len: length in bytes of the string to parse + * + * Parses the XML plist file stored in @data which length is @len + * bytes. If an error occurs during the parsing, + * empathy_plist_parse_from_memory() will return NULL. + * + * Returns: NULL on error, a newly allocated + * #GValue otherwise. Free it using tp_g_value_slice_free() + */ +GValue * +empathy_plist_parse_from_memory (const char *data, gsize len) +{ + xmlDoc *doc = NULL; + xmlNode *root_element = NULL; + GValue *parsed_doc; + + doc = xmlReadMemory (data, len, "noname.xml", NULL, 0); + + if (doc == NULL) { + return NULL; + } + + root_element = xmlDocGetRootElement (doc); + + parsed_doc = empathy_plist_parse (root_element); + + xmlFreeDoc (doc); + xmlCleanupParser (); + + return parsed_doc; +} + diff --git a/libempathy-gtk/empathy-plist.h b/libempathy-gtk/empathy-plist.h new file mode 100644 index 000000000..a15ad6a01 --- /dev/null +++ b/libempathy-gtk/empathy-plist.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Christophe Fergeau <teuf@gnome.org> + * Based on itdb_plist parser from the gtkpod project. + * + * The code contained in this file is free software; you can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This file 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this code; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __EMPATHY_PLIST_H__ +#define __EMPATHY_PLIST_H__ + +#include <glib.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +GValue * empathy_plist_parse_from_file (const char *filename); +GValue * empathy_plist_parse_from_memory (const char *data, gsize len); + +G_END_DECLS + +#endif diff --git a/libempathy-gtk/empathy-smiley-manager.c b/libempathy-gtk/empathy-smiley-manager.c index e8f623424..900e9211c 100644 --- a/libempathy-gtk/empathy-smiley-manager.c +++ b/libempathy-gtk/empathy-smiley-manager.c @@ -314,7 +314,7 @@ empathy_smiley_manager_parse (EmpathySmileyManager *manager, for (t = text; *t; t = g_utf8_next_char (t)) { SmileyManagerTree *child; gunichar c; - + c = g_utf8_get_char (t); child = smiley_manager_tree_find_child (cur_tree, c); diff --git a/libempathy-gtk/empathy-sound.c b/libempathy-gtk/empathy-sound.c new file mode 100644 index 000000000..d97f72bef --- /dev/null +++ b/libempathy-gtk/empathy-sound.c @@ -0,0 +1,385 @@ +/* + * empathy-sound.c - Various sound related utility functions. + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <config.h> + +#include "empathy-sound.h" + +#include <canberra-gtk.h> +#include <glib/gi18n-lib.h> +#include <gtk/gtk.h> + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include <libempathy/empathy-debug.h> +#include <libempathy/empathy-utils.h> + +#include "empathy-conf.h" + +typedef struct { + EmpathySound sound_id; + const char * event_ca_id; + const char * event_ca_description; + const char * gconf_key; +} EmpathySoundEntry; + +typedef struct { + GtkWidget *widget; + gint sound_id; + guint play_interval; + guint replay_timeout_id; +} EmpathyRepeatableSound; + +/* NOTE: these entries MUST be in the same order than EmpathySound enum */ +static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = { + { EMPATHY_SOUND_MESSAGE_INCOMING, "message-new-instant", + N_("Received an instant message"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE } , + { EMPATHY_SOUND_MESSAGE_OUTGOING, "message-sent-instant", + N_("Sent an instant message"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE } , + { EMPATHY_SOUND_CONVERSATION_NEW, "message-new-instant", + N_("Incoming chat request"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION }, + { EMPATHY_SOUND_CONTACT_CONNECTED, "service-login", + N_("Contact connected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN }, + { EMPATHY_SOUND_CONTACT_DISCONNECTED, "service-logout", + N_("Contact disconnected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT }, + { EMPATHY_SOUND_ACCOUNT_CONNECTED, "service-login", + N_("Connected to server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN }, + { EMPATHY_SOUND_ACCOUNT_DISCONNECTED, "service-logout", + N_("Disconnected from server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }, + { EMPATHY_SOUND_PHONE_INCOMING, "phone-incoming-call", + N_("Incoming voice call"), NULL }, + { EMPATHY_SOUND_PHONE_OUTGOING, "phone-outgoing-calling", + N_("Outgoing voice call"), NULL }, + { EMPATHY_SOUND_PHONE_HANGUP, "phone-hangup", + N_("Voice call ended"), NULL }, +}; + +/* An hash table containing currently repeating sounds. The format is the + * following: + * Key: An EmpathySound + * Value : The EmpathyRepeatableSound associated with that EmpathySound. */ +static GHashTable *repeating_sounds; + +static gboolean +empathy_sound_pref_is_enabled (EmpathySound sound_id) +{ + EmpathySoundEntry *entry; + EmpathyConf *conf; + gboolean res; + + entry = &(sound_entries[sound_id]); + g_return_val_if_fail (entry->sound_id == sound_id, FALSE); + + if (entry->gconf_key == NULL) + return TRUE; + + conf = empathy_conf_get (); + res = FALSE; + + empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_ENABLED, &res); + + if (!res) + return FALSE; + + if (!empathy_check_available_state ()) + { + empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_DISABLED_AWAY, &res); + + if (res) + return FALSE; + } + + empathy_conf_get_bool (conf, entry->gconf_key, &res); + + return res; +} + +/** + * empathy_sound_stop: + * @sound_id: The #EmpathySound to stop playing. + * + * Stop playing a sound. If it has been stated in loop with + * empathy_sound_start_playing(), it will also stop replaying. + */ +void +empathy_sound_stop (EmpathySound sound_id) +{ + EmpathySoundEntry *entry; + + g_return_if_fail (sound_id < LAST_EMPATHY_SOUND); + + entry = &(sound_entries[sound_id]); + g_return_if_fail (entry->sound_id == sound_id); + + if (repeating_sounds != NULL) + { + EmpathyRepeatableSound *repeatable_sound; + + repeatable_sound = g_hash_table_lookup (repeating_sounds, + GINT_TO_POINTER (sound_id)); + if (repeatable_sound != NULL) + { + /* The sound must be stopped... If it is waiting for replay, remove + * it from hash table to cancel. Otherwise we'll cancel the sound + * being played. */ + if (repeatable_sound->replay_timeout_id != 0) + { + g_hash_table_remove (repeating_sounds, GINT_TO_POINTER (sound_id)); + return; + } + } + } + + ca_context_cancel (ca_gtk_context_get (), entry->sound_id); +} + +static gboolean +empathy_sound_play_internal (GtkWidget *widget, EmpathySound sound_id, + ca_finish_callback_t callback, gpointer user_data) +{ + EmpathySoundEntry *entry; + ca_context *c; + ca_proplist *p = NULL; + + entry = &(sound_entries[sound_id]); + g_return_val_if_fail (entry->sound_id == sound_id, FALSE); + + c = ca_gtk_context_get (); + ca_context_cancel (c, entry->sound_id); + + DEBUG ("Play sound \"%s\" (%s)", + entry->event_ca_id, + entry->event_ca_description); + + if (ca_proplist_create (&p) < 0) + goto failed; + + if (ca_proplist_sets (p, CA_PROP_EVENT_ID, entry->event_ca_id) < 0) + goto failed; + + if (ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION, + gettext (entry->event_ca_id)) < 0) + goto failed; + + if (ca_gtk_proplist_set_for_widget (p, widget) < 0) + goto failed; + + ca_context_play_full (ca_gtk_context_get (), entry->sound_id, p, callback, + user_data); + + ca_proplist_destroy (p); + + return TRUE; + +failed: + if (p != NULL) + ca_proplist_destroy (p); + + return FALSE; +} + +/** + * empathy_sound_play_full: + * @widget: The #GtkWidget from which the sound is originating. + * @sound_id: The #EmpathySound to play. + * @callback: The #ca_finish_callback_t function that will be called when the + * sound has stopped playing. + * @user_data: user data to pass to the function. + * + * Plays a sound. + * + * Returns %TRUE if the sound has successfully started playing, otherwise + * returning %FALSE and @callback won't be called. + * + * This function returns %FALSE if the sound is already playing in loop using + * %empathy_sound_start_playing. + * + * This function returns %FALSE if the sound is disabled in empathy preferences. + * + * Return value: %TRUE if the sound has successfully started playing, %FALSE + * otherwise. + */ +gboolean +empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id, + ca_finish_callback_t callback, gpointer user_data) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE); + + if (!empathy_sound_pref_is_enabled (sound_id)) + return FALSE; + + /* The sound might already be playing repeatedly. If it's the case, we + * immediadely return since there's no need to make it play again */ + if (repeating_sounds != NULL && + g_hash_table_lookup (repeating_sounds, GINT_TO_POINTER (sound_id)) != NULL) + return FALSE; + + return empathy_sound_play_internal (widget, sound_id, callback, user_data); +} + +/** + * empathy_sound_play: + * @widget: The #GtkWidget from which the sound is originating. + * @sound_id: The #EmpathySound to play. + * + * Plays a sound. See %empathy_sound_play_full for details.' + * + * Return value: %TRUE if the sound has successfully started playing, %FALSE + * otherwise. + */ +gboolean +empathy_sound_play (GtkWidget *widget, EmpathySound sound_id) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE); + + return empathy_sound_play_full (widget, sound_id, NULL, NULL); +} + +static void playing_finished_cb (ca_context *c, guint id, int error_code, + gpointer user_data); + +static gboolean +playing_timeout_cb (gpointer data) +{ + EmpathyRepeatableSound *repeatable_sound = data; + gboolean playing; + + repeatable_sound->replay_timeout_id = 0; + + playing = empathy_sound_play_internal (repeatable_sound->widget, + repeatable_sound->sound_id, playing_finished_cb, data); + + if (!playing) + { + DEBUG ("Failed to replay sound, stop repeating"); + g_hash_table_remove (repeating_sounds, + GINT_TO_POINTER (repeatable_sound->sound_id)); + } + + return FALSE; +} + +static void +playing_finished_cb (ca_context *c, guint id, int error_code, + gpointer user_data) +{ + EmpathyRepeatableSound *repeatable_sound = user_data; + + if (error_code != CA_SUCCESS) + { + DEBUG ("Error: %s", ca_strerror (error_code)); + g_hash_table_remove (repeating_sounds, + GINT_TO_POINTER (repeatable_sound->sound_id)); + return; + } + + repeatable_sound->replay_timeout_id = g_timeout_add ( + repeatable_sound->play_interval, playing_timeout_cb, user_data); +} + +static void +empathy_sound_widget_destroyed_cb (GtkWidget *widget, gpointer user_data) +{ + EmpathyRepeatableSound *repeatable_sound = user_data; + + /* The sound must be stopped... If it is waiting for replay, remove + * it from hash table to cancel. Otherwise playing_finished_cb will be + * called with an error. */ + if (repeatable_sound->replay_timeout_id != 0) + { + g_hash_table_remove (repeating_sounds, + GINT_TO_POINTER (repeatable_sound->sound_id)); + } +} + +static void +repeating_sounds_item_delete (gpointer data) +{ + EmpathyRepeatableSound *repeatable_sound = data; + + if (repeatable_sound->replay_timeout_id != 0) + g_source_remove (repeatable_sound->replay_timeout_id); + + g_signal_handlers_disconnect_by_func (repeatable_sound->widget, + empathy_sound_widget_destroyed_cb, repeatable_sound); + + g_slice_free (EmpathyRepeatableSound, repeatable_sound); +} + +/** + * empathy_sound_start_playing: + * @widget: The #GtkWidget from which the sound is originating. + * @sound_id: The #EmpathySound to play. + * @timeout_before_replay: The amount of time, in milliseconds, between two + * consecutive play. + * + * Start playing a sound in loop. To stop the sound, call empathy_call_stop () + * by passing it the same @sound_id. Note that if you start playing a sound + * multiple times, you'll have to call %empathy_sound_stop the same number of + * times. + * + * Return value: %TRUE if the sound has successfully started playing. + */ +gboolean +empathy_sound_start_playing (GtkWidget *widget, EmpathySound sound_id, + guint timeout_before_replay) +{ + EmpathyRepeatableSound *repeatable_sound; + gboolean playing = FALSE; + + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE); + + if (!empathy_sound_pref_is_enabled (sound_id)) + return FALSE; + + if (repeating_sounds == NULL) + { + repeating_sounds = g_hash_table_new_full (g_direct_hash, g_direct_equal, + NULL, repeating_sounds_item_delete); + } + else if (g_hash_table_lookup (repeating_sounds, + GINT_TO_POINTER (sound_id)) != NULL) + { + /* The sound is already playing in loop. No need to continue. */ + return FALSE; + } + + repeatable_sound = g_slice_new0 (EmpathyRepeatableSound); + repeatable_sound->widget = widget; + repeatable_sound->sound_id = sound_id; + repeatable_sound->play_interval = timeout_before_replay; + repeatable_sound->replay_timeout_id = 0; + + g_hash_table_insert (repeating_sounds, GINT_TO_POINTER (sound_id), + repeatable_sound); + + g_signal_connect (G_OBJECT (widget), "destroy", + G_CALLBACK (empathy_sound_widget_destroyed_cb), + repeatable_sound); + + playing = empathy_sound_play_internal (widget, sound_id, playing_finished_cb, + repeatable_sound); + + if (!playing) + g_hash_table_remove (repeating_sounds, GINT_TO_POINTER (sound_id)); + + return playing; +} diff --git a/libempathy-gtk/empathy-sound.h b/libempathy-gtk/empathy-sound.h new file mode 100644 index 000000000..f65f6260e --- /dev/null +++ b/libempathy-gtk/empathy-sound.h @@ -0,0 +1,56 @@ +/* + * empathy-sound.h - Various sound related utility functions. + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __EMPATHY_SOUND_H__ +#define __EMPATHY_SOUND_H__ + +#include <gtk/gtk.h> + +#include <canberra-gtk.h> + +G_BEGIN_DECLS + +/* NOTE: Keep this sync with sound_entries in empathy-sound.c */ +typedef enum { + EMPATHY_SOUND_MESSAGE_INCOMING = 0, + EMPATHY_SOUND_MESSAGE_OUTGOING, + EMPATHY_SOUND_CONVERSATION_NEW, + EMPATHY_SOUND_CONTACT_CONNECTED, + EMPATHY_SOUND_CONTACT_DISCONNECTED, + EMPATHY_SOUND_ACCOUNT_CONNECTED, + EMPATHY_SOUND_ACCOUNT_DISCONNECTED, + EMPATHY_SOUND_PHONE_INCOMING, + EMPATHY_SOUND_PHONE_OUTGOING, + EMPATHY_SOUND_PHONE_HANGUP, + LAST_EMPATHY_SOUND, +} EmpathySound; + +gboolean empathy_sound_play (GtkWidget *widget, EmpathySound sound_id); +void empathy_sound_stop (EmpathySound sound_id); + +gboolean empathy_sound_start_playing (GtkWidget *widget, EmpathySound sound_id, + guint timeout_before_replay); + +gboolean empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id, + ca_finish_callback_t callback, gpointer user_data); + +G_END_DECLS + +#endif /* #ifndef __EMPATHY_SOUND_H__*/ diff --git a/libempathy-gtk/empathy-spell.c b/libempathy-gtk/empathy-spell.c index 9cd7c555b..076e81a03 100644 --- a/libempathy-gtk/empathy-spell.c +++ b/libempathy-gtk/empathy-spell.c @@ -175,7 +175,7 @@ spell_notify_languages_cb (EmpathyConf *conf, enchant_broker_free_dict (lang->config, lang->speller); enchant_broker_free (lang->config); - + g_slice_free (SpellLanguage, lang); } @@ -363,7 +363,7 @@ empathy_spell_get_suggestions (const gchar *word) suggestions = enchant_dict_suggest (lang->speller, word, len, &number_of_suggestions); - + for (i = 0; i < number_of_suggestions; i++) { suggestion_list = g_list_append (suggestion_list, g_strdup (suggestions[i])); diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 321d1998c..1f1b3b06d 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -25,46 +25,63 @@ #include <glib/gi18n.h> #include <webkit/webkitnetworkrequest.h> +#include <telepathy-glib/dbus.h> +#include <telepathy-glib/util.h> + #include <libempathy/empathy-time.h> #include <libempathy/empathy-utils.h> +#include <libmissioncontrol/mc-profile.h> #include "empathy-theme-adium.h" #include "empathy-smiley-manager.h" #include "empathy-conf.h" #include "empathy-ui-utils.h" +#include "empathy-plist.h" #define DEBUG_FLAG EMPATHY_DEBUG_CHAT #include <libempathy/empathy-debug.h> #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium) +/* "Join" consecutive messages with timestamps within five minutes */ +#define MESSAGE_JOIN_PERIOD 5*60 + typedef struct { + EmpathyAdiumData *data; EmpathySmileyManager *smiley_manager; EmpathyContact *last_contact; + time_t last_timestamp; gboolean page_loaded; GList *message_queue; - gchar *path; - gchar *default_avatar_filename; - gchar *template_html; - gchar *basedir; - gchar *in_content_html; - gsize in_content_len; - gchar *in_nextcontent_html; - gsize in_nextcontent_len; - gchar *out_content_html; - gsize out_content_len; - gchar *out_nextcontent_html; - gsize out_nextcontent_len; - gchar *status_html; - gsize status_len; } EmpathyThemeAdiumPriv; +struct _EmpathyAdiumData { + guint ref_count; + gchar *path; + gchar *basedir; + gchar *default_avatar_filename; + gchar *default_incoming_avatar_filename; + gchar *default_outgoing_avatar_filename; + gchar *template_html; + gchar *in_content_html; + gsize in_content_len; + gchar *in_nextcontent_html; + gsize in_nextcontent_len; + gchar *out_content_html; + gsize out_content_len; + gchar *out_nextcontent_html; + gsize out_nextcontent_len; + gchar *status_html; + gsize status_len; + GHashTable *info; +}; + static void theme_adium_iface_init (EmpathyChatViewIface *iface); enum { PROP_0, - PROP_PATH, + PROP_ADIUM_DATA, }; G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium, @@ -72,100 +89,6 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium, G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW, theme_adium_iface_init)); -static void -theme_adium_load (EmpathyThemeAdium *theme) -{ - EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); - gchar *file; - gchar *template_html = NULL; - gsize template_len; - GString *string; - gchar **strv = NULL; - gchar *css_path; - guint len = 0; - guint i = 0; - gchar *basedir_uri; - - priv->basedir = g_strconcat (priv->path, G_DIR_SEPARATOR_S "Contents" G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL); - basedir_uri = g_strconcat ("file://", priv->basedir, NULL); - - /* Load html files */ - file = g_build_filename (priv->basedir, "Incoming", "Content.html", NULL); - g_file_get_contents (file, &priv->in_content_html, &priv->in_content_len, NULL); - g_free (file); - - file = g_build_filename (priv->basedir, "Incoming", "NextContent.html", NULL); - g_file_get_contents (file, &priv->in_nextcontent_html, &priv->in_nextcontent_len, NULL); - g_free (file); - - file = g_build_filename (priv->basedir, "Outgoing", "Content.html", NULL); - g_file_get_contents (file, &priv->out_content_html, &priv->out_content_len, NULL); - g_free (file); - - file = g_build_filename (priv->basedir, "Outgoing", "NextContent.html", NULL); - g_file_get_contents (file, &priv->out_nextcontent_html, &priv->out_nextcontent_len, NULL); - g_free (file); - - file = g_build_filename (priv->basedir, "Status.html", NULL); - g_file_get_contents (file, &priv->status_html, &priv->status_len, NULL); - g_free (file); - - css_path = g_build_filename (priv->basedir, "main.css", NULL); - - /* There is 2 formats for Template.html: The old one has 4 parameters, - * the new one has 5 parameters. */ - file = g_build_filename (priv->basedir, "Template.html", NULL); - if (g_file_get_contents (file, &template_html, &template_len, NULL)) { - strv = g_strsplit (template_html, "%@", -1); - len = g_strv_length (strv); - } - g_free (file); - - if (len != 5 && len != 6) { - /* Either the theme has no template or it don't have the good - * number of parameters. Fallback to use our own template. */ - g_free (template_html); - g_strfreev (strv); - - file = empathy_file_lookup ("Template.html", "data"); - g_file_get_contents (file, &template_html, &template_len, NULL); - g_free (file); - strv = g_strsplit (template_html, "%@", -1); - len = g_strv_length (strv); - } - - /* Replace %@ with the needed information in the template html. */ - string = g_string_sized_new (template_len); - g_string_append (string, strv[i++]); - g_string_append (string, priv->basedir); - g_string_append (string, strv[i++]); - if (len == 6) { - /* We include main.css by default */ - g_string_append_printf (string, "@import url(\"%s\");", css_path); - g_string_append (string, strv[i++]); - /* FIXME: We should set the variant css here */ - g_string_append (string, ""); - } else { - /* FIXME: We should set main.css OR the variant css */ - g_string_append (string, css_path); - } - g_string_append (string, strv[i++]); - g_string_append (string, ""); /* We don't want header */ - g_string_append (string, strv[i++]); - g_string_append (string, ""); /* FIXME: We don't support footer yet */ - g_string_append (string, strv[i++]); - priv->template_html = g_string_free (string, FALSE); - - /* Load the template */ - webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (theme), - priv->template_html, basedir_uri); - - g_free (basedir_uri); - g_free (template_html); - g_free (css_path); - g_strfreev (strv); -} - static WebKitNavigationResponse theme_adium_navigation_requested_cb (WebKitWebView *view, WebKitWebFrame *frame, @@ -190,12 +113,12 @@ theme_adium_populate_popup_cb (WebKitWebView *view, /* Remove default menu items */ gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback) gtk_widget_destroy, NULL); - + /* Select all item */ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + g_signal_connect_swapped (item, "activate", G_CALLBACK (webkit_web_view_select_all), view); @@ -205,7 +128,7 @@ theme_adium_populate_popup_cb (WebKitWebView *view, item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + g_signal_connect_swapped (item, "activate", G_CALLBACK (webkit_web_view_copy_clipboard), view); @@ -215,11 +138,11 @@ theme_adium_populate_popup_cb (WebKitWebView *view, item = gtk_separator_menu_item_new (); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - + g_signal_connect_swapped (item, "activate", G_CALLBACK (empathy_chat_view_clear), view); @@ -343,7 +266,7 @@ escape_and_append_len (GString *string, const gchar *str, gint len) switch (*str) { case '\\': /* \ becomes \\ */ - g_string_append (string, "\\\\"); + g_string_append (string, "\\\\"); break; case '\"': /* " becomes \" */ @@ -382,6 +305,9 @@ theme_adium_append_html (EmpathyThemeAdium *theme, const gchar *message, const gchar *avatar_filename, const gchar *name, + const gchar *contact_id, + const gchar *service_name, + const gchar *message_classes, time_t timestamp) { GString *string; @@ -397,10 +323,28 @@ theme_adium_append_html (EmpathyThemeAdium *theme, if (theme_adium_match (&cur, "%message%")) { replace = message; + } else if (theme_adium_match (&cur, "%messageClasses%")) { + replace = message_classes; } else if (theme_adium_match (&cur, "%userIconPath%")) { replace = avatar_filename; } else if (theme_adium_match (&cur, "%sender%")) { replace = name; + } else if (theme_adium_match (&cur, "%senderScreenName%")) { + replace = contact_id; + } else if (theme_adium_match (&cur, "%senderDisplayName%")) { + /* %senderDisplayName% - + * "The serverside (remotely set) name of the sender, + * such as an MSN display name." + * + * We don't have access to that yet so we use local + * alias instead.*/ + replace = name; + } else if (theme_adium_match (&cur, "%service%")) { + replace = service_name; + } else if (theme_adium_match (&cur, "%shortTime%")) { + dup_replace = empathy_time_to_string_local (timestamp, + EMPATHY_TIME_FORMAT_DISPLAY_SHORT); + replace = dup_replace; } else if (theme_adium_match (&cur, "%time")) { gchar *format = NULL; gchar *end; @@ -448,15 +392,20 @@ theme_adium_append_message (EmpathyChatView *view, EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view); EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); EmpathyContact *sender; + EmpathyAccount *account; + McProfile *account_profile; gchar *dup_body = NULL; const gchar *body; const gchar *name; + const gchar *contact_id; EmpathyAvatar *avatar; const gchar *avatar_filename = NULL; time_t timestamp; gchar *html = NULL; gsize len = 0; const gchar *func; + const gchar *service_name; + const gchar *message_classes = NULL; if (!priv->page_loaded) { priv->message_queue = g_list_prepend (priv->message_queue, @@ -466,6 +415,9 @@ theme_adium_append_message (EmpathyChatView *view, /* Get information */ sender = empathy_message_get_sender (msg); + account = empathy_contact_get_account (sender); + account_profile = empathy_account_get_profile (account); + service_name = mc_profile_get_display_name (account_profile); timestamp = empathy_message_get_timestamp (msg); body = empathy_message_get_body (msg); dup_body = theme_adium_parse_body (theme, body); @@ -473,6 +425,7 @@ theme_adium_append_message (EmpathyChatView *view, body = dup_body; } name = empathy_contact_get_name (sender); + contact_id = empathy_contact_get_id (sender); /* If this is a /me, append an event */ if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) { @@ -491,46 +444,68 @@ theme_adium_append_message (EmpathyChatView *view, avatar_filename = avatar->filename; } if (!avatar_filename) { - if (!priv->default_avatar_filename) { - priv->default_avatar_filename = - empathy_filename_from_icon_name ("stock_person", - GTK_ICON_SIZE_DIALOG); + if (empathy_contact_is_user (sender)) { + avatar_filename = priv->data->default_outgoing_avatar_filename; + } else { + avatar_filename = priv->data->default_incoming_avatar_filename; + } + if (!avatar_filename) { + if (!priv->data->default_avatar_filename) { + priv->data->default_avatar_filename = + empathy_filename_from_icon_name ("stock_person", + GTK_ICON_SIZE_DIALOG); + } + avatar_filename = priv->data->default_avatar_filename; } - avatar_filename = priv->default_avatar_filename; } /* Get the right html/func to add the message */ func = "appendMessage"; - if (empathy_contact_equal (priv->last_contact, sender)) { + /* + * To mimick Adium's behavior, we only want to join messages + * sent within a 5 minute time frame. + */ + if (empathy_contact_equal (priv->last_contact, sender) && + (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD)) { func = "appendNextMessage"; if (empathy_contact_is_user (sender)) { - html = priv->out_nextcontent_html; - len = priv->out_nextcontent_len; + message_classes = "consecutive incoming message"; + html = priv->data->out_nextcontent_html; + len = priv->data->out_nextcontent_len; } if (!html) { - html = priv->in_nextcontent_html; - len = priv->in_nextcontent_len; + message_classes = "consecutive message outgoing"; + html = priv->data->in_nextcontent_html; + len = priv->data->in_nextcontent_len; } } if (!html) { if (empathy_contact_is_user (sender)) { - html = priv->out_content_html; - len = priv->out_content_len; + if (!message_classes) { + message_classes = "incoming message"; + } + html = priv->data->out_content_html; + len = priv->data->out_content_len; } if (!html) { - html = priv->in_content_html; - len = priv->in_content_len; + if (!message_classes) { + message_classes = "message outgoing"; + } + html = priv->data->in_content_html; + len = priv->data->in_content_len; } } theme_adium_append_html (theme, func, html, len, body, avatar_filename, - name, timestamp); + name, contact_id, service_name, message_classes, + timestamp); /* Keep the sender of the last displayed message */ if (priv->last_contact) { g_object_unref (priv->last_contact); } priv->last_contact = g_object_ref (sender); + priv->last_timestamp = timestamp; g_free (dup_body); } @@ -542,10 +517,11 @@ theme_adium_append_event (EmpathyChatView *view, EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view); EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); - if (priv->status_html) { + if (priv->data->status_html) { theme_adium_append_html (theme, "appendMessage", - priv->status_html, priv->status_len, - str, NULL, NULL, + priv->data->status_html, + priv->data->status_len, + str, NULL, NULL, NULL, NULL, "event", empathy_time_get_current ()); } @@ -583,9 +559,10 @@ theme_adium_clear (EmpathyChatView *view) gchar *basedir_uri; priv->page_loaded = FALSE; - basedir_uri = g_strconcat ("file://", priv->basedir, NULL); + basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL); webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view), - priv->template_html, basedir_uri); + priv->data->template_html, + basedir_uri); g_free (basedir_uri); } @@ -683,14 +660,7 @@ theme_adium_finalize (GObject *object) { EmpathyThemeAdiumPriv *priv = GET_PRIV (object); - g_free (priv->basedir); - g_free (priv->template_html); - g_free (priv->in_content_html); - g_free (priv->in_nextcontent_html); - g_free (priv->out_content_html); - g_free (priv->out_nextcontent_html); - g_free (priv->default_avatar_filename); - g_free (priv->path); + empathy_adium_data_unref (priv->data); G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object); } @@ -716,7 +686,32 @@ theme_adium_dispose (GObject *object) static void theme_adium_constructed (GObject *object) { - theme_adium_load (EMPATHY_THEME_ADIUM (object)); + EmpathyThemeAdiumPriv *priv = GET_PRIV (object); + gchar *basedir_uri; + const gchar *font_family = NULL; + gint font_size = 0; + WebKitWebSettings *webkit_settings; + + /* Set default settings */ + font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily"); + font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL); + webkit_settings = webkit_web_settings_new (); + if (font_family) { + g_object_set (G_OBJECT (webkit_settings), "default-font-family", font_family, NULL); + } + if (font_size) { + g_object_set (G_OBJECT (webkit_settings), "default-font-size", font_size, NULL); + } + webkit_web_view_set_settings (WEBKIT_WEB_VIEW (object), webkit_settings); + + /* Load template */ + basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL); + webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (object), + priv->data->template_html, + basedir_uri); + + g_object_unref (webkit_settings); + g_free (basedir_uri); } static void @@ -728,8 +723,8 @@ theme_adium_get_property (GObject *object, EmpathyThemeAdiumPriv *priv = GET_PRIV (object); switch (param_id) { - case PROP_PATH: - g_value_set_string (value, priv->path); + case PROP_ADIUM_DATA: + g_value_set_boxed (value, priv->data); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -746,9 +741,9 @@ theme_adium_set_property (GObject *object, EmpathyThemeAdiumPriv *priv = GET_PRIV (object); switch (param_id) { - case PROP_PATH: - g_free (priv->path); - priv->path = g_value_dup_string (value); + case PROP_ADIUM_DATA: + g_assert (priv->data == NULL); + priv->data = g_value_dup_boxed (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -760,7 +755,7 @@ static void empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - + object_class->finalize = theme_adium_finalize; object_class->dispose = theme_adium_dispose; object_class->constructed = theme_adium_constructed; @@ -768,13 +763,14 @@ empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass) object_class->set_property = theme_adium_set_property; g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_string ("path", - "The theme path", - "Path to the adium theme", - g_get_home_dir (), + PROP_ADIUM_DATA, + g_param_spec_boxed ("adium-data", + "The theme data", + "Data for the adium theme", + EMPATHY_TYPE_ADIUM_DATA, G_PARAM_CONSTRUCT_ONLY | - G_PARAM_READWRITE)); + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv)); @@ -786,7 +782,7 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme, EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv); - theme->priv = priv; + theme->priv = priv; priv->smiley_manager = empathy_smiley_manager_dup_singleton (); @@ -802,17 +798,17 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) } EmpathyThemeAdium * -empathy_theme_adium_new (const gchar *path) +empathy_theme_adium_new (EmpathyAdiumData *data) { - g_return_val_if_fail (empathy_theme_adium_is_valid (path), NULL); + g_return_val_if_fail (data != NULL, NULL); return g_object_new (EMPATHY_TYPE_THEME_ADIUM, - "path", path, + "adium-data", data, NULL); } gboolean -empathy_theme_adium_is_valid (const gchar *path) +empathy_adium_path_is_valid (const gchar *path) { gboolean ret; gchar *file; @@ -829,3 +825,227 @@ empathy_theme_adium_is_valid (const gchar *path) return ret; } +GHashTable * +empathy_adium_info_new (const gchar *path) +{ + gchar *file; + GValue *value; + GHashTable *info = NULL; + + g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL); + + file = g_build_filename (path, "Contents", "Info.plist", NULL); + value = empathy_plist_parse_from_file (file); + g_free (file); + + if (value) { + info = g_value_dup_boxed (value); + tp_g_value_slice_free (value); + } + + return info; +} + +GType +empathy_adium_data_get_type (void) +{ + static GType type_id = 0; + + if (!type_id) + { + type_id = g_boxed_type_register_static ("EmpathyAdiumData", + (GBoxedCopyFunc) empathy_adium_data_ref, + (GBoxedFreeFunc) empathy_adium_data_unref); + } + + return type_id; +} + +EmpathyAdiumData * +empathy_adium_data_new_with_info (const gchar *path, GHashTable *info) +{ + EmpathyAdiumData *data; + gchar *file; + gchar *template_html = NULL; + gsize template_len; + gchar *footer_html = NULL; + gsize footer_len; + GString *string; + gchar **strv = NULL; + gchar *css_path; + guint len = 0; + guint i = 0; + + g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL); + + data = g_slice_new0 (EmpathyAdiumData); + data->ref_count = 1; + data->path = g_strdup (path); + data->basedir = g_strconcat (path, G_DIR_SEPARATOR_S "Contents" + G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL); + data->info = g_hash_table_ref (info); + + /* Load html files */ + file = g_build_filename (data->basedir, "Incoming", "Content.html", NULL); + g_file_get_contents (file, &data->in_content_html, &data->in_content_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL); + g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL); + g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Outgoing", "NextContent.html", NULL); + g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Status.html", NULL); + g_file_get_contents (file, &data->status_html, &data->status_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Footer.html", NULL); + g_file_get_contents (file, &footer_html, &footer_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Incoming", "buddy_icon.png", NULL); + if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + data->default_incoming_avatar_filename = file; + } else { + g_free (file); + } + + file = g_build_filename (data->basedir, "Outgoing", "buddy_icon.png", NULL); + if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + data->default_outgoing_avatar_filename = file; + } else { + g_free (file); + } + + css_path = g_build_filename (data->basedir, "main.css", NULL); + + /* There is 2 formats for Template.html: The old one has 4 parameters, + * the new one has 5 parameters. */ + file = g_build_filename (data->basedir, "Template.html", NULL); + if (g_file_get_contents (file, &template_html, &template_len, NULL)) { + strv = g_strsplit (template_html, "%@", -1); + len = g_strv_length (strv); + } + g_free (file); + + if (len != 5 && len != 6) { + /* Either the theme has no template or it don't have the good + * number of parameters. Fallback to use our own template. */ + g_free (template_html); + g_strfreev (strv); + + file = empathy_file_lookup ("Template.html", "data"); + g_file_get_contents (file, &template_html, &template_len, NULL); + g_free (file); + strv = g_strsplit (template_html, "%@", -1); + len = g_strv_length (strv); + } + + /* Replace %@ with the needed information in the template html. */ + string = g_string_sized_new (template_len); + g_string_append (string, strv[i++]); + g_string_append (string, data->basedir); + g_string_append (string, strv[i++]); + if (len == 6) { + const gchar *variant; + + /* We include main.css by default */ + g_string_append_printf (string, "@import url(\"%s\");", css_path); + g_string_append (string, strv[i++]); + variant = tp_asv_get_string (data->info, "DefaultVariant"); + if (variant) { + g_string_append (string, "Variants/"); + g_string_append (string, variant); + g_string_append (string, ".css"); + } + } else { + /* FIXME: We should set main.css OR the variant css */ + g_string_append (string, css_path); + } + g_string_append (string, strv[i++]); + g_string_append (string, ""); /* We don't want header */ + g_string_append (string, strv[i++]); + /* FIXME: We should replace adium %macros% in footer */ + if (footer_html) { + g_string_append (string, footer_html); + } + g_string_append (string, strv[i++]); + data->template_html = g_string_free (string, FALSE); + + g_free (footer_html); + g_free (template_html); + g_free (css_path); + g_strfreev (strv); + + return data; +} + +EmpathyAdiumData * +empathy_adium_data_new (const gchar *path) +{ + EmpathyAdiumData *data; + GHashTable *info; + + info = empathy_adium_info_new (path); + data = empathy_adium_data_new_with_info (path, info); + g_hash_table_unref (info); + + return data; +} + +EmpathyAdiumData * +empathy_adium_data_ref (EmpathyAdiumData *data) +{ + g_return_val_if_fail (data != NULL, NULL); + + data->ref_count++; + + return data; +} + +void +empathy_adium_data_unref (EmpathyAdiumData *data) +{ + g_return_if_fail (data != NULL); + + data->ref_count--; + if (data->ref_count == 0) { + g_free (data->path); + g_free (data->basedir); + g_free (data->template_html); + g_free (data->in_content_html); + g_free (data->in_nextcontent_html); + g_free (data->out_content_html); + g_free (data->out_nextcontent_html); + g_free (data->default_avatar_filename); + g_free (data->default_incoming_avatar_filename); + g_free (data->default_outgoing_avatar_filename); + g_free (data->status_html); + g_hash_table_unref (data->info); + g_slice_free (EmpathyAdiumData, data); + } +} + +GHashTable * +empathy_adium_data_get_info (EmpathyAdiumData *data) +{ + g_return_val_if_fail (data != NULL, NULL); + + return data->info; +} + +const gchar * +empathy_adium_data_get_path (EmpathyAdiumData *data) +{ + g_return_val_if_fail (data != NULL, NULL); + + return data->path; +} + diff --git a/libempathy-gtk/empathy-theme-adium.h b/libempathy-gtk/empathy-theme-adium.h index b62675680..a8ed19de4 100644 --- a/libempathy-gtk/empathy-theme-adium.h +++ b/libempathy-gtk/empathy-theme-adium.h @@ -37,6 +37,7 @@ G_BEGIN_DECLS typedef struct _EmpathyThemeAdium EmpathyThemeAdium; typedef struct _EmpathyThemeAdiumClass EmpathyThemeAdiumClass; +typedef struct _EmpathyAdiumData EmpathyAdiumData; struct _EmpathyThemeAdium { WebKitWebView parent; @@ -48,8 +49,21 @@ struct _EmpathyThemeAdiumClass { }; GType empathy_theme_adium_get_type (void) G_GNUC_CONST; -EmpathyThemeAdium *empathy_theme_adium_new (const gchar *path); -gboolean empathy_theme_adium_is_valid (const gchar *path); +EmpathyThemeAdium *empathy_theme_adium_new (EmpathyAdiumData *data); + +gboolean empathy_adium_path_is_valid (const gchar *path); +GHashTable *empathy_adium_info_new (const gchar *path); + +#define EMPATHY_TYPE_ADIUM_DATA (empathy_adium_data_get_type ()) +GType empathy_adium_data_get_type (void) G_GNUC_CONST; +EmpathyAdiumData *empathy_adium_data_new (const gchar *path); +EmpathyAdiumData *empathy_adium_data_new_with_info (const gchar *path, + GHashTable *info); +EmpathyAdiumData *empathy_adium_data_ref (EmpathyAdiumData *data); +void empathy_adium_data_unref (EmpathyAdiumData *data); +GHashTable *empathy_adium_data_get_info (EmpathyAdiumData *data); +const gchar *empathy_adium_data_get_path (EmpathyAdiumData *data); + G_END_DECLS diff --git a/libempathy-gtk/empathy-theme-boxes.c b/libempathy-gtk/empathy-theme-boxes.c index 64d95d4f2..f5224278c 100644 --- a/libempathy-gtk/empathy-theme-boxes.c +++ b/libempathy-gtk/empathy-theme-boxes.c @@ -167,7 +167,7 @@ table_size_allocate_cb (GtkWidget *view, gtk_widget_get_size_request (box, NULL, &height); width = allocation->width; - + width -= \ gtk_text_view_get_right_margin (GTK_TEXT_VIEW (view)) - \ gtk_text_view_get_left_margin (GTK_TEXT_VIEW (view)); @@ -269,7 +269,7 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme, NULL); g_free (tmp); g_free (str); - + /* Set foreground color of labels to the same color than the header tag. */ table = gtk_text_buffer_get_tag_table (buffer); tag = gtk_text_tag_table_lookup (table, EMPATHY_THEME_BOXES_TAG_HEADER); @@ -349,7 +349,7 @@ theme_boxes_notify_show_avatars_cb (EmpathyConf *conf, gpointer user_data) { EmpathyThemeBoxesPriv *priv = GET_PRIV (user_data); - + empathy_conf_get_bool (conf, key, &priv->show_avatars); } diff --git a/libempathy-gtk/empathy-theme-irc.c b/libempathy-gtk/empathy-theme-irc.c index 183a5cc51..5d298564e 100644 --- a/libempathy-gtk/empathy-theme-irc.c +++ b/libempathy-gtk/empathy-theme-irc.c @@ -83,7 +83,7 @@ theme_irc_append_message (EmpathyChatTextView *view, nick_tag = EMPATHY_THEME_IRC_TAG_NICK_OTHER; } } - + gtk_text_buffer_get_end_iter (buffer, &iter); /* The nickname. */ diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c index c6da8ea68..ba3d48e68 100644 --- a/libempathy-gtk/empathy-theme-manager.c +++ b/libempathy-gtk/empathy-theme-manager.c @@ -193,7 +193,7 @@ theme_manager_update_boxes_tags (EmpathyThemeBoxes *theme, /* FIXME: GtkTextTag don't support to set color properties to NULL. * See bug #542523 */ - + #define TAG_SET(prop, prop_set, value) \ if (value != NULL) { \ g_object_set (tag, prop, value, NULL); \ @@ -252,7 +252,7 @@ theme_manager_update_boxes_tags (EmpathyThemeBoxes *theme, } static void -theme_manager_update_simple_tags (EmpathyThemeBoxes *theme) +on_style_set_cb (GtkWidget *widget, GtkStyle *previous_style, gpointer data) { GtkStyle *style; gchar color1[10]; @@ -260,14 +260,14 @@ theme_manager_update_simple_tags (EmpathyThemeBoxes *theme) gchar color3[10]; gchar color4[10]; - style = gtk_widget_get_default_style (); + style = gtk_widget_get_style (GTK_WIDGET (widget)); theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color1); theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color2); theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color3); theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color4); - theme_manager_update_boxes_tags (theme, + theme_manager_update_boxes_tags (EMPATHY_THEME_BOXES (widget), color4, /* header_foreground */ color2, /* header_background */ color3, /* header_line_background */ @@ -287,7 +287,8 @@ theme_manager_update_boxes_theme (EmpathyThemeManager *manager, EmpathyThemeManagerPriv *priv = GET_PRIV (manager); if (strcmp (priv->name, "simple") == 0) { - theme_manager_update_simple_tags (theme); + g_signal_connect (G_OBJECT (theme), "style-set", + G_CALLBACK (on_style_set_cb), theme); } else if (strcmp (priv->name, "clean") == 0) { theme_manager_update_boxes_tags (theme, @@ -329,8 +330,28 @@ empathy_theme_manager_create_view (EmpathyThemeManager *manager) #ifdef HAVE_WEBKIT if (strcmp (priv->name, "adium") == 0) { - if (empathy_theme_adium_is_valid (priv->adium_path)) { - return EMPATHY_CHAT_VIEW (empathy_theme_adium_new (priv->adium_path)); + if (empathy_adium_path_is_valid (priv->adium_path)) { + static EmpathyAdiumData *data = NULL; + EmpathyThemeAdium *theme_adium; + + if (data && + !tp_strdiff (empathy_adium_data_get_path (data), + priv->adium_path)) { + /* Theme did not change, reuse data */ + theme_adium = empathy_theme_adium_new (data); + return EMPATHY_CHAT_VIEW (theme_adium); + } + + /* Theme changed, drop old data if any and + * load a new one */ + if (data) { + empathy_adium_data_unref (data); + data = NULL; + } + + data = empathy_adium_data_new (priv->adium_path); + theme_adium = empathy_theme_adium_new (data); + return EMPATHY_CHAT_VIEW (theme_adium); } else { /* The adium path is not valid, fallback to classic theme */ return EMPATHY_CHAT_VIEW (theme_manager_create_irc_view (manager)); @@ -348,25 +369,6 @@ empathy_theme_manager_create_view (EmpathyThemeManager *manager) return EMPATHY_CHAT_VIEW (theme); } -static void -theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager) -{ - EmpathyThemeManagerPriv *priv = GET_PRIV (manager); - - /* FIXME: Make that work, it should update color when theme changes but - * it doesnt seems to work with all themes. */ - - if (strcmp (priv->name, "simple") == 0) { - GList *l; - - /* We are using the simple theme which use the GTK theme color, - * Update views to use the new color. */ - for (l = priv->boxes_views; l; l = l->next) { - theme_manager_update_simple_tags (EMPATHY_THEME_BOXES (l->data)); - } - } -} - static gboolean theme_manager_ensure_theme_exists (const gchar *name) { @@ -512,12 +514,6 @@ empathy_theme_manager_init (EmpathyThemeManager *manager) theme_manager_notify_adium_path_cb (empathy_conf_get (), EMPATHY_PREFS_CHAT_ADIUM_PATH, manager); - - /* Track GTK color changes */ - priv->settings = gtk_settings_get_default (); - g_signal_connect_swapped (priv->settings, "notify::color-hash", - G_CALLBACK (theme_manager_color_hash_notify_cb), - manager); } EmpathyThemeManager * diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index cf423de41..baa6d21de 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -37,7 +37,6 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> #include <gio/gio.h> -#include <canberra-gtk.h> #include <libmissioncontrol/mc-profile.h> @@ -184,11 +183,11 @@ empathy_builder_unref_and_keep_widget (GtkBuilder *gui, } const gchar * -empathy_icon_name_from_account (McAccount *account) +empathy_icon_name_from_account (EmpathyAccount *account) { McProfile *profile; - profile = mc_account_get_profile (account); + profile = empathy_account_get_profile (account); return mc_profile_get_icon_name (profile); } @@ -1311,8 +1310,8 @@ empathy_window_present (GtkWindow *window, } timestamp = gtk_get_current_event_time (); - gtk_window_set_skip_taskbar_hint (window, FALSE); gtk_window_present_with_time (window, timestamp); + gtk_window_set_skip_taskbar_hint (window, FALSE); /* FIXME: This shouldn't be required as gtk_window_present's doc says * it deiconify automatically. */ gtk_window_deiconify (window); @@ -1540,140 +1539,4 @@ empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler) G_CALLBACK (file_manager_receive_file_response_cb), handler); gtk_widget_show (widget); -} - -typedef struct { - EmpathySound sound_id; - const char * event_ca_id; - const char * event_ca_description; - const char * gconf_key; -} EmpathySoundEntry; - -/* NOTE: these entries MUST be in the same order than EmpathySound enum */ -static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = { - { EMPATHY_SOUND_MESSAGE_INCOMING, "message-new-instant", - N_("Received an instant message"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE } , - { EMPATHY_SOUND_MESSAGE_OUTGOING, "message-sent-instant", - N_("Sent an instant message"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE } , - { EMPATHY_SOUND_CONVERSATION_NEW, "message-new-instant", - N_("Incoming chat request"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION }, - { EMPATHY_SOUND_CONTACT_CONNECTED, "service-login", - N_("Contact connected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN }, - { EMPATHY_SOUND_CONTACT_DISCONNECTED, "service-logout", - N_("Contact disconnected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT }, - { EMPATHY_SOUND_ACCOUNT_CONNECTED, "service-login", - N_("Connected to server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN }, - { EMPATHY_SOUND_ACCOUNT_DISCONNECTED, "service-logout", - N_("Disconnected from server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }, - { EMPATHY_SOUND_PHONE_INCOMING, "phone-incoming-call", - N_("Incoming voice call"), NULL }, - { EMPATHY_SOUND_PHONE_OUTGOING, "phone-outgoing-calling", - N_("Outgoing voice call"), NULL }, - { EMPATHY_SOUND_PHONE_HANGUP, "phone-hangup", - N_("Voice call ended"), NULL }, -}; - - -static gboolean -empathy_sound_pref_is_enabled (const char *key) -{ - EmpathyConf *conf; - gboolean res; - - conf = empathy_conf_get (); - res = FALSE; - - empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_ENABLED, &res); - - if (!res) { - return FALSE; - } - - if (!empathy_check_available_state ()) { - empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_DISABLED_AWAY, - &res); - if (res) { - return FALSE; - } - } - - empathy_conf_get_bool (conf, key, &res); - - return res; -} - -void -empathy_sound_stop (EmpathySound sound_id) -{ - EmpathySoundEntry *entry; - - g_return_if_fail (sound_id < LAST_EMPATHY_SOUND); - - entry = &(sound_entries[sound_id]); - g_return_if_fail (entry->sound_id == sound_id); - - ca_context_cancel (ca_gtk_context_get (), entry->sound_id); -} - - -gboolean -empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id, - ca_finish_callback_t callback, gpointer user_data) -{ - EmpathySoundEntry *entry; - gboolean should_play = TRUE; - ca_proplist *p = NULL; - ca_context *c; - - g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE); - - entry = &(sound_entries[sound_id]); - g_return_val_if_fail (entry->sound_id == sound_id, FALSE); - - if (entry->gconf_key != NULL) { - should_play = empathy_sound_pref_is_enabled (entry->gconf_key); - } - - if (!should_play) - return FALSE; - - c = ca_gtk_context_get (); - ca_context_cancel (c, entry->sound_id); - - DEBUG ("Play sound \"%s\" (%s)", - entry->event_ca_id, - entry->event_ca_description); - - if (ca_proplist_create (&p) < 0) - goto failed; - - if (ca_proplist_sets (p, CA_PROP_EVENT_ID, entry->event_ca_id) < 0) - goto failed; - - if (ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION, - gettext (entry->event_ca_id)) < 0) - goto failed; - - if (ca_gtk_proplist_set_for_widget (p, widget) < 0) - goto failed; - - ca_context_play_full (ca_gtk_context_get (), entry->sound_id, - p, callback, user_data); - - ca_proplist_destroy (p); - - return TRUE; - -failed: - if (p != NULL) - ca_proplist_destroy (p); - - return FALSE; -} - -void -empathy_sound_play (GtkWidget *widget, EmpathySound sound_id) -{ - empathy_sound_play_full (widget, sound_id, NULL, NULL); -} - +}
\ No newline at end of file diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 60d48f3c4..10f889b0c 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -34,33 +34,16 @@ #include <gtk/gtk.h> -#include <canberra-gtk.h> - -#include <libmissioncontrol/mc-account.h> #include <libmissioncontrol/mc-profile.h> #include <libempathy/empathy-contact.h> +#include <libempathy/empathy-account.h> #include <libempathy/empathy-ft-handler.h> #include "empathy-chat-view.h" G_BEGIN_DECLS -/* NOTE: Keep this sync with sound_entries in empathy-ui-utils.c */ -typedef enum { - EMPATHY_SOUND_MESSAGE_INCOMING = 0, - EMPATHY_SOUND_MESSAGE_OUTGOING, - EMPATHY_SOUND_CONVERSATION_NEW, - EMPATHY_SOUND_CONTACT_CONNECTED, - EMPATHY_SOUND_CONTACT_DISCONNECTED, - EMPATHY_SOUND_ACCOUNT_CONNECTED, - EMPATHY_SOUND_ACCOUNT_DISCONNECTED, - EMPATHY_SOUND_PHONE_INCOMING, - EMPATHY_SOUND_PHONE_OUTGOING, - EMPATHY_SOUND_PHONE_HANGUP, - LAST_EMPATHY_SOUND, -} EmpathySound; - void empathy_gtk_init (void); GRegex * empathy_uri_regex_dup_singleton (void); @@ -76,7 +59,7 @@ GtkWidget *empathy_builder_unref_and_keep_widget (GtkBuilder *gui, GtkWidget *root); /* Pixbufs */ -const gchar * empathy_icon_name_from_account (McAccount *account); +const gchar * empathy_icon_name_from_account (EmpathyAccount *account); const gchar * empathy_icon_name_for_presence (TpConnectionPresenceType presence); const gchar * empathy_icon_name_for_contact (EmpathyContact *contact); GdkPixbuf * empathy_pixbuf_from_data (gchar *data, @@ -129,15 +112,6 @@ GtkWidget * empathy_link_button_new (const gchar *url, void empathy_send_file_with_file_chooser (EmpathyContact *contact); void empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler); -/* Sounds */ -void empathy_sound_play (GtkWidget *widget, - EmpathySound sound_id); -gboolean empathy_sound_play_full (GtkWidget *widget, - EmpathySound sound_id, - ca_finish_callback_t callback, - gpointer user_data); -void empathy_sound_stop (EmpathySound sound_id); - G_END_DECLS #endif /* __EMPATHY_UI_UTILS_H__ */ |