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 | #ifndef KABC_SORTMODE_H |
22 | #define KABC_SORTMODE_H |
23 | |
24 | #include "kabc_export.h" |
25 | #include "addressee.h" |
26 | |
27 | namespace KABC { |
28 | |
29 | class Field; |
30 | |
31 | /** |
32 | @short Sort method for sorting an addressee list. |
33 | |
34 | This interface should be reimplemented by classes which shall act as |
35 | SortModes for KABC::AddresseeList. |
36 | */ |
37 | class KABC_EXPORT SortMode |
38 | { |
39 | public: |
40 | virtual ~SortMode(); |
41 | |
42 | /** |
43 | Reimplement this method and return whether the first contact is 'smaller' |
44 | than the second. |
45 | */ |
46 | virtual bool lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const = 0; |
47 | }; |
48 | |
49 | /** |
50 | @short Implements comparison by name. |
51 | |
52 | This class implements a comparison of two Addressee objects by name. |
53 | */ |
54 | class KABC_EXPORT NameSortMode : public SortMode |
55 | { |
56 | public: |
57 | /** |
58 | Specifies which parts of the name are used for comparison. |
59 | */ |
60 | enum NameType { |
61 | FormattedName, /**< use the formatted name, e.g. "John Doe" */ |
62 | FamilyName, /**< use the last name, e.g. "Doe" */ |
63 | GivenName /**< use the first name, e.g. "John" */ |
64 | }; |
65 | |
66 | /** |
67 | Constructor. |
68 | |
69 | Creates a NameSortMethod with FormattedName as name type set. |
70 | */ |
71 | NameSortMode(); |
72 | |
73 | /** |
74 | Constructor. |
75 | |
76 | Creates a NameSortMethod with the specified name type. |
77 | |
78 | @param type The name type. |
79 | @param ascending if @c true, Addressee object are sorted in |
80 | ascending order; if @c false, objects are sorted in |
81 | descending order |
82 | */ |
83 | explicit NameSortMode( NameType type, bool ascending = true ); |
84 | |
85 | virtual ~NameSortMode(); |
86 | |
87 | /** |
88 | Returns whether the first contact is 'smaller' then the second. |
89 | */ |
90 | virtual bool lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const; |
91 | |
92 | private: |
93 | class Private; |
94 | Private *const d; |
95 | |
96 | Q_DISABLE_COPY( NameSortMode ) |
97 | }; |
98 | |
99 | /** |
100 | @short Implements comparison by an arbitrary field. |
101 | |
102 | This class implements a comparison of two Addressee objects by the |
103 | value of an arbitrary field. |
104 | */ |
105 | class KABC_EXPORT FieldSortMode : public SortMode |
106 | { |
107 | public: |
108 | /** |
109 | Constructor. |
110 | |
111 | Creates a FieldSortMethod with the specified @p field. |
112 | |
113 | @param field The field. |
114 | @param ascending if @c true, Addressee object are sorted in |
115 | ascending order; if @c false, objects are sorted in |
116 | descending order |
117 | */ |
118 | explicit FieldSortMode( KABC::Field *field, bool ascending = true ); |
119 | |
120 | virtual ~FieldSortMode(); |
121 | |
122 | /** |
123 | Returns whether the first contact is 'smaller' then the second. |
124 | */ |
125 | virtual bool lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const; |
126 | |
127 | private: |
128 | class Private; |
129 | Private *const d; |
130 | |
131 | Q_DISABLE_COPY( FieldSortMode ) |
132 | }; |
133 | |
134 | } |
135 | |
136 | #endif |
137 | |