- implemented menuevents enter+leave
- new method menuitem_get_client() - more maintainable way to specify count of enums - corrected some typos (VB)
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "shared/report.h"
|
#include "shared/report.h"
|
||||||
#include "shared/sockets.h"
|
#include "shared/sockets.h"
|
||||||
@@ -163,6 +164,8 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
|||||||
item = menuitem_create_ip (item_id, menu_commands_handler, text,
|
item = menuitem_create_ip (item_id, menu_commands_handler, text,
|
||||||
0, "192.168.1.245");
|
0, "192.168.1.245");
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
assert(!"unexpected menuitem type");
|
||||||
}
|
}
|
||||||
menu_add_item (menu, item);
|
menu_add_item (menu, item);
|
||||||
menuscreen_inform_item_modified (menu);
|
menuscreen_inform_item_modified (menu);
|
||||||
@@ -659,6 +662,8 @@ menu_goto_func (Client * c, int argc, char **argv)
|
|||||||
char * menu_id;
|
char * menu_id;
|
||||||
Menu * menu;
|
Menu * menu;
|
||||||
|
|
||||||
|
debug (RPT_DEBUG, "%s( Client [%d], %s )",
|
||||||
|
__FUNCTION__, c->sock, (argc > 1 ? argv[1] : "<null>") );
|
||||||
if (!c->ack)
|
if (!c->ack)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -676,12 +681,14 @@ menu_goto_func (Client * c, int argc, char **argv)
|
|||||||
/* A specified menu */
|
/* A specified menu */
|
||||||
menu = menu_find_item (c->menu, menu_id, true);
|
menu = menu_find_item (c->menu, menu_id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!menu) {
|
if (!menu) {
|
||||||
sock_send_string (c->sock, "huh? Cannot find menu id\n");
|
sock_send_string (c->sock, "huh? Cannot find menu id\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
menuscreen_goto (menu);
|
menuscreen_goto (menu);
|
||||||
/* Failure is not returned */
|
/* Failure is not returned */
|
||||||
|
/* why not? (Volker) */
|
||||||
sock_send_string(c->sock, "success\n");
|
sock_send_string(c->sock, "success\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -695,7 +702,6 @@ MenuEventFunc (menu_commands_handler)
|
|||||||
{
|
{
|
||||||
char buf[80] = "";
|
char buf[80] = "";
|
||||||
Client * c;
|
Client * c;
|
||||||
MenuItem * i;
|
|
||||||
|
|
||||||
/* Compose message */
|
/* Compose message */
|
||||||
if( event == MENUEVENT_UPDATE
|
if( event == MENUEVENT_UPDATE
|
||||||
@@ -738,6 +744,13 @@ MenuEventFunc (menu_commands_handler)
|
|||||||
item->id);
|
item->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (event == MENUEVENT_ENTER
|
||||||
|
|| event == MENUEVENT_LEAVE)
|
||||||
|
{
|
||||||
|
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||||
|
menuitem_eventtype_to_eventtypename(event),
|
||||||
|
item->id);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||||
menuitem_eventtype_to_eventtypename(event),
|
menuitem_eventtype_to_eventtypename(event),
|
||||||
@@ -747,10 +760,10 @@ MenuEventFunc (menu_commands_handler)
|
|||||||
buf[sizeof(buf)-1] = 0;
|
buf[sizeof(buf)-1] = 0;
|
||||||
|
|
||||||
/* Where should the message go to ? */
|
/* Where should the message go to ? */
|
||||||
for( i = item; i && i->parent != main_menu; i = i->parent );
|
c = menuitem_get_client(item);
|
||||||
c = (Client *) i->data.menu.association;
|
|
||||||
if( !c ) {
|
if( !c ) {
|
||||||
report( RPT_ERR, "%s: Could not find client of item \"%s\"", __FUNCTION__, item->id );
|
report( RPT_ERR, "%s: Could not find client of item \"%s\"",
|
||||||
|
__FUNCTION__, item->id );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "shared/report.h"
|
#include "shared/report.h"
|
||||||
|
|
||||||
#include "menuitem.h"
|
#include "menuitem.h"
|
||||||
|
#include "menuscreens.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "drivers.h"
|
#include "drivers.h"
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@
|
|||||||
|
|
||||||
char *error_strs[] = {"", "Out of range", "Too long", "Too short", "Invalid Address"};
|
char *error_strs[] = {"", "Out of range", "Too long", "Too short", "Invalid Address"};
|
||||||
char *menuitemtypenames[] = {"menu", "action", "checkbox", "ring", "slider", "numeric", "alpha","ip"};
|
char *menuitemtypenames[] = {"menu", "action", "checkbox", "ring", "slider", "numeric", "alpha","ip"};
|
||||||
char *menueventtypenames[] = {"select", "update", "plus", "minus"};
|
char *menueventtypenames[] = {"select", "update", "plus", "minus", "enter", "leave"};
|
||||||
|
|
||||||
void menuitem_destroy_action (MenuItem *item);
|
void menuitem_destroy_action (MenuItem *item);
|
||||||
void menuitem_destroy_checkbox (MenuItem *item);
|
void menuitem_destroy_checkbox (MenuItem *item);
|
||||||
@@ -1291,6 +1293,20 @@ MenuResult menuitem_process_input_ip (MenuItem *item, MenuToken token, char * ke
|
|||||||
return MENURESULT_ERROR;
|
return MENURESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the Client that owns item. extracted from menu_commands_handler().
|
||||||
|
*/
|
||||||
|
Client * menuitem_get_client(MenuItem * item)
|
||||||
|
{
|
||||||
|
MenuItem * i;
|
||||||
|
|
||||||
|
/* not fool prove... */
|
||||||
|
assert(item != NULL);
|
||||||
|
for (i = item; i && i->parent != main_menu; i = i->parent)
|
||||||
|
;
|
||||||
|
return (Client *) i->data.menu.association;
|
||||||
|
}
|
||||||
|
|
||||||
LinkedList * tablist2linkedlist (char *strings)
|
LinkedList * tablist2linkedlist (char *strings)
|
||||||
{
|
{
|
||||||
LinkedList * list;
|
LinkedList * list;
|
||||||
|
|||||||
+11
-10
@@ -41,7 +41,6 @@
|
|||||||
* Data definitions of the menustuff
|
* Data definitions of the menustuff
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NUM_ITEMTYPES 8
|
|
||||||
typedef enum MenuItemType { /* These values are used in the */
|
typedef enum MenuItemType { /* These values are used in the */
|
||||||
MENUITEM_MENU = 0, /* function tables in menuitem.c ! */
|
MENUITEM_MENU = 0, /* function tables in menuitem.c ! */
|
||||||
MENUITEM_ACTION = 1,
|
MENUITEM_ACTION = 1,
|
||||||
@@ -51,6 +50,7 @@ typedef enum MenuItemType { /* These values are used in the */
|
|||||||
MENUITEM_NUMERIC = 5,
|
MENUITEM_NUMERIC = 5,
|
||||||
MENUITEM_ALPHA = 6,
|
MENUITEM_ALPHA = 6,
|
||||||
MENUITEM_IP = 7,
|
MENUITEM_IP = 7,
|
||||||
|
NUM_ITEMTYPES = 8
|
||||||
} MenuItemType;
|
} MenuItemType;
|
||||||
|
|
||||||
typedef enum CheckboxValue {
|
typedef enum CheckboxValue {
|
||||||
@@ -80,16 +80,18 @@ typedef enum MenuResult {
|
|||||||
} MenuResult;
|
} MenuResult;
|
||||||
|
|
||||||
/* Events caused by a menuitem */
|
/* Events caused by a menuitem */
|
||||||
#define NUM_EVENTTYPES 4
|
|
||||||
typedef enum MenuEventType {
|
typedef enum MenuEventType {
|
||||||
MENUEVENT_SELECT = 0, /* Item has been selected
|
MENUEVENT_SELECT = 0, /* Item has been selected
|
||||||
(action chosen) */
|
(action chosen) */
|
||||||
MENUEVENT_UPDATE, /* Item has been modified
|
MENUEVENT_UPDATE = 1, /* Item has been modified
|
||||||
(checkbox, numeric, alphanumeric) */
|
(checkbox, numeric, alphanumeric) */
|
||||||
MENUEVENT_PLUS, /* Item has been modified in positive direction
|
MENUEVENT_PLUS = 2, /* Item has been modified in positive direction
|
||||||
(slider moved) */
|
(slider moved) */
|
||||||
MENUEVENT_MINUS, /* Item has been modified in negative direction
|
MENUEVENT_MINUS = 3, /* Item has been modified in negative direction
|
||||||
(slider moved) */
|
(slider moved) */
|
||||||
|
MENUEVENT_ENTER = 4, /* Menu has been entered */
|
||||||
|
MENUEVENT_LEAVE = 5, /* Menu has been left */
|
||||||
|
NUM_EVENTTYPES = 6
|
||||||
} MenuEventType;
|
} MenuEventType;
|
||||||
|
|
||||||
#define MenuEventFunc(f) int (f) (struct MenuItem *item, MenuEventType event)
|
#define MenuEventFunc(f) int (f) (struct MenuItem *item, MenuEventType event)
|
||||||
@@ -204,7 +206,7 @@ MenuItem *menuitem_create (MenuItemType type, char *id,
|
|||||||
MenuItem *menuitem_create_action (char *id, MenuEventFunc(*event_func),
|
MenuItem *menuitem_create_action (char *id, MenuEventFunc(*event_func),
|
||||||
char *text, MenuResult menu_result);
|
char *text, MenuResult menu_result);
|
||||||
/* Creates a an action item (a string only).
|
/* Creates a an action item (a string only).
|
||||||
* Generated events: MENUEVENT_ENTER when user selects the item.
|
* Generated events: MENUEVENT_SELECT when user selects the item.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MenuItem *menuitem_create_checkbox (char *id, MenuEventFunc(*event_func),
|
MenuItem *menuitem_create_checkbox (char *id, MenuEventFunc(*event_func),
|
||||||
@@ -229,7 +231,6 @@ MenuItem *menuitem_create_slider (char *id, MenuEventFunc(*event_func),
|
|||||||
* at the end positions of the slider.
|
* at the end positions of the slider.
|
||||||
* You can set the step size. Make it 0 to disable the automatic value chaning,
|
* You can set the step size. Make it 0 to disable the automatic value chaning,
|
||||||
* and update the value yourself.
|
* and update the value yourself.
|
||||||
* Generated events: MENUEVENT_ENTER upon entering this item,
|
|
||||||
* MENUEVENT_PLUS, MENUEVENT_MINUS when slider is moved (immediately).
|
* MENUEVENT_PLUS, MENUEVENT_MINUS when slider is moved (immediately).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -237,7 +238,6 @@ MenuItem *menuitem_create_numeric (char *id, MenuEventFunc(*event_func),
|
|||||||
char *text, int minvalue, int maxvalue, int value);
|
char *text, int minvalue, int maxvalue, int value);
|
||||||
/* Creates a numeric value box.
|
/* Creates a numeric value box.
|
||||||
* Value can range from minvalue to maxvalue.
|
* Value can range from minvalue to maxvalue.
|
||||||
* Generated events: MENUEVENT_ENTER upon entering this item,
|
|
||||||
* MENUEVENT_UPDATE when user finishes the value (no immediate update).
|
* MENUEVENT_UPDATE when user finishes the value (no immediate update).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -250,14 +250,12 @@ MenuItem *menuitem_create_alpha (char *id, MenuEventFunc(*event_func),
|
|||||||
* caps, non-caps and numbers are allowed. Also you can alow other characters.
|
* caps, non-caps and numbers are allowed. Also you can alow other characters.
|
||||||
* If password char is non-zero, you will only see this char, not the actual
|
* If password char is non-zero, you will only see this char, not the actual
|
||||||
* input.
|
* input.
|
||||||
* Generated events: MENUEVENT_ENTER upon entering this item,
|
|
||||||
* MENUEVENT_UPDATE when user finishes the value (no immediate update).
|
* MENUEVENT_UPDATE when user finishes the value (no immediate update).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MenuItem *menuitem_create_ip (char *id, MenuEventFunc(*event_func),
|
MenuItem *menuitem_create_ip (char *id, MenuEventFunc(*event_func),
|
||||||
char *text, bool v6, char *value);
|
char *text, bool v6, char *value);
|
||||||
/* Creates an ip value box. can be either v4 or v6
|
/* Creates an ip value box. can be either v4 or v6
|
||||||
* Generated events: MENUEVENT_ENTER upon entering this item,
|
|
||||||
* MENUEVENT_UPDATE when user finishes the value (no immediate update).
|
* MENUEVENT_UPDATE when user finishes the value (no immediate update).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -296,6 +294,9 @@ MenuResult menuitem_process_input (MenuItem *item, MenuToken token, char * key,
|
|||||||
* key is only used if token is MENUTOKEN_OTHER.
|
* key is only used if token is MENUTOKEN_OTHER.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Client * menuitem_get_client(MenuItem * item);
|
||||||
|
/* returns the Client that owns the MenuItem. item must not be null */
|
||||||
|
|
||||||
LinkedList * tablist2linkedlist (char * strings);
|
LinkedList * tablist2linkedlist (char * strings);
|
||||||
/* Converts a tab-separated list to a LinkedList. */
|
/* Converts a tab-separated list to a LinkedList. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user