Diffstat (limited to 'libopie2/opiepim/private/opimtodosortvector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/private/opimtodosortvector.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libopie2/opiepim/private/opimtodosortvector.cpp b/libopie2/opiepim/private/opimtodosortvector.cpp index 8d15710..1db20df 100644 --- a/libopie2/opiepim/private/opimtodosortvector.cpp +++ b/libopie2/opiepim/private/opimtodosortvector.cpp | |||
@@ -1,119 +1,121 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2004 Holger Freyther <freyther@handhelds.org> | 3 | Copyright (C) 2004 Holger Freyther <freyther@handhelds.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "opimtodosortvector.h" | 30 | #include "opimtodosortvector.h" |
31 | #include <opie2/otodoaccess.h> | 31 | #include <opie2/otodoaccess.h> |
32 | 32 | ||
33 | namespace Opie { | 33 | namespace Opie { |
34 | namespace Internal { | 34 | namespace Internal { |
35 | 35 | ||
36 | namespace{ | ||
36 | inline QString string( const OPimTodo& todo) { | 37 | inline QString string( const OPimTodo& todo) { |
37 | return todo.summary().isEmpty() ? | 38 | return todo.summary().isEmpty() ? |
38 | todo.description().left(20 ) : | 39 | todo.description().left(20 ) : |
39 | todo.summary(); | 40 | todo.summary(); |
40 | } | 41 | } |
41 | 42 | ||
42 | inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) { | 43 | inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) { |
43 | int ret = 0; | 44 | int ret = 0; |
44 | if ( todo1.isCompleted() ) ret++; | 45 | if ( todo1.isCompleted() ) ret++; |
45 | if ( todo2.isCompleted() ) ret--; | 46 | if ( todo2.isCompleted() ) ret--; |
46 | return ret; | 47 | return ret; |
47 | } | 48 | } |
48 | 49 | ||
49 | inline int priority( const OPimTodo& t1, const OPimTodo& t2) { | 50 | inline int priority( const OPimTodo& t1, const OPimTodo& t2) { |
50 | return ( t1.priority() - t2.priority() ); | 51 | return ( t1.priority() - t2.priority() ); |
51 | } | 52 | } |
52 | 53 | ||
53 | inline int summary( const OPimTodo& t1, const OPimTodo& t2) { | 54 | inline int summary( const OPimTodo& t1, const OPimTodo& t2) { |
54 | return QString::compare( string(t1), string(t2) ); | 55 | return QString::compare( string(t1), string(t2) ); |
55 | } | 56 | } |
56 | 57 | ||
57 | inline int deadline( const OPimTodo& t1, const OPimTodo& t2) { | 58 | inline int deadline( const OPimTodo& t1, const OPimTodo& t2) { |
58 | int ret = 0; | 59 | int ret = 0; |
59 | if ( t1.hasDueDate() && | 60 | if ( t1.hasDueDate() && |
60 | t2.hasDueDate() ) | 61 | t2.hasDueDate() ) |
61 | ret = t2.dueDate().daysTo( t1.dueDate() ); | 62 | ret = t2.dueDate().daysTo( t1.dueDate() ); |
62 | else if ( t1.hasDueDate() ) | 63 | else if ( t1.hasDueDate() ) |
63 | ret = -1; | 64 | ret = -1; |
64 | else if ( t2.hasDueDate() ) | 65 | else if ( t2.hasDueDate() ) |
65 | ret = 1; | 66 | ret = 1; |
66 | else | 67 | else |
67 | ret = 0; | 68 | ret = 0; |
68 | 69 | ||
69 | return ret; | 70 | return ret; |
70 | } | 71 | } |
71 | 72 | ||
73 | } | ||
72 | 74 | ||
73 | OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort ) | 75 | OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort ) |
74 | : OPimSortVector<OPimTodo>( size, asc, sort ) | 76 | : OPimSortVector<OPimTodo>( size, asc, sort ) |
75 | {} | 77 | {} |
76 | 78 | ||
77 | int OPimTodoSortVector::compareItems( const OPimTodo& con1, const OPimTodo& con2 ) { | 79 | int OPimTodoSortVector::compareItems( const OPimTodo& con1, const OPimTodo& con2 ) { |
78 | bool seComp, sePrio, seSum, seDeadline; | 80 | bool seComp, sePrio, seSum, seDeadline; |
79 | seComp = sePrio = seDeadline = seSum = false; | 81 | seComp = sePrio = seDeadline = seSum = false; |
80 | int ret =0; | 82 | int ret =0; |
81 | bool asc = sortAscending(); | 83 | bool asc = sortAscending(); |
82 | 84 | ||
83 | /* same item */ | 85 | /* same item */ |
84 | if ( con1.uid() == con2.uid() ) | 86 | if ( con1.uid() == con2.uid() ) |
85 | return 0; | 87 | return 0; |
86 | 88 | ||
87 | switch ( sortOrder() ) { | 89 | switch ( sortOrder() ) { |
88 | case OPimTodoAccess::Completed: { | 90 | case OPimTodoAccess::Completed: { |
89 | ret = completed( con1, con2 ); | 91 | ret = completed( con1, con2 ); |
90 | seComp = TRUE; | 92 | seComp = TRUE; |
91 | break; | 93 | break; |
92 | } | 94 | } |
93 | case OPimTodoAccess::Priority: { | 95 | case OPimTodoAccess::Priority: { |
94 | ret = priority( con1, con2 ); | 96 | ret = priority( con1, con2 ); |
95 | sePrio = TRUE; | 97 | sePrio = TRUE; |
96 | break; | 98 | break; |
97 | } | 99 | } |
98 | case OPimTodoAccess::SortSummary: { | 100 | case OPimTodoAccess::SortSummary: { |
99 | ret = summary( con1, con2 ); | 101 | ret = summary( con1, con2 ); |
100 | seSum = TRUE; | 102 | seSum = TRUE; |
101 | break; | 103 | break; |
102 | } | 104 | } |
103 | case OPimTodoAccess::SortByDate: | 105 | case OPimTodoAccess::SortByDate: |
104 | case OPimTodoAccess::Deadline: { | 106 | case OPimTodoAccess::Deadline: { |
105 | ret = deadline( con1, con2 ); | 107 | ret = deadline( con1, con2 ); |
106 | seDeadline = TRUE; | 108 | seDeadline = TRUE; |
107 | break; | 109 | break; |
108 | } | 110 | } |
109 | default: | 111 | default: |
110 | ret = 0; | 112 | ret = 0; |
111 | break; | 113 | break; |
112 | }; | 114 | }; |
113 | /* | 115 | /* |
114 | * FIXME do better sorting if the first sort criteria | 116 | * FIXME do better sorting if the first sort criteria |
115 | * ret equals 0 start with complete and so on... | 117 | * ret equals 0 start with complete and so on... |
116 | */ | 118 | */ |
117 | 119 | ||
118 | /* twist it we're not ascending*/ | 120 | /* twist it we're not ascending*/ |
119 | if (!asc) | 121 | if (!asc) |