• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
undo.cpp
Go to the documentation of this file.
1 /*
2  * undo.cpp - undo/redo facility
3  * Program: kalarm
4  * Copyright © 2005-2014 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h" //krazy:exclude=includes (kalarm.h must be first)
22 #include "undo.h"
23 
24 #include "alarmcalendar.h"
25 #include "functions.h"
26 #include "messagebox.h"
27 
28 #include <kalarmcal/alarmtext.h>
29 #include <kalarmcal/kaevent.h>
30 
31 #include <kapplication.h>
32 #include <klocale.h>
33 #include <kdebug.h>
34 
35 static int maxCount = 12;
36 
37 #ifdef DELETE
38 #undef DELETE // conflicting Windows macro
39 #endif
40 
41 // Simplify access to Undo::Event struct
42 #ifdef USE_AKONADI
43 #define RESOURCE_PARAM_TYPE const Collection&
44 #define EVENT_RESOURCE collection
45 #else
46 #define RESOURCE_PARAM_TYPE AlarmResource*
47 #define EVENT_RESOURCE resource
48 #endif
49 
50 #ifdef USE_AKONADI
51 using namespace Akonadi;
52 #endif
53 
54 class UndoItem
55 {
56  public:
57  enum Operation { ADD, EDIT, DELETE, REACTIVATE, DEACTIVATE, MULTI };
58  UndoItem(); // needed by QList
59  virtual ~UndoItem();
60  virtual Operation operation() const = 0;
61  virtual QString actionText() const { return !mName.isEmpty() ? mName : defaultActionText(); }
62  virtual QString defaultActionText() const = 0;
63  virtual QString description() const { return QString(); }
64  virtual QString eventID() const { return QString(); }
65  virtual QString oldEventID() const { return QString(); }
66  virtual QString newEventID() const { return QString(); }
67 #ifdef USE_AKONADI
68  virtual Collection collection() const { return Collection(); }
69 #else
70  virtual AlarmResource* resource() const { return 0; }
71 #endif
72  int id() const { return mId; }
73  Undo::Type type() const { return mType; }
74  void setType(Undo::Type t) { mType = t; }
75  CalEvent::Type calendar() const { return mCalendar; }
76  virtual void setCalendar(CalEvent::Type s) { mCalendar = s; }
77  virtual UndoItem* restore() = 0;
78  virtual bool deleteID(const QString& /*id*/) { return false; }
79 
80  enum Error { ERR_NONE, ERR_PROG, ERR_NOT_FOUND, ERR_CREATE, ERR_TEMPLATE, ERR_ARCHIVED };
81  enum Warning { WARN_NONE, WARN_KORG_ADD, WARN_KORG_MODIFY, WARN_KORG_DELETE };
82  static int mLastId;
83  static Error mRestoreError; // error code valid only if restore() returns 0
84  static Warning mRestoreWarning; // warning code set by restore()
85  static KAlarm::UpdateResult mRestoreWarningKorg; // KOrganizer error status set by restore()
86  static int mRestoreWarningCount; // item count for mRestoreWarning (to allow i18n messages to work correctly)
87 
88  protected:
89  UndoItem(Undo::Type, const QString& name = QString());
90  static QString addDeleteActionText(CalEvent::Type, bool add);
91  QString description(const KAEvent&) const;
92  void replaceWith(UndoItem* item) { Undo::replace(this, item); }
93 
94  QString mName; // specified action name (overrides default)
95  int mId; // unique identifier (only for mType = UNDO, REDO)
96  Undo::Type mType; // which list (if any) the object is in
97  CalEvent::Type mCalendar;
98 };
99 
100 class UndoMultiBase : public UndoItem
101 {
102  public:
103  UndoMultiBase(Undo::Type t, const QString& name)
104  : UndoItem(t, name), mUndos(new Undo::List) { }
105  UndoMultiBase(Undo::Type t, Undo::List* undos, const QString& name)
106  : UndoItem(t, name), mUndos(undos) { }
107  ~UndoMultiBase() { delete mUndos; }
108  const Undo::List* undos() const { return mUndos; }
109  protected:
110  Undo::List* mUndos; // this list must always have >= 2 entries
111 };
112 
113 template <class T> class UndoMulti : public UndoMultiBase
114 {
115  public:
116  UndoMulti(Undo::Type, const Undo::EventList&, const QString& name);
117  UndoMulti(Undo::Type t, Undo::List* undos, const QString& name) : UndoMultiBase(t, undos, name) { }
118  virtual Operation operation() const { return MULTI; }
119  virtual UndoItem* restore();
120  virtual bool deleteID(const QString& id);
121  virtual UndoItem* createRedo(Undo::List*) = 0;
122 };
123 
124 class UndoAdd : public UndoItem
125 {
126  public:
127  UndoAdd(Undo::Type, const Undo::Event&, const QString& name = QString());
128  UndoAdd(Undo::Type, const KAEvent&, RESOURCE_PARAM_TYPE, const QString& name = QString());
129  UndoAdd(Undo::Type, const KAEvent&, RESOURCE_PARAM_TYPE, const QString& name, CalEvent::Type);
130  virtual Operation operation() const { return ADD; }
131  virtual QString defaultActionText() const;
132  virtual QString description() const { return mDescription; }
133 #ifdef USE_AKONADI
134  virtual Collection collection() const { return mResource; }
135 #else
136  virtual AlarmResource* resource() const { return mResource; }
137 #endif
138  virtual QString eventID() const { return mEventId; }
139  virtual QString newEventID() const { return mEventId; }
140  virtual UndoItem* restore() { return doRestore(); }
141  protected:
142  UndoItem* doRestore(bool setArchive = false);
143  virtual UndoItem* createRedo(const KAEvent&, RESOURCE_PARAM_TYPE);
144  private:
145 #ifdef USE_AKONADI
146  Collection mResource; // collection containing the event
147 #else
148  AlarmResource* mResource; // resource calendar containing the event
149 #endif
150  QString mEventId;
151  QString mDescription;
152 };
153 
154 class UndoEdit : public UndoItem
155 {
156  public:
157  UndoEdit(Undo::Type, const KAEvent& oldEvent, const QString& newEventID,
158  RESOURCE_PARAM_TYPE, const QStringList& dontShowErrors, const QString& description);
159  ~UndoEdit();
160  virtual Operation operation() const { return EDIT; }
161  virtual QString defaultActionText() const;
162  virtual QString description() const { return mDescription; }
163 #ifdef USE_AKONADI
164  virtual Collection collection() const { return mResource; }
165 #else
166  virtual AlarmResource* resource() const { return mResource; }
167 #endif
168  virtual QString eventID() const { return mNewEventId; }
169  virtual QString oldEventID() const { return mOldEvent->id(); }
170  virtual QString newEventID() const { return mNewEventId; }
171  virtual UndoItem* restore();
172  private:
173 #ifdef USE_AKONADI
174  Collection mResource; // collection containing the event
175 #else
176  AlarmResource* mResource; // resource calendar containing the event
177 #endif
178  KAEvent* mOldEvent;
179  QString mNewEventId;
180  QString mDescription;
181  QStringList mDontShowErrors;
182 };
183 
184 class UndoDelete : public UndoItem
185 {
186  public:
187  UndoDelete(Undo::Type, const Undo::Event&, const QString& name = QString());
188  UndoDelete(Undo::Type, const KAEvent&, RESOURCE_PARAM_TYPE, const QStringList& dontShowErrors, const QString& name = QString());
189  ~UndoDelete();
190  virtual Operation operation() const { return DELETE; }
191  virtual QString defaultActionText() const;
192  virtual QString description() const { return UndoItem::description(*mEvent); }
193 #ifdef USE_AKONADI
194  virtual Collection collection() const { return mResource; }
195 #else
196  virtual AlarmResource* resource() const { return mResource; }
197 #endif
198  virtual QString eventID() const { return mEvent->id(); }
199  virtual QString oldEventID() const { return mEvent->id(); }
200  virtual UndoItem* restore();
201  KAEvent* event() const { return mEvent; }
202  protected:
203  virtual UndoItem* createRedo(const KAEvent&, RESOURCE_PARAM_TYPE);
204  private:
205 #ifdef USE_AKONADI
206  Collection mResource; // collection containing the event
207 #else
208  AlarmResource* mResource; // resource calendar containing the event
209 #endif
210  KAEvent* mEvent;
211  QStringList mDontShowErrors;
212 };
213 
214 class UndoReactivate : public UndoAdd
215 {
216  public:
217  UndoReactivate(Undo::Type t, const Undo::Event& e, const QString& name = QString())
218  : UndoAdd(t, e.event, e.EVENT_RESOURCE, name, CalEvent::ACTIVE) { }
219  UndoReactivate(Undo::Type t, const KAEvent& e, RESOURCE_PARAM_TYPE r, const QString& name = QString())
220  : UndoAdd(t, e, r, name, CalEvent::ACTIVE) { }
221  virtual Operation operation() const { return REACTIVATE; }
222  virtual QString defaultActionText() const;
223  virtual UndoItem* restore();
224  protected:
225  virtual UndoItem* createRedo(const KAEvent&, RESOURCE_PARAM_TYPE);
226 };
227 
228 class UndoDeactivate : public UndoDelete
229 {
230  public:
231  UndoDeactivate(Undo::Type t, const KAEvent& e, RESOURCE_PARAM_TYPE r, const QString& name = QString())
232  : UndoDelete(t, e, r, QStringList(), name) { }
233  virtual Operation operation() const { return DEACTIVATE; }
234  virtual QString defaultActionText() const;
235  virtual UndoItem* restore();
236  protected:
237  virtual UndoItem* createRedo(const KAEvent&, RESOURCE_PARAM_TYPE);
238 };
239 
240 class UndoAdds : public UndoMulti<UndoAdd>
241 {
242  public:
243  UndoAdds(Undo::Type t, const Undo::EventList& events, const QString& name = QString())
244  : UndoMulti<UndoAdd>(t, events, name) { } // UNDO only
245  UndoAdds(Undo::Type t, Undo::List* undos, const QString& name)
246  : UndoMulti<UndoAdd>(t, undos, name) { }
247  virtual QString defaultActionText() const;
248  virtual UndoItem* createRedo(Undo::List*);
249 };
250 
251 class UndoDeletes : public UndoMulti<UndoDelete>
252 {
253  public:
254  UndoDeletes(Undo::Type t, const Undo::EventList& events, const QString& name = QString())
255  : UndoMulti<UndoDelete>(t, events, name) { } // UNDO only
256  UndoDeletes(Undo::Type t, Undo::List* undos, const QString& name)
257  : UndoMulti<UndoDelete>(t, undos, name) { }
258  virtual QString defaultActionText() const;
259  virtual UndoItem* createRedo(Undo::List*);
260 };
261 
262 class UndoReactivates : public UndoMulti<UndoReactivate>
263 {
264  public:
265  UndoReactivates(Undo::Type t, const Undo::EventList& events, const QString& name = QString())
266  : UndoMulti<UndoReactivate>(t, events, name) { } // UNDO only
267  UndoReactivates(Undo::Type t, Undo::List* undos, const QString& name)
268  : UndoMulti<UndoReactivate>(t, undos, name) { }
269  virtual QString defaultActionText() const;
270  virtual UndoItem* createRedo(Undo::List*);
271 };
272 
273 Undo* Undo::mInstance = 0;
274 Undo::List Undo::mUndoList;
275 Undo::List Undo::mRedoList;
276 
277 
278 /******************************************************************************
279 * Create the one and only instance of the Undo class.
280 */
281 Undo* Undo::instance()
282 {
283  if (!mInstance)
284  mInstance = new Undo(kapp);
285  return mInstance;
286 }
287 
288 /******************************************************************************
289 * Clear the lists of undo and redo items.
290 */
291 void Undo::clear()
292 {
293  if (!mUndoList.isEmpty() || !mRedoList.isEmpty())
294  {
295  mInstance->blockSignals(true);
296  while (!mUndoList.isEmpty())
297  delete mUndoList.first(); // N.B. 'delete' removes the object from the list
298  while (!mRedoList.isEmpty())
299  delete mRedoList.first(); // N.B. 'delete' removes the object from the list
300  mInstance->blockSignals(false);
301  emitChanged();
302  }
303 }
304 
305 /******************************************************************************
306 * Create an undo item and add it to the list of undos.
307 * N.B. The base class constructor adds the object to the undo list.
308 */
309 void Undo::saveAdd(const KAEvent& event, RESOURCE_PARAM_TYPE resource, const QString& name)
310 {
311  new UndoAdd(UNDO, event, resource, name);
312  emitChanged();
313 }
314 
315 void Undo::saveAdds(const Undo::EventList& events, const QString& name)
316 {
317  int count = events.count();
318  if (count == 1)
319  saveAdd(events.first().event, events.first().EVENT_RESOURCE, name);
320  else if (count > 1)
321  {
322  new UndoAdds(UNDO, events, name);
323  emitChanged();
324  }
325 }
326 
327 void Undo::saveEdit(const Undo::Event& oldEvent, const KAEvent& newEvent)
328 {
329  new UndoEdit(UNDO, oldEvent.event, newEvent.id(), oldEvent.EVENT_RESOURCE, oldEvent.dontShowErrors, AlarmText::summary(newEvent));
330  removeRedos(oldEvent.event.id()); // remove any redos which are made invalid by this edit
331  emitChanged();
332 }
333 
334 void Undo::saveDelete(const Undo::Event& event, const QString& name)
335 {
336  new UndoDelete(UNDO, event.event, event.EVENT_RESOURCE, event.dontShowErrors, name);
337  removeRedos(event.event.id()); // remove any redos which are made invalid by this deletion
338  emitChanged();
339 }
340 
341 void Undo::saveDeletes(const Undo::EventList& events, const QString& name)
342 {
343  int count = events.count();
344  if (count == 1)
345  saveDelete(events[0], name);
346  else if (count > 1)
347  {
348  new UndoDeletes(UNDO, events, name);
349  for (int i = 0, end = events.count(); i < end; ++i)
350  removeRedos(events[i].event.id()); // remove any redos which are made invalid by these deletions
351  emitChanged();
352  }
353 }
354 
355 void Undo::saveReactivate(const KAEvent& event, RESOURCE_PARAM_TYPE resource, const QString& name)
356 {
357  new UndoReactivate(UNDO, event, resource, name);
358  emitChanged();
359 }
360 
361 void Undo::saveReactivates(const EventList& events, const QString& name)
362 {
363  int count = events.count();
364  if (count == 1)
365  saveReactivate(events[0].event, events[0].EVENT_RESOURCE, name);
366  else if (count > 1)
367  {
368  new UndoReactivates(UNDO, events, name);
369  emitChanged();
370  }
371 }
372 
373 /******************************************************************************
374 * Remove any redos which are made invalid by a new undo.
375 */
376 void Undo::removeRedos(const QString& eventID)
377 {
378  QString id = eventID;
379  for (int i = 0; i < mRedoList.count(); )
380  {
381  UndoItem* item = mRedoList[i];
382 //kDebug()<<item->eventID()<<" (looking for"<<id<<")";
383  if (item->operation() == UndoItem::MULTI)
384  {
385  if (item->deleteID(id))
386  {
387  // The old multi-redo was replaced with a new single redo
388  delete item; // N.B. 'delete' removes the object from the list
389  }
390  }
391  else if (item->eventID() == id)
392  {
393  if (item->operation() == UndoItem::EDIT)
394  id = item->oldEventID(); // continue looking for its post-edit ID
395  delete item; // N.B. 'delete' removes the object from the list
396  }
397  else
398  ++i;
399  }
400 }
401 
402 /******************************************************************************
403 * Undo or redo a specified item.
404 * Reply = true if success, or if the item no longer exists.
405 */
406 bool Undo::undo(int i, Undo::Type type, QWidget* parent, const QString& action)
407 {
408  UndoItem::mRestoreError = UndoItem::ERR_NONE;
409  UndoItem::mRestoreWarning = UndoItem::WARN_NONE;
410  UndoItem::mRestoreWarningKorg = KAlarm::UPDATE_OK;
411  UndoItem::mRestoreWarningCount = 0;
412  List& list = (type == UNDO) ? mUndoList : mRedoList;
413  if (i < list.count() && list[i]->type() == type)
414  {
415  list[i]->restore();
416  delete list[i]; // N.B. 'delete' removes the object from its list
417  emitChanged();
418  }
419 
420  QString err;
421  switch (UndoItem::mRestoreError)
422  {
423  case UndoItem::ERR_NONE:
424  {
425  KAlarm::UpdateError errcode;
426  switch (UndoItem::mRestoreWarning)
427  {
428  case UndoItem::WARN_KORG_ADD: errcode = KAlarm::ERR_ADD; break;
429  case UndoItem::WARN_KORG_MODIFY: errcode = KAlarm::ERR_MODIFY; break;
430  case UndoItem::WARN_KORG_DELETE: errcode = KAlarm::ERR_DELETE; break;
431  case UndoItem::WARN_NONE:
432  default:
433  return true;
434  }
435  KAlarm::displayKOrgUpdateError(parent, errcode, UndoItem::mRestoreWarningKorg, UndoItem::mRestoreWarningCount);
436  return true;
437  }
438  case UndoItem::ERR_NOT_FOUND: err = i18nc("@info/plain", "Alarm not found"); break;
439  case UndoItem::ERR_CREATE: err = i18nc("@info/plain", "Error recreating alarm"); break;
440  case UndoItem::ERR_TEMPLATE: err = i18nc("@info/plain", "Error recreating alarm template"); break;
441  case UndoItem::ERR_ARCHIVED: err = i18nc("@info/plain", "Cannot reactivate archived alarm"); break;
442  case UndoItem::ERR_PROG: err = i18nc("@info/plain", "Program error"); break;
443  default: err = i18nc("@info/plain", "Unknown error"); break;
444  }
445  KAMessageBox::sorry(parent, i18nc("@info Undo-action: message", "%1: %2", action, err));
446  return false;
447 }
448 
449 /******************************************************************************
450 * Add an undo item to the start of one of the lists.
451 */
452 void Undo::add(UndoItem* item, bool undo)
453 {
454  if (item)
455  {
456  // Limit the number of items stored
457  int undoCount = mUndoList.count();
458  int redoCount = mRedoList.count();
459  if (undoCount + redoCount >= maxCount - 1)
460  {
461  if (undoCount)
462  mUndoList.pop_back();
463  else
464  mRedoList.pop_back();
465  }
466 
467  // Append the new item
468  List* list = undo ? &mUndoList : &mRedoList;
469  list->prepend(item);
470  }
471 }
472 
473 /******************************************************************************
474 * Remove an undo item from one of the lists.
475 */
476 void Undo::remove(UndoItem* item, bool undo)
477 {
478  List* list = undo ? &mUndoList : &mRedoList;
479  if (!list->isEmpty())
480  list->removeAt(list->indexOf(item));
481 }
482 
483 /******************************************************************************
484 * Replace an undo item in one of the lists.
485 */
486 void Undo::replace(UndoItem* old, UndoItem* New)
487 {
488  Type type = old->type();
489  List* list = (type == UNDO) ? &mUndoList : (type == REDO) ? &mRedoList : 0;
490  if (!list)
491  return;
492  int i = list->indexOf(old);
493  if (i >= 0)
494  {
495  New->setType(type); // ensure the item points to the correct list
496  (*list)[i] = New;
497  old->setType(NONE); // mark the old item as no longer being in a list
498  }
499 }
500 
501 /******************************************************************************
502 * Return the action description of the latest undo/redo item.
503 */
504 QString Undo::actionText(Undo::Type type)
505 {
506  List* list = (type == UNDO) ? &mUndoList : (type == REDO) ? &mRedoList : 0;
507  return (list && !list->isEmpty()) ? (*list)[0]->actionText() : QString();
508 }
509 
510 /******************************************************************************
511 * Return the action description of the undo/redo item with the specified ID.
512 */
513 QString Undo::actionText(Undo::Type type, int id)
514 {
515  UndoItem* undo = getItem(id, type);
516  return undo ? undo->actionText() : QString();
517 }
518 
519 /******************************************************************************
520 * Return the alarm description of the undo/redo item with the specified ID.
521 */
522 QString Undo::description(Undo::Type type, int id)
523 {
524  UndoItem* undo = getItem(id, type);
525  return undo ? undo->description() : QString();
526 }
527 
528 /******************************************************************************
529 * Return the descriptions of all undo or redo items, in order latest first.
530 * For alarms which have undergone more than one change, only the first one is
531 * listed, to force dependent undos to be executed in their correct order.
532 * If 'ids' is non-null, also returns a list of their corresponding IDs.
533 */
534 QList<int> Undo::ids(Undo::Type type)
535 {
536  QList<int> ids;
537  QStringList ignoreIDs;
538 //int n=0;
539  List* list = (type == UNDO) ? &mUndoList : (type == REDO) ? &mRedoList : 0;
540  if (!list)
541  return ids;
542  for (int i = 0, end = list->count(); i < end; ++i)
543  {
544  // Check whether this item should be ignored because it is a
545  // dependent undo. If not, add this item's ID to the ignore list.
546  UndoItem* item = (*list)[i];
547  bool omit = false;
548  if (item->operation() == UndoItem::MULTI)
549  {
550  // If any item in a multi-undo is disqualified, omit the whole multi-undo
551  QStringList newIDs;
552  const Undo::List* undos = ((UndoMultiBase*)item)->undos();
553  for (int u = 0, uend = undos->count(); u < uend; ++u)
554  {
555  QString evid = (*undos)[u]->eventID();
556  if (ignoreIDs.contains(evid))
557  omit = true;
558  else if (omit)
559  ignoreIDs.append(evid);
560  else
561  newIDs.append(evid);
562  }
563  if (omit)
564  {
565  for (int i = 0, iend = newIDs.count(); i < iend; ++i)
566  ignoreIDs.append(newIDs[i]);
567  }
568  }
569  else
570  {
571  omit = ignoreIDs.contains(item->eventID());
572  if (!omit)
573  ignoreIDs.append(item->eventID());
574  if (item->operation() == UndoItem::EDIT)
575  ignoreIDs.append(item->oldEventID()); // continue looking for its post-edit ID
576  }
577  if (!omit)
578  ids.append(item->id());
579 //else kDebug()<<"Undo::ids(): omit"<<item->actionText()<<":"<<item->description();
580  }
581 //kDebug()<<"Undo::ids():"<<n<<" ->"<<ids.count();
582  return ids;
583 }
584 
585 /******************************************************************************
586 * Emit the appropriate 'changed' signal.
587 */
588 void Undo::emitChanged()
589 {
590  if (mInstance)
591  mInstance->emitChanged(actionText(UNDO), actionText(REDO));
592 }
593 
594 /******************************************************************************
595 * Return the item with the specified ID.
596 */
597 UndoItem* Undo::getItem(int id, Undo::Type type)
598 {
599  List* list = (type == UNDO) ? &mUndoList : (type == REDO) ? &mRedoList : 0;
600  if (list)
601  {
602  for (int i = 0, end = list->count(); i < end; ++i)
603  {
604  if ((*list)[i]->id() == id)
605  return (*list)[i];
606  }
607  }
608  return 0;
609 }
610 
611 /******************************************************************************
612 * Find an item with the specified ID.
613 */
614 int Undo::findItem(int id, Undo::Type type)
615 {
616  List& list = (type == UNDO) ? mUndoList : mRedoList;
617  int i = 0;
618  for (int end = list.count(); i < end; ++i)
619  {
620  if (list[i]->id() == id)
621  break;
622  }
623  return i;
624 }
625 
626 
627 /*=============================================================================
628 = Class: UndoItem
629 = A single undo action.
630 =============================================================================*/
631 int UndoItem::mLastId = 0;
632 UndoItem::Error UndoItem::mRestoreError;
633 UndoItem::Warning UndoItem::mRestoreWarning;
634 KAlarm::UpdateResult UndoItem::mRestoreWarningKorg;
635 int UndoItem::mRestoreWarningCount;
636 
637 /******************************************************************************
638 * Constructor.
639 * Optionally appends the undo to the list of undos.
640 */
641 UndoItem::UndoItem(Undo::Type type, const QString& name)
642  : mName(name),
643  mId(0),
644  mType(type),
645  mCalendar(CalEvent::EMPTY)
646 {
647  if (type != Undo::NONE)
648  {
649  mId = ++mLastId;
650  if (mId < 0)
651  mId = mLastId = 1; // wrap round if we reach a negative number
652  Undo::add(this, (mType == Undo::UNDO));
653  }
654 }
655 
656 /******************************************************************************
657 * Destructor.
658 * Removes the undo from the list (if it's in the list).
659 */
660 UndoItem::~UndoItem()
661 {
662  if (mType != Undo::NONE)
663  Undo::remove(this, (mType == Undo::UNDO));
664 }
665 
666 /******************************************************************************
667 * Return the description of an event.
668 */
669 QString UndoItem::description(const KAEvent& event) const
670 {
671  return (mCalendar == CalEvent::TEMPLATE) ? event.templateName() : AlarmText::summary(event);
672 }
673 
674 /******************************************************************************
675 * Return the action description of an add or delete Undo/Redo item for displaying.
676 */
677 QString UndoItem::addDeleteActionText(CalEvent::Type calendar, bool add)
678 {
679  switch (calendar)
680  {
681  case CalEvent::ACTIVE:
682  if (add)
683  return i18nc("@info/plain Action to create a new alarm", "New alarm");
684  else
685  return i18nc("@info/plain Action to delete an alarm", "Delete alarm");
686  case CalEvent::TEMPLATE:
687  if (add)
688  return i18nc("@info/plain Action to create a new alarm template", "New template");
689  else
690  return i18nc("@info/plain Action to delete an alarm template", "Delete template");
691  case CalEvent::ARCHIVED:
692  return i18nc("@info/plain", "Delete archived alarm");
693  default:
694  break;
695  }
696  return QString();
697 }
698 
699 
700 /*=============================================================================
701 = Class: UndoMultiBase
702 = Undo item for multiple alarms.
703 =============================================================================*/
704 
705 template <class T>
706 UndoMulti<T>::UndoMulti(Undo::Type type, const Undo::EventList& events, const QString& name)
707  : UndoMultiBase(type, name) // UNDO only
708 {
709  for (int i = 0, end = events.count(); i < end; ++i)
710  mUndos->append(new T(Undo::NONE, events[i]));
711 }
712 
713 /******************************************************************************
714 * Undo the item, i.e. restore multiple alarms which were deleted (or delete
715 * alarms which were restored).
716 * Create a redo item to delete (or restore) the alarms again.
717 * Reply = redo item.
718 */
719 template <class T>
720 UndoItem* UndoMulti<T>::restore()
721 {
722  Undo::List* newUndos = new Undo::List;
723  for (int i = 0, end = mUndos->count(); i < end; ++i)
724  {
725  UndoItem* undo = (*mUndos)[i]->restore();
726  if (undo)
727  newUndos->append(undo);
728  }
729  if (newUndos->isEmpty())
730  {
731  delete newUndos;
732  return 0;
733  }
734 
735  // Create a redo item to delete the alarm again
736  return createRedo(newUndos);
737 }
738 
739 /******************************************************************************
740 * If one of the multiple items has the specified ID, delete it.
741 * If an item is deleted and there is only one item left, the UndoMulti
742 * instance is removed from its list and replaced by the remaining UndoItem instead.
743 * Reply = true if this instance was replaced. The caller must delete it.
744 * = false otherwise.
745 */
746 template <class T>
747 bool UndoMulti<T>::deleteID(const QString& id)
748 {
749  for (int i = 0, end = mUndos->count(); i < end; ++i)
750  {
751  UndoItem* item = (*mUndos)[i];
752  if (item->eventID() == id)
753  {
754  // Found a matching entry - remove it
755  mUndos->removeAt(i);
756  if (mUndos->count() == 1)
757  {
758  // There is only one entry left after removal.
759  // Replace 'this' multi instance with the remaining single entry.
760  replaceWith(item);
761  return true;
762  }
763  else
764  {
765  delete item;
766  return false;
767  }
768  }
769  }
770  return false;
771 }
772 
773 
774 /*=============================================================================
775 = Class: UndoAdd
776 = Undo item for alarm creation.
777 =============================================================================*/
778 
779 UndoAdd::UndoAdd(Undo::Type type, const Undo::Event& undo, const QString& name)
780  : UndoItem(type, name),
781  mResource(undo.EVENT_RESOURCE),
782  mEventId(undo.event.id())
783 {
784  setCalendar(undo.event.category());
785  mDescription = UndoItem::description(undo.event); // calendar must be set before calling this
786 }
787 
788 UndoAdd::UndoAdd(Undo::Type type, const KAEvent& event, RESOURCE_PARAM_TYPE resource, const QString& name)
789  : UndoItem(type, name),
790  mResource(resource),
791  mEventId(event.id())
792 {
793  setCalendar(event.category());
794  mDescription = UndoItem::description(event); // calendar must be set before calling this
795 }
796 
797 UndoAdd::UndoAdd(Undo::Type type, const KAEvent& event, RESOURCE_PARAM_TYPE resource, const QString& name, CalEvent::Type cal)
798  : UndoItem(type, name),
799  mResource(resource),
800  mEventId(CalEvent::uid(event.id(), cal)) // convert if old-style event ID
801 {
802  setCalendar(cal);
803  mDescription = UndoItem::description(event); // calendar must be set before calling this
804 }
805 
806 /******************************************************************************
807 * Undo the item, i.e. delete the alarm which was added.
808 * Create a redo item to add the alarm back again.
809 * Reply = redo item.
810 */
811 UndoItem* UndoAdd::doRestore(bool setArchive)
812 {
813  // Retrieve the current state of the alarm
814  kDebug() << mEventId;
815 #ifdef USE_AKONADI
816  const KAEvent* ev = AlarmCalendar::getEvent(EventId(mResource.id(), mEventId));
817 #else
818  const KAEvent* ev = AlarmCalendar::getEvent(mEventId);
819 #endif
820  if (!ev)
821  {
822  mRestoreError = ERR_NOT_FOUND; // alarm is no longer in calendar
823  return 0;
824  }
825  KAEvent event(*ev);
826 
827  // Create a redo item to recreate the alarm.
828  // Do it now, since 'event' gets modified by KAlarm::deleteEvent()
829  UndoItem* undo = createRedo(event, mResource);
830 
831  switch (calendar())
832  {
833  case CalEvent::ACTIVE:
834  {
835  if (setArchive)
836  event.setArchive();
837  // Archive it if it has already triggered
838  KAlarm::UpdateResult status = KAlarm::deleteEvent(event, true);
839  switch (status.status)
840  {
841  case KAlarm::UPDATE_ERROR:
842  case KAlarm::UPDATE_FAILED:
843  case KAlarm::SAVE_FAILED:
844  mRestoreError = ERR_CREATE;
845  break;
846  case KAlarm::UPDATE_KORG_FUNCERR:
847  case KAlarm::UPDATE_KORG_ERRINIT:
848  case KAlarm::UPDATE_KORG_ERRSTART:
849  case KAlarm::UPDATE_KORG_ERR:
850  mRestoreWarning = WARN_KORG_DELETE;
851  ++mRestoreWarningCount;
852  if (status.status > mRestoreWarningKorg.status)
853  mRestoreWarningKorg = status;
854  break;
855  default:
856  break;
857  }
858  break;
859  }
860  case CalEvent::TEMPLATE:
861 #ifdef USE_AKONADI
862  if (KAlarm::deleteTemplate(event) != KAlarm::UPDATE_OK)
863 #else
864  if (KAlarm::deleteTemplate(event.id()) != KAlarm::UPDATE_OK)
865 #endif
866  mRestoreError = ERR_TEMPLATE;
867  break;
868  case CalEvent::ARCHIVED: // redoing the deletion of an archived alarm
869  KAlarm::deleteEvent(event);
870  break;
871  default:
872  delete undo;
873  mRestoreError = ERR_PROG;
874  return 0;
875  }
876  return undo;
877 }
878 
879 /******************************************************************************
880 * Create a redo item to add the alarm back again.
881 */
882 UndoItem* UndoAdd::createRedo(const KAEvent& event, RESOURCE_PARAM_TYPE resource)
883 {
884  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
885  return new UndoDelete(t, event, resource, QStringList(), mName);
886 }
887 
888 /******************************************************************************
889 * Return the action description of the Undo item for displaying.
890 */
891 QString UndoAdd::defaultActionText() const
892 {
893  return addDeleteActionText(calendar(), (type() == Undo::UNDO));
894 }
895 
896 
897 /*=============================================================================
898 = Class: UndoAdds
899 = Undo item for multiple alarm creation.
900 =============================================================================*/
901 
902 /******************************************************************************
903 * Create a redo item to add the alarms again.
904 */
905 UndoItem* UndoAdds::createRedo(Undo::List* undos)
906 {
907  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
908  return new UndoAdds(t, undos, mName);
909 }
910 
911 /******************************************************************************
912 * Return the action description of the Undo item for displaying.
913 */
914 QString UndoAdds::defaultActionText() const
915 {
916  return i18nc("@info/plain", "Create multiple alarms");
917 }
918 
919 
920 /*=============================================================================
921 = Class: UndoEdit
922 = Undo item for alarm edit.
923 =============================================================================*/
924 
925 UndoEdit::UndoEdit(Undo::Type type, const KAEvent& oldEvent, const QString& newEventID,
926  RESOURCE_PARAM_TYPE resource, const QStringList& dontShowErrors, const QString& description)
927  : UndoItem(type),
928  mResource(resource),
929  mOldEvent(new KAEvent(oldEvent)),
930  mNewEventId(newEventID),
931  mDescription(description),
932  mDontShowErrors(dontShowErrors)
933 {
934  setCalendar(oldEvent.category());
935 }
936 
937 UndoEdit::~UndoEdit()
938 {
939  delete mOldEvent;
940 }
941 
942 /******************************************************************************
943 * Undo the item, i.e. undo an edit to a previously existing alarm.
944 * Create a redo item to reapply the edit.
945 * Reply = redo item.
946 */
947 UndoItem* UndoEdit::restore()
948 {
949  kDebug() << mNewEventId;
950  // Retrieve the current state of the alarm
951 #ifdef USE_AKONADI
952  const KAEvent* event = AlarmCalendar::getEvent(EventId(mResource.id(), mNewEventId));
953 #else
954  const KAEvent* event = AlarmCalendar::getEvent(mNewEventId);
955 #endif
956  if (!event)
957  {
958  mRestoreError = ERR_NOT_FOUND; // alarm is no longer in calendar
959  return 0;
960  }
961  KAEvent newEvent(*event);
962 
963  // Create a redo item to restore the edit
964  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
965 #ifdef USE_AKONADI
966  UndoItem* undo = new UndoEdit(t, newEvent, mOldEvent->id(), mResource, KAlarm::dontShowErrors(EventId(newEvent)), mDescription);
967 #else
968  UndoItem* undo = new UndoEdit(t, newEvent, mOldEvent->id(), mResource, KAlarm::dontShowErrors(mNewEventId), mDescription);
969 #endif
970 
971  switch (calendar())
972  {
973  case CalEvent::ACTIVE:
974  {
975  KAlarm::UpdateResult status = KAlarm::modifyEvent(newEvent, *mOldEvent);
976  switch (status.status)
977  {
978  case KAlarm::UPDATE_ERROR:
979  case KAlarm::UPDATE_FAILED:
980  case KAlarm::SAVE_FAILED:
981  mRestoreError = ERR_CREATE;
982  break;
983  case KAlarm::UPDATE_KORG_FUNCERR:
984  case KAlarm::UPDATE_KORG_ERRINIT:
985  case KAlarm::UPDATE_KORG_ERRSTART:
986  case KAlarm::UPDATE_KORG_ERR:
987  mRestoreWarning = WARN_KORG_MODIFY;
988  ++mRestoreWarningCount;
989  if (status.status > mRestoreWarningKorg.status)
990  mRestoreWarningKorg = status;
991  // fall through to default
992  default:
993 #ifdef USE_AKONADI
994  KAlarm::setDontShowErrors(EventId(*mOldEvent), mDontShowErrors);
995 #else
996  KAlarm::setDontShowErrors(mOldEvent->id(), mDontShowErrors);
997 #endif
998  break;
999  }
1000  break;
1001  }
1002  case CalEvent::TEMPLATE:
1003  if (KAlarm::updateTemplate(*mOldEvent) != KAlarm::UPDATE_OK)
1004  mRestoreError = ERR_TEMPLATE;
1005  break;
1006  case CalEvent::ARCHIVED: // editing of archived events is not allowed
1007  default:
1008  delete undo;
1009  mRestoreError = ERR_PROG;
1010  return 0;
1011  }
1012  return undo;
1013 }
1014 
1015 /******************************************************************************
1016 * Return the action description of the Undo item for displaying.
1017 */
1018 QString UndoEdit::defaultActionText() const
1019 {
1020  switch (calendar())
1021  {
1022  case CalEvent::ACTIVE:
1023  return i18nc("@info/plain Action to edit an alarm", "Edit alarm");
1024  case CalEvent::TEMPLATE:
1025  return i18nc("@info/plain Action to edit an alarm template", "Edit template");
1026  default:
1027  break;
1028  }
1029  return QString();
1030 }
1031 
1032 
1033 /*=============================================================================
1034 = Class: UndoDelete
1035 = Undo item for alarm deletion.
1036 =============================================================================*/
1037 
1038 UndoDelete::UndoDelete(Undo::Type type, const Undo::Event& undo, const QString& name)
1039  : UndoItem(type, name),
1040  mResource(undo.EVENT_RESOURCE),
1041  mEvent(new KAEvent(undo.event)),
1042  mDontShowErrors(undo.dontShowErrors)
1043 {
1044  setCalendar(mEvent->category());
1045 }
1046 
1047 UndoDelete::UndoDelete(Undo::Type type, const KAEvent& event, RESOURCE_PARAM_TYPE resource, const QStringList& dontShowErrors, const QString& name)
1048  : UndoItem(type, name),
1049  mResource(resource),
1050  mEvent(new KAEvent(event)),
1051  mDontShowErrors(dontShowErrors)
1052 {
1053  setCalendar(mEvent->category());
1054 }
1055 
1056 UndoDelete::~UndoDelete()
1057 {
1058  delete mEvent;
1059 }
1060 
1061 /******************************************************************************
1062 * Undo the item, i.e. restore an alarm which was deleted.
1063 * Create a redo item to delete the alarm again.
1064 * Reply = redo item.
1065 */
1066 UndoItem* UndoDelete::restore()
1067 {
1068  kDebug() << mEvent->id();
1069  // Restore the original event
1070  switch (calendar())
1071  {
1072  case CalEvent::ACTIVE:
1073  if (mEvent->toBeArchived())
1074  {
1075  // It was archived when it was deleted
1076  mEvent->setCategory(CalEvent::ARCHIVED);
1077 #ifdef USE_AKONADI
1078  KAlarm::UpdateResult status = KAlarm::reactivateEvent(*mEvent, &mResource);
1079 #else
1080  KAlarm::UpdateResult status = KAlarm::reactivateEvent(*mEvent, mResource);
1081 #endif
1082  switch (status.status)
1083  {
1084  case KAlarm::UPDATE_KORG_FUNCERR:
1085  case KAlarm::UPDATE_KORG_ERRINIT:
1086  case KAlarm::UPDATE_KORG_ERRSTART:
1087  case KAlarm::UPDATE_KORG_ERR:
1088  mRestoreWarning = WARN_KORG_ADD;
1089  ++mRestoreWarningCount;
1090  if (status.status > mRestoreWarningKorg.status)
1091  mRestoreWarningKorg = status;
1092  break;
1093  case KAlarm::UPDATE_ERROR:
1094  case KAlarm::UPDATE_FAILED:
1095  case KAlarm::SAVE_FAILED:
1096  mRestoreError = ERR_ARCHIVED;
1097  return 0;
1098  case KAlarm::UPDATE_OK:
1099  break;
1100  }
1101  }
1102  else
1103  {
1104 #ifdef USE_AKONADI
1105  KAlarm::UpdateResult status = KAlarm::addEvent(*mEvent, &mResource, 0, true);
1106 #else
1107  KAlarm::UpdateResult status = KAlarm::addEvent(*mEvent, mResource, 0, true);
1108 #endif
1109  switch (status.status)
1110  {
1111  case KAlarm::UPDATE_KORG_FUNCERR:
1112  case KAlarm::UPDATE_KORG_ERRINIT:
1113  case KAlarm::UPDATE_KORG_ERRSTART:
1114  case KAlarm::UPDATE_KORG_ERR:
1115  mRestoreWarning = WARN_KORG_ADD;
1116  ++mRestoreWarningCount;
1117  if (status.status > mRestoreWarningKorg.status)
1118  mRestoreWarningKorg = status;
1119  break;
1120  case KAlarm::UPDATE_ERROR:
1121  case KAlarm::UPDATE_FAILED:
1122  case KAlarm::SAVE_FAILED:
1123  mRestoreError = ERR_CREATE;
1124  return 0;
1125  case KAlarm::UPDATE_OK:
1126  break;
1127  }
1128  }
1129 #ifdef USE_AKONADI
1130  KAlarm::setDontShowErrors(EventId(*mEvent), mDontShowErrors);
1131 #else
1132  KAlarm::setDontShowErrors(mEvent->id(), mDontShowErrors);
1133 #endif
1134  break;
1135  case CalEvent::TEMPLATE:
1136 #ifdef USE_AKONADI
1137  if (KAlarm::addTemplate(*mEvent, &mResource) != KAlarm::UPDATE_OK)
1138 #else
1139  if (KAlarm::addTemplate(*mEvent, mResource) != KAlarm::UPDATE_OK)
1140 #endif
1141  {
1142  mRestoreError = ERR_CREATE;
1143  return 0;
1144  }
1145  break;
1146  case CalEvent::ARCHIVED:
1147 #ifdef USE_AKONADI
1148  if (!KAlarm::addArchivedEvent(*mEvent, &mResource))
1149 #else
1150  if (!KAlarm::addArchivedEvent(*mEvent, mResource))
1151 #endif
1152  {
1153  mRestoreError = ERR_CREATE;
1154  return 0;
1155  }
1156  break;
1157  default:
1158  mRestoreError = ERR_PROG;
1159  return 0;
1160  }
1161 
1162  // Create a redo item to delete the alarm again
1163  return createRedo(*mEvent, mResource);
1164 }
1165 
1166 /******************************************************************************
1167 * Create a redo item to archive the alarm again.
1168 */
1169 UndoItem* UndoDelete::createRedo(const KAEvent& event, RESOURCE_PARAM_TYPE resource)
1170 {
1171  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
1172  return new UndoAdd(t, event, resource, mName);
1173 }
1174 
1175 /******************************************************************************
1176 * Return the action description of the Undo item for displaying.
1177 */
1178 QString UndoDelete::defaultActionText() const
1179 {
1180  return addDeleteActionText(calendar(), (type() == Undo::REDO));
1181 }
1182 
1183 
1184 /*=============================================================================
1185 = Class: UndoDeletes
1186 = Undo item for multiple alarm deletion.
1187 =============================================================================*/
1188 
1189 /******************************************************************************
1190 * Create a redo item to delete the alarms again.
1191 */
1192 UndoItem* UndoDeletes::createRedo(Undo::List* undos)
1193 {
1194  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
1195  return new UndoDeletes(t, undos, mName);
1196 }
1197 
1198 /******************************************************************************
1199 * Return the action description of the Undo item for displaying.
1200 */
1201 QString UndoDeletes::defaultActionText() const
1202 {
1203  if (mUndos->isEmpty())
1204  return QString();
1205  for (int i = 0, end = mUndos->count(); i < end; ++i)
1206  {
1207  switch ((*mUndos)[i]->calendar())
1208  {
1209  case CalEvent::ACTIVE:
1210  return i18nc("@info/plain", "Delete multiple alarms");
1211  case CalEvent::TEMPLATE:
1212  return i18nc("@info/plain", "Delete multiple templates");
1213  case CalEvent::ARCHIVED:
1214  break; // check if they are ALL archived
1215  default:
1216  return QString();
1217  }
1218  }
1219  return i18nc("@info/plain", "Delete multiple archived alarms");
1220 }
1221 
1222 
1223 /*=============================================================================
1224 = Class: UndoReactivate
1225 = Undo item for alarm reactivation.
1226 =============================================================================*/
1227 
1228 /******************************************************************************
1229 * Undo the item, i.e. re-archive the alarm which was reactivated.
1230 * Create a redo item to reactivate the alarm back again.
1231 * Reply = redo item.
1232 */
1233 UndoItem* UndoReactivate::restore()
1234 {
1235  kDebug();
1236  // Validate the alarm's calendar
1237  switch (calendar())
1238  {
1239  case CalEvent::ACTIVE:
1240  break;
1241  default:
1242  mRestoreError = ERR_PROG;
1243  return 0;
1244  }
1245  return UndoAdd::doRestore(true); // restore alarm, ensuring that it is re-archived
1246 }
1247 
1248 /******************************************************************************
1249 * Create a redo item to add the alarm back again.
1250 */
1251 UndoItem* UndoReactivate::createRedo(const KAEvent& event, RESOURCE_PARAM_TYPE resource)
1252 {
1253  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
1254  return new UndoDeactivate(t, event, resource, mName);
1255 }
1256 
1257 /******************************************************************************
1258 * Return the action description of the Undo item for displaying.
1259 */
1260 QString UndoReactivate::defaultActionText() const
1261 {
1262  return i18nc("@info/plain", "Reactivate alarm");
1263 }
1264 
1265 
1266 /*=============================================================================
1267 = Class: UndoDeactivate
1268 = Redo item for alarm reactivation.
1269 =============================================================================*/
1270 
1271 /******************************************************************************
1272 * Undo the item, i.e. reactivate an alarm which was archived.
1273 * Create a redo item to archive the alarm again.
1274 * Reply = redo item.
1275 */
1276 UndoItem* UndoDeactivate::restore()
1277 {
1278  kDebug();
1279  // Validate the alarm's calendar
1280  switch (calendar())
1281  {
1282  case CalEvent::ACTIVE:
1283  break;
1284  default:
1285  mRestoreError = ERR_PROG;
1286  return 0;
1287  }
1288 
1289  return UndoDelete::restore();
1290 }
1291 
1292 /******************************************************************************
1293 * Create a redo item to archive the alarm again.
1294 */
1295 UndoItem* UndoDeactivate::createRedo(const KAEvent& event, RESOURCE_PARAM_TYPE resource)
1296 {
1297  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
1298  return new UndoReactivate(t, event, resource, mName);
1299 }
1300 
1301 /******************************************************************************
1302 * Return the action description of the Undo item for displaying.
1303 */
1304 QString UndoDeactivate::defaultActionText() const
1305 {
1306  return i18nc("@info/plain", "Reactivate alarm");
1307 }
1308 
1309 
1310 /*=============================================================================
1311 = Class: UndoReactivates
1312 = Undo item for multiple alarm reactivation.
1313 =============================================================================*/
1314 
1315 /******************************************************************************
1316 * Create a redo item to reactivate the alarms again.
1317 */
1318 UndoItem* UndoReactivates::createRedo(Undo::List* undos)
1319 {
1320  Undo::Type t = (type() == Undo::UNDO) ? Undo::REDO : (type() == Undo::REDO) ? Undo::UNDO : Undo::NONE;
1321  return new UndoReactivates(t, undos, mName);
1322 }
1323 
1324 /******************************************************************************
1325 * Return the action description of the Undo item for displaying.
1326 */
1327 QString UndoReactivates::defaultActionText() const
1328 {
1329  return i18nc("@info/plain", "Reactivate multiple alarms");
1330 }
1331 
1332 
1333 /*=============================================================================
1334 = Class: Event
1335 = Event details for external calls.
1336 =============================================================================*/
1337 Undo::Event::Event(const KAEvent& e, RESOURCE_PARAM_TYPE r)
1338  : event(e),
1339  EVENT_RESOURCE(r)
1340 {
1341  if (e.category() == CalEvent::ACTIVE)
1342 #ifdef USE_AKONADI
1343  dontShowErrors = KAlarm::dontShowErrors(EventId(e));
1344 #else
1345  dontShowErrors = KAlarm::dontShowErrors(e.id());
1346 #endif
1347 }
1348 
1349 // vim: et sw=4:
Undo::emitChanged
static void emitChanged()
Definition: undo.cpp:588
Undo::Event::dontShowErrors
QStringList dontShowErrors
Definition: undo.h:65
maxCount
static int maxCount
Definition: undo.cpp:35
QWidget
Undo::NONE
Definition: undo.h:47
Undo::UNDO
Definition: undo.h:47
undo.h
undo/redo facility
KAlarm::UpdateResult
Result of calendar update.
Definition: functions.h:79
QList::removeAt
void removeAt(int i)
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Undo::description
static QString description(Type, int id)
Definition: undo.cpp:522
Undo::saveEdit
static void saveEdit(const Event &oldEvent, const KAEvent &newEvent)
Definition: undo.cpp:327
alarmcalendar.h
Undo::Event
Definition: undo.h:51
Undo::saveDeletes
static void saveDeletes(const EventList &, const QString &name=QString())
Definition: undo.cpp:341
QList::indexOf
int indexOf(const T &value, int from) const
AlarmCalendar::getEvent
static KAEvent * getEvent(const QString &uniqueId)
Definition: alarmcalendar.cpp:150
Undo::Type
Type
Definition: undo.h:47
Undo::saveAdds
static void saveAdds(const EventList &, const QString &name=QString())
Definition: undo.cpp:315
Undo::EventList
Definition: undo.h:67
Undo
Definition: undo.h:43
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
Undo::ids
static QList< int > ids(Type)
Definition: undo.cpp:534
Undo::Event::Event
Event()
Definition: undo.h:53
RESOURCE_PARAM_TYPE
#define RESOURCE_PARAM_TYPE
Definition: undo.cpp:46
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
EVENT_RESOURCE
#define EVENT_RESOURCE
Definition: undo.cpp:47
Undo::saveReactivate
static void saveReactivate(const KAEvent &, AlarmResource *, const QString &name=QString())
Definition: undo.cpp:355
QList::first
T & first()
messagebox.h
QString
QList
T
QStringList
Undo::undo
static bool undo(QWidget *parent, const QString &action)
Definition: undo.h:93
Undo::remove
static void remove(UndoItem *, bool undo)
Definition: undo.cpp:476
Undo::saveAdd
static void saveAdd(const KAEvent &, AlarmResource *, const QString &name=QString())
Definition: undo.cpp:309
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
Undo::REDO
Definition: undo.h:47
Undo::saveReactivates
static void saveReactivates(const EventList &, const QString &name=QString())
Definition: undo.cpp:361
Undo::replace
static void replace(UndoItem *old, UndoItem *New)
Definition: undo.cpp:486
Undo::saveDelete
static void saveDelete(const Event &, const QString &name=QString())
Definition: undo.cpp:334
functions.h
miscellaneous functions
KAMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
kalarm.h
Undo::clear
static void clear()
Definition: undo.cpp:291
Undo::add
static void add(UndoItem *, bool undo)
Definition: undo.cpp:452
Undo::actionText
static QString actionText(Type)
Definition: undo.cpp:504
QList::prepend
void prepend(const T &value)
Undo::List
AutoDeleteList< UndoItem > List
Definition: undo.h:111
KAlarm::UpdateResult::status
UpdateStatus status
Definition: functions.h:81
AutoDeleteList
Undo::instance
static Undo * instance()
Definition: undo.cpp:281
Undo::Event::event
KAEvent event
Definition: undo.h:59
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal