summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/ChangeLog3
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.cpp3
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h3
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp58
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h25
-rw-r--r--libopie2/opiepim/private/opimeventsortvector.cpp134
-rw-r--r--libopie2/opiepim/private/opimeventsortvector.h48
-rw-r--r--libopie2/opiepim/private/opimsortvector.h34
-rw-r--r--libopie2/opiepim/private/opimtodosortvector.cpp2
-rw-r--r--libopie2/opiepim/private/private.pro2
10 files changed, 307 insertions, 5 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog
index 320b189..e94fa59 100644
--- a/libopie2/opiepim/ChangeLog
+++ b/libopie2/opiepim/ChangeLog
@@ -1,12 +1,15 @@
12005-01-16 Stefan Eilers <stefan@eilers-online.net>
2 * Added new OPimEventSortVector class, improved OPimSortVector
3 * OPimAccessBackend now supports generic sorting.
12005-01-03 Stefan Eilers <stefan@eilers-online.net> 42005-01-03 Stefan Eilers <stefan@eilers-online.net>
2 * Fixing bug in API documentation 5 * Fixing bug in API documentation
3 * Moving hasQuerySettings() and querySettings() to OPimAccessTemplate to be available for all frontends 6 * Moving hasQuerySettings() and querySettings() to OPimAccessTemplate to be available for all frontends
42004-12-28 Stefan Eilers <stefan@eilers-online.net> 72004-12-28 Stefan Eilers <stefan@eilers-online.net>
5 * Make improved query by example accessable via frontend 8 * Make improved query by example accessable via frontend
6 * Some API documentation improvement 9 * Some API documentation improvement
7 * Cleanup of backend api.. 10 * Cleanup of backend api..
8 * Fixing bug #1501 11 * Fixing bug #1501
92004-11-23 Stefan Eilers <stefan@eilers-online.net> 122004-11-23 Stefan Eilers <stefan@eilers-online.net>
10 * Implement fast and full featured version of sorted() for addressbook 13 * Implement fast and full featured version of sorted() for addressbook
11 * Implement generic queryByExample for all Addressboook backends. It allows incremental search. 14 * Implement generic queryByExample for all Addressboook backends. It allows incremental search.
12 * Update of API Documentation 15 * Update of API Documentation
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.cpp b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
index b4fdd46..c09427c 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
@@ -1,15 +1,16 @@
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) Holger Freyther <freyther@handhelds.org>
4 Copyright (C) Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 14 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index 27d70ab..d5c463b 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -1,15 +1,16 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) Holger Freyther <freyther@handhelds.org>
4 Copyright (C) Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 14 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index e44912a..6da0170 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -19,27 +19,29 @@
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#include <qtl.h> 29#include <qtl.h>
30 30
31#include <opie2/odebug.h>
31#include <opie2/opimrecurrence.h> 32#include <opie2/opimrecurrence.h>
32 33#include <opie2/odatebookaccess.h>
33#include <opie2/odatebookaccessbackend.h> 34#include <opie2/odatebookaccessbackend.h>
35#include <opie2/private/opimeventsortvector.h>
34 36
35using namespace Opie; 37using namespace Opie;
36 38
37namespace { 39namespace {
38/* a small helper to get all NonRepeating events for a range of time */ 40/* a small helper to get all NonRepeating events for a range of time */
39void events( OPimBackendOccurrence::List& tmpList, 41void events( OPimBackendOccurrence::List& tmpList,
40 const OPimEvent::ValueList& events, 42 const OPimEvent::ValueList& events,
41 const QDate& from, const QDate& to ) { 43 const QDate& from, const QDate& to ) {
42 QDateTime dtStart, dtEnd; 44 QDateTime dtStart, dtEnd;
43 45
44 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { 46 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
45 dtStart = (*it).startDateTime(); 47 dtStart = (*it).startDateTime();
@@ -135,26 +137,76 @@ bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const
135 return false; 137 return false;
136} 138}
137 139
138 140
139 141
140UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, 142UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings,
141 const QDateTime& d )const 143 const QDateTime& d )const
142{ 144{
143 qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" ); 145 qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" );
144 return UIDArray(); 146 return UIDArray();
145} 147}
146 148
147UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { 149UIDArray ODateBookAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, int filter, const QArray<int>& categories )const {
148 return UIDArray(); 150 odebug << "Using Unaccelerated ODateBookAccessBackend sorted Implementation" << oendl;
151
152 Internal::OPimEventSortVector vector( ar.count(), asc, sortOrder );
153 int item = 0;
154
155 for ( uint i = 0; i < ar.count(); ++i ){
156 OPimEvent event = find( ar[i], ar, i, Frontend::Forward );
157 if ( event.isEmpty() )
158 continue;
159
160 bool catPassed = true;
161 if ( filter & ODateBookAccess::FilterCategory ){
162 catPassed = false;
163 // Filter Categories
164 for ( uint cat_idx = 0; cat_idx < categories.count(); ++cat_idx ){
165 int cat = categories[cat_idx];
166 if ( cat == -1 || cat == 0 ){
167 // Unfiled. Check next category if list is not empty.
168 // Else: take it as we will not filter unfiled events..
169 if ( !event.categories().isEmpty() )
170 continue;
171 else
172 catPassed = true;
173 } else {
174 if ( !event.categories().contains( cat ) )
175 continue;
176 else{
177 catPassed = true;
178 break;
179 }
180 }
181 }
182 }
183
184 // Continue to next event if the category filter removed this item
185 if ( !catPassed )
186 continue;
187
188 vector.insert( item++, event );
189 }
190
191 // Now sort the vector and return the list of UID's
192 vector.resize( item );
193 vector.sort();
194
195 UIDArray array( vector.count() );
196 for ( uint i= 0; i < vector.count(); i++ )
197 array[i] = vector.uidAt( i );
198
199 return array;
200
149} 201}
150 202
151OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, 203OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
152 const QDateTime& dt ) { 204 const QDateTime& dt ) {
153 OPimBackendOccurrence::List tmpList; 205 OPimBackendOccurrence::List tmpList;
154 OPimBackendOccurrence::List::ConstIterator it; 206 OPimBackendOccurrence::List::ConstIterator it;
155 207
156 for ( it = dayList.begin(); it != dayList.end(); ++it ) { 208 for ( it = dayList.begin(); it != dayList.end(); ++it ) {
157 OPimBackendOccurrence occ = *it; 209 OPimBackendOccurrence occ = *it;
158 210
159 /* 211 /*
160 * Let us find occurrences that are 'now'! 212 * Let us find occurrences that are 'now'!
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index 0be8606..d2e3925 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -37,24 +37,49 @@
37namespace Opie { 37namespace Opie {
38/** 38/**
39 * This is the object orientated datebook database. It'll use OBackendFactory 39 * This is the object orientated datebook database. It'll use OBackendFactory
40 * to query for a backend. 40 * to query for a backend.
41 * All access to the datebook should be done via this class. 41 * All access to the datebook should be done via this class.
42 * Make sure to load and save the datebook this is not part of 42 * Make sure to load and save the datebook this is not part of
43 * destructing and creating the object 43 * destructing and creating the object
44 * 44 *
45 * @author Holger Freyther, Stefan Eilers 45 * @author Holger Freyther, Stefan Eilers
46 */ 46 */
47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { 47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> {
48public: 48public:
49 /**
50 * Filter for sorted()
51 * @see SortFilterBase in OPimBase
52 */
53 enum SortFilter {
54
55 };
56
57 /**
58 * Sort order for sorted()
59 * @see SortOrderBase in OPimBase
60 */
61 enum SortOrder {
62 SortDescription = SortCustom,
63 SortLocation,
64 SortNote,
65 SortStartTime,
66 SortEndTime,
67 SortStartDate,
68 SortEndDate,
69 SortStartDateTime,
70 SortEndDateTime,
71 SortAlarmDateTime,
72 };
73
49 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); 74 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
50 ~ODateBookAccess(); 75 ~ODateBookAccess();
51 76
52 /* return repeating events */ 77 /* return repeating events */
53 List rawRepeats()const; 78 List rawRepeats()const;
54 79
55 /* return non repeating events */ 80 /* return non repeating events */
56 List nonRepeats()const; 81 List nonRepeats()const;
57 82
58 /* return non repeating events (from,to) */ 83 /* return non repeating events (from,to) */
59 OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; 84 OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
60 OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const; 85 OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const;
diff --git a/libopie2/opiepim/private/opimeventsortvector.cpp b/libopie2/opiepim/private/opimeventsortvector.cpp
new file mode 100644
index 0000000..4220c63
--- a/dev/null
+++ b/libopie2/opiepim/private/opimeventsortvector.cpp
@@ -0,0 +1,134 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimeventsortvector.h"
31#include <opie2/ocontactaccess.h>
32#include <opie2/opimnotifymanager.h>
33#include <opie2/odatebookaccess.h>
34
35#include <qvaluelist.h>
36
37namespace Opie {
38namespace Internal {
39
40namespace{
41
42inline int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){
43 OPimNotifyManager::Alarms left_alarms = leftnotifiers.alarms();
44 OPimNotifyManager::Alarms right_alarms = rightnotifiers.alarms();
45
46 // Well.. How could we compare two lists of alarms? I think we should find the most early datetimes
47 // and compare them.. (se)
48 // Find the first alarm of the left list
49 OPimNotifyManager::Alarms::Iterator it;
50 QDateTime left_earliest; // This datetime is initialized as invalid!!
51 for ( it = left_alarms.begin(); it != left_alarms.end(); ++it ){
52 if ( !left_earliest.isValid() || left_earliest > (*it).dateTime() ){
53 left_earliest = (*it).dateTime();
54 }
55 }
56 QDateTime right_earliest; // This datetime is initialized as invalid!!
57 for ( it = right_alarms.begin(); it != right_alarms.end(); ++it ){
58 if ( !right_earliest.isValid() || right_earliest > (*it).dateTime() ){
59 right_earliest = (*it).dateTime();
60 }
61 }
62
63 int ret;
64
65 // Now compare this found alarms
66 if ( !left_earliest .isValid() ) ret++;
67 if ( !right_earliest.isValid() ) ret--;
68
69 if ( left_earliest.isValid() && right_earliest.isValid() ){
70 ret += left_earliest < right_earliest ? -1 : 1;
71 }
72
73 return ret;
74
75}
76}
77
78OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort )
79 : OPimSortVector<OPimEvent>( size, asc, sort ) {}
80
81int OPimEventSortVector::compareItems( const OPimEvent& left,
82 const OPimEvent& right ) {
83 if ( left.uid() == right.uid() )
84 return 0;
85
86 int ret = 0;
87 bool asc = sortAscending();
88
89 switch( sortOrder() ) {
90 case ODateBookAccess::SortDescription:
91 ret = testString( left.description(), right.description() );
92 break;
93 case ODateBookAccess::SortLocation:
94 ret = testString( left.location(), right.location() );
95 break;
96 case ODateBookAccess::SortNote:
97 ret = testString( left.note(),right.note() );
98 break;
99 case ODateBookAccess::SortStartTime:
100 ret = testTime( left.startDateTime().time(), right.startDateTime().time() );
101 break;
102 case ODateBookAccess::SortEndTime:
103 ret = testTime( left.endDateTime().time(), right.endDateTime().time() );
104 break;
105 case ODateBookAccess::SortStartDate:
106 ret = testDate( left.startDateTime().date(), right.startDateTime().date() );
107 break;
108 case ODateBookAccess::SortEndDate:
109 ret = testDate( left.endDateTime().date(), right.endDateTime().date() );
110 break;
111 case ODateBookAccess::SortStartDateTime:
112 ret = testDateTime( left.startDateTime(), right.startDateTime() );
113 break;
114 case ODateBookAccess::SortEndDateTime:
115 ret = testDateTime( left.endDateTime(), right.endDateTime() );
116 break;
117 case ODateBookAccess::SortAlarmDateTime:
118 ret = testAlarmNotifiers( left.notifiers(), right.notifiers() );
119 break;
120 default:
121 odebug << "OpimEventSortVector: Unknown sortOrder: " << sortOrder() << oendl;
122 }
123
124 /* twist to honor ascending/descending setting as QVector only sorts ascending */
125 if ( !asc )
126 ret *= -1;
127
128 // Maybe differentiate as in OPimTodoSortVector ### FIXME
129 // if( ret )
130 return ret;
131}
132
133}
134}
diff --git a/libopie2/opiepim/private/opimeventsortvector.h b/libopie2/opiepim/private/opimeventsortvector.h
new file mode 100644
index 0000000..dde26df
--- a/dev/null
+++ b/libopie2/opiepim/private/opimeventsortvector.h
@@ -0,0 +1,48 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OPIM_CONTACT_SORT_VECTOR_H
31#define OPIM_CONTACT_SORT_VECTOR_H
32
33#include <opie2/opimevent.h>
34#include <opie2/private/opimsortvector.h>
35
36namespace Opie {
37namespace Internal {
38class OPimEventSortVector : public OPimSortVector<OPimEvent> {
39public:
40 OPimEventSortVector( uint size, bool asc, int sort );
41private:
42 int compareItems( const OPimEvent&, const OPimEvent& );
43};
44}
45}
46
47
48#endif
diff --git a/libopie2/opiepim/private/opimsortvector.h b/libopie2/opiepim/private/opimsortvector.h
index 6c21339..11a40ac 100644
--- a/libopie2/opiepim/private/opimsortvector.h
+++ b/libopie2/opiepim/private/opimsortvector.h
@@ -44,24 +44,27 @@ struct OPimSortVectorContainer {
44template<class T> 44template<class T>
45class OPimSortVector : public QVector<OPimSortVectorContainer<T> > { 45class OPimSortVector : public QVector<OPimSortVectorContainer<T> > {
46 typedef OPimSortVectorContainer<T> VectorItem; 46 typedef OPimSortVectorContainer<T> VectorItem;
47public: 47public:
48 OPimSortVector( uint size, bool asc, int sort ); 48 OPimSortVector( uint size, bool asc, int sort );
49 int compareItems( QCollection::Item d1, QCollection::Item d2 ); 49 int compareItems( QCollection::Item d1, QCollection::Item d2 );
50 bool insert( uint, const T& t ); 50 bool insert( uint, const T& t );
51 UID uidAt( uint i )const; 51 UID uidAt( uint i )const;
52 52
53protected: 53protected:
54 int testString( const QString&, const QString& )const; 54 int testString( const QString&, const QString& )const;
55 int testDate( const QDate&, const QDate& )const; 55 int testDate( const QDate&, const QDate& )const;
56 int testTime( const QTime&, const QTime& )const;
57 int testDateTime( const QDateTime& left,
58 const QDateTime& right )const;
56protected: 59protected:
57 bool sortAscending()const; 60 bool sortAscending()const;
58 int sortOrder()const; 61 int sortOrder()const;
59 62
60private: 63private:
61 bool m_ascending : 1; 64 bool m_ascending : 1;
62 int m_sort; 65 int m_sort;
63 virtual int compareItems( const T& item1, const T& item2 ) = 0; 66 virtual int compareItems( const T& item1, const T& item2 ) = 0;
64}; 67};
65 68
66template<class T> 69template<class T>
67OPimSortVector<T>::OPimSortVector( uint size, bool asc, int sort ) 70OPimSortVector<T>::OPimSortVector( uint size, bool asc, int sort )
@@ -111,28 +114,59 @@ bool OPimSortVector<T>::insert( uint i, const T& record ) {
111 114
112template<class T> 115template<class T>
113UID OPimSortVector<T>::uidAt( uint index )const { 116UID OPimSortVector<T>::uidAt( uint index )const {
114 return this->at( index )->item.uid(); 117 return this->at( index )->item.uid();
115} 118}
116 119
117template<class T> 120template<class T>
118inline int OPimSortVector<T>::testString( const QString& left, 121inline int OPimSortVector<T>::testString( const QString& left,
119 const QString& right )const { 122 const QString& right )const {
120 return QString::compare( left, right ); 123 return QString::compare( left, right );
121} 124}
122 125
126
123template<class T> 127template<class T>
124inline int OPimSortVector<T>::testDate( const QDate& left, 128inline int OPimSortVector<T>::testDate( const QDate& left,
125 const QDate& right )const { 129 const QDate& right )const {
126 int ret = 0; 130 int ret = 0;
127 if ( !left .isValid() ) ret++; 131 if ( !left .isValid() ) ret++;
128 if ( !right.isValid() ) ret--; 132 if ( !right.isValid() ) ret--;
129 133
130 if ( left.isValid() && right.isValid() ) 134 if ( left.isValid() && right.isValid() )
131 ret += left < right ? -1 : 1; 135 ret += left < right ? -1 : 1;
132 136
133 return ret; 137 return ret;
134} 138}
139
140template<class T>
141inline int OPimSortVector<T>::testTime( const QTime& left,
142 const QTime& right )const {
143 int ret = 0;
144 if ( !left .isValid() ) ret++;
145 if ( !right.isValid() ) ret--;
146
147 if ( left.isValid() && right.isValid() ){
148 ret += left < right ? -1 : 1;
149 }
150
151 return ret;
152}
153
154template<class T>
155inline int OPimSortVector<T>::testDateTime( const QDateTime& left,
156 const QDateTime& right )const {
157 int ret = 0;
158 if ( !left .isValid() ) ret++;
159 if ( !right.isValid() ) ret--;
160
161 if ( left.isValid() && right.isValid() ){
162 ret += left < right ? -1 : 1;
163 }
164
165 return ret;
166
167}
168
135} 169}
136} 170}
137 171
138#endif 172#endif
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
@@ -24,24 +24,25 @@
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
33namespace Opie { 33namespace Opie {
34namespace Internal { 34namespace Internal {
35 35
36namespace{
36inline QString string( const OPimTodo& todo) { 37inline 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
42inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) { 43inline 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}
@@ -60,24 +61,25 @@ inline int deadline( const OPimTodo& t1, const OPimTodo& t2) {
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
73OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort ) 75OPimTodoSortVector::OPimTodoSortVector( uint size, bool asc, int sort )
74 : OPimSortVector<OPimTodo>( size, asc, sort ) 76 : OPimSortVector<OPimTodo>( size, asc, sort )
75{} 77{}
76 78
77int OPimTodoSortVector::compareItems( const OPimTodo& con1, const OPimTodo& con2 ) { 79int 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 */
diff --git a/libopie2/opiepim/private/private.pro b/libopie2/opiepim/private/private.pro
index 618c2d6..92c24cb 100644
--- a/libopie2/opiepim/private/private.pro
+++ b/libopie2/opiepim/private/private.pro
@@ -1,9 +1,11 @@
1HEADERS += private/vobject_p.h \ 1HEADERS += private/vobject_p.h \
2 private/opimcontactsortvector.h \ 2 private/opimcontactsortvector.h \
3 private/opimeventsortvector.h \
3 private/opimoccurrence_p.h \ 4 private/opimoccurrence_p.h \
4 private/opimsortvector.h \ 5 private/opimsortvector.h \
5 private/opimtodosortvector.h 6 private/opimtodosortvector.h
6 7
7SOURCES += private/opimcontactsortvector.cpp \ 8SOURCES += private/opimcontactsortvector.cpp \
9 private/opimeventsortvector.cpp \
8 private/opimtodosortvector.cpp 10 private/opimtodosortvector.cpp
9 11