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 "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
00047
00048
00049 OPimNotifyManager::Alarms::Iterator it;
00050 QDateTime left_earliest;
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;
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
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
00125 if ( !asc )
00126 ret *= -1;
00127
00128
00129
00130 return ret;
00131 }
00132
00133 }
00134 }