Пример #1
0
void HtmlExport::createEventList(QTextStream *ts)
{
    int columns = 3;
    *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">" << endl;
    *ts << "  <tr>" << endl;
    *ts << "    <th class=\"sum\">" << i18nc("@title:column event start time",
            "Start Time") << "</th>" << endl;
    *ts << "    <th>" << i18nc("@title:column event end time",
                               "End Time") << "</th>" << endl;
    *ts << "    <th>" << i18nc("@title:column event description",
                               "Event") << "</th>" << endl;
    if (d->mSettings->eventLocation()) {
        *ts << "    <th>" << i18nc("@title:column event locatin",
                                   "Location") << "</th>" << endl;
        ++columns;
    }
    if (d->mSettings->eventCategories()) {
        *ts << "    <th>" << i18nc("@title:column event categories",
                                   "Categories") << "</th>" << endl;
        ++columns;
    }
    if (d->mSettings->eventAttendees()) {
        *ts << "    <th>" << i18nc("@title:column event attendees",
                                   "Attendees") << "</th>" << endl;
        ++columns;
    }

    *ts << "  </tr>" << endl;

    for (QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1)) {
        qCDebug(KCALUTILS_LOG) << "Getting events for" << dt.toString();
        Event::List events = d->mCalendar->events(dt, d->mCalendar->timeSpec(),
                             EventSortStartDate,
                             SortDirectionAscending);
        if (events.count()) {
            *ts << "  <tr><td colspan=\"" << QString::number(columns)
                << "\" class=\"datehead\"><i>"
                << QLocale().toString(dt)
                << "</i></td></tr>" << endl;

            Event::List::ConstIterator it;
            for (it = events.constBegin(); it != events.constEnd(); ++it) {
                if (checkSecrecy(*it)) {
                    createEvent(ts, *it, dt);
                }
            }
        }
    }

    *ts << "</table>" << endl;
}
Пример #2
0
//@cond PRIVATE
void FreeBusy::Private::init( const Event::List &eventList,
                              const KDateTime &start, const KDateTime &end )
{
  int extraDays, i, x, duration;
  duration = start.daysTo( end );
  QDate day;
  KDateTime tmpStart;
  KDateTime tmpEnd;

  // Loops through every event in the calendar
  Event::List::ConstIterator it;
  for ( it = eventList.constBegin(); it != eventList.constEnd(); ++it ) {
    Event::Ptr event = *it;

    // If this event is transparent it shouldn't be in the freebusy list.
    if ( event->transparency() == Event::Transparent ) {
      continue;
    }

    // The code below can not handle all-day events. Fixing this resulted
    // in a lot of duplicated code. Instead, make a copy of the event and
    // set the period to the full day(s). This trick works for recurring,
    // multiday, and single day all-day events.
    Event::Ptr allDayEvent;
    if ( event->allDay() ) {
      // addDay event. Do the hack
      kDebug() << "All-day event";
      allDayEvent = Event::Ptr( new Event( *event ) );

      // Set the start and end times to be on midnight
      KDateTime st = allDayEvent->dtStart();
      st.setTime( QTime( 0, 0 ) );
      KDateTime nd = allDayEvent->dtEnd();
      nd.setTime( QTime( 23, 59, 59, 999 ) );
      allDayEvent->setAllDay( false );
      allDayEvent->setDtStart( st );
      allDayEvent->setDtEnd( nd );

      kDebug() << "Use:" << st.toString() << "to" << nd.toString();
      // Finally, use this event for the setting below
      event = allDayEvent;
    }

    // This whole for loop is for recurring events, it loops through
    // each of the days of the freebusy request

    for ( i = 0; i <= duration; ++i ) {
      day = start.addDays( i ).date();
      tmpStart.setDate( day );
      tmpEnd.setDate( day );

      if ( event->recurs() ) {
        if ( event->isMultiDay() ) {
  // FIXME: This doesn't work for sub-daily recurrences or recurrences with
  //        a different time than the original event.
          extraDays = event->dtStart().daysTo( event->dtEnd() );
          for ( x = 0; x <= extraDays; ++x ) {
            if ( event->recursOn( day.addDays( -x ), start.timeSpec() ) ) {
              tmpStart.setDate( day.addDays( -x ) );
              tmpStart.setTime( event->dtStart().time() );
              tmpEnd = event->duration().end( tmpStart );

              addLocalPeriod( q, tmpStart, tmpEnd );
              break;
            }
          }
        } else {
          if ( event->recursOn( day, start.timeSpec() ) ) {
            tmpStart.setTime( event->dtStart().time() );
            tmpEnd.setTime( event->dtEnd().time() );

            addLocalPeriod ( q, tmpStart, tmpEnd );
          }
        }
      }

    }
    // Non-recurring events
    addLocalPeriod( q, event->dtStart(), event->dtEnd() );
  }

  q->sortList();
}
Пример #3
0
void HtmlExport::createMonthView(QTextStream *ts)
{
    QDate start = fromDate();
    start.setYMD(start.year(), start.month(), 1);    // go back to first day in month

    QDate end(start.year(), start.month(), start.daysInMonth());

    int startmonth = start.month();
    int startyear = start.year();

    while (start < toDate()) {
        // Write header
        QDate hDate(start.year(), start.month(), 1);
        QString hMon = hDate.toString(QStringLiteral("MMMM"));
        QString hYear = hDate.toString(QStringLiteral("yyyy"));
        *ts << "<h2>"
            << i18nc("@title month and year", "%1 %2", hMon, hYear)
            << "</h2>" << endl;
        if (QLocale().firstDayOfWeek() == 1) {
            start = start.addDays(1 - start.dayOfWeek());
        } else {
            if (start.dayOfWeek() != 7) {
                start = start.addDays(-start.dayOfWeek());
            }
        }
        *ts << "<table border=\"1\">" << endl;

        // Write table header
        *ts << "  <tr>";
        for (int i = 0; i < 7; ++i) {
            *ts << "<th>" << QLocale().dayName(start.addDays(i).dayOfWeek()) << "</th>";
        }
        *ts << "</tr>" << endl;

        // Write days
        while (start <= end) {
            *ts << "  <tr>" << endl;
            for (int i = 0; i < 7; ++i) {
                *ts << "    <td valign=\"top\"><table border=\"0\">";

                *ts << "<tr><td ";
                if (d->mHolidayMap.contains(start) || start.dayOfWeek() == 7) {
                    *ts << "class=\"dateholiday\"";
                } else {
                    *ts << "class=\"date\"";
                }
                *ts << ">" << QString::number(start.day());

                if (d->mHolidayMap.contains(start)) {
                    *ts << " <em>" << d->mHolidayMap[start] << "</em>";
                }

                *ts << "</td></tr><tr><td valign=\"top\">";

                // Only print events within the from-to range
                if (start >= fromDate() && start <= toDate()) {
                    Event::List events = d->mCalendar->events(start, d->mCalendar->timeSpec(),
                                         EventSortStartDate,
                                         SortDirectionAscending);
                    if (events.count()) {
                        *ts << "<table>";
                        Event::List::ConstIterator it;
                        for (it = events.constBegin(); it != events.constEnd(); ++it) {
                            if (checkSecrecy(*it)) {
                                createEvent(ts, *it, start, false);
                            }
                        }
                        *ts << "</table>";
                    } else {
                        *ts << "&nbsp;";
                    }
                }

                *ts << "</td></tr></table></td>" << endl;
                start = start.addDays(1);
            }
            *ts << "  </tr>" << endl;
        }
        *ts << "</table>" << endl;
        startmonth += 1;
        if (startmonth > 12) {
            startyear += 1;
            startmonth = 1;
        }
        start.setYMD(startyear, startmonth, 1);
        end.setYMD(start.year(), start.month(), start.daysInMonth());
    }
}