---
 src/stk.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index e24897f..9136732 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -40,6 +40,17 @@
 
 static GSList *g_drivers = NULL;
 
+struct stk_menu {
+       char *title;
+       GSList *items;
+       struct stk_items_next_action_indicator next_action;
+       int default_item;
+       struct stk_text_attribute title_attr;
+       struct stk_item_text_attribute_list item_attrs;
+       gboolean soft_key;
+       gboolean has_help;
+};
+
 struct stk_app_agent {
        char *path;
        char *bus;
@@ -235,6 +246,87 @@ static void stk_command_cb(const struct ofono_error *error,
        DBG("TERMINAL RESPONSE to a command reported no errors");
 }
 
+static struct stk_menu *stk_menu_create(const char *title,
+               const struct stk_text_attribute *title_attr, GSList *items,
+               const struct stk_item_text_attribute_list *item_attrs,
+               const struct stk_items_next_action_indicator *next_action,
+               int default_id, gboolean soft_key, gboolean has_help)
+{
+       struct stk_menu *ret = g_new(struct stk_menu, 1);
+       GSList *l;
+       int i;
+
+       ret->title = g_strdup(title ?: "");
+       ret->items = g_slist_copy((GSList *) items);
+       ret->default_item = -1;
+       memcpy(&ret->next_action, next_action, sizeof(ret->next_action));
+       memcpy(&ret->title_attr, title_attr, sizeof(ret->title_attr));
+       memcpy(&ret->item_attrs, item_attrs, sizeof(ret->item_attrs));
+       ret->soft_key = soft_key;
+       ret->has_help = has_help;
+
+       for (l = ret->items, i = 0; l; l = l->next, i++) {
+               struct stk_item *j = g_memdup(l->data, sizeof(*j));
+
+               j->text = g_strdup(j->text);
+               l->data = j;
+
+               if (j->id == default_id)
+                       ret->default_item = i;
+       }
+
+       return ret;
+}
+
+static void stk_menu_free(struct stk_menu *menu)
+{
+       GSList *l;
+
+       for (l = menu->items; l; l = l->next) {
+               struct stk_item *i = l->data;
+
+               g_free(i->text);
+               g_free(i);
+       }
+
+       g_slist_free(menu->items);
+       g_free(menu->title);
+       g_free(menu);
+}
+
+static char **stk_menu_items_strlist(struct stk_menu *menu)
+{
+       char **items = g_new0(char *, g_slist_length(menu->items) + 1);
+       int i;
+       GSList *l;
+
+       for (i = 0, l = menu->items; l; l = l->next, i++) {
+               struct stk_item *item = l->data;
+               items[i] = item->text;
+       }
+
+       return items;
+}
+
+static void append_menu(DBusMessage *msg, struct stk_menu *menu,
+                       dbus_bool_t main_menu)
+{
+       char **items;
+       dbus_bool_t has_help = menu->has_help;
+       dbus_int16_t default_item = menu->default_item;
+
+       items = stk_menu_items_strlist(menu);
+       dbus_message_append_args(msg,
+                                       DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+                                       &items, g_slist_length(menu->items),
+                                       DBUS_TYPE_STRING, &menu->title,
+                                       DBUS_TYPE_BOOLEAN, &has_help,
+                                       DBUS_TYPE_INT16, &default_item,
+                                       DBUS_TYPE_BOOLEAN, &main_menu,
+                                       DBUS_TYPE_INVALID);
+       g_free(items);
+}
+
 static void app_agent_request_end(struct ofono_stk *stk)
 {
        stk->cmd_send = NULL;
-- 
1.7.1.86.g0e460.dirty

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to