From 911473db35a9fce5f3589f03c27210456faaba86 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Tue, 24 Feb 2004 12:46:23 +0000 Subject: *phew* here is the class and file rename patch. not converted yet: backend, but that will be not visible to application classes so we can change it later. --- (limited to 'libopie2/opiepim/core/opimtodo.cpp') diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp new file mode 100644 index 0000000..34df807 --- a/dev/null +++ b/libopie2/opiepim/core/opimtodo.cpp @@ -0,0 +1,712 @@ +/* + This file is part of the Opie Project + Copyright (C) The Main Author + =. Copyright (C) The Opie Team + .=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_,=:_. -`: 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 "opimtodo.h" + +/* OPIE */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* QT */ +#include +#include + +namespace Opie +{ + +struct OPimTodo::OPimTodoData : public QShared +{ + OPimTodoData() : QShared() + { + recur = 0; + state = 0; + maintainer = 0; + notifiers = 0; + }; + ~OPimTodoData() + { + delete recur; + delete maintainer; + delete notifiers; + } + + QDate date; + bool isCompleted: 1; + bool hasDate: 1; + int priority; + QString desc; + QString sum; + QMap extra; + ushort prog; + OPimState *state; + OPimRecurrence *recur; + OPimMaintainer *maintainer; + QDate start; + QDate completed; + OPimNotifyManager *notifiers; +}; + + +OPimTodo::OPimTodo( const OPimTodo &event ) + : OPimRecord( event ), data( event.data ) +{ + data->ref(); + // qWarning("ref up"); +} + + +OPimTodo::~OPimTodo() +{ + + // qWarning("~OPimTodo " ); + if ( data->deref() ) + { + // qWarning("OPimTodo::dereffing"); + delete data; + data = 0l; + } +} + + +OPimTodo::OPimTodo( bool completed, int priority, + const QArray &category, + const QString& summary, + const QString &description, + ushort progress, + bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) +{ + // qWarning("OPimTodoData " + summary); + setCategories( category ); + + data = new OPimTodoData; + + data->date = date; + data->isCompleted = completed; + data->hasDate = hasDate; + data->priority = priority; + data->sum = summary; + data->prog = progress; + data->desc = Qtopia::simplifyMultiLineSpace( description ); +} + + +OPimTodo::OPimTodo( bool completed, int priority, + const QStringList &category, + const QString& summary, + const QString &description, + ushort progress, + bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) +{ + // qWarning("OPimTodoData" + summary); + setCategories( idsFromString( category.join( ";" ) ) ); + + data = new OPimTodoData; + + data->date = date; + data->isCompleted = completed; + data->hasDate = hasDate; + data->priority = priority; + data->sum = summary; + data->prog = progress; + data->desc = Qtopia::simplifyMultiLineSpace( description ); +} + + +bool OPimTodo::match( const QRegExp ®Exp ) const +{ + if ( QString::number( data->priority ).find( regExp ) != -1 ) + { + setLastHitField( Priority ); + return true; + } + else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) + { + setLastHitField( HasDate ); + return true; + } + else if ( data->desc.find( regExp ) != -1 ) + { + setLastHitField( Description ); + return true; + } + else if ( data->sum.find( regExp ) != -1 ) + { + setLastHitField( Summary ); + return true; + } + return false; +} + + +bool OPimTodo::isCompleted() const +{ + return data->isCompleted; +} + + +bool OPimTodo::hasDueDate() const +{ + return data->hasDate; +} + + +bool OPimTodo::hasStartDate() const +{ + return data->start.isValid(); +} + + +bool OPimTodo::hasCompletedDate() const +{ + return data->completed.isValid(); +} + + +int OPimTodo::priority() const +{ + return data->priority; +} + + +QString OPimTodo::summary() const +{ + return data->sum; +} + + +ushort OPimTodo::progress() const +{ + return data->prog; +} + + +QDate OPimTodo::dueDate() const +{ + return data->date; +} + + +QDate OPimTodo::startDate() const +{ + return data->start; +} + + +QDate OPimTodo::completedDate() const +{ + return data->completed; +} + + +QString OPimTodo::description() const +{ + return data->desc; +} + + +bool OPimTodo::hasState() const +{ + if ( !data->state ) return false; + return ( data->state->state() != OPimState::Undefined ); +} + + +OPimState OPimTodo::state() const +{ + if ( !data->state ) + { + OPimState state; + return state; + } + + return ( *data->state ); +} + + +bool OPimTodo::hasRecurrence() const +{ + if ( !data->recur ) return false; + return data->recur->doesRecur(); +} + + +OPimRecurrence OPimTodo::recurrence() const +{ + if ( !data->recur ) return OPimRecurrence(); + + return ( *data->recur ); +} + + +bool OPimTodo::hasMaintainer() const +{ + if ( !data->maintainer ) return false; + + return ( data->maintainer->mode() != OPimMaintainer::Undefined ); +} + + +OPimMaintainer OPimTodo::maintainer() const +{ + if ( !data->maintainer ) return OPimMaintainer(); + + return ( *data->maintainer ); +} + + +void OPimTodo::setCompleted( bool completed ) +{ + changeOrModify(); + data->isCompleted = completed; +} + + +void OPimTodo::setHasDueDate( bool hasDate ) +{ + changeOrModify(); + data->hasDate = hasDate; +} + + +void OPimTodo::setDescription( const QString &desc ) +{ + // qWarning( "desc " + desc ); + changeOrModify(); + data->desc = Qtopia::simplifyMultiLineSpace( desc ); +} + + +void OPimTodo::setSummary( const QString& sum ) +{ + changeOrModify(); + data->sum = sum; +} + + +void OPimTodo::setPriority( int prio ) +{ + changeOrModify(); + data->priority = prio; +} + + +void OPimTodo::setDueDate( const QDate& date ) +{ + changeOrModify(); + data->date = date; +} + + +void OPimTodo::setStartDate( const QDate& date ) +{ + changeOrModify(); + data->start = date; +} + + +void OPimTodo::setCompletedDate( const QDate& date ) +{ + changeOrModify(); + data->completed = date; +} + + +void OPimTodo::setState( const OPimState& state ) +{ + changeOrModify(); + if ( data->state ) + ( *data->state ) = state; + else + data->state = new OPimState( state ); +} + + +void OPimTodo::setRecurrence( const OPimRecurrence& rec ) +{ + changeOrModify(); + if ( data->recur ) + ( *data->recur ) = rec; + else + data->recur = new OPimRecurrence( rec ); +} + + +void OPimTodo::setMaintainer( const OPimMaintainer& pim ) +{ + changeOrModify(); + + if ( data->maintainer ) + ( *data->maintainer ) = pim; + else + data->maintainer = new OPimMaintainer( pim ); +} + + +bool OPimTodo::isOverdue( ) +{ + if ( data->hasDate && !data->isCompleted ) + return QDate::currentDate() > data->date; + return false; +} + + +void OPimTodo::setProgress( ushort progress ) +{ + changeOrModify(); + data->prog = progress; +} + + +QString OPimTodo::toShortText() const +{ + return summary(); +} + + +/*! + Returns a richt text string +*/ +QString OPimTodo::toRichText() const +{ + QString text; + QStringList catlist; + + // summary + text += "

"; + if ( !summary().isEmpty() ) + { + text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); + } + text += "




"; + + // description + if ( !description().isEmpty() ) + { + text += "" + QObject::tr( "Description:" ) + "
"; + text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "
" ) + "
"; + } + + // priority + int priorityval = priority(); + text += "" + QObject::tr( "Priority:" ) + " "; + + switch ( priorityval ) + { + case 1 : text += QObject::tr( "Very high" ); + break; + case 2 : text += QObject::tr( "High" ); + break; + case 3 : text += QObject::tr( "Normal" ); + break; + case 4 : text += QObject::tr( "Low" ); + break; + case 5 : text += QObject::tr( "Very low" ); + break; + }; + text += "
"; + + // progress + text += "" + QObject::tr( "Progress:" ) + " " + + QString::number( progress() ) + " %
"; + + // due date + if ( hasDueDate() ) + { + QDate dd = dueDate(); + int off = QDate::currentDate().daysTo( dd ); + + text += "" + QObject::tr( "Deadline:" ) + " 0 ) + text += "#00FF00"; + + text += "\">" + dd.toString() + "
"; + } + + // categories + text += "" + QObject::tr( "Category:" ) + " "; + text += categoryNames( "Todo List" ).join( ", " ); + text += "
"; + + return text; +} + + +bool OPimTodo::hasNotifiers() const +{ + if ( !data->notifiers ) return false; + return !data->notifiers->isEmpty(); +} + + +OPimNotifyManager& OPimTodo::notifiers() +{ + if ( !data->notifiers ) + data->notifiers = new OPimNotifyManager; + return ( *data->notifiers ); +} + + +const OPimNotifyManager& OPimTodo::notifiers() const +{ + if ( !data->notifiers ) + data->notifiers = new OPimNotifyManager; + + return ( *data->notifiers ); +} + + +bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() < toDoEvent.priority(); + } + else + { + return dueDate() < toDoEvent.dueDate(); + } + } + return false; +} + + +bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() <= toDoEvent.priority(); + } + else + { + return dueDate() <= toDoEvent.dueDate(); + } + } + return true; +} + + +bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() > toDoEvent.priority(); + } + else + { + return dueDate() > toDoEvent.dueDate(); + } + } + return false; +} + + +bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() > toDoEvent.priority(); + } + else + { + return dueDate() > toDoEvent.dueDate(); + } + } + return true; +} + + +bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const +{ + if ( data->priority != toDoEvent.data->priority ) return false; + if ( data->priority != toDoEvent.data->prog ) return false; + if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; + if ( data->hasDate != toDoEvent.data->hasDate ) return false; + if ( data->date != toDoEvent.data->date ) return false; + if ( data->sum != toDoEvent.data->sum ) return false; + if ( data->desc != toDoEvent.data->desc ) return false; + if ( data->maintainer != toDoEvent.data->maintainer ) + return false; + + return OPimRecord::operator==( toDoEvent ); +} + + +void OPimTodo::deref() +{ + + // qWarning("deref in ToDoEvent"); + if ( data->deref() ) + { + // qWarning("deleting"); + delete data; + data = 0; + } +} + + +OPimTodo &OPimTodo::operator=( const OPimTodo &item ) +{ + if ( this == &item ) return * this; + + OPimRecord::operator=( item ); + //qWarning("operator= ref "); + item.data->ref(); + deref(); + data = item.data; + + return *this; +} + + +QMap OPimTodo::toMap() const +{ + QMap map; + + map.insert( Uid, QString::number( uid() ) ); + map.insert( Category, idsToString( categories() ) ); + map.insert( HasDate, QString::number( data->hasDate ) ); + map.insert( Completed, QString::number( data->isCompleted ) ); + map.insert( Description, data->desc ); + map.insert( Summary, data->sum ); + map.insert( Priority, QString::number( data->priority ) ); + map.insert( DateDay, QString::number( data->date.day() ) ); + map.insert( DateMonth, QString::number( data->date.month() ) ); + map.insert( DateYear, QString::number( data->date.year() ) ); + map.insert( Progress, QString::number( data->prog ) ); + // map.insert( CrossReference, crossToString() ); + /* FIXME!!! map.insert( State, ); + map.insert( Recurrence, ); + map.insert( Reminders, ); + map. + */ + return map; +} + + +/** + * change or modify looks at the ref count and either + * creates a new QShared Object or it can modify it + * right in place + */ +void OPimTodo::changeOrModify() +{ + if ( data->count != 1 ) + { + qWarning( "changeOrModify" ); + data->deref(); + OPimTodoData* d2 = new OPimTodoData(); + copy( data, d2 ); + data = d2; + } +} + + +// WATCHOUT +/* + * if you add something to the Data struct + * be sure to copy it here + */ +void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) +{ + dest->date = src->date; + dest->isCompleted = src->isCompleted; + dest->hasDate = src->hasDate; + dest->priority = src->priority; + dest->desc = src->desc; + dest->sum = src->sum; + dest->extra = src->extra; + dest->prog = src->prog; + + if ( src->state ) + dest->state = new OPimState( *src->state ); + + if ( src->recur ) + dest->recur = new OPimRecurrence( *src->recur ); + + if ( src->maintainer ) + dest->maintainer = new OPimMaintainer( *src->maintainer ) + ; + dest->start = src->start; + dest->completed = src->completed; + + if ( src->notifiers ) + dest->notifiers = new OPimNotifyManager( *src->notifiers ); +} + + +QString OPimTodo::type() const +{ + return QString::fromLatin1( "OPimTodo" ); +} + + +QString OPimTodo::recordField( int /*id*/ ) const +{ + return QString::null; +} + + +int OPimTodo::rtti() +{ + return OPimResolver::TodoList; +} + +} -- cgit v0.9.0.2