summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccessvcal.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccessvcal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp192
1 files changed, 192 insertions, 0 deletions
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}