• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kcalcore
sorting.cpp
1 /*
2  This file is part of the kcalcore library.
3 
4  Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5  Contact: Alvaro Manera <alvaro.manera@nokia.com>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 #include "sorting.h"
23 #include "event.h"
24 #include "journal.h"
25 #include "todo.h"
26 
27 #include <KDateTime>
28 
29 // PENDING(kdab) Review
30 // The QString::compare() need to be replace by a DUI string comparisons.
31 // See http://qt.gitorious.org/maemo-6-ui-framework/libdui
32 // If not compiled in "meego-mode" should we be using locale compares?
33 
34 using namespace KCalCore;
35 
36 bool KCalCore::Events::startDateLessThan(const Event::Ptr &e1, const Event::Ptr &e2)
37 {
38  const KDateTime d1= e1->dtStart();
39  KDateTime::Comparison res = d1.compare(e2->dtStart());
40  if (res == KDateTime::Equal) {
41  return Events::summaryLessThan(e1, e2);
42  } else {
43  return (res & KDateTime::Before || res & KDateTime::AtStart);
44  }
45 }
46 
47 bool KCalCore::Events::startDateMoreThan(const Event::Ptr &e1, const Event::Ptr &e2)
48 {
49  const KDateTime d1= e1->dtStart();
50  KDateTime::Comparison res = d1.compare(e2->dtStart());
51  if (res == KDateTime::Equal) {
52  return Events::summaryMoreThan(e1, e2);
53  } else {
54  return (res & KDateTime::After || res & KDateTime::AtEnd);
55  }
56 }
57 
58 bool KCalCore::Events::summaryLessThan(const Event::Ptr &e1, const Event::Ptr &e2)
59 {
60  return QString::compare(e1->summary(), e2->summary(), Qt::CaseInsensitive) < 0;
61 }
62 
63 bool KCalCore::Events::summaryMoreThan(const Event::Ptr &e1, const Event::Ptr &e2)
64 {
65  return QString::compare(e1->summary(), e2->summary(), Qt::CaseInsensitive) > 0;
66 }
67 
68 bool KCalCore::Events::endDateLessThan(const Event::Ptr &e1, const Event::Ptr &e2)
69 {
70  const KDateTime d1= e1->dtEnd();
71  KDateTime::Comparison res = d1.compare(e2->dtEnd());
72  if (res == KDateTime::Equal) {
73  return Events::summaryLessThan(e1, e2);
74  } else {
75  return (res & KDateTime::Before || res & KDateTime::AtStart);
76  }
77 }
78 
79 bool KCalCore::Events::endDateMoreThan(const Event::Ptr &e1, const Event::Ptr &e2)
80 {
81  const KDateTime d1= e1->dtEnd();
82  KDateTime::Comparison res = d1.compare(e2->dtEnd());
83  if (res == KDateTime::Equal) {
84  return Events::summaryMoreThan(e1, e2);
85  } else {
86  return (res & KDateTime::After || res & KDateTime::AtEnd);
87  }
88 }
89 
90 bool KCalCore::Journals::dateLessThan(const Journal::Ptr &j1, const Journal::Ptr &j2)
91 {
92  const KDateTime d1 = j1->dtStart();
93  KDateTime::Comparison res = d1.compare(j2->dtStart());
94  return (res & KDateTime::Before || res & KDateTime::AtStart);
95 }
96 
97 bool KCalCore::Journals::dateMoreThan(const Journal::Ptr &j1, const Journal::Ptr &j2)
98 {
99  const KDateTime d1= j1->dtStart();
100  KDateTime::Comparison res = d1.compare(j2->dtStart());
101  return (res & KDateTime::After || res & KDateTime::AtEnd);
102 }
103 
104 bool KCalCore::Journals::summaryLessThan(const Journal::Ptr &j1, const Journal::Ptr &j2)
105 {
106 
107  return QString::compare(j1->summary(), j2->summary(), Qt::CaseInsensitive) < 0;
108 }
109 
110 bool KCalCore::Journals::summaryMoreThan(const Journal::Ptr &j1, const Journal::Ptr &j2)
111 {
112  return QString::compare(j1->summary(), j2->summary(), Qt::CaseInsensitive) > 0;
113 }
114 
115 bool KCalCore::Todos::startDateLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
116 {
117  const KDateTime d1= t1->dtStart();
118  KDateTime::Comparison res = d1.compare(t2->dtStart());
119  if (res == KDateTime::Equal) {
120  return Todos::summaryLessThan(t1, t2);
121  } else {
122  return (res & KDateTime::Before || res & KDateTime::AtStart);
123  }
124 }
125 
126 bool KCalCore::Todos::startDateMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
127 {
128  const KDateTime d1= t1->dtStart();
129  KDateTime::Comparison res = d1.compare(t2->dtStart());
130  if (res == KDateTime::Equal) {
131  return Todos::summaryMoreThan(t1, t2);
132  } else {
133  return (res & KDateTime::After || res & KDateTime::AtEnd);
134  }
135 }
136 
137 bool KCalCore::Todos::dueDateLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
138 {
139  const KDateTime d1= t1->dtDue();
140  KDateTime::Comparison res = d1.compare(t2->dtDue());
141  if (res == KDateTime::Equal) {
142  return Todos::summaryLessThan(t1, t2);
143  } else {
144  return (res & KDateTime::Before || res & KDateTime::AtStart);
145  }
146 }
147 
148 bool KCalCore::Todos::dueDateMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
149 {
150  const KDateTime d1= t1->dtDue();
151  KDateTime::Comparison res = d1.compare(t2->dtDue());
152  if (res == KDateTime::Equal) {
153  return Todos::summaryMoreThan(t1, t2);
154  } else {
155  return (res & KDateTime::After || res & KDateTime::AtEnd);
156  }
157 }
158 
159 bool KCalCore::Todos::priorityLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
160 {
161  if (t1->priority() < t2->priority()) {
162  return true;
163  } else if (t1->priority() == t2->priority()) {
164  return Todos::summaryLessThan(t1, t2);
165  } else {
166  return false;
167  }
168 }
169 
170 bool KCalCore::Todos::priorityMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
171 {
172  if (t1->priority() > t2->priority()) {
173  return true;
174  } else if (t1->priority() == t2->priority()) {
175  return Todos::summaryMoreThan(t1, t2);
176  } else {
177  return false;
178  }
179 }
180 
181 bool KCalCore::Todos::percentLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
182 {
183  if (t1->percentComplete() < t2->percentComplete()) {
184  return true;
185  } else if (t1->percentComplete() == t2->percentComplete()) {
186  return Todos::summaryLessThan(t1, t2);
187  } else {
188  return false;
189  }
190 }
191 
192 bool KCalCore::Todos::percentMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
193 {
194  if (t1->percentComplete() > t2->percentComplete()) {
195  return true;
196  } else if (t1->percentComplete() == t2->percentComplete()) {
197  return Todos::summaryMoreThan(t1, t2);
198  } else {
199  return false;
200  }
201 }
202 
203 bool KCalCore::Todos::summaryLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
204 {
205  return QString::compare(t1->summary(), t2->summary(), Qt::CaseInsensitive) < 0;
206 }
207 
208 bool KCalCore::Todos::summaryMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
209 {
210  return QString::compare(t1->summary(), t2->summary(), Qt::CaseInsensitive) > 0;
211 }
212 
213 bool KCalCore::Todos::createdLessThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
214 {
215  const KDateTime d1= t1->created();
216  KDateTime::Comparison res = d1.compare(t2->created());
217  if (res == KDateTime::Equal) {
218  return Todos::summaryLessThan(t1, t2);
219  } else {
220  return (res & KDateTime::Before || res & KDateTime::AtStart);
221  }
222 }
223 
224 bool KCalCore::Todos::createdMoreThan(const Todo::Ptr &t1, const Todo::Ptr &t2)
225 {
226  const KDateTime d1= t1->created();
227  KDateTime::Comparison res = d1.compare(t2->created());
228  if (res == KDateTime::Equal) {
229  return Todos::summaryMoreThan(t1, t2);
230  } else {
231  return (res & KDateTime::After || res & KDateTime::AtEnd);
232  }
233 }
234 
235 bool KCalCore::Incidences::dateLessThan(const Incidence::Ptr &i1,
236  const Incidence::Ptr &i2)
237 {
238  const KDateTime d1 = i1->dateTime(Incidence::RoleSort);
239  const KDateTime d2 = i2->dateTime(Incidence::RoleSort);
240 
241  KDateTime::Comparison res = d1.compare(d2);
242  if (res == KDateTime::Equal) {
243  return Incidences::summaryLessThan(i1, i2);
244  } else {
245  return (res & KDateTime::Before || res & KDateTime::AtStart);
246  }
247 }
248 
249 bool KCalCore::Incidences::dateMoreThan(const Incidence::Ptr &i1,
250  const Incidence::Ptr &i2)
251 {
252  const KDateTime d1 = i1->dateTime(Incidence::RoleSort);
253  const KDateTime d2 = i2->dateTime(Incidence::RoleSort);
254 
255  KDateTime::Comparison res = d1.compare(d2);
256  if (res == KDateTime::Equal) {
257  return Incidences::summaryMoreThan(i1, i2);
258  } else {
259  return (res & KDateTime::After || res & KDateTime::AtEnd);
260  }
261 }
262 
263 bool KCalCore::Incidences::createdLessThan(const Incidence::Ptr &i1,
264  const Incidence::Ptr &i2)
265 {
266  const KDateTime d1= i1->created();
267  KDateTime::Comparison res = d1.compare(i2->created());
268  if (res == KDateTime::Equal) {
269  return Incidences::summaryLessThan(i1, i2);
270  } else {
271  return (res & KDateTime::Before || res & KDateTime::AtStart);
272  }
273 }
274 
275 bool KCalCore::Incidences::createdMoreThan(const Incidence::Ptr &i1,
276  const Incidence::Ptr &i2)
277 {
278  const KDateTime d1= i1->created();
279  KDateTime::Comparison res = d1.compare(i2->created());
280  if (res == KDateTime::Equal) {
281  return Incidences::summaryMoreThan(i1, i2);
282  } else {
283  return (res & KDateTime::After || res & KDateTime::AtEnd);
284  }
285 }
286 
287 bool KCalCore::Incidences::summaryLessThan(const Incidence::Ptr &i1,
288  const Incidence::Ptr &i2)
289 {
290  return QString::compare(i1->summary(), i2->summary(), Qt::CaseInsensitive) < 0;
291 }
292 
293 bool KCalCore::Incidences::summaryMoreThan(const Incidence::Ptr &i1,
294  const Incidence::Ptr &i2)
295 {
296  return QString::compare(i1->summary(), i2->summary(), Qt::CaseInsensitive) > 0;
297 }
298 
299 bool KCalCore::Persons::countMoreThan(const Person::Ptr &p1, const Person::Ptr &p2)
300 {
301  return p1->count() > p2->count();
302 }
KCalCore::Event::Ptr
QSharedPointer< Event > Ptr
A shared pointer to an Event object.
Definition: event.h:55
KCalCore::Incidence::Ptr
QSharedPointer< Incidence > Ptr
A shared pointer to an Incidence.
Definition: incidence.h:112
todo.h
This file is part of the API for handling calendar data and defines the Todo class.
KCalCore::IncidenceBase::RoleSort
Role for an incidence's date/time used when sorting.
Definition: incidencebase.h:136
journal.h
This file is part of the API for handling calendar data and defines the Journal class.
KCalCore::Person::Ptr
QSharedPointer< Person > Ptr
A shared pointer to a Person object.
Definition: person.h:56
event.h
This file is part of the API for handling calendar data and defines the Event class.
KCalCore::Todo::Ptr
QSharedPointer< Todo > Ptr
A shared pointer to a Todo object.
Definition: todo.h:50
KCalCore::Journal::Ptr
QSharedPointer< Journal > Ptr
A shared pointer to a Journal object.
Definition: journal.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

Skip menu "KCalCore Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal