QString WeatherPlugin::replace(const QString &text) { QString res = text; QString sun_set, sun_raise, updated; #if COMPAT_QT_VERSION >= 0x030000 QTime tmp_time; QDateTime dt; int h,m; parseTime(getSun_set(),h,m); tmp_time.setHMS(h,m,0,0); sun_set = tmp_time.toString(Qt::LocalDate); sun_set = sun_set.left(sun_set.length() - 3); parseTime(getSun_raise(),h,m); tmp_time.setHMS(h,m,0,0); sun_raise = tmp_time.toString(Qt::LocalDate); sun_raise = sun_raise.left(sun_raise.length() - 3); parseDateTime(getUpdated(),dt); updated = dt.toString(Qt::LocalDate); updated = updated.left(updated.length() - 3); #else sun_set = getSun_set(); sun_raise = getSun_raise(); updated = getUpdated(); #endif /* double Expressions *before* single or better RegExp ! */ res = res.replace(QRegExp("\\%mp"), i18n("moonphase", getMoonPhase())); res = res.replace(QRegExp("\\%mi"), number(getMoonIcon())); res = res.replace(QRegExp("\\%pp"), number(getPrecipitation())); res = res.replace(QRegExp("\\%ut"), i18n("weather", getUV_Description())); res = res.replace(QRegExp("\\%ui"), number(getUV_Intensity())); res = res.replace(QRegExp("\\%t"), QString::number((int)getTemperature()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%f"), QString::number((int)getFeelsLike()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%d"), QString::number((int)getDewPoint()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%h"), number(getHumidity()) + "%"); res = res.replace(QRegExp("\\%w"), number(getWind_speed()) + " " + i18n(getUS())); res = res.replace(QRegExp("\\%x"), QString::number(getWind_speed() * 10 / 36) + " " + i18n("m/s")); res = res.replace(QRegExp("\\%g"), getWindGust() ? QString("(") + i18n("gust ") + number(getWindGust()) + i18n(getUS()) + QString(")") : QString("")); res = res.replace(QRegExp("\\%y"), getWindGust() ? QString("(") + i18n("gust ") + number(getWindGust() * 10 / 36) + QString(" ") + i18n("m/s") + QString(")") : QString("")); res = res.replace(QRegExp("\\%p"), number(getPressure()) + " " + i18n(getUP())); res = res.replace(QRegExp("\\%a"), number(getPressure() * 75 / 100)); res = res.replace(QRegExp("\\%q"), i18n("weather", getPressureD())); res = res.replace(QRegExp("\\%l"), getLocation()); res = res.replace(QRegExp("\\%b"), i18n("weather", getWind())); res = res.replace(QRegExp("\\%u"), updated); res = res.replace(QRegExp("\\%r"), sun_raise); res = res.replace(QRegExp("\\%s"), sun_set); res = res.replace(QRegExp("\\%c"), i18n_conditions(getConditions())); res = res.replace(QRegExp("\\%v"), i18n("weather", getVisibility()) + (atol(getVisibility()) ? QString(" ") + i18n(getUD()) : QString(""))); res = res.replace(QRegExp("\\%i"), number(getIcon())); return res; }
QString WeatherPlugin::replace(const QString &text) { QString res = text; res = res.replace(QRegExp("\\%t"), number(getTemperature()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%h"), number(getHumidity()) + "%"); res = res.replace(QRegExp("\\%w"), number(getWind_speed()) + " " + getUS()); res = res.replace(QRegExp("\\%i"), number(getPressure()) + " " + getUP()); res = res.replace(QRegExp("\\%l"), getLocation()); res = res.replace(QRegExp("\\%r"), getWind()); res = res.replace(QRegExp("\\%u"), getUpdated()); res = res.replace(QRegExp("\\%p"), getSun_raise()); res = res.replace(QRegExp("\\%q"), getSun_set()); res = res.replace(QRegExp("\\%c"), i18n("weather", getConditions())); return res; }
bool WeatherPlugin::isDay() { int raise_h, raise_m; int set_h, set_m; if (!parseTime(getSun_raise(), raise_h, raise_m) || !parseTime(getSun_set(), set_h, set_m)) return false; time_t now = time(NULL); struct tm *tm = localtime(&now); if ((tm->tm_hour > raise_h) && (tm->tm_hour < set_h)) return true; if ((tm->tm_hour == raise_h) && (tm->tm_min >= raise_m)) return true; if ((tm->tm_hour == set_h) && (tm->tm_min <= set_m)) return true; return false; }
QString WeatherPlugin::replace(const QString &text) { QString res = text; res = res.replace(QRegExp("\\%f"), number(getTemperature_f())); res = res.replace(QRegExp("\\%s"), number(getTemperature_c())); res = res.replace(QRegExp("\\%h"), number(getHumidity())); res = res.replace(QRegExp("\\%w"), number(getWind_speed_mph())); res = res.replace(QRegExp("\\%x"), number(getWind_speed_km())); res = res.replace(QRegExp("\\%i"), number(getPressure_in())); res = res.replace(QRegExp("\\%a"), number(getPressure_hpa())); res = res.replace(QRegExp("\\%l"), getLocation()); res = res.replace(QRegExp("\\%r"), getWind()); res = res.replace(QRegExp("\\%u"), getUpdated()); res = res.replace(QRegExp("\\%p"), getSun_raise()); res = res.replace(QRegExp("\\%q"), getSun_set()); res = res.replace(QRegExp("\\%c"), i18n("weather", getConditions())); return res; }
QString WeatherPlugin::replace(const QString &text) { QString res = text; res = res.replace(QRegExp("\\%t"), number(getTemperature()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%f"), number(getFeelsLike()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%d"), number(getDewPoint()) + QChar((unsigned short)176) + getUT()); res = res.replace(QRegExp("\\%h"), number(getHumidity()) + "%"); res = res.replace(QRegExp("\\%w"), number(getWind_speed()) + " " + getUS()); res = res.replace(QRegExp("\\%g"), getWindGust() ? QString("<") + i18n("gust ") + number(getWindGust()) + ")" : ""); res = res.replace(QRegExp("\\%p"), number(getPressure()) + " " + getUP() + " (" + i18n("weather", getPressureD()) + ")"); res = res.replace(QRegExp("\\%a"), number(getPressure() * 75 / 100)); res = res.replace(QRegExp("\\%l"), getLocation()); res = res.replace(QRegExp("\\%b"), getWind()); res = res.replace(QRegExp("\\%u"), getUpdated()); res = res.replace(QRegExp("\\%r"), getSun_raise()); res = res.replace(QRegExp("\\%s"), getSun_set()); res = res.replace(QRegExp("\\%c"), i18n_conditions(getConditions())); res = res.replace(QRegExp("\\%v"), i18n("weather", getVisibility())); return res; }