예제 #1
0
void
menuscreen_create_menu(void)
{
	Menu *options_menu;
	Menu *driver_menu;
	MenuItem *checkbox;
	MenuItem *slider;
	Driver *driver;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	main_menu = menu_create("mainmenu", NULL, "LCDproc Menu", NULL);
	if (main_menu == NULL) {
		report(RPT_ERR, "%s: Cannot create main menu", __FUNCTION__);
		return;
	}

	options_menu = menu_create("options", NULL, "Options", NULL);
	if (options_menu == NULL) {
		report(RPT_ERR, "%s: Cannot create options menu", __FUNCTION__);
		return;
	}
	menu_add_item(main_menu, options_menu);

#ifdef LCDPROC_TESTMENUS
	/*
	 * TODO: Menu items in the screens menu currently have no functions
	 * assigned. Therefore only enable the menu for testing. If functions
	 * are available, this code should be outside the #ifdef.
	 */
	screens_menu = menu_create("screens", NULL, "Screens", NULL);
	if (screens_menu == NULL) {
		report(RPT_ERR, "%s: Cannot create screens menu", __FUNCTION__);
		return;
	}
	menu_add_item(main_menu, screens_menu);

	menuscreen_create_testmenu();
#endif

	/*
	 * add option menu contents: menu's client is NULL since we're in the
	 * server
	 */
	checkbox = menuitem_create_checkbox("heartbeat", heartbeat_handler, "Heartbeat", NULL, true, heartbeat);
	menu_add_item(options_menu, checkbox);

	checkbox = menuitem_create_checkbox("backlight", backlight_handler, "Backlight", NULL, true, backlight);
	menu_add_item(options_menu, checkbox);

	slider = menuitem_create_slider("titlespeed", titlespeed_handler,
					"TitleSpeed", NULL, "0", "10", TITLESPEED_NO, TITLESPEED_MAX, 1, titlespeed);
	menu_add_item(options_menu, slider);

	/*
	 * add driver specific option menus for each driver: menu's client is
	 * NULL since we're in the server
	 */
	for (driver = drivers_getfirst(); driver; driver = drivers_getnext()) {
		int contrast_avail = (driver->get_contrast && driver->set_contrast) ? 1 : 0;
		int brightness_avail = (driver->get_brightness && driver->set_brightness) ? 1 : 0;

		if (contrast_avail || brightness_avail) {
			/* menu's client is NULL since we're in the server */
			driver_menu = menu_create(driver->name, NULL, driver->name, NULL);
			if (driver_menu == NULL) {
				report(RPT_ERR, "%s: Cannot create menu for driver %s",
				       __FUNCTION__, driver->name);
				continue;
			}
			menu_set_association(driver_menu, driver);
			menu_add_item(options_menu, driver_menu);
			if (contrast_avail) {
				int contrast = driver->get_contrast(driver);

				/* menu's client is NULL since we're in the server */
				slider = menuitem_create_slider("contrast", contrast_handler, "Contrast",
								NULL, "min", "max", 0, 1000, 25, contrast);
				menu_add_item(driver_menu, slider);
			}
			if (brightness_avail) {
				int onbrightness = driver->get_brightness(driver, BACKLIGHT_ON);
				int offbrightness = driver->get_brightness(driver, BACKLIGHT_OFF);

				slider = menuitem_create_slider("onbrightness", brightness_handler, "On Brightness",
								NULL, "min", "max", 0, 1000, 25, onbrightness);
				menu_add_item(driver_menu, slider);

				slider = menuitem_create_slider("offbrightness", brightness_handler, "Off Brightness",
								NULL, "min", "max", 0, 1000, 25, offbrightness);
				menu_add_item(driver_menu, slider);
			}
		}
	}
}
예제 #2
0
void
menuscreen_create_testmenu(void)
{
	MenuItem *test_item;
	Menu *test_menu;

	char testiso[] = {
		'D', 'e', 'm', 'o', '\t',
		/* #160 */
		160, 161, 162, 163, 164, 165, 166, 167, '\t',
		168, 169, 170, 171, 172, 173, 174, 175, '\t',
		176, 177, 178, 179, 180, 181, 182, 183, '\t',
		184, 185, 186, 187, 188, 189, 190, 191, '\t',
		/* #192 */
		192, 193, 194, 195, 196, 197, 198, 199, '\t',
		200, 201, 202, 203, 204, 205, 206, 207, '\t',
		208, 209, 210, 211, 212, 213, 214, 215, '\t',
		216, 217, 218, 219, 220, 221, 222, 223, '\t',
		/* #224 */
		224, 225, 226, 227, 228, 229, 230, 231, '\t',
		232, 233, 234, 235, 236, 237, 238, 239, '\t',
		240, 241, 242, 243, 244, 245, 246, 247, '\t',
		248, 249, 250, 251, 252, 253, 254, 255, '\0'
	};

	test_menu = menu_create("test", NULL, "Test menu", NULL);
	if (test_menu == NULL) {
		report(RPT_ERR, "%s: Cannot create test menu", __FUNCTION__);
		return;
	}
	menu_add_item(main_menu, test_menu);

	/* menu's client is NULL since we're in the server */
	test_item = menuitem_create_action("", NULL, "Action", NULL, MENURESULT_NONE);
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_action("", NULL, "Action,closing", NULL, MENURESULT_CLOSE);
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_action("", NULL, "Action,quitting", NULL, MENURESULT_QUIT);
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_checkbox("", NULL, "Checkbox", NULL, false, false);
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_checkbox("", NULL, "Checkbox, gray", NULL, true, false);
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_ring("", NULL, "Ring", NULL, "ABC\tDEF\t01234567890\tOr a very long string that will not fit on any display", 1);
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_slider("", NULL, "Slider", NULL, "mintext", "maxtext", -20, 20, 1, 0);
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_slider("", NULL, "Slider,step=5", NULL, "mintext", "maxtext", -20, 20, 5, 0);
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_numeric("", NULL, "Numeric", NULL, 1, 365, 15);
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_numeric("", NULL, "Numeric,signed", NULL, -20, +20, 15);
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_alpha("", NULL, "Alpha", NULL, 0, 3, 14, true, true, true, ".-+@", "LCDproc-v0.5.7");
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_alpha("", NULL, "Alpha, caps only", NULL, 0, 3, 12, true, false, false, "-", "LCDPROC");
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_ip("", NULL, "IPv4", NULL, false, "192.168.1.245");
	menu_add_item(test_menu, test_item);
	test_item = menuitem_create_ip("", NULL, "IPv6", NULL, true, "1080:0:0:0:8:800:200C:417A");
	menu_add_item(test_menu, test_item);

	test_item = menuitem_create_ring("", NULL, "Charset", NULL, testiso, 0);
	menu_add_item(test_menu, test_item);
}
예제 #3
0
/*************************************************************************
 * menu_add_item_func
 *
 * Adds an item to a menu
 *
 * Usage: menu_add_item <menuid> <newitemid> <type> [<text>]
 * You should use "" as id for the client's main menu. This menu will be
 * created automatically when you add an item to it the first time.
 * You (currently?) cannot create a menu in the main level yourself.
 * The names you use for items should be unique for your client.
 * The text is the visible text for the item.
 *
 * The following types are available:
 * - menu
 * - action
 * - checkbox
 * - ring (a kind of listbox of one line)
 * - slider
 * - numeric
 * - alpha
 * - ip
 */
int
menu_add_item_func (Client * c, int argc, char **argv)
{
	char * menu_id;
	char * item_id;
	char * text = NULL;
	Menu * menu = NULL;
	MenuItem * item;
	MenuItemType itemtype;
	char** argv_set = NULL;

	debug (RPT_DEBUG, "%s( Client [%d], %s, %s )",
	       __FUNCTION__, c->sock, argv[1], argv[2]);
	if (!c->ack)
		return 1;

	if (!c->name) {
		sock_send_error(c->sock, "You need to give your client a name first\n");
		return 0;
	}

	if ((argc < 4 )) {
		sock_send_error(c->sock, "Usage: menu_add_item <menuid> <newitemid> <type> [<text>]\n");
		return 0;
	}

	menu_id = argv[1];
	item_id = argv[2];

	/* Does the client have a menu already ? */
	if (!c->menu) {
		/* We need to create it */
		report( RPT_INFO, "Client [%d] is using the menu", c->sock );
		c->menu = menu_create ("_client_menu_", menu_commands_handler, c->name, c);
		menu_add_item (main_menu, c->menu);
	}

	if ( menu_id[0] == 0 ) {
		/* No menu specified = client's main menu */
		menu = c->menu;
	} else {
		/* A specified menu */
		menu = menu_find_item (c->menu, menu_id, true);
	}
	if (!menu) {
		sock_send_error(c->sock, "Cannot find menu id\n");
		return 0;
	}

	item = menu_find_item (c->menu, item_id, true);
	if (item) {
		sock_send_error(c->sock, "Item id already in use\n");
		return 0;
	}

	/* Find menuitem type */
	itemtype = menuitem_typename_to_type (argv[3]);
	if (itemtype == -1) {
		sock_send_error(c->sock, "Invalid menuitem type\n");
		return 0;
	}

	/* Is a text given (options don't count)? */
	if (argc >= 5 && argv[4][0] != '-') {
		text = argv[4];
	}
	else {
		text = "";
	}

	/* Create the menuitem */
	switch (itemtype) {
	  case MENUITEM_MENU:
		item = menu_create (item_id, menu_commands_handler, text, c);
		break;
	  case MENUITEM_ACTION:
		item = menuitem_create_action (item_id, menu_commands_handler, text, c,
				MENURESULT_NONE);
		break;
	  case MENUITEM_CHECKBOX:
		item = menuitem_create_checkbox (item_id, menu_commands_handler, text, c,
				false, false);
		break;
	  case MENUITEM_RING:
		item = menuitem_create_ring (item_id, menu_commands_handler, text, c,
				"", 0);
		break;
	  case MENUITEM_SLIDER:
		item = menuitem_create_slider (item_id, menu_commands_handler, text, c,
				 "", "", 0, 100, 1, 25);
		break;
	  case MENUITEM_NUMERIC:
		item = menuitem_create_numeric (item_id, menu_commands_handler, text, c,
				0, 100, 0);
		break;
	  case MENUITEM_ALPHA:
		item = menuitem_create_alpha (item_id, menu_commands_handler, text, c,
				0, 0, 10, true, false, true, "-./", "");
		break;
	  case MENUITEM_IP:
		item = menuitem_create_ip (item_id, menu_commands_handler, text, c,
				0, "192.168.1.245");
		break;
	 default:
	   assert(!"unexpected menuitem type");
	}
	menu_add_item (menu, item);
	menuscreen_inform_item_modified (menu);
	sock_send_string(c->sock, "success\n");

	/* are there any options (starting with '-')?
	 * - create a temporary argv for menu_set_item() call */
	if (argc > 5 || argv[4][0] == '-') {
		// menu_add_item <menuid> <newitemid> <type> [<text>]
		// menu_set_item <menuid> <itemid> {<option>}+
		int i, j;
		argv_set = malloc(argc * sizeof(char*));
		assert(argv_set);
		argv_set[0] = "menu_set_item";
		for (i = j = 1; i < argc; ++i)
		{
			/* skip "type" */
			if (i == 3)
				continue;
			/* skip "text" */
			if (i == 4 && argv[4][0] != '-')
				continue;

			argv_set[j++] = argv[i];
		}
		menu_set_item_func(c, j, argv_set);
		free(argv_set);
	}
	return 0;
}