summaryrefslogtreecommitdiff
path: root/libopie/pim
authorzecke <zecke>2002-10-13 19:05:24 (UTC)
committer zecke <zecke>2002-10-13 19:05:24 (UTC)
commit34c1199becdb2f9b0447553e66c85d8f6770558f (patch) (unidiff)
tree36c3bf20b6f07e643f4caef793356261f9982bd6 /libopie/pim
parenta469689def798954c0f571a00cc52e87d6b008ce (diff)
downloadopie-34c1199becdb2f9b0447553e66c85d8f6770558f.zip
opie-34c1199becdb2f9b0447553e66c85d8f6770558f.tar.gz
opie-34c1199becdb2f9b0447553e66c85d8f6770558f.tar.bz2
Add a vCal Resource
Play a bit with cahce sizes The idea is to have the current page and the prior page cached... still looking how to do that
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/otodoaccesssql.cpp9
-rw-r--r--libopie/pim/otodoaccessvcal.cpp192
-rw-r--r--libopie/pim/otodoaccessvcal.h35
3 files changed, 232 insertions, 4 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
index ea8b3c9..9ef6b7c 100644
--- a/libopie/pim/otodoaccesssql.cpp
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -257,84 +257,85 @@ OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
257bool OTodoAccessBackendSQL::load(){ 257bool OTodoAccessBackendSQL::load(){
258 if (!m_driver->open() ) 258 if (!m_driver->open() )
259 return false; 259 return false;
260 260
261 CreateQuery creat; 261 CreateQuery creat;
262 OSQLResult res = m_driver->query(&creat ); 262 OSQLResult res = m_driver->query(&creat );
263 263
264 m_dirty = true; 264 m_dirty = true;
265 return true; 265 return true;
266} 266}
267bool OTodoAccessBackendSQL::reload(){ 267bool OTodoAccessBackendSQL::reload(){
268 return load(); 268 return load();
269} 269}
270 270
271bool OTodoAccessBackendSQL::save(){ 271bool OTodoAccessBackendSQL::save(){
272 return m_driver->close(); 272 return m_driver->close();
273} 273}
274QArray<int> OTodoAccessBackendSQL::allRecords()const { 274QArray<int> OTodoAccessBackendSQL::allRecords()const {
275 if (m_dirty ) 275 if (m_dirty )
276 update(); 276 update();
277 277
278 return m_uids; 278 return m_uids;
279} 279}
280QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ 280QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
281 QArray<int> ints(0); 281 QArray<int> ints(0);
282 return ints; 282 return ints;
283} 283}
284OTodo OTodoAccessBackendSQL::find(int uid ) const{ 284OTodo OTodoAccessBackendSQL::find(int uid ) const{
285 FindQuery query( uid ); 285 FindQuery query( uid );
286 return todo( m_driver->query(&query) ); 286 return todo( m_driver->query(&query) );
287 287
288} 288}
289#define CACHE 32
289OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 290OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
290 uint cur, Frontend::CacheDirection dir ) const{ 291 uint cur, Frontend::CacheDirection dir ) const{
291 qWarning("searching for %d", uid ); 292 qWarning("searching for %d", uid );
292 QArray<int> search( 8 ); 293 QArray<int> search( CACHE );
293 uint size =0; 294 uint size =0;
294 OTodo to; 295 OTodo to;
295 296
296 // we try to cache 8 items 297 // we try to cache CACHE items
297 switch( dir ) { 298 switch( dir ) {
298 /* forward */ 299 /* forward */
299 case 0: 300 case 0:
300 for (uint i = cur; i < ints.count() && size < 8; i++ ) { 301 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
301 qWarning("size %d %d", size, ints[i] ); 302 qWarning("size %d %d", size, ints[i] );
302 search[size] = ints[i]; 303 search[size] = ints[i];
303 size++; 304 size++;
304 } 305 }
305 break; 306 break;
306 /* reverse */ 307 /* reverse */
307 case 1: 308 case 1:
308 for (uint i = cur; i != 0 && size < 8; i-- ) { 309 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
309 search[size] = ints[i]; 310 search[size] = ints[i];
310 size++; 311 size++;
311 } 312 }
312 break; 313 break;
313 } 314 }
314 search.resize( size ); 315 search.resize( size );
315 FindQuery query( search ); 316 FindQuery query( search );
316 OSQLResult res = m_driver->query( &query ); 317 OSQLResult res = m_driver->query( &query );
317 if ( res.state() != OSQLResult::Success ) 318 if ( res.state() != OSQLResult::Success )
318 return to; 319 return to;
319 320
320 return todo( res ); 321 return todo( res );
321} 322}
322void OTodoAccessBackendSQL::clear() { 323void OTodoAccessBackendSQL::clear() {
323 ClearQuery cle; 324 ClearQuery cle;
324 OSQLResult res = m_driver->query( &cle ); 325 OSQLResult res = m_driver->query( &cle );
325 CreateQuery qu; 326 CreateQuery qu;
326 res = m_driver->query(&qu); 327 res = m_driver->query(&qu);
327} 328}
328bool OTodoAccessBackendSQL::add( const OTodo& t) { 329bool OTodoAccessBackendSQL::add( const OTodo& t) {
329 InsertQuery ins( t ); 330 InsertQuery ins( t );
330 OSQLResult res = m_driver->query( &ins ); 331 OSQLResult res = m_driver->query( &ins );
331 332
332 if ( res.state() == OSQLResult::Failure ) 333 if ( res.state() == OSQLResult::Failure )
333 return false; 334 return false;
334 int c = m_uids.count(); 335 int c = m_uids.count();
335 m_uids.resize( c+1 ); 336 m_uids.resize( c+1 );
336 m_uids[c] = t.uid(); 337 m_uids[c] = t.uid();
337 338
338 return true; 339 return true;
339} 340}
340bool OTodoAccessBackendSQL::remove( int uid ) { 341bool OTodoAccessBackendSQL::remove( int uid ) {
diff --git a/libopie/pim/otodoaccessvcal.cpp b/libopie/pim/otodoaccessvcal.cpp
new file mode 100644
index 0000000..ac70ea0
--- a/dev/null
+++ b/libopie/pim/otodoaccessvcal.cpp
@@ -0,0 +1,192 @@
1#include <qfile.h>
2
3#include <qtopia/private/vobject_p.h>
4#include <qtopia/timeconversion.h>
5#include <qtopia/private/qfiledirect_p.h>
6
7#include "otodoaccessvcal.h"
8
9namespace {
10 static OTodo eventByVObj( VObject *obj ){
11 OTodo event;
12 VObject *ob;
13 QCString name;
14 // no uid, attendees, ... and no fun
15 // description
16 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
17 name = vObjectStringZValue( ob );
18 event.setDescription( name );
19 }
20 // summary
21 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
22 name = vObjectStringZValue( ob );
23 event.setSummary( name );
24 }
25 // completed
26 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
27 name = vObjectStringZValue( ob );
28 if( name == "COMPLETED" ){
29 event.setCompleted( true );
30 }else{
31 event.setCompleted( false );
32 }
33 }else
34 event.setCompleted( false );
35 // priority
36 if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
37 name = vObjectStringZValue( ob );
38 bool ok;
39 event.setPriority(name.toInt(&ok) );
40 }
41 //due date
42 if((ob = isAPropertyOf(obj, VCDueProp)) ){
43 event.setHasDueDate( true );
44 name = vObjectStringZValue( ob );
45 event.setDueDate( TimeConversion::fromISO8601( name).date() );
46 }
47 // categories
48 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
49 name = vObjectStringZValue( ob );
50 qWarning("Categories:%s", name.data() );
51 }
52
53 event.setUid( 1 );
54 return event;
55 };
56 static VObject *vobjByEvent( const OTodo &event ) {
57 VObject *task = newVObject( VCTodoProp );
58 if( task == 0 )
59 return 0l;
60
61 if( event.hasDueDate() )
62 addPropValue( task, VCDueProp,
63 TimeConversion::toISO8601( event.dueDate() ) );
64
65 if( event.isCompleted() )
66 addPropValue( task, VCStatusProp, "COMPLETED");
67
68 QString string = QString::number(event.priority() );
69 addPropValue( task, VCPriorityProp, string.local8Bit() );
70
71 addPropValue( task, VCCategoriesProp,
72 event.idsToString( event.categories() ).local8Bit() );
73
74 addPropValue( task, VCDescriptionProp,
75 event.description().local8Bit() );
76
77 addPropValue( task, VCSummaryProp,
78 event.summary().local8Bit() );
79 return task;
80};
81}
82
83OTodoAccessVCal::OTodoAccessVCal( const QString& path )
84 : m_dirty(false), m_file( path )
85{
86}
87OTodoAccessVCal::~OTodoAccessVCal() {
88}
89bool OTodoAccessVCal::load() {
90 m_map.clear();
91 m_dirty = false;
92
93 VObject* vcal = 0l;
94 vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
95 if (!vcal )
96 return false;
97
98 // Iterate over the list
99 VObjectIterator it;
100 VObject* vobj;
101
102 initPropIterator(&it, vcal);
103
104 while( moreIteration( &it ) ) {
105 vobj = ::nextVObject( &it );
106 QCString name = ::vObjectName( vobj );
107 if( name == VCTodoProp ){
108 OTodo to = eventByVObj( vobj );
109 m_map.insert( to.uid(), to );
110 }
111 }
112
113 // Should I do a delete vcal?
114
115 return true;
116}
117bool OTodoAccessVCal::reload() {
118 return load();
119}
120bool OTodoAccessVCal::save() {
121 if (!m_dirty )
122 return true;
123
124 QFileDirect file( m_file );
125 if (!file.open(IO_WriteOnly ) )
126 return false;
127
128 VObject *obj;
129 obj = newVObject( VCCalProp );
130 addPropValue( obj, VCVersionProp, "1.0" );
131 VObject *vo;
132 for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
133 vo = vobjByEvent( it.data() );
134 addVObjectProp(obj, vo );
135 }
136 writeVObject( file.directHandle(), obj );
137 cleanVObject( obj );
138 cleanStrTbl();
139
140 m_dirty = false;
141 return true;
142}
143void OTodoAccessVCal::clear() {
144 m_map.clear();
145 m_dirty = true;
146}
147bool OTodoAccessVCal::add( const OTodo& to ) {
148 m_map.insert( to.uid(), to );
149 m_dirty = true;
150 return true;
151}
152bool OTodoAccessVCal::remove( int uid ) {
153 m_map.remove( uid );
154 m_dirty = true;
155 return true;
156}
157bool OTodoAccessVCal::replace( const OTodo& to ) {
158 m_map.replace( to.uid(), to );
159 m_dirty = true;
160 return true;
161}
162OTodo OTodoAccessVCal::find(int uid )const {
163 return m_map[uid];
164}
165QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) {
166 QArray<int> ar(0);
167 return ar;
168}
169QArray<int> OTodoAccessVCal::allRecords()const {
170 QArray<int> ar( m_map.count() );
171 QMap<int, OTodo>::ConstIterator it;
172 int i = 0;
173 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
174 ar[i] = it.key();
175 i++;
176 }
177 return ar;
178}
179QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int ) {
180 QArray<int> ar(0);
181 return ar;
182}
183QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& ,
184 const QDate& ,
185 bool ) {
186 QArray<int> ar(0);
187 return ar;
188}
189QArray<int> OTodoAccessVCal::overDue() {
190 QArray<int> ar(0);
191 return ar;
192}
diff --git a/libopie/pim/otodoaccessvcal.h b/libopie/pim/otodoaccessvcal.h
new file mode 100644
index 0000000..4499a7e
--- a/dev/null
+++ b/libopie/pim/otodoaccessvcal.h
@@ -0,0 +1,35 @@
1#ifndef OPIE_OTODO_ACCESS_VCAL_H
2#define OPIE_OTODO_ACCESS_VCAL_H
3
4#include "otodoaccessbackend.h"
5
6class OTodoAccessVCal : public OTodoAccessBackend {
7public:
8 OTodoAccessVCal(const QString& );
9 ~OTodoAccessVCal();
10
11 bool load();
12 bool reload();
13 bool save();
14
15 QArray<int> allRecords()const;
16 QArray<int> queryByExample( const OTodo& t, int sort );
17 QArray<int> effectiveToDos( const QDate& start,
18 const QDate& end,
19 bool includeNoDates );
20 QArray<int> overDue();
21 QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
22 int cat );
23 OTodo find(int uid)const;
24 void clear();
25 bool add( const OTodo& );
26 bool remove( int uid );
27 bool replace( const OTodo& );
28
29private:
30 bool m_dirty : 1;
31 QString m_file;
32 QMap<int, OTodo> m_map;
33};
34
35#endif