static QString i18n_conditions(const QString &str) { if (str.isEmpty()) return ""; int n = str.find(" / "); if (n >= 0) return i18n_conditions(str.left(n)) + " / " + i18n_conditions(str.mid(n + 3)); n = str.find(" Early"); if (n >= 0) return i18n_conditions(str.left(n)) + " " + i18n("weather", "Early"); n = str.find(" Later"); if (n >= 0) return i18n_conditions(str.left(n)) + " " + i18n("weather", "Later"); return i18n("weather", str); }
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; }
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::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)); if ((minT < 0) && (maxT < 0)){ int r = minT; minT = maxT; maxT = r; } if (minT < 0){ temp += "-"; minT = -minT; }else if (minT > 0){ temp += "+"; } temp += number((unsigned)minT).c_str(); temp += QChar((unsigned short)176); temp += getUT(); if (maxT < 0){ temp += "-"; maxT = -maxT; }else if (maxT >= 0){ temp += "+"; } temp += number((unsigned)maxT).c_str(); 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"), number(m_day).c_str()); 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; }
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; }
static QString i18n_conditions(const QString &str) { if (str.isEmpty()) return ""; int n = str.find(" / "); if (n >= 0) return i18n_conditions(str.left(n)) + " / " + i18n_conditions(str.mid(n + 3)); n = str.find(" and "); if (n >= 0) return i18n_conditions(str.left(n)) + " " + i18n("and") + " " + i18n_conditions(str.mid(n + 5)); n = str.find(" Early"); if (n >= 0) return i18n_conditions(str.left(n)) + " " + i18n("weather", "Early"); n = str.find(" Late"); if (n >= 0) return i18n_conditions(str.left(n)) + " " + i18n("weather", "Late"); QString s = str; s = s.replace(QRegExp(" Showers"), ""); s = s.replace(QRegExp(" Shower"), ""); return i18n("weather", s); }