aboutsummaryrefslogtreecommitdiffstats
path: root/conf_scr.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-02-05 19:04:33 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2012-02-05 19:04:33 +0000
commitf3410da7f0bd208a5f2d792131b215454e782e93 (patch)
tree6e79c9acde383b91f5f21eb3a72f33e9c7fbbfce /conf_scr.c
parent03dfbc2efa31d3c4fd7e576111883ea488e3e179 (diff)
downloadwavemon-f3410da7f0bd208a5f2d792131b215454e782e93.tar.gz
Imported Upstream version 0.7.3upstream/0.7.3
Diffstat (limited to 'conf_scr.c')
-rw-r--r--conf_scr.c156
1 files changed, 67 insertions, 89 deletions
diff --git a/conf_scr.c b/conf_scr.c
index ecf13a0..674137c 100644
--- a/conf_scr.c
+++ b/conf_scr.c
@@ -27,6 +27,14 @@
*/
#define MAX_NUM_CONF_ROWS (MAXYLEN - 1)
+/* GLOBALS */
+extern int conf_items; /* index into array storing menu items */
+
+static WINDOW *w_conf, *w_confpad;
+static int first_item, active_item;
+static int num_items, list_offset;
+static struct conf_item *item;
+
static void waddstr_item(WINDOW *w, int y, struct conf_item *item, char hilight)
{
char s[0x40];
@@ -42,17 +50,9 @@ static void waddstr_item(WINDOW *w, int y, struct conf_item *item, char hilight)
case t_int:
sprintf(s, "%d", *item->v.i);
break;
- case t_string:
- strncpy(s, item->v.s, item->max);
- break;
- case t_switch:
- strcpy(s, *item->v.b ? "Enabled" : "Disabled");
- break;
case t_list:
- strncpy(s, ll_get(item->list, *item->v.b), LISTVAL_MAX);
- break;
- case t_listval:
- strncpy(s, item->v.s, LISTVAL_MAX);
+ assert(item->list && item->list[*item->v.i]);
+ strncpy(s, item->list[*item->v.i], sizeof(s));
/* Fall through, dummy statements to pacify gcc -Wall */
case t_sep:
case t_func:
@@ -102,32 +102,14 @@ static void change_item(int inum, char sign)
*item->v.i + item->inc * sign >= item->min)
*item->v.i += item->inc * sign;
break;
- case t_switch:
- *item->v.b = *item->v.b == 0 ? 1 : 0;
- break;
case t_list:
- *item->v.b = *item->v.b + sign;
- if (*item->v.b >= ll_size(item->list))
- *item->v.b = 0;
- else if (*item->v.b < 0)
- *item->v.b = ll_size(item->list) - 1;
- break;
- case t_listval:
- tmp = ll_scan(item->list, "s", item->v.s);
- if (tmp == -1) {
- tmp = 0;
- } else {
- tmp += sign;
- if (tmp >= ll_size(item->list)) {
- tmp = 0;
- } else if (tmp < 0) {
- tmp = ll_size(item->list) - 1;
- }
- }
- strncpy(item->v.s, ll_get(item->list, tmp), LISTVAL_MAX);
- break;
- /* Dummy statements to pacify gcc -Wall */
- case t_string:
+ *item->v.i = *item->v.i + sign;
+ tmp = argv_count(item->list);
+ if (*item->v.i >= tmp)
+ *item->v.i = 0;
+ else if (*item->v.i < 0)
+ *item->v.i = tmp - 1;
+ /* Fall through, dummy statements to pacify gcc -Wall */
case t_sep:
case t_func:
break;
@@ -175,68 +157,64 @@ static int m_pref(WINDOW *w_conf, int list_offset, int active_item, int num_item
return list_offset;
}
-enum wavemon_screen scr_conf(WINDOW *w_menu)
+void scr_conf_init(void)
{
- WINDOW *w_conf, *w_confpad;
- int first_item, active_item = 0;
- int num_items = ll_size(conf_items);
- int list_offset = 0;
- int key = 0;
- struct conf_item *item;
+ conf_get_interface_list(); /* may have changed in the meantime */
+ num_items = ll_size(conf_items);
w_conf = newwin_title(0, WAV_HEIGHT, "Preferences", false);
w_confpad = newpad(num_items + 1, CONF_SCREEN_WIDTH);
- while ((item = ll_get(conf_items, active_item)) && item->type == t_sep)
- active_item++;
- first_item = active_item;
-
- while (key < KEY_F(1) || key > KEY_F(10)) {
- list_offset = m_pref(w_confpad, list_offset, active_item, num_items);
-
- prefresh(w_confpad, list_offset, 0,
- 1, (WAV_WIDTH - CONF_SCREEN_WIDTH)/2,
- MAXYLEN, (WAV_WIDTH + CONF_SCREEN_WIDTH)/2);
- wrefresh(w_conf);
-
- key = wgetch(w_menu);
- switch (key) {
- case KEY_DOWN:
- active_item = select_item(active_item, 1);
- if (active_item >= num_items) {
- active_item = first_item;
- list_offset = 0;
- }
- break;
- case KEY_UP:
- active_item = select_item(active_item, -1);
- if (active_item < first_item)
- active_item = num_items - 1;
- break;
- case KEY_LEFT:
- change_item(active_item, -1);
- break;
- case KEY_RIGHT:
- change_item(active_item, 1);
- break;
- case '\r':
- item = ll_get(conf_items, active_item);
- if (item->type == t_func) {
- flash();
- (*item->v.fp)();
- }
- break;
- /* Keyboard shortcuts */
- case 'q':
- key = KEY_F(10);
- break;
- case 'i':
- key = KEY_F(1);
+ if (first_item) /* already initialized */
+ return;
+ while ((item = ll_get(conf_items, first_item)) && item->type == t_sep)
+ first_item++;
+ active_item = first_item;
+}
+
+int scr_conf_loop(WINDOW *w_menu)
+{
+ int key;
+
+ list_offset = m_pref(w_confpad, list_offset, active_item, num_items);
+
+ prefresh(w_confpad, list_offset, 0,
+ 1, (WAV_WIDTH - CONF_SCREEN_WIDTH)/2,
+ MAXYLEN, (WAV_WIDTH + CONF_SCREEN_WIDTH)/2);
+ wrefresh(w_conf);
+
+ key = wgetch(w_menu);
+ switch (key) {
+ case KEY_DOWN:
+ active_item = select_item(active_item, 1);
+ if (active_item >= num_items) {
+ active_item = first_item;
+ list_offset = 0;
+ }
+ break;
+ case KEY_UP:
+ active_item = select_item(active_item, -1);
+ if (active_item < first_item)
+ active_item = num_items - 1;
+ break;
+ case KEY_LEFT:
+ change_item(active_item, -1);
+ break;
+ case KEY_RIGHT:
+ change_item(active_item, 1);
+ break;
+ case '\r':
+ item = ll_get(conf_items, active_item);
+ if (item->type == t_func) {
+ flash();
+ (*item->v.fp)();
}
}
+ return key;
+}
+void scr_conf_fini(void)
+{
delwin(w_conf);
delwin(w_confpad);
-
- return key - KEY_F(1);
}