示例#1
0
QString WeatherPlugin::forecastReplace(const QString &text)
{
    if (*getDay(m_day) == 0)
        return "";
    QString res = text;
    QString temp;
    int minT = atol(getMinT(m_day));
    int maxT = atol(getMaxT(m_day));
    temp += QString::number(minT);
    temp += QChar((unsigned short)176);
    temp += getUT();
    if ((strcmp(getMaxT(m_day), "N/A")) && (maxT != -255)) {
        temp += "/";
		temp += QString::number(maxT);
        temp += QChar((unsigned short)176);
        temp += getUT();
    }
    string dd = getDay(m_day);
    string mon = getToken(dd, ' ');
    QString day = dd.c_str();
    day += ". ";
    day += i18n(mon.c_str());
    res = res.replace(QRegExp("\\%n"), getDayIcon(m_day));
    res = res.replace(QRegExp("\\%t"), temp);
    res = res.replace(QRegExp("\\%c"), i18n_conditions(getDayConditions(m_day)));
    res = res.replace(QRegExp("\\%w"), i18n(getWDay(m_day)));
    res = res.replace(QRegExp("\\%d"), day);
    return res;
}
示例#2
0
void WeatherPlugin::updateButton()
{
    if ((getTime() == 0) || (m_bar == NULL))
        return;
    const char **xpm = xpms[getIcon()];
    if (xpm){
        IconDef icon;
        icon.name = "weather";
        icon.xpm  = xpm;
        Event eIcon(EventAddIcon, &icon);
        eIcon.process();
    }
    QString text = unquoteText(getButtonText());
    QString tip = getTipText();
    QString ftip = getForecastText();
    text = replace(text);
    tip  = replace(tip);
	if (getForecast())
		tip = QString("<table><tr><td>") + tip + "</td><td>";
	unsigned n = (getForecast() + 1) / 2;
	if (n < 3)
		n = getForecast();
	for (m_day = 1; m_day <= getForecast(); m_day++){
		tip += forecastReplace(ftip);
	    const char **xpm = xpms[atol(getDayIcon(m_day))];
		if (xpm){
			string url = "weather";
			url += number(m_day);
			IconDef icon;
			icon.name = url.c_str();
			icon.xpm  = xpm;
			Event eIcon(EventAddIcon, &icon);
			eIcon.process();
		}
		if (--n == 0){
			tip += "</td><td>";
			n = (getForecast() + 1) / 2;
		}
	}
	if (getForecast())
		tip += "</td></tr></table>";
	tip += "<br>\nWeather data provided by weather.com";
	tip += QChar((unsigned short)176);
    Command cmd;
    cmd->id		= CmdWeather;
    cmd->param	= m_bar;
    Event e(EventCommandWidget, cmd);
    CToolButton *btn = (CToolButton*)e.process();
    if (btn == NULL)
        return;
    btn->setTextLabel(text);
    btn->repaint();
    QToolTip::add(btn, tip);
}