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