Exemplo n.º 1
0
void
menuscreen_add_screen(Screen *s)
{
	Menu *m;
	MenuItem *mi;

	debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__,
	      ((s != NULL) ? s->id : "(null)"));

	/* screens have not been created or no screen given ... */
	if ((screens_menu == NULL) || (s == NULL))
		return;

	/* Create a menu entry for the screen */
	m = menu_create(s->id, NULL, ((s->name != NULL) ? s->name : s->id), s->client);
	if (m == NULL) {
		report(RPT_ERR, "%s: Cannot create menu", __FUNCTION__);
		return;
	}
	menu_set_association(m, s);
	menu_add_item(screens_menu, m);

	/* And add some items for it... */
	mi = menuitem_create_action("", NULL, "(don't work yet)", s->client, MENURESULT_NONE);
	menu_add_item(m, mi);

	mi = menuitem_create_action("", NULL, "To Front", s->client, MENURESULT_QUIT);
	menu_add_item(m, mi);

	mi = menuitem_create_checkbox("", NULL, "Visible", s->client, false, true);
	menu_add_item(m, mi);

	mi = menuitem_create_numeric("", NULL, "Duration", s->client, 2, 3600, s->duration);
	menu_add_item(m, mi);

	mi = menuitem_create_ring("", NULL, "Priority", s->client,
	       "Hidden\tBackground\tForeground\tAlert\tInput", s->priority);
	menu_add_item(m, mi);
}
Exemplo n.º 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);
}
Exemplo n.º 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;
}