Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

otodoaccessbackend.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) The Main Author <main-author@whereever.org>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
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 //     odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl;
00063 
00064 //     UIDArray m_currentQuery( uid_array.count() );
00065 //     uint arraycounter = 0;
00066 
00067 //     for( uint it = 0; it < uid_array.count(); ++it ){
00068 //          /* Search all fields and compare them with query object. Store them into list
00069 //           * if all fields matches.
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         /* show category */
00095         /* -1 == unfiled */
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          * If none of the Categories matched
00111          * continue
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     /* sort it now */
00125     vector.sort();
00126     /* now get the uids */
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          * If isOverdue but in the 'normal' range we will fill
00150          * the hash so we won't have duplicates in OPimBackendOccurrence
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      * Create the OverDue items but skip
00164      * the already handled Records
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 }

Generated on Sat Nov 5 16:16:16 2005 for OPIE by  doxygen 1.4.2