Diffstat (limited to 'libopie2/opiepim/backend/otodoaccessvcal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessvcal.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp index 6415952..e364ee2 100644 --- a/libopie2/opiepim/backend/otodoaccessvcal.cpp +++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp | |||
@@ -1,55 +1,85 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qfile.h> | 29 | #include <qfile.h> |
2 | 30 | ||
3 | #include <qtopia/private/vobject_p.h> | 31 | #include <qtopia/private/vobject_p.h> |
4 | #include <qtopia/timeconversion.h> | 32 | #include <qtopia/timeconversion.h> |
5 | #include <qtopia/private/qfiledirect_p.h> | 33 | #include <qtopia/private/qfiledirect_p.h> |
6 | 34 | ||
7 | #include "otodoaccessvcal.h" | 35 | #include <opie2/otodoaccessvcal.h> |
36 | |||
37 | using namespace Opie; | ||
8 | 38 | ||
9 | namespace { | 39 | namespace { |
10 | static OTodo eventByVObj( VObject *obj ){ | 40 | static OTodo eventByVObj( VObject *obj ){ |
11 | OTodo event; | 41 | OTodo event; |
12 | VObject *ob; | 42 | VObject *ob; |
13 | QCString name; | 43 | QCString name; |
14 | // no uid, attendees, ... and no fun | 44 | // no uid, attendees, ... and no fun |
15 | // description | 45 | // description |
16 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | 46 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ |
17 | name = vObjectStringZValue( ob ); | 47 | name = vObjectStringZValue( ob ); |
18 | #if 0 | 48 | #if 0 |
19 | event.setDescription( name ); | 49 | event.setDescription( name ); |
20 | #else | 50 | #else |
21 | event.setSummary( name ); | 51 | event.setSummary( name ); |
22 | #endif | 52 | #endif |
23 | } | 53 | } |
24 | // summary | 54 | // summary |
25 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { | 55 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { |
26 | name = vObjectStringZValue( ob ); | 56 | name = vObjectStringZValue( ob ); |
27 | #if 0 | 57 | #if 0 |
28 | event.setSummary( name ); | 58 | event.setSummary( name ); |
29 | #else | 59 | #else |
30 | event.setDescription( name ); | 60 | event.setDescription( name ); |
31 | #endif | 61 | #endif |
32 | } | 62 | } |
33 | // completed | 63 | // completed |
34 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | 64 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ |
35 | name = vObjectStringZValue( ob ); | 65 | name = vObjectStringZValue( ob ); |
36 | if( name == "COMPLETED" ){ | 66 | if( name == "COMPLETED" ){ |
37 | event.setCompleted( true ); | 67 | event.setCompleted( true ); |
38 | }else{ | 68 | }else{ |
39 | event.setCompleted( false ); | 69 | event.setCompleted( false ); |
40 | } | 70 | } |
41 | }else | 71 | }else |
42 | event.setCompleted( false ); | 72 | event.setCompleted( false ); |
43 | // priority | 73 | // priority |
44 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | 74 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { |
45 | name = vObjectStringZValue( ob ); | 75 | name = vObjectStringZValue( ob ); |
46 | bool ok; | 76 | bool ok; |
47 | event.setPriority(name.toInt(&ok) ); | 77 | event.setPriority(name.toInt(&ok) ); |
48 | } | 78 | } |
49 | //due date | 79 | //due date |
50 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | 80 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ |
51 | event.setHasDueDate( true ); | 81 | event.setHasDueDate( true ); |
52 | name = vObjectStringZValue( ob ); | 82 | name = vObjectStringZValue( ob ); |
53 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); | 83 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); |
54 | } | 84 | } |
55 | // categories | 85 | // categories |
@@ -62,96 +92,97 @@ namespace { | |||
62 | return event; | 92 | return event; |
63 | }; | 93 | }; |
64 | static VObject *vobjByEvent( const OTodo &event ) { | 94 | static VObject *vobjByEvent( const OTodo &event ) { |
65 | VObject *task = newVObject( VCTodoProp ); | 95 | VObject *task = newVObject( VCTodoProp ); |
66 | if( task == 0 ) | 96 | if( task == 0 ) |
67 | return 0l; | 97 | return 0l; |
68 | 98 | ||
69 | if( event.hasDueDate() ) { | 99 | if( event.hasDueDate() ) { |
70 | QTime time(0, 0, 0); | 100 | QTime time(0, 0, 0); |
71 | QDateTime date(event.dueDate(), time ); | 101 | QDateTime date(event.dueDate(), time ); |
72 | addPropValue( task, VCDueProp, | 102 | addPropValue( task, VCDueProp, |
73 | TimeConversion::toISO8601( date ) ); | 103 | TimeConversion::toISO8601( date ) ); |
74 | } | 104 | } |
75 | 105 | ||
76 | if( event.isCompleted() ) | 106 | if( event.isCompleted() ) |
77 | addPropValue( task, VCStatusProp, "COMPLETED"); | 107 | addPropValue( task, VCStatusProp, "COMPLETED"); |
78 | 108 | ||
79 | QString string = QString::number(event.priority() ); | 109 | QString string = QString::number(event.priority() ); |
80 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | 110 | addPropValue( task, VCPriorityProp, string.local8Bit() ); |
81 | 111 | ||
82 | addPropValue( task, VCCategoriesProp, | 112 | addPropValue( task, VCCategoriesProp, |
83 | event.idsToString( event.categories() ).local8Bit() ); | 113 | event.idsToString( event.categories() ).local8Bit() ); |
84 | 114 | ||
85 | #if 0 | 115 | #if 0 |
86 | 116 | ||
87 | // There seems a misrepresentation between summary in otodoevent | 117 | // There seems a misrepresentation between summary in otodoevent |
88 | // and summary in vcard. | 118 | // and summary in vcard. |
89 | // The same with description.. | 119 | // The same with description.. |
90 | // Description is summary and vice versa.. Argh.. (eilers) | 120 | // Description is summary and vice versa.. Argh.. (eilers) |
91 | 121 | ||
92 | 122 | ||
93 | addPropValue( task, VCDescriptionProp, | 123 | addPropValue( task, VCDescriptionProp, |
94 | event.description().local8Bit() ); | 124 | event.description().local8Bit() ); |
95 | 125 | ||
96 | addPropValue( task, VCSummaryProp, | 126 | addPropValue( task, VCSummaryProp, |
97 | event.summary().local8Bit() ); | 127 | event.summary().local8Bit() ); |
98 | 128 | ||
99 | #else | 129 | #else |
100 | addPropValue( task, VCDescriptionProp, | 130 | addPropValue( task, VCDescriptionProp, |
101 | event.summary().local8Bit() ); | 131 | event.summary().local8Bit() ); |
102 | 132 | ||
103 | addPropValue( task, VCSummaryProp, | 133 | addPropValue( task, VCSummaryProp, |
104 | event.description().local8Bit() ); | 134 | event.description().local8Bit() ); |
105 | #endif | 135 | #endif |
106 | return task; | 136 | return task; |
107 | }; | 137 | }; |
108 | } | 138 | } |
109 | 139 | ||
140 | namespace Opie { | ||
110 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) | 141 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) |
111 | : m_dirty(false), m_file( path ) | 142 | : m_dirty(false), m_file( path ) |
112 | { | 143 | { |
113 | } | 144 | } |
114 | OTodoAccessVCal::~OTodoAccessVCal() { | 145 | OTodoAccessVCal::~OTodoAccessVCal() { |
115 | } | 146 | } |
116 | bool OTodoAccessVCal::load() { | 147 | bool OTodoAccessVCal::load() { |
117 | m_map.clear(); | 148 | m_map.clear(); |
118 | m_dirty = false; | 149 | m_dirty = false; |
119 | 150 | ||
120 | VObject* vcal = 0l; | 151 | VObject* vcal = 0l; |
121 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 152 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
122 | if (!vcal ) | 153 | if (!vcal ) |
123 | return false; | 154 | return false; |
124 | 155 | ||
125 | // Iterate over the list | 156 | // Iterate over the list |
126 | VObjectIterator it; | 157 | VObjectIterator it; |
127 | VObject* vobj; | 158 | VObject* vobj; |
128 | 159 | ||
129 | initPropIterator(&it, vcal); | 160 | initPropIterator(&it, vcal); |
130 | 161 | ||
131 | while( moreIteration( &it ) ) { | 162 | while( moreIteration( &it ) ) { |
132 | vobj = ::nextVObject( &it ); | 163 | vobj = ::nextVObject( &it ); |
133 | QCString name = ::vObjectName( vobj ); | 164 | QCString name = ::vObjectName( vobj ); |
134 | if( name == VCTodoProp ){ | 165 | if( name == VCTodoProp ){ |
135 | OTodo to = eventByVObj( vobj ); | 166 | OTodo to = eventByVObj( vobj ); |
136 | m_map.insert( to.uid(), to ); | 167 | m_map.insert( to.uid(), to ); |
137 | } | 168 | } |
138 | } | 169 | } |
139 | 170 | ||
140 | // Should I do a delete vcal? | 171 | // Should I do a delete vcal? |
141 | 172 | ||
142 | return true; | 173 | return true; |
143 | } | 174 | } |
144 | bool OTodoAccessVCal::reload() { | 175 | bool OTodoAccessVCal::reload() { |
145 | return load(); | 176 | return load(); |
146 | } | 177 | } |
147 | bool OTodoAccessVCal::save() { | 178 | bool OTodoAccessVCal::save() { |
148 | if (!m_dirty ) | 179 | if (!m_dirty ) |
149 | return true; | 180 | return true; |
150 | 181 | ||
151 | QFileDirect file( m_file ); | 182 | QFileDirect file( m_file ); |
152 | if (!file.open(IO_WriteOnly ) ) | 183 | if (!file.open(IO_WriteOnly ) ) |
153 | return false; | 184 | return false; |
154 | 185 | ||
155 | VObject *obj; | 186 | VObject *obj; |
156 | obj = newVObject( VCCalProp ); | 187 | obj = newVObject( VCCalProp ); |
157 | addPropValue( obj, VCVersionProp, "1.0" ); | 188 | addPropValue( obj, VCVersionProp, "1.0" ); |
@@ -202,48 +233,50 @@ QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { | |||
202 | QArray<int> OTodoAccessVCal::allRecords()const { | 233 | QArray<int> OTodoAccessVCal::allRecords()const { |
203 | QArray<int> ar( m_map.count() ); | 234 | QArray<int> ar( m_map.count() ); |
204 | QMap<int, OTodo>::ConstIterator it; | 235 | QMap<int, OTodo>::ConstIterator it; |
205 | int i = 0; | 236 | int i = 0; |
206 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 237 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
207 | ar[i] = it.key(); | 238 | ar[i] = it.key(); |
208 | i++; | 239 | i++; |
209 | } | 240 | } |
210 | return ar; | 241 | return ar; |
211 | } | 242 | } |
212 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { | 243 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { |
213 | QArray<int> ar(0); | 244 | QArray<int> ar(0); |
214 | return ar; | 245 | return ar; |
215 | } | 246 | } |
216 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { | 247 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { |
217 | QArray<int> ar(0); | 248 | QArray<int> ar(0); |
218 | return ar; | 249 | return ar; |
219 | } | 250 | } |
220 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , | 251 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , |
221 | const QDate& , | 252 | const QDate& , |
222 | bool ) { | 253 | bool ) { |
223 | QArray<int> ar(0); | 254 | QArray<int> ar(0); |
224 | return ar; | 255 | return ar; |
225 | } | 256 | } |
226 | QArray<int> OTodoAccessVCal::overDue() { | 257 | QArray<int> OTodoAccessVCal::overDue() { |
227 | QArray<int> ar(0); | 258 | QArray<int> ar(0); |
228 | return ar; | 259 | return ar; |
229 | } | 260 | } |
230 | QBitArray OTodoAccessVCal::supports()const { | 261 | QBitArray OTodoAccessVCal::supports()const { |
231 | static QBitArray ar = sup(); | 262 | static QBitArray ar = sup(); |
232 | 263 | ||
233 | return ar; | 264 | return ar; |
234 | } | 265 | } |
235 | QBitArray OTodoAccessVCal::sup() { | 266 | QBitArray OTodoAccessVCal::sup() { |
236 | QBitArray ar ( OTodo::CompletedDate +1 ); | 267 | QBitArray ar ( OTodo::CompletedDate +1 ); |
237 | ar.fill( true ); | 268 | ar.fill( true ); |
238 | 269 | ||
239 | ar[OTodo::CrossReference] = false; | 270 | ar[OTodo::CrossReference] = false; |
240 | ar[OTodo::State ] = false; | 271 | ar[OTodo::State ] = false; |
241 | ar[OTodo::Reminders] = false; | 272 | ar[OTodo::Reminders] = false; |
242 | ar[OTodo::Notifiers] = false; | 273 | ar[OTodo::Notifiers] = false; |
243 | ar[OTodo::Maintainer] = false; | 274 | ar[OTodo::Maintainer] = false; |
244 | ar[OTodo::Progress] = false; | 275 | ar[OTodo::Progress] = false; |
245 | ar[OTodo::Alarms ] = false; | 276 | ar[OTodo::Alarms ] = false; |
246 | ar[OTodo::Recurrence] = false; | 277 | ar[OTodo::Recurrence] = false; |
247 | 278 | ||
248 | return ar; | 279 | return ar; |
249 | } | 280 | } |
281 | |||
282 | } | ||