otodo.cpp
Go to the documentation of this file.00001
00002 #include <qobject.h>
00003 #include <qshared.h>
00004
00005
00006
00007 #include <qpe/palmtopuidgen.h>
00008 #include <qpe/stringutil.h>
00009 #include <qpe/palmtoprecord.h>
00010 #include <qpe/stringutil.h>
00011 #include <qpe/categories.h>
00012 #include <qpe/categoryselect.h>
00013
00014
00015 #include "opimstate.h"
00016 #include "orecur.h"
00017 #include "opimmaintainer.h"
00018 #include "opimnotifymanager.h"
00019 #include "opimresolver.h"
00020
00021 #include "otodo.h"
00022
00023
00024 struct OTodo::OTodoData : public QShared {
00025 OTodoData() : QShared() {
00026 recur = 0;
00027 state = 0;
00028 maintainer = 0;
00029 notifiers = 0;
00030 };
00031 ~OTodoData() {
00032 delete recur;
00033 delete maintainer;
00034 delete notifiers;
00035 }
00036
00037 QDate date;
00038 bool isCompleted:1;
00039 bool hasDate:1;
00040 int priority;
00041 QString desc;
00042 QString sum;
00043 QMap<QString, QString> extra;
00044 ushort prog;
00045 OPimState *state;
00046 ORecur *recur;
00047 OPimMaintainer *maintainer;
00048 QDate start;
00049 QDate completed;
00050 OPimNotifyManager *notifiers;
00051 };
00052
00053 OTodo::OTodo(const OTodo &event )
00054 : OPimRecord( event ), data( event.data )
00055 {
00056 data->ref();
00057
00058 }
00059 OTodo::~OTodo() {
00060
00061
00062 if ( data->deref() ) {
00063
00064 delete data;
00065 data = 0l;
00066 }
00067 }
00068 OTodo::OTodo(bool completed, int priority,
00069 const QArray<int> &category,
00070 const QString& summary,
00071 const QString &description,
00072 ushort progress,
00073 bool hasDate, QDate date, int uid )
00074 : OPimRecord( uid )
00075 {
00076
00077 setCategories( category );
00078
00079 data = new OTodoData;
00080
00081 data->date = date;
00082 data->isCompleted = completed;
00083 data->hasDate = hasDate;
00084 data->priority = priority;
00085 data->sum = summary;
00086 data->prog = progress;
00087 data->desc = Qtopia::simplifyMultiLineSpace(description );
00088 }
00089 OTodo::OTodo(bool completed, int priority,
00090 const QStringList &category,
00091 const QString& summary,
00092 const QString &description,
00093 ushort progress,
00094 bool hasDate, QDate date, int uid )
00095 : OPimRecord( uid )
00096 {
00097
00098 setCategories( idsFromString( category.join(";") ) );
00099
00100 data = new OTodoData;
00101
00102 data->date = date;
00103 data->isCompleted = completed;
00104 data->hasDate = hasDate;
00105 data->priority = priority;
00106 data->sum = summary;
00107 data->prog = progress;
00108 data->desc = Qtopia::simplifyMultiLineSpace(description );
00109 }
00110 bool OTodo::match( const QRegExp ®Exp )const
00111 {
00112 if( QString::number( data->priority ).find( regExp ) != -1 ){
00113 setLastHitField( Priority );
00114 return true;
00115 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
00116 setLastHitField( HasDate );
00117 return true;
00118 }else if(data->desc.find( regExp ) != -1 ){
00119 setLastHitField( Description );
00120 return true;
00121 }else if(data->sum.find( regExp ) != -1 ) {
00122 setLastHitField( Summary );
00123 return true;
00124 }
00125 return false;
00126 }
00127 bool OTodo::isCompleted() const
00128 {
00129 return data->isCompleted;
00130 }
00131 bool OTodo::hasDueDate() const
00132 {
00133 return data->hasDate;
00134 }
00135 bool OTodo::hasStartDate()const {
00136 return data->start.isValid();
00137 }
00138 bool OTodo::hasCompletedDate()const {
00139 return data->completed.isValid();
00140 }
00141 int OTodo::priority()const
00142 {
00143 return data->priority;
00144 }
00145 QString OTodo::summary() const
00146 {
00147 return data->sum;
00148 }
00149 ushort OTodo::progress() const
00150 {
00151 return data->prog;
00152 }
00153 QDate OTodo::dueDate()const
00154 {
00155 return data->date;
00156 }
00157 QDate OTodo::startDate()const {
00158 return data->start;
00159 }
00160 QDate OTodo::completedDate()const {
00161 return data->completed;
00162 }
00163 QString OTodo::description()const
00164 {
00165 return data->desc;
00166 }
00167 bool OTodo::hasState() const{
00168 if (!data->state ) return false;
00169 return ( data->state->state() != OPimState::Undefined );
00170 }
00171 OPimState OTodo::state()const {
00172 if (!data->state ) {
00173 OPimState state;
00174 return state;
00175 }
00176
00177 return (*data->state);
00178 }
00179 bool OTodo::hasRecurrence()const {
00180 if (!data->recur) return false;
00181 return data->recur->doesRecur();
00182 }
00183 ORecur OTodo::recurrence()const {
00184 if (!data->recur) return ORecur();
00185
00186 return (*data->recur);
00187 }
00188 bool OTodo::hasMaintainer()const {
00189 if (!data->maintainer) return false;
00190
00191 return (data->maintainer->mode() != OPimMaintainer::Undefined );
00192 }
00193 OPimMaintainer OTodo::maintainer()const {
00194 if (!data->maintainer) return OPimMaintainer();
00195
00196 return (*data->maintainer);
00197 }
00198 void OTodo::setCompleted( bool completed )
00199 {
00200 changeOrModify();
00201 data->isCompleted = completed;
00202 }
00203 void OTodo::setHasDueDate( bool hasDate )
00204 {
00205 changeOrModify();
00206 data->hasDate = hasDate;
00207 }
00208 void OTodo::setDescription(const QString &desc )
00209 {
00210
00211 changeOrModify();
00212 data->desc = Qtopia::simplifyMultiLineSpace(desc );
00213 }
00214 void OTodo::setSummary( const QString& sum )
00215 {
00216 changeOrModify();
00217 data->sum = sum;
00218 }
00219 void OTodo::setPriority(int prio )
00220 {
00221 changeOrModify();
00222 data->priority = prio;
00223 }
00224 void OTodo::setDueDate( const QDate& date )
00225 {
00226 changeOrModify();
00227 data->date = date;
00228 }
00229 void OTodo::setStartDate( const QDate& date ) {
00230 changeOrModify();
00231 data->start = date;
00232 }
00233 void OTodo::setCompletedDate( const QDate& date ) {
00234 changeOrModify();
00235 data->completed = date;
00236 }
00237 void OTodo::setState( const OPimState& state ) {
00238 changeOrModify();
00239 if (data->state )
00240 (*data->state) = state;
00241 else
00242 data->state = new OPimState( state );
00243 }
00244 void OTodo::setRecurrence( const ORecur& rec) {
00245 changeOrModify();
00246 if (data->recur )
00247 (*data->recur) = rec;
00248 else
00249 data->recur = new ORecur( rec );
00250 }
00251 void OTodo::setMaintainer( const OPimMaintainer& pim ) {
00252 changeOrModify();
00253
00254 if (data->maintainer )
00255 (*data->maintainer) = pim;
00256 else
00257 data->maintainer = new OPimMaintainer( pim );
00258 }
00259 bool OTodo::isOverdue( )
00260 {
00261 if( data->hasDate && !data->isCompleted)
00262 return QDate::currentDate() > data->date;
00263 return false;
00264 }
00265 void OTodo::setProgress(ushort progress )
00266 {
00267 changeOrModify();
00268 data->prog = progress;
00269 }
00270 QString OTodo::toShortText() const {
00271 return summary();
00272 }
00276 QString OTodo::toRichText() const
00277 {
00278 QString text;
00279 QStringList catlist;
00280
00281
00282 text += "<b><h3><img src=\"todo/TodoList\"> ";
00283 if ( !summary().isEmpty() ) {
00284 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" );
00285 }
00286 text += "</h3></b><br><hr><br>";
00287
00288
00289 if( !description().isEmpty() ){
00290 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
00291 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
00292 }
00293
00294
00295 int priorityval = priority();
00296 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" +
00297 QString::number( priorityval ) + "\"> ";
00298
00299 switch ( priorityval )
00300 {
00301 case 1 : text += QObject::tr( "Very high" );
00302 break;
00303 case 2 : text += QObject::tr( "High" );
00304 break;
00305 case 3 : text += QObject::tr( "Normal" );
00306 break;
00307 case 4 : text += QObject::tr( "Low" );
00308 break;
00309 case 5 : text += QObject::tr( "Very low" );
00310 break;
00311 };
00312 text += "<br>";
00313
00314
00315 text += "<b>" + QObject::tr( "Progress:") + " </b>"
00316 + QString::number( progress() ) + " %<br>";
00317
00318
00319 if (hasDueDate() ){
00320 QDate dd = dueDate();
00321 int off = QDate::currentDate().daysTo( dd );
00322
00323 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
00324 if ( off < 0 )
00325 text += "#FF0000";
00326 else if ( off == 0 )
00327 text += "#FFFF00";
00328 else if ( off > 0 )
00329 text += "#00FF00";
00330
00331 text += "\">" + dd.toString() + "</font><br>";
00332 }
00333
00334
00335 text += "<b>" + QObject::tr( "Category:") + "</b> ";
00336 text += categoryNames( "Todo List" ).join(", ");
00337 text += "<br>";
00338
00339 return text;
00340 }
00341 bool OTodo::hasNotifiers()const {
00342 if (!data->notifiers) return false;
00343 return !data->notifiers->isEmpty();
00344 }
00345 OPimNotifyManager& OTodo::notifiers() {
00346 if (!data->notifiers )
00347 data->notifiers = new OPimNotifyManager;
00348 return (*data->notifiers);
00349 }
00350 const OPimNotifyManager& OTodo::notifiers()const{
00351 if (!data->notifiers )
00352 data->notifiers = new OPimNotifyManager;
00353
00354 return (*data->notifiers);
00355 }
00356
00357 bool OTodo::operator<( const OTodo &toDoEvent )const{
00358 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
00359 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
00360 if( hasDueDate() && toDoEvent.hasDueDate() ){
00361 if( dueDate() == toDoEvent.dueDate() ){
00362 return priority() < toDoEvent.priority();
00363 }else{
00364 return dueDate() < toDoEvent.dueDate();
00365 }
00366 }
00367 return false;
00368 }
00369 bool OTodo::operator<=(const OTodo &toDoEvent )const
00370 {
00371 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
00372 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
00373 if( hasDueDate() && toDoEvent.hasDueDate() ){
00374 if( dueDate() == toDoEvent.dueDate() ){
00375 return priority() <= toDoEvent.priority();
00376 }else{
00377 return dueDate() <= toDoEvent.dueDate();
00378 }
00379 }
00380 return true;
00381 }
00382 bool OTodo::operator>(const OTodo &toDoEvent )const
00383 {
00384 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
00385 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
00386 if( hasDueDate() && toDoEvent.hasDueDate() ){
00387 if( dueDate() == toDoEvent.dueDate() ){
00388 return priority() > toDoEvent.priority();
00389 }else{
00390 return dueDate() > toDoEvent.dueDate();
00391 }
00392 }
00393 return false;
00394 }
00395 bool OTodo::operator>=(const OTodo &toDoEvent )const
00396 {
00397 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
00398 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
00399 if( hasDueDate() && toDoEvent.hasDueDate() ){
00400 if( dueDate() == toDoEvent.dueDate() ){
00401 return priority() > toDoEvent.priority();
00402 }else{
00403 return dueDate() > toDoEvent.dueDate();
00404 }
00405 }
00406 return true;
00407 }
00408 bool OTodo::operator==(const OTodo &toDoEvent )const
00409 {
00410 if ( data->priority != toDoEvent.data->priority ) return false;
00411 if ( data->priority != toDoEvent.data->prog ) return false;
00412 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
00413 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
00414 if ( data->date != toDoEvent.data->date ) return false;
00415 if ( data->sum != toDoEvent.data->sum ) return false;
00416 if ( data->desc != toDoEvent.data->desc ) return false;
00417 if ( data->maintainer != toDoEvent.data->maintainer )
00418 return false;
00419
00420 return OPimRecord::operator==( toDoEvent );
00421 }
00422 void OTodo::deref() {
00423
00424
00425 if ( data->deref() ) {
00426
00427 delete data;
00428 data= 0;
00429 }
00430 }
00431 OTodo &OTodo::operator=(const OTodo &item )
00432 {
00433 if ( this == &item ) return *this;
00434
00435 OPimRecord::operator=( item );
00436
00437 item.data->ref();
00438 deref();
00439 data = item.data;
00440
00441 return *this;
00442 }
00443
00444 QMap<int, QString> OTodo::toMap() const {
00445 QMap<int, QString> map;
00446
00447 map.insert( Uid, QString::number( uid() ) );
00448 map.insert( Category, idsToString( categories() ) );
00449 map.insert( HasDate, QString::number( data->hasDate ) );
00450 map.insert( Completed, QString::number( data->isCompleted ) );
00451 map.insert( Description, data->desc );
00452 map.insert( Summary, data->sum );
00453 map.insert( Priority, QString::number( data->priority ) );
00454 map.insert( DateDay, QString::number( data->date.day() ) );
00455 map.insert( DateMonth, QString::number( data->date.month() ) );
00456 map.insert( DateYear, QString::number( data->date.year() ) );
00457 map.insert( Progress, QString::number( data->prog ) );
00458
00459
00460
00461
00462
00463
00464 return map;
00465 }
00466
00472 void OTodo::changeOrModify() {
00473 if ( data->count != 1 ) {
00474 qWarning("changeOrModify");
00475 data->deref();
00476 OTodoData* d2 = new OTodoData();
00477 copy(data, d2 );
00478 data = d2;
00479 }
00480 }
00481
00482
00483
00484
00485
00486 void OTodo::copy( OTodoData* src, OTodoData* dest ) {
00487 dest->date = src->date;
00488 dest->isCompleted = src->isCompleted;
00489 dest->hasDate = src->hasDate;
00490 dest->priority = src->priority;
00491 dest->desc = src->desc;
00492 dest->sum = src->sum;
00493 dest->extra = src->extra;
00494 dest->prog = src->prog;
00495
00496 if (src->state )
00497 dest->state = new OPimState( *src->state );
00498
00499 if (src->recur )
00500 dest->recur = new ORecur( *src->recur );
00501
00502 if (src->maintainer )
00503 dest->maintainer = new OPimMaintainer( *src->maintainer )
00504 ;
00505 dest->start = src->start;
00506 dest->completed = src->completed;
00507
00508 if (src->notifiers )
00509 dest->notifiers = new OPimNotifyManager( *src->notifiers );
00510 }
00511 QString OTodo::type() const {
00512 return QString::fromLatin1("OTodo");
00513 }
00514 QString OTodo::recordField(int )const {
00515 return QString::null;
00516 }
00517
00518 int OTodo::rtti(){
00519 return OPimResolver::TodoList;
00520 }
This file is part of the documentation for OPIE Version 1.1.