예제 #1
0
bool WeatherPlugin::done(unsigned code, Buffer &data, const char*)
{
    if (code != 200)
        return false;
    m_data  = "";
    m_day   = 0;
    m_bBar  = false;
    m_bWind = false;
    m_bUv	= false;
    m_bCC	= false;
    m_bMoon	= false;
    reset();
    if (!parse(data.data(), data.size(), false)){
        log(L_WARN, "XML parse error");
        return false;
    }
    time_t now = time(NULL);
    setTime(now);
    if (m_bForecast)
        setForecastTime(now);
    updateButton();
    Event eUpdate(EventWeather);
    eUpdate.process();
    return false;
}
예제 #2
0
bool WeatherPlugin::done(unsigned code, Buffer &data, const char*)
{
    if (code != 200)
        return false;
    m_data  = "";
    m_day   = 0;
    m_bBar  = false;
    m_bWind = false;
    m_bUv	= false;
    m_bCC	= false;
    m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
    if (xmlParseChunk(m_context, data.data(), data.size(), 0)){
        log(L_WARN, "XML parse error");
        xmlFreeParserCtxt(m_context);
        return false;
    }
    xmlFreeParserCtxt(m_context);
    time_t now;
    time(&now);
    setTime(now);
	if (m_bForecast)
		setForecastTime(now);
    updateButton();
    Event eUpdate(EventWeather);
    eUpdate.process();
    return false;
}
예제 #3
0
void *WeatherPlugin::processEvent(Event *e)
{
    if (e->type() == EventLanguageChanged)
        updateButton();
    if (e->type() == EventInit)
        showBar();
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->id == CmdWeather) && *getID()){
            string url = "http://www.weather.com/outlook/travel/pastweather/";
            url += getID();
            Event eGo(EventGoURL, (void*)url.c_str());
            eGo.process();
            return e->param();
        }
    }
    if (e->type() == EventFetchDone){
        fetchData *d = (fetchData*)(e->param());
        if (d->req_id != m_fetch_id)
            return NULL;
        m_fetch_id = 0;
        if (d->result != 200)
            return NULL;
        m_data  = "";
		m_day   = 0;
        m_bBar  = false;
        m_bWind = false;
        m_bUv	= false;
		m_bCC	= false;
        m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
        if (xmlParseChunk(m_context, d->data->data(), d->data->size(), 0)){
            log(L_WARN, "XML parse error");
            xmlFreeParserCtxt(m_context);
            return NULL;
        }
        xmlFreeParserCtxt(m_context);
        time_t now;
        time(&now);
        setTime(now);
        updateButton();
        Event eUpdate(EventWeather);
        eUpdate.process();
    }
    return NULL;
}
예제 #4
0
void *WeatherPlugin::processEvent(Event *e)
{
	if (e->type() == EventLanguageChanged)
		updateButton();
    if (e->type() == EventInit)
        showBar();
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->id == CmdWeather) && *getURL()){
            Event eGo(EventGoURL, (void*)getURL());
            eGo.process();
            return e->param();
        }
    }
    if (e->type() == EventFetchDone){
        fetchData *d = (fetchData*)(e->param());
        if (d->req_id != m_fetch_id)
            return NULL;
        m_fetch_id = 0;
        if (d->result != 200)
            return NULL;
        WeatherParser p(*d->data);
        setStr(p.m_updated.c_str(), data.Updated);
        setStr(p.m_location.c_str(), data.Location);
        setLong(p.m_temperature_f.c_str(), data.Temperature_f);
        setLong(p.m_temperature_c.c_str(), data.Temperature_c);
        setLong(p.m_humidity.c_str(), data.Humidity);
        setLong(p.m_pressure_in.c_str(), data.Pressure_in);
        setLong(p.m_pressure_hpa.c_str(), data.Pressure_hpa);
        setStr(p.m_conditions.c_str(), data.Conditions);
        setStr(p.m_wind.c_str(), data.Wind);
        setLong(p.m_wind_speed_mph.c_str(), data.Wind_speed_mph);
        setLong(p.m_wind_speed_km.c_str(), data.Wind_speed_km);
        setStr(p.m_sun_raise.c_str(), data.Sun_raise);
        setStr(p.m_sun_set.c_str(), data.Sun_set);
        QString condition = getConditions();
        condition = condition.lower();
        if (condition.find("fog") >= 0)
            condition = "Fog";
        if (condition.find("overcast") >= 0)
            condition = "Overcast";
        if (condition.find("mist") >= 0)
            condition = "Fog";
        if (condition.find("storm") >= 0)
            condition = "Storm";
        if (condition.find("rain") >= 0)
            condition = "Rain";
        if (condition.find("snow") >= 0)
            condition = "Snow";
        if (condition.find("clear") >= 0)
            condition = "Clear";
        if (condition.find("cloudy") >= 0){
            if (condition.find("part") >= 0){
                condition = "Partial cloudy";
            }else{
                condition = "Cloudy";
            }
        }
        if (condition.find("clouds") >= 0)
            condition = "Partial cloudy";
        setConditions(condition.latin1());
        time_t now;
        time(&now);
        setTime(now);
        updateButton();
        Event eUpdate(EventWeather);
        eUpdate.process();
    }
    return NULL;
}