aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-04-29 20:05:50 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2011-10-21 14:04:50 +0800
commitcac6aa1626dcfe6c3503ee78c863f218c6a26551 (patch)
treee21a676035c87341abaacf40607f9db0bb5a161b /src
parent1cc11526cb28298f79ba6b194abfe24b14b229cd (diff)
downloadgsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.tar
gsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.tar.gz
gsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.tar.bz2
gsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.tar.lz
gsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.tar.xz
gsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.tar.zst
gsoc2013-empathy-cac6aa1626dcfe6c3503ee78c863f218c6a26551.zip
Show an infobar if there's not enough credit
With a button to buy some if desired.
Diffstat (limited to 'src')
-rw-r--r--src/empathy-call-handler.c9
-rw-r--r--src/empathy-call-window.c103
2 files changed, 106 insertions, 6 deletions
diff --git a/src/empathy-call-handler.c b/src/empathy-call-handler.c
index 9fe89337d..0f197bf5d 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)
{
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index d2e32a10a..2ec79516e 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;
@@ -2915,6 +2938,14 @@ display_error (EmpathyCallWindow *self,
info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL);
+ 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_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
@@ -2962,13 +2993,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 +3120,77 @@ empathy_call_window_video_stream_error (TpyCallChannel *call,
#endif
static void
+show_balance_error (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ EmpathyCallWindow *self = user_data;
+ TpConnection *conn = TP_CONNECTION (object);
+ GError *error = NULL;
+ gchar *balance, *tmp;
+ const gchar *uri, *currency;
+ gint amount;
+ guint scale;
+
+ if (!tp_proxy_prepare_finish (conn, res, &error))
+ {
+ DEBUG ("Failed to prepare Balance: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ uri = tp_connection_get_balance_uri (conn);
+
+ if (!tp_connection_get_balance (conn, &amount, &scale, &currency))
+ {
+ /* 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);
+ }
+
+ display_error (self,
+ NULL,
+ _("Sorry, you don’t have enough credit for that call."),
+ tmp = g_strdup_printf (_("Your current balance is %s."),
+ balance),
+ NULL,
+ _("Get credit..."),
+ uri,
+ EMP_RESPONSE_BALANCE);
+ g_free (tmp);
+}
+
+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))
+ {
+ TpConnection *conn;
+ GQuark features[] = { TP_CONNECTION_FEATURE_BALANCE, 0 };
+
+ g_object_get (self->priv->handler, "call-channel", &call, NULL);
+ conn = tp_channel_borrow_connection (TP_CHANNEL (call));
+ g_object_unref (call);
+
+ tp_proxy_prepare_async (conn, features, show_balance_error, self);
+ return;
+ }
+
if (state != TPY_CALL_STATE_ACCEPTED)
return;