Incidence *ICalFormat::fromString(const QString &text) { CalendarLocal cal(mTimeZoneId); fromString(&cal, text); Incidence *ical = 0; Event::List elist = cal.events(); if(elist.count() > 0) { ical = elist.first(); } else { Todo::List tlist = cal.todos(); if(tlist.count() > 0) { ical = tlist.first(); } else { Journal::List jlist = cal.journals(); if(jlist.count() > 0) { ical = jlist.first(); } } } return ical ? ical->clone() : 0; }
bool KonsoleKalendar::showInstance() { bool status = true; QFile f; QString title; Event::Ptr event; const KDateTime::Spec timeSpec = m_variables->getCalendar()->timeSpec(); Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar(); if (m_variables->isDryRun()) { cout << i18n("View Events <Dry Run>:").toLocal8Bit().data() << endl; printSpecs(); } else { qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendar.cpp::showInstance() |" << "open export file"; if (m_variables->isExportFile()) { f.setFileName(m_variables->getExportFile()); if (!f.open(QIODevice::WriteOnly)) { status = false; qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendar.cpp::showInstance() |" << "unable to open export file" << m_variables->getExportFile(); } } else { f.open(stdout, QIODevice::WriteOnly); } if (status) { qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendar.cpp::showInstance() |" << "opened successful"; if (m_variables->isVerbose()) { cout << i18n("View Event <Verbose>:").toLocal8Bit().data() << endl; printSpecs(); } QTextStream ts(&f); if (m_variables->getExportType() != ExportTypeHTML && m_variables->getExportType() != ExportTypeMonthHTML) { if (m_variables->getAll()) { qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendar.cpp::showInstance() |" << "view all events sorted list"; Event::List sortedList = calendar->events(EventSortStartDate); qCDebug(KONSOLEKALENDAR_LOG) << "Found" << sortedList.count() << "events"; if (!sortedList.isEmpty()) { // The code that was here before the akonadi port was really slow with 200 events // this is much faster: foreach (const KCalCore::Event::Ptr &event, sortedList) { status &= printEvent(&ts, event, event->dtStart().date()); } } } else if (m_variables->isUID()) {
void KOEventEditor::loadTemplate( CalendarLocal &cal ) { Event::List events = cal.events(); if ( events.count() == 0 ) { KMessageBox::error( this, i18nc( "@info", "Template does not contain a valid event." ) ); } else { readEvent( events.first(), QDate(), true ); } }
void HtmlExport::createEventList(QTextStream *ts) { int columns = 3; *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n"; *ts << " <tr>\n"; *ts << " <th class=\"sum\">" << i18n("Start Time") << "</th>\n"; *ts << " <th>" << i18n("End Time") << "</th>\n"; *ts << " <th>" << i18n("Event") << "</th>\n"; if(mSettings->eventLocation()) { *ts << " <th>" << i18n("Location") << "</th>\n"; ++columns; } if(mSettings->eventCategories()) { *ts << " <th>" << i18n("Categories") << "</th>\n"; ++columns; } if(mSettings->eventAttendees()) { *ts << " <th>" << i18n("Attendees") << "</th>\n"; ++columns; } *ts << " </tr>\n"; for(QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1)) { kdDebug(5850) << "Getting events for " << dt.toString() << endl; Event::List events = mCalendar->events(dt, EventSortStartDate, SortDirectionAscending); if(events.count()) { Event::List::ConstIterator it; bool first = true; for(it = events.begin(); it != events.end(); ++it) { if(checkSecrecy(*it)) { if(first) { *ts << " <tr><td colspan=\"" << QString::number(columns) << "\" class=\"datehead\"><i>" << KGlobal::locale()->formatDate(dt) << "</i></td></tr>\n"; first = false; } createEvent(ts, *it, dt); } } } } *ts << "</table>\n"; }
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; }
/****************************************************************************** * Check whether the alarm types in a calendar correspond with the resource's * alarm type. * Reply = true if at least 1 alarm is the right type. */ bool AlarmResource::checkAlarmTypes(KCal::CalendarLocal& calendar) const { KCalEvent::Status type = kcalEventType(); if (type != KCalEvent::EMPTY) { bool have = false; bool other = false; const Event::List events = calendar.rawEvents(); for (int i = 0, iend = events.count(); i < iend; ++i) { KCalEvent::Status s = KCalEvent::status(events[i]); if (type == s) have = true; else other = true; if (have && other) break; } if (!have && other) return false; // contains only wrong alarm types } return true; }
void KOWhatsNextView::updateView() { KIconLoader kil("kdepim"); QString *ipath = new QString(); kil.loadIcon("kdepim",KIcon::NoGroup,32,KIcon::DefaultState,ipath); mText = "<table width=\"100%\">\n"; mText += "<tr bgcolor=\"#3679AD\"><td><h1>"; mText += "<img src=\""; mText += *ipath; mText += "\">"; mText += "<font color=\"white\"> "; mText += i18n("What's Next?") + "</font></h1>"; mText += "</td></tr>\n<tr><td>"; mText += "<h2>"; if ( mStartDate.daysTo( mEndDate ) < 1 ) { mText += KGlobal::locale()->formatDate( mStartDate ); } else { mText += i18n("Date from - to", "%1 - %2") .arg( KGlobal::locale()->formatDate( mStartDate ) ) .arg( KGlobal::locale()->formatDate( mEndDate ) ); } mText+="</h2>\n"; Event::List events; for ( QDate date = mStartDate; date <= mEndDate; date = date.addDays( 1 ) ) events += calendar()->events(date, EventSortStartDate, SortDirectionAscending); if (events.count() > 0) { mText += "<p></p>"; kil.loadIcon("appointment",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("Events:") + "</h2>\n"; mText += "<table>\n"; Event::List::ConstIterator it; for( it = events.begin(); it != events.end(); ++it ) { Event *ev = *it; if ( !ev->doesRecur() ){ appendEvent(ev); } else { // FIXME: This should actually be cleaned up. Libkcal should // provide a method to return a list of all recurrences in a // given time span. Recurrence *recur = ev->recurrence(); int duration = ev->dtStart().secsTo( ev->dtEnd() ); QDateTime start = recur->getPreviousDateTime( QDateTime( mStartDate, QTime() ) ); QDateTime end = start.addSecs( duration ); if ( end.date() >= mStartDate ) { appendEvent( ev, start, end ); } start = recur->getNextDateTime( start ); while ( start.isValid() && start.date() <= mEndDate ) { appendEvent( ev, start ); start = recur->getNextDateTime( start ); } } } mText += "</table>\n"; } mTodos.clear(); Todo::List todos = calendar()->todos( TodoSortDueDate, SortDirectionAscending ); if ( todos.count() > 0 ) { kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("To-do:") + "</h2>\n"; mText += "<ul>\n"; Todo::List::ConstIterator it; for( it = todos.begin(); it != todos.end(); ++it ) { Todo *todo = *it; if ( !todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= mEndDate ) appendTodo(todo); } bool gotone = false; int priority = 1; while (!gotone && priority<=9 ) { for( it = todos.begin(); it != todos.end(); ++it ) { Todo *todo = *it; if (!todo->isCompleted() && (todo->priority() == priority) ) { appendTodo(todo); gotone = true; } } priority++; kdDebug(5850) << "adding the todos..." << endl; } mText += "</ul>\n"; } QStringList myEmails( KOPrefs::instance()->allEmails() ); int replies = 0; events = calendar()->events( QDate::currentDate(), QDate(2975,12,6) ); Event::List::ConstIterator it2; for( it2 = events.begin(); it2 != events.end(); ++it2 ) { Event *ev = *it2; Attendee *me = ev->attendeeByMails( myEmails ); if (me!=0) { if (me->status()==Attendee::NeedsAction && me->RSVP()) { if (replies == 0) { mText += "<p></p>"; kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("Events and to-dos that need a reply:") + "</h2>\n"; mText += "<table>\n"; } replies++; appendEvent( ev ); } } } todos = calendar()->todos(); Todo::List::ConstIterator it3; for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) { Todo *to = *it3; Attendee *me = to->attendeeByMails( myEmails ); if (me!=0) { if (me->status()==Attendee::NeedsAction && me->RSVP()) { if (replies == 0) { mText += "<p></p>"; kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("Events and to-dos that need a reply:") + "</h2>\n"; mText += "<table>\n"; } replies++; appendEvent(to); } } kdDebug () << "check for todo-replies..." << endl; } if (replies > 0 ) mText += "</table>\n"; mText += "</td></tr>\n</table>\n"; kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl; delete ipath; mView->setText(mText); }
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 *ts << "<h2>" << (i18n("month_year","%1 %2").arg(KGlobal::locale()->calendar()->monthName(start)) .arg(start.year())) << "</h2>\n"; if ( KGlobal::locale()->weekStartDay() == 1 ) { start = start.addDays(1 - start.dayOfWeek()); } else { if (start.dayOfWeek() != 7) { start = start.addDays(-start.dayOfWeek()); } } *ts << "<table border=\"1\">\n"; // Write table header *ts << " <tr>"; for(int i=0; i<7; ++i) { *ts << "<th>" << KGlobal::locale()->calendar()->weekDayName( start.addDays(i) ) << "</th>"; } *ts << "</tr>\n"; // Write days while (start <= end) { *ts << " <tr>\n"; for(int i=0; i<7; ++i) { *ts << " <td valign=\"top\"><table border=\"0\">"; *ts << "<tr><td "; if (mHolidayMap.contains(start) || start.dayOfWeek() == 7) { *ts << "class=\"dateholiday\""; } else { *ts << "class=\"date\""; } *ts << ">" << QString::number(start.day()); if (mHolidayMap.contains(start)) { *ts << " <em>" << mHolidayMap[start] << "</em>"; } *ts << "</td></tr><tr><td valign=\"top\">"; Event::List events = mCalendar->events( start, EventSortStartDate, SortDirectionAscending ); if (events.count()) { *ts << "<table>"; Event::List::ConstIterator it; for( it = events.begin(); it != events.end(); ++it ) { if ( checkSecrecy( *it ) ) { createEvent( ts, *it, start, false ); } } *ts << "</table>"; } else { *ts << " "; } *ts << "</td></tr></table></td>\n"; start = start.addDays(1); } *ts << " </tr>\n"; } *ts << "</table>\n"; startmonth += 1; if ( startmonth > 12 ) { startyear += 1; startmonth = 1; } start.setYMD( startyear, startmonth, 1 ); end.setYMD(start.year(),start.month(),start.daysInMonth()); } }
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 << " "; } } *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()); } }