aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-04-29 20:05:50 +0800
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-04-29 21:45:53 +0800
commit1c68eae8b655e8904bbb0a90001f01eb6d3b342a (patch)
tree72c15c44bee41ac11f9c305c08caec983a9db118
parent5304b0a50868ceb2dd624d29a6ae8e07bdfcdeb3 (diff)
downloadgsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.tar
gsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.tar.gz
gsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.tar.bz2
gsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.tar.lz
gsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.tar.xz
gsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.tar.zst
gsoc2013-empathy-1c68eae8b655e8904bbb0a90001f01eb6d3b342a.zip
Show an infobar if there's not enough credit
With a button to buy some if desired.
-rw-r--r--src/empathy-call-handler.c13
-rw-r--r--src/empathy-call-window.c113
2 files changed, 118 insertions, 8 deletions
diff --git a/src/empathy-call-handler.c b/src/empathy-call-handler.c
index aff96bd6e..56d109838 100644
--- a/src/empathy-call-handler.c
+++ b/src/empathy-call-handler.c
@@ -189,13 +189,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)
{
@@ -503,8 +508,8 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
signals[STATE_CHANGED] =
g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
+ _src_marshal_VOID__UINT_STRING,
+ 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 fdb753245..3f260327a 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -2110,14 +2110,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;
@@ -2132,6 +2155,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));
@@ -2179,13 +2210,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,
@@ -2305,14 +2337,87 @@ empathy_call_window_video_stream_error (TpyCallChannel *call,
#endif
static void
+got_balance_props (TpProxy *proxy,
+ GHashTable *props,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (weak_object);
+ GValueArray *balance;
+ gchar *balance_str, *currency, *tmp;
+ const gchar *uri;
+ gint amount, scale;
+
+ if (error != NULL)
+ {
+ DEBUG ("Failed to get Balance: %s", error->message);
+ return;
+ }
+
+ balance = tp_asv_get_boxed (props, "AccountBalance",
+ TP_STRUCT_TYPE_CURRENCY_AMOUNT);
+ uri = tp_asv_get_string (props, "ManageCreditURI");
+ tp_value_array_unpack (balance, 3,
+ &amount,
+ &scale,
+ &currency);
+
+ if (amount == 0 &&
+ scale == G_MAXINT32 &&
+ tp_str_empty (currency))
+ {
+ /* unknown balance */
+ balance_str = g_strdup ("(--)");
+ }
+ else
+ {
+ char *money = empathy_format_currency (amount, scale, currency);
+
+ balance_str = g_strdup_printf ("%s %s",
+ currency, money);
+ g_free (money);
+ }
+
+ /* FIXME: don't hardcode Skype here */
+ display_error (self,
+ NULL,
+ _("Sorry, you don’t have enough Skype Credit for that call."),
+ tmp = g_strdup_printf (_("Your current balance is %s."),
+ balance_str),
+ NULL,
+ _("Buy Skype 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))
+ {
+ g_object_get (handler, "call-channel", &call, NULL);
+
+ tp_cli_dbus_properties_call_get_all (
+ tp_channel_borrow_connection (TP_CHANNEL (call)),
+ -1,
+ TP_IFACE_CONNECTION_INTERFACE_BALANCE,
+ got_balance_props,
+ NULL, NULL, G_OBJECT (self));
+
+ g_object_unref (call);
+ return;
+ }
+
if (state != TPY_CALL_STATE_ACCEPTED)
return;