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

opimeventsortvector.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net>
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 "opimeventsortvector.h"
00031 #include <opie2/ocontactaccess.h>
00032 #include <opie2/opimnotifymanager.h>
00033 #include <opie2/odatebookaccess.h>
00034 
00035 #include <qvaluelist.h>
00036 
00037 namespace Opie {
00038 namespace Internal {
00039 
00040 namespace{
00041 
00042 inline int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){
00043         OPimNotifyManager::Alarms left_alarms = leftnotifiers.alarms();
00044         OPimNotifyManager::Alarms right_alarms = rightnotifiers.alarms();
00045         
00046         // Well.. How could we compare two lists of alarms? I think we should find the most early datetimes
00047         // and compare them.. (se)
00048         // Find the first alarm of the left list
00049         OPimNotifyManager::Alarms::Iterator it;
00050         QDateTime left_earliest; // This datetime is initialized as invalid!!
00051         for ( it = left_alarms.begin(); it != left_alarms.end(); ++it ){
00052                 if ( !left_earliest.isValid() || left_earliest > (*it).dateTime() ){
00053                         left_earliest = (*it).dateTime();
00054                 }
00055         }
00056         QDateTime right_earliest; // This datetime is initialized as invalid!!
00057         for ( it = right_alarms.begin(); it != right_alarms.end(); ++it ){
00058                 if ( !right_earliest.isValid() || right_earliest > (*it).dateTime() ){
00059                         right_earliest = (*it).dateTime();
00060                 }
00061         }
00062         
00063         int ret;
00064         
00065         // Now compare this found alarms
00066         if ( !left_earliest .isValid() ) ret++;
00067         if ( !right_earliest.isValid() ) ret--;
00068         
00069         if ( left_earliest.isValid() && right_earliest.isValid() ){
00070                 ret += left_earliest < right_earliest ? -1 : 1;    
00071         }
00072         
00073         return ret;
00074         
00075 }
00076 }
00077 
00078 OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort )
00079     : OPimSortVector<OPimEvent>( size, asc, sort ) {}
00080 
00081 int OPimEventSortVector::compareItems( const OPimEvent& left,
00082                                          const OPimEvent& right ) {
00083     if ( left.uid() == right.uid() )
00084         return 0;
00085 
00086     int ret = 0;
00087     bool asc = sortAscending();
00088 
00089     switch( sortOrder() ) {
00090     case ODateBookAccess::SortDescription:
00091         ret = testString( left.description(), right.description() );
00092         break;
00093     case ODateBookAccess::SortLocation:
00094         ret = testString( left.location(), right.location() );
00095         break;
00096     case ODateBookAccess::SortNote:
00097         ret = testString( left.note(),right.note() );
00098         break;
00099     case ODateBookAccess::SortStartTime:
00100             ret = testTime( left.startDateTime().time(), right.startDateTime().time() );
00101         break;
00102     case ODateBookAccess::SortEndTime:
00103             ret = testTime( left.endDateTime().time(), right.endDateTime().time() );
00104         break;
00105     case ODateBookAccess::SortStartDate:
00106             ret = testDate( left.startDateTime().date(), right.startDateTime().date() );
00107         break;
00108     case ODateBookAccess::SortEndDate:
00109             ret = testDate( left.endDateTime().date(), right.endDateTime().date() );
00110         break;
00111     case ODateBookAccess::SortStartDateTime:
00112             ret = testDateTime( left.startDateTime(), right.startDateTime() );
00113         break;
00114     case ODateBookAccess::SortEndDateTime:
00115             ret = testDateTime( left.endDateTime(), right.endDateTime() );
00116         break;
00117     case ODateBookAccess::SortAlarmDateTime:
00118             ret = testAlarmNotifiers( left.notifiers(), right.notifiers() );
00119         break;
00120     default:
00121             odebug << "OpimEventSortVector: Unknown sortOrder: " << sortOrder() << oendl;
00122     }
00123 
00124     /* twist to honor ascending/descending setting as QVector only sorts ascending */
00125     if ( !asc )
00126         ret *= -1;
00127 
00128     //  Maybe differentiate as in OPimTodoSortVector ### FIXME
00129     //  if( ret )
00130     return ret;
00131 }
00132 
00133 }
00134 }

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