00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <opie2/otodoaccessbackend.h>
00031 #include <opie2/private/opimtodosortvector.h>
00032 #include <opie2/otodoaccess.h>
00033
00034 #include <qintdict.h>
00035
00036 namespace Opie {
00037 OPimTodoAccessBackend::OPimTodoAccessBackend()
00038 : OPimAccessBackend<OPimTodo>()
00039 {
00040 }
00041 OPimTodoAccessBackend::~OPimTodoAccessBackend() {
00042
00043 }
00044
00045 const uint OPimTodoAccessBackend::querySettings() const
00046 {
00047 return 0;
00048 }
00049
00050 bool OPimTodoAccessBackend::hasQuerySettings (uint querySettings) const
00051 {
00052 return false;
00053 }
00054
00055
00056 UIDArray OPimTodoAccessBackend::queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings,
00057 const QDateTime& startperiod )const
00058 {
00059 qDebug( "Accessing OPimTodoAccessBackend::queryByExample() which is not implemented!" );
00060 return UIDArray();
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 }
00075
00076 UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc,
00077 int sortOrder, int sortFilter,
00078 const QArray<int>& categories )const {
00079 odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl;
00080 Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
00081 int item = 0;
00082
00083 bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false;
00084 bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
00085 bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false;
00086 bool catPassed = false;
00087 int cat;
00088
00089 for ( uint i = 0; i < events.count(); ++i ) {
00090 OPimTodo todo = find( events[i], events, i, Frontend::Forward );
00091 if ( todo.isEmpty() )
00092 continue;
00093
00094
00095
00096 catPassed = false;
00097 for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
00098 cat = categories[cat_nu];
00099 if ( bCat && cat == -1 ) {
00100 if(!todo.categories().isEmpty() )
00101 continue;
00102 } else if ( bCat && cat != 0)
00103 if (!todo.categories().contains( cat ) )
00104 continue;
00105 catPassed = true;
00106 break;
00107 }
00108
00109
00110
00111
00112
00113 if ( !catPassed )
00114 continue;
00115 if ( !todo.isOverdue() && bOnly )
00116 continue;
00117 if (todo.isCompleted() && comp )
00118 continue;
00119
00120 vector.insert(item++, todo );
00121 }
00122
00123 vector.resize( item );
00124
00125 vector.sort();
00126
00127 UIDArray array( vector.count() );
00128 for (uint i= 0; i < vector.count(); i++ )
00129 array[i] = vector.uidAt( i );
00130
00131 return array;
00132 }
00133
00134 OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start,
00135 const QDate& end )const {
00136 OPimBackendOccurrence::List lst;
00137 UIDArray effective = effectiveToDos( start, end, false );
00138 UIDArray overdue = overDue();
00139 uint count = effective.count();
00140 int uid;
00141 QIntDict<int> hash;
00142 hash.setAutoDelete( true );
00143 OPimTodo todo;
00144
00145 for ( uint i = 0; i < count; ++i ) {
00146 uid = effective[i];
00147 todo = find( uid, effective, i, Frontend::Forward );
00148
00149
00150
00151
00152 if ( todo.isOverdue() )
00153 hash.insert( uid, new int(6) );
00154 OPimBackendOccurrence oc = todo.hasStartDate() ?
00155 OPimBackendOccurrence( todo.startDate(),
00156 todo.dueDate(), uid ) :
00157 OPimBackendOccurrence( todo.dueDate(), uid, QString::null );
00158 oc.setSummary( todo.summary() );
00159 lst.append( oc );
00160 }
00161
00162
00163
00164
00165
00166 if ( !overdue.isEmpty() ) {
00167 QDate today = QDate::currentDate();
00168 QDate dueDate = (start >= today && today <= end ) ? today : start;
00169 count = overdue.count();
00170 for ( uint i = 0; i < count; ++i ) {
00171 uid = overdue[i];
00172 if (!hash.find( uid ) )
00173 continue;
00174 todo = find( uid, overdue, i, Frontend::Forward );
00175 lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) );
00176 }
00177 }
00178
00179 return lst;
00180 }
00181 }