diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-10-22 05:45:04 +0800 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-10-22 05:45:04 +0800 |
commit | 60a28f1712b841606b278cad8f3637b346063a79 (patch) | |
tree | 18cea31cc4072146ca73e5ae86a409c1c3c69d2f | |
parent | 8977f509839ca251cf0bdfd16a9cfb4d66962f02 (diff) | |
parent | bf6ec911f61590159f94d424c1a0632c439623f9 (diff) | |
download | gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.tar gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.tar.gz gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.tar.bz2 gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.tar.lz gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.tar.xz gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.tar.zst gsoc2013-empathy-60a28f1712b841606b278cad8f3637b346063a79.zip |
Merge branch 'balance-errors'
-rw-r--r-- | src/empathy-call-handler.c | 11 | ||||
-rw-r--r-- | src/empathy-call-window.c | 101 |
2 files changed, 103 insertions, 9 deletions
diff --git a/src/empathy-call-handler.c b/src/empathy-call-handler.c index 9fe89337d..99054b9de 100644 --- a/src/empathy-call-handler.c +++ b/src/empathy-call-handler.c @@ -190,13 +190,18 @@ static void on_call_state_changed_cb (TpyCallChannel *call, TpyCallState state, TpyCallFlags flags, - const GValueArray *call_state_reason, + const GValueArray *call_state_reason, GHashTable *call_state_details, EmpathyCallHandler *handler) { EmpathyCallHandlerPriv *priv = handler->priv; + gchar *dbus_reason; + guint actor, reason; - g_signal_emit (handler, signals[STATE_CHANGED], 0, state); + tp_value_array_unpack ((GValueArray *) call_state_reason, 3, + &actor, &reason, &dbus_reason); + + g_signal_emit (handler, signals[STATE_CHANGED], 0, state, dbus_reason); if (state == TPY_CALL_STATE_ENDED) { @@ -505,7 +510,7 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass) g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, - G_TYPE_NONE, 1, G_TYPE_UINT); + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); } EmpathyCallHandler * diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c index d2e32a10a..f7efe37a2 100644 --- a/src/empathy-call-window.c +++ b/src/empathy-call-window.c @@ -2893,14 +2893,37 @@ empathy_call_window_update_timer (gpointer user_data) return TRUE; } -#if 0 +enum +{ + EMP_RESPONSE_BALANCE +}; + +static void +on_error_infobar_response_cb (GtkInfoBar *info_bar, + gint response_id, + gpointer user_data) +{ + switch (response_id) + { + case GTK_RESPONSE_CLOSE: + gtk_widget_destroy (GTK_WIDGET (info_bar)); + break; + case EMP_RESPONSE_BALANCE: + empathy_url_show (GTK_WIDGET (info_bar), + g_object_get_data (G_OBJECT (info_bar), "uri")); + break; + } +} + static void display_error (EmpathyCallWindow *self, - TpyCallChannel *call, const gchar *img, const gchar *title, const gchar *desc, - const gchar *details) + const gchar *details, + const gchar *button_text, + const gchar *uri, + gint button_response) { EmpathyCallWindowPriv *priv = GET_PRIV (self); GtkWidget *info_bar; @@ -2912,8 +2935,18 @@ display_error (EmpathyCallWindow *self, gchar *txt; /* Create info bar */ - info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); + info_bar = gtk_info_bar_new (); + + if (button_text != NULL) + { + gtk_info_bar_add_button (GTK_INFO_BAR (info_bar), + button_text, button_response); + g_object_set_data_full (G_OBJECT (info_bar), + "uri", g_strdup (uri), g_free); + } + + gtk_info_bar_add_button (GTK_INFO_BAR (info_bar), + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING); @@ -2962,13 +2995,14 @@ display_error (EmpathyCallWindow *self, } g_signal_connect (info_bar, "response", - G_CALLBACK (gtk_widget_destroy), NULL); + G_CALLBACK (on_error_infobar_response_cb), NULL); gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING); gtk_widget_show_all (info_bar); } +#if 0 static gchar * media_stream_error_to_txt (EmpathyCallWindow *self, TpyCallChannel *call, @@ -3088,14 +3122,69 @@ empathy_call_window_video_stream_error (TpyCallChannel *call, #endif static void +show_balance_error (EmpathyCallWindow *self) +{ + TpChannel *call; + TpConnection *conn; + gchar *balance, *tmp; + const gchar *uri, *currency; + gint amount; + guint scale; + + g_object_get (self->priv->handler, + "call-channel", &call, + NULL); + + conn = tp_channel_borrow_connection (call); + g_object_unref (call); + + uri = tp_connection_get_balance_uri (conn); + + if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy)) + { + /* unknown balance */ + balance = g_strdup ("(--)"); + } + else + { + char *money = empathy_format_currency (amount, scale, currency); + + balance = g_strdup_printf ("%s %s", + currency, money); + g_free (money); + } + + tmp = g_strdup_printf (_("Your current balance is %s."), balance), + + display_error (self, + NULL, + _("Sorry, you don’t have enough credit for that call."), + tmp, NULL, + _("Top Up"), + uri, + EMP_RESPONSE_BALANCE); + + g_free (tmp); + g_free (balance); +} + +static void empathy_call_window_state_changed_cb (EmpathyCallHandler *handler, TpyCallState state, + gchar *reason, EmpathyCallWindow *self) { EmpathyCallWindowPriv *priv = GET_PRIV (self); TpyCallChannel *call; gboolean can_send_video; + if (state == TPY_CALL_STATE_ENDED && + !tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE)) + { + show_balance_error (self); + return; + } + if (state != TPY_CALL_STATE_ACCEPTED) return; |