Example #1
0
static void test_wlist(void *p)
{
	str_check(wlist("1,2,3"), "1,2,3");
	str_check(wlist(" 1 , \n 2 \t , \t3"), "1,2,3");
	str_check(wlist("  1 "), "1");
	str_check(wlist("  1 ,"), "1");
	str_check(wlist(",  1 "), "1");
	str_check(wlist("1  2"), "1  2");
	str_check(wlist("  "), "");
end:;
}
int CNetworkSetup::showWlanList()
{
	int   res = menu_return::RETURN_REPAINT;

	CHintBox hintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_NETWORKMENU_SSID_SCAN_WAIT));
	hintBox.paint();

	std::vector<wlan_network> networks;
	bool found = get_wlan_list(g_settings.ifname, networks);
	hintBox.hide();
	if (!found) {
		ShowMsg(LOCALE_MESSAGEBOX_ERROR, g_Locale->getText(LOCALE_NETWORKMENU_SSID_SCAN_ERROR), CMessageBox::mbrBack, CMessageBox::mbBack); // UTF-8
		return res;
	}

	CMenuWidget wlist(LOCALE_MAINSETTINGS_NETWORK, NEUTRINO_ICON_SETTINGS, width);
	wlist.addIntroItems(LOCALE_NETWORKMENU_SSID_SCAN); //intros

	char cnt[5];
	int select = -1;
	CMenuSelectorTarget * selector = new CMenuSelectorTarget(&select);

	std::string option[networks.size()];
	for (unsigned i = 0; i < networks.size(); ++i) {
		sprintf(cnt, "%d", i);
		
		option[i] = networks[i].qual;
		option[i] += ", ";
		option[i] += networks[i].channel;

		const char * icon = NULL;
		if (networks[i].encrypted)
			icon = NEUTRINO_ICON_LOCK;
		CMenuForwarder * net = new CMenuForwarder(networks[i].ssid.c_str(), true, option[i], selector, cnt, CRCInput::RC_nokey, NULL, icon);
		net->setItemButton(NEUTRINO_ICON_BUTTON_OKAY, true);
		wlist.addItem(net, networks[i].ssid == network_ssid);
	}
	res = wlist.exec(NULL, "");
	delete selector;

	printf("CNetworkSetup::showWlanList: selected: %d\n", select);
	if (select >= 0) {
		network_ssid = networks[select].ssid;
	}
	return res;
}