summaryrefslogtreecommitdiff
path: root/libopie
authorzecke <zecke>2002-06-15 16:46:37 (UTC)
committer zecke <zecke>2002-06-15 16:46:37 (UTC)
commitff47b17768607d8819ef5cd3316a1cab0abdcf3a (patch) (unidiff)
treeaddbc4d7d8826ce2952aca872e67e3575d77cda7 /libopie
parent9f41969610f9db5d60d6080abae0b21e54a549e2 (diff)
downloadopie-ff47b17768607d8819ef5cd3316a1cab0abdcf3a.zip
opie-ff47b17768607d8819ef5cd3316a1cab0abdcf3a.tar.gz
opie-ff47b17768607d8819ef5cd3316a1cab0abdcf3a.tar.bz2
Summary support
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/tododb.cpp12
-rw-r--r--libopie/todoevent.cpp43
-rw-r--r--libopie/todoevent.h67
-rw-r--r--libopie/todovcalresource.cpp23
4 files changed, 121 insertions, 24 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp
index fe8b8bf..6b10ec2 100644
--- a/libopie/tododb.cpp
+++ b/libopie/tododb.cpp
@@ -1,41 +1,43 @@
1 1
2#include <qdir.h> 2#include <qdir.h>
3#include <opie/tododb.h> 3#include <opie/tododb.h>
4#include <opie/xmltree.h> 4#include <opie/xmltree.h>
5#include <opie/todoresource.h> 5#include <opie/todoresource.h>
6#include <qpe/palmtoprecord.h> 6#include <qpe/palmtoprecord.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9using namespace Opie; 9using namespace Opie;
10 10
11namespace { 11namespace {
12 12
13class FileToDoResource : public ToDoResource { 13class FileToDoResource : public ToDoResource {
14public: 14public:
15 FileToDoResource() {}; 15 FileToDoResource() {};
16 // FIXME better parsing
16 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ 17 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
17 // prepare the XML 18 // prepare the XML
18 XMLElement *tasks = new XMLElement( ); 19 XMLElement *tasks = new XMLElement( );
19 tasks->setTagName("Tasks" ); 20 tasks->setTagName("Tasks" );
20 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ 21 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
21 XMLElement::AttributeMap map; 22 XMLElement::AttributeMap map;
22 XMLElement *task = new XMLElement(); 23 XMLElement *task = new XMLElement();
23 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); 24 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
24 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); 25 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
25 map.insert( "Priority", QString::number( (*it).priority() ) ); 26 map.insert( "Priority", QString::number( (*it).priority() ) );
27 map.insert( "Summary", (*it).summary() );
26 QArray<int> arrat = (*it).categories(); 28 QArray<int> arrat = (*it).categories();
27 QString attr; 29 QString attr;
28 for(uint i=0; i < arrat.count(); i++ ){ 30 for(uint i=0; i < arrat.count(); i++ ){
29 attr.append(QString::number(arrat[i])+";" ); 31 attr.append(QString::number(arrat[i])+";" );
30 } 32 }
31 if(!attr.isEmpty() ) // remove the last ; 33 if(!attr.isEmpty() ) // remove the last ;
32 attr.remove(attr.length()-1, 1 ); 34 attr.remove(attr.length()-1, 1 );
33 map.insert( "Categories", attr ); 35 map.insert( "Categories", attr );
34 //else 36 //else
35 //map.insert( "Categories", QString::null ); 37 //map.insert( "Categories", QString::null );
36 map.insert( "Description", (*it).description() ); 38 map.insert( "Description", (*it).description() );
37 if( (*it).hasDate() ){ 39 if( (*it).hasDate() ){
38 map.insert("DateYear", QString::number( (*it).date().year() ) ); 40 map.insert("DateYear", QString::number( (*it).date().year() ) );
39 map.insert("DateMonth", QString::number( (*it).date().month() ) ); 41 map.insert("DateMonth", QString::number( (*it).date().month() ) );
40 map.insert("DateDay", QString::number( (*it).date().day() ) ); 42 map.insert("DateDay", QString::number( (*it).date().day() ) );
41 } 43 }
@@ -98,37 +100,39 @@ public:
98 dumInt = dummy.toInt(&ok ); 100 dumInt = dummy.toInt(&ok );
99 if(ok ) month = dumInt; 101 if(ok ) month = dumInt;
100 dummy = element->attribute("DateDay" ); 102 dummy = element->attribute("DateDay" );
101 dumInt = dummy.toInt(&ok ); 103 dumInt = dummy.toInt(&ok );
102 if(ok ) day = dumInt; 104 if(ok ) day = dumInt;
103 // set the date 105 // set the date
104 QDate date( year, month, day ); 106 QDate date( year, month, day );
105 event.setDate( date); 107 event.setDate( date);
106 } 108 }
107 dummy = element->attribute("Priority" ); 109 dummy = element->attribute("Priority" );
108 dumInt = dummy.toInt(&ok ); 110 dumInt = dummy.toInt(&ok );
109 if(!ok ) dumInt = ToDoEvent::NORMAL; 111 if(!ok ) dumInt = ToDoEvent::NORMAL;
110 event.setPriority( dumInt ); 112 event.setPriority( dumInt );
111 //description 113 //description
112 dummy = element->attribute("Description" ); 114 dummy = element->attribute("Description" );
113 event.setDescription( dummy ); 115 event.setDescription( dummy );
116 dummy = element->attribute("Summary" );
117 event.setSummary( dummy );
114 // category 118 // category
115 dummy = element->attribute("Categories" ); 119 dummy = element->attribute("Categories" );
116 QStringList ids = QStringList::split(";", dummy ); 120 QStringList ids = QStringList::split(";", dummy );
117 event.setCategories( ids ); 121 event.setCategories( ids );
118 122
119 //uid 123 //uid
120 dummy = element->attribute("Uid" ); 124 dummy = element->attribute("Uid" );
121 dumInt = dummy.toInt(&ok ); 125 dumInt = dummy.toInt(&ok );
122 if(ok ) event.setUid( dumInt ); 126 if(ok ) event.setUid( dumInt );
123 m_todos.append( event ); 127 m_todos.append( event );
124 element = element->nextChild(); // next element 128 element = element->nextChild(); // next element
125 } 129 }
126 //} 130 //}
127 }else { 131 }else {
128 qWarning("could not load" ); 132 qWarning("could not load" );
129 } 133 }
130 delete root; 134 delete root;
131 qWarning("returning" ); 135 qWarning("returning" );
132 return m_todos; 136 return m_todos;
133 } 137 }
134}; 138};
@@ -168,33 +172,33 @@ QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to,
168 if( (*it).date() >= from && (*it).date() <= to ) 172 if( (*it).date() >= from && (*it).date() <= to )
169 events.append( (*it) ); 173 events.append( (*it) );
170 }else if( all ){ 174 }else if( all ){
171 events.append( (*it) ); 175 events.append( (*it) );
172 } 176 }
173 } 177 }
174 return events; 178 return events;
175} 179}
176QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, 180QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from,
177 bool all) 181 bool all)
178{ 182{
179 return effectiveToDos( from, QDate::currentDate(), all ); 183 return effectiveToDos( from, QDate::currentDate(), all );
180} 184}
181QValueList<ToDoEvent> ToDoDB::overDue() 185QValueList<ToDoEvent> ToDoDB::overDue()
182{ 186{
183 QValueList<ToDoEvent> events; 187 QValueList<ToDoEvent> events;
184 for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ 188 for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
185 if( (*it).isOverdue() ) 189 if( (*it).isOverdue() )
186 events.append((*it) ); 190 events.append((*it) );
187 } 191 }
188 return events; 192 return events;
189} 193}
190QValueList<ToDoEvent> ToDoDB::rawToDos() 194QValueList<ToDoEvent> ToDoDB::rawToDos()
191{ 195{
192 return m_todos; 196 return m_todos;
193} 197}
194void ToDoDB::addEvent( const ToDoEvent &event ) 198void ToDoDB::addEvent( const ToDoEvent &event )
195{ 199{
196 m_todos.append( event ); 200 m_todos.append( event );
197} 201}
198void ToDoDB::editEvent( const ToDoEvent &event ) 202void ToDoDB::editEvent( const ToDoEvent &event )
199{ 203{
200 m_todos.remove( event ); 204 m_todos.remove( event );
@@ -225,30 +229,30 @@ void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events )
225{ 229{
226 QValueList<ToDoEvent>::ConstIterator it; 230 QValueList<ToDoEvent>::ConstIterator it;
227 for( it = events.begin(); it != events.end(); ++it ){ 231 for( it = events.begin(); it != events.end(); ++it ){
228 replaceEvent( (*it) ); 232 replaceEvent( (*it) );
229 } 233 }
230} 234}
231void ToDoDB::setFileName(const QString &file ) 235void ToDoDB::setFileName(const QString &file )
232{ 236{
233 m_fileName =file; 237 m_fileName =file;
234} 238}
235QString ToDoDB::fileName()const 239QString ToDoDB::fileName()const
236{ 240{
237 return m_fileName; 241 return m_fileName;
238} 242}
239void ToDoDB::load() 243void ToDoDB::load()
240{ 244{
241 m_todos = m_res->load( m_fileName ); 245 m_todos = m_res->load( m_fileName );
242} 246}
243bool ToDoDB::save() 247bool ToDoDB::save()
244{ 248{
245 return m_res->save( m_fileName, m_todos ); 249 return m_res->save( m_fileName, m_todos );
246} 250}
247 251
248 252
249 253
250 254
251 255
252 256
253 257
254 258
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
index aa348a2..fb7073c 100644
--- a/libopie/todoevent.cpp
+++ b/libopie/todoevent.cpp
@@ -4,47 +4,51 @@
4 4
5#include <qpe/palmtopuidgen.h> 5#include <qpe/palmtopuidgen.h>
6#include <qpe/stringutil.h> 6#include <qpe/stringutil.h>
7#include <qpe/palmtoprecord.h> 7#include <qpe/palmtoprecord.h>
8 8
9#include <qpe/stringutil.h> 9#include <qpe/stringutil.h>
10#include <qpe/categories.h> 10#include <qpe/categories.h>
11#include <qpe/categoryselect.h> 11#include <qpe/categoryselect.h>
12 12
13#include <qobject.h> 13#include <qobject.h>
14 14
15ToDoEvent::ToDoEvent(const ToDoEvent &event ) 15ToDoEvent::ToDoEvent(const ToDoEvent &event )
16{ 16{
17 *this = event; 17 *this = event;
18} 18}
19 19
20ToDoEvent::ToDoEvent(bool completed, int priority, const QStringList &category, 20ToDoEvent::ToDoEvent(bool completed, int priority,
21 const QString &description, bool hasDate, QDate date, int uid ) 21 const QStringList &category,
22 const QString& summary,
23 const QString &description,
24 bool hasDate, QDate date, int uid )
22{ 25{
23 m_date = date; 26 m_date = date;
24 m_isCompleted = completed; 27 m_isCompleted = completed;
25 m_hasDate = hasDate; 28 m_hasDate = hasDate;
26 m_priority = priority; 29 m_priority = priority;
27 m_category = category; 30 m_category = category;
31 m_sum = summary;
28 m_desc = Qtopia::simplifyMultiLineSpace(description ); 32 m_desc = Qtopia::simplifyMultiLineSpace(description );
29 if (uid == -1 ) { 33 if (uid == -1 ) {
30 Qtopia::UidGen *uidgen = new Qtopia::UidGen(); 34 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
31 uid = uidgen->generate(); 35 uid = uidgen->generate();
32 delete uidgen; 36 delete uidgen;
33 }// generate the ids 37 }// generate the ids
34 m_uid = uid; 38 m_uid = uid;
35} 39}
36QArray<int> ToDoEvent::categories()const 40QArray<int> ToDoEvent::categories()const
37{ 41{
38 QArray<int> array(m_category.count() ); // currently the datebook can be only in one category 42 QArray<int> array(m_category.count() ); // currently the datebook can be only in one category
39 array = Qtopia::Record::idsFromString( m_category.join(";") ); 43 array = Qtopia::Record::idsFromString( m_category.join(";") );
40 return array; 44 return array;
41} 45}
42bool ToDoEvent::match( const QRegExp &regExp )const 46bool ToDoEvent::match( const QRegExp &regExp )const
43{ 47{
44 if( QString::number( m_priority ).find( regExp ) != -1 ){ 48 if( QString::number( m_priority ).find( regExp ) != -1 ){
45 return true; 49 return true;
46 }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ 50 }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){
47 return true; 51 return true;
48 }else if(m_desc.find( regExp ) != -1 ){ 52 }else if(m_desc.find( regExp ) != -1 ){
49 return true; 53 return true;
50 } 54 }
@@ -53,32 +57,40 @@ bool ToDoEvent::match( const QRegExp &regExp )const
53bool ToDoEvent::isCompleted() const 57bool ToDoEvent::isCompleted() const
54{ 58{
55 return m_isCompleted; 59 return m_isCompleted;
56} 60}
57bool ToDoEvent::hasDate() const 61bool ToDoEvent::hasDate() const
58{ 62{
59 return m_hasDate; 63 return m_hasDate;
60} 64}
61int ToDoEvent::priority()const 65int ToDoEvent::priority()const
62{ 66{
63 return m_priority; 67 return m_priority;
64} 68}
65QStringList ToDoEvent::allCategories()const 69QStringList ToDoEvent::allCategories()const
66{ 70{
67 return m_category; 71 return m_category;
68} 72}
73QString ToDoEvent::extra(const QString& )const
74{
75 return QString::null;
76}
77QString ToDoEvent::summary() const
78{
79 return m_sum;
80}
69void ToDoEvent::insertCategory(const QString &str ) 81void ToDoEvent::insertCategory(const QString &str )
70{ 82{
71 m_category.append( str ); 83 m_category.append( str );
72} 84}
73void ToDoEvent::clearCategories() 85void ToDoEvent::clearCategories()
74{ 86{
75 m_category.clear(); 87 m_category.clear();
76} 88}
77void ToDoEvent::setCategories(const QStringList &list ) 89void ToDoEvent::setCategories(const QStringList &list )
78{ 90{
79 m_category = list; 91 m_category = list;
80} 92}
81QDate ToDoEvent::date()const 93QDate ToDoEvent::date()const
82{ 94{
83 return m_date; 95 return m_date;
84} 96}
@@ -86,83 +98,93 @@ QDate ToDoEvent::date()const
86QString ToDoEvent::description()const 98QString ToDoEvent::description()const
87{ 99{
88 return m_desc; 100 return m_desc;
89} 101}
90void ToDoEvent::setCompleted( bool completed ) 102void ToDoEvent::setCompleted( bool completed )
91{ 103{
92 m_isCompleted = completed; 104 m_isCompleted = completed;
93} 105}
94void ToDoEvent::setHasDate( bool hasDate ) 106void ToDoEvent::setHasDate( bool hasDate )
95{ 107{
96 m_hasDate = hasDate; 108 m_hasDate = hasDate;
97} 109}
98void ToDoEvent::setDescription(const QString &desc ) 110void ToDoEvent::setDescription(const QString &desc )
99{ 111{
100 m_desc = Qtopia::simplifyMultiLineSpace(desc ); 112 m_desc = Qtopia::simplifyMultiLineSpace(desc );
101} 113}
114void ToDoEvent::setExtra( const QString&, const QString& )
115{
116
117}
118void ToDoEvent::setSummary( const QString& sum )
119{
120 m_sum = sum;
121}
102void ToDoEvent::setCategory( const QString &cat ) 122void ToDoEvent::setCategory( const QString &cat )
103{ 123{
104 qWarning("setCategory %s", cat.latin1() ); 124 qWarning("setCategory %s", cat.latin1() );
105 m_category.clear(); 125 m_category.clear();
106 m_category << cat; 126 m_category << cat;
107} 127}
108void ToDoEvent::setPriority(int prio ) 128void ToDoEvent::setPriority(int prio )
109{ 129{
110 m_priority = prio; 130 m_priority = prio;
111} 131}
112void ToDoEvent::setDate( QDate date ) 132void ToDoEvent::setDate( QDate date )
113{ 133{
114 m_date = date; 134 m_date = date;
115} 135}
116bool ToDoEvent::isOverdue( ) 136bool ToDoEvent::isOverdue( )
117{ 137{
118 if( m_hasDate ) 138 if( m_hasDate )
119 return QDate::currentDate() > m_date; 139 return QDate::currentDate() > m_date;
120 return false; 140 return false;
121} 141}
122 142
123/*! 143/*!
124 Returns a richt text string 144 Returns a richt text string
125*/ 145*/
126QString ToDoEvent::richText() const 146QString ToDoEvent::richText() const
127{ 147{
128 QString text; 148 QString text;
129 QStringList catlist; 149 QStringList catlist;
130 150
131 // Description of the todo 151 // Description of the todo
132 if ( !description().isEmpty() ){ 152 if ( !description().isEmpty() ){
153 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
154 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
133 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 155 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
134 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 156 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
135 } 157 }
136 text += "<b>" + QObject::tr( "Priority:") +" </b>" 158 text += "<b>" + QObject::tr( "Priority:") +" </b>"
137 + QString::number( priority() ) + "<br>"; 159 + QString::number( priority() ) + "<br>";
138 if (hasDate() ){ 160 if (hasDate() ){
139 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 161 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
140 text += date().toString(); 162 text += date().toString();
141 text += "<br>"; 163 text += "<br>";
142 } 164 }
143 165
144 // Open database of all categories and get the list of 166 // Open database of all categories and get the list of
145 // the categories this todoevent belongs to. 167 // the categories this todoevent belongs to.
146 // Then print them... 168 // Then print them...
147 // I am not sure whether there is no better way doing this !? 169 // I am not sure whether there is no better way doing this !?
148 Categories catdb; 170 Categories catdb;
149 bool firstloop = true; 171 bool firstloop = true;
150 catdb.load( categoryFileName() ); 172 catdb.load( categoryFileName() );
151 catlist = allCategories(); 173 catlist = allCategories();
152 174
153 text += "<b>" + QObject::tr( "Category:") + "</b> "; 175 text += "<b>" + QObject::tr( "Category:") + "</b> ";
154 for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { 176 for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) {
155 if (!firstloop){ 177 if (!firstloop){
156 text += ", "; 178 text += ", ";
157 } 179 }
158 firstloop = false; 180 firstloop = false;
159 text += catdb.label ("todo", (*it).toInt()); 181 text += catdb.label ("todo", (*it).toInt());
160 } 182 }
161 text += "<br>"; 183 text += "<br>";
162 return text; 184 return text;
163} 185}
164 186
165bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ 187bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{
166 if( !hasDate() && !toDoEvent.hasDate() ) return true; 188 if( !hasDate() && !toDoEvent.hasDate() ) return true;
167 if( !hasDate() && toDoEvent.hasDate() ) return true; 189 if( !hasDate() && toDoEvent.hasDate() ) return true;
168 if( hasDate() && toDoEvent.hasDate() ){ 190 if( hasDate() && toDoEvent.hasDate() ){
@@ -202,39 +224,46 @@ bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const
202} 224}
203bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const 225bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const
204{ 226{
205 if( !hasDate() && !toDoEvent.hasDate() ) return true; 227 if( !hasDate() && !toDoEvent.hasDate() ) return true;
206 if( !hasDate() && toDoEvent.hasDate() ) return false; 228 if( !hasDate() && toDoEvent.hasDate() ) return false;
207 if( hasDate() && toDoEvent.hasDate() ){ 229 if( hasDate() && toDoEvent.hasDate() ){
208 if( date() == toDoEvent.date() ){ // let's the priority decide 230 if( date() == toDoEvent.date() ){ // let's the priority decide
209 return priority() > toDoEvent.priority(); 231 return priority() > toDoEvent.priority();
210 }else{ 232 }else{
211 return date() > toDoEvent.date(); 233 return date() > toDoEvent.date();
212 } 234 }
213 } 235 }
214 return true; 236 return true;
215} 237}
216bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const 238bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const
217{ 239{
218 if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_desc ) 240 if( m_priority == toDoEvent.m_priority &&
241 m_isCompleted == toDoEvent.m_isCompleted &&
242 m_hasDate == toDoEvent.m_hasDate &&
243 m_date == toDoEvent.m_date &&
244 m_category == toDoEvent.m_category &&
245 m_sum == toDoEvent.m_sum &&
246 m_desc == toDoEvent.m_desc )
219 return true; 247 return true;
220 return false; 248 return false;
221} 249}
222ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) 250ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item )
223{ 251{
224 m_date = item.m_date; 252 m_date = item.m_date;
225 m_isCompleted = item.m_isCompleted; 253 m_isCompleted = item.m_isCompleted;
226 m_hasDate = item.m_hasDate; 254 m_hasDate = item.m_hasDate;
227 m_priority = item.m_priority; 255 m_priority = item.m_priority;
228 m_category = item.m_category; 256 m_category = item.m_category;
229 m_desc = item.m_desc; 257 m_desc = item.m_desc;
230 m_uid = item.m_uid; 258 m_uid = item.m_uid;
259 m_sum = item.m_sum;
231 return *this; 260 return *this;
232} 261}
233 262
234 263
235 264
236 265
237 266
238 267
239 268
240 269
diff --git a/libopie/todoevent.h b/libopie/todoevent.h
index 8a00f99..7454241 100644
--- a/libopie/todoevent.h
+++ b/libopie/todoevent.h
@@ -1,92 +1,151 @@
1 1
2#ifndef todoevent_h 2#ifndef todoevent_h
3#define todoevent_h 3#define todoevent_h
4 4
5#include <qmap.h>
5#include <qregexp.h> 6#include <qregexp.h>
6#include <qstringlist.h> 7#include <qstringlist.h>
7#include <qdatetime.h> 8#include <qdatetime.h>
8 9
9class ToDoEvent { 10class ToDoEvent {
10 friend class ToDoDB; 11 friend class ToDoDB;
11 public: 12 public:
12 // priorities from Very low to very high 13 // priorities from Very low to very high
13 enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; 14 enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW };
14 /* Constructs a new ToDoEvent 15 /* Constructs a new ToDoEvent
15 @param completed Is the TodoEvent completed 16 @param completed Is the TodoEvent completed
16 @param priority What is the priority of this ToDoEvent 17 @param priority What is the priority of this ToDoEvent
17 @param category Which category does it belong( uid ) 18 @param category Which category does it belong( uid )
19 @param summary A small summary of the todo
18 @param description What is this ToDoEvent about 20 @param description What is this ToDoEvent about
19 @param hasDate Does this Event got a deadline 21 @param hasDate Does this Event got a deadline
20 @param date what is the deadline? 22 @param date what is the deadline?
21 @param uid what is the UUID of this Event 23 @param uid what is the UUID of this Event
22 **/ 24 **/
23 ToDoEvent( bool completed = false, int priority = NORMAL, 25 ToDoEvent( bool completed = false, int priority = NORMAL,
24 const QStringList &category = QStringList(), 26 const QStringList &category = QStringList(),
25 const QString &description = QString::null , 27 const QString &summary = QString::null ,
28 const QString &description = QString::null,
26 bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); 29 bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 );
27 /* Copy c'tor 30 /* Copy c'tor
28 31
29 **/ 32 **/
30 ToDoEvent(const ToDoEvent & ); 33 ToDoEvent(const ToDoEvent & );
31 34
32 /* 35 /*
33 Is this event completed? 36 Is this event completed?
34 **/ 37 **/
35 bool isCompleted() const; 38 bool isCompleted() const;
36 39
37 /* 40 /*
38 Does this Event have a deadline 41 Does this Event have a deadline
39 **/ 42 **/
40 bool hasDate() const; 43 bool hasDate() const;
41 44
42 /* 45 /*
43 What is the priority? 46 What is the priority?
44 **/ 47 **/
45 int priority()const ; 48 int priority()const ;
49
50 /*
51 All category numbers as QString in a List
52 **/
46 QStringList allCategories()const; 53 QStringList allCategories()const;
54
55 /*
56 * Same as above but with QArray<int>
57 */
47 QArray<int> categories() const; 58 QArray<int> categories() const;
59
60 /**
61 * The end Date
62 */
48 QDate date()const; 63 QDate date()const;
64
65 /**
66 * The description of the todo
67 */
49 QString description()const; 68 QString description()const;
50 69
70 /**
71 * A small summary of the todo
72 */
73 QString summary() const;
74
75 /**
76 * Return this todoevent in a RichText formatted QString
77 */
51 QString richText() const; 78 QString richText() const;
52 79
80 /**
81 * Returns the UID of the Todo
82 */
53 int uid()const { return m_uid;}; 83 int uid()const { return m_uid;};
84
85
86 QString extra(const QString& )const;
87 /**
88 * Set if this Todo is completed
89 */
54 void setCompleted(bool completed ); 90 void setCompleted(bool completed );
91
92 /**
93 * set if this todo got an end data
94 */
55 void setHasDate( bool hasDate ); 95 void setHasDate( bool hasDate );
56 // if the category doesn't exist we will create it 96 // if the category doesn't exist we will create it
57 // this sets the the Category after this call category will be the only category 97 // this sets the the Category after this call category will be the only category
58 void setCategory( const QString &category ); 98 void setCategory( const QString &category );
59 // adds a category to the Categories of this event 99 // adds a category to the Categories of this event
60 void insertCategory(const QString &category ); 100 void insertCategory(const QString &category );
101
102 /**
103 * Removes this event from all categories
104 */
61 void clearCategories(); 105 void clearCategories();
106
107 /**
108 * This todo belongs to xxx categories
109 */
62 void setCategories(const QStringList& ); 110 void setCategories(const QStringList& );
63 111
112 /**
113 * Set the priority of the Todo
114 */
64 void setPriority(int priority ); 115 void setPriority(int priority );
116
117 /**
118 * set the end date
119 */
65 void setDate( QDate date ); 120 void setDate( QDate date );
66 void setDescription(const QString& ); 121 void setDescription(const QString& );
122 void setSummary(const QString& );
123 void setExtra( const QString&, const QString& );
67 bool isOverdue(); 124 bool isOverdue();
68 125
69 bool match( const QRegExp &r )const; 126 bool match( const QRegExp &r )const;
70 127
71 void setUid(int id) {m_uid = id; }; 128 void setUid(int id) {m_uid = id; };
72 bool operator<(const ToDoEvent &toDoEvent )const; 129 bool operator<(const ToDoEvent &toDoEvent )const;
73 bool operator<=(const ToDoEvent &toDoEvent )const; 130 bool operator<=(const ToDoEvent &toDoEvent )const;
74 bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; 131 bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); };
75 bool operator>(const ToDoEvent &toDoEvent )const; 132 bool operator>(const ToDoEvent &toDoEvent )const;
76 bool operator>=(const ToDoEvent &toDoEvent)const; 133 bool operator>=(const ToDoEvent &toDoEvent)const;
77 bool operator==(const ToDoEvent &toDoEvent )const; 134 bool operator==(const ToDoEvent &toDoEvent )const;
78 ToDoEvent &operator=(const ToDoEvent &toDoEvent ); 135 ToDoEvent &operator=(const ToDoEvent &toDoEvent );
79 private: 136 private:
80 class ToDoEventPrivate; 137 class ToDoEventPrivate;
81 ToDoEventPrivate *d; 138 ToDoEventPrivate *d;
82 QDate m_date; 139 QDate m_date;
83 bool m_isCompleted:1; 140 bool m_isCompleted:1;
84 bool m_hasDate:1; 141 bool m_hasDate:1;
85 int m_priority; 142 int m_priority;
86 QStringList m_category; 143 QStringList m_category;
87 QString m_desc; 144 QString m_desc;
145 QString m_sum;
146 QMap<QString, QString> m_extra;
88 int m_uid; 147 int m_uid;
89}; 148};
90 149
91 150
92#endif 151#endif
diff --git a/libopie/todovcalresource.cpp b/libopie/todovcalresource.cpp
index 75f2197..80f8c60 100644
--- a/libopie/todovcalresource.cpp
+++ b/libopie/todovcalresource.cpp
@@ -1,115 +1,120 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org> 3             .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org>
4           .>+-= the use of vobject was inspired by libkcal 4           .>+-= the use of vobject was inspired by libkcal
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qfile.h> 29#include <qfile.h>
30#include <qvaluelist.h> 30#include <qvaluelist.h>
31#include <opie/todoevent.h> 31#include <opie/todoevent.h>
32#include <opie/todovcalresource.h> 32#include <opie/todovcalresource.h>
33 33
34#include "../library/backend/vobject_p.h" 34#include "../library/backend/vobject_p.h"
35#include "../library/backend/timeconversion.h" 35#include "../library/backend/timeconversion.h"
36#include "../library/backend/qfiledirect_p.h" 36#include "../library/backend/qfiledirect_p.h"
37 37
38static VObject *vobjByEvent( const ToDoEvent &event ) 38static VObject *vobjByEvent( const ToDoEvent &event )
39{ 39{
40 VObject *task = newVObject( VCTodoProp ); 40 VObject *task = newVObject( VCTodoProp );
41 if( task == 0 ) 41 if( task == 0 )
42 return 0l; 42 return 0l;
43 if( event.hasDate() ) 43 if( event.hasDate() )
44 addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) ); 44 addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) );
45 45
46 if( event.isCompleted() ) 46 if( event.isCompleted() )
47 addPropValue( task, VCStatusProp, "COMPLETED"); 47 addPropValue( task, VCStatusProp, "COMPLETED");
48 48
49 QString string = QString::number(event.priority() ); 49 QString string = QString::number(event.priority() );
50 addPropValue( task, VCPriorityProp, string.local8Bit() ); 50 addPropValue( task, VCPriorityProp, string.local8Bit() );
51 addPropValue( task, VCCategoriesProp, event.allCategories().join(";").local8Bit() ); 51 addPropValue( task, VCCategoriesProp, event.allCategories().join(";").local8Bit() );
52 addPropValue( task, VCDescriptionProp, event.description().local8Bit() ); 52 addPropValue( task, VCDescriptionProp, event.description().local8Bit() );
53 addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() ); 53 addPropValue( task, VCSummaryProp, event.summary().left(15).local8Bit() );
54 return task; 54 return task;
55}; 55};
56 56
57static ToDoEvent eventByVObj( VObject *obj ){ 57static ToDoEvent eventByVObj( VObject *obj ){
58 ToDoEvent event; 58 ToDoEvent event;
59 VObject *ob; 59 VObject *ob;
60 QCString name; 60 QCString name;
61 // no uid, attendees, ... and no fun 61 // no uid, attendees, ... and no fun
62 // description 62 // description
63 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ 63 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
64 name = vObjectStringZValue( ob ); 64 name = vObjectStringZValue( ob );
65 event.setDescription( name ); 65 event.setDescription( name );
66 } 66 }
67 // summary
68 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
69 name = vObjectStringZValue( ob );
70 event.setSummary( name );
71 }
67 // completed 72 // completed
68 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ 73 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
69 name = vObjectStringZValue( ob ); 74 name = vObjectStringZValue( ob );
70 if( name == "COMPLETED" ){ 75 if( name == "COMPLETED" ){
71 event.setCompleted( true ); 76 event.setCompleted( true );
72 }else{ 77 }else{
73 event.setCompleted( false ); 78 event.setCompleted( false );
74 } 79 }
75 }else 80 }else
76 event.setCompleted( false ); 81 event.setCompleted( false );
77 // priority 82 // priority
78 if ((ob = isAPropertyOf(obj, VCPriorityProp))) { 83 if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
79 name = vObjectStringZValue( ob ); 84 name = vObjectStringZValue( ob );
80 bool ok; 85 bool ok;
81 event.setPriority(name.toInt(&ok) ); 86 event.setPriority(name.toInt(&ok) );
82 } 87 }
83 //due date 88 //due date
84 if((ob = isAPropertyOf(obj, VCDueProp)) ){ 89 if((ob = isAPropertyOf(obj, VCDueProp)) ){
85 event.setHasDate( true ); 90 event.setHasDate( true );
86 name = vObjectStringZValue( ob ); 91 name = vObjectStringZValue( ob );
87 event.setDate( TimeConversion::fromISO8601( name).date() ); 92 event.setDate( TimeConversion::fromISO8601( name).date() );
88 } 93 }
89 // categories 94 // categories
90 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ 95 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
91 name = vObjectStringZValue( ob ); 96 name = vObjectStringZValue( ob );
92 qWarning("Categories:%s", name.data() ); 97 qWarning("Categories:%s", name.data() );
93 } 98 }
94 99
95 return event; 100 return event;
96}; 101};
97 102
98 103
99QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file) 104QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file)
100{ 105{
101 QValueList<ToDoEvent> events; 106 QValueList<ToDoEvent> events;
102 VObject *vcal = 0l; 107 VObject *vcal = 0l;
103 vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject 108 vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject
104 if(!vcal ) 109 if(!vcal )
105 return events; 110 return events;
106 // start parsing 111 // start parsing
107 112
108 VObjectIterator it; 113 VObjectIterator it;
109 VObject *vobj; 114 VObject *vobj;
110 initPropIterator(&it, vcal); 115 initPropIterator(&it, vcal);
111 116
112 while( moreIteration( &it ) ) { 117 while( moreIteration( &it ) ) {
113 vobj = ::nextVObject( &it ); 118 vobj = ::nextVObject( &it );
114 QCString name = ::vObjectName( vobj ); 119 QCString name = ::vObjectName( vobj );
115 //QCString objVal = ::vObjectStringZValue( vobj ); 120 //QCString objVal = ::vObjectStringZValue( vobj );