AlarmListViewItem::AlarmListViewItem(AlarmListView *parent, const KAEvent &event, const QDateTime &now) : EventListViewItemBase(parent, event), mMessageTruncated(false), mTimeToAlarmShown(false) { setLastColumnText(); // set the message column text DateTime dateTime = event.expired() ? event.startDateTime() : event.displayDateTime(); if(parent->column(AlarmListView::TIME_COLUMN) >= 0) setText(parent->column(AlarmListView::TIME_COLUMN), alarmTimeText(dateTime)); if(parent->column(AlarmListView::TIME_TO_COLUMN) >= 0) { QString tta = timeToAlarmText(now); setText(parent->column(AlarmListView::TIME_TO_COLUMN), tta); mTimeToAlarmShown = !tta.isNull(); } QTime t = dateTime.time(); mDateTimeOrder.sprintf("%04d%03d%02d%02d", dateTime.date().year(), dateTime.date().dayOfYear(), t.hour(), t.minute()); int repeatOrder = 0; int repeatInterval = 0; QString repeatText = event.recurrenceText(true); // text displayed in Repeat column if(repeatText.isEmpty()) repeatText = event.repetitionText(true); if(event.repeatAtLogin()) repeatOrder = 1; else { repeatInterval = event.recurInterval(); switch(event.recurType()) { case KARecurrence::MINUTELY: repeatOrder = 2; break; case KARecurrence::DAILY: repeatOrder = 3; break; case KARecurrence::WEEKLY: repeatOrder = 4; break; case KARecurrence::MONTHLY_DAY: case KARecurrence::MONTHLY_POS: repeatOrder = 5; break; case KARecurrence::ANNUAL_DATE: case KARecurrence::ANNUAL_POS: repeatOrder = 6; break; case KARecurrence::NO_RECUR: default: break; } } setText(parent->column(AlarmListView::REPEAT_COLUMN), repeatText); mRepeatOrder.sprintf("%c%08d", '0' + repeatOrder, repeatInterval); bool showColour = (event.action() == KAEvent::MESSAGE || event.action() == KAEvent::FILE); mColourOrder.sprintf("%06u", (showColour ? event.bgColour().rgb() : 0)); mTypeOrder.sprintf("%02d", event.action()); }
/****************************************************************************** * 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); }