summaryrefslogtreecommitdiff
authorsimon <simon>2002-03-25 19:20:12 (UTC)
committer simon <simon>2002-03-25 19:20:12 (UTC)
commit843b7b0841976f8d6ea0ff0306dc0f59ebdeece0 (patch) (unidiff)
treeebe9b0d81db9a22d083438200c1efb201a1834e8
parent956522a9355051294e12e85e564d8ae1f0b928a3 (diff)
downloadopie-843b7b0841976f8d6ea0ff0306dc0f59ebdeece0.zip
opie-843b7b0841976f8d6ea0ff0306dc0f59ebdeece0.tar.gz
opie-843b7b0841976f8d6ea0ff0306dc0f59ebdeece0.tar.bz2
- added missing default: break; in switch
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/task.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/library/backend/task.cpp b/library/backend/task.cpp
index e7d697d..f0a38f1 100644
--- a/library/backend/task.cpp
+++ b/library/backend/task.cpp
@@ -1,245 +1,246 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpe/task.h> 21#include <qpe/task.h>
22#include <qregexp.h> 22#include <qregexp.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qpe/recordfields.h> 24#include <qpe/recordfields.h>
25#include "vobject_p.h" 25#include "vobject_p.h"
26#include "timeconversion.h" 26#include "timeconversion.h"
27#include "qfiledirect_p.h" 27#include "qfiledirect_p.h"
28 28
29#include <stdio.h> 29#include <stdio.h>
30 30
31using namespace Qtopia; 31using namespace Qtopia;
32UidGen Task::sUidGen( UidGen::Qtopia ); 32UidGen Task::sUidGen( UidGen::Qtopia );
33 33
34Task::Task() : Record(), mDue( FALSE ), 34Task::Task() : Record(), mDue( FALSE ),
35mDueDate( QDate::currentDate() ), 35mDueDate( QDate::currentDate() ),
36mCompleted( FALSE ), mPriority( 3 ), mDesc() 36mCompleted( FALSE ), mPriority( 3 ), mDesc()
37{ 37{
38} 38}
39 39
40Task::Task( const QMap<int, QString> &m ) : Record(), mDue( FALSE ), 40Task::Task( const QMap<int, QString> &m ) : Record(), mDue( FALSE ),
41mDueDate( QDate::currentDate() ), mCompleted( FALSE ), mPriority( 3 ), mDesc() 41mDueDate( QDate::currentDate() ), mCompleted( FALSE ), mPriority( 3 ), mDesc()
42{ 42{
43 //qDebug("Task::Task fromMap"); 43 //qDebug("Task::Task fromMap");
44 //dump( m ); 44 //dump( m );
45 for ( QMap<int,QString>::ConstIterator it = m.begin(); it != m.end();++it ) 45 for ( QMap<int,QString>::ConstIterator it = m.begin(); it != m.end();++it )
46 switch ( (TaskFields) it.key() ) { 46 switch ( (TaskFields) it.key() ) {
47 case HasDate: if ( *it == "1" ) mDue = TRUE; break; 47 case HasDate: if ( *it == "1" ) mDue = TRUE; break;
48 case Completed: setCompleted( *it == "1" ); break; 48 case Completed: setCompleted( *it == "1" ); break;
49 case TaskCategory: setCategories( idsFromString( *it ) ); break; 49 case TaskCategory: setCategories( idsFromString( *it ) ); break;
50 case TaskDescription: setDescription( *it ); break; 50 case TaskDescription: setDescription( *it ); break;
51 case Priority: setPriority( (*it).toInt() ); break; 51 case Priority: setPriority( (*it).toInt() ); break;
52 case Date: mDueDate = TimeConversion::fromString( (*it) ); break; 52 case Date: mDueDate = TimeConversion::fromString( (*it) ); break;
53 case TaskUid: setUid( (*it).toInt() ); break; 53 case TaskUid: setUid( (*it).toInt() ); break;
54 default: break;
54 } 55 }
55} 56}
56 57
57Task::~Task() 58Task::~Task()
58{ 59{
59} 60}
60 61
61QMap<int, QString> Task::toMap() const 62QMap<int, QString> Task::toMap() const
62{ 63{
63 QMap<int, QString> m; 64 QMap<int, QString> m;
64 m.insert( HasDate, hasDueDate() ? "1" : "0" ); 65 m.insert( HasDate, hasDueDate() ? "1" : "0" );
65 m.insert( Completed, isCompleted() ? "1" : "0" ); 66 m.insert( Completed, isCompleted() ? "1" : "0" );
66 m.insert( TaskCategory, idsToString( categories() ) ); 67 m.insert( TaskCategory, idsToString( categories() ) );
67 m.insert( TaskDescription, description() ); 68 m.insert( TaskDescription, description() );
68 m.insert( Priority, QString::number( priority() ) ); 69 m.insert( Priority, QString::number( priority() ) );
69 m.insert( Date, TimeConversion::toString( dueDate() ) ); 70 m.insert( Date, TimeConversion::toString( dueDate() ) );
70 m.insert( TaskUid, QString::number(uid()) ); 71 m.insert( TaskUid, QString::number(uid()) );
71 72
72 //qDebug("Task::toMap"); 73 //qDebug("Task::toMap");
73 //dump( m ); 74 //dump( m );
74 return m; 75 return m;
75} 76}
76 77
77void Task::save( QString& buf ) const 78void Task::save( QString& buf ) const
78{ 79{
79 buf += " Completed=\""; 80 buf += " Completed=\"";
80 // qDebug( "writing %d", complete ); 81 // qDebug( "writing %d", complete );
81 buf += QString::number( (int)mCompleted ); 82 buf += QString::number( (int)mCompleted );
82 buf += "\""; 83 buf += "\"";
83 buf += " HasDate=\""; 84 buf += " HasDate=\"";
84 // qDebug( "writing %d", ); 85 // qDebug( "writing %d", );
85 buf += QString::number( (int)mDue ); 86 buf += QString::number( (int)mDue );
86 buf += "\""; 87 buf += "\"";
87 buf += " Priority=\""; 88 buf += " Priority=\"";
88 // qDebug ("writing %d", prior ); 89 // qDebug ("writing %d", prior );
89 buf += QString::number( mPriority ); 90 buf += QString::number( mPriority );
90 buf += "\""; 91 buf += "\"";
91 buf += " Categories=\""; 92 buf += " Categories=\"";
92 buf += Qtopia::Record::idsToString( categories() ); 93 buf += Qtopia::Record::idsToString( categories() );
93 buf += "\""; 94 buf += "\"";
94 buf += " Description=\""; 95 buf += " Description=\"";
95 // qDebug( "writing note %s", note.latin1() ); 96 // qDebug( "writing note %s", note.latin1() );
96 buf += Qtopia::escapeString( mDesc ); 97 buf += Qtopia::escapeString( mDesc );
97 buf += "\""; 98 buf += "\"";
98 if ( mDue ) { 99 if ( mDue ) {
99 // qDebug("saving ymd %d %d %d", mDueDate.year(), mDueDate.month(), 100 // qDebug("saving ymd %d %d %d", mDueDate.year(), mDueDate.month(),
100 // mDueDate.day() ); 101 // mDueDate.day() );
101 buf += " DateYear=\""; 102 buf += " DateYear=\"";
102 buf += QString::number( mDueDate.year() ); 103 buf += QString::number( mDueDate.year() );
103 buf += "\""; 104 buf += "\"";
104 buf += " DateMonth=\""; 105 buf += " DateMonth=\"";
105 buf += QString::number( mDueDate.month() ); 106 buf += QString::number( mDueDate.month() );
106 buf += "\""; 107 buf += "\"";
107 buf += " DateDay=\""; 108 buf += " DateDay=\"";
108 buf += QString::number( mDueDate.day() ); 109 buf += QString::number( mDueDate.day() );
109 buf += "\""; 110 buf += "\"";
110 } 111 }
111 buf += customToXml(); 112 buf += customToXml();
112 // qDebug ("writing uid %d", uid() ); 113 // qDebug ("writing uid %d", uid() );
113 buf += " Uid=\""; 114 buf += " Uid=\"";
114 buf += QString::number( uid() ); 115 buf += QString::number( uid() );
115 // terminate it in the application... 116 // terminate it in the application...
116 buf += "\""; 117 buf += "\"";
117} 118}
118 119
119bool Task::match ( const QRegExp &r ) const 120bool Task::match ( const QRegExp &r ) const
120{ 121{
121 // match on priority, description on due date... 122 // match on priority, description on due date...
122 bool match; 123 bool match;
123 match = false; 124 match = false;
124 if ( QString::number( mPriority ).find( r ) > -1 ) 125 if ( QString::number( mPriority ).find( r ) > -1 )
125 match = true; 126 match = true;
126 else if ( mDue && mDueDate.toString().find( r ) > -1 ) 127 else if ( mDue && mDueDate.toString().find( r ) > -1 )
127 match = true; 128 match = true;
128 else if ( mDesc.find( r ) > -1 ) 129 else if ( mDesc.find( r ) > -1 )
129 match = true; 130 match = true;
130 return match; 131 return match;
131} 132}
132 133
133static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 134static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
134{ 135{
135 VObject *ret = 0; 136 VObject *ret = 0;
136 if ( o && !value.isEmpty() ) 137 if ( o && !value.isEmpty() )
137 ret = addPropValue( o, prop, value.latin1() ); 138 ret = addPropValue( o, prop, value.latin1() );
138 return ret; 139 return ret;
139} 140}
140 141
141static inline VObject *safeAddProp( VObject *o, const char *prop) 142static inline VObject *safeAddProp( VObject *o, const char *prop)
142{ 143{
143 VObject *ret = 0; 144 VObject *ret = 0;
144 if ( o ) 145 if ( o )
145 ret = addProp( o, prop ); 146 ret = addProp( o, prop );
146 return ret; 147 return ret;
147} 148}
148 149
149 150
150static VObject *createVObject( const Task &t ) 151static VObject *createVObject( const Task &t )
151{ 152{
152 VObject *vcal = newVObject( VCCalProp ); 153 VObject *vcal = newVObject( VCCalProp );
153 safeAddPropValue( vcal, VCVersionProp, "1.0" ); 154 safeAddPropValue( vcal, VCVersionProp, "1.0" );
154 VObject *task = safeAddProp( vcal, VCTodoProp ); 155 VObject *task = safeAddProp( vcal, VCTodoProp );
155 156
156 if ( t.hasDueDate() ) 157 if ( t.hasDueDate() )
157 safeAddPropValue( task, VCDueProp, TimeConversion::toISO8601( t.dueDate() ) ); 158 safeAddPropValue( task, VCDueProp, TimeConversion::toISO8601( t.dueDate() ) );
158 safeAddPropValue( task, VCDescriptionProp, t.description() ); 159 safeAddPropValue( task, VCDescriptionProp, t.description() );
159 if ( t.isCompleted() ) 160 if ( t.isCompleted() )
160 safeAddPropValue( task, VCStatusProp, "COMPLETED" ); 161 safeAddPropValue( task, VCStatusProp, "COMPLETED" );
161 safeAddPropValue( task, VCPriorityProp, QString::number( t.priority() ) ); 162 safeAddPropValue( task, VCPriorityProp, QString::number( t.priority() ) );
162 163
163 return vcal; 164 return vcal;
164} 165}
165 166
166 167
167static Task parseVObject( VObject *obj ) 168static Task parseVObject( VObject *obj )
168{ 169{
169 Task t; 170 Task t;
170 171
171 VObjectIterator it; 172 VObjectIterator it;
172 initPropIterator( &it, obj ); 173 initPropIterator( &it, obj );
173 while( moreIteration( &it ) ) { 174 while( moreIteration( &it ) ) {
174 VObject *o = nextVObject( &it ); 175 VObject *o = nextVObject( &it );
175 QCString name = vObjectName( o ); 176 QCString name = vObjectName( o );
176 QCString value = vObjectStringZValue( o ); 177 QCString value = vObjectStringZValue( o );
177 if ( name == VCDueProp ) { 178 if ( name == VCDueProp ) {
178 t.setDueDate( TimeConversion::fromISO8601( value ).date(), TRUE ); 179 t.setDueDate( TimeConversion::fromISO8601( value ).date(), TRUE );
179 } 180 }
180 else if ( name == VCDescriptionProp ) { 181 else if ( name == VCDescriptionProp ) {
181 t.setDescription( value ); 182 t.setDescription( value );
182 } 183 }
183 else if ( name == VCStatusProp ) { 184 else if ( name == VCStatusProp ) {
184 if ( value == "COMPLETED" ) 185 if ( value == "COMPLETED" )
185 t.setCompleted( TRUE ); 186 t.setCompleted( TRUE );
186 } 187 }
187 else if ( name == VCPriorityProp ) { 188 else if ( name == VCPriorityProp ) {
188 t.setPriority( value.toInt() ); 189 t.setPriority( value.toInt() );
189 } 190 }
190#if 0 191#if 0
191 else { 192 else {
192 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 193 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
193 VObjectIterator nit; 194 VObjectIterator nit;
194 initPropIterator( &nit, o ); 195 initPropIterator( &nit, o );
195 while( moreIteration( &nit ) ) { 196 while( moreIteration( &nit ) ) {
196 VObject *o = nextVObject( &nit ); 197 VObject *o = nextVObject( &nit );
197 QCString name = vObjectName( o ); 198 QCString name = vObjectName( o );
198 QString value = vObjectStringZValue( o ); 199 QString value = vObjectStringZValue( o );
199 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 200 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
200 } 201 }
201 } 202 }
202#endif 203#endif
203 } 204 }
204 205
205 return t; 206 return t;
206} 207}
207 208
208 209
209 210
210void Task::writeVCalendar( const QString &filename, const QValueList<Task> &tasks) 211void Task::writeVCalendar( const QString &filename, const QValueList<Task> &tasks)
211{ 212{
212 QFileDirect f( filename.utf8().data() ); 213 QFileDirect f( filename.utf8().data() );
213 if ( !f.open( IO_WriteOnly ) ) { 214 if ( !f.open( IO_WriteOnly ) ) {
214 qWarning("Unable to open vcard write"); 215 qWarning("Unable to open vcard write");
215 return; 216 return;
216 } 217 }
217 218
218 QValueList<Task>::ConstIterator it; 219 QValueList<Task>::ConstIterator it;
219 for( it = tasks.begin(); it != tasks.end(); ++it ) { 220 for( it = tasks.begin(); it != tasks.end(); ++it ) {
220 VObject *obj = createVObject( *it ); 221 VObject *obj = createVObject( *it );
221 writeVObject(f.directHandle() , obj ); 222 writeVObject(f.directHandle() , obj );
222 cleanVObject( obj ); 223 cleanVObject( obj );
223 } 224 }
224 225
225 cleanStrTbl(); 226 cleanStrTbl();
226} 227}
227 228
228void Task::writeVCalendar( const QString &filename, const Task &task) 229void Task::writeVCalendar( const QString &filename, const Task &task)
229{ 230{
230 QFileDirect f( filename.utf8().data() ); 231 QFileDirect f( filename.utf8().data() );
231 if ( !f.open( IO_WriteOnly ) ) { 232 if ( !f.open( IO_WriteOnly ) ) {
232 qWarning("Unable to open vcard write"); 233 qWarning("Unable to open vcard write");
233 return; 234 return;
234 } 235 }
235 236
236 VObject *obj = createVObject( task ); 237 VObject *obj = createVObject( task );
237 writeVObject(f.directHandle() , obj ); 238 writeVObject(f.directHandle() , obj );
238 cleanVObject( obj ); 239 cleanVObject( obj );
239 240
240 cleanStrTbl(); 241 cleanStrTbl();
241} 242}
242 243
243 244
244QValueList<Task> Task::readVCalendar( const QString &filename ) 245QValueList<Task> Task::readVCalendar( const QString &filename )
245{ 246{