void CBEChannelWidget::paintDetails(int index)
{
	char buf[128] = {0};
	int len = 0;

	transponder_id_t ct = (*Channels)[index]->getTransponderId();
	transponder_list_t::iterator tpI = transponders.find(ct);
	sat_iterator_t sit = satellitePositions.find((*Channels)[index]->getSatellitePosition());

	len = snprintf(buf, sizeof(buf), "%d ", (*Channels)[index]->getFreqId());

	if(tpI != transponders.end()) {
		char * f, *s, *m;
		switch(CFrontend::getInstance()->getInfo()->type)
		{
			case FE_QPSK:
				CFrontend::getInstance()->getDelSys(tpI->second.feparams.u.qpsk.fec_inner, dvbs_get_modulation(tpI->second.feparams.u.qpsk.fec_inner),  f, s, m);
				len += snprintf(&buf[len], sizeof(buf) - len, "%c %d %s %s %s ", tpI->second.polarization ? 'V' : 'H', tpI->second.feparams.u.qpsk.symbol_rate/1000, f, s, m);
				break;
			case FE_QAM:
				CFrontend::getInstance()->getDelSys(tpI->second.feparams.u.qam.fec_inner, tpI->second.feparams.u.qam.modulation, f, s, m);
				len += snprintf(&buf[len], sizeof(buf) - len, "%d %s %s %s ", tpI->second.feparams.u.qam.symbol_rate/1000, f, s, m);
				break;
			case FE_OFDM:
			case FE_ATSC:
				break;
		}
	}

	if((*Channels)[index]->pname) {
		snprintf(&buf[len], sizeof(buf) - len, "(%s)", (*Channels)[index]->pname);
	}
	else {
		if(sit != satellitePositions.end()) {
			snprintf(&buf[len], sizeof(buf) - len, "(%s)", sit->second.name.c_str());
		}
	}

	if(sit != satellitePositions.end()) {
		g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST]->RenderString(x+ 10, y+ height+ 5+ fheight, width - 30,  sit->second.name.c_str(), COL_MENUCONTENTDARK, 0, true);
	}
	g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST]->RenderString(x+ 10, y+ height+ 5+ 2*fheight, width - 30, buf, COL_MENUCONTENTDARK, 0, true);
}
bool CFrontend::buildProperties(const FrontendParameters *feparams, struct dtv_properties& cmdseq)
{
	fe_delivery_system delsys = SYS_DVBS;
	fe_modulation_t modulation = QPSK;
	fe_rolloff_t rolloff = ROLLOFF_35;
	fe_pilot_t pilot = PILOT_OFF;
	int fec;
	fe_code_rate_t fec_inner;

	/* Decode the needed settings */
	switch (info.type) {
	case FE_QPSK:
		fec_inner = feparams->dvb_feparams.u.qpsk.fec_inner;
		delsys = dvbs_get_delsys(fec_inner);
		modulation = dvbs_get_modulation(fec_inner);
		rolloff = dvbs_get_rolloff(delsys);
		break;
	case FE_QAM:
		fec_inner = feparams->dvb_feparams.u.qam.fec_inner;
		modulation = feparams->dvb_feparams.u.qam.modulation;
		delsys = SYS_DVBC_ANNEX_AC;
		break;
	case FE_OFDM:
		fec_inner = FEC_AUTO; /* dummy, for next switch statement */
		modulation = feparams->dvb_feparams.u.ofdm.constellation;
		delsys = SYS_DVBT;
		break;
	default:
		INFO("unknown frontend type %d, exiting", (int)info.type);
		return 0;
	}

	/* cast to int is ncesessary because many of the FEC_S2 values are not
	 * properly defined in the enum, thus the compiler complains... :-( */
	switch ((int)fec_inner) {
	case FEC_1_2:
	case FEC_S2_QPSK_1_2:
	case FEC_S2_8PSK_1_2:
		fec = FEC_1_2;
		break;
	case FEC_2_3:
	case FEC_S2_QPSK_2_3:
	case FEC_S2_8PSK_2_3:
		fec = FEC_2_3;
		if (modulation == PSK_8)
			pilot = PILOT_ON;
		break;
	case FEC_3_4:
	case FEC_S2_QPSK_3_4:
	case FEC_S2_8PSK_3_4:
		fec = FEC_3_4;
		if (modulation == PSK_8)
			pilot = PILOT_ON;
		break;
	case FEC_S2_QPSK_3_5:
	case FEC_S2_8PSK_3_5:
		fec = FEC_3_5;
		if (modulation == PSK_8)
			pilot = PILOT_ON;
		break;
	case FEC_4_5:
	case FEC_S2_QPSK_4_5:
	case FEC_S2_8PSK_4_5:
		fec = FEC_4_5;
		break;
	case FEC_5_6:
	case FEC_S2_QPSK_5_6:
	case FEC_S2_8PSK_5_6:
		fec = FEC_5_6;
		if (modulation == PSK_8)
			pilot = PILOT_ON;
		break;
	case FEC_6_7:
		fec = FEC_6_7;
		break;
	case FEC_7_8:
	case FEC_S2_QPSK_7_8:
	case FEC_S2_8PSK_7_8:
		fec = FEC_7_8;
		break;
	case FEC_8_9:
	case FEC_S2_QPSK_8_9:
	case FEC_S2_8PSK_8_9:
		fec = FEC_8_9;
		break;
	case FEC_S2_QPSK_9_10:
	case FEC_S2_8PSK_9_10:
		fec = FEC_9_10;
		break;
	default:
		INFO("[fe%d] unknown FEC: %d", fenumber, fec_inner);
	case FEC_AUTO:
	case FEC_S2_AUTO:
		fec = FEC_AUTO;
		break;
	}

	int nrOfProps	= 0;

	switch (info.type) {
	case FE_QPSK:
		if (delsys == SYS_DVBS2) {
			nrOfProps	= FE_DVBS2_PROPS;
			memcpy(cmdseq.props, dvbs2_cmdargs, sizeof(dvbs2_cmdargs));

			cmdseq.props[MODULATION].u.data	= modulation;
			cmdseq.props[ROLLOFF].u.data	= rolloff;
			cmdseq.props[PILOTS].u.data	= pilot;
			
		} else {
			memcpy(cmdseq.props, dvbs_cmdargs, sizeof(dvbs_cmdargs));
			nrOfProps	= FE_DVBS_PROPS;
		}
		cmdseq.props[FREQUENCY].u.data	= feparams->dvb_feparams.frequency;
		cmdseq.props[SYMBOL_RATE].u.data= feparams->dvb_feparams.u.qpsk.symbol_rate;
		cmdseq.props[INNER_FEC].u.data	= fec; /*_inner*/ ;
		break;
	case FE_QAM:
		memcpy(cmdseq.props, dvbc_cmdargs, sizeof(dvbc_cmdargs));
		cmdseq.props[FREQUENCY].u.data	= feparams->dvb_feparams.frequency;
		cmdseq.props[MODULATION].u.data	= modulation;
		cmdseq.props[SYMBOL_RATE].u.data= feparams->dvb_feparams.u.qam.symbol_rate;
		cmdseq.props[INNER_FEC].u.data	= fec_inner;
		nrOfProps			= FE_DVBC_PROPS;
		break;
	case FE_OFDM:
		memcpy(cmdseq.props, dvbt_cmdargs, sizeof(dvbt_cmdargs));
		nrOfProps				= FE_DVBT_PROPS;
		cmdseq.props[FREQUENCY].u.data		= feparams->dvb_feparams.frequency;
		cmdseq.props[MODULATION].u.data		= modulation;
		cmdseq.props[INVERSION].u.data		= feparams->dvb_feparams.inversion;
		cmdseq.props[CODE_RATE_HP].u.data	= feparams->dvb_feparams.u.ofdm.code_rate_HP;
		cmdseq.props[CODE_RATE_LP].u.data	= feparams->dvb_feparams.u.ofdm.code_rate_LP;
		cmdseq.props[TRANSMISSION_MODE].u.data	= feparams->dvb_feparams.u.ofdm.transmission_mode;
		cmdseq.props[GUARD_INTERVAL].u.data	= feparams->dvb_feparams.u.ofdm.guard_interval;
		cmdseq.props[HIERARCHY].u.data		= feparams->dvb_feparams.u.ofdm.hierarchy_information;
		switch (feparams->dvb_feparams.u.ofdm.bandwidth) {
		case BANDWIDTH_6_MHZ:
			cmdseq.props[BANDWIDTH].u.data	= 6000000;
			break;
		case BANDWIDTH_7_MHZ:
			cmdseq.props[BANDWIDTH].u.data	= 7000000;
			break;
		case BANDWIDTH_8_MHZ:
			cmdseq.props[BANDWIDTH].u.data	= 8000000;
			break;
		default:
			INFO("[fe%d] unknown OFDM bandwidth %d",
				fenumber, feparams->dvb_feparams.u.ofdm.bandwidth);
			/* fallthrough */
		case BANDWIDTH_AUTO:
			cmdseq.props[BANDWIDTH].u.data	= 0;
			break;
		}
		break;
	default:
		INFO("unknown frontend type, exiting");
		return false;
	}


	if (config.diseqcType == DISEQC_UNICABLE)
		cmdseq.props[FREQUENCY].u.data = sendEN50494TuningCommand(feparams->dvb_feparams.frequency,
							currentToneMode == SEC_TONE_ON,
							currentVoltage == SEC_VOLTAGE_18,
							!!config.uni_lnb);

	cmdseq.num	+= nrOfProps;

	return true;
}
int CTPSelectHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
    transponder_list_t::iterator tI;
    sat_iterator_t sit;
    t_satellite_position position = 0;
    std::map<int, transponder> tmplist;
    std::map<int, transponder>::iterator tmpI;
    int i;
    char cnt[5];
    int select = -1;
    static int old_selected = 0;
    static t_satellite_position old_position = 0;

    if (parent)
        parent->hide();

    //loop throught satpos
    for(sit = satellitePositions.begin(); sit != satellitePositions.end(); sit++)
    {
        if(!strcmp(sit->second.name.c_str(), CNeutrinoApp::getInstance()->getScanSettings().satNameNoDiseqc))
        {
            position = sit->first;
            break;
        }
    }

    if(old_position != position)
    {
        old_selected = 0;
        old_position = position;
    }

    printf("CTPSelectHandler::exec: fe(%d) %s position(%d)\n", feindex, CNeutrinoApp::getInstance()->getScanSettings().satNameNoDiseqc, position);

    CMenuWidget * menu = new CMenuWidget(LOCALE_SCANTS_SELECT_TP, NEUTRINO_ICON_SETTINGS);
    CMenuSelectorTarget * selector = new CMenuSelectorTarget(&select);

    // intros
    //menu->addItem(GenericMenuSeparator);

    i = 0;

    for(tI = select_transponders.begin(); tI != select_transponders.end(); tI++)
    {
        t_satellite_position satpos = GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xFFF;
        if(GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xF000)
            satpos = -satpos;

        if(satpos != position)
            continue;

        char buf[128];
        sprintf(cnt, "%d", i);
        char * f, *s, *m;

        switch(CFrontend::getInstance(feindex)->getInfo()->type)
        {
        case FE_QPSK:
        {
            CFrontend::getInstance(feindex)->getDelSys(tI->second.feparams.u.qpsk.fec_inner, dvbs_get_modulation(tI->second.feparams.u.qpsk.fec_inner),  f, s, m);

            snprintf(buf, sizeof(buf), "%d %c %d %s %s %s ", tI->second.feparams.frequency/1000, tI->second.polarization ? 'V' : 'H', tI->second.feparams.u.qpsk.symbol_rate/1000, f, s, m);
        }
        break;

        case FE_QAM:
        {
            CFrontend::getInstance(feindex)->getDelSys(tI->second.feparams.u.qam.fec_inner, tI->second.feparams.u.qam.modulation, f, s, m);

            snprintf(buf, sizeof(buf), "%d %d %s %s %s ", tI->second.feparams.frequency/1000, tI->second.feparams.u.qam.symbol_rate/1000, f, s, m);
        }
        break;

        case FE_OFDM:
        {
            CFrontend::getInstance(feindex)->getDelSys(tI->second.feparams.u.ofdm.code_rate_HP, tI->second.feparams.u.ofdm.constellation, f, s, m);

            snprintf(buf, sizeof(buf), "%d %s %s %s ", tI->second.feparams.frequency/1000, f, s, m);
        }
        break;

        case FE_ATSC:
            break;
        }

        menu->addItem(new CMenuForwarderNonLocalized(buf, true, NULL, selector, cnt), old_selected == i);
        tmplist.insert(std::pair <int, transponder>(i, tI->second));
        i++;
    }

    int retval = menu->exec(NULL, "");
    delete menu;
    delete selector;

    if(select >= 0)
    {
        old_selected = select;

        tmpI = tmplist.find(select);
        //printf("CTPSelectHandler::exec: selected TP: freq %d pol %d SR %d\n", tmpI->second.feparams.frequency, tmpI->second.polarization, tmpI->second.feparams.u.qpsk.symbol_rate);

        sprintf(get_set.TP_freq, "%d", tmpI->second.feparams.frequency);

        switch(CFrontend::getInstance(feindex)->getInfo()->type)
        {
        case FE_QPSK:
            printf("CTPSelectHandler::exec: fe(%d) selected TP: freq %d pol %d SR %d fec %d\n", feindex, tmpI->second.feparams.frequency, tmpI->second.polarization, tmpI->second.feparams.u.qpsk.symbol_rate, tmpI->second.feparams.u.qpsk.fec_inner);

            sprintf(get_set.TP_rate, "%d", tmpI->second.feparams.u.qpsk.symbol_rate);
            get_set.TP_fec = tmpI->second.feparams.u.qpsk.fec_inner;
            get_set.TP_pol = tmpI->second.polarization;
            break;

        case FE_QAM:
            printf("CTPSelectHandler::exec: fe(%d) selected TP: freq %d SR %d fec %d mod %d\n", feindex, tmpI->second.feparams.frequency, tmpI->second.feparams.u.qpsk.symbol_rate, tmpI->second.feparams.u.qam.fec_inner, tmpI->second.feparams.u.qam.modulation);

            sprintf(get_set.TP_rate, "%d", tmpI->second.feparams.u.qam.symbol_rate);
            get_set.TP_fec = tmpI->second.feparams.u.qam.fec_inner;
            get_set.TP_mod = tmpI->second.feparams.u.qam.modulation;
            break;

        case FE_OFDM:
        {
            printf("CTPSelectHandler::exec: fe(%d) selected TP: freq %d band %d HP %d LP %d const %d trans %d guard %d hierarchy %d\n", feindex, tmpI->second.feparams.frequency, tmpI->second.feparams.u.ofdm.bandwidth, tmpI->second.feparams.u.ofdm.code_rate_HP, tmpI->second.feparams.u.ofdm.code_rate_LP, tmpI->second.feparams.u.ofdm.constellation, tmpI->second.feparams.u.ofdm.transmission_mode, tmpI->second.feparams.u.ofdm.guard_interval, tmpI->second.feparams.u.ofdm.hierarchy_information);

            get_set.TP_band = tmpI->second.feparams.u.ofdm.bandwidth;
            get_set.TP_HP = tmpI->second.feparams.u.ofdm.code_rate_HP;
            get_set.TP_LP = tmpI->second.feparams.u.ofdm.code_rate_LP;
            get_set.TP_const = tmpI->second.feparams.u.ofdm.constellation;
            get_set.TP_trans = tmpI->second.feparams.u.ofdm.transmission_mode;
            get_set.TP_guard = tmpI->second.feparams.u.ofdm.guard_interval;
            get_set.TP_hierarchy = tmpI->second.feparams.u.ofdm.hierarchy_information;
        }
        break;

        case FE_ATSC:
            break;
        }
    }

    if(retval == menu_return::RETURN_EXIT_ALL)
        return menu_return::RETURN_EXIT_ALL;

    return menu_return::RETURN_REPAINT;
}