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

kabc

  • 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
24using namespace KABC;
25
26SortMode::~SortMode()
27{
28}
29
30class NameSortMode::Private
31{
32 public:
33 NameType mNameType;
34 bool mAscendingOrder;
35};
36
37NameSortMode::NameSortMode()
38 : d( new Private )
39{
40 d->mNameType = FormattedName;
41 d->mAscendingOrder = true;
42}
43
44NameSortMode::NameSortMode( NameType type, bool ascending )
45 : d( new Private )
46{
47 d->mNameType = type;
48 d->mAscendingOrder = ascending;
49}
50
51NameSortMode::~NameSortMode()
52{
53 delete d;
54}
55
56bool 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
82class FieldSortMode::Private
83{
84 public:
85 KABC::Field *mField;
86 bool mAscendingOrder;
87};
88
89FieldSortMode::FieldSortMode( KABC::Field *field, bool ascending )
90 : d( new Private )
91{
92 d->mField = field;
93 d->mAscendingOrder = ascending;
94}
95
96FieldSortMode::~FieldSortMode()
97{
98 delete d;
99}
100
101bool 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::Addressee
address book entry
Definition addressee.h:79
KABC::Addressee::familyName
QString familyName() const
Return family name.
Definition addressee.cpp:599
KABC::Addressee::formattedName
QString formattedName() const
Return formatted name.
Definition addressee.cpp:579
KABC::Addressee::givenName
QString givenName() const
Return given name.
Definition addressee.cpp:619
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::FieldSortMode::FieldSortMode
FieldSortMode(KABC::Field *field, bool ascending=true)
Constructor.
Definition sortmode.cpp:89
KABC::Field
Represents a field in the Addressbook.
Definition field.h:47
KABC::Field::value
virtual QString value(const KABC::Addressee &)
Returns a string representation of the value the field has in the given Addressee.
Definition field.cpp:231
KABC::NameSortMode::NameSortMode
NameSortMode()
Constructor.
Definition sortmode.cpp:37
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::NameSortMode::NameType
NameType
Specifies which parts of the name are used for comparison.
Definition sortmode.h:60
KABC::NameSortMode::FormattedName
@ FormattedName
use the formatted name, e.g.
Definition sortmode.h:61
KABC::NameSortMode::GivenName
@ GivenName
use the first name, e.g.
Definition sortmode.h:63
KABC::NameSortMode::FamilyName
@ FamilyName
use the last name, e.g.
Definition sortmode.h:62
KABC
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition address.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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