4 #include <Elementary.h>
9 #include "simple-popup.h"
14 OFono_Pending *pending;
15 OFono_USSD_State state;
17 OFono_Callback_List_Modem_Node *cb_changed;
20 static void _ussd_respond_reply(void *data, OFono_Error err, const char *str)
24 DBG("ctx=%p, e=%d, str=%s, popup=%p", ctx, err, str, ctx->popup);
28 /* no popup? then it was canceled */
32 if (err == OFONO_ERROR_NONE) {
33 eina_stringshare_replace(&(ctx->message), str);
34 simple_popup_message_set(ctx->popup, ctx->message);
35 } else if (err == OFONO_ERROR_OFFLINE) {
36 simple_popup_title_set(ctx->popup, "Offline");
37 simple_popup_message_set(ctx->popup, "System is Offline");
38 simple_popup_button_dismiss_set(ctx->popup);
42 if (ctx->state == OFONO_USSD_STATE_USER_RESPONSE)
43 snprintf(buf, sizeof(buf),
44 "Could not complete.<br>Error: %s.<br>"
45 "Try again:<br><br>%s",
46 ofono_error_message_get(err),
49 snprintf(buf, sizeof(buf),
50 "Could not complete.<br>Error: %s.",
51 ofono_error_message_get(err));
53 simple_popup_title_set(ctx->popup, "Error");
54 simple_popup_message_set(ctx->popup, buf);
58 static void _ussd_respond(void *data, Evas_Object *o __UNUSED__,
59 void *event_info __UNUSED__)
62 const char *markup = simple_popup_entry_get(ctx->popup);
65 DBG("ctx=%p, markup=%s, pending=%p, popup=%p",
66 ctx, markup, ctx->pending, ctx->popup);
71 /* do not respond if there is a pending ss call */
72 EINA_SAFETY_ON_TRUE_RETURN(ctx->pending != NULL);
74 utf8 = elm_entry_markup_to_utf8(markup);
75 EINA_SAFETY_ON_NULL_RETURN(utf8);
77 ctx->pending = ofono_ussd_respond(utf8, _ussd_respond_reply, ctx);
80 simple_popup_message_set(ctx->popup, NULL);
81 simple_popup_entry_disable(ctx->popup);
84 static void _ussd_cancel_reply(void *data, OFono_Error e)
88 DBG("ctx=%p, e=%d, pending=%p, popup=%p",
89 ctx, e, ctx->pending, ctx->popup);
92 evas_object_del(ctx->popup);
95 static void _ussd_cancel(void *data, Evas_Object *o __UNUSED__,
96 void *event_info __UNUSED__)
99 ofono_ussd_cancel(_ussd_cancel_reply, ctx);
102 static void _ofono_changed(void *data)
105 OFono_USSD_State state = ofono_ussd_state_get();
107 DBG("ctx=%p, state=%d (was: %d), pending=%p",
108 ctx, state, ctx->state, ctx->pending);
110 if (ctx->state == state)
113 if (state != OFONO_USSD_STATE_USER_RESPONSE) {
114 simple_popup_entry_disable(ctx->popup);
115 simple_popup_button_dismiss_set(ctx->popup);
117 simple_popup_entry_enable(ctx->popup);
118 simple_popup_buttons_set(ctx->popup,
131 static void _on_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__,
132 void *event_info __UNUSED__)
136 DBG("ctx=%p, pending=%p, cb_changed=%p",
137 ctx, ctx->pending, ctx->cb_changed);
142 ofono_ussd_cancel(NULL, NULL);
143 ofono_pending_cancel(ctx->pending);
146 eina_stringshare_del(ctx->message);
147 ofono_modem_changed_cb_del(ctx->cb_changed);
150 void ussd_start(const char *message)
154 EINA_SAFETY_ON_NULL_RETURN(message);
155 ctx = calloc(1, sizeof(USSD));
156 EINA_SAFETY_ON_NULL_RETURN(ctx);
158 ctx->message = eina_stringshare_add(message);
160 ctx->cb_changed = ofono_modem_changed_cb_add(_ofono_changed, ctx);
162 ctx->popup = gui_simple_popup("Supplementary Services", ctx->message);
163 evas_object_event_callback_add(ctx->popup, EVAS_CALLBACK_DEL,