summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authorzecke <zecke>2003-04-13 16:55:34 (UTC)
committer zecke <zecke>2003-04-13 16:55:34 (UTC)
commit1537ccb435ca725c793db6e94e0b9e83484b57e7 (patch) (unidiff)
treef1aa77e10de202c058259ece02216957d8d520e3 /libopie2/opiepim
parent3bd592876c43c11ed44b2f3725d4c7425ebceb09 (diff)
downloadopie-1537ccb435ca725c793db6e94e0b9e83484b57e7.zip
opie-1537ccb435ca725c793db6e94e0b9e83484b57e7.tar.gz
opie-1537ccb435ca725c793db6e94e0b9e83484b57e7.tar.bz2
OEvent/OTodo compare by address and not by value..
ODatebookAccess: clear does change it too
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp1
-rw-r--r--libopie2/opiepim/oevent.cpp2
-rw-r--r--libopie2/opiepim/otodo.cpp2
3 files changed, 3 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index 11e19d9..a0ae7b7 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -1,587 +1,588 @@
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
25namespace { 25namespace {
26 // FROM TT again 26 // FROM TT again
27char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 27char *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
52namespace { 52namespace {
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\"";
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
167ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 167ODateBookAccessBackend_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}
173ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { 173ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
174} 174}
175bool ODateBookAccessBackend_XML::load() { 175bool ODateBookAccessBackend_XML::load() {
176 return loadFile(); 176 return loadFile();
177} 177}
178bool ODateBookAccessBackend_XML::reload() { 178bool ODateBookAccessBackend_XML::reload() {
179 clear(); 179 clear();
180 return load(); 180 return load();
181} 181}
182bool ODateBookAccessBackend_XML::save() { 182bool 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}
231QArray<int> ODateBookAccessBackend_XML::allRecords()const { 231QArray<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}
247QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { 247QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) {
248 return QArray<int>(); 248 return QArray<int>();
249} 249}
250void ODateBookAccessBackend_XML::clear() { 250void ODateBookAccessBackend_XML::clear() {
251 m_changed = true;
251 m_raw.clear(); 252 m_raw.clear();
252 m_rep.clear(); 253 m_rep.clear();
253} 254}
254OEvent ODateBookAccessBackend_XML::find( int uid ) const{ 255OEvent ODateBookAccessBackend_XML::find( int uid ) const{
255 if ( m_raw.contains( uid ) ) 256 if ( m_raw.contains( uid ) )
256 return m_raw[uid]; 257 return m_raw[uid];
257 else 258 else
258 return m_rep[uid]; 259 return m_rep[uid];
259} 260}
260bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { 261bool ODateBookAccessBackend_XML::add( const OEvent& ev ) {
261 m_changed = true; 262 m_changed = true;
262 if (ev.hasRecurrence() ) 263 if (ev.hasRecurrence() )
263 m_rep.insert( ev.uid(), ev ); 264 m_rep.insert( ev.uid(), ev );
264 else 265 else
265 m_raw.insert( ev.uid(), ev ); 266 m_raw.insert( ev.uid(), ev );
266 267
267 return true; 268 return true;
268} 269}
269bool ODateBookAccessBackend_XML::remove( int uid ) { 270bool ODateBookAccessBackend_XML::remove( int uid ) {
270 m_changed = true; 271 m_changed = true;
271 m_rep.remove( uid ); 272 m_rep.remove( uid );
272 m_rep.remove( uid ); 273 m_rep.remove( uid );
273 274
274 return true; 275 return true;
275} 276}
276bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { 277bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) {
277 replace( ev.uid() ); 278 replace( ev.uid() );
278 return add( ev ); 279 return add( ev );
279} 280}
280QArray<int> ODateBookAccessBackend_XML::rawEvents()const { 281QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
281 return allRecords(); 282 return allRecords();
282} 283}
283QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { 284QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
284 QArray<int> ints( m_rep.count() ); 285 QArray<int> ints( m_rep.count() );
285 uint i = 0; 286 uint i = 0;
286 QMap<int, OEvent>::ConstIterator it; 287 QMap<int, OEvent>::ConstIterator it;
287 288
288 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 289 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
289 ints[i] = it.key(); 290 ints[i] = it.key();
290 i++; 291 i++;
291 } 292 }
292 293
293 return ints; 294 return ints;
294} 295}
295QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { 296QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
296 QArray<int> ints( m_raw.count() ); 297 QArray<int> ints( m_raw.count() );
297 uint i = 0; 298 uint i = 0;
298 QMap<int, OEvent>::ConstIterator it; 299 QMap<int, OEvent>::ConstIterator it;
299 300
300 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 301 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
301 ints[i] = it.key(); 302 ints[i] = it.key();
302 i++; 303 i++;
303 } 304 }
304 305
305 return ints; 306 return ints;
306} 307}
307OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { 308OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
308 OEvent::ValueList list; 309 OEvent::ValueList list;
309 QMap<int, OEvent>::ConstIterator it; 310 QMap<int, OEvent>::ConstIterator it;
310 for (it = m_raw.begin(); it != m_raw.end(); ++it ) 311 for (it = m_raw.begin(); it != m_raw.end(); ++it )
311 list.append( it.data() ); 312 list.append( it.data() );
312 313
313 return list; 314 return list;
314} 315}
315OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { 316OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
316 OEvent::ValueList list; 317 OEvent::ValueList list;
317 QMap<int, OEvent>::ConstIterator it; 318 QMap<int, OEvent>::ConstIterator it;
318 for (it = m_rep.begin(); it != m_rep.end(); ++it ) 319 for (it = m_rep.begin(); it != m_rep.end(); ++it )
319 list.append( it.data() ); 320 list.append( it.data() );
320 321
321 return list; 322 return list;
322} 323}
323bool ODateBookAccessBackend_XML::loadFile() { 324bool ODateBookAccessBackend_XML::loadFile() {
324 m_changed = false; 325 m_changed = false;
325 326
326 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); 327 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY );
327 if ( fd < 0 ) return false; 328 if ( fd < 0 ) return false;
328 329
329 struct stat attribute; 330 struct stat attribute;
330 if ( ::fstat(fd, &attribute ) == -1 ) { 331 if ( ::fstat(fd, &attribute ) == -1 ) {
331 ::close( fd ); 332 ::close( fd );
332 return false; 333 return false;
333 } 334 }
334 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 335 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 );
335 if ( map_addr == ( (caddr_t)-1) ) { 336 if ( map_addr == ( (caddr_t)-1) ) {
336 ::close( fd ); 337 ::close( fd );
337 return false; 338 return false;
338 } 339 }
339 340
340 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); 341 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL );
341 ::close( fd ); 342 ::close( fd );
342 343
343 QAsciiDict<int> dict(FExceptions+1); 344 QAsciiDict<int> dict(FExceptions+1);
344 dict.setAutoDelete( true ); 345 dict.setAutoDelete( true );
345 dict.insert( "description", new int(FDescription) ); 346 dict.insert( "description", new int(FDescription) );
346 dict.insert( "location", new int(FLocation) ); 347 dict.insert( "location", new int(FLocation) );
347 dict.insert( "categories", new int(FCategories) ); 348 dict.insert( "categories", new int(FCategories) );
348 dict.insert( "uid", new int(FUid) ); 349 dict.insert( "uid", new int(FUid) );
349 dict.insert( "type", new int(FType) ); 350 dict.insert( "type", new int(FType) );
350 dict.insert( "alarm", new int(FAlarm) ); 351 dict.insert( "alarm", new int(FAlarm) );
351 dict.insert( "sound", new int(FSound) ); 352 dict.insert( "sound", new int(FSound) );
352 dict.insert( "rtype", new int(FRType) ); 353 dict.insert( "rtype", new int(FRType) );
353 dict.insert( "rweekdays", new int(FRWeekdays) ); 354 dict.insert( "rweekdays", new int(FRWeekdays) );
354 dict.insert( "rposition", new int(FRPosition) ); 355 dict.insert( "rposition", new int(FRPosition) );
355 dict.insert( "rfreq", new int(FRFreq) ); 356 dict.insert( "rfreq", new int(FRFreq) );
356 dict.insert( "rhasenddate", new int(FRHasEndDate) ); 357 dict.insert( "rhasenddate", new int(FRHasEndDate) );
357 dict.insert( "enddt", new int(FREndDate) ); 358 dict.insert( "enddt", new int(FREndDate) );
358 dict.insert( "start", new int(FRStart) ); 359 dict.insert( "start", new int(FRStart) );
359 dict.insert( "end", new int(FREnd) ); 360 dict.insert( "end", new int(FREnd) );
360 dict.insert( "note", new int(FNote) ); 361 dict.insert( "note", new int(FNote) );
361 dict.insert( "created", new int(FCreated) ); 362 dict.insert( "created", new int(FCreated) );
362 dict.insert( "recparent", new int(FRecParent) ); 363 dict.insert( "recparent", new int(FRecParent) );
363 dict.insert( "recchildren", new int(FRecChildren) ); 364 dict.insert( "recchildren", new int(FRecChildren) );
364 dict.insert( "exceptions", new int(FExceptions) ); 365 dict.insert( "exceptions", new int(FExceptions) );
365 dict.insert( "timezone", new int(FTimeZone) ); 366 dict.insert( "timezone", new int(FTimeZone) );
366 367
367 char* dt = (char*)map_addr; 368 char* dt = (char*)map_addr;
368 int len = attribute.st_size; 369 int len = attribute.st_size;
369 int i = 0; 370 int i = 0;
370 char* point; 371 char* point;
371 const char* collectionString = "<event "; 372 const char* collectionString = "<event ";
372 int strLen = ::strlen(collectionString); 373 int strLen = ::strlen(collectionString);
373 int *find; 374 int *find;
374 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { 375 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
375 i = point -dt; 376 i = point -dt;
376 i+= strLen; 377 i+= strLen;
377 378
378 alarmTime = -1; 379 alarmTime = -1;
379 snd = 0; // silent 380 snd = 0; // silent
380 381
381 OEvent ev; 382 OEvent ev;
382 rec = 0; 383 rec = 0;
383 384
384 while ( TRUE ) { 385 while ( TRUE ) {
385 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 386 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
386 ++i; 387 ++i;
387 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 388 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
388 break; 389 break;
389 390
390 391
391 // we have another attribute, read it. 392 // we have another attribute, read it.
392 int j = i; 393 int j = i;
393 while ( j < len && dt[j] != '=' ) 394 while ( j < len && dt[j] != '=' )
394 ++j; 395 ++j;
395 QCString attr( dt+i, j-i+1); 396 QCString attr( dt+i, j-i+1);
396 397
397 i = ++j; // skip = 398 i = ++j; // skip =
398 399
399 // find the start of quotes 400 // find the start of quotes
400 while ( i < len && dt[i] != '"' ) 401 while ( i < len && dt[i] != '"' )
401 ++i; 402 ++i;
402 j = ++i; 403 j = ++i;
403 404
404 bool haveUtf = FALSE; 405 bool haveUtf = FALSE;
405 bool haveEnt = FALSE; 406 bool haveEnt = FALSE;
406 while ( j < len && dt[j] != '"' ) { 407 while ( j < len && dt[j] != '"' ) {
407 if ( ((unsigned char)dt[j]) > 0x7f ) 408 if ( ((unsigned char)dt[j]) > 0x7f )
408 haveUtf = TRUE; 409 haveUtf = TRUE;
409 if ( dt[j] == '&' ) 410 if ( dt[j] == '&' )
410 haveEnt = TRUE; 411 haveEnt = TRUE;
411 ++j; 412 ++j;
412 } 413 }
413 if ( i == j ) { 414 if ( i == j ) {
414 // empty value 415 // empty value
415 i = j + 1; 416 i = j + 1;
416 continue; 417 continue;
417 } 418 }
418 419
419 QCString value( dt+i, j-i+1 ); 420 QCString value( dt+i, j-i+1 );
420 i = j + 1; 421 i = j + 1;
421 422
422 QString str = (haveUtf ? QString::fromUtf8( value ) 423 QString str = (haveUtf ? QString::fromUtf8( value )
423 : QString::fromLatin1( value ) ); 424 : QString::fromLatin1( value ) );
424 if ( haveEnt ) 425 if ( haveEnt )
425 str = Qtopia::plainString( str ); 426 str = Qtopia::plainString( str );
426 427
427 /* 428 /*
428 * add key + value 429 * add key + value
429 */ 430 */
430 find = dict[attr.data()]; 431 find = dict[attr.data()];
431 if (!find) 432 if (!find)
432 ev.setCustomField( attr, value ); 433 ev.setCustomField( attr, value );
433 else { 434 else {
434 setField( ev, *find, value ); 435 setField( ev, *find, value );
435 } 436 }
436 } 437 }
437 /* time to finalize */ 438 /* time to finalize */
438 finalizeRecord( ev ); 439 finalizeRecord( ev );
439 delete rec; 440 delete rec;
440 } 441 }
441 ::munmap(map_addr, attribute.st_size ); 442 ::munmap(map_addr, attribute.st_size );
442 m_changed = false; // changed during add 443 m_changed = false; // changed during add
443 444
444 return true; 445 return true;
445} 446}
446void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { 447void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) {
447 /* AllDay is alway in UTC */ 448 /* AllDay is alway in UTC */
448 if ( ev.isAllDay() ) { 449 if ( ev.isAllDay() ) {
449 OTimeZone utc = OTimeZone::utc(); 450 OTimeZone utc = OTimeZone::utc();
450 ev.setStartDateTime( utc.fromUTCDateTime( start ) ); 451 ev.setStartDateTime( utc.fromUTCDateTime( start ) );
451 ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); 452 ev.setEndDateTime ( utc.fromUTCDateTime( end ) );
452 ev.setTimeZone( "UTC"); // make sure it is really utc 453 ev.setTimeZone( "UTC"); // make sure it is really utc
453 }else { 454 }else {
454 /* to current date time */ 455 /* to current date time */
455 qWarning(" Start is %d", start ); 456 qWarning(" Start is %d", start );
456 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); 457 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() );
457 QDateTime date = zone.toDateTime( start ); 458 QDateTime date = zone.toDateTime( start );
458 qWarning(" Start is %s", date.toString().latin1() ); 459 qWarning(" Start is %s", date.toString().latin1() );
459 ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); 460 ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );
460 461
461 date = zone.toDateTime( end ); 462 date = zone.toDateTime( end );
462 ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); 463 ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) );
463 } 464 }
464 if ( rec && rec->doesRecur() ) { 465 if ( rec && rec->doesRecur() ) {
465 OTimeZone utc = OTimeZone::utc(); 466 OTimeZone utc = OTimeZone::utc();
466 ORecur recu( *rec ); // call copy c'tor; 467 ORecur recu( *rec ); // call copy c'tor;
467 recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); 468 recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() );
468 recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); 469 recu.setCreatedDateTime( utc.fromUTCDateTime( created ) );
469 recu.setStart( ev.startDateTime().date() ); 470 recu.setStart( ev.startDateTime().date() );
470 ev.setRecurrence( recu ); 471 ev.setRecurrence( recu );
471 } 472 }
472 473
473 if (alarmTime != -1 ) { 474 if (alarmTime != -1 ) {
474 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); 475 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 );
475 OPimAlarm al( snd , dt ); 476 OPimAlarm al( snd , dt );
476 ev.notifiers().add( al ); 477 ev.notifiers().add( al );
477 } 478 }
478 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { 479 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
479 qWarning("already contains assign uid"); 480 qWarning("already contains assign uid");
480 ev.setUid( 1 ); 481 ev.setUid( 1 );
481 } 482 }
482 qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); 483 qWarning("addind %d %s", ev.uid(), ev.description().latin1() );
483 if ( ev.hasRecurrence() ) 484 if ( ev.hasRecurrence() )
484 m_rep.insert( ev.uid(), ev ); 485 m_rep.insert( ev.uid(), ev );
485 else 486 else
486 m_raw.insert( ev.uid(), ev ); 487 m_raw.insert( ev.uid(), ev );
487 488
488} 489}
489void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { 490void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) {
490// qWarning(" setting %s", value.latin1() ); 491// qWarning(" setting %s", value.latin1() );
491 switch( id ) { 492 switch( id ) {
492 case FDescription: 493 case FDescription:
493 e.setDescription( value ); 494 e.setDescription( value );
494 break; 495 break;
495 case FLocation: 496 case FLocation:
496 e.setLocation( value ); 497 e.setLocation( value );
497 break; 498 break;
498 case FCategories: 499 case FCategories:
499 e.setCategories( e.idsFromString( value ) ); 500 e.setCategories( e.idsFromString( value ) );
500 break; 501 break;
501 case FUid: 502 case FUid:
502 e.setUid( value.toInt() ); 503 e.setUid( value.toInt() );
503 break; 504 break;
504 case FType: 505 case FType:
505 if ( value == "AllDay" ) { 506 if ( value == "AllDay" ) {
506 e.setAllDay( true ); 507 e.setAllDay( true );
507 e.setTimeZone( "UTC" ); 508 e.setTimeZone( "UTC" );
508 } 509 }
509 break; 510 break;
510 case FAlarm: 511 case FAlarm:
511 alarmTime = value.toInt(); 512 alarmTime = value.toInt();
512 break; 513 break;
513 case FSound: 514 case FSound:
514 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; 515 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent;
515 break; 516 break;
516 // recurrence stuff 517 // recurrence stuff
517 case FRType: 518 case FRType:
518 if ( value == "Daily" ) 519 if ( value == "Daily" )
519 recur()->setType( ORecur::Daily ); 520 recur()->setType( ORecur::Daily );
520 else if ( value == "Weekly" ) 521 else if ( value == "Weekly" )
521 recur()->setType( ORecur::Weekly); 522 recur()->setType( ORecur::Weekly);
522 else if ( value == "MonthlyDay" ) 523 else if ( value == "MonthlyDay" )
523 recur()->setType( ORecur::MonthlyDay ); 524 recur()->setType( ORecur::MonthlyDay );
524 else if ( value == "MonthlyDate" ) 525 else if ( value == "MonthlyDate" )
525 recur()->setType( ORecur::MonthlyDate ); 526 recur()->setType( ORecur::MonthlyDate );
526 else if ( value == "Yearly" ) 527 else if ( value == "Yearly" )
527 recur()->setType( ORecur::Yearly ); 528 recur()->setType( ORecur::Yearly );
528 else 529 else
529 recur()->setType( ORecur::NoRepeat ); 530 recur()->setType( ORecur::NoRepeat );
530 break; 531 break;
531 case FRWeekdays: 532 case FRWeekdays:
532 recur()->setDays( value.toInt() ); 533 recur()->setDays( value.toInt() );
533 break; 534 break;
534 case FRPosition: 535 case FRPosition:
535 recur()->setPosition( value.toInt() ); 536 recur()->setPosition( value.toInt() );
536 break; 537 break;
537 case FRFreq: 538 case FRFreq:
538 recur()->setFrequency( value.toInt() ); 539 recur()->setFrequency( value.toInt() );
539 break; 540 break;
540 case FRHasEndDate: 541 case FRHasEndDate:
541 recur()->setHasEndDate( value.toInt() ); 542 recur()->setHasEndDate( value.toInt() );
542 break; 543 break;
543 case FREndDate: { 544 case FREndDate: {
544 rp_end = (time_t) value.toLong(); 545 rp_end = (time_t) value.toLong();
545 break; 546 break;
546 } 547 }
547 case FRStart: { 548 case FRStart: {
548 start = (time_t) value.toLong(); 549 start = (time_t) value.toLong();
549 break; 550 break;
550 } 551 }
551 case FREnd: { 552 case FREnd: {
552 end = ( (time_t) value.toLong() ); 553 end = ( (time_t) value.toLong() );
553 break; 554 break;
554 } 555 }
555 case FNote: 556 case FNote:
556 e.setNote( value ); 557 e.setNote( value );
557 break; 558 break;
558 case FCreated: 559 case FCreated:
559 created = value.toInt(); 560 created = value.toInt();
560 break; 561 break;
561 case FRecParent: 562 case FRecParent:
562 e.setParent( value.toInt() ); 563 e.setParent( value.toInt() );
563 break; 564 break;
564 case FRecChildren:{ 565 case FRecChildren:{
565 QStringList list = QStringList::split(' ', value ); 566 QStringList list = QStringList::split(' ', value );
566 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 567 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
567 e.addChild( (*it).toInt() ); 568 e.addChild( (*it).toInt() );
568 } 569 }
569 } 570 }
570 break; 571 break;
571 case FExceptions:{ 572 case FExceptions:{
572 QStringList list = QStringList::split(' ', value ); 573 QStringList list = QStringList::split(' ', value );
573 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 574 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
574 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); 575 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
575 qWarning("adding exception %s", date.toString().latin1() ); 576 qWarning("adding exception %s", date.toString().latin1() );
576 recur()->exceptions().append( date ); 577 recur()->exceptions().append( date );
577 } 578 }
578 } 579 }
579 break; 580 break;
580 case FTimeZone: 581 case FTimeZone:
581 if ( value != "None" ) 582 if ( value != "None" )
582 e.setTimeZone( value ); 583 e.setTimeZone( value );
583 break; 584 break;
584 default: 585 default:
585 break; 586 break;
586 } 587 }
587} 588}
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index c3eeee2..56ea10d 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -1,489 +1,489 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qpe/palmtopuidgen.h> 3#include <qpe/palmtopuidgen.h>
4#include <qpe/categories.h> 4#include <qpe/categories.h>
5 5
6#include "orecur.h" 6#include "orecur.h"
7#include "opimresolver.h" 7#include "opimresolver.h"
8#include "opimnotifymanager.h" 8#include "opimnotifymanager.h"
9 9
10#include "oevent.h" 10#include "oevent.h"
11 11
12int OCalendarHelper::week( const QDate& date) { 12int OCalendarHelper::week( const QDate& date) {
13 // Calculates the week this date is in within that 13 // Calculates the week this date is in within that
14 // month. Equals the "row" is is in in the month view 14 // month. Equals the "row" is is in in the month view
15 int week = 1; 15 int week = 1;
16 QDate tmp( date.year(), date.month(), 1 ); 16 QDate tmp( date.year(), date.month(), 1 );
17 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 17 if ( date.dayOfWeek() < tmp.dayOfWeek() )
18 ++week; 18 ++week;
19 19
20 week += ( date.day() - 1 ) / 7; 20 week += ( date.day() - 1 ) / 7;
21 21
22 return week; 22 return week;
23} 23}
24int OCalendarHelper::ocurrence( const QDate& date) { 24int OCalendarHelper::ocurrence( const QDate& date) {
25 // calculates the number of occurrances of this day of the 25 // calculates the number of occurrances of this day of the
26 // week till the given date (e.g 3rd Wednesday of the month) 26 // week till the given date (e.g 3rd Wednesday of the month)
27 return ( date.day() - 1 ) / 7 + 1; 27 return ( date.day() - 1 ) / 7 + 1;
28} 28}
29int OCalendarHelper::dayOfWeek( char day ) { 29int OCalendarHelper::dayOfWeek( char day ) {
30 int dayOfWeek = 1; 30 int dayOfWeek = 1;
31 char i = ORecur::MON; 31 char i = ORecur::MON;
32 while ( !( i & day ) && i <= ORecur::SUN ) { 32 while ( !( i & day ) && i <= ORecur::SUN ) {
33 i <<= 1; 33 i <<= 1;
34 ++dayOfWeek; 34 ++dayOfWeek;
35 } 35 }
36 return dayOfWeek; 36 return dayOfWeek;
37} 37}
38int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 38int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
39 return ( second.year() - first.year() ) * 12 + 39 return ( second.year() - first.year() ) * 12 +
40 second.month() - first.month(); 40 second.month() - first.month();
41} 41}
42 42
43struct OEvent::Data : public QShared { 43struct OEvent::Data : public QShared {
44 Data() : QShared() { 44 Data() : QShared() {
45 child = 0; 45 child = 0;
46 recur = 0; 46 recur = 0;
47 manager = 0; 47 manager = 0;
48 isAllDay = false; 48 isAllDay = false;
49 parent = 0; 49 parent = 0;
50 } 50 }
51 ~Data() { 51 ~Data() {
52 delete manager; 52 delete manager;
53 delete recur; 53 delete recur;
54 } 54 }
55 QString description; 55 QString description;
56 QString location; 56 QString location;
57 OPimNotifyManager* manager; 57 OPimNotifyManager* manager;
58 ORecur* recur; 58 ORecur* recur;
59 QString note; 59 QString note;
60 QDateTime created; 60 QDateTime created;
61 QDateTime start; 61 QDateTime start;
62 QDateTime end; 62 QDateTime end;
63 bool isAllDay : 1; 63 bool isAllDay : 1;
64 QString timezone; 64 QString timezone;
65 QArray<int>* child; 65 QArray<int>* child;
66 int parent; 66 int parent;
67}; 67};
68 68
69OEvent::OEvent( int uid ) 69OEvent::OEvent( int uid )
70 : OPimRecord( uid ) { 70 : OPimRecord( uid ) {
71 data = new Data; 71 data = new Data;
72} 72}
73OEvent::OEvent( const OEvent& ev) 73OEvent::OEvent( const OEvent& ev)
74 : OPimRecord( ev ), data( ev.data ) 74 : OPimRecord( ev ), data( ev.data )
75{ 75{
76 data->ref(); 76 data->ref();
77} 77}
78OEvent::~OEvent() { 78OEvent::~OEvent() {
79 if ( data->deref() ) { 79 if ( data->deref() ) {
80 delete data; 80 delete data;
81 data = 0; 81 data = 0;
82 } 82 }
83} 83}
84OEvent& OEvent::operator=( const OEvent& ev) { 84OEvent& OEvent::operator=( const OEvent& ev) {
85 if ( *this == ev ) return *this; 85 if ( this == &ev ) return *this;
86 86
87 OPimRecord::operator=( ev ); 87 OPimRecord::operator=( ev );
88 ev.data->ref(); 88 ev.data->ref();
89 deref(); 89 deref();
90 data = ev.data; 90 data = ev.data;
91 91
92 92
93 return *this; 93 return *this;
94} 94}
95QString OEvent::description()const { 95QString OEvent::description()const {
96 return data->description; 96 return data->description;
97} 97}
98void OEvent::setDescription( const QString& description ) { 98void OEvent::setDescription( const QString& description ) {
99 changeOrModify(); 99 changeOrModify();
100 data->description = description; 100 data->description = description;
101} 101}
102void OEvent::setLocation( const QString& loc ) { 102void OEvent::setLocation( const QString& loc ) {
103 changeOrModify(); 103 changeOrModify();
104 data->location = loc; 104 data->location = loc;
105} 105}
106QString OEvent::location()const { 106QString OEvent::location()const {
107 return data->location; 107 return data->location;
108} 108}
109OPimNotifyManager &OEvent::notifiers()const { 109OPimNotifyManager &OEvent::notifiers()const {
110 // I hope we can skip the changeOrModify here 110 // I hope we can skip the changeOrModify here
111 // the notifier should take care of it 111 // the notifier should take care of it
112 // and OPimNotify is shared too 112 // and OPimNotify is shared too
113 if (!data->manager ) 113 if (!data->manager )
114 data->manager = new OPimNotifyManager; 114 data->manager = new OPimNotifyManager;
115 115
116 return *data->manager; 116 return *data->manager;
117} 117}
118bool OEvent::hasNotifiers()const { 118bool OEvent::hasNotifiers()const {
119 if (!data->manager ) 119 if (!data->manager )
120 return false; 120 return false;
121 if (data->manager->reminders().isEmpty() && 121 if (data->manager->reminders().isEmpty() &&
122 data->manager->alarms().isEmpty() ) 122 data->manager->alarms().isEmpty() )
123 return false; 123 return false;
124 124
125 return true; 125 return true;
126} 126}
127ORecur OEvent::recurrence()const { 127ORecur OEvent::recurrence()const {
128 if (!data->recur) 128 if (!data->recur)
129 data->recur = new ORecur; 129 data->recur = new ORecur;
130 130
131 return *data->recur; 131 return *data->recur;
132} 132}
133void OEvent::setRecurrence( const ORecur& rec) { 133void OEvent::setRecurrence( const ORecur& rec) {
134 changeOrModify(); 134 changeOrModify();
135 if (data->recur ) 135 if (data->recur )
136 (*data->recur) = rec; 136 (*data->recur) = rec;
137 else 137 else
138 data->recur = new ORecur( rec ); 138 data->recur = new ORecur( rec );
139} 139}
140bool OEvent::hasRecurrence()const { 140bool OEvent::hasRecurrence()const {
141 if (!data->recur ) return false; 141 if (!data->recur ) return false;
142 return data->recur->doesRecur(); 142 return data->recur->doesRecur();
143} 143}
144QString OEvent::note()const { 144QString OEvent::note()const {
145 return data->note; 145 return data->note;
146} 146}
147void OEvent::setNote( const QString& note ) { 147void OEvent::setNote( const QString& note ) {
148 changeOrModify(); 148 changeOrModify();
149 data->note = note; 149 data->note = note;
150} 150}
151QDateTime OEvent::createdDateTime()const { 151QDateTime OEvent::createdDateTime()const {
152 return data->created; 152 return data->created;
153} 153}
154void OEvent::setCreatedDateTime( const QDateTime& time ) { 154void OEvent::setCreatedDateTime( const QDateTime& time ) {
155 changeOrModify(); 155 changeOrModify();
156 data->created = time; 156 data->created = time;
157} 157}
158QDateTime OEvent::startDateTime()const { 158QDateTime OEvent::startDateTime()const {
159 if ( data->isAllDay ) 159 if ( data->isAllDay )
160 return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); 160 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
161 return data->start; 161 return data->start;
162} 162}
163QDateTime OEvent::startDateTimeInZone()const { 163QDateTime OEvent::startDateTimeInZone()const {
164 /* if no timezone, or all day event or if the current and this timeZone match... */ 164 /* if no timezone, or all day event or if the current and this timeZone match... */
165 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); 165 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
166 166
167 OTimeZone zone(data->timezone ); 167 OTimeZone zone(data->timezone );
168 return zone.toDateTime( data->start, OTimeZone::current() ); 168 return zone.toDateTime( data->start, OTimeZone::current() );
169} 169}
170void OEvent::setStartDateTime( const QDateTime& dt ) { 170void OEvent::setStartDateTime( const QDateTime& dt ) {
171 changeOrModify(); 171 changeOrModify();
172 data->start = dt; 172 data->start = dt;
173} 173}
174QDateTime OEvent::endDateTime()const { 174QDateTime OEvent::endDateTime()const {
175 /* 175 /*
176 * if all Day event the end time needs 176 * if all Day event the end time needs
177 * to be on the same day as the start 177 * to be on the same day as the start
178 */ 178 */
179 if ( data->isAllDay ) 179 if ( data->isAllDay )
180 return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); 180 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
181 return data->end; 181 return data->end;
182} 182}
183QDateTime OEvent::endDateTimeInZone()const { 183QDateTime OEvent::endDateTimeInZone()const {
184 /* if no timezone, or all day event or if the current and this timeZone match... */ 184 /* if no timezone, or all day event or if the current and this timeZone match... */
185 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); 185 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
186 186
187 OTimeZone zone(data->timezone ); 187 OTimeZone zone(data->timezone );
188 return zone.toDateTime( data->end, OTimeZone::current() ); 188 return zone.toDateTime( data->end, OTimeZone::current() );
189} 189}
190void OEvent::setEndDateTime( const QDateTime& dt ) { 190void OEvent::setEndDateTime( const QDateTime& dt ) {
191 changeOrModify(); 191 changeOrModify();
192 data->end = dt; 192 data->end = dt;
193} 193}
194bool OEvent::isMultipleDay()const { 194bool OEvent::isMultipleDay()const {
195 return data->end.date().day() - data->start.date().day(); 195 return data->end.date().day() - data->start.date().day();
196} 196}
197bool OEvent::isAllDay()const { 197bool OEvent::isAllDay()const {
198 return data->isAllDay; 198 return data->isAllDay;
199} 199}
200void OEvent::setAllDay( bool allDay ) { 200void OEvent::setAllDay( bool allDay ) {
201 changeOrModify(); 201 changeOrModify();
202 data->isAllDay = allDay; 202 data->isAllDay = allDay;
203 if (allDay ) data->timezone = "UTC"; 203 if (allDay ) data->timezone = "UTC";
204} 204}
205void OEvent::setTimeZone( const QString& tz ) { 205void OEvent::setTimeZone( const QString& tz ) {
206 changeOrModify(); 206 changeOrModify();
207 data->timezone = tz; 207 data->timezone = tz;
208} 208}
209QString OEvent::timeZone()const { 209QString OEvent::timeZone()const {
210 if (data->isAllDay ) return QString::fromLatin1("UTC"); 210 if (data->isAllDay ) return QString::fromLatin1("UTC");
211 return data->timezone; 211 return data->timezone;
212} 212}
213bool OEvent::match( const QRegExp& )const { 213bool OEvent::match( const QRegExp& )const {
214 // FIXME 214 // FIXME
215 return false; 215 return false;
216} 216}
217QString OEvent::toRichText()const { 217QString OEvent::toRichText()const {
218 // FIXME 218 // FIXME
219 return "OEvent test"; 219 return "OEvent test";
220} 220}
221QString OEvent::toShortText()const { 221QString OEvent::toShortText()const {
222 return "OEvent shotText"; 222 return "OEvent shotText";
223} 223}
224QString OEvent::type()const { 224QString OEvent::type()const {
225 return QString::fromLatin1("OEvent"); 225 return QString::fromLatin1("OEvent");
226} 226}
227QString OEvent::recordField( int /*id */ )const { 227QString OEvent::recordField( int /*id */ )const {
228 return QString::null; 228 return QString::null;
229} 229}
230int OEvent::rtti() { 230int OEvent::rtti() {
231 return OPimResolver::DateBook; 231 return OPimResolver::DateBook;
232} 232}
233bool OEvent::loadFromStream( QDataStream& ) { 233bool OEvent::loadFromStream( QDataStream& ) {
234 return true; 234 return true;
235} 235}
236bool OEvent::saveToStream( QDataStream& )const { 236bool OEvent::saveToStream( QDataStream& )const {
237 return true; 237 return true;
238} 238}
239void OEvent::changeOrModify() { 239void OEvent::changeOrModify() {
240 if ( data->count != 1 ) { 240 if ( data->count != 1 ) {
241 data->deref(); 241 data->deref();
242 Data* d2 = new Data; 242 Data* d2 = new Data;
243 d2->description = data->description; 243 d2->description = data->description;
244 d2->location = data->location; 244 d2->location = data->location;
245 d2->manager = data->manager; 245 d2->manager = data->manager;
246 d2->recur = data->recur; 246 d2->recur = data->recur;
247 d2->note = data->note; 247 d2->note = data->note;
248 d2->created = data->created; 248 d2->created = data->created;
249 d2->start = data->start; 249 d2->start = data->start;
250 d2->end = data->end; 250 d2->end = data->end;
251 d2->isAllDay = data->isAllDay; 251 d2->isAllDay = data->isAllDay;
252 d2->timezone = data->timezone; 252 d2->timezone = data->timezone;
253 d2->parent = data->parent; 253 d2->parent = data->parent;
254 d2->child = data->child; 254 d2->child = data->child;
255 255
256 if (d2->child ) 256 if (d2->child )
257 d2->child->detach(); 257 d2->child->detach();
258 258
259 data = d2; 259 data = d2;
260 } 260 }
261} 261}
262void OEvent::deref() { 262void OEvent::deref() {
263 if ( data->deref() ) { 263 if ( data->deref() ) {
264 delete data; 264 delete data;
265 data = 0; 265 data = 0;
266 } 266 }
267} 267}
268// FIXME 268// FIXME
269QMap<int, QString> OEvent::toMap()const { 269QMap<int, QString> OEvent::toMap()const {
270 return QMap<int, QString>(); 270 return QMap<int, QString>();
271} 271}
272QMap<QString, QString> OEvent::toExtraMap()const { 272QMap<QString, QString> OEvent::toExtraMap()const {
273 return QMap<QString, QString>(); 273 return QMap<QString, QString>();
274} 274}
275int OEvent::parent()const { 275int OEvent::parent()const {
276 return data->parent; 276 return data->parent;
277} 277}
278void OEvent::setParent( int uid ) { 278void OEvent::setParent( int uid ) {
279 changeOrModify(); 279 changeOrModify();
280 data->parent = uid; 280 data->parent = uid;
281} 281}
282QArray<int> OEvent::children() const{ 282QArray<int> OEvent::children() const{
283 if (!data->child) return QArray<int>(); 283 if (!data->child) return QArray<int>();
284 else 284 else
285 return data->child->copy(); 285 return data->child->copy();
286} 286}
287void OEvent::setChildren( const QArray<int>& arr ) { 287void OEvent::setChildren( const QArray<int>& arr ) {
288 changeOrModify(); 288 changeOrModify();
289 if (data->child) delete data->child; 289 if (data->child) delete data->child;
290 290
291 data->child = new QArray<int>( arr ); 291 data->child = new QArray<int>( arr );
292 data->child->detach(); 292 data->child->detach();
293} 293}
294void OEvent::addChild( int uid ) { 294void OEvent::addChild( int uid ) {
295 changeOrModify(); 295 changeOrModify();
296 if (!data->child ) { 296 if (!data->child ) {
297 data->child = new QArray<int>(1); 297 data->child = new QArray<int>(1);
298 (*data->child)[0] = uid; 298 (*data->child)[0] = uid;
299 }else{ 299 }else{
300 int count = data->child->count(); 300 int count = data->child->count();
301 data->child->resize( count + 1 ); 301 data->child->resize( count + 1 );
302 (*data->child)[count] = uid; 302 (*data->child)[count] = uid;
303 } 303 }
304} 304}
305void OEvent::removeChild( int uid ) { 305void OEvent::removeChild( int uid ) {
306 if (!data->child || !data->child->contains( uid ) ) return; 306 if (!data->child || !data->child->contains( uid ) ) return;
307 changeOrModify(); 307 changeOrModify();
308 QArray<int> newAr( data->child->count() - 1 ); 308 QArray<int> newAr( data->child->count() - 1 );
309 int j = 0; 309 int j = 0;
310 uint count = data->child->count(); 310 uint count = data->child->count();
311 for ( uint i = 0; i < count; i++ ) { 311 for ( uint i = 0; i < count; i++ ) {
312 if ( (*data->child)[i] != uid ) { 312 if ( (*data->child)[i] != uid ) {
313 newAr[j] = (*data->child)[i]; 313 newAr[j] = (*data->child)[i];
314 j++; 314 j++;
315 } 315 }
316 } 316 }
317 (*data->child) = newAr; 317 (*data->child) = newAr;
318} 318}
319struct OEffectiveEvent::Data : public QShared { 319struct OEffectiveEvent::Data : public QShared {
320 Data() : QShared() { 320 Data() : QShared() {
321 } 321 }
322 OEvent event; 322 OEvent event;
323 QDate date; 323 QDate date;
324 QTime start, end; 324 QTime start, end;
325 QDate startDate, endDate; 325 QDate startDate, endDate;
326 bool dates : 1; 326 bool dates : 1;
327}; 327};
328 328
329OEffectiveEvent::OEffectiveEvent() { 329OEffectiveEvent::OEffectiveEvent() {
330 data = new Data; 330 data = new Data;
331 data->date = QDate::currentDate(); 331 data->date = QDate::currentDate();
332 data->start = data->end = QTime::currentTime(); 332 data->start = data->end = QTime::currentTime();
333 data->dates = false; 333 data->dates = false;
334} 334}
335OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 335OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
336 Position pos ) { 336 Position pos ) {
337 data = new Data; 337 data = new Data;
338 data->event = ev; 338 data->event = ev;
339 data->date = startDate; 339 data->date = startDate;
340 if ( pos & Start ) 340 if ( pos & Start )
341 data->start = ev.startDateTime().time(); 341 data->start = ev.startDateTime().time();
342 else 342 else
343 data->start = QTime( 0, 0, 0 ); 343 data->start = QTime( 0, 0, 0 );
344 344
345 if ( pos & End ) 345 if ( pos & End )
346 data->end = ev.endDateTime().time(); 346 data->end = ev.endDateTime().time();
347 else 347 else
348 data->end = QTime( 23, 59, 59 ); 348 data->end = QTime( 23, 59, 59 );
349 349
350 data->dates = false; 350 data->dates = false;
351} 351}
352OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 352OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
353 data = ev.data; 353 data = ev.data;
354 data->ref(); 354 data->ref();
355} 355}
356OEffectiveEvent::~OEffectiveEvent() { 356OEffectiveEvent::~OEffectiveEvent() {
357 if ( data->deref() ) { 357 if ( data->deref() ) {
358 delete data; 358 delete data;
359 data = 0; 359 data = 0;
360 } 360 }
361} 361}
362OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 362OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
363 if ( *this == ev ) return *this; 363 if ( *this == ev ) return *this;
364 364
365 ev.data->ref(); 365 ev.data->ref();
366 deref(); 366 deref();
367 data = ev.data; 367 data = ev.data;
368 368
369 return *this; 369 return *this;
370} 370}
371 371
372void OEffectiveEvent::setStartTime( const QTime& ti) { 372void OEffectiveEvent::setStartTime( const QTime& ti) {
373 changeOrModify(); 373 changeOrModify();
374 data->start = ti; 374 data->start = ti;
375} 375}
376void OEffectiveEvent::setEndTime( const QTime& en) { 376void OEffectiveEvent::setEndTime( const QTime& en) {
377 changeOrModify(); 377 changeOrModify();
378 data->end = en; 378 data->end = en;
379} 379}
380void OEffectiveEvent::setEvent( const OEvent& ev) { 380void OEffectiveEvent::setEvent( const OEvent& ev) {
381 changeOrModify(); 381 changeOrModify();
382 data->event = ev; 382 data->event = ev;
383} 383}
384void OEffectiveEvent::setDate( const QDate& da) { 384void OEffectiveEvent::setDate( const QDate& da) {
385 changeOrModify(); 385 changeOrModify();
386 data->date = da; 386 data->date = da;
387} 387}
388void OEffectiveEvent::setEffectiveDates( const QDate& from, 388void OEffectiveEvent::setEffectiveDates( const QDate& from,
389 const QDate& to ) { 389 const QDate& to ) {
390 if (!from.isValid() ) { 390 if (!from.isValid() ) {
391 data->dates = false; 391 data->dates = false;
392 return; 392 return;
393 } 393 }
394 394
395 data->startDate = from; 395 data->startDate = from;
396 data->endDate = to; 396 data->endDate = to;
397} 397}
398QString OEffectiveEvent::description()const { 398QString OEffectiveEvent::description()const {
399 return data->event.description(); 399 return data->event.description();
400} 400}
401QString OEffectiveEvent::location()const { 401QString OEffectiveEvent::location()const {
402 return data->event.location(); 402 return data->event.location();
403} 403}
404QString OEffectiveEvent::note()const { 404QString OEffectiveEvent::note()const {
405 return data->event.note(); 405 return data->event.note();
406} 406}
407OEvent OEffectiveEvent::event()const { 407OEvent OEffectiveEvent::event()const {
408 return data->event; 408 return data->event;
409} 409}
410QTime OEffectiveEvent::startTime()const { 410QTime OEffectiveEvent::startTime()const {
411 return data->start; 411 return data->start;
412} 412}
413QTime OEffectiveEvent::endTime()const { 413QTime OEffectiveEvent::endTime()const {
414 return data->end; 414 return data->end;
415} 415}
416QDate OEffectiveEvent::date()const { 416QDate OEffectiveEvent::date()const {
417 return data->date; 417 return data->date;
418} 418}
419int OEffectiveEvent::length()const { 419int OEffectiveEvent::length()const {
420 return (data->end.hour() * 60 - data->start.hour() * 60) 420 return (data->end.hour() * 60 - data->start.hour() * 60)
421 + QABS(data->start.minute() - data->end.minute() ); 421 + QABS(data->start.minute() - data->end.minute() );
422} 422}
423int OEffectiveEvent::size()const { 423int OEffectiveEvent::size()const {
424 return ( data->end.hour() - data->start.hour() ) * 3600 424 return ( data->end.hour() - data->start.hour() ) * 3600
425 + (data->end.minute() - data->start.minute() * 60 425 + (data->end.minute() - data->start.minute() * 60
426 + data->end.second() - data->start.second() ); 426 + data->end.second() - data->start.second() );
427} 427}
428QDate OEffectiveEvent::startDate()const { 428QDate OEffectiveEvent::startDate()const {
429 if ( data->dates ) 429 if ( data->dates )
430 return data->startDate; 430 return data->startDate;
431 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 431 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
432 return data->date; 432 return data->date;
433 else 433 else
434 return data->event.startDateTime().date(); 434 return data->event.startDateTime().date();
435} 435}
436QDate OEffectiveEvent::endDate()const { 436QDate OEffectiveEvent::endDate()const {
437 if ( data->dates ) 437 if ( data->dates )
438 return data->endDate; 438 return data->endDate;
439 else if ( data->event.hasRecurrence() ) 439 else if ( data->event.hasRecurrence() )
440 return data->date; 440 return data->date;
441 else 441 else
442 return data->event.endDateTime().date(); 442 return data->event.endDateTime().date();
443} 443}
444void OEffectiveEvent::deref() { 444void OEffectiveEvent::deref() {
445 if ( data->deref() ) { 445 if ( data->deref() ) {
446 delete data; 446 delete data;
447 data = 0; 447 data = 0;
448 } 448 }
449} 449}
450void OEffectiveEvent::changeOrModify() { 450void OEffectiveEvent::changeOrModify() {
451 if ( data->count != 1 ) { 451 if ( data->count != 1 ) {
452 data->deref(); 452 data->deref();
453 Data* d2 = new Data; 453 Data* d2 = new Data;
454 d2->event = data->event; 454 d2->event = data->event;
455 d2->date = data->date; 455 d2->date = data->date;
456 d2->start = data->start; 456 d2->start = data->start;
457 d2->end = data->end; 457 d2->end = data->end;
458 d2->startDate = data->startDate; 458 d2->startDate = data->startDate;
459 d2->endDate = data->endDate; 459 d2->endDate = data->endDate;
460 d2->dates = data->dates; 460 d2->dates = data->dates;
461 data = d2; 461 data = d2;
462 } 462 }
463} 463}
464bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ 464bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
465 if ( data->date < e.date() ) 465 if ( data->date < e.date() )
466 return TRUE; 466 return TRUE;
467 if ( data->date == e.date() ) 467 if ( data->date == e.date() )
468 return ( startTime() < e.startTime() ); 468 return ( startTime() < e.startTime() );
469 else 469 else
470 return FALSE; 470 return FALSE;
471} 471}
472bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ 472bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
473 return (data->date <= e.date() ); 473 return (data->date <= e.date() );
474} 474}
475bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { 475bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
476 return ( date() == e.date() 476 return ( date() == e.date()
477 && startTime() == e.startTime() 477 && startTime() == e.startTime()
478 && endTime()== e.endTime() 478 && endTime()== e.endTime()
479 && event() == e.event() ); 479 && event() == e.event() );
480} 480}
481bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { 481bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
482 return !(*this == e ); 482 return !(*this == e );
483} 483}
484bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { 484bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
485 return !(*this <= e ); 485 return !(*this <= e );
486} 486}
487bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { 487bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
488 return !(*this < e); 488 return !(*this < e);
489} 489}
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp
index 049359e..ea66d39 100644
--- a/libopie2/opiepim/otodo.cpp
+++ b/libopie2/opiepim/otodo.cpp
@@ -1,424 +1,424 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h" 19#include "opimresolver.h"
20 20
21#include "otodo.h" 21#include "otodo.h"
22 22
23 23
24struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
25 OTodoData() : QShared() { 25 OTodoData() : QShared() {
26 }; 26 };
27 27
28 QDate date; 28 QDate date;
29 bool isCompleted:1; 29 bool isCompleted:1;
30 bool hasDate:1; 30 bool hasDate:1;
31 int priority; 31 int priority;
32 QString desc; 32 QString desc;
33 QString sum; 33 QString sum;
34 QMap<QString, QString> extra; 34 QMap<QString, QString> extra;
35 ushort prog; 35 ushort prog;
36 OPimState state; 36 OPimState state;
37 ORecur recur; 37 ORecur recur;
38 OPimMaintainer maintainer; 38 OPimMaintainer maintainer;
39 QDate start; 39 QDate start;
40 QDate completed; 40 QDate completed;
41 OPimNotifyManager notifiers; 41 OPimNotifyManager notifiers;
42}; 42};
43 43
44OTodo::OTodo(const OTodo &event ) 44OTodo::OTodo(const OTodo &event )
45 : OPimRecord( event ), data( event.data ) 45 : OPimRecord( event ), data( event.data )
46{ 46{
47 data->ref(); 47 data->ref();
48// qWarning("ref up"); 48// qWarning("ref up");
49} 49}
50OTodo::~OTodo() { 50OTodo::~OTodo() {
51 51
52// qWarning("~OTodo " ); 52// qWarning("~OTodo " );
53 if ( data->deref() ) { 53 if ( data->deref() ) {
54// qWarning("OTodo::dereffing"); 54// qWarning("OTodo::dereffing");
55 delete data; 55 delete data;
56 data = 0l; 56 data = 0l;
57 } 57 }
58} 58}
59OTodo::OTodo(bool completed, int priority, 59OTodo::OTodo(bool completed, int priority,
60 const QArray<int> &category, 60 const QArray<int> &category,
61 const QString& summary, 61 const QString& summary,
62 const QString &description, 62 const QString &description,
63 ushort progress, 63 ushort progress,
64 bool hasDate, QDate date, int uid ) 64 bool hasDate, QDate date, int uid )
65 : OPimRecord( uid ) 65 : OPimRecord( uid )
66{ 66{
67// qWarning("OTodoData " + summary); 67// qWarning("OTodoData " + summary);
68 setCategories( category ); 68 setCategories( category );
69 69
70 data = new OTodoData; 70 data = new OTodoData;
71 71
72 data->date = date; 72 data->date = date;
73 data->isCompleted = completed; 73 data->isCompleted = completed;
74 data->hasDate = hasDate; 74 data->hasDate = hasDate;
75 data->priority = priority; 75 data->priority = priority;
76 data->sum = summary; 76 data->sum = summary;
77 data->prog = progress; 77 data->prog = progress;
78 data->desc = Qtopia::simplifyMultiLineSpace(description ); 78 data->desc = Qtopia::simplifyMultiLineSpace(description );
79} 79}
80OTodo::OTodo(bool completed, int priority, 80OTodo::OTodo(bool completed, int priority,
81 const QStringList &category, 81 const QStringList &category,
82 const QString& summary, 82 const QString& summary,
83 const QString &description, 83 const QString &description,
84 ushort progress, 84 ushort progress,
85 bool hasDate, QDate date, int uid ) 85 bool hasDate, QDate date, int uid )
86 : OPimRecord( uid ) 86 : OPimRecord( uid )
87{ 87{
88// qWarning("OTodoData" + summary); 88// qWarning("OTodoData" + summary);
89 setCategories( idsFromString( category.join(";") ) ); 89 setCategories( idsFromString( category.join(";") ) );
90 90
91 data = new OTodoData; 91 data = new OTodoData;
92 92
93 data->date = date; 93 data->date = date;
94 data->isCompleted = completed; 94 data->isCompleted = completed;
95 data->hasDate = hasDate; 95 data->hasDate = hasDate;
96 data->priority = priority; 96 data->priority = priority;
97 data->sum = summary; 97 data->sum = summary;
98 data->prog = progress; 98 data->prog = progress;
99 data->desc = Qtopia::simplifyMultiLineSpace(description ); 99 data->desc = Qtopia::simplifyMultiLineSpace(description );
100} 100}
101bool OTodo::match( const QRegExp &regExp )const 101bool OTodo::match( const QRegExp &regExp )const
102{ 102{
103 if( QString::number( data->priority ).find( regExp ) != -1 ){ 103 if( QString::number( data->priority ).find( regExp ) != -1 ){
104 return true; 104 return true;
105 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 105 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
106 return true; 106 return true;
107 }else if(data->desc.find( regExp ) != -1 ){ 107 }else if(data->desc.find( regExp ) != -1 ){
108 return true; 108 return true;
109 }else if(data->sum.find( regExp ) != -1 ) { 109 }else if(data->sum.find( regExp ) != -1 ) {
110 return true; 110 return true;
111 } 111 }
112 return false; 112 return false;
113} 113}
114bool OTodo::isCompleted() const 114bool OTodo::isCompleted() const
115{ 115{
116 return data->isCompleted; 116 return data->isCompleted;
117} 117}
118bool OTodo::hasDueDate() const 118bool OTodo::hasDueDate() const
119{ 119{
120 return data->hasDate; 120 return data->hasDate;
121} 121}
122bool OTodo::hasStartDate()const { 122bool OTodo::hasStartDate()const {
123 return data->start.isValid(); 123 return data->start.isValid();
124} 124}
125bool OTodo::hasCompletedDate()const { 125bool OTodo::hasCompletedDate()const {
126 return data->completed.isValid(); 126 return data->completed.isValid();
127} 127}
128int OTodo::priority()const 128int OTodo::priority()const
129{ 129{
130 return data->priority; 130 return data->priority;
131} 131}
132QString OTodo::summary() const 132QString OTodo::summary() const
133{ 133{
134 return data->sum; 134 return data->sum;
135} 135}
136ushort OTodo::progress() const 136ushort OTodo::progress() const
137{ 137{
138 return data->prog; 138 return data->prog;
139} 139}
140QDate OTodo::dueDate()const 140QDate OTodo::dueDate()const
141{ 141{
142 return data->date; 142 return data->date;
143} 143}
144QDate OTodo::startDate()const { 144QDate OTodo::startDate()const {
145 return data->start; 145 return data->start;
146} 146}
147QDate OTodo::completedDate()const { 147QDate OTodo::completedDate()const {
148 return data->completed; 148 return data->completed;
149} 149}
150QString OTodo::description()const 150QString OTodo::description()const
151{ 151{
152 return data->desc; 152 return data->desc;
153} 153}
154OPimState OTodo::state()const { 154OPimState OTodo::state()const {
155 return data->state; 155 return data->state;
156} 156}
157ORecur OTodo::recurrence()const { 157ORecur OTodo::recurrence()const {
158 return data->recur; 158 return data->recur;
159} 159}
160OPimMaintainer OTodo::maintainer()const { 160OPimMaintainer OTodo::maintainer()const {
161 return data->maintainer; 161 return data->maintainer;
162} 162}
163void OTodo::setCompleted( bool completed ) 163void OTodo::setCompleted( bool completed )
164{ 164{
165 changeOrModify(); 165 changeOrModify();
166 data->isCompleted = completed; 166 data->isCompleted = completed;
167} 167}
168void OTodo::setHasDueDate( bool hasDate ) 168void OTodo::setHasDueDate( bool hasDate )
169{ 169{
170 changeOrModify(); 170 changeOrModify();
171 data->hasDate = hasDate; 171 data->hasDate = hasDate;
172} 172}
173void OTodo::setDescription(const QString &desc ) 173void OTodo::setDescription(const QString &desc )
174{ 174{
175// qWarning( "desc " + desc ); 175// qWarning( "desc " + desc );
176 changeOrModify(); 176 changeOrModify();
177 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 177 data->desc = Qtopia::simplifyMultiLineSpace(desc );
178} 178}
179void OTodo::setSummary( const QString& sum ) 179void OTodo::setSummary( const QString& sum )
180{ 180{
181 changeOrModify(); 181 changeOrModify();
182 data->sum = sum; 182 data->sum = sum;
183} 183}
184void OTodo::setPriority(int prio ) 184void OTodo::setPriority(int prio )
185{ 185{
186 changeOrModify(); 186 changeOrModify();
187 data->priority = prio; 187 data->priority = prio;
188} 188}
189void OTodo::setDueDate( const QDate& date ) 189void OTodo::setDueDate( const QDate& date )
190{ 190{
191 changeOrModify(); 191 changeOrModify();
192 data->date = date; 192 data->date = date;
193} 193}
194void OTodo::setStartDate( const QDate& date ) { 194void OTodo::setStartDate( const QDate& date ) {
195 changeOrModify(); 195 changeOrModify();
196 data->start = date; 196 data->start = date;
197} 197}
198void OTodo::setCompletedDate( const QDate& date ) { 198void OTodo::setCompletedDate( const QDate& date ) {
199 changeOrModify(); 199 changeOrModify();
200 data->completed = date; 200 data->completed = date;
201} 201}
202void OTodo::setState( const OPimState& state ) { 202void OTodo::setState( const OPimState& state ) {
203 changeOrModify(); 203 changeOrModify();
204 data->state = state; 204 data->state = state;
205} 205}
206void OTodo::setRecurrence( const ORecur& rec) { 206void OTodo::setRecurrence( const ORecur& rec) {
207 changeOrModify(); 207 changeOrModify();
208 data->recur = rec; 208 data->recur = rec;
209} 209}
210void OTodo::setMaintainer( const OPimMaintainer& pim ) { 210void OTodo::setMaintainer( const OPimMaintainer& pim ) {
211 changeOrModify(); 211 changeOrModify();
212 data->maintainer = pim; 212 data->maintainer = pim;
213} 213}
214bool OTodo::isOverdue( ) 214bool OTodo::isOverdue( )
215{ 215{
216 if( data->hasDate && !data->isCompleted) 216 if( data->hasDate && !data->isCompleted)
217 return QDate::currentDate() > data->date; 217 return QDate::currentDate() > data->date;
218 return false; 218 return false;
219} 219}
220void OTodo::setProgress(ushort progress ) 220void OTodo::setProgress(ushort progress )
221{ 221{
222 changeOrModify(); 222 changeOrModify();
223 data->prog = progress; 223 data->prog = progress;
224} 224}
225QString OTodo::toShortText() const { 225QString OTodo::toShortText() const {
226 return summary(); 226 return summary();
227} 227}
228/*! 228/*!
229 Returns a richt text string 229 Returns a richt text string
230*/ 230*/
231QString OTodo::toRichText() const 231QString OTodo::toRichText() const
232{ 232{
233 QString text; 233 QString text;
234 QStringList catlist; 234 QStringList catlist;
235 235
236 // Description of the todo 236 // Description of the todo
237 if ( !summary().isEmpty() ) { 237 if ( !summary().isEmpty() ) {
238 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 238 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
239 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 239 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
240 } 240 }
241 if( !description().isEmpty() ){ 241 if( !description().isEmpty() ){
242 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 242 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
244 } 244 }
245 text += "<br><br><br>"; 245 text += "<br><br><br>";
246 246
247 text += "<b>" + QObject::tr( "Priority:") +" </b>" 247 text += "<b>" + QObject::tr( "Priority:") +" </b>"
248 + QString::number( priority() ) + " <br>"; 248 + QString::number( priority() ) + " <br>";
249 text += "<b>" + QObject::tr( "Progress:") + " </b>" 249 text += "<b>" + QObject::tr( "Progress:") + " </b>"
250 + QString::number( progress() ) + " %<br>"; 250 + QString::number( progress() ) + " %<br>";
251 if (hasDueDate() ){ 251 if (hasDueDate() ){
252 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 252 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
253 text += dueDate().toString(); 253 text += dueDate().toString();
254 text += "<br>"; 254 text += "<br>";
255 } 255 }
256 256
257 text += "<b>" + QObject::tr( "Category:") + "</b> "; 257 text += "<b>" + QObject::tr( "Category:") + "</b> ";
258 text += categoryNames( "Todo List" ).join(", "); 258 text += categoryNames( "Todo List" ).join(", ");
259 text += "<br>"; 259 text += "<br>";
260 260
261 return text; 261 return text;
262} 262}
263OPimNotifyManager& OTodo::notifiers() { 263OPimNotifyManager& OTodo::notifiers() {
264 return data->notifiers; 264 return data->notifiers;
265} 265}
266 266
267bool OTodo::operator<( const OTodo &toDoEvent )const{ 267bool OTodo::operator<( const OTodo &toDoEvent )const{
268 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 268 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
269 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 269 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
270 if( hasDueDate() && toDoEvent.hasDueDate() ){ 270 if( hasDueDate() && toDoEvent.hasDueDate() ){
271 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 271 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
272 return priority() < toDoEvent.priority(); 272 return priority() < toDoEvent.priority();
273 }else{ 273 }else{
274 return dueDate() < toDoEvent.dueDate(); 274 return dueDate() < toDoEvent.dueDate();
275 } 275 }
276 } 276 }
277 return false; 277 return false;
278} 278}
279bool OTodo::operator<=(const OTodo &toDoEvent )const 279bool OTodo::operator<=(const OTodo &toDoEvent )const
280{ 280{
281 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 281 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
282 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 282 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
283 if( hasDueDate() && toDoEvent.hasDueDate() ){ 283 if( hasDueDate() && toDoEvent.hasDueDate() ){
284 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 284 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
285 return priority() <= toDoEvent.priority(); 285 return priority() <= toDoEvent.priority();
286 }else{ 286 }else{
287 return dueDate() <= toDoEvent.dueDate(); 287 return dueDate() <= toDoEvent.dueDate();
288 } 288 }
289 } 289 }
290 return true; 290 return true;
291} 291}
292bool OTodo::operator>(const OTodo &toDoEvent )const 292bool OTodo::operator>(const OTodo &toDoEvent )const
293{ 293{
294 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 294 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
295 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 295 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
296 if( hasDueDate() && toDoEvent.hasDueDate() ){ 296 if( hasDueDate() && toDoEvent.hasDueDate() ){
297 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 297 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
298 return priority() > toDoEvent.priority(); 298 return priority() > toDoEvent.priority();
299 }else{ 299 }else{
300 return dueDate() > toDoEvent.dueDate(); 300 return dueDate() > toDoEvent.dueDate();
301 } 301 }
302 } 302 }
303 return false; 303 return false;
304} 304}
305bool OTodo::operator>=(const OTodo &toDoEvent )const 305bool OTodo::operator>=(const OTodo &toDoEvent )const
306{ 306{
307 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 307 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
308 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 308 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
309 if( hasDueDate() && toDoEvent.hasDueDate() ){ 309 if( hasDueDate() && toDoEvent.hasDueDate() ){
310 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 310 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
311 return priority() > toDoEvent.priority(); 311 return priority() > toDoEvent.priority();
312 }else{ 312 }else{
313 return dueDate() > toDoEvent.dueDate(); 313 return dueDate() > toDoEvent.dueDate();
314 } 314 }
315 } 315 }
316 return true; 316 return true;
317} 317}
318bool OTodo::operator==(const OTodo &toDoEvent )const 318bool OTodo::operator==(const OTodo &toDoEvent )const
319{ 319{
320 if ( data->priority != toDoEvent.data->priority ) return false; 320 if ( data->priority != toDoEvent.data->priority ) return false;
321 if ( data->priority != toDoEvent.data->prog ) return false; 321 if ( data->priority != toDoEvent.data->prog ) return false;
322 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 322 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
323 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 323 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
324 if ( data->date != toDoEvent.data->date ) return false; 324 if ( data->date != toDoEvent.data->date ) return false;
325 if ( data->sum != toDoEvent.data->sum ) return false; 325 if ( data->sum != toDoEvent.data->sum ) return false;
326 if ( data->desc != toDoEvent.data->desc ) return false; 326 if ( data->desc != toDoEvent.data->desc ) return false;
327 if ( data->maintainer != toDoEvent.data->maintainer ) 327 if ( data->maintainer != toDoEvent.data->maintainer )
328 return false; 328 return false;
329 329
330 return OPimRecord::operator==( toDoEvent ); 330 return OPimRecord::operator==( toDoEvent );
331} 331}
332void OTodo::deref() { 332void OTodo::deref() {
333 333
334// qWarning("deref in ToDoEvent"); 334// qWarning("deref in ToDoEvent");
335 if ( data->deref() ) { 335 if ( data->deref() ) {
336// qWarning("deleting"); 336// qWarning("deleting");
337 delete data; 337 delete data;
338 data= 0; 338 data= 0;
339 } 339 }
340} 340}
341OTodo &OTodo::operator=(const OTodo &item ) 341OTodo &OTodo::operator=(const OTodo &item )
342{ 342{
343 if ( *this == item ) return *this; 343 if ( this == &item ) return *this;
344 344
345 OPimRecord::operator=( item ); 345 OPimRecord::operator=( item );
346 //qWarning("operator= ref "); 346 //qWarning("operator= ref ");
347 item.data->ref(); 347 item.data->ref();
348 deref(); 348 deref();
349 data = item.data; 349 data = item.data;
350 350
351 return *this; 351 return *this;
352} 352}
353 353
354QMap<int, QString> OTodo::toMap() const { 354QMap<int, QString> OTodo::toMap() const {
355 QMap<int, QString> map; 355 QMap<int, QString> map;
356 356
357 map.insert( Uid, QString::number( uid() ) ); 357 map.insert( Uid, QString::number( uid() ) );
358 map.insert( Category, idsToString( categories() ) ); 358 map.insert( Category, idsToString( categories() ) );
359 map.insert( HasDate, QString::number( data->hasDate ) ); 359 map.insert( HasDate, QString::number( data->hasDate ) );
360 map.insert( Completed, QString::number( data->isCompleted ) ); 360 map.insert( Completed, QString::number( data->isCompleted ) );
361 map.insert( Description, data->desc ); 361 map.insert( Description, data->desc );
362 map.insert( Summary, data->sum ); 362 map.insert( Summary, data->sum );
363 map.insert( Priority, QString::number( data->priority ) ); 363 map.insert( Priority, QString::number( data->priority ) );
364 map.insert( DateDay, QString::number( data->date.day() ) ); 364 map.insert( DateDay, QString::number( data->date.day() ) );
365 map.insert( DateMonth, QString::number( data->date.month() ) ); 365 map.insert( DateMonth, QString::number( data->date.month() ) );
366 map.insert( DateYear, QString::number( data->date.year() ) ); 366 map.insert( DateYear, QString::number( data->date.year() ) );
367 map.insert( Progress, QString::number( data->prog ) ); 367 map.insert( Progress, QString::number( data->prog ) );
368// map.insert( CrossReference, crossToString() ); 368// map.insert( CrossReference, crossToString() );
369 /* FIXME!!! map.insert( State, ); 369 /* FIXME!!! map.insert( State, );
370 map.insert( Recurrence, ); 370 map.insert( Recurrence, );
371 map.insert( Reminders, ); 371 map.insert( Reminders, );
372 map. 372 map.
373 */ 373 */
374 return map; 374 return map;
375} 375}
376 376
377QMap<QString, QString> OTodo::toExtraMap()const { 377QMap<QString, QString> OTodo::toExtraMap()const {
378 return data->extra; 378 return data->extra;
379} 379}
380/** 380/**
381 * change or modify looks at the ref count and either 381 * change or modify looks at the ref count and either
382 * creates a new QShared Object or it can modify it 382 * creates a new QShared Object or it can modify it
383 * right in place 383 * right in place
384 */ 384 */
385void OTodo::changeOrModify() { 385void OTodo::changeOrModify() {
386 if ( data->count != 1 ) { 386 if ( data->count != 1 ) {
387 qWarning("changeOrModify"); 387 qWarning("changeOrModify");
388 data->deref(); 388 data->deref();
389 OTodoData* d2 = new OTodoData(); 389 OTodoData* d2 = new OTodoData();
390 copy(data, d2 ); 390 copy(data, d2 );
391 data = d2; 391 data = d2;
392 } 392 }
393} 393}
394// WATCHOUT 394// WATCHOUT
395/* 395/*
396 * if you add something to the Data struct 396 * if you add something to the Data struct
397 * be sure to copy it here 397 * be sure to copy it here
398 */ 398 */
399void OTodo::copy( OTodoData* src, OTodoData* dest ) { 399void OTodo::copy( OTodoData* src, OTodoData* dest ) {
400 dest->date = src->date; 400 dest->date = src->date;
401 dest->isCompleted = src->isCompleted; 401 dest->isCompleted = src->isCompleted;
402 dest->hasDate = src->hasDate; 402 dest->hasDate = src->hasDate;
403 dest->priority = src->priority; 403 dest->priority = src->priority;
404 dest->desc = src->desc; 404 dest->desc = src->desc;
405 dest->sum = src->sum; 405 dest->sum = src->sum;
406 dest->extra = src->extra; 406 dest->extra = src->extra;
407 dest->prog = src->prog; 407 dest->prog = src->prog;
408 dest->state = src->state; 408 dest->state = src->state;
409 dest->recur = src->recur; 409 dest->recur = src->recur;
410 dest->maintainer = src->maintainer; 410 dest->maintainer = src->maintainer;
411 dest->start = src->start; 411 dest->start = src->start;
412 dest->completed = src->completed; 412 dest->completed = src->completed;
413 dest->notifiers = src->notifiers; 413 dest->notifiers = src->notifiers;
414} 414}
415QString OTodo::type() const { 415QString OTodo::type() const {
416 return QString::fromLatin1("OTodo"); 416 return QString::fromLatin1("OTodo");
417} 417}
418QString OTodo::recordField(int /*id*/ )const { 418QString OTodo::recordField(int /*id*/ )const {
419 return QString::null; 419 return QString::null;
420} 420}
421 421
422int OTodo::rtti(){ 422int OTodo::rtti(){
423 return OPimResolver::TodoList; 423 return OPimResolver::TodoList;
424} 424}