예제 #1
0
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
}
예제 #2
0
/******************************************************************************
*  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;
}
예제 #3
0
/******************************************************************************
*  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);
}
예제 #4
0
void Undo::saveDelete(const KAEvent &event)
{
    new UndoDelete(UNDO, event);
    removeRedos(event.id());    // remove any redos which are made invalid by this deletion
    emitChanged();
}
예제 #5
0
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();
}