[Lcdproc] How can a client force the menu system to exit?

Marcus Priesch marcus@priesch.priv.at
Wed Mar 21 18:51:01 2007


--=-0/pqPTUEPeogM++o9aDy
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2007-03-21 at 18:07 +0100, Robert Buchholz wrote:
> > i have a patch here for lcdproc 0.5.0 ;)
> 
> Patches go to the list always. That's what it is for :-)

ok, so heeere you are ;)

i just found out that it actually adds "menusystem_quit" and
"menusystem_enter" commands to exit the menu system and enter it at any
point. we need the possibility to tell the user of some important events
when he/she is navigating the menu ... after acting on the event, the
menu should be resumed at the point where the event "left" it ...

i must admit that i am not the author of the patch, but he is not
subscribed to the list ... if there are any questions, please ask me, i
will forward them for you ! - also the patch is a bit more than it
actually needs ... so please dont blame me on that ;) - this is another
reason why we haven't submitted it yet!

have fun & a big thank for LCDproc,
mexx.


--=-0/pqPTUEPeogM++o9aDy
Content-Disposition: attachment; filename=lcdproc-0.5.0_menu_enter_quit.patch
Content-Type: text/x-patch; name=lcdproc-0.5.0_menu_enter_quit.patch; charset=us-ascii
Content-Transfer-Encoding: 7bit

diff -ur LCDproc_orig/server/commands/command_list.c LCDproc_work/server/commands/command_list.c
--- LCDproc_orig/server/commands/command_list.c	2005-06-28 18:00:07.000000000 +0200
+++ LCDproc_work/server/commands/command_list.c	2007-02-19 12:31:33.000000000 +0100
@@ -28,31 +28,33 @@
 #include <string.h>
 
 static client_function commands[] = {
-	{ "test_func",      test_func_func      },
-	{ "hello",          hello_func          },
-	{ "client_set",     client_set_func     },
-	{ "client_add_key", client_add_key_func },
-	{ "client_del_key", client_del_key_func },
-/*	{ "screen_add_key", screen_add_key_func }, */
-/*	{ "screen_del_key", screen_del_key_func }, */
-	{ "screen_add",     screen_add_func     },
-	{ "screen_del",     screen_del_func     },
-	{ "screen_set",     screen_set_func     },
-	{ "widget_add",     widget_add_func     },
-	{ "widget_del",     widget_del_func     },
-	{ "widget_set",     widget_set_func     },
-	{ "menu_add_item",  menu_add_item_func  },
-	{ "menu_del_item",  menu_del_item_func  },
-	{ "menu_set_item",  menu_set_item_func  },
-	{ "menu_goto",      menu_goto_func      },
-	{ "menu_set_main",  menu_set_main_func  },
+	{ "test_func",        test_func_func      },
+	{ "hello",            hello_func          },
+	{ "client_set",       client_set_func     },
+	{ "client_add_key",   client_add_key_func },
+	{ "client_del_key",   client_del_key_func },
+/*	{ "screen_add_key",   screen_add_key_func }, */
+/*	{ "screen_del_key",   screen_del_key_func }, */
+	{ "screen_add",       screen_add_func     },
+	{ "screen_del",       screen_del_func     },
+	{ "screen_set",       screen_set_func     },
+	{ "widget_add",       widget_add_func     },
+	{ "widget_del",       widget_del_func     },
+	{ "widget_set",       widget_set_func     },
+	{ "menu_add_item",    menu_add_item_func  },
+	{ "menu_del_item",    menu_del_item_func  },
+	{ "menu_set_item",    menu_set_item_func  },
+	{ "menu_goto",        menu_goto_func      },
+	{ "menu_set_main",    menu_set_main_func  },
+	{ "menusystem_quit",  menusystem_quit     },
+	{ "menusystem_enter", menusystem_enter    },
 	/* Misc stuff...*/
-	{ "backlight",      backlight_func      },
-	{ "output",         output_func         },
-	{ "noop",           noop_func           },
-	{ "info",           info_func           },
-	{ "sleep",          sleep_func          },
-	{ NULL,             NULL},
+	{ "backlight",        backlight_func      },
+	{ "output",           output_func         },
+	{ "noop",             noop_func           },
+	{ "info",             info_func           },
+	{ "sleep",            sleep_func          },
+	{ NULL,               NULL},
 };
 
 
diff -ur LCDproc_orig/server/commands/menu_commands.c LCDproc_work/server/commands/menu_commands.c
--- LCDproc_orig/server/commands/menu_commands.c	2005-07-22 19:47:29.000000000 +0200
+++ LCDproc_work/server/commands/menu_commands.c	2007-02-19 12:33:22.000000000 +0100
@@ -754,7 +754,48 @@
 	sock_send_string(c->sock, "success\n");
 	return 0;
 }
+int 
+menusystem_quit(Client * c, int argc, char **argv)
+{
+	menuscreen_goto(NULL);
+	sock_send_string(c->sock, "success\n");
+	return 0;
+}
+int 
+menusystem_enter(Client * c, int argc, char **argv)
+{
+	char * menu_id;
+	Menu * menu;
+
+	debug (RPT_DEBUG, "%s( Client [%d], %s, %s )",
+	       __FUNCTION__, c->sock, (argc > 1 ? argv[1] : "<null>"));
+	if (!c->ack)
+		return 1;
+
+	if ((argc < 1 )) {
+		sock_send_error(c->sock, "Usage: menusystem_enter <menuid> [<predecessor_id>]\n");
+		return 0;
+	}
 
+	menu_id = argv[1];
+
+	if ( menu_id[0] == 0 ) {
+		/* No menu specified = client's main menu */
+		menu = c->menu;
+	} else {
+		/* A specified menu */
+		menu = menuitem_search(menu_id, c);
+	}
+
+	if (!menu) {
+		sock_send_error(c->sock, "Cannot find menu id\n");
+		return 0;
+	}
+	menuscreen_goto (menu);
+	/* Failure is not returned (Robijn) */
+	sock_send_string(c->sock, "success\n");
+	return 0;
+}
 /** Sets the predecessor of a Menuitem item to itemid (for wizzards)
  * i.e. the menuitem to go to after hitting "Enter" on item.
  *
Nur in LCDproc_work/server/commands: menu_commands.c~.
diff -ur LCDproc_orig/server/commands/menu_commands.h LCDproc_work/server/commands/menu_commands.h
--- LCDproc_orig/server/commands/menu_commands.h	2005-05-20 11:43:22.000000000 +0200
+++ LCDproc_work/server/commands/menu_commands.h	2007-02-19 12:31:33.000000000 +0100
@@ -18,6 +18,8 @@
 int menu_set_item_func (Client * c, int argc, char **argv);
 int menu_goto_func (Client * c, int argc, char **argv);
 int menu_set_main_func (Client * c, int argc, char **argv);
+int menusystem_quit(Client * c, int argc, char **argv);
+int menusystem_enter(Client * c, int argc, char **argv);
 
 #endif
 

--=-0/pqPTUEPeogM++o9aDy--