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

kabc

  • sources
  • kde-4.12
  • kdepimlibs
  • kabc
sortmode.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "sortmode.h"
22 #include "field.h"
23 
24 using namespace KABC;
25 
26 SortMode::~SortMode()
27 {
28 }
29 
30 class NameSortMode::Private
31 {
32  public:
33  NameType mNameType;
34  bool mAscendingOrder;
35 };
36 
37 NameSortMode::NameSortMode()
38  : d( new Private )
39 {
40  d->mNameType = FormattedName;
41  d->mAscendingOrder = true;
42 }
43 
44 NameSortMode::NameSortMode( NameType type, bool ascending )
45  : d( new Private )
46 {
47  d->mNameType = type;
48  d->mAscendingOrder = ascending;
49 }
50 
51 NameSortMode::~NameSortMode()
52 {
53  delete d;
54 }
55 
56 bool NameSortMode::lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const
57 {
58  bool lesser = false;
59 
60  switch ( d->mNameType ) {
61  case FormattedName:
62  lesser = QString::localeAwareCompare( first.formattedName(), second.formattedName() ) < 0;
63  break;
64  case FamilyName:
65  lesser = QString::localeAwareCompare( first.familyName(), second.familyName() ) < 0;
66  break;
67  case GivenName:
68  lesser = QString::localeAwareCompare( first.givenName(), second.givenName() ) < 0;
69  break;
70  default:
71  lesser = false;
72  break;
73  }
74 
75  if ( !d->mAscendingOrder ) {
76  lesser = !lesser;
77  }
78 
79  return lesser;
80 }
81 
82 class FieldSortMode::Private
83 {
84  public:
85  KABC::Field *mField;
86  bool mAscendingOrder;
87 };
88 
89 FieldSortMode::FieldSortMode( KABC::Field *field, bool ascending )
90  : d( new Private )
91 {
92  d->mField = field;
93  d->mAscendingOrder = ascending;
94 }
95 
96 FieldSortMode::~FieldSortMode()
97 {
98  delete d;
99 }
100 
101 bool FieldSortMode::lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const
102 {
103  if ( !d->mField ) {
104  return false;
105  } else {
106  bool lesser =
107  QString::localeAwareCompare( d->mField->value( first ), d->mField->value( second ) ) < 0;
108  if ( !d->mAscendingOrder ) {
109  lesser = !lesser;
110  }
111 
112  return lesser;
113  }
114 }
KABC::NameSortMode::NameSortMode
NameSortMode()
Constructor.
Definition: sortmode.cpp:37
KABC::Addressee::familyName
QString familyName() const
Return family name.
Definition: addressee.cpp:436
KABC::Addressee::formattedName
QString formattedName() const
Return formatted name.
Definition: addressee.cpp:416
KABC::FieldSortMode::lesser
virtual bool lesser(const KABC::Addressee &first, const KABC::Addressee &second) const
Returns whether the first contact is 'smaller' then the second.
Definition: sortmode.cpp:101
KABC::NameSortMode::GivenName
use the first name, e.g.
Definition: sortmode.h:63
KABC::NameSortMode::NameType
NameType
Specifies which parts of the name are used for comparison.
Definition: sortmode.h:60
KABC::NameSortMode::FamilyName
use the last name, e.g.
Definition: sortmode.h:62
KABC::NameSortMode::FormattedName
use the formatted name, e.g.
Definition: sortmode.h:61
KABC::Addressee::givenName
QString givenName() const
Return given name.
Definition: addressee.cpp:456
KABC::Field
Represents a field in the Addressbook.
Definition: field.h:46
KABC::Addressee
address book entry
Definition: addressee.h:74
KABC::NameSortMode::lesser
virtual bool lesser(const KABC::Addressee &first, const KABC::Addressee &second) const
Returns whether the first contact is 'smaller' then the second.
Definition: sortmode.cpp:56
KABC::FieldSortMode::FieldSortMode
FieldSortMode(KABC::Field *field, bool ascending=true)
Constructor.
Definition: sortmode.cpp:89
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • 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