summaryrefslogtreecommitdiff
path: root/libopie/pim/otodo.cpp
Unidiff
Diffstat (limited to 'libopie/pim/otodo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/otodo.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index 38b93f7..5a18c37 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,126 +1,131 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h" 19#include "opimresolver.h"
20 20
21#include "otodo.h" 21#include "otodo.h"
22 22
23 23
24struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
25 OTodoData() : QShared() { 25 OTodoData() : QShared() {
26 recur = 0; 26 recur = 0;
27 state = 0; 27 state = 0;
28 maintainer = 0; 28 maintainer = 0;
29 notifiers = 0; 29 notifiers = 0;
30 }; 30 };
31 ~OTodoData() {
32 delete recur;
33 delete maintainer;
34 delete notifiers;
35 }
31 36
32 QDate date; 37 QDate date;
33 bool isCompleted:1; 38 bool isCompleted:1;
34 bool hasDate:1; 39 bool hasDate:1;
35 int priority; 40 int priority;
36 QString desc; 41 QString desc;
37 QString sum; 42 QString sum;
38 QMap<QString, QString> extra; 43 QMap<QString, QString> extra;
39 ushort prog; 44 ushort prog;
40 OPimState *state; 45 OPimState *state;
41 ORecur *recur; 46 ORecur *recur;
42 OPimMaintainer *maintainer; 47 OPimMaintainer *maintainer;
43 QDate start; 48 QDate start;
44 QDate completed; 49 QDate completed;
45 OPimNotifyManager *notifiers; 50 OPimNotifyManager *notifiers;
46}; 51};
47 52
48OTodo::OTodo(const OTodo &event ) 53OTodo::OTodo(const OTodo &event )
49 : OPimRecord( event ), data( event.data ) 54 : OPimRecord( event ), data( event.data )
50{ 55{
51 data->ref(); 56 data->ref();
52// qWarning("ref up"); 57// qWarning("ref up");
53} 58}
54OTodo::~OTodo() { 59OTodo::~OTodo() {
55 60
56// qWarning("~OTodo " ); 61// qWarning("~OTodo " );
57 if ( data->deref() ) { 62 if ( data->deref() ) {
58// qWarning("OTodo::dereffing"); 63// qWarning("OTodo::dereffing");
59 delete data; 64 delete data;
60 data = 0l; 65 data = 0l;
61 } 66 }
62} 67}
63OTodo::OTodo(bool completed, int priority, 68OTodo::OTodo(bool completed, int priority,
64 const QArray<int> &category, 69 const QArray<int> &category,
65 const QString& summary, 70 const QString& summary,
66 const QString &description, 71 const QString &description,
67 ushort progress, 72 ushort progress,
68 bool hasDate, QDate date, int uid ) 73 bool hasDate, QDate date, int uid )
69 : OPimRecord( uid ) 74 : OPimRecord( uid )
70{ 75{
71// qWarning("OTodoData " + summary); 76// qWarning("OTodoData " + summary);
72 setCategories( category ); 77 setCategories( category );
73 78
74 data = new OTodoData; 79 data = new OTodoData;
75 80
76 data->date = date; 81 data->date = date;
77 data->isCompleted = completed; 82 data->isCompleted = completed;
78 data->hasDate = hasDate; 83 data->hasDate = hasDate;
79 data->priority = priority; 84 data->priority = priority;
80 data->sum = summary; 85 data->sum = summary;
81 data->prog = progress; 86 data->prog = progress;
82 data->desc = Qtopia::simplifyMultiLineSpace(description ); 87 data->desc = Qtopia::simplifyMultiLineSpace(description );
83} 88}
84OTodo::OTodo(bool completed, int priority, 89OTodo::OTodo(bool completed, int priority,
85 const QStringList &category, 90 const QStringList &category,
86 const QString& summary, 91 const QString& summary,
87 const QString &description, 92 const QString &description,
88 ushort progress, 93 ushort progress,
89 bool hasDate, QDate date, int uid ) 94 bool hasDate, QDate date, int uid )
90 : OPimRecord( uid ) 95 : OPimRecord( uid )
91{ 96{
92// qWarning("OTodoData" + summary); 97// qWarning("OTodoData" + summary);
93 setCategories( idsFromString( category.join(";") ) ); 98 setCategories( idsFromString( category.join(";") ) );
94 99
95 data = new OTodoData; 100 data = new OTodoData;
96 101
97 data->date = date; 102 data->date = date;
98 data->isCompleted = completed; 103 data->isCompleted = completed;
99 data->hasDate = hasDate; 104 data->hasDate = hasDate;
100 data->priority = priority; 105 data->priority = priority;
101 data->sum = summary; 106 data->sum = summary;
102 data->prog = progress; 107 data->prog = progress;
103 data->desc = Qtopia::simplifyMultiLineSpace(description ); 108 data->desc = Qtopia::simplifyMultiLineSpace(description );
104} 109}
105bool OTodo::match( const QRegExp &regExp )const 110bool OTodo::match( const QRegExp &regExp )const
106{ 111{
107 if( QString::number( data->priority ).find( regExp ) != -1 ){ 112 if( QString::number( data->priority ).find( regExp ) != -1 ){
108 setLastHitField( Priority ); 113 setLastHitField( Priority );
109 return true; 114 return true;
110 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 115 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
111 setLastHitField( HasDate ); 116 setLastHitField( HasDate );
112 return true; 117 return true;
113 }else if(data->desc.find( regExp ) != -1 ){ 118 }else if(data->desc.find( regExp ) != -1 ){
114 setLastHitField( Description ); 119 setLastHitField( Description );
115 return true; 120 return true;
116 }else if(data->sum.find( regExp ) != -1 ) { 121 }else if(data->sum.find( regExp ) != -1 ) {
117 setLastHitField( Summary ); 122 setLastHitField( Summary );
118 return true; 123 return true;
119 } 124 }
120 return false; 125 return false;
121} 126}
122bool OTodo::isCompleted() const 127bool OTodo::isCompleted() const
123{ 128{
124 return data->isCompleted; 129 return data->isCompleted;
125} 130}
126bool OTodo::hasDueDate() const 131bool OTodo::hasDueDate() const
@@ -181,210 +186,209 @@ ORecur OTodo::recurrence()const {
181 return (*data->recur); 186 return (*data->recur);
182} 187}
183bool OTodo::hasMaintainer()const { 188bool OTodo::hasMaintainer()const {
184 if (!data->maintainer) return false; 189 if (!data->maintainer) return false;
185 190
186 return (data->maintainer->mode() != OPimMaintainer::Undefined ); 191 return (data->maintainer->mode() != OPimMaintainer::Undefined );
187} 192}
188OPimMaintainer OTodo::maintainer()const { 193OPimMaintainer OTodo::maintainer()const {
189 if (!data->maintainer) return OPimMaintainer(); 194 if (!data->maintainer) return OPimMaintainer();
190 195
191 return (*data->maintainer); 196 return (*data->maintainer);
192} 197}
193void OTodo::setCompleted( bool completed ) 198void OTodo::setCompleted( bool completed )
194{ 199{
195 changeOrModify(); 200 changeOrModify();
196 data->isCompleted = completed; 201 data->isCompleted = completed;
197} 202}
198void OTodo::setHasDueDate( bool hasDate ) 203void OTodo::setHasDueDate( bool hasDate )
199{ 204{
200 changeOrModify(); 205 changeOrModify();
201 data->hasDate = hasDate; 206 data->hasDate = hasDate;
202} 207}
203void OTodo::setDescription(const QString &desc ) 208void OTodo::setDescription(const QString &desc )
204{ 209{
205// qWarning( "desc " + desc ); 210// qWarning( "desc " + desc );
206 changeOrModify(); 211 changeOrModify();
207 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 212 data->desc = Qtopia::simplifyMultiLineSpace(desc );
208} 213}
209void OTodo::setSummary( const QString& sum ) 214void OTodo::setSummary( const QString& sum )
210{ 215{
211 changeOrModify(); 216 changeOrModify();
212 data->sum = sum; 217 data->sum = sum;
213} 218}
214void OTodo::setPriority(int prio ) 219void OTodo::setPriority(int prio )
215{ 220{
216 changeOrModify(); 221 changeOrModify();
217 data->priority = prio; 222 data->priority = prio;
218} 223}
219void OTodo::setDueDate( const QDate& date ) 224void OTodo::setDueDate( const QDate& date )
220{ 225{
221 changeOrModify(); 226 changeOrModify();
222 data->date = date; 227 data->date = date;
223} 228}
224void OTodo::setStartDate( const QDate& date ) { 229void OTodo::setStartDate( const QDate& date ) {
225 changeOrModify(); 230 changeOrModify();
226 data->start = date; 231 data->start = date;
227} 232}
228void OTodo::setCompletedDate( const QDate& date ) { 233void OTodo::setCompletedDate( const QDate& date ) {
229 changeOrModify(); 234 changeOrModify();
230 data->completed = date; 235 data->completed = date;
231} 236}
232void OTodo::setState( const OPimState& state ) { 237void OTodo::setState( const OPimState& state ) {
233 changeOrModify(); 238 changeOrModify();
234 if (data->state ) 239 if (data->state )
235 (*data->state) = state; 240 (*data->state) = state;
236 else 241 else
237 data->state = new OPimState( state ); 242 data->state = new OPimState( state );
238} 243}
239void OTodo::setRecurrence( const ORecur& rec) { 244void OTodo::setRecurrence( const ORecur& rec) {
240 changeOrModify(); 245 changeOrModify();
241 if (data->recur ) 246 if (data->recur )
242 (*data->recur) = rec; 247 (*data->recur) = rec;
243 else 248 else
244 data->recur = new ORecur( rec ); 249 data->recur = new ORecur( rec );
245} 250}
246void OTodo::setMaintainer( const OPimMaintainer& pim ) { 251void OTodo::setMaintainer( const OPimMaintainer& pim ) {
247 changeOrModify(); 252 changeOrModify();
248 253
249 if (data->maintainer ) 254 if (data->maintainer )
250 (*data->maintainer) = pim; 255 (*data->maintainer) = pim;
251 else 256 else
252 data->maintainer = new OPimMaintainer( pim ); 257 data->maintainer = new OPimMaintainer( pim );
253} 258}
254bool OTodo::isOverdue( ) 259bool OTodo::isOverdue( )
255{ 260{
256 if( data->hasDate && !data->isCompleted) 261 if( data->hasDate && !data->isCompleted)
257 return QDate::currentDate() > data->date; 262 return QDate::currentDate() > data->date;
258 return false; 263 return false;
259} 264}
260void OTodo::setProgress(ushort progress ) 265void OTodo::setProgress(ushort progress )
261{ 266{
262 changeOrModify(); 267 changeOrModify();
263 data->prog = progress; 268 data->prog = progress;
264} 269}
265QString OTodo::toShortText() const { 270QString OTodo::toShortText() const {
266 return summary(); 271 return summary();
267} 272}
268/*! 273/*!
269 Returns a richt text string 274 Returns a richt text string
270*/ 275*/
271QString OTodo::toRichText() const 276QString OTodo::toRichText() const
272{ 277{
273 QString text; 278 QString text;
274 QStringList catlist; 279 QStringList catlist;
275 280
276 // summary 281 // summary
277 text += "<b><h3><img src=\"todo/TodoList\">"; 282 text += "<b><h3><img src=\"todo/TodoList\"> ";
278 if ( !summary().isEmpty() ) { 283 if ( !summary().isEmpty() ) {
279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); 284 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" );
280 } 285 }
281 text += "</h3></b><br><hr><br>"; 286 text += "</h3></b><br><hr><br>";
282 287
283 // description 288 // description
284 if( !description().isEmpty() ){ 289 if( !description().isEmpty() ){
285 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 290 text += "<b>" + QObject::tr( "Notes:" ) + "</b><br>";
286 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 291 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
287 } 292 }
288 293
289 // priority 294 // priority
290 int priorityval = priority(); 295 int priorityval = priority();
291 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + 296 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" +
292 QString::number( priorityval ) + "\">"; 297 QString::number( priorityval ) + "\"> ";
293// text += "<b>" + QObject::tr( "Priority:") +"</b><img src=\"todo/priority" + 298
294// QString::number( priority() ) + "\"><br>";
295 switch ( priorityval ) 299 switch ( priorityval )
296 { 300 {
297 case 1 : text += QObject::tr( "Very high" ); 301 case 1 : text += QObject::tr( "Very high" );
298 break; 302 break;
299 case 2 : text += QObject::tr( "High" ); 303 case 2 : text += QObject::tr( "High" );
300 break; 304 break;
301 case 3 : text += QObject::tr( "Normal" ); 305 case 3 : text += QObject::tr( "Normal" );
302 break; 306 break;
303 case 4 : text += QObject::tr( "Low" ); 307 case 4 : text += QObject::tr( "Low" );
304 break; 308 break;
305 case 5 : text += QObject::tr( "Very low" ); 309 case 5 : text += QObject::tr( "Very low" );
306 break; 310 break;
307 }; 311 };
308 text += "<br>"; 312 text += "<br>";
309 313
310 // progress 314 // progress
311 text += "<b>" + QObject::tr( "Progress:") + " </b>" 315 text += "<b>" + QObject::tr( "Progress:") + " </b>"
312 + QString::number( progress() ) + " %<br>"; 316 + QString::number( progress() ) + " %<br>";
313 317
314 // due date 318 // due date
315 if (hasDueDate() ){ 319 if (hasDueDate() ){
316 QDate dd = dueDate(); 320 QDate dd = dueDate();
317 int off = QDate::currentDate().daysTo( dd ); 321 int off = QDate::currentDate().daysTo( dd );
318 322
319 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 323 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
320 if ( off < 0 ) 324 if ( off < 0 )
321 text += "#FF0000"; 325 text += "#FF0000";
322 else if ( off == 0 ) 326 else if ( off == 0 )
323 text += "#FFFF00"; 327 text += "#FFFF00";
324 else if ( off > 0 ) 328 else if ( off > 0 )
325 text += "#00FF00"; 329 text += "#00FF00";
326 330
327 text += "\">" + dd.toString() + "</font><br>"; 331 text += "\">" + dd.toString() + "</font><br>";
328 } 332 }
329 333
330 // categories 334 // categories
331 text += "<b>" + QObject::tr( "Category:") + "</b> "; 335 text += "<b>" + QObject::tr( "Category:") + "</b> ";
332 text += categoryNames( "Todo List" ).join(", "); 336 text += categoryNames( "Todo List" ).join(", ");
333 text += "<br>"; 337 text += "<br>";
334 338
335 return text; 339 return text;
336} 340}
337bool OTodo::hasNotifiers()const { 341bool OTodo::hasNotifiers()const {
338 if (!data->notifiers) return false; 342 if (!data->notifiers) return false;
339 return !data->notifiers->isEmpty(); 343 return !data->notifiers->isEmpty();
340} 344}
341OPimNotifyManager& OTodo::notifiers() { 345OPimNotifyManager& OTodo::notifiers() {
342 if (!data->notifiers ) 346 if (!data->notifiers )
343 data->notifiers = new OPimNotifyManager; 347 data->notifiers = new OPimNotifyManager;
344 return (*data->notifiers); 348 return (*data->notifiers);
345} 349}
346const OPimNotifyManager& OTodo::notifiers()const{ 350const OPimNotifyManager& OTodo::notifiers()const{
347 if (!data->notifiers ) 351 if (!data->notifiers )
348 data->notifiers = new OPimNotifyManager; 352 data->notifiers = new OPimNotifyManager;
349 353
350 return (*data->notifiers); 354 return (*data->notifiers);
351} 355}
352 356
353bool OTodo::operator<( const OTodo &toDoEvent )const{ 357bool OTodo::operator<( const OTodo &toDoEvent )const{
354 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 358 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
355 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 359 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
356 if( hasDueDate() && toDoEvent.hasDueDate() ){ 360 if( hasDueDate() && toDoEvent.hasDueDate() ){
357 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 361 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
358 return priority() < toDoEvent.priority(); 362 return priority() < toDoEvent.priority();
359 }else{ 363 }else{
360 return dueDate() < toDoEvent.dueDate(); 364 return dueDate() < toDoEvent.dueDate();
361 } 365 }
362 } 366 }
363 return false; 367 return false;
364} 368}
365bool OTodo::operator<=(const OTodo &toDoEvent )const 369bool OTodo::operator<=(const OTodo &toDoEvent )const
366{ 370{
367 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 371 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
368 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 372 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
369 if( hasDueDate() && toDoEvent.hasDueDate() ){ 373 if( hasDueDate() && toDoEvent.hasDueDate() ){
370 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 374 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
371 return priority() <= toDoEvent.priority(); 375 return priority() <= toDoEvent.priority();
372 }else{ 376 }else{
373 return dueDate() <= toDoEvent.dueDate(); 377 return dueDate() <= toDoEvent.dueDate();
374 } 378 }
375 } 379 }
376 return true; 380 return true;
377} 381}
378bool OTodo::operator>(const OTodo &toDoEvent )const 382bool OTodo::operator>(const OTodo &toDoEvent )const
379{ 383{
380 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 384 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
381 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 385 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
382 if( hasDueDate() && toDoEvent.hasDueDate() ){ 386 if( hasDueDate() && toDoEvent.hasDueDate() ){
383 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 387 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
384 return priority() > toDoEvent.priority(); 388 return priority() > toDoEvent.priority();
385 }else{ 389 }else{
386 return dueDate() > toDoEvent.dueDate(); 390 return dueDate() > toDoEvent.dueDate();
387 } 391 }
388 } 392 }
389 return false; 393 return false;
390} 394}