void ResourceCached::cleanUpEventCache(const Event::List &eventList) { CalendarLocal calendar(QString::fromLatin1("UTC")); if(KStandardDirs::exists(cacheFile())) calendar.load(cacheFile()); else return; Event::List list = calendar.events(); Event::List::ConstIterator cacheIt, it; for(cacheIt = list.begin(); cacheIt != list.end(); ++cacheIt) { bool found = false; for(it = eventList.begin(); it != eventList.end(); ++it) { if((*it)->uid() == (*cacheIt)->uid()) found = true; } if(!found) { mIdMapper.removeRemoteId(mIdMapper.remoteId((*cacheIt)->uid())); Event *event = mCalendar.event((*cacheIt)->uid()); if(event) mCalendar.deleteEvent(event); } } calendar.close(); }
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; }
/* Invoked by korgac when checking alarms. Always updates the cache. */ Alarm::List ResourceExchange::alarms(const QDateTime &from, const QDateTime &to) { kdDebug(5800) << "ResourceExchange::alarms(" << from.toString() << " - " << to.toString() << ")\n"; Alarm::List list; QDate start = from.date(); QDate end = to.date(); if(mCache) { /* Clear the cache */ Event::List oldEvents = mCache->rawEvents(start, end, false); Event::List::ConstIterator it; for(it = oldEvents.begin(); it != oldEvents.end(); ++it) { mCache->deleteEvent(*it); } /* Fetch events */ mClient->downloadSynchronous(mCache, start, end, false); list = mCache->alarms(from, to); } return list; }
TEST(EventListTest, testSize) { Event::List list; EXPECT_EQ(0, list.size()); Event event(0, EventType::NOTE); list.add(event); EXPECT_EQ(1, list.size()); }
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"; }
QString ICalFormat::toString(Calendar *cal) { setTimeZone(cal->timeZoneId(), !cal->isLocalTime()); icalcomponent *calendar = mImpl->createCalendarComponent(cal); icalcomponent *component; // todos Todo::List todoList = cal->rawTodos(); Todo::List::ConstIterator it; for(it = todoList.begin(); it != todoList.end(); ++it) { // kdDebug(5800) << "ICalFormat::toString() write todo " // << (*it)->uid() << endl; component = mImpl->writeTodo(*it); icalcomponent_add_component(calendar, component); } // events Event::List events = cal->rawEvents(); Event::List::ConstIterator it2; for(it2 = events.begin(); it2 != events.end(); ++it2) { // kdDebug(5800) << "ICalFormat::toString() write event " // << (*it2)->uid() << endl; component = mImpl->writeEvent(*it2); icalcomponent_add_component(calendar, component); } // journals Journal::List journals = cal->journals(); Journal::List::ConstIterator it3; for(it3 = journals.begin(); it3 != journals.end(); ++it3) { kdDebug(5800) << "ICalFormat::toString() write journal " << (*it3)->uid() << endl; component = mImpl->writeJournal(*it3); icalcomponent_add_component(calendar, component); } QString text = QString::fromUtf8(icalcomponent_as_ical_string(calendar)); icalcomponent_free(calendar); icalmemory_free_ring(); if(!text) { setException(new ErrorFormat(ErrorFormat::SaveError, i18n("libical error"))); return QString::null; } return text; }
TEST(EventListTest, testAddWithInternalId) { Event::List list; Event a(0, EventType::NOTE); Event b(0, EventType::NOTE); int idOfA = list.add(a, 100); int idOfB = list.add(b, 2); EXPECT_EQ(100, idOfA); EXPECT_EQ(2, idOfB); EXPECT_EQ(100, list.get(0)->id); EXPECT_EQ(2, list.get(1)->id); }
TEST(EventListTest, testFindIndexFromId) { Event::List list; Event a(1, EventType::NOTE); Event b(0, EventType::NOTE); list.add(a, 0); list.add(b, 1); // aのほうがtickが大きいので, 後ろに並び替えられる EXPECT_EQ(0, list.findIndexFromId(1)); EXPECT_EQ(1, list.findIndexFromId(0)); }
TEST(EventListTest, testFindFromId) { Event::List list; Event a(0, EventType::NOTE); Event b(0, EventType::SINGER); list.add(a, 0); list.add(b, 1); EXPECT_EQ(EventType::NOTE, list.findFromId(0)->type()); EXPECT_EQ(EventType::SINGER, list.findFromId(1)->type()); EXPECT_TRUE(NULL == list.findFromId(1000)); }
TEST(EventListTest, testAddWithoutInternalId) { Event::List list; Event a(1, EventType::NOTE); Event b(0, EventType::NOTE); int idOfA = list.add(a); int idOfB = list.add(b); // bよりaのほうがtickが大きいので, 並べ替えが起きるはず EXPECT_EQ(idOfB, list.get(0)->id); EXPECT_EQ(idOfA, list.get(1)->id); EXPECT_TRUE(idOfA != idOfB); }
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; }
// taking a QDate, this function will look for an eventlist in the dict // with that date attached - Event::List ResourceExchange::rawEventsForDate(const QDate &qd, EventSortField sortField, SortDirection sortDirection) { if(!mCache) return Event::List(); // If the events for this date are not in the cache, or if they are old, // get them again QDateTime now = QDateTime::currentDateTime(); // kdDebug() << "Now is " << now.toString() << endl; // kdDebug() << "mDates: " << mDates << endl; QDate start = QDate(qd.year(), qd.month(), 1); // First day of month if(mDates && (!mDates->contains(start) || (*mCacheDates)[start].secsTo(now) > mCachedSeconds)) { QDate end = start.addMonths(1).addDays(-1); // Last day of month // Get events that occur in this period from the cache Event::List oldEvents = mCache->rawEvents(start, end, false); // And remove them all Event::List::ConstIterator it; for(it = oldEvents.begin(); it != oldEvents.end(); ++it) { mCache->deleteEvent(*it); } // FIXME: This is needed for the hack below: Event::List eventsBefore = mCache->rawEvents(); kdDebug() << "Reading events for month of " << start.toString() << endl; mClient->downloadSynchronous(mCache, start, end, true); // Show progress dialog // FIXME: This is a terrible hack! We need to install the observer for // newly downloaded events.However, downloading is done by // mClient->downloadSynchronous, where we don't have the pointer to this // available... On the other hand, here we don't really know which events // are really new. Event::List eventsAfter = mCache->rawEvents(); for(it = eventsAfter.begin(); it != eventsAfter.end(); ++it) { if(eventsBefore.find(*it) == eventsBefore.end()) { // it's a new event downloaded by downloadSynchronous -> install observer (*it)->registerObserver(this); } } mDates->add(start); mCacheDates->insert(start, now); } // Events are safely in the cache now, return them from cache Event::List events; if(mCache) events = mCache->rawEventsForDate(qd, sortField, sortDirection); // kdDebug() << "Found " << events.count() << " events." << endl; return events; }
Event::Ptr DndFactory::createDropEvent( const QMimeData *mimeData ) { //kDebug(); Event::Ptr event; MemoryCalendar::Ptr calendar( createDropCalendar( mimeData ) ); if ( calendar ) { Event::List events = calendar->events(); if ( !events.isEmpty() ) { event = Event::Ptr( new Event( *events.first() ) ); } } return event; }
Event *DndFactory::createDropEvent( const QMimeData *md ) { kDebug(); Event *ev = 0; Calendar *cal = createDropCalendar( md ); if ( cal ) { Event::List events = cal->events(); if ( !events.isEmpty() ) { ev = new Event( *events.first() ); } delete cal; } return ev; }
TEST(EventListTest, testRemoveAt) { Event::List list; Event a(0, EventType::NOTE); Event b(0, EventType::NOTE); list.add(a, 100); list.add(b, 2); EXPECT_EQ(100, list.get(0)->id); EXPECT_EQ(2, list.get(1)->id); EXPECT_EQ(2, list.size()); list.removeAt(0); EXPECT_EQ(1, list.size()); EXPECT_EQ(2, list.get(0)->id); }
Incidence::List Calendar::mergeIncidenceList(const Event::List &events, const Todo::List &todos, const Journal::List &journals) { Incidence::List incidences; Event::List::ConstIterator it1; for(it1 = events.begin(); it1 != events.end(); ++it1) incidences.append(*it1); Todo::List::ConstIterator it2; for(it2 = todos.begin(); it2 != todos.end(); ++it2) incidences.append(*it2); Journal::List::ConstIterator it3; for(it3 = journals.begin(); it3 != journals.end(); ++it3) incidences.append(*it3); return incidences; }
TEST(EventListTest, testGetAndSetElement) { Event::List list; Event a(0, EventType::NOTE); Event b(0, EventType::NOTE); list.add(a, 100); list.add(b, 2); EXPECT_EQ(100, list.get(0)->id); EXPECT_EQ(2, list.get(1)->id); Event c(480, EventType::NOTE); c.id = 99; list.set(1, c); EXPECT_EQ(100, list.get(0)->id); EXPECT_EQ(2, list.get(1)->id); EXPECT_EQ((tick_t)480, list.get(1)->tick); }
TEST(EventListTest, testIterator) { Event::List list; Event::ListIterator iterator = list.iterator(); EXPECT_TRUE(false == iterator.hasNext()); Event singerEvent(0, EventType::SINGER); singerEvent.singerHandle = Handle(HandleType::SINGER); list.add(singerEvent, 1); Event crescendoEvent(240, EventType::ICON); crescendoEvent.iconDynamicsHandle = Handle(HandleType::DYNAMICS); crescendoEvent.iconDynamicsHandle.iconId = "$05020001"; list.add(crescendoEvent, 2); iterator = list.iterator(); EXPECT_TRUE(iterator.hasNext()); EXPECT_EQ((tick_t)0, iterator.next()->tick); EXPECT_TRUE(iterator.hasNext()); EXPECT_EQ((tick_t)240, iterator.next()->tick); EXPECT_TRUE(false == iterator.hasNext()); }
/** * @brief 反復子の次の要素を探索する * @return (int) 次のインデックス */ int _nextPosition() const{ int count = _list->size(); for( int i = _pos + 1; i < count; ++i ){ const Event *item = _list->get( i ); if( _kindSinger ){ if( item->type == EventType::SINGER ){ return i; } } if( _kindNote ){ if( item->type == EventType::NOTE ){ return i; } } if( _kindDynaff || _kindCrescend || _kindDecrescend ){ if( item->type == EventType::ICON && item->iconDynamicsHandle.getHandleType() != HandleType::UNKNOWN ) { if( _kindDynaff ){ if( item->iconDynamicsHandle.isDynaffType() ){ return i; } } if( _kindCrescend ){ if( item->iconDynamicsHandle.isCrescendType() ){ return i; } } if( _kindDecrescend ){ if( item->iconDynamicsHandle.isDecrescendType() ){ return i; } } } } } return -1; }
/****************************************************************************** * 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; }
TEST(EventListTest, testClear) { Event::List list; Event b(480, EventType::NOTE); Event a(0, EventType::NOTE); list.add(b, 14); list.add(a, 20); EXPECT_EQ(2, list.size()); EXPECT_EQ(20, list.get(0)->id); list.clear(); EXPECT_EQ(0, list.size()); }
TEST(EventListTest, testSetForId) { Event::List listA; Event event(0, EventType::NOTE); event.note = 60; event.id = 10; Event replace(0, EventType::NOTE); replace.note = 90; replace.id = 100; listA.add(event, 10); listA.setForId(10, replace); EXPECT_EQ(10, listA.get(0)->id); EXPECT_EQ(90, listA.get(0)->note); // 無効なinternalIdを渡すので, setが行われない場合 Event::List listB; listB.add(event, 10); listB.setForId(9999, replace); EXPECT_EQ(60, listB.get(0)->note); }
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); }
/****************************************************************************** * Initialise or update the birthday selection list by fetching all birthdays * from the address book and displaying those which do not already have alarms. */ void BirthdayDlg::updateSelectionList() { // Compile a list of all pending alarm messages which look like birthdays QStringList messageList; KAEvent event; Event::List events = AlarmCalendar::activeCalendar()->events(); for (Event::List::ConstIterator it = events.begin(); it != events.end(); ++it) { Event* kcalEvent = *it; event.set(*kcalEvent); if (event.action() == KAEvent::MESSAGE && event.recurType() == KARecurrence::ANNUAL_DATE && (mPrefixText.isEmpty() || event.message().startsWith(mPrefixText))) messageList.append(event.message()); } // Fetch all birthdays from the address book for (KABC::AddressBook::ConstIterator abit = mAddressBook->begin(); abit != mAddressBook->end(); ++abit) { const KABC::Addressee& addressee = *abit; if (addressee.birthday().isValid()) { // Create a list entry for this birthday QDate birthday = addressee.birthday().date(); QString name = addressee.nickName(); if (name.isEmpty()) name = addressee.realName(); // Check if the birthday already has an alarm QString text = mPrefixText + name + mSuffixText; bool alarmExists = (messageList.find(text) != messageList.end()); // Check if the birthday is already in the selection list bool inSelectionList = false; AddresseeItem* item = 0; for (QListViewItem* qitem = mAddresseeList->firstChild(); qitem; qitem = qitem->nextSibling()) { item = dynamic_cast<AddresseeItem*>(qitem); if (item && item->text(AddresseeItem::NAME) == name && item->birthday() == birthday) { inSelectionList = true; break; } } if (alarmExists && inSelectionList) delete item; // alarm exists, so remove from selection list else if (!alarmExists && !inSelectionList) new AddresseeItem(mAddresseeList, name, birthday); // add to list } } // mAddresseeList->setUpdatesEnabled(true); // Enable/disable OK button according to whether anything is currently selected bool selection = false; for (QListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling()) if (mAddresseeList->isSelected(item)) { selection = true; break; } enableButtonOK(selection); }
//@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(); }
FreeBusy::FreeBusy( Calendar *calendar, const QDateTime &start, const QDateTime &end ) { kdDebug(5800) << "FreeBusy::FreeBusy" << endl; mCalendar = calendar; setDtStart(start); setDtEnd(end); // Get all the events in the calendar Event::List eventList = mCalendar->rawEvents( start.date(), end.date() ); int extraDays, i, x, duration; duration = start.daysTo(end); QDate day; QDateTime tmpStart; QDateTime tmpEnd; // Loops through every event in the calendar Event::List::ConstIterator it; for( it = eventList.begin(); it != eventList.end(); ++it ) { Event *event = *it; // The code below can not handle floating 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 floating events. Event *floatingEvent = 0; if ( event->doesFloat() ) { // Floating event. Do the hack kdDebug(5800) << "Floating event\n"; floatingEvent = new Event( *event ); // Set the start and end times to be on midnight QDateTime start( floatingEvent->dtStart().date(), QTime( 0, 0 ) ); QDateTime end( floatingEvent->dtEnd().date(), QTime( 23, 59, 59, 999 ) ); floatingEvent->setFloats( false ); floatingEvent->setDtStart( start ); floatingEvent->setDtEnd( end ); kdDebug(5800) << "Use: " << start.toString() << " to " << end.toString() << endl; // Finally, use this event for the setting below event = floatingEvent; } // This whole for loop is for recurring events, it loops through // each of the days of the freebusy request // First check if this is transparent. If it is, it shouldn't be in the // freebusy list if ( event->transparency() == Event::Transparent ) // Transparent continue; for( i = 0; i <= duration; ++i ) { day=(start.addDays(i).date()); tmpStart.setDate(day); tmpEnd.setDate(day); if( event->doesRecur() ) { 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().date().daysTo(event->dtEnd().date()); for ( x = 0; x <= extraDays; ++x ) { if ( event->recursOn(day.addDays(-x))) { tmpStart.setDate(day.addDays(-x)); tmpStart.setTime(event->dtStart().time()); tmpEnd=tmpStart.addSecs( (event->duration()) ); addLocalPeriod( tmpStart, tmpEnd ); break; } } } else { if (event->recursOn(day)) { tmpStart.setTime(event->dtStart().time()); tmpEnd.setTime(event->dtEnd().time()); addLocalPeriod (tmpStart, tmpEnd); } } } } // Non-recurring events addLocalPeriod(event->dtStart(), event->dtEnd()); // Clean up delete floatingEvent; } sortList(); }
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()); } }
TEST(EventListTest, testConstruct) { Event::List list; EXPECT_EQ(0, list.size()); }