/****************************************************************************** * 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); } }
UndoAdd::UndoAdd(Undo::Type type, const KAEvent &event, KAEvent::Status cal) : UndoItem(type), mEventID(KAEvent::uid(event.id(), cal)) { setCalendar(cal); mDescription = UndoItem::description(event); // calendar must be set before calling this }
TemplateListViewItem::TemplateListViewItem(TemplateListView* parent, const KAEvent& event) : EventListViewItemBase(parent, event) { setLastColumnText(); // set the template name column text int index; switch (event.action()) { case KAAlarm::FILE: index = 2; break; case KAAlarm::COMMAND: index = 3; break; case KAAlarm::EMAIL: index = 4; break; case KAAlarm::MESSAGE: default: index = 1; break; } mIconOrder.sprintf("%01u", index); setPixmap(templateListView()->iconColumn(), *eventIcon()); }
/****************************************************************************** * Undo the item, i.e. undo an edit to a previously existing alarm. * Create a redo item to reapply the edit. * Reply = redo item. */ UndoItem *UndoEdit::restore() { kdDebug(5950) << "UndoEdit::restore(" << mNewEventID << ")\n"; // Retrieve the current state of the alarm const KCal::Event *kcalEvent = AlarmCalendar::getEvent(mNewEventID); if(!kcalEvent) { mRestoreError = ERR_NOT_FOUND; // alarm is no longer in calendar return 0; } KAEvent newEvent(*kcalEvent); // Create a redo item to restore the edit Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE; UndoItem *undo = new UndoEdit(t, newEvent, mOldEvent->id(), mDescription); switch(calendar()) { case KAEvent::ACTIVE: switch(KAlarm::modifyEvent(newEvent, *mOldEvent, 0)) { case KAlarm::UPDATE_ERROR: case KAlarm::UPDATE_FAILED: case KAlarm::SAVE_FAILED: mRestoreError = ERR_CREATE; break; case KAlarm::UPDATE_KORG_ERR: mRestoreWarning = WARN_KORG_MODIFY; ++mRestoreWarningCount; break; default: break; } break; case KAEvent::TEMPLATE: if(KAlarm::updateTemplate(*mOldEvent, 0) != KAlarm::UPDATE_OK) mRestoreError = ERR_TEMPLATE; break; case KAEvent::EXPIRED: // editing of expired events is not allowed default: delete undo; mRestoreError = ERR_PROG; return 0; } return undo; }
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); }
/****************************************************************************** * Undo the item, i.e. restore an alarm which was deleted. * Create a redo item to delete the alarm again. * Reply = redo item. */ UndoItem *UndoDelete::restore() { kdDebug(5950) << "UndoDelete::restore(" << mEvent->id() << ")\n"; // Restore the original event switch(calendar()) { case KAEvent::ACTIVE: if(mEvent->toBeArchived()) { // It was archived when it was deleted mEvent->setUid(KAEvent::EXPIRED); switch(KAlarm::reactivateEvent(*mEvent, 0, true)) { case KAlarm::UPDATE_KORG_ERR: mRestoreWarning = WARN_KORG_ADD; ++mRestoreWarningCount; break; case KAlarm::UPDATE_ERROR: case KAlarm::UPDATE_FAILED: case KAlarm::SAVE_FAILED: mRestoreError = ERR_EXPIRED; return 0; case KAlarm::UPDATE_OK: break; } } else { switch(KAlarm::addEvent(*mEvent, 0, 0, true)) { case KAlarm::UPDATE_KORG_ERR: mRestoreWarning = WARN_KORG_ADD; ++mRestoreWarningCount; break; case KAlarm::UPDATE_ERROR: case KAlarm::UPDATE_FAILED: case KAlarm::SAVE_FAILED: mRestoreError = ERR_CREATE; return 0; case KAlarm::UPDATE_OK: break; } } break; case KAEvent::TEMPLATE: if(KAlarm::addTemplate(*mEvent, 0) != KAlarm::UPDATE_OK) { mRestoreError = ERR_CREATE; return 0; } break; case KAEvent::EXPIRED: if(!KAlarm::addExpiredEvent(*mEvent)) { mRestoreError = ERR_CREATE; return 0; } break; default: mRestoreError = ERR_PROG; return 0; } // Create a redo item to delete the alarm again return createRedo(*mEvent); }
/****************************************************************************** * Return the description of an event. */ QString UndoItem::description(const KAEvent &event) const { return (mCalendar == KAEvent::TEMPLATE) ? event.templateName() : AlarmText::summary(event); }
void Undo::saveDelete(const KAEvent &event) { new UndoDelete(UNDO, event); removeRedos(event.id()); // remove any redos which are made invalid by this deletion emitChanged(); }
void Undo::saveEdit(const KAEvent &oldEvent, const KAEvent &newEvent) { new UndoEdit(UNDO, oldEvent, newEvent.id(), AlarmText::summary(newEvent)); removeRedos(oldEvent.id()); // remove any redos which are made invalid by this edit emitChanged(); }