summaryrefslogtreecommitdiffstats
path: root/libmenu/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmenu/menu.c')
-rw-r--r--libmenu/menu.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/libmenu/menu.c b/libmenu/menu.c
index a262d7a960..cae17a55c9 100644
--- a/libmenu/menu.c
+++ b/libmenu/menu.c
@@ -88,6 +88,8 @@ double menu_mouse_y = -1.0;
int menu_mouse_pos_updated = 0;
static struct MPContext *menu_ctx = NULL;
+static struct m_config *menu_mconfig = NULL;
+static struct input_ctx *menu_input = NULL;
static menu_def_t* menu_list = NULL;
static int menu_count = 0;
static menu_cmd_bindings_t *cmd_bindings = NULL;
@@ -103,16 +105,17 @@ static menu_cmd_bindings_t *get_cmd_bindings(const char *name)
return NULL;
}
-static int menu_parse_config(char* buffer) {
+static int menu_parse_config(char* buffer, struct m_config *mconfig)
+{
char *element,*body, **attribs, *name;
menu_info_t* minfo = NULL;
int r,i;
- ASX_Parser_t* parser = asx_parser_new();
+ ASX_Parser_t* parser = asx_parser_new(mconfig);
while(1) {
r = asx_get_element(parser,&buffer,&element,&body,&attribs);
if(r < 0) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] syntax error at line: %d\n",parser->line);
asx_parser_free(parser);
return 0;
} else if(r == 0) {
@@ -122,7 +125,7 @@ static int menu_parse_config(char* buffer) {
// Has it a name ?
name = asx_get_attrib("name",attribs);
if(!name) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuDefinitionsNeedANameAttrib,parser->line);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Menu definitions need a name attribute (line %d).\n",parser->line);
free(element);
if(body) free(body);
asx_free_attribs(attribs);
@@ -154,7 +157,7 @@ static int menu_parse_config(char* buffer) {
for(;;) {
r = asx_get_element(parser,&bd,&element,&b,&attribs);
if(r < 0) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] syntax error at line: %d\n",
parser->line);
free(body);
asx_parser_free(parser);
@@ -207,13 +210,13 @@ static int menu_parse_config(char* buffer) {
for(i = 0 ; attribs[2*i] ; i++) {
if(strcasecmp(attribs[2*i],"name") == 0) continue;
if(!m_struct_set(&minfo->priv_st,menu_list[menu_count].cfg,attribs[2*i], attribs[2*i+1]))
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_BadAttrib,attribs[2*i],attribs[2*i+1],
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] bad attribute %s=%s in menu '%s' at line %d\n",attribs[2*i],attribs[2*i+1],
name,parser->line);
}
menu_count++;
memset(&menu_list[menu_count],0,sizeof(menu_def_t));
} else {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuType,element,parser->line);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] unknown menu type '%s' at line %d\n",element,parser->line);
free(name);
if(body) free(body);
}
@@ -229,7 +232,9 @@ static int menu_parse_config(char* buffer) {
#define BUF_STEP 1024
#define BUF_MIN 128
#define BUF_MAX BUF_STEP*1024
-int menu_init(struct MPContext *mpctx, char* cfg_file) {
+int menu_init(struct MPContext *mpctx, struct m_config *mconfig,
+ struct input_ctx *input_ctx, char* cfg_file)
+{
char* buffer = NULL;
int bl = BUF_STEP, br = 0;
int f, fd;
@@ -239,7 +244,7 @@ int menu_init(struct MPContext *mpctx, char* cfg_file) {
#endif
fd = open(cfg_file, O_RDONLY);
if(fd < 0) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_CantOpenConfigFile,cfg_file);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Can't open menu config file: %s\n",cfg_file);
return 0;
}
buffer = malloc(bl);
@@ -247,7 +252,7 @@ int menu_init(struct MPContext *mpctx, char* cfg_file) {
int r;
if(bl - br < BUF_MIN) {
if(bl >= BUF_MAX) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ConfigFileIsTooBig,BUF_MAX/1024);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Config file is too big (> %d KB)\n",BUF_MAX/1024);
close(fd);
free(buffer);
return 0;
@@ -260,7 +265,7 @@ int menu_init(struct MPContext *mpctx, char* cfg_file) {
br += r;
}
if(!br) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ConfigFileIsEmpty);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Config file is empty.\n");
return 0;
}
buffer[br-1] = '\0';
@@ -268,7 +273,9 @@ int menu_init(struct MPContext *mpctx, char* cfg_file) {
close(fd);
menu_ctx = mpctx;
- f = menu_parse_config(buffer);
+ menu_mconfig = mconfig;
+ menu_input = input_ctx;
+ f = menu_parse_config(buffer, mconfig);
free(buffer);
return f;
}
@@ -304,7 +311,8 @@ int menu_dflt_read_key(menu_t* menu,int cmd) {
for (i = 0; i < bindings->binding_num; ++i) {
if (bindings->bindings[i].key == cmd) {
if (bindings->bindings[i].cmd)
- mp_input_parse_and_queue_cmds(bindings->bindings[i].cmd);
+ mp_input_parse_and_queue_cmds(menu->input_ctx,
+ bindings->bindings[i].cmd);
return 1;
}
}
@@ -322,20 +330,22 @@ menu_t* menu_open(char *name) {
break;
}
if(menu_list[i].name == NULL) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuNotFound,name);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Menu %s not found.\n",name);
return NULL;
}
m = calloc(1,sizeof(menu_t));
m->priv_st = &(menu_list[i].type->priv_st);
m->priv = m_struct_copy(m->priv_st,menu_list[i].cfg);
m->ctx = menu_ctx;
+ m->mconfig = menu_mconfig;
+ m->input_ctx = menu_input;
m->type = &menu_list[i];
if(menu_list[i].type->open(m,menu_list[i].args))
return m;
if(m->priv)
m_struct_free(m->priv_st,m->priv);
free(m);
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuInitFailed,name);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Menu '%s': Init failed.\n",name);
return NULL;
}
@@ -473,7 +483,7 @@ void menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) {
int font;
if(!draw_alpha) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Unsupported output format!!!!\n");
return;
}
@@ -507,7 +517,7 @@ void menu_draw_text_full(mp_image_t* mpi,char* txt,
draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);
if(!draw_alpha) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Unsupported output format!!!!\n");
return;
}
@@ -750,7 +760,7 @@ void menu_draw_box(mp_image_t* mpi,unsigned char grey,unsigned char alpha, int x
int g;
if(!draw_alpha) {
- mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);
+ mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Unsupported output format!!!!\n");
return;
}