author | eilers <eilers> | 2003-11-17 15:55:43 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-11-17 15:55:43 (UTC) |
commit | 3ba032c6a4833260ef6274b6b2bf6a6a9ccc2540 (patch) (unidiff) | |
tree | 051c0bda86446e65009f2e6f42c57272e93f562c /libopie | |
parent | c4a6e9c529ea6bcb1c9a42fee33a70300f116c98 (diff) | |
download | opie-3ba032c6a4833260ef6274b6b2bf6a6a9ccc2540.zip opie-3ba032c6a4833260ef6274b6b2bf6a6a9ccc2540.tar.gz opie-3ba032c6a4833260ef6274b6b2bf6a6a9ccc2540.tar.bz2 |
Minor changes..
-rw-r--r-- | libopie/pim/odatebookaccessbackend_xml.cpp | 2 | ||||
-rw-r--r-- | libopie/pim/opimrecord.h | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp index 5ea945c..39c43c5 100644 --- a/libopie/pim/odatebookaccessbackend_xml.cpp +++ b/libopie/pim/odatebookaccessbackend_xml.cpp | |||
@@ -1,288 +1,288 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | 6 | ||
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
9 | #include <sys/stat.h> | 9 | #include <sys/stat.h> |
10 | 10 | ||
11 | #include <unistd.h> | 11 | #include <unistd.h> |
12 | 12 | ||
13 | #include <qasciidict.h> | 13 | #include <qasciidict.h> |
14 | #include <qfile.h> | 14 | #include <qfile.h> |
15 | 15 | ||
16 | #include <qtopia/global.h> | 16 | #include <qtopia/global.h> |
17 | #include <qtopia/stringutil.h> | 17 | #include <qtopia/stringutil.h> |
18 | #include <qtopia/timeconversion.h> | 18 | #include <qtopia/timeconversion.h> |
19 | 19 | ||
20 | #include "opimnotifymanager.h" | 20 | #include "opimnotifymanager.h" |
21 | #include "orecur.h" | 21 | #include "orecur.h" |
22 | #include "otimezone.h" | 22 | #include "otimezone.h" |
23 | #include "odatebookaccessbackend_xml.h" | 23 | #include "odatebookaccessbackend_xml.h" |
24 | 24 | ||
25 | namespace { | 25 | namespace { |
26 | // FROM TT again | 26 | // FROM TT again |
27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
28 | { | 28 | { |
29 | char needleChar; | 29 | char needleChar; |
30 | char haystackChar; | 30 | char haystackChar; |
31 | if (!needle || !haystack || !hLen || !nLen) | 31 | if (!needle || !haystack || !hLen || !nLen) |
32 | return 0; | 32 | return 0; |
33 | 33 | ||
34 | const char* hsearch = haystack; | 34 | const char* hsearch = haystack; |
35 | 35 | ||
36 | if ((needleChar = *needle++) != 0) { | 36 | if ((needleChar = *needle++) != 0) { |
37 | nLen--; //(to make up for needle++) | 37 | nLen--; //(to make up for needle++) |
38 | do { | 38 | do { |
39 | do { | 39 | do { |
40 | if ((haystackChar = *hsearch++) == 0) | 40 | if ((haystackChar = *hsearch++) == 0) |
41 | return (0); | 41 | return (0); |
42 | if (hsearch >= haystack + hLen) | 42 | if (hsearch >= haystack + hLen) |
43 | return (0); | 43 | return (0); |
44 | } while (haystackChar != needleChar); | 44 | } while (haystackChar != needleChar); |
45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
46 | hsearch--; | 46 | hsearch--; |
47 | } | 47 | } |
48 | return ((char *)hsearch); | 48 | return ((char *)hsearch); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | namespace { | 52 | namespace { |
53 | time_t start, end, created, rp_end; | 53 | time_t start, end, created, rp_end; |
54 | ORecur* rec; | 54 | ORecur* rec; |
55 | ORecur* recur() { | 55 | ORecur* recur() { |
56 | if (!rec) | 56 | if (!rec) |
57 | rec = new ORecur; | 57 | rec = new ORecur; |
58 | 58 | ||
59 | return rec; | 59 | return rec; |
60 | } | 60 | } |
61 | int alarmTime; | 61 | int alarmTime; |
62 | int snd; | 62 | int snd; |
63 | enum Attribute{ | 63 | enum Attribute{ |
64 | FDescription = 0, | 64 | FDescription = 0, |
65 | FLocation, | 65 | FLocation, |
66 | FCategories, | 66 | FCategories, |
67 | FUid, | 67 | FUid, |
68 | FType, | 68 | FType, |
69 | FAlarm, | 69 | FAlarm, |
70 | FSound, | 70 | FSound, |
71 | FRType, | 71 | FRType, |
72 | FRWeekdays, | 72 | FRWeekdays, |
73 | FRPosition, | 73 | FRPosition, |
74 | FRFreq, | 74 | FRFreq, |
75 | FRHasEndDate, | 75 | FRHasEndDate, |
76 | FREndDate, | 76 | FREndDate, |
77 | FRStart, | 77 | FRStart, |
78 | FREnd, | 78 | FREnd, |
79 | FNote, | 79 | FNote, |
80 | FCreated, | 80 | FCreated, |
81 | FTimeZone, | 81 | FTimeZone, |
82 | FRecParent, | 82 | FRecParent, |
83 | FRecChildren, | 83 | FRecChildren, |
84 | FExceptions | 84 | FExceptions |
85 | }; | 85 | }; |
86 | inline void save( const OEvent& ev, QString& buf ) { | 86 | inline void save( const OEvent& ev, QString& buf ) { |
87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); | 87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); |
88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
89 | if (!ev.location().isEmpty() ) | 89 | if (!ev.location().isEmpty() ) |
90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
91 | 91 | ||
92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
94 | 94 | ||
95 | if (ev.isAllDay() ) | 95 | if (ev.isAllDay() ) |
96 | buf += " type=\"AllDay\""; | 96 | buf += " type=\"AllDay\""; // is that all ?? (eilers) |
97 | 97 | ||
98 | if (ev.hasNotifiers() ) { | 98 | if (ev.hasNotifiers() ) { |
99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
102 | if ( alarm.sound() == OPimAlarm::Loud ) | 102 | if ( alarm.sound() == OPimAlarm::Loud ) |
103 | buf += "loud"; | 103 | buf += "loud"; |
104 | else | 104 | else |
105 | buf += "silent"; | 105 | buf += "silent"; |
106 | buf += "\""; | 106 | buf += "\""; |
107 | } | 107 | } |
108 | if ( ev.hasRecurrence() ) { | 108 | if ( ev.hasRecurrence() ) { |
109 | buf += ev.recurrence().toString(); | 109 | buf += ev.recurrence().toString(); |
110 | } | 110 | } |
111 | 111 | ||
112 | /* | 112 | /* |
113 | * fscking timezones :) well, we'll first convert | 113 | * fscking timezones :) well, we'll first convert |
114 | * the QDateTime to a QDateTime in UTC time | 114 | * the QDateTime to a QDateTime in UTC time |
115 | * and then we'll create a nice time_t | 115 | * and then we'll create a nice time_t |
116 | */ | 116 | */ |
117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
120 | if (!ev.note().isEmpty() ) { | 120 | if (!ev.note().isEmpty() ) { |
121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
122 | } | 122 | } |
123 | 123 | ||
124 | buf += " timezone=\""; | 124 | buf += " timezone=\""; |
125 | if ( ev.timeZone().isEmpty() ) | 125 | if ( ev.timeZone().isEmpty() ) |
126 | buf += "None"; | 126 | buf += "None"; |
127 | else | 127 | else |
128 | buf += ev.timeZone(); | 128 | buf += ev.timeZone(); |
129 | buf += "\""; | 129 | buf += "\""; |
130 | 130 | ||
131 | if (ev.parent() != 0 ) { | 131 | if (ev.parent() != 0 ) { |
132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
133 | } | 133 | } |
134 | 134 | ||
135 | if (ev.children().count() != 0 ) { | 135 | if (ev.children().count() != 0 ) { |
136 | QArray<int> children = ev.children(); | 136 | QArray<int> children = ev.children(); |
137 | buf += " recchildren=\""; | 137 | buf += " recchildren=\""; |
138 | for ( uint i = 0; i < children.count(); i++ ) { | 138 | for ( uint i = 0; i < children.count(); i++ ) { |
139 | if ( i != 0 ) buf += " "; | 139 | if ( i != 0 ) buf += " "; |
140 | buf += QString::number( children[i] ); | 140 | buf += QString::number( children[i] ); |
141 | } | 141 | } |
142 | buf+= "\""; | 142 | buf+= "\""; |
143 | } | 143 | } |
144 | 144 | ||
145 | // skip custom writing | 145 | // skip custom writing |
146 | } | 146 | } |
147 | 147 | ||
148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
149 | QMap<int, OEvent>::ConstIterator it; | 149 | QMap<int, OEvent>::ConstIterator it; |
150 | QString buf; | 150 | QString buf; |
151 | QCString str; | 151 | QCString str; |
152 | int total_written; | 152 | int total_written; |
153 | for ( it = list.begin(); it != list.end(); ++it ) { | 153 | for ( it = list.begin(); it != list.end(); ++it ) { |
154 | buf = "<event"; | 154 | buf = "<event"; |
155 | save( it.data(), buf ); | 155 | save( it.data(), buf ); |
156 | buf += " />\n"; | 156 | buf += " />\n"; |
157 | str = buf.utf8(); | 157 | str = buf.utf8(); |
158 | 158 | ||
159 | total_written = file.writeBlock(str.data(), str.length() ); | 159 | total_written = file.writeBlock(str.data(), str.length() ); |
160 | if ( total_written != int(str.length() ) ) | 160 | if ( total_written != int(str.length() ) ) |
161 | return false; | 161 | return false; |
162 | } | 162 | } |
163 | return true; | 163 | return true; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
168 | const QString& fileName ) | 168 | const QString& fileName ) |
169 | : ODateBookAccessBackend() { | 169 | : ODateBookAccessBackend() { |
170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
171 | m_changed = false; | 171 | m_changed = false; |
172 | } | 172 | } |
173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
174 | } | 174 | } |
175 | bool ODateBookAccessBackend_XML::load() { | 175 | bool ODateBookAccessBackend_XML::load() { |
176 | return loadFile(); | 176 | return loadFile(); |
177 | } | 177 | } |
178 | bool ODateBookAccessBackend_XML::reload() { | 178 | bool ODateBookAccessBackend_XML::reload() { |
179 | clear(); | 179 | clear(); |
180 | return load(); | 180 | return load(); |
181 | } | 181 | } |
182 | bool ODateBookAccessBackend_XML::save() { | 182 | bool ODateBookAccessBackend_XML::save() { |
183 | if (!m_changed) return true; | 183 | if (!m_changed) return true; |
184 | 184 | ||
185 | int total_written; | 185 | int total_written; |
186 | QString strFileNew = m_name + ".new"; | 186 | QString strFileNew = m_name + ".new"; |
187 | 187 | ||
188 | QFile f( strFileNew ); | 188 | QFile f( strFileNew ); |
189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
190 | 190 | ||
191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
193 | buf += "<events>\n"; | 193 | buf += "<events>\n"; |
194 | QCString str = buf.utf8(); | 194 | QCString str = buf.utf8(); |
195 | total_written = f.writeBlock( str.data(), str.length() ); | 195 | total_written = f.writeBlock( str.data(), str.length() ); |
196 | if ( total_written != int(str.length() ) ) { | 196 | if ( total_written != int(str.length() ) ) { |
197 | f.close(); | 197 | f.close(); |
198 | QFile::remove( strFileNew ); | 198 | QFile::remove( strFileNew ); |
199 | return false; | 199 | return false; |
200 | } | 200 | } |
201 | 201 | ||
202 | if (!forAll( m_raw, f ) ) { | 202 | if (!forAll( m_raw, f ) ) { |
203 | f.close(); | 203 | f.close(); |
204 | QFile::remove( strFileNew ); | 204 | QFile::remove( strFileNew ); |
205 | return false; | 205 | return false; |
206 | } | 206 | } |
207 | if (!forAll( m_rep, f ) ) { | 207 | if (!forAll( m_rep, f ) ) { |
208 | f.close(); | 208 | f.close(); |
209 | QFile::remove( strFileNew ); | 209 | QFile::remove( strFileNew ); |
210 | return false; | 210 | return false; |
211 | } | 211 | } |
212 | 212 | ||
213 | buf = "</events>\n</DATEBOOK>\n"; | 213 | buf = "</events>\n</DATEBOOK>\n"; |
214 | str = buf.utf8(); | 214 | str = buf.utf8(); |
215 | total_written = f.writeBlock( str.data(), str.length() ); | 215 | total_written = f.writeBlock( str.data(), str.length() ); |
216 | if ( total_written != int(str.length() ) ) { | 216 | if ( total_written != int(str.length() ) ) { |
217 | f.close(); | 217 | f.close(); |
218 | QFile::remove( strFileNew ); | 218 | QFile::remove( strFileNew ); |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | f.close(); | 221 | f.close(); |
222 | 222 | ||
223 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 223 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
224 | QFile::remove( strFileNew ); | 224 | QFile::remove( strFileNew ); |
225 | return false; | 225 | return false; |
226 | } | 226 | } |
227 | 227 | ||
228 | m_changed = false; | 228 | m_changed = false; |
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
233 | uint i = 0; | 233 | uint i = 0; |
234 | QMap<int, OEvent>::ConstIterator it; | 234 | QMap<int, OEvent>::ConstIterator it; |
235 | 235 | ||
236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
237 | ints[i] = it.key(); | 237 | ints[i] = it.key(); |
238 | i++; | 238 | i++; |
239 | } | 239 | } |
240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
241 | ints[i] = it.key(); | 241 | ints[i] = it.key(); |
242 | i++; | 242 | i++; |
243 | } | 243 | } |
244 | 244 | ||
245 | return ints; | 245 | return ints; |
246 | } | 246 | } |
247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { | 247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { |
248 | return QArray<int>(); | 248 | return QArray<int>(); |
249 | } | 249 | } |
250 | void ODateBookAccessBackend_XML::clear() { | 250 | void ODateBookAccessBackend_XML::clear() { |
251 | m_changed = true; | 251 | m_changed = true; |
252 | m_raw.clear(); | 252 | m_raw.clear(); |
253 | m_rep.clear(); | 253 | m_rep.clear(); |
254 | } | 254 | } |
255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
256 | if ( m_raw.contains( uid ) ) | 256 | if ( m_raw.contains( uid ) ) |
257 | return m_raw[uid]; | 257 | return m_raw[uid]; |
258 | else | 258 | else |
259 | return m_rep[uid]; | 259 | return m_rep[uid]; |
260 | } | 260 | } |
261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
262 | m_changed = true; | 262 | m_changed = true; |
263 | if (ev.hasRecurrence() ) | 263 | if (ev.hasRecurrence() ) |
264 | m_rep.insert( ev.uid(), ev ); | 264 | m_rep.insert( ev.uid(), ev ); |
265 | else | 265 | else |
266 | m_raw.insert( ev.uid(), ev ); | 266 | m_raw.insert( ev.uid(), ev ); |
267 | 267 | ||
268 | return true; | 268 | return true; |
269 | } | 269 | } |
270 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 270 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
271 | m_changed = true; | 271 | m_changed = true; |
272 | m_rep.remove( uid ); | 272 | m_rep.remove( uid ); |
273 | m_rep.remove( uid ); | 273 | m_rep.remove( uid ); |
274 | 274 | ||
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
278 | replace( ev.uid() ); | 278 | replace( ev.uid() ); |
279 | return add( ev ); | 279 | return add( ev ); |
280 | } | 280 | } |
281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
282 | return allRecords(); | 282 | return allRecords(); |
283 | } | 283 | } |
284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
285 | QArray<int> ints( m_rep.count() ); | 285 | QArray<int> ints( m_rep.count() ); |
286 | uint i = 0; | 286 | uint i = 0; |
287 | QMap<int, OEvent>::ConstIterator it; | 287 | QMap<int, OEvent>::ConstIterator it; |
288 | 288 | ||
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index 563b19c..3d774e2 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h | |||
@@ -1,157 +1,158 @@ | |||
1 | #ifndef OPIE_PIM_RECORD_H | 1 | #ifndef OPIE_PIM_RECORD_H |
2 | #define OPIE_PIM_RECORD_H | 2 | #define OPIE_PIM_RECORD_H |
3 | 3 | ||
4 | #include <qdatastream.h> | 4 | #include <qdatastream.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qstringlist.h> | 7 | #include <qstringlist.h> |
8 | 8 | ||
9 | /* | 9 | /* |
10 | * we need to get customMap which is private... | 10 | * we need to get customMap which is private... |
11 | */ | 11 | */ |
12 | #define private protected | 12 | #define private protected |
13 | #include <qpe/palmtoprecord.h> | 13 | #include <qpe/palmtoprecord.h> |
14 | #undef private | 14 | #undef private |
15 | 15 | ||
16 | #include <opie/opimxrefmanager.h> | 16 | #include <opie/opimxrefmanager.h> |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * This is the base class for | 19 | * This is the base class for |
20 | * all PIM Records | 20 | * all PIM Records |
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | class OPimRecord : public Qtopia::Record { | 23 | class OPimRecord : public Qtopia::Record { |
24 | public: | 24 | public: |
25 | /** | 25 | /** |
26 | * c'tor | 26 | * c'tor |
27 | * uid of 0 isEmpty | 27 | * uid of 0 isEmpty |
28 | * uid of 1 will be assigned a new one | 28 | * uid of 1 will be assigned a new one |
29 | */ | 29 | */ |
30 | OPimRecord(int uid = 0); | 30 | OPimRecord(int uid = 0); |
31 | ~OPimRecord(); | 31 | ~OPimRecord(); |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * copy c'tor | 34 | * copy c'tor |
35 | */ | 35 | */ |
36 | OPimRecord( const OPimRecord& rec ); | 36 | OPimRecord( const OPimRecord& rec ); |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * copy operator | 39 | * copy operator |
40 | */ | 40 | */ |
41 | OPimRecord &operator=( const OPimRecord& ); | 41 | OPimRecord &operator=( const OPimRecord& ); |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * category names resolved | 44 | * category names resolved |
45 | */ | 45 | */ |
46 | QStringList categoryNames( const QString& appname )const; | 46 | QStringList categoryNames( const QString& appname )const; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * set category names they will be resolved | 49 | * set category names they will be resolved |
50 | */ | 50 | */ |
51 | void setCategoryNames( const QStringList& ); | 51 | void setCategoryNames( const QStringList& ); |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * addCategoryName adds a name | 54 | * addCategoryName adds a name |
55 | * to the internal category list | 55 | * to the internal category list |
56 | */ | 56 | */ |
57 | void addCategoryName( const QString& ); | 57 | void addCategoryName( const QString& ); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * if a Record isEmpty | 60 | * if a Record isEmpty |
61 | * it's empty if it's 0 | 61 | * it's empty if it's 0 |
62 | */ | 62 | */ |
63 | virtual bool isEmpty()const; | 63 | virtual bool isEmpty()const; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * toRichText summary | 66 | * toRichText summary |
67 | */ | 67 | */ |
68 | virtual QString toRichText()const = 0; | 68 | virtual QString toRichText()const = 0; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * a small one line summary | 71 | * a small one line summary |
72 | */ | 72 | */ |
73 | virtual QString toShortText()const = 0; | 73 | virtual QString toShortText()const = 0; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * the name of the Record | 76 | * the name of the Record |
77 | */ | 77 | */ |
78 | virtual QString type()const = 0; | 78 | virtual QString type()const = 0; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * matches the Records the regular expression? | 81 | * matches the Records the regular expression? |
82 | */ | 82 | */ |
83 | virtual bool match( const QString ®exp ) const | 83 | virtual bool match( const QString ®exp ) const |
84 | {setLastHitField( -1 ); | 84 | {setLastHitField( -1 ); |
85 | return Qtopia::Record::match(QRegExp(regexp));}; | 85 | return Qtopia::Record::match(QRegExp(regexp));}; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * if implemented this function returns which item has been | 88 | * if implemented this function returns which item has been |
89 | * last hit by the match() function. | 89 | * last hit by the match() function. |
90 | * or -1 if not implemented or no hit has occured | 90 | * or -1 if not implemented or no hit has occured |
91 | */ | 91 | */ |
92 | int lastHitField()const; | 92 | int lastHitField()const; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * converts the internal structure to a map | 95 | * converts the internal structure to a map |
96 | */ | 96 | */ |
97 | virtual QMap<int, QString> toMap()const = 0; | 97 | virtual QMap<int, QString> toMap()const = 0; |
98 | // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers) | ||
98 | 99 | ||
99 | /** | 100 | /** |
100 | * key value representation of extra items | 101 | * key value representation of extra items |
101 | */ | 102 | */ |
102 | QMap<QString, QString> toExtraMap()const; | 103 | QMap<QString, QString> toExtraMap()const; |
103 | void setExtraMap( const QMap<QString, QString>& ); | 104 | void setExtraMap( const QMap<QString, QString>& ); |
104 | 105 | ||
105 | /** | 106 | /** |
106 | * the name for a recordField | 107 | * the name for a recordField |
107 | */ | 108 | */ |
108 | virtual QString recordField(int)const = 0; | 109 | virtual QString recordField(int)const = 0; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * returns a reference of the | 112 | * returns a reference of the |
112 | * Cross Reference Manager | 113 | * Cross Reference Manager |
113 | * Partner 'One' is THIS PIM RECORD! | 114 | * Partner 'One' is THIS PIM RECORD! |
114 | * 'Two' is the Partner where we link to | 115 | * 'Two' is the Partner where we link to |
115 | */ | 116 | */ |
116 | OPimXRefManager& xrefmanager(); | 117 | OPimXRefManager& xrefmanager(); |
117 | 118 | ||
118 | /** | 119 | /** |
119 | * set the uid | 120 | * set the uid |
120 | */ | 121 | */ |
121 | virtual void setUid( int uid ); | 122 | virtual void setUid( int uid ); |
122 | 123 | ||
123 | /* | 124 | /* |
124 | * used inside the Templates for casting | 125 | * used inside the Templates for casting |
125 | * REIMPLEMENT in your .... | 126 | * REIMPLEMENT in your .... |
126 | */ | 127 | */ |
127 | static int rtti(); | 128 | static int rtti(); |
128 | 129 | ||
129 | /** | 130 | /** |
130 | * some marshalling and de marshalling code | 131 | * some marshalling and de marshalling code |
131 | * saves the OPimRecord | 132 | * saves the OPimRecord |
132 | * to and from a DataStream | 133 | * to and from a DataStream |
133 | */ | 134 | */ |
134 | virtual bool loadFromStream(QDataStream& ); | 135 | virtual bool loadFromStream(QDataStream& ); |
135 | virtual bool saveToStream( QDataStream& stream )const; | 136 | virtual bool saveToStream( QDataStream& stream )const; |
136 | 137 | ||
137 | protected: | 138 | protected: |
138 | // need to be const cause it is called from const methods | 139 | // need to be const cause it is called from const methods |
139 | mutable int m_lastHit; | 140 | mutable int m_lastHit; |
140 | void setLastHitField( int lastHit )const; | 141 | void setLastHitField( int lastHit )const; |
141 | Qtopia::UidGen &uidGen(); | 142 | Qtopia::UidGen &uidGen(); |
142 | // QString crossToString()const; | 143 | // QString crossToString()const; |
143 | 144 | ||
144 | private: | 145 | private: |
145 | class OPimRecordPrivate; | 146 | class OPimRecordPrivate; |
146 | OPimRecordPrivate *d; | 147 | OPimRecordPrivate *d; |
147 | OPimXRefManager m_xrefman; | 148 | OPimXRefManager m_xrefman; |
148 | static Qtopia::UidGen m_uidGen; | 149 | static Qtopia::UidGen m_uidGen; |
149 | 150 | ||
150 | private: | 151 | private: |
151 | void flush( const OPimXRefPartner&, QDataStream& stream )const; | 152 | void flush( const OPimXRefPartner&, QDataStream& stream )const; |
152 | OPimXRefPartner partner( QDataStream& ); | 153 | OPimXRefPartner partner( QDataStream& ); |
153 | }; | 154 | }; |
154 | 155 | ||
155 | 156 | ||
156 | 157 | ||
157 | #endif | 158 | #endif |