summaryrefslogtreecommitdiff
Unidiff
Diffstat (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
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp9
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp192
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h35
6 files changed, 464 insertions, 8 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
@@ -286,18 +286,19 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{
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++;
@@ -305,7 +306,7 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
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 }
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
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index ea8b3c9..9ef6b7c 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -286,18 +286,19 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{
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++;
@@ -305,7 +306,7 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
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 }
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp
new file mode 100644
index 0000000..ac70ea0
--- a/dev/null
+++ b/libopie2/opiepim/backend/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/libopie2/opiepim/backend/otodoaccessvcal.h b/libopie2/opiepim/backend/otodoaccessvcal.h
new file mode 100644
index 0000000..4499a7e
--- a/dev/null
+++ b/libopie2/opiepim/backend/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