• 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.h
Go to the documentation of this file.
1 /*
2  * undo.h - undo/redo facility
3  * Program: kalarm
4  * Copyright © 2005-2011 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 #ifndef UNDO_H
22 #define UNDO_H
23 
26 #include "autodeletelist.h"
27 
28 #include <kalarmcal/kaevent.h>
29 
30 #ifdef USE_AKONADI
31 #include <akonadi/collection.h>
32 #endif
33 #include <QList>
34 #include <QStringList>
35 
36 #ifndef USE_AKONADI
37 class AlarmResource;
38 #endif
39 class UndoItem;
40 using namespace KAlarmCal;
41 
42 
43 class Undo : public QObject
44 {
45  Q_OBJECT
46  public:
47  enum Type { NONE, UNDO, REDO };
48  // N.B. The Event structure must be constructed before the action for
49  // which the undo is being created is carried out, since the
50  // don't-show-errors status is not contained within the KAEvent itself.
51  struct Event
52  {
53  Event() {}
54 #ifdef USE_AKONADI
55  Event(const KAEvent&, const Akonadi::Collection&);
56 #else
57  Event(const KAEvent&, AlarmResource*);
58 #endif
59  KAEvent event;
60 #ifdef USE_AKONADI
61  mutable Akonadi::Collection collection;
62 #else
63  AlarmResource* resource;
64 #endif
65  QStringList dontShowErrors;
66  };
67  class EventList : public QList<Event>
68  {
69  public:
70 #ifdef USE_AKONADI
71  void append(const KAEvent& e, const Akonadi::Collection& c) { QList<Event>::append(Event(e, c)); }
72 #else
73  void append(const KAEvent& e, AlarmResource* r) { QList<Event>::append(Event(e, r)); }
74 #endif
75  };
76 
77  static Undo* instance();
78 #ifdef USE_AKONADI
79  static void saveAdd(const KAEvent&, const Akonadi::Collection&, const QString& name = QString());
80 #else
81  static void saveAdd(const KAEvent&, AlarmResource*, const QString& name = QString());
82 #endif
83  static void saveAdds(const EventList&, const QString& name = QString());
84  static void saveEdit(const Event& oldEvent, const KAEvent& newEvent);
85  static void saveDelete(const Event&, const QString& name = QString());
86  static void saveDeletes(const EventList&, const QString& name = QString());
87 #ifdef USE_AKONADI
88  static void saveReactivate(const KAEvent&, const Akonadi::Collection&, const QString& name = QString());
89 #else
90  static void saveReactivate(const KAEvent&, AlarmResource*, const QString& name = QString());
91 #endif
92  static void saveReactivates(const EventList&, const QString& name = QString());
93  static bool undo(QWidget* parent, const QString& action)
94  { return undo(0, UNDO, parent, action); }
95  static bool undo(int id, QWidget* parent, const QString& action)
96  { return undo(findItem(id, UNDO), UNDO, parent, action); }
97  static bool redo(QWidget* parent, const QString& action)
98  { return undo(0, REDO, parent, action); }
99  static bool redo(int id, QWidget* parent, const QString& action)
100  { return undo(findItem(id, REDO), REDO, parent, action); }
101  static void clear();
102  static bool haveUndo() { return !mUndoList.isEmpty(); }
103  static bool haveRedo() { return !mRedoList.isEmpty(); }
104  static QString actionText(Type);
105  static QString actionText(Type, int id);
106  static QString description(Type, int id);
107  static QList<int> ids(Type);
108  static void emitChanged();
109 
110  // Types for use by UndoItem class and its descendants
111  typedef AutoDeleteList<UndoItem> List;
112 
113  signals:
114  void changed(const QString& undo, const QString& redo);
115 
116  protected:
117  // Methods for use by UndoItem class
118  static void add(UndoItem*, bool undo);
119  static void remove(UndoItem*, bool undo);
120  static void replace(UndoItem* old, UndoItem* New);
121 
122  private:
123  Undo(QObject* parent) : QObject(parent) { }
124  static void removeRedos(const QString& eventID);
125  static bool undo(int index, Type, QWidget* parent, const QString& action);
126  static UndoItem* getItem(int id, Type);
127  static int findItem(int id, Type);
128  void emitChanged(const QString& undo, const QString& redo)
129  { emit changed(undo, redo); }
130 
131  static Undo* mInstance; // the one and only Undo instance
132  static List mUndoList; // edit history for undo, latest undo first
133  static List mRedoList; // edit history for redo, latest redo first
134 
135  friend class UndoItem;
136 };
137 
138 #endif // UNDO_H
139 
140 // vim: et sw=4:
Undo::haveRedo
static bool haveRedo()
Definition: undo.h:103
Undo::Event::dontShowErrors
QStringList dontShowErrors
Definition: undo.h:65
QWidget
Undo::redo
static bool redo(QWidget *parent, const QString &action)
Definition: undo.h:97
Undo::UNDO
Definition: undo.h:47
Undo::redo
static bool redo(int id, QWidget *parent, const QString &action)
Definition: undo.h:99
Undo::Event
Definition: undo.h:51
Undo::Event::resource
AlarmResource * resource
Definition: undo.h:63
Undo::Type
Type
Definition: undo.h:47
Undo::EventList
Definition: undo.h:67
Undo
Definition: undo.h:43
QList::append
void append(const T &value)
Undo::Event::Event
Event()
Definition: undo.h:53
QObject
QString
QList
QStringList
Undo::undo
static bool undo(int id, QWidget *parent, const QString &action)
Definition: undo.h:95
Undo::undo
static bool undo(QWidget *parent, const QString &action)
Definition: undo.h:93
autodeletelist.h
Undo::haveUndo
static bool haveUndo()
Definition: undo.h:102
Undo::List
AutoDeleteList< UndoItem > List
Definition: undo.h:111
Undo::EventList::append
void append(const KAEvent &e, AlarmResource *r)
Definition: undo.h:73
AutoDeleteList
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