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 "opimtodosortvector.h"
00031 #include <opie2/otodoaccess.h>
00032
00033 namespace Opie {
00034 namespace Internal {
00035
00036 namespace{
00037 inline QString string( const OPimTodo& todo) {
00038 return todo.summary().isEmpty() ?
00039 todo.description().left(20 ) :
00040 todo.summary();
00041 }
00042
00043 inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) {
00044 int ret = 0;
00045 if ( todo1.isCompleted() ) ret++;
00046 if ( todo2.isCompleted() ) ret--;
00047 return ret;
00048 }
00049
00050 inline int priority( const OPimTodo& t1, const OPimTodo& t2) {
00051 return ( t1.priority() - t2.priority() );
00052 }
00053
00054 inline int summary( const OPimTodo& t1, const OPimTodo& t2) {
00055 return QString::compare( string(t1), string(t2) );
00056 }
00057
00058 inline int deadline( const OPimTodo& t1, const OPimTodo& t2) {
00059 int ret = 0;
00060 if ( t1.hasDueDate() &&
00061 t2.hasDueDate() )
00062 ret = t2.dueDate().daysTo( t1.dueDate() );
00063 else if ( t1.hasDueDate() )
00064 ret = -1;
00065 else if ( t2.hasDueDate() )
00066 ret = 1;
00067 else
00068 ret = 0;
00069
00070 return ret;
00071 }
00072
00073 }
00074
00075 OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort )
00076 : OPimSortVector<OPimTodo>( size, asc, sort )
00077 {}
00078
00079 int OPimTodoSortVector::compareItems( const OPimTodo& con1, const OPimTodo& con2 ) {
00080 bool seComp, sePrio, seSum, seDeadline;
00081 seComp = sePrio = seDeadline = seSum = false;
00082 int ret =0;
00083 bool asc = sortAscending();
00084
00085
00086 if ( con1.uid() == con2.uid() )
00087 return 0;
00088
00089 switch ( sortOrder() ) {
00090 case OPimTodoAccess::Completed: {
00091 ret = completed( con1, con2 );
00092 seComp = TRUE;
00093 break;
00094 }
00095 case OPimTodoAccess::Priority: {
00096 ret = priority( con1, con2 );
00097 sePrio = TRUE;
00098 break;
00099 }
00100 case OPimTodoAccess::SortSummary: {
00101 ret = summary( con1, con2 );
00102 seSum = TRUE;
00103 break;
00104 }
00105 case OPimTodoAccess::SortByDate:
00106 case OPimTodoAccess::Deadline: {
00107 ret = deadline( con1, con2 );
00108 seDeadline = TRUE;
00109 break;
00110 }
00111 default:
00112 ret = 0;
00113 break;
00114 };
00115
00116
00117
00118
00119
00120
00121 if (!asc)
00122 ret = ret * -1;
00123
00124 if ( ret )
00125 return ret;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 if (!seComp ) {
00137 if ( (ret = completed( con1, con2 ) ) ) {
00138 if (!asc ) ret *= -1;
00139 return ret;
00140 }
00141 }
00142 if (!sePrio ) {
00143 if ( (ret = priority( con1, con2 ) ) ) {
00144 if (!asc ) ret *= -1;
00145 return ret;
00146 }
00147 }
00148 if (!seSum ) {
00149 if ( (ret = summary(con1, con2 ) ) ) {
00150 if (!asc) ret *= -1;
00151 return ret;
00152 }
00153 }
00154 if (!seDeadline) {
00155 if ( (ret = deadline( con1, con2 ) ) ) {
00156 if (!asc) ret *= -1;
00157 return ret;
00158 }
00159 }
00160
00161 return 0;
00162 }
00163
00164 }
00165 }