From 416da629fa9a0e9293b811d36547b0b189b6e13d Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 15 Apr 2011 14:20:31 +1000 Subject: Add a menuitem to report the account balance for each account Adds a menu item for each connection that supports Conn.I.Balance, requests the current balance and then tracks further updates to the balance. TODO: - remove the menu item when the account is disconnected - implement the activated signal --- src/empathy-main-window.c | 197 +++++++++++++++++++++++++++++++++++++++++++++ src/empathy-main-window.ui | 2 + 2 files changed, 199 insertions(+) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 851a424ea..8d031385a 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -145,6 +145,8 @@ struct _EmpathyMainWindowPriv { GtkWidget *edit_context; GtkWidget *edit_context_separator; + GtkActionGroup *balance_action_group; + guint size_timeout_id; /* reffed TpAccount* => visible GtkInfoBar* */ @@ -783,6 +785,196 @@ main_window_update_status (EmpathyMainWindow *window) g_list_free (children); } +static char * +main_window_account_to_action_name (TpAccount *account) +{ + char *r; + + /* action names can't have '/' in them, replace it with '.' */ + r = g_strdup (tp_account_get_path_suffix (account)); + r = g_strdelimit (r, "/", '.'); + + return r; +} + +static void +main_window_balance_activate_cb (GtkAction *action, + EmpathyMainWindow *window) +{ + DEBUG ("ACTIVATE!"); +} + +static void +main_window_balance_update_balance (GtkAction *action, + GValueArray *balance) +{ + TpAccount *account = g_object_get_data (G_OBJECT (action), "account"); + int amount = 0; + guint scale = G_MAXINT32; + const char *currency = ""; + char *str; + + if (balance != NULL) + tp_value_array_unpack (balance, 3, + &amount, + &scale, + ¤cy); + + if (amount == 0 && + scale == G_MAXINT32 && + tp_str_empty (currency)) { + /* unknown balance */ + str = g_strdup_printf ("%s (--)", + tp_account_get_display_name (account)); + } else { + char *money = empathy_format_currency (amount, scale, currency); + + str = g_strdup_printf ("%s (%s %s)", + tp_account_get_display_name (account), + currency, money); + g_free (money); + } + + gtk_action_set_label (action, str); + g_free (str); +} + +static void +main_window_setup_balance_got_balance (TpProxy *conn, + const GValue *value, + const GError *in_error, + gpointer user_data, + GObject *action) +{ + GValueArray *balance = NULL; + + if (in_error != NULL) { + DEBUG ("Failed to get account balance: %s", + in_error->message); + } else if (!G_VALUE_HOLDS (value, TP_STRUCT_TYPE_CURRENCY_AMOUNT)) { + DEBUG ("Type mismatch"); + } else { + balance = g_value_get_boxed (value); + } + + main_window_balance_update_balance (GTK_ACTION (action), balance); +} + +static void +main_window_balance_changed_cb (TpConnection *conn, + const GValueArray *balance, + gpointer user_data, + GObject *action) +{ + main_window_balance_update_balance (GTK_ACTION (action), + (GValueArray *) balance); +} + +static void +main_window_setup_balance_conn_ready (GObject *conn, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyMainWindow *window = user_data; + EmpathyMainWindowPriv *priv = GET_PRIV (window); + TpAccount *account = g_object_get_data (conn, "account"); + GtkAction *action; + char *name, *ui; + GError *error = NULL; + + if (!tp_proxy_prepare_finish (conn, result, &error)) { + DEBUG ("Failed to prepare connection: %s", error->message); + + g_error_free (error); + return; + } + + if (!tp_proxy_has_interface_by_id (conn, + TP_IFACE_QUARK_CONNECTION_INTERFACE_BALANCE)) { + return; + } + + DEBUG ("Setting up balance for acct: %s", + tp_account_get_display_name (account)); + + if (priv->balance_action_group == NULL) { + /* create the action group */ + priv->balance_action_group = + gtk_action_group_new ("balance-action-group"); + + gtk_ui_manager_insert_action_group (priv->ui_manager, + priv->balance_action_group, -1); + } + + /* create the action */ + name = main_window_account_to_action_name (account); + action = gtk_action_new (name, + tp_account_get_display_name (account), + _("Top up account credit"), + tp_account_get_icon_name (account)); + + g_object_set_data (G_OBJECT (action), "account", account); + g_signal_connect (action, "activate", + G_CALLBACK (main_window_balance_activate_cb), window); + + gtk_action_group_add_action (priv->balance_action_group, action); + g_object_unref (action); + + ui = g_strdup_printf ( + "" + " " + " " + " " + " " + " " + " " + " " + "", + name); + + /* FIXME: do we want the merge id, can use it to unmerge the UI */ + gtk_ui_manager_add_ui_from_string (priv->ui_manager, ui, -1, + &error); + + g_free (name); + g_free (ui); + + if (error != NULL) { + DEBUG ("Failed to add balance UI for %s: %s", + tp_account_get_display_name (account), + error->message); + g_error_free (error); + return; + } + + /* request the current balance and monitor for any changes */ + tp_cli_dbus_properties_call_get (conn, -1, + TP_IFACE_CONNECTION_INTERFACE_BALANCE, + "AccountBalance", + main_window_setup_balance_got_balance, + window, NULL, G_OBJECT (action)); + + tp_cli_connection_interface_balance_connect_to_balance_changed ( + TP_CONNECTION (conn), main_window_balance_changed_cb, + window, NULL, G_OBJECT (action), NULL); +} + +static void +main_window_setup_balance (EmpathyMainWindow *window, + TpAccount *account) +{ + TpConnection *conn = tp_account_get_connection (account); + + if (conn == NULL) + return; + + /* need to prepare the connection: + * store the account on the connection */ + g_object_set_data (G_OBJECT (conn), "account", account); + tp_proxy_prepare_async (conn, NULL, + main_window_setup_balance_conn_ready, window); +} + static void main_window_connection_changed_cb (TpAccount *account, guint old_status, @@ -804,6 +996,8 @@ main_window_connection_changed_cb (TpAccount *account, if (current == TP_CONNECTION_STATUS_DISCONNECTED) { empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window), EMPATHY_SOUND_ACCOUNT_DISCONNECTED); + + /* FIXME: remove balance */ } if (current == TP_CONNECTION_STATUS_CONNECTED) { @@ -812,6 +1006,7 @@ main_window_connection_changed_cb (TpAccount *account, /* Account connected without error, remove error message if any */ main_window_remove_error (window, account); + main_window_setup_balance (window, account); } } @@ -1677,6 +1872,8 @@ account_manager_prepared_cb (GObject *source_object, window); g_hash_table_insert (priv->status_changed_handlers, account, GUINT_TO_POINTER (handler_id)); + + main_window_setup_balance (window, account); } g_signal_connect (manager, "account-validity-changed", diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 864be1d28..91b493b56 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -265,6 +265,8 @@ + + -- cgit v1.2.3 From 0892b114ee4fd20559fb0c613c7c145c8bedbc9d Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 15 Apr 2011 14:33:20 +1000 Subject: Remove balance from menu when account is disconnected --- src/empathy-main-window.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 8d031385a..03386a01a 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -880,6 +880,7 @@ main_window_setup_balance_conn_ready (GObject *conn, TpAccount *account = g_object_get_data (conn, "account"); GtkAction *action; char *name, *ui; + guint merge_id; GError *error = NULL; if (!tp_proxy_prepare_finish (conn, result, &error)) { @@ -932,9 +933,10 @@ main_window_setup_balance_conn_ready (GObject *conn, "", name); - /* FIXME: do we want the merge id, can use it to unmerge the UI */ - gtk_ui_manager_add_ui_from_string (priv->ui_manager, ui, -1, - &error); + merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager, + ui, -1, &error); + g_object_set_data (G_OBJECT (action), + "merge-id", GUINT_TO_POINTER (merge_id)); g_free (name); g_free (ui); @@ -997,7 +999,33 @@ main_window_connection_changed_cb (TpAccount *account, empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window), EMPATHY_SOUND_ACCOUNT_DISCONNECTED); - /* FIXME: remove balance */ + /* remove balance action if required */ + if (priv->balance_action_group != NULL) { + GtkAction *action; + char *name; + + name = main_window_account_to_action_name (account); + + action = gtk_action_group_get_action ( + priv->balance_action_group, name); + + if (action != NULL) { + guint merge_id; + + DEBUG ("Removing action"); + + merge_id = GPOINTER_TO_UINT (g_object_get_data ( + G_OBJECT (action), + "merge-id")); + + gtk_ui_manager_remove_ui (priv->ui_manager, + merge_id); + gtk_action_group_remove_action ( + priv->balance_action_group, action); + } + + g_free (name); + } } if (current == TP_CONNECTION_STATUS_CONNECTED) { -- cgit v1.2.3 From c26345ba2beb3957327810e201a9f71097910738 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 15 Apr 2011 15:24:23 +1000 Subject: Support Conn.I.Balance.ManageCreditURI --- src/empathy-main-window.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 03386a01a..ed306509e 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -801,7 +801,16 @@ static void main_window_balance_activate_cb (GtkAction *action, EmpathyMainWindow *window) { - DEBUG ("ACTIVATE!"); + const char *uri; + + uri = g_object_get_data (G_OBJECT (action), "manage-credit-uri"); + + if (!tp_str_empty (uri)) { + DEBUG ("Top-up credit URI: %s", uri); + empathy_url_show (GTK_WIDGET (window), uri); + } else { + DEBUG ("unknown protocol for top-up"); + } } static void @@ -840,23 +849,30 @@ main_window_balance_update_balance (GtkAction *action, } static void -main_window_setup_balance_got_balance (TpProxy *conn, - const GValue *value, - const GError *in_error, - gpointer user_data, - GObject *action) +main_window_setup_balance_got_balance_props (TpProxy *conn, + GHashTable *props, + const GError *in_error, + gpointer user_data, + GObject *action) { GValueArray *balance = NULL; + const char *uri; if (in_error != NULL) { - DEBUG ("Failed to get account balance: %s", + DEBUG ("Failed to get account balance properties: %s", in_error->message); - } else if (!G_VALUE_HOLDS (value, TP_STRUCT_TYPE_CURRENCY_AMOUNT)) { - DEBUG ("Type mismatch"); - } else { - balance = g_value_get_boxed (value); + goto finally; } + balance = tp_asv_get_boxed (props, "AccountBalance", + TP_STRUCT_TYPE_CURRENCY_AMOUNT); + uri = tp_asv_get_string (props, "ManageCreditURI"); + + g_object_set_data_full (action, "manage-credit-uri", + g_strdup (uri), g_free); + gtk_action_set_sensitive (GTK_ACTION (action), !tp_str_empty (uri)); + +finally: main_window_balance_update_balance (GTK_ACTION (action), balance); } @@ -950,10 +966,9 @@ main_window_setup_balance_conn_ready (GObject *conn, } /* request the current balance and monitor for any changes */ - tp_cli_dbus_properties_call_get (conn, -1, + tp_cli_dbus_properties_call_get_all (conn, -1, TP_IFACE_CONNECTION_INTERFACE_BALANCE, - "AccountBalance", - main_window_setup_balance_got_balance, + main_window_setup_balance_got_balance_props, window, NULL, G_OBJECT (action)); tp_cli_connection_interface_balance_connect_to_balance_changed ( -- cgit v1.2.3 From 4f128d19a94c2315db1bab800be93d97e6033b72 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 15 Apr 2011 15:47:50 +1000 Subject: Factor out main_window_setup_balance_create_action() --- src/empathy-main-window.c | 66 ++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index ed306509e..80bfd92d5 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -146,6 +146,7 @@ struct _EmpathyMainWindowPriv { GtkWidget *edit_context_separator; GtkActionGroup *balance_action_group; + GtkWidget *balance_vbox; guint size_timeout_id; @@ -886,36 +887,18 @@ main_window_balance_changed_cb (TpConnection *conn, (GValueArray *) balance); } -static void -main_window_setup_balance_conn_ready (GObject *conn, - GAsyncResult *result, - gpointer user_data) +static GtkAction * +main_window_setup_balance_create_action (EmpathyMainWindow *window, + TpAccount *account) { - EmpathyMainWindow *window = user_data; EmpathyMainWindowPriv *priv = GET_PRIV (window); - TpAccount *account = g_object_get_data (conn, "account"); GtkAction *action; char *name, *ui; guint merge_id; GError *error = NULL; - if (!tp_proxy_prepare_finish (conn, result, &error)) { - DEBUG ("Failed to prepare connection: %s", error->message); - - g_error_free (error); - return; - } - - if (!tp_proxy_has_interface_by_id (conn, - TP_IFACE_QUARK_CONNECTION_INTERFACE_BALANCE)) { - return; - } - - DEBUG ("Setting up balance for acct: %s", - tp_account_get_display_name (account)); - + /* create the action group if required */ if (priv->balance_action_group == NULL) { - /* create the action group */ priv->balance_action_group = gtk_action_group_new ("balance-action-group"); @@ -951,20 +934,50 @@ main_window_setup_balance_conn_ready (GObject *conn, merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager, ui, -1, &error); + if (error != NULL) { + DEBUG ("Failed to add balance UI for %s: %s", + tp_account_get_display_name (account), + error->message); + g_error_free (error); + } + g_object_set_data (G_OBJECT (action), "merge-id", GUINT_TO_POINTER (merge_id)); g_free (name); g_free (ui); - if (error != NULL) { - DEBUG ("Failed to add balance UI for %s: %s", - tp_account_get_display_name (account), - error->message); + return action; +} + +static void +main_window_setup_balance_conn_ready (GObject *conn, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyMainWindow *window = user_data; + TpAccount *account = g_object_get_data (conn, "account"); + GtkAction *action; + GError *error = NULL; + + if (!tp_proxy_prepare_finish (conn, result, &error)) { + DEBUG ("Failed to prepare connection: %s", error->message); + g_error_free (error); return; } + if (!tp_proxy_has_interface_by_id (conn, + TP_IFACE_QUARK_CONNECTION_INTERFACE_BALANCE)) { + return; + } + + DEBUG ("Setting up balance for acct: %s", + tp_account_get_display_name (account)); + + /* create the action */ + action = main_window_setup_balance_create_action (window, account); + /* request the current balance and monitor for any changes */ tp_cli_dbus_properties_call_get_all (conn, -1, TP_IFACE_CONNECTION_INTERFACE_BALANCE, @@ -2013,6 +2026,7 @@ empathy_main_window_init (EmpathyMainWindow *window) filename = empathy_file_lookup ("empathy-main-window.ui", "src"); gui = empathy_builder_get_file (filename, "main_vbox", &priv->main_vbox, + "balance_box", &priv->balance_vbox, "errors_vbox", &priv->errors_vbox, "auth_vbox", &priv->auth_vbox, "ui_manager", &priv->ui_manager, -- cgit v1.2.3 From 1038e0350d5cbe5b70f8d618b1a13d6717da8d7c Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 15 Apr 2011 16:18:33 +1000 Subject: Create balance widget, tie it to the action TODO: - show and hide balance widgets in response to a toggleaction --- src/empathy-main-window.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- src/empathy-main-window.ui | 19 ++++++++++++++--- 2 files changed, 68 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 80bfd92d5..c02fccb02 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -950,6 +950,50 @@ main_window_setup_balance_create_action (EmpathyMainWindow *window, return action; } +static GtkWidget * +main_window_setup_balance_create_widget (EmpathyMainWindow *window, + GtkAction *action) +{ + EmpathyMainWindowPriv *priv = GET_PRIV (window); + GtkWidget *hbox, *image, *label, *button; + + if (action == NULL) + return NULL; + + hbox = gtk_hbox_new (FALSE, 6); + + image = gtk_image_new (); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0); + gtk_widget_show (image); + + label = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + + button = gtk_button_new_with_label (_("Top Up...")); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0); + gtk_widget_show (button); + + gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0); + gtk_widget_show_all (hbox); + + /* bind the properties from the action to the widgets -- I could have + * written a widget that implemented GtkActivatable, but effort */ + g_object_bind_property (action, "label", label, "label", + G_BINDING_SYNC_CREATE); + g_object_bind_property (action, "icon-name", image, "icon-name", + G_BINDING_SYNC_CREATE); + g_signal_connect_swapped (button, "clicked", + G_CALLBACK (gtk_action_activate), action); + + /* tie the lifetime of the widget to the lifetime of the action */ + g_object_weak_ref (G_OBJECT (action), + (GWeakNotify) gtk_widget_destroy, hbox); + + return hbox; +} + static void main_window_setup_balance_conn_ready (GObject *conn, GAsyncResult *result, @@ -958,6 +1002,7 @@ main_window_setup_balance_conn_ready (GObject *conn, EmpathyMainWindow *window = user_data; TpAccount *account = g_object_get_data (conn, "account"); GtkAction *action; + GtkWidget *widget; GError *error = NULL; if (!tp_proxy_prepare_finish (conn, result, &error)) { @@ -978,6 +1023,9 @@ main_window_setup_balance_conn_ready (GObject *conn, /* create the action */ action = main_window_setup_balance_create_action (window, account); + /* create the display widget */ + widget = main_window_setup_balance_create_widget (window, action); + /* request the current balance and monitor for any changes */ tp_cli_dbus_properties_call_get_all (conn, -1, TP_IFACE_CONNECTION_INTERFACE_BALANCE, @@ -2026,7 +2074,7 @@ empathy_main_window_init (EmpathyMainWindow *window) filename = empathy_file_lookup ("empathy-main-window.ui", "src"); gui = empathy_builder_get_file (filename, "main_vbox", &priv->main_vbox, - "balance_box", &priv->balance_vbox, + "balance_vbox", &priv->balance_vbox, "errors_vbox", &priv->errors_vbox, "auth_vbox", &priv->auth_vbox, "ui_manager", &priv->ui_manager, @@ -2204,6 +2252,9 @@ empathy_main_window_init (EmpathyMainWindow *window) /* Set window size. */ empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME); + /* FIXME: bind balance_vbox to action */ + gtk_widget_show (priv->balance_vbox); + /* Enable event handling */ priv->call_observer = empathy_call_observer_dup_singleton (); priv->event_manager = empathy_event_manager_dup_singleton (); diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 91b493b56..7852de151 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -319,7 +319,7 @@ - + @@ -328,10 +328,11 @@ False False 2 + 3 - + @@ -342,6 +343,18 @@ 3 + + + + + + + + False + False + 4 + + True @@ -374,7 +387,7 @@ - 4 + 5 -- cgit v1.2.3 From 4786fdc5f4424c88c7fcaad5357f42a27c4e24ad Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 15 Apr 2011 16:39:40 +1000 Subject: Add a menu item to choose whether to show account balances in the roster --- src/empathy-main-window.c | 30 +++++++++++++++++++++++++----- src/empathy-main-window.ui | 8 ++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index c02fccb02..0952284e6 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -146,6 +146,7 @@ struct _EmpathyMainWindowPriv { GtkWidget *edit_context_separator; GtkActionGroup *balance_action_group; + GtkAction *view_balance_show_in_roster; GtkWidget *balance_vbox; guint size_timeout_id; @@ -957,9 +958,6 @@ main_window_setup_balance_create_widget (EmpathyMainWindow *window, EmpathyMainWindowPriv *priv = GET_PRIV (window); GtkWidget *hbox, *image, *label, *button; - if (action == NULL) - return NULL; - hbox = gtk_hbox_new (FALSE, 6); image = gtk_image_new (); @@ -1000,6 +998,7 @@ main_window_setup_balance_conn_ready (GObject *conn, gpointer user_data) { EmpathyMainWindow *window = user_data; + EmpathyMainWindowPriv *priv = GET_PRIV (window); TpAccount *account = g_object_get_data (conn, "account"); GtkAction *action; GtkWidget *widget; @@ -1023,6 +1022,11 @@ main_window_setup_balance_conn_ready (GObject *conn, /* create the action */ action = main_window_setup_balance_create_action (window, account); + if (action == NULL) + return; + + gtk_action_set_visible (priv->view_balance_show_in_roster, TRUE); + /* create the display widget */ widget = main_window_setup_balance_create_widget (window, action); @@ -1079,6 +1083,7 @@ main_window_connection_changed_cb (TpAccount *account, if (priv->balance_action_group != NULL) { GtkAction *action; char *name; + GList *a; name = main_window_account_to_action_name (account); @@ -1101,6 +1106,15 @@ main_window_connection_changed_cb (TpAccount *account, } g_free (name); + + a = gtk_action_group_list_actions ( + priv->balance_action_group); + + gtk_action_set_visible ( + priv->view_balance_show_in_roster, + g_list_length (a) > 0); + + g_list_free (a); } } @@ -2092,6 +2106,7 @@ empathy_main_window_init (EmpathyMainWindow *window) "notebook", &priv->notebook, "no_entry_label", &priv->no_entry_label, "roster_scrolledwindow", &sw, + "view_balance_show_in_roster", &priv->view_balance_show_in_roster, NULL); g_free (filename); @@ -2252,8 +2267,13 @@ empathy_main_window_init (EmpathyMainWindow *window) /* Set window size. */ empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME); - /* FIXME: bind balance_vbox to action */ - gtk_widget_show (priv->balance_vbox); + /* bind view_balance_show_in_roster */ + g_settings_bind (priv->gsettings_ui, "show-balance-in-roster", + priv->view_balance_show_in_roster, "active", + G_SETTINGS_BIND_DEFAULT); + g_object_bind_property (priv->view_balance_show_in_roster, "active", + priv->balance_vbox, "visible", + G_BINDING_SYNC_CREATE); /* Enable event handling */ priv->call_observer = empathy_call_observer_dup_singleton (); diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 7852de151..278d1392a 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -69,6 +69,13 @@ Show P_rotocols + + + view_balance_show_in_roster + Show Account _Balances in Roster + False + + view_show_map @@ -265,6 +272,7 @@ + -- cgit v1.2.3 From d4597e973a5eef6389f0900c3cea91d73e7c9873 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 18 Apr 2011 10:51:34 +1000 Subject: 'spacing' is an object property, not a child property of the packing --- src/empathy-main-window.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 278d1392a..757d591c3 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -328,6 +328,7 @@ + 3 @@ -336,7 +337,6 @@ False False 2 - 3 -- cgit v1.2.3 From 0ba165de9aecc194985de7c6c938b69360e9c3a3 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 19 Apr 2011 08:32:31 +1000 Subject: The icon needs to be set as "icon-name" not "stock-id" --- src/empathy-main-window.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 0952284e6..e888808ab 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -912,7 +912,9 @@ main_window_setup_balance_create_action (EmpathyMainWindow *window, action = gtk_action_new (name, tp_account_get_display_name (account), _("Top up account credit"), - tp_account_get_icon_name (account)); + NULL); + g_object_bind_property (account, "icon-name", action, "icon-name", + G_BINDING_SYNC_CREATE); g_object_set_data (G_OBJECT (action), "account", account); g_signal_connect (action, "activate", -- cgit v1.2.3 From 49af530a5bfa17173e28a7b706c5e68117c2cd21 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 3 May 2011 17:22:30 +1000 Subject: Change menu string to "Top up My Account ($1.23)..." --- src/empathy-main-window.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index e888808ab..4dc357fa7 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -823,7 +823,7 @@ main_window_balance_update_balance (GtkAction *action, int amount = 0; guint scale = G_MAXINT32; const char *currency = ""; - char *str; + char *money, *str; if (balance != NULL) tp_value_array_unpack (balance, 3, @@ -835,19 +835,25 @@ main_window_balance_update_balance (GtkAction *action, scale == G_MAXINT32 && tp_str_empty (currency)) { /* unknown balance */ - str = g_strdup_printf ("%s (--)", - tp_account_get_display_name (account)); + money = g_strdup ("--"); } else { - char *money = empathy_format_currency (amount, scale, currency); + char *tmp = empathy_format_currency (amount, scale, currency); - str = g_strdup_printf ("%s (%s %s)", - tp_account_get_display_name (account), - currency, money); - g_free (money); + money = g_strdup_printf ("%s %s", currency, tmp); + g_free (tmp); } + /* Translators: this string will be something like: + * Top up My Account ($1.23)..." */ + str = g_strdup_printf (_("Top up %s (%s)..."), + tp_account_get_display_name (account), + money); + gtk_action_set_label (action, str); g_free (str); + + /* pass ownership of @money to object data */ + g_object_set_data_full (G_OBJECT (action), "money", money, g_free); } static void -- cgit v1.2.3 From 8b7ca3f8fc98f353c439841efbf6951e86ad45a7 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 3 May 2011 17:33:34 +1000 Subject: Update balance view in roster per feedback --- src/empathy-main-window.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 4dc357fa7..c31f237c7 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -820,6 +820,7 @@ main_window_balance_update_balance (GtkAction *action, GValueArray *balance) { TpAccount *account = g_object_get_data (G_OBJECT (action), "account"); + GtkWidget *label; int amount = 0; guint scale = G_MAXINT32; const char *currency = ""; @@ -852,8 +853,11 @@ main_window_balance_update_balance (GtkAction *action, gtk_action_set_label (action, str); g_free (str); - /* pass ownership of @money to object data */ - g_object_set_data_full (G_OBJECT (action), "money", money, g_free); + /* update the money label in the roster */ + label = g_object_get_data (G_OBJECT (action), "money-label"); + + gtk_label_set_text (GTK_LABEL (label), money); + g_free (money); } static void @@ -964,35 +968,42 @@ main_window_setup_balance_create_widget (EmpathyMainWindow *window, GtkAction *action) { EmpathyMainWindowPriv *priv = GET_PRIV (window); + TpAccount *account; GtkWidget *hbox, *image, *label, *button; + account = g_object_get_data (G_OBJECT (action), "account"); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + hbox = gtk_hbox_new (FALSE, 6); + /* protocol icon */ image = gtk_image_new (); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0); - gtk_widget_show (image); + g_object_bind_property (action, "icon-name", image, "icon-name", + G_BINDING_SYNC_CREATE); + /* account name label */ label = gtk_label_new (""); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); + g_object_bind_property (account, "display-name", label, "label", + G_BINDING_SYNC_CREATE); + + /* balance label */ + label = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); + g_object_set_data (G_OBJECT (action), "money-label", label); + /* top up button */ button = gtk_button_new_with_label (_("Top Up...")); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0); - gtk_widget_show (button); + g_signal_connect_swapped (button, "clicked", + G_CALLBACK (gtk_action_activate), action); gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0); gtk_widget_show_all (hbox); - /* bind the properties from the action to the widgets -- I could have - * written a widget that implemented GtkActivatable, but effort */ - g_object_bind_property (action, "label", label, "label", - G_BINDING_SYNC_CREATE); - g_object_bind_property (action, "icon-name", image, "icon-name", - G_BINDING_SYNC_CREATE); - g_signal_connect_swapped (button, "clicked", - G_CALLBACK (gtk_action_activate), action); - /* tie the lifetime of the widget to the lifetime of the action */ g_object_weak_ref (G_OBJECT (action), (GWeakNotify) gtk_widget_destroy, hbox); -- cgit v1.2.3 From 90d1301153a574f9d3ac986783efa6b96ebb2f57 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 3 May 2011 17:36:12 +1000 Subject: Change the menu to say "Credit Balance" --- src/empathy-main-window.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/empathy-main-window.ui b/src/empathy-main-window.ui index 757d591c3..b21a07bac 100644 --- a/src/empathy-main-window.ui +++ b/src/empathy-main-window.ui @@ -72,7 +72,7 @@ view_balance_show_in_roster - Show Account _Balances in Roster + Credit Balance False -- cgit v1.2.3