mirror of git://git.sysmocom.de/ofono
stk: Utilities to deal with menus.
This commit is contained in:
parent
9654c69d7d
commit
5faa3951c2
67
src/stk.c
67
src/stk.c
|
@ -224,6 +224,73 @@ static void stk_command_cb(const struct ofono_error *error, void *data)
|
|||
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,
|
||||
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 ? title : "");
|
||||
ret->icon_id = 0;
|
||||
ret->items = g_new0(struct stk_menu_item, g_slist_length(items) + 1);
|
||||
ret->default_item = -1;
|
||||
ret->soft_key = soft_key;
|
||||
ret->has_help = has_help;
|
||||
|
||||
for (l = items, i = 0; l; l = l->next, i++) {
|
||||
struct stk_item *item = l->data;
|
||||
|
||||
ret->items[i].text = g_strdup(item->text);
|
||||
ret->items[i].item_id = item->id;
|
||||
|
||||
if (item->id == default_id)
|
||||
ret->default_item = i;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct stk_menu *stk_menu_create_from_set_up_menu(
|
||||
const struct stk_command *cmd)
|
||||
{
|
||||
gboolean soft_key = (cmd->qualifier & (1 << 0)) != 0;
|
||||
gboolean has_help = (cmd->qualifier & (1 << 7)) != 0;
|
||||
|
||||
return stk_menu_create(cmd->setup_menu.alpha_id,
|
||||
&cmd->setup_menu.text_attr,
|
||||
cmd->setup_menu.items,
|
||||
&cmd->setup_menu.item_text_attr_list,
|
||||
0, soft_key, has_help);
|
||||
}
|
||||
|
||||
static struct stk_menu *stk_menu_create_from_select_item(
|
||||
const struct stk_command *cmd)
|
||||
{
|
||||
gboolean soft_key = (cmd->qualifier & (1 << 2)) != 0;
|
||||
gboolean has_help = (cmd->qualifier & (1 << 7)) != 0;
|
||||
|
||||
return stk_menu_create(cmd->select_item.alpha_id,
|
||||
&cmd->select_item.text_attr,
|
||||
cmd->select_item.items,
|
||||
&cmd->select_item.item_text_attr_list,
|
||||
cmd->select_item.item_id, soft_key, has_help);
|
||||
}
|
||||
|
||||
static void stk_menu_free(struct stk_menu *menu)
|
||||
{
|
||||
struct stk_menu_item *i;
|
||||
|
||||
for (i = menu->items; i->text; i++)
|
||||
g_free(i->text);
|
||||
|
||||
g_free(menu->items);
|
||||
g_free(menu->title);
|
||||
g_free(menu);
|
||||
}
|
||||
|
||||
static void stk_alpha_id_set(struct ofono_stk *stk, const char *text)
|
||||
{
|
||||
/* TODO */
|
||||
|
|
|
@ -297,3 +297,39 @@ struct stk_agent *stk_agent_new(const char *path, const char *sender,
|
|||
|
||||
return agent;
|
||||
}
|
||||
|
||||
static void append_menu_items(DBusMessageIter *iter,
|
||||
const struct stk_menu_item *item)
|
||||
{
|
||||
DBusMessageIter array, entry;
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
|
||||
"(sy)", &array);
|
||||
|
||||
for (; item->text; item++) {
|
||||
dbus_message_iter_open_container(&array, DBUS_TYPE_STRUCT,
|
||||
NULL, &entry);
|
||||
|
||||
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING,
|
||||
&item->text);
|
||||
dbus_message_iter_append_basic(&entry, DBUS_TYPE_BYTE,
|
||||
&item->icon_id);
|
||||
|
||||
dbus_message_iter_close_container(&array, &entry);
|
||||
}
|
||||
|
||||
dbus_message_iter_close_container(iter, &array);
|
||||
}
|
||||
|
||||
void append_menu_items_variant(DBusMessageIter *iter,
|
||||
const struct stk_menu_item *items)
|
||||
{
|
||||
DBusMessageIter variant;
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
|
||||
"a(sy)", &variant);
|
||||
|
||||
append_menu_items(&variant, items);
|
||||
|
||||
dbus_message_iter_close_container(iter, &variant);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,21 @@
|
|||
*
|
||||
*/
|
||||
|
||||
struct stk_menu_item {
|
||||
char *text;
|
||||
uint8_t icon_id;
|
||||
uint8_t item_id;
|
||||
};
|
||||
|
||||
struct stk_menu {
|
||||
char *title;
|
||||
uint8_t icon_id;
|
||||
struct stk_menu_item *items;
|
||||
int default_item;
|
||||
gboolean soft_key;
|
||||
gboolean has_help;
|
||||
};
|
||||
|
||||
enum stk_agent_result {
|
||||
STK_AGENT_RESULT_OK,
|
||||
STK_AGENT_RESULT_BACK,
|
||||
|
@ -45,3 +60,6 @@ void stk_agent_set_destroy_watch(struct stk_agent *agent, GDestroyNotify notify,
|
|||
void *user_data);
|
||||
|
||||
void stk_agent_request_cancel(struct stk_agent *agent);
|
||||
|
||||
void append_menu_items_variant(DBusMessageIter *iter,
|
||||
const struct stk_menu_item *items);
|
||||
|
|
Loading…
Reference in New Issue