Beispiel #1
0
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;
}
Beispiel #3
0
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;
}
Beispiel #5
0
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 );
    }
Beispiel #6
0
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;
}
Beispiel #7
0
const bool SyntaxNode::FindElements(
        Element::List& CLI_ExactList,
        Element::List& CLI_NearList,
        const char* const STR_Keyword
        ) const
{
    // For each child...
    for (   Element::List::Iterator it = m_cliElements.GetIterator();
            m_cliElements.IsValid(it);
            m_cliElements.MoveNext(it))
    {
        if (const Element* const pcli_Element = m_cliElements.GetAt(it))
        {
            if (0) {}
            else if (const SyntaxTag* const pcli_Tag = dynamic_cast<const SyntaxTag*>(pcli_Element))
            {
                // Propagate call over child non hollow tag.
                if (! pcli_Tag->GetbHollow())
                {
                    if (! pcli_Tag->FindElements(CLI_ExactList, CLI_NearList, STR_Keyword))
                    {
                        return false;
                    }
                }
            }
            else if (const SyntaxRef* const pcli_Ref = dynamic_cast<const SyntaxRef*>(pcli_Element))
            {
                // Propagate call over referenced tag.
                if (! pcli_Ref->GetTag().FindElements(CLI_ExactList, CLI_NearList, STR_Keyword))
                {
                    return false;
                }
            }
            else if (STR_Keyword == NULL)
            {
                // No keyword begun.
                // Retrieve all sub-elements.
                if (! CLI_NearList.AddTail(pcli_Element))
                {
                    GetTraces().Trace(INTERNAL_ERROR) << "SyntaxNode::FindElements(): Not enough space in CLI_ExactList." << endl;
                }
            }
            else
            {
                // A beginning of word has been given.
                const tk::String str_Keyword(MAX_WORD_LENGTH, STR_Keyword);

                if (const Param* const pcli_Param = dynamic_cast<const Param*>(pcli_Element))
                {
                    // If the child element is a parameter, check SetstrValue() works for it.
                    if (str_Keyword != "\n")
                    {
                        if (pcli_Param->SetstrValue(str_Keyword))
                        {
                            if (! CLI_NearList.AddTail(pcli_Param))
                            {
                                GetTraces().Trace(INTERNAL_ERROR) << "SyntaxNode::FindElements(): Not enough space in CLI_ExactList." << endl;
                            }
                            if (! CLI_ExactList.AddTail(pcli_Param))
                            {
                                GetTraces().Trace(INTERNAL_ERROR) << "SyntaxNode::FindElements(): Not enough space in CLI_ExactList." << endl;
                            }
                        }
                    }
                }
                else if (pcli_Element->GetKeyword().SubString(0, str_Keyword.GetLength()) == str_Keyword)
                {
                    // Check the beginning of the word for other elements.
                    if (! CLI_NearList.AddTail(pcli_Element))
                    {
                        GetTraces().Trace(INTERNAL_ERROR) << "SyntaxNode::FindElements(): Not enough space in CLI_ExactList." << endl;
                    }
                    if (str_Keyword.GetLength() == pcli_Element->GetKeyword().GetLength())
                    {
                        if (! CLI_ExactList.AddTail(pcli_Element))
                        {
                            GetTraces().Trace(INTERNAL_ERROR) << "SyntaxNode::FindElements(): Not enough space in CLI_ExactList." << endl;
                        }
                    }
                }
            }
        }
    }

    return true;
}