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

KCalCore Library

sorting.cpp
00001 /*
00002   This file is part of the kcalcore library.
00003 
00004   Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00005   Contact: Alvaro Manera <alvaro.manera@nokia.com>
00006 
00007   This library is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU Library General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This library is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   Library General Public License for more details.
00016 
00017   You should have received a copy of the GNU Library General Public License
00018   along with this library; see the file COPYING.LIB.  If not, write to
00019   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020   Boston, MA 02110-1301, USA.
00021 */
00022 #include "sorting.h"
00023 #include "event.h"
00024 #include "journal.h"
00025 #include "todo.h"
00026 
00027 #include <KDateTime>
00028 
00029 // PENDING(kdab) Review
00030 // The QString::compare() need to be replace by a DUI string comparisons.
00031 // See http://qt.gitorious.org/maemo-6-ui-framework/libdui
00032 // If not compiled in "meego-mode" should we be using locale compares?
00033 
00034 using namespace KCalCore;
00035 
00036 bool KCalCore::Events::startDateLessThan( const Event::Ptr &e1, const Event::Ptr &e2 )
00037 {
00038   const KDateTime d1= e1->dtStart();
00039   KDateTime::Comparison res = d1.compare( e2->dtStart() );
00040   if ( res == KDateTime::Equal ) {
00041     return Events::summaryLessThan( e1, e2 );
00042   } else {
00043     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00044   }
00045 }
00046 
00047 bool KCalCore::Events::startDateMoreThan( const Event::Ptr &e1, const Event::Ptr &e2 )
00048 {
00049   const KDateTime d1= e1->dtStart();
00050   KDateTime::Comparison res = d1.compare( e2->dtStart() );
00051   if ( res == KDateTime::Equal ) {
00052     return Events::summaryMoreThan( e1, e2 );
00053   } else {
00054     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00055   }
00056 }
00057 
00058 bool KCalCore::Events::summaryLessThan( const Event::Ptr &e1, const Event::Ptr &e2 )
00059 {
00060   return QString::compare( e1->summary(), e2->summary(), Qt::CaseInsensitive ) < 0;
00061 }
00062 
00063 bool KCalCore::Events::summaryMoreThan( const Event::Ptr &e1, const Event::Ptr &e2 )
00064 {
00065   return QString::compare( e1->summary(), e2->summary(), Qt::CaseInsensitive ) > 0;
00066 }
00067 
00068 bool KCalCore::Events::endDateLessThan( const Event::Ptr &e1, const Event::Ptr &e2 )
00069 {
00070   const KDateTime d1= e1->dtEnd();
00071   KDateTime::Comparison res = d1.compare( e2->dtEnd() );
00072   if ( res == KDateTime::Equal ) {
00073     return Events::summaryLessThan( e1, e2 );
00074   } else {
00075     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00076   }
00077 }
00078 
00079 bool KCalCore::Events::endDateMoreThan( const Event::Ptr &e1, const Event::Ptr &e2 )
00080 {
00081   const KDateTime d1= e1->dtEnd();
00082   KDateTime::Comparison res = d1.compare( e2->dtEnd() );
00083   if ( res == KDateTime::Equal ) {
00084     return Events::summaryMoreThan( e1, e2 );
00085   } else {
00086     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00087   }
00088 }
00089 
00090 bool KCalCore::Journals::dateLessThan( const Journal::Ptr &j1, const Journal::Ptr &j2 )
00091 {
00092   const KDateTime d1 = j1->dtStart();
00093   KDateTime::Comparison res = d1.compare( j2->dtStart() );
00094   return ( res & KDateTime::Before || res & KDateTime::AtStart );
00095 }
00096 
00097 bool KCalCore::Journals::dateMoreThan( const Journal::Ptr &j1, const Journal::Ptr &j2 )
00098 {
00099   const KDateTime d1= j1->dtStart();
00100   KDateTime::Comparison res = d1.compare( j2->dtStart() );
00101   return ( res & KDateTime::After || res & KDateTime::AtEnd );
00102 }
00103 
00104 bool KCalCore::Journals::summaryLessThan( const Journal::Ptr &j1, const Journal::Ptr &j2 )
00105 {
00106 
00107   return QString::compare( j1->summary(), j2->summary(), Qt::CaseInsensitive ) < 0;
00108 }
00109 
00110 bool KCalCore::Journals::summaryMoreThan( const Journal::Ptr &j1, const Journal::Ptr &j2 )
00111 {
00112   return QString::compare( j1->summary(), j2->summary(), Qt::CaseInsensitive ) > 0;
00113 }
00114 
00115 bool KCalCore::Todos::startDateLessThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00116 {
00117   const KDateTime d1= t1->dtStart();
00118   KDateTime::Comparison res = d1.compare( t2->dtStart() );
00119   if ( res == KDateTime::Equal ) {
00120     return Todos::summaryLessThan( t1, t2 );
00121   } else {
00122     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00123   }
00124 }
00125 
00126 bool KCalCore::Todos::startDateMoreThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00127 {
00128   const KDateTime d1= t1->dtStart();
00129   KDateTime::Comparison res = d1.compare( t2->dtStart() );
00130   if ( res == KDateTime::Equal ) {
00131     return Todos::summaryMoreThan( t1, t2 );
00132   } else {
00133     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00134   }
00135 }
00136 
00137 bool KCalCore::Todos::dueDateLessThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00138 {
00139   const KDateTime d1= t1->dtDue();
00140   KDateTime::Comparison res = d1.compare( t2->dtDue() );
00141   if ( res == KDateTime::Equal ) {
00142     return Todos::summaryLessThan( t1, t2 );
00143   } else {
00144     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00145   }
00146 }
00147 
00148 bool KCalCore::Todos::dueDateMoreThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00149 {
00150   const KDateTime d1= t1->dtDue();
00151   KDateTime::Comparison res = d1.compare( t2->dtDue() );
00152   if ( res == KDateTime::Equal ) {
00153     return Todos::summaryMoreThan( t1, t2 );
00154   } else {
00155     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00156   }
00157 }
00158 
00159 bool KCalCore::Todos::priorityLessThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00160 {
00161   if ( t1->priority() < t2->priority() ) {
00162     return true;
00163   } else if ( t1->priority() == t2->priority() ) {
00164     return Todos::summaryLessThan( t1, t2 );
00165   } else {
00166     return false;
00167   }
00168 }
00169 
00170 bool KCalCore::Todos::priorityMoreThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00171 {
00172   if ( t1->priority() > t2->priority() ) {
00173     return true;
00174   } else if ( t1->priority() == t2->priority() ) {
00175     return Todos::summaryMoreThan( t1, t2 );
00176   } else {
00177     return false;
00178   }
00179 }
00180 
00181 bool KCalCore::Todos::percentLessThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00182 {
00183   if ( t1->percentComplete() < t2->percentComplete() ) {
00184     return true;
00185   } else if ( t1->percentComplete() == t2->percentComplete() ) {
00186     return Todos::summaryLessThan( t1, t2 );
00187   } else {
00188     return false;
00189   }
00190 }
00191 
00192 bool KCalCore::Todos::percentMoreThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00193 {
00194   if ( t1->percentComplete() > t2->percentComplete() ) {
00195     return true;
00196   } else if ( t1->percentComplete() == t2->percentComplete() ) {
00197     return Todos::summaryMoreThan( t1, t2 );
00198   } else {
00199     return false;
00200   }
00201 }
00202 
00203 bool KCalCore::Todos::summaryLessThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00204 {
00205   return QString::compare( t1->summary(), t2->summary(), Qt::CaseInsensitive ) < 0;
00206 }
00207 
00208 bool KCalCore::Todos::summaryMoreThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00209 {
00210   return QString::compare( t1->summary(), t2->summary(), Qt::CaseInsensitive ) > 0;
00211 }
00212 
00213 bool KCalCore::Todos::createdLessThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00214 {
00215   const KDateTime d1= t1->created();
00216   KDateTime::Comparison res = d1.compare( t2->created() );
00217   if ( res == KDateTime::Equal ) {
00218     return Todos::summaryLessThan( t1, t2 );
00219   } else {
00220     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00221   }
00222 }
00223 
00224 bool KCalCore::Todos::createdMoreThan( const Todo::Ptr &t1, const Todo::Ptr &t2 )
00225 {
00226   const KDateTime d1= t1->created();
00227   KDateTime::Comparison res = d1.compare( t2->created() );
00228   if ( res == KDateTime::Equal ) {
00229     return Todos::summaryMoreThan( t1, t2 );
00230   } else {
00231     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00232   }
00233 }
00234 
00235 bool KCalCore::Incidences::dateLessThan( const Incidence::Ptr &i1,
00236                                          const Incidence::Ptr &i2 )
00237 {
00238   const KDateTime d1 = i1->dateTime( Incidence::RoleSort );
00239   const KDateTime d2 = i2->dateTime( Incidence::RoleSort );
00240 
00241   KDateTime::Comparison res = d1.compare( d2 );
00242   if ( res == KDateTime::Equal ) {
00243     return Incidences::summaryLessThan( i1, i2 );
00244   } else {
00245     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00246   }
00247 }
00248 
00249 bool KCalCore::Incidences::dateMoreThan( const Incidence::Ptr &i1,
00250                                          const Incidence::Ptr &i2 )
00251 {
00252   const KDateTime d1 = i1->dateTime( Incidence::RoleSort );
00253   const KDateTime d2 = i2->dateTime( Incidence::RoleSort );
00254 
00255   KDateTime::Comparison res = d1.compare( d2 );
00256   if ( res == KDateTime::Equal ) {
00257     return Incidences::summaryMoreThan( i1, i2 );
00258   } else {
00259     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00260   }
00261 }
00262 
00263 bool KCalCore::Incidences::createdLessThan( const Incidence::Ptr &i1,
00264                                             const Incidence::Ptr &i2 )
00265 {
00266   const KDateTime d1= i1->created();
00267   KDateTime::Comparison res = d1.compare( i2->created() );
00268   if ( res == KDateTime::Equal ) {
00269     return Incidences::summaryLessThan( i1, i2 );
00270   } else {
00271     return ( res & KDateTime::Before || res & KDateTime::AtStart );
00272   }
00273 }
00274 
00275 bool KCalCore::Incidences::createdMoreThan( const Incidence::Ptr &i1,
00276                                             const Incidence::Ptr &i2 )
00277 {
00278   const KDateTime d1= i1->created();
00279   KDateTime::Comparison res = d1.compare( i2->created() );
00280   if ( res == KDateTime::Equal ) {
00281     return Incidences::summaryMoreThan( i1, i2 );
00282   } else {
00283     return ( res & KDateTime::After || res & KDateTime::AtEnd );
00284   }
00285 }
00286 
00287 bool KCalCore::Incidences::summaryLessThan( const Incidence::Ptr &i1,
00288                                             const Incidence::Ptr &i2 )
00289 {
00290   return QString::compare( i1->summary(), i2->summary(), Qt::CaseInsensitive ) < 0;
00291 }
00292 
00293 bool KCalCore::Incidences::summaryMoreThan( const Incidence::Ptr &i1,
00294                                             const Incidence::Ptr &i2 )
00295 {
00296   return QString::compare( i1->summary(), i2->summary(), Qt::CaseInsensitive ) > 0;
00297 }
00298 
00299 bool KCalCore::Persons::countMoreThan( const Person::Ptr &p1, const Person::Ptr &p2 )
00300 {
00301   return p1->count() > p2->count();
00302 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:21 by doxygen 1.8.0 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-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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