Diffstat (limited to 'libopie2/opiepim/backend/otodoaccessbackend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessbackend.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp index 790a764..5f86be9 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.cpp +++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp | |||
@@ -28,6 +28,10 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/otodoaccessbackend.h> | 30 | #include <opie2/otodoaccessbackend.h> |
31 | #include <opie2/private/opimtodosortvector.h> | ||
32 | #include <opie2/otodoaccess.h> | ||
33 | |||
34 | #include <qintdict.h> | ||
31 | 35 | ||
32 | namespace Opie { | 36 | namespace Opie { |
33 | OPimTodoAccessBackend::OPimTodoAccessBackend() | 37 | OPimTodoAccessBackend::OPimTodoAccessBackend() |
@@ -38,4 +42,114 @@ OPimTodoAccessBackend::~OPimTodoAccessBackend() { | |||
38 | 42 | ||
39 | } | 43 | } |
40 | 44 | ||
45 | UIDArray OPimTodoAccessBackend::queryByExample( const OPimTodo&, int settings, | ||
46 | const QDateTime& d)const { | ||
47 | return UIDArray(); | ||
48 | } | ||
49 | |||
50 | UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc, | ||
51 | int sortOrder, int sortFilter, | ||
52 | const QArray<int>& categories )const { | ||
53 | odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl; | ||
54 | Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); | ||
55 | int item = 0; | ||
56 | |||
57 | bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; | ||
58 | bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; | ||
59 | bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; | ||
60 | bool catPassed = false; | ||
61 | int cat; | ||
62 | |||
63 | for ( uint i = 0; i < events.count(); ++i ) { | ||
64 | OPimTodo todo = find( events[i], events, i, Frontend::Forward ); | ||
65 | if ( todo.isEmpty() ) | ||
66 | continue; | ||
67 | |||
68 | /* show category */ | ||
69 | /* -1 == unfiled */ | ||
70 | catPassed = false; | ||
71 | for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { | ||
72 | cat = categories[cat_nu]; | ||
73 | if ( bCat && cat == -1 ) { | ||
74 | if(!todo.categories().isEmpty() ) | ||
75 | continue; | ||
76 | } else if ( bCat && cat != 0) | ||
77 | if (!todo.categories().contains( cat ) ) | ||
78 | continue; | ||
79 | catPassed = true; | ||
80 | break; | ||
81 | } | ||
82 | |||
83 | /* | ||
84 | * If none of the Categories matched | ||
85 | * continue | ||
86 | */ | ||
87 | if ( !catPassed ) | ||
88 | continue; | ||
89 | if ( !todo.isOverdue() && bOnly ) | ||
90 | continue; | ||
91 | if (todo.isCompleted() && comp ) | ||
92 | continue; | ||
93 | |||
94 | vector.insert(item++, todo ); | ||
95 | } | ||
96 | |||
97 | vector.resize( item ); | ||
98 | /* sort it now */ | ||
99 | vector.sort(); | ||
100 | /* now get the uids */ | ||
101 | UIDArray array( vector.count() ); | ||
102 | for (uint i= 0; i < vector.count(); i++ ) | ||
103 | array[i] = vector.uidAt( i ); | ||
104 | |||
105 | return array; | ||
106 | } | ||
107 | |||
108 | OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start, | ||
109 | const QDate& end )const { | ||
110 | OPimBackendOccurrence::List lst; | ||
111 | UIDArray effective = effectiveToDos( start, end, false ); | ||
112 | UIDArray overdue = overDue(); | ||
113 | uint count = effective.count(); | ||
114 | int uid; | ||
115 | QIntDict<int> hash; | ||
116 | hash.setAutoDelete( true ); | ||
117 | OPimTodo todo; | ||
118 | |||
119 | for ( uint i = 0; i < count; ++i ) { | ||
120 | uid = effective[i]; | ||
121 | todo = find( uid, effective, i, Frontend::Forward ); | ||
122 | /* | ||
123 | * If isOverdue but in the 'normal' range we will fill | ||
124 | * the hash so we won't have duplicates in OPimBackendOccurrence | ||
125 | */ | ||
126 | if ( todo.isOverdue() ) | ||
127 | hash.insert( uid, new int(6) ); | ||
128 | OPimBackendOccurrence oc = todo.hasStartDate() ? | ||
129 | OPimBackendOccurrence( todo.startDate(), | ||
130 | todo.dueDate(), uid ) : | ||
131 | OPimBackendOccurrence( todo.dueDate(), uid, QString::null ); | ||
132 | oc.setSummary( todo.summary() ); | ||
133 | lst.append( oc ); | ||
134 | } | ||
135 | |||
136 | /* | ||
137 | * Create the OverDue items but skip | ||
138 | * the already handled Records | ||
139 | */ | ||
140 | if ( !overdue.isEmpty() ) { | ||
141 | QDate today = QDate::currentDate(); | ||
142 | QDate dueDate = (start >= today && today <= end ) ? today : start; | ||
143 | count = overdue.count(); | ||
144 | for ( uint i = 0; i < count; ++i ) { | ||
145 | uid = overdue[i]; | ||
146 | if (!hash.find( uid ) ) | ||
147 | continue; | ||
148 | todo = find( uid, overdue, i, Frontend::Forward ); | ||
149 | lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) ); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | return lst; | ||
154 | } | ||
41 | } | 155 | } |