/****************************************************************************** * Add all the current alarms to the list. */ void AlarmListView::populate() { KAEvent event; KCal::Event::List events; KCal::Event::List::ConstIterator it; QDateTime now = QDateTime::currentDateTime(); if(mShowExpired) { AlarmCalendar *cal = AlarmCalendar::expiredCalendarOpen(); if(cal) { events = cal->events(); for(it = events.begin(); it != events.end(); ++it) { KCal::Event *kcalEvent = *it; if(kcalEvent->alarms().count() > 0) { event.set(*kcalEvent); addEntry(event, now); } } } } events = AlarmCalendar::activeCalendar()->events(); for(it = events.begin(); it != events.end(); ++it) { KCal::Event *kcalEvent = *it; event.set(*kcalEvent); if(mShowExpired || !event.expired()) addEntry(event, now); } }
/****************************************************************************** * 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); }