Element::List Datenums::createDayElements(const QDate &date) { Element::List result; int dayOfYear = date.dayOfYear(); int remainingDays = date.daysInYear() - dayOfYear; StoredElement *e; switch (mDisplayedInfo) { case DayOfYear: // only day of year e = new StoredElement(QStringLiteral("main element"), QString::number(dayOfYear)); break; case DaysRemaining: // only days until end of year e = new StoredElement(QStringLiteral("main element"), QString::number(remainingDays), i18np("1 day before the end of the year", "%1 days before the end of the year", remainingDays)); break; case DayOfYear + DaysRemaining: // both day of year and days till end of year default: e = new StoredElement(QStringLiteral("main element"), QString::number(dayOfYear), i18nc("dayOfYear / daysTillEndOfYear", "%1 / %2", dayOfYear, remainingDays), i18np("1 day since the beginning of the year,\n", "%1 days since the beginning of the year,\n", dayOfYear) + i18np("1 day until the end of the year", "%1 days until the end of the year", remainingDays)); break; } result.append(e); return result; }
Element::List Picoftheday::createDayElements( const QDate &date ) { Element::List elements; POTDElement *element = new POTDElement( "main element", date, mThumbSize ); elements.append( element ); return elements; }
void Parser::parseCompositor( ParserContext *context, const QDomElement &element, ComplexType &ct ) { QName name = element.tagName(); bool isChoice = name.localName() == "choice"; bool isSequence = name.localName() == "sequence"; Compositor compositor; if ( isChoice ) compositor.setType( Compositor::Choice ); else if ( isSequence ) compositor.setType( Compositor::Sequence ); if ( isChoice || isSequence ) { Element::List newElements; QDomElement childElement = element.firstChildElement(); while ( !childElement.isNull() ) { QName csName = childElement.tagName(); if ( csName.localName() == "element" ) { Element newElement; if ( isChoice ) { newElement = parseElement( context, childElement, ct.nameSpace(), element ); } else { if ( isSequence ) { // occurence attributes can be either in the // parent (sequence) to on the current element if ( childElement.hasAttribute("minOccurs") || childElement.hasAttribute("maxOccurs")) { newElement = parseElement( context, childElement, ct.nameSpace(), childElement ); } else { newElement = parseElement( context, childElement, ct.nameSpace(), element ); } } else { newElement = parseElement( context, childElement, ct.nameSpace(), childElement ); } } newElements.append( newElement ); compositor.addChild( csName ); } else if ( csName.localName() == "any" ) { addAny( context, childElement, ct ); } else if ( isChoice ) { parseCompositor( context, childElement, ct ); } else if ( isSequence ) { parseCompositor( context, childElement, ct ); } childElement = childElement.nextSiblingElement(); } foreach( Element e, newElements ) { e.setCompositor( compositor ); ct.addElement( e ); }
Element::List ThisDayInHistory::createMonthElements( const QDate &date ) { Element::List elements; StoredElement *element = new StoredElement( "Wikipedia link", i18n( "This month in history" ) ); element->setUrl( QString( i18nc( "Localized Wikipedia website", "http://en.wikipedia.org/wiki/" ) + date.toString( i18nc( "Qt date format used by the localized Wikipedia", "MMMM_yyyy" ) ) ) ); elements.append( element ); return elements; }
void Parser::parseCompositor( ParserContext *context, const QDomElement &element, ComplexType &ct ) { const QName name( element.tagName() ); bool isChoice = name.localName() == QLatin1String("choice"); bool isSequence = name.localName() == QLatin1String("sequence"); Compositor compositor; if ( isChoice ) compositor.setType( Compositor::Choice ); else if ( isSequence ) compositor.setType( Compositor::Sequence ); compositor.setMaxOccurs( readMaxOccurs( element ) ); if ( isChoice || isSequence ) { Element::List newElements; QDomElement childElement = element.firstChildElement(); while ( !childElement.isNull() ) { NSManager namespaceManager( context, childElement ); const QName csName( childElement.tagName() ); if ( csName.localName() == QLatin1String("element") ) { Element newElement; if ( isChoice ) { newElement = parseElement( context, childElement, ct.nameSpace(), element ); } else { newElement = parseElement( context, childElement, ct.nameSpace(), childElement ); } newElements.append( newElement ); compositor.addChild( csName ); } else if ( csName.localName() == QLatin1String("any") ) { addAny( context, childElement, ct ); } else if ( isChoice ) { parseCompositor( context, childElement, ct ); } else if ( isSequence ) { parseCompositor( context, childElement, ct ); } childElement = childElement.nextSiblingElement(); } foreach( Element e, newElements ) { e.setCompositor( compositor ); ct.addElement( e ); }
Element::List Datenums::createWeekElements(const QDate &date) { Element::List result; const KCalendarSystem *calsys = KLocale::global()->calendar(); int *yearOfTheWeek; yearOfTheWeek = Q_NULLPTR; int remainingWeeks; const int weekOfYear = date.weekNumber(yearOfTheWeek); QString weekOfYearShort; QString weekOfYearLong; QString weekOfYearExtensive; QString remainingWeeksShort; QString remainingWeeksLong; QString remainingWeeksExtensive; QString weekOfYearAndRemainingWeeksShort; // Usual case: the week belongs to this year remainingWeeks = calsys->weeksInYear(date.year()) - weekOfYear; weekOfYearShort = QString::number(weekOfYear); weekOfYearLong = i18nc("Week weekOfYear", "Week %1", weekOfYear); weekOfYearExtensive = i18np("1 week since the beginning of the year", "%1 weeks since the beginning of the year", weekOfYear); if (yearOfTheWeek) { // The week does not belong to this year weekOfYearShort = i18nc("weekOfYear (year)", "%1 (%2)", weekOfYear, *yearOfTheWeek); weekOfYearLong = i18nc("Week weekOfYear (year)", "Week %1 (%2)", weekOfYear, *yearOfTheWeek); if (*yearOfTheWeek == date.year() + 1) { // The week belongs to next year remainingWeeks = 0; weekOfYearExtensive = i18np("1 week since the beginning of the year", "%1 weeks since the beginning of the year", weekOfYear); } else { // The week belongs to last year remainingWeeks = calsys->weeksInYear(date.year()); weekOfYearExtensive = i18np("1 week since the beginning of the year", "%1 weeks since the beginning of the year", 0); } } remainingWeeksShort = QString::number(remainingWeeks); remainingWeeksShort = i18np("1 week remaining", "%1 weeks remaining", remainingWeeks); remainingWeeksExtensive = i18np("1 week until the end of the year", "%1 weeks until the end of the year", remainingWeeks); weekOfYearAndRemainingWeeksShort = i18nc("weekOfYear / weeksTillEndOfYear", "%1 / %2", weekOfYear, remainingWeeks); StoredElement *e; switch (mDisplayedInfo) { case DayOfYear: // only week of year e = new StoredElement(QStringLiteral("main element"), weekOfYearShort, weekOfYearLong, weekOfYearExtensive); break; case DaysRemaining: // only weeks until end of year e = new StoredElement(QStringLiteral("main element"), remainingWeeksShort, remainingWeeksLong, remainingWeeksExtensive); break; case DayOfYear + DaysRemaining: // both week of year and weeks till end of year default: e = new StoredElement(QStringLiteral("main element"), weekOfYearShort, weekOfYearAndRemainingWeeksShort, i18nc("n weeks since the beginning of the year\n" "n weeks until the end of the year", "%1\n%2", weekOfYearExtensive, remainingWeeksExtensive)); break; } result.append(e); return result; }