summaryrefslogtreecommitdiff
path: root/libopie
authorzecke <zecke>2003-02-22 16:12:49 (UTC)
committer zecke <zecke>2003-02-22 16:12:49 (UTC)
commit66b00525256255290dfcd9d48ebe1539f15b8dce (patch) (unidiff)
treee0857ba9251d6ebcd7df5d23b9269c69d6edd944 /libopie
parent397a7b1635488deda02b36df70692e27f59bb3e0 (diff)
downloadopie-66b00525256255290dfcd9d48ebe1539f15b8dce.zip
opie-66b00525256255290dfcd9d48ebe1539f15b8dce.tar.gz
opie-66b00525256255290dfcd9d48ebe1539f15b8dce.tar.bz2
Remove some testing code
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/odatebookaccessbackend_xml.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp
index 5239d84..bc51996 100644
--- a/libopie/pim/odatebookaccessbackend_xml.cpp
+++ b/libopie/pim/odatebookaccessbackend_xml.cpp
@@ -26,298 +26,296 @@ namespace {
26 time_t start, end, created, rp_end; 26 time_t start, end, created, rp_end;
27 ORecur* rec; 27 ORecur* rec;
28 ORecur* recur() { 28 ORecur* recur() {
29 if (!rec) 29 if (!rec)
30 rec = new ORecur; 30 rec = new ORecur;
31 31
32 return rec; 32 return rec;
33 } 33 }
34 int alarmTime; 34 int alarmTime;
35 int snd; 35 int snd;
36 enum Attribute{ 36 enum Attribute{
37 FDescription = 0, 37 FDescription = 0,
38 FLocation, 38 FLocation,
39 FCategories, 39 FCategories,
40 FUid, 40 FUid,
41 FType, 41 FType,
42 FAlarm, 42 FAlarm,
43 FSound, 43 FSound,
44 FRType, 44 FRType,
45 FRWeekdays, 45 FRWeekdays,
46 FRPosition, 46 FRPosition,
47 FRFreq, 47 FRFreq,
48 FRHasEndDate, 48 FRHasEndDate,
49 FREndDate, 49 FREndDate,
50 FRStart, 50 FRStart,
51 FREnd, 51 FREnd,
52 FNote, 52 FNote,
53 FCreated, 53 FCreated,
54 FTimeZone, 54 FTimeZone,
55 FRecParent, 55 FRecParent,
56 FRecChildren, 56 FRecChildren,
57 FExceptions 57 FExceptions
58 }; 58 };
59 inline void save( const OEvent& ev, QString& buf ) { 59 inline void save( const OEvent& ev, QString& buf ) {
60 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; 60 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
61 if (!ev.location().isEmpty() ) 61 if (!ev.location().isEmpty() )
62 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; 62 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
63 63
64 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; 64 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\"";
65 buf += " uid=\"" + QString::number( ev.uid() ) + "\""; 65 buf += " uid=\"" + QString::number( ev.uid() ) + "\"";
66 66
67 if (ev.isAllDay() ) 67 if (ev.isAllDay() )
68 buf += " type=\"AllDay\""; 68 buf += " type=\"AllDay\"";
69 69
70 if (ev.hasNotifiers() ) { 70 if (ev.hasNotifiers() ) {
71 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first 71 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first
72 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; 72 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60;
73 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; 73 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\"";
74 if ( alarm.sound() == OPimAlarm::Loud ) 74 if ( alarm.sound() == OPimAlarm::Loud )
75 buf += "loud"; 75 buf += "loud";
76 else 76 else
77 buf += "silent"; 77 buf += "silent";
78 buf += "\""; 78 buf += "\"";
79 } 79 }
80 if ( ev.hasRecurrence() ) { 80 if ( ev.hasRecurrence() ) {
81 buf += ev.recurrence().toString(); 81 buf += ev.recurrence().toString();
82 } 82 }
83 83
84 /* 84 /*
85 * fscking timezones :) well, we'll first convert 85 * fscking timezones :) well, we'll first convert
86 * the QDateTime to a QDateTime in UTC time 86 * the QDateTime to a QDateTime in UTC time
87 * and then we'll create a nice time_t 87 * and then we'll create a nice time_t
88 */ 88 */
89 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); 89 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() );
90 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; 90 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\"";
91 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; 91 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\"";
92 if (!ev.note().isEmpty() ) { 92 if (!ev.note().isEmpty() ) {
93 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; 93 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\"";
94 } 94 }
95 95
96 buf += " timezone=\""; 96 buf += " timezone=\"";
97 if ( ev.timeZone().isEmpty() ) 97 if ( ev.timeZone().isEmpty() )
98 buf += "None"; 98 buf += "None";
99 else 99 else
100 buf += ev.timeZone(); 100 buf += ev.timeZone();
101 101
102 if (ev.parent() != 0 ) { 102 if (ev.parent() != 0 ) {
103 buf += " recparent=\""+QString::number(ev.parent() )+"\""; 103 buf += " recparent=\""+QString::number(ev.parent() )+"\"";
104 } 104 }
105 105
106 if (ev.children().count() != 0 ) { 106 if (ev.children().count() != 0 ) {
107 QArray<int> children = ev.children(); 107 QArray<int> children = ev.children();
108 buf += " recchildren=\""; 108 buf += " recchildren=\"";
109 for ( uint i = 0; i < children.count(); i++ ) { 109 for ( uint i = 0; i < children.count(); i++ ) {
110 if ( i != 0 ) buf += " "; 110 if ( i != 0 ) buf += " ";
111 buf += QString::number( children[i] ); 111 buf += QString::number( children[i] );
112 } 112 }
113 buf+= "\""; 113 buf+= "\"";
114 } 114 }
115 115
116 // skip custom writing 116 // skip custom writing
117 } 117 }
118 118
119 inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { 119 inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) {
120 QMap<int, OEvent>::ConstIterator it; 120 QMap<int, OEvent>::ConstIterator it;
121 QString buf; 121 QString buf;
122 QCString str; 122 QCString str;
123 int total_written; 123 int total_written;
124 for ( it = list.begin(); it != list.end(); ++it ) { 124 for ( it = list.begin(); it != list.end(); ++it ) {
125 buf = "<event"; 125 buf = "<event";
126 save( it.data(), buf ); 126 save( it.data(), buf );
127 buf += " />\n"; 127 buf += " />\n";
128 str = buf.utf8(); 128 str = buf.utf8();
129 129
130 total_written = file.writeBlock(str.data(), str.length() ); 130 total_written = file.writeBlock(str.data(), str.length() );
131 if ( total_written != int(str.length() ) ) 131 if ( total_written != int(str.length() ) )
132 return false; 132 return false;
133 } 133 }
134 return true; 134 return true;
135 } 135 }
136} 136}
137 137
138ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 138ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& ,
139 const QString& fileName ) 139 const QString& fileName )
140 : ODateBookAccessBackend() { 140 : ODateBookAccessBackend() {
141 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; 141 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName;
142 m_changed = false; 142 m_changed = false;
143} 143}
144ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { 144ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
145} 145}
146bool ODateBookAccessBackend_XML::load() { 146bool ODateBookAccessBackend_XML::load() {
147 return loadFile(); 147 return loadFile();
148} 148}
149bool ODateBookAccessBackend_XML::reload() { 149bool ODateBookAccessBackend_XML::reload() {
150 clear(); 150 clear();
151 return load(); 151 return load();
152} 152}
153bool ODateBookAccessBackend_XML::save() { 153bool ODateBookAccessBackend_XML::save() {
154 qWarning("going to save now"); 154 if (!m_changed) return true;
155// if (!m_changed) return true;
156 155
157 int total_written; 156 int total_written;
158 QString strFileNew = m_name + ".new"; 157 QString strFileNew = m_name + ".new";
159 158
160 QFile f( strFileNew ); 159 QFile f( strFileNew );
161 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; 160 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;
162 161
163 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); 162 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
164 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; 163 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
165 buf += "<events>\n"; 164 buf += "<events>\n";
166 QCString str = buf.utf8(); 165 QCString str = buf.utf8();
167 total_written = f.writeBlock( str.data(), str.length() ); 166 total_written = f.writeBlock( str.data(), str.length() );
168 if ( total_written != int(str.length() ) ) { 167 if ( total_written != int(str.length() ) ) {
169 f.close(); 168 f.close();
170 QFile::remove( strFileNew ); 169 QFile::remove( strFileNew );
171 return false; 170 return false;
172 } 171 }
173 172
174 if (!forAll( m_raw, f ) ) { 173 if (!forAll( m_raw, f ) ) {
175 f.close(); 174 f.close();
176 QFile::remove( strFileNew ); 175 QFile::remove( strFileNew );
177 return false; 176 return false;
178 } 177 }
179 if (!forAll( m_rep, f ) ) { 178 if (!forAll( m_rep, f ) ) {
180 f.close(); 179 f.close();
181 QFile::remove( strFileNew ); 180 QFile::remove( strFileNew );
182 return false; 181 return false;
183 } 182 }
184 183
185 buf = "</events>\n</DATEBOOK>\n"; 184 buf = "</events>\n</DATEBOOK>\n";
186 str = buf.utf8(); 185 str = buf.utf8();
187 total_written = f.writeBlock( str.data(), str.length() ); 186 total_written = f.writeBlock( str.data(), str.length() );
188 if ( total_written != int(str.length() ) ) { 187 if ( total_written != int(str.length() ) ) {
189 f.close(); 188 f.close();
190 QFile::remove( strFileNew ); 189 QFile::remove( strFileNew );
191 return false; 190 return false;
192 } 191 }
193 f.close(); 192 f.close();
194 193
195 exit(0);
196 if ( ::rename( strFileNew, m_name ) < 0 ) { 194 if ( ::rename( strFileNew, m_name ) < 0 ) {
197 QFile::remove( strFileNew ); 195 QFile::remove( strFileNew );
198 return false; 196 return false;
199 } 197 }
200 198
201 m_changed = false; 199 m_changed = false;
202 return true; 200 return true;
203} 201}
204QArray<int> ODateBookAccessBackend_XML::allRecords()const { 202QArray<int> ODateBookAccessBackend_XML::allRecords()const {
205 QArray<int> ints( m_raw.count()+ m_rep.count() ); 203 QArray<int> ints( m_raw.count()+ m_rep.count() );
206 uint i = 0; 204 uint i = 0;
207 QMap<int, OEvent>::ConstIterator it; 205 QMap<int, OEvent>::ConstIterator it;
208 206
209 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 207 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
210 ints[i] = it.key(); 208 ints[i] = it.key();
211 i++; 209 i++;
212 } 210 }
213 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 211 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
214 ints[i] = it.key(); 212 ints[i] = it.key();
215 i++; 213 i++;
216 } 214 }
217 215
218 return ints; 216 return ints;
219} 217}
220QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int ) { 218QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int ) {
221 return QArray<int>(); 219 return QArray<int>();
222} 220}
223void ODateBookAccessBackend_XML::clear() { 221void ODateBookAccessBackend_XML::clear() {
224 m_raw.clear(); 222 m_raw.clear();
225 m_rep.clear(); 223 m_rep.clear();
226} 224}
227OEvent ODateBookAccessBackend_XML::find( int uid ) const{ 225OEvent ODateBookAccessBackend_XML::find( int uid ) const{
228 if ( m_raw.contains( uid ) ) 226 if ( m_raw.contains( uid ) )
229 return m_raw[uid]; 227 return m_raw[uid];
230 else 228 else
231 return m_rep[uid]; 229 return m_rep[uid];
232} 230}
233bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { 231bool ODateBookAccessBackend_XML::add( const OEvent& ev ) {
234 m_changed = true; 232 m_changed = true;
235 if (ev.hasRecurrence() ) 233 if (ev.hasRecurrence() )
236 m_rep.insert( ev.uid(), ev ); 234 m_rep.insert( ev.uid(), ev );
237 else 235 else
238 m_raw.insert( ev.uid(), ev ); 236 m_raw.insert( ev.uid(), ev );
239 237
240 return true; 238 return true;
241} 239}
242bool ODateBookAccessBackend_XML::remove( int uid ) { 240bool ODateBookAccessBackend_XML::remove( int uid ) {
243 m_changed = true; 241 m_changed = true;
244 m_rep.remove( uid ); 242 m_rep.remove( uid );
245 m_rep.remove( uid ); 243 m_rep.remove( uid );
246 244
247 return true; 245 return true;
248} 246}
249bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { 247bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) {
250 replace( ev.uid() ); 248 replace( ev.uid() );
251 return add( ev ); 249 return add( ev );
252} 250}
253QArray<int> ODateBookAccessBackend_XML::rawEvents()const { 251QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
254 return allRecords(); 252 return allRecords();
255} 253}
256QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { 254QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
257 QArray<int> ints( m_rep.count() ); 255 QArray<int> ints( m_rep.count() );
258 uint i = 0; 256 uint i = 0;
259 QMap<int, OEvent>::ConstIterator it; 257 QMap<int, OEvent>::ConstIterator it;
260 258
261 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 259 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
262 ints[i] = it.key(); 260 ints[i] = it.key();
263 i++; 261 i++;
264 } 262 }
265 263
266 return ints; 264 return ints;
267} 265}
268QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { 266QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
269 QArray<int> ints( m_raw.count() ); 267 QArray<int> ints( m_raw.count() );
270 uint i = 0; 268 uint i = 0;
271 QMap<int, OEvent>::ConstIterator it; 269 QMap<int, OEvent>::ConstIterator it;
272 270
273 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 271 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
274 ints[i] = it.key(); 272 ints[i] = it.key();
275 i++; 273 i++;
276 } 274 }
277 275
278 return ints; 276 return ints;
279} 277}
280OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { 278OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
281 OEvent::ValueList list; 279 OEvent::ValueList list;
282 QMap<int, OEvent>::ConstIterator it; 280 QMap<int, OEvent>::ConstIterator it;
283 for (it = m_raw.begin(); it != m_raw.end(); ++it ) 281 for (it = m_raw.begin(); it != m_raw.end(); ++it )
284 list.append( it.data() ); 282 list.append( it.data() );
285 283
286 return list; 284 return list;
287} 285}
288OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { 286OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
289 OEvent::ValueList list; 287 OEvent::ValueList list;
290 QMap<int, OEvent>::ConstIterator it; 288 QMap<int, OEvent>::ConstIterator it;
291 for (it = m_rep.begin(); it != m_rep.end(); ++it ) 289 for (it = m_rep.begin(); it != m_rep.end(); ++it )
292 list.append( it.data() ); 290 list.append( it.data() );
293 291
294 return list; 292 return list;
295} 293}
296bool ODateBookAccessBackend_XML::loadFile() { 294bool ODateBookAccessBackend_XML::loadFile() {
297 m_changed = false; 295 m_changed = false;
298 296
299 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); 297 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY );
300 if ( fd < 0 ) return false; 298 if ( fd < 0 ) return false;
301 299
302 struct stat attribute; 300 struct stat attribute;
303 if ( ::fstat(fd, &attribute ) == -1 ) { 301 if ( ::fstat(fd, &attribute ) == -1 ) {
304 ::close( fd ); 302 ::close( fd );
305 return false; 303 return false;
306 } 304 }
307 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 305 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 );
308 if ( map_addr == ( (caddr_t)-1) ) { 306 if ( map_addr == ( (caddr_t)-1) ) {
309 ::close( fd ); 307 ::close( fd );
310 return false; 308 return false;
311 } 309 }
312 310
313 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); 311 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL );
314 ::close( fd ); 312 ::close( fd );
315 313
316 QAsciiDict<int> dict(FExceptions+1); 314 QAsciiDict<int> dict(FExceptions+1);
317 dict.setAutoDelete( true ); 315 dict.setAutoDelete( true );
318 dict.insert( "description", new int(FDescription) ); 316 dict.insert( "description", new int(FDescription) );
319 dict.insert( "location", new int(FLocation) ); 317 dict.insert( "location", new int(FLocation) );
320 dict.insert( "categories", new int(FCategories) ); 318 dict.insert( "categories", new int(FCategories) );
321 dict.insert( "uid", new int(FUid) ); 319 dict.insert( "uid", new int(FUid) );
322 dict.insert( "type", new int(FType) ); 320 dict.insert( "type", new int(FType) );
323 dict.insert( "alarm", new int(FAlarm) ); 321 dict.insert( "alarm", new int(FAlarm) );