/****************************************************************************** * Return a list of events for birthdays chosen. */ QValueList<KAEvent> BirthdayDlg::events() const { QValueList<KAEvent> list; QDate today = QDate::currentDate(); QDateTime todayNoon(today, QTime(12, 0, 0)); int thisYear = today.year(); int reminder = mReminder->minutes(); for (QListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling()) { if (mAddresseeList->isSelected(item)) { AddresseeItem* aItem = dynamic_cast<AddresseeItem*>(item); if (aItem) { QDate date = aItem->birthday(); date.setYMD(thisYear, date.month(), date.day()); if (date <= today) date.setYMD(thisYear + 1, date.month(), date.day()); KAEvent event(date, mPrefix->text() + aItem->text(AddresseeItem::NAME) + mSuffix->text(), mFontColourButton->bgColour(), mFontColourButton->fgColour(), mFontColourButton->font(), KAEvent::MESSAGE, mLateCancel->minutes(), mFlags); float fadeVolume; int fadeSecs; float volume = mSoundPicker->volume(fadeVolume, fadeSecs); event.setAudioFile(mSoundPicker->file(), volume, fadeVolume, fadeSecs); QValueList<int> months; months.append(date.month()); event.setRecurAnnualByDate(1, months, 0, Preferences::defaultFeb29Type(), -1, QDate()); event.setRepetition(mSubRepetition->interval(), mSubRepetition->count()); event.setNextOccurrence(todayNoon); if (reminder) event.setReminder(reminder, false); if (mSpecialActionsButton) event.setActions(mSpecialActionsButton->preAction(), mSpecialActionsButton->postAction()); list.append(event); } } } return list; }
/****************************************************************************** * 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); }