|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Contact sorter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cvimpststoragecontactsorter.h" |
|
21 #include "mvimpststoragecontact.h" |
|
22 #include "tvimpstenums.h" |
|
23 #include "cvimpststoragedefs.h" |
|
24 #include "uiservicetabtracer.h" |
|
25 |
|
26 // The order of contacts if sorted by status |
|
27 const TInt KConstOnline = 1; |
|
28 const TInt KConstBusy = 2; |
|
29 const TInt KConstAway = 3; |
|
30 const TInt KConstServiceOut = 4; |
|
31 const TInt KConstOnPhone = 5; |
|
32 const TInt KConstInvisible = 6; |
|
33 const TInt KConstOffline = 7; |
|
34 const TInt KConstCallForward = 8; |
|
35 const TInt KConstUnknown = 9; |
|
36 |
|
37 // local functions |
|
38 // sorting algorithms, you can add new one to extend functionality |
|
39 |
|
40 |
|
41 // Compares alphabetically using MVIMPSTStorageContact::Identification and |
|
42 // TDesC::CompareC |
|
43 TInt CompareAlphabetically( const MVIMPSTStorageContact& aFirst, |
|
44 const MVIMPSTStorageContact& aSecond ) |
|
45 { |
|
46 TRACER_AUTO; |
|
47 return aFirst.Name().CompareC( aSecond.Name(), |
|
48 KCollationLevel, NULL ); |
|
49 } |
|
50 |
|
51 |
|
52 // Group the contact by it's status. |
|
53 TInt OrderContact( const MVIMPSTStorageContact& aContact ) |
|
54 { |
|
55 TRACER_AUTO; |
|
56 // Contact is not blocked, group by presence status |
|
57 switch( aContact.OnlineStatus() ) |
|
58 { |
|
59 case TVIMPSTEnums::EOnline: |
|
60 { |
|
61 return KConstOnline; // First group, contact is online |
|
62 } |
|
63 case TVIMPSTEnums::EDoNotDisturb: |
|
64 case TVIMPSTEnums::EBusy: |
|
65 { |
|
66 return KConstBusy; // second group, contact is busy/donotdisturb |
|
67 } |
|
68 case TVIMPSTEnums::EOnPhone: |
|
69 { |
|
70 return KConstOnPhone; //fifth group, contact is onphone |
|
71 } |
|
72 case TVIMPSTEnums::EInvisible: |
|
73 { |
|
74 return KConstInvisible; // sixth group, contact is invisible |
|
75 } |
|
76 case TVIMPSTEnums::EAway: |
|
77 { |
|
78 return KConstAway; // third group, contact is away |
|
79 } |
|
80 case TVIMPSTEnums::EOffline: |
|
81 { |
|
82 return KConstOffline; // seventh group, contact is offline |
|
83 } |
|
84 case TVIMPSTEnums::ECallForward: |
|
85 { |
|
86 return KConstCallForward; // eight group, contact state is callforward |
|
87 } |
|
88 case TVIMPSTEnums::EServiceOut: |
|
89 { |
|
90 return KConstServiceOut; // fourth group, contact is serviceout(has ony pstn or msisdn number) |
|
91 } |
|
92 default: |
|
93 { |
|
94 return KConstUnknown; // unknown status |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 // Compares by contact status, -1 = aFirst is greater, 1 = aSecond is greater. |
|
100 TInt CompareByPresence( const MVIMPSTStorageContact& aFirst, |
|
101 const MVIMPSTStorageContact& aSecond ) |
|
102 { |
|
103 TRACER_AUTO; |
|
104 TInt firstGroup( OrderContact( aFirst ) ); |
|
105 TInt secondGroup( OrderContact( aSecond ) ); |
|
106 |
|
107 // If both contacts belong to same group, sort alphabetically |
|
108 if( firstGroup == secondGroup ) |
|
109 { |
|
110 return CompareAlphabetically( aFirst, aSecond ); |
|
111 } |
|
112 |
|
113 // Otherwise return the difference of groups |
|
114 return firstGroup - secondGroup; |
|
115 } |
|
116 |
|
117 // ================= MEMBER FUNCTIONS ======================= |
|
118 |
|
119 // Two-phased constructor. |
|
120 CVIMPSTStorageContactSorter* CVIMPSTStorageContactSorter::NewL() |
|
121 { |
|
122 TRACER_AUTO; |
|
123 CVIMPSTStorageContactSorter* self = new( ELeave ) CVIMPSTStorageContactSorter(); |
|
124 return self; |
|
125 } |
|
126 |
|
127 // Destructor |
|
128 CVIMPSTStorageContactSorter::~CVIMPSTStorageContactSorter() |
|
129 { |
|
130 TRACER_AUTO; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // CVIMPSTStorageContactSorter::Sort( RPointerArray<MVIMPSTStorageContact>& aList ) |
|
135 // Sorts given array. |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 void CVIMPSTStorageContactSorter::Sort( RPointerArray< MVIMPSTStorageContact >& aList ) |
|
139 { |
|
140 TRACER_AUTO; |
|
141 aList.Sort( iAlgorithm ); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CVIMPSTStorageContactSorter::Compare( const MVIMPSTStorageContact& aFirst, |
|
146 // const MVIMPSTStorageContact& aSecond ) const |
|
147 // Get function pointer from inside of TLinearOrder and |
|
148 // execute the function. |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 TInt CVIMPSTStorageContactSorter::Compare( const MVIMPSTStorageContact& aFirst, |
|
152 const MVIMPSTStorageContact& aSecond ) const |
|
153 { |
|
154 TRACER_AUTO; |
|
155 return iAlgorithm.operator TGeneralLinearOrder()( &aFirst, &aSecond ); |
|
156 } |
|
157 |
|
158 // C++ default constructor can NOT contain any code, that |
|
159 // might leave. |
|
160 // Default algorithm is alphabetic. It is changed later in ConstructL. |
|
161 // |
|
162 CVIMPSTStorageContactSorter::CVIMPSTStorageContactSorter() : |
|
163 iAlgorithm( *CompareByPresence ) |
|
164 { |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // CVIMPSTStorageContactSorter::SetSortAlgorithm() |
|
169 // Get setting item value and choose algorithm. |
|
170 // New algorithms can be added to this method. |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 void CVIMPSTStorageContactSorter::SetSortAlgorithm( |
|
174 MVIMPSTStorageContact::TSortAlgorithm aAlgorithm ) |
|
175 { |
|
176 TRACER_AUTO; |
|
177 switch( aAlgorithm ) |
|
178 { |
|
179 case MVIMPSTStorageContact::ECompareByPresence: |
|
180 { |
|
181 iAlgorithm = |
|
182 TLinearOrder< MVIMPSTStorageContact > ( *CompareByPresence ); |
|
183 break; |
|
184 } |
|
185 |
|
186 case MVIMPSTStorageContact::ECompareAlphabetically: // flowthrough |
|
187 default : |
|
188 { |
|
189 iAlgorithm = |
|
190 TLinearOrder< MVIMPSTStorageContact > ( *CompareAlphabetically ); |
|
191 break; |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CVIMPSTStorageContactSorter::InsertOrder() |
|
198 // Get setting item value and choose algorithm. |
|
199 // New algorithms can be added to this method. |
|
200 // --------------------------------------------------------- |
|
201 // |
|
202 TLinearOrder< MVIMPSTStorageContact >& CVIMPSTStorageContactSorter::InsertOrder() |
|
203 { |
|
204 return iAlgorithm; |
|
205 } |
|
206 |
|
207 // End of file |