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; }
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(); } } return NULL; }
void *LiveJournalClient::processEvent(Event *e) { TCPClient::processEvent(e); if (e->type() == EventOpenMessage) { Message **msg = (Message**)(e->param()); if ((*msg)->type() != MessageUpdated) return NULL; if (dataName(&data.owner) != (*msg)->client()) return NULL; Event eDel(EventMessageDeleted, msg); eDel.process(); string url = "http://"; url += getServer(); if (getPort() != 80) { url += ":"; url += number(getPort()); } url += "/"; Event eGo(EventGoURL, (void*)url.c_str()); eGo.process(); if (getState() == Connected) m_timer->start(getInterval() * 60 * 1000, true); return e->param(); } if (e->type() == EventCommandExec) { CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdDeleteJournalMessage) { Message *msg = (Message*)(cmd->param); Contact *contact = getContacts()->contact(msg->contact()); if (contact == NULL) return NULL; LiveJournalUserData *data; ClientDataIterator it(contact->clientData, this); while ((data = (LiveJournalUserData*)(++it)) != NULL) { if (dataName(data) == msg->client()) { Buffer cfg; cfg << "[Title]\n" << msg->save().c_str(); cfg.setWritePos(0); cfg.getSection(); JournalMessage *m = new JournalMessage(&cfg); m->setContact(msg->contact()); m->setOldID(msg->id()); m->setText(""); if (!send(m, data)) delete m; return e->param(); } } return NULL; } unsigned menu_id = cmd->menu_id - MenuWeb; if (menu_id > LiveJournalPlugin::MenuCount) return NULL; unsigned item_id = cmd->id - CmdMenuWeb; if ((item_id == 0) || (item_id >= 0x100)) return NULL; const char *url = getMenuUrl(menu_id * 0x100 + item_id); if ((url == NULL) || (*url == 0)) return NULL; Event eUrl(EventGoURL, (void*)url); eUrl.process(); return e->param(); } if (e->type() == EventCheckState) { CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->id == CmdMenuWeb) { unsigned menu_id = cmd->menu_id - MenuWeb; if (menu_id > LiveJournalPlugin::MenuCount) return NULL; unsigned nItems = 0; unsigned list_id = menu_id * 0x100 + 1; for (;;) { const char *text = getMenu(list_id); if ((text == NULL) || (*text == 0)) break; nItems++; list_id++; } if (nItems == 0) return NULL; CommandDef *cmds = new CommandDef[nItems + 1]; memset(cmds, 0, sizeof(CommandDef) * (nItems + 1)); list_id = menu_id * 0x100 + 1; for (unsigned i = 0;; i++) { const char *text = getMenu(list_id); if ((text == NULL) || (*text == 0)) break; cmds[i].text = "_"; if (strcmp(text, "-")) { cmds[i].id = CmdMenuWeb + i + 1; cmds[i].text = "_"; QString s = i18n(text); cmds[i].text_wrk = strdup(s.utf8()); const char *url = getMenuUrl(list_id); if (url && (*url == '@')) { unsigned nSub = atol(url + 1); while (nSub > LiveJournalPlugin::MenuCount) { unsigned long menu_id = MenuWeb + (++LiveJournalPlugin::MenuCount); Event eMenu(EventMenuCreate, (void*)menu_id); eMenu.process(); Command cmd; cmd->id = CmdMenuWeb; cmd->text = "_"; cmd->menu_id = menu_id; cmd->menu_grp = 0x1000; cmd->flags = COMMAND_CHECK_STATE; Event e(EventCommandCreate, cmd); e.process(); } cmds[i].popup_id = MenuWeb + nSub; } } else { cmds[i].id = 0; } list_id++; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; return e->param(); } } return NULL; }
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; }