-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 53 | ||||
-rw-r--r-- | libopie2/opiepim/core/otemplatebase.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 71 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.h | 79 |
4 files changed, 180 insertions, 25 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 36f5a99..31ab516 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,191 +1,196 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 7 | #include <opie/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 8 | #include <opie/orecordlist.h> |
9 | 9 | ||
10 | #include "otemplatebase.h" | 10 | #include "otemplatebase.h" |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * Thats the frontend to our OPIE PIM | 13 | * Thats the frontend to our OPIE PIM |
14 | * Library. Either you want to use it's | 14 | * Library. Either you want to use it's |
15 | * interface or you want to implement | 15 | * interface or you want to implement |
16 | * your own Access lib | 16 | * your own Access lib |
17 | * Just create a OPimRecord and inherit from | 17 | * Just create a OPimRecord and inherit from |
18 | * the plugins | 18 | * the plugins |
19 | */ | 19 | */ |
20 | 20 | ||
21 | template <class T = OPimRecord > | 21 | template <class T = OPimRecord > |
22 | class OPimAccessTemplate : public OTemplateBase<T> { | 22 | class OPimAccessTemplate : public OTemplateBase<T> { |
23 | public: | 23 | public: |
24 | typedef ORecordList<T> List; | 24 | typedef ORecordList<T> List; |
25 | typedef OPimAccessBackend<T> BackEnd; | 25 | typedef OPimAccessBackend<T> BackEnd; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * our sort order | 28 | * our sort order |
29 | * should be safe explaining | 29 | * should be safe explaining |
30 | */ | 30 | */ |
31 | enum SortOrder { WildCards = 0, IgnoreCase = 1, | 31 | enum SortOrder { WildCards = 0, IgnoreCase = 1, |
32 | RegExp = 2, ExactMatch = 4 }; | 32 | RegExp = 2, ExactMatch = 4 }; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * c'tor BackEnd | 35 | * c'tor BackEnd |
36 | */ | 36 | */ |
37 | OPimAccessTemplate( BackEnd* end); | 37 | OPimAccessTemplate( BackEnd* end); |
38 | virtual ~OPimAccessTemplate(); | 38 | virtual ~OPimAccessTemplate(); |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * load from the backend | 41 | * load from the backend |
42 | */ | 42 | */ |
43 | virtual void load(); | 43 | virtual bool load(); |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * reload from the backend | 46 | * reload from the backend |
47 | */ | 47 | */ |
48 | virtual void reload(); | 48 | virtual bool reload(); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * save to the backend | 51 | * save to the backend |
52 | */ | 52 | */ |
53 | virtual void save(); | 53 | virtual bool save(); |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * if the resource was changed externally | 56 | * if the resource was changed externally |
57 | */ | 57 | */ |
58 | bool wasChangedExternally()const; | 58 | bool wasChangedExternally()const; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * return a List of records | 61 | * return a List of records |
62 | * you can iterate over them | 62 | * you can iterate over them |
63 | */ | 63 | */ |
64 | virtual List allRecords()const; | 64 | virtual List allRecords()const; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * queryByExample | 67 | * queryByExample |
68 | */ | 68 | */ |
69 | virtual List queryByExample( const T& t, int sortOrder ); | 69 | virtual List queryByExample( const T& t, int sortOrder ); |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * find the OPimRecord uid | 72 | * find the OPimRecord uid |
73 | */ | 73 | */ |
74 | virtual T find( int uid ); | 74 | virtual T find( int uid )const; |
75 | 75 | ||
76 | /* invalidate cache here */ | 76 | /* invalidate cache here */ |
77 | /** | 77 | /** |
78 | * clears the backend and invalidates the backend | 78 | * clears the backend and invalidates the backend |
79 | */ | 79 | */ |
80 | virtual void clear() ; | 80 | virtual void clear() ; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * add T to the backend | 83 | * add T to the backend |
84 | */ | 84 | */ |
85 | virtual bool add( const T& t ) ; | 85 | virtual bool add( const T& t ) ; |
86 | 86 | ||
87 | /* only the uid matters */ | 87 | /* only the uid matters */ |
88 | /** | 88 | /** |
89 | * remove T from the backend | 89 | * remove T from the backend |
90 | */ | 90 | */ |
91 | virtual bool remove( const T& t ); | 91 | virtual bool remove( const T& t ); |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * remove the OPimRecord with uid | 94 | * remove the OPimRecord with uid |
95 | */ | 95 | */ |
96 | virtual bool remove( int uid ); | 96 | virtual bool remove( int uid ); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * replace T from backend | 99 | * replace T from backend |
100 | */ | 100 | */ |
101 | virtual bool replace( const T& t) ; | 101 | virtual bool replace( const T& t) ; |
102 | protected: | 102 | protected: |
103 | /** | 103 | /** |
104 | * invalidate the cache | 104 | * invalidate the cache |
105 | */ | 105 | */ |
106 | void invalidateCache(); | 106 | void invalidateCache(); |
107 | 107 | ||
108 | void setBackEnd( BackEnd* end ); | ||
108 | /** | 109 | /** |
109 | * returns the backend | 110 | * returns the backend |
110 | */ | 111 | */ |
111 | BackEnd* backEnd(); | 112 | BackEnd* backEnd(); |
112 | BackEnd* m_backEnd; | 113 | BackEnd* m_backEnd; |
113 | 114 | ||
114 | }; | 115 | }; |
115 | 116 | ||
116 | template <class T> | 117 | template <class T> |
117 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 118 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
118 | : OTemplateBase<T>(), m_backEnd( end ) | 119 | : OTemplateBase<T>(), m_backEnd( end ) |
119 | { | 120 | { |
120 | 121 | ||
121 | } | 122 | } |
122 | template <class T> | 123 | template <class T> |
123 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 124 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
124 | qWarning("~OPimAccessTemplate<T>"); | 125 | qWarning("~OPimAccessTemplate<T>"); |
125 | delete m_backEnd; | 126 | delete m_backEnd; |
126 | } | 127 | } |
127 | template <class T> | 128 | template <class T> |
128 | void OPimAccessTemplate<T>::load() { | 129 | bool OPimAccessTemplate<T>::load() { |
129 | m_backEnd->load(); | 130 | return m_backEnd->load(); |
130 | } | 131 | } |
131 | template <class T> | 132 | template <class T> |
132 | void OPimAccessTemplate<T>::reload() { | 133 | bool OPimAccessTemplate<T>::reload() { |
133 | m_backEnd->reload(); | 134 | return m_backEnd->reload(); |
134 | } | 135 | } |
135 | template <class T> | 136 | template <class T> |
136 | void OPimAccessTemplate<T>::save() { | 137 | bool OPimAccessTemplate<T>::save() { |
137 | m_backEnd->save(); | 138 | return m_backEnd->save(); |
138 | } | 139 | } |
139 | template <class T> | 140 | template <class T> |
140 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 141 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
141 | QArray<int> ints = m_backEnd->allRecords(); | 142 | QArray<int> ints = m_backEnd->allRecords(); |
142 | List lis(ints, this ); | 143 | List lis(ints, this ); |
143 | return lis; | 144 | return lis; |
144 | } | 145 | } |
145 | template <class T> | 146 | template <class T> |
146 | OPimAccessTemplate<T>::List | 147 | OPimAccessTemplate<T>::List |
147 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { | 148 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { |
148 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); | 149 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); |
149 | 150 | ||
150 | List lis(ints, this ); | 151 | List lis(ints, this ); |
151 | return lis; | 152 | return lis; |
152 | } | 153 | } |
153 | template <class T> | 154 | template <class T> |
154 | T OPimAccessTemplate<T>::find( int uid ) { | 155 | T OPimAccessTemplate<T>::find( int uid ) const{ |
155 | T t = m_backEnd->find( uid ); | 156 | T t = m_backEnd->find( uid ); |
156 | return t; | 157 | return t; |
157 | } | 158 | } |
158 | template <class T> | 159 | template <class T> |
159 | void OPimAccessTemplate<T>::clear() { | 160 | void OPimAccessTemplate<T>::clear() { |
160 | invalidateCache(); | 161 | invalidateCache(); |
161 | m_backEnd->clear(); | 162 | m_backEnd->clear(); |
162 | } | 163 | } |
163 | template <class T> | 164 | template <class T> |
164 | bool OPimAccessTemplate<T>::add( const T& t ) { | 165 | bool OPimAccessTemplate<T>::add( const T& t ) { |
165 | return m_backEnd->add( t ); | 166 | return m_backEnd->add( t ); |
166 | } | 167 | } |
167 | template <class T> | 168 | template <class T> |
168 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 169 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
169 | return m_backEnd->remove( t.uid() ); | 170 | return m_backEnd->remove( t.uid() ); |
170 | } | 171 | } |
171 | template <class T> | 172 | template <class T> |
172 | bool OPimAccessTemplate<T>::remove( int uid ) { | 173 | bool OPimAccessTemplate<T>::remove( int uid ) { |
173 | return m_backEnd->remove( uid ); | 174 | return m_backEnd->remove( uid ); |
174 | } | 175 | } |
175 | template <class T> | 176 | template <class T> |
176 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 177 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
177 | return m_backEnd->replace( t ); | 178 | return m_backEnd->replace( t ); |
178 | } | 179 | } |
179 | template <class T> | 180 | template <class T> |
180 | void OPimAccessTemplate<T>::invalidateCache() { | 181 | void OPimAccessTemplate<T>::invalidateCache() { |
181 | 182 | ||
182 | } | 183 | } |
183 | template <class T> | 184 | template <class T> |
184 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 185 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
185 | return m_backEnd; | 186 | return m_backEnd; |
186 | } | 187 | } |
187 | template <class T> | 188 | template <class T> |
188 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 189 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
189 | return false; | 190 | return false; |
190 | } | 191 | } |
192 | template <class T> | ||
193 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | ||
194 | m_backEnd = end; | ||
195 | } | ||
191 | #endif | 196 | #endif |
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h index add1de4..f71417b 100644 --- a/libopie2/opiepim/core/otemplatebase.h +++ b/libopie2/opiepim/core/otemplatebase.h | |||
@@ -1,21 +1,21 @@ | |||
1 | #ifndef OPIE_TEMPLATE_BASE_H | 1 | #ifndef OPIE_TEMPLATE_BASE_H |
2 | #define OPIE_TEMPLATE_BASE_H | 2 | #define OPIE_TEMPLATE_BASE_H |
3 | 3 | ||
4 | #include "opimrecord.h" | 4 | #include "opimrecord.h" |
5 | 5 | ||
6 | /** | 6 | /** |
7 | * internal template base | 7 | * internal template base |
8 | */ | 8 | */ |
9 | template <class T = OPimRecord> | 9 | template <class T = OPimRecord> |
10 | class OTemplateBase { | 10 | class OTemplateBase { |
11 | public: | 11 | public: |
12 | OTemplateBase() { | 12 | OTemplateBase() { |
13 | }; | 13 | }; |
14 | virtual ~OTemplateBase() { | 14 | virtual ~OTemplateBase() { |
15 | } | 15 | } |
16 | virtual T find( int uid ) = 0; | 16 | virtual T find( int uid )const = 0; |
17 | 17 | ||
18 | }; | 18 | }; |
19 | 19 | ||
20 | 20 | ||
21 | #endif | 21 | #endif |
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp new file mode 100644 index 0000000..a65cf5c --- a/dev/null +++ b/libopie2/opiepim/core/otodoaccess.cpp | |||
@@ -0,0 +1,71 @@ | |||
1 | #include <qdatetime.h> | ||
2 | |||
3 | #include <qpe/alarmserver.h> | ||
4 | |||
5 | #include "otodoaccessxml.h" | ||
6 | #include "otodoaccess.h" | ||
7 | |||
8 | |||
9 | OTodoAccess::OTodoAccess( OTodoAccessBackend* end ) | ||
10 | : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) | ||
11 | { | ||
12 | if (end == 0l ) | ||
13 | m_todoBackEnd = new OTodoAccessXML( "Todolist" ); | ||
14 | |||
15 | setBackEnd( m_todoBackEnd ); | ||
16 | } | ||
17 | OTodoAccess::~OTodoAccess() { | ||
18 | qWarning("~OTodoAccess"); | ||
19 | } | ||
20 | void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { | ||
21 | QValueList<OTodo>::ConstIterator it; | ||
22 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
23 | replace( (*it) ); | ||
24 | } | ||
25 | } | ||
26 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, | ||
27 | const QDate& end, | ||
28 | bool includeNoDates ) { | ||
29 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); | ||
30 | |||
31 | List lis( ints, this ); | ||
32 | return lis; | ||
33 | } | ||
34 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, | ||
35 | bool includeNoDates ) { | ||
36 | return effectiveToDos( start, QDate::currentDate(), | ||
37 | includeNoDates ); | ||
38 | } | ||
39 | OTodoAccess::List OTodoAccess::overDue() { | ||
40 | List lis( m_todoBackEnd->overDue(), this ); | ||
41 | return lis; | ||
42 | } | ||
43 | void OTodoAccess::addAlarm( const OTodo& event) { | ||
44 | if (!event.hasAlarmDateTime() ) | ||
45 | return; | ||
46 | |||
47 | QDateTime now = QDateTime::currentDateTime(); | ||
48 | QDateTime schedule = event.alarmDateTime(); | ||
49 | |||
50 | if ( schedule > now ){ | ||
51 | AlarmServer::addAlarm( schedule, | ||
52 | "QPE/Application/todolist", | ||
53 | "alarm(QDateTime,int)", event.uid() ); | ||
54 | |||
55 | } | ||
56 | } | ||
57 | void OTodoAccess::delAlarm( int uid) { | ||
58 | |||
59 | QDateTime schedule; // Create null DateTime | ||
60 | |||
61 | // I hope this will remove all scheduled alarms | ||
62 | // with the given uid !? | ||
63 | // If not: I have to rethink how to remove already | ||
64 | // scheduled events... (se) | ||
65 | // it should be fine -zecke | ||
66 | qWarning("Removing alarm for event with uid %d", uid ); | ||
67 | AlarmServer::deleteAlarm( schedule , | ||
68 | "QPE/Application/todolist", | ||
69 | "alarm(QDateTime,int)", uid ); | ||
70 | } | ||
71 | |||
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h new file mode 100644 index 0000000..c43efe9 --- a/dev/null +++ b/libopie2/opiepim/core/otodoaccess.h | |||
@@ -0,0 +1,79 @@ | |||
1 | #ifndef OPIE_TODO_ACCESS_H | ||
2 | #define OPIE_TODO_ACCESS_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qvaluelist.h> | ||
6 | |||
7 | #include "otodo.h" | ||
8 | #include "otodoaccessbackend.h" | ||
9 | #include "opimaccesstemplate.h" | ||
10 | |||
11 | |||
12 | /** | ||
13 | * OTodoAccess | ||
14 | * the class to get access to | ||
15 | * the todolist | ||
16 | */ | ||
17 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { | ||
18 | Q_OBJECT | ||
19 | public: | ||
20 | /** | ||
21 | * if you use 0l | ||
22 | * the default resource will be | ||
23 | * icked up | ||
24 | */ | ||
25 | OTodoAccess( OTodoAccessBackend* = 0l); | ||
26 | ~OTodoAccess(); | ||
27 | |||
28 | |||
29 | /* our functions here */ | ||
30 | /** | ||
31 | * include todos from start to end | ||
32 | * includeNoDates whether or not to include | ||
33 | * events with no dates | ||
34 | */ | ||
35 | List effectiveToDos( const QDate& start, | ||
36 | const QDate& end, | ||
37 | bool includeNoDates = true ); | ||
38 | |||
39 | /** | ||
40 | * start | ||
41 | * end date taken from the currentDate() | ||
42 | */ | ||
43 | List effectiveToDos( const QDate& start, | ||
44 | bool includeNoDates = true ); | ||
45 | |||
46 | |||
47 | /** | ||
48 | * return overdue OTodos | ||
49 | */ | ||
50 | List overDue(); | ||
51 | /** | ||
52 | * merge a list of OTodos into | ||
53 | * the resource | ||
54 | */ | ||
55 | void mergeWith( const QValueList<OTodo>& ); | ||
56 | |||
57 | /** | ||
58 | * add an Alarm to the AlarmServer | ||
59 | */ | ||
60 | void addAlarm( const OTodo& ); | ||
61 | |||
62 | /** | ||
63 | * delete an alarm with the uid from | ||
64 | * the alarm server | ||
65 | */ | ||
66 | void delAlarm( int uid ); | ||
67 | |||
68 | signals: | ||
69 | /** | ||
70 | * if the OTodoAccess was changed | ||
71 | */ | ||
72 | void signalChanged( const OTodoAccess* ); | ||
73 | private: | ||
74 | OTodoAccessBackend* m_todoBackEnd; | ||
75 | class OTodoAccessPrivate; | ||
76 | OTodoAccessPrivate* d; | ||
77 | }; | ||
78 | |||
79 | #endif | ||