|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of the CProfilesNamesArrayImpl |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CProfilesNamesArrayImpl.h" |
|
22 #include <collate.h> |
|
23 #include <MProfilesNamesArray.h> |
|
24 #include "CProfileNameImpl.h" |
|
25 #include "ProfileEng.hrh" |
|
26 #include "ProfileEngPanic.h" |
|
27 #include "ProfileEngineConstants.h" |
|
28 |
|
29 // LOCAL CONSTANTS AND MACROS |
|
30 const TInt KProfileNamesGranularity( 5 ); |
|
31 const TInt KMaxCollationLevel( 3 ); |
|
32 |
|
33 // ============================= LOCAL FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // SortOrder sort profile names. |
|
37 // Returns: zero: if the two objects are equal |
|
38 // negative value: if the first object is less than the second. |
|
39 // positive value: if the first object is greater than the second. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 TInt SortOrder( |
|
43 const CProfileNameImpl& aFirst, |
|
44 const CProfileNameImpl& aSecond ) |
|
45 { |
|
46 TInt firstId( aFirst.Id() ); |
|
47 TInt secondId( aSecond.Id() ); |
|
48 if( firstId < KProfileBaseDynamicProfileId || |
|
49 secondId < KProfileBaseDynamicProfileId ) |
|
50 { |
|
51 return firstId - secondId; |
|
52 } |
|
53 else |
|
54 { |
|
55 TCollationMethod m = *Mem::CollationMethodByIndex( 0 ); // get the standard method |
|
56 m.iFlags |= TCollationMethod::EIgnoreNone; |
|
57 return aFirst.Name().CompareC( aSecond.Name(), KMaxCollationLevel, &m ); |
|
58 } |
|
59 } |
|
60 |
|
61 // ============================ MEMBER FUNCTIONS =============================== |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CProfilesNamesArrayImpl::CProfilesNamesArrayImpl |
|
65 // C++ default constructor can NOT contain any code, that |
|
66 // might leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CProfilesNamesArrayImpl::CProfilesNamesArrayImpl() |
|
70 : iProfilesNames( KProfileNamesGranularity ), iNullName( KNullDesC ) |
|
71 { |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CProfilesNamesArrayImpl::NewL |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CProfilesNamesArrayImpl* CProfilesNamesArrayImpl::NewL() |
|
80 { |
|
81 return new( ELeave ) CProfilesNamesArrayImpl; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CProfilesNamesArrayImpl::NewLC |
|
86 // Two-phased constructor. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CProfilesNamesArrayImpl* CProfilesNamesArrayImpl::NewLC() |
|
90 { |
|
91 CProfilesNamesArrayImpl* self = new( ELeave ) CProfilesNamesArrayImpl; |
|
92 |
|
93 CleanupStack::PushL( self ); |
|
94 |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 // Destructor |
|
100 CProfilesNamesArrayImpl::~CProfilesNamesArrayImpl() |
|
101 { |
|
102 iProfilesNames.ResetAndDestroy(); |
|
103 } |
|
104 |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CProfilesNamesArrayImpl::InsertInOrder |
|
108 // |
|
109 // (other items were commented in a header). |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 TInt CProfilesNamesArrayImpl::InsertInOrder( |
|
113 const CProfileNameImpl* aProfileName ) |
|
114 { |
|
115 __ASSERT_DEBUG( aProfileName, |
|
116 ProfileEngPanic::Panic( EProfileEngPanicNullPointer ) ); |
|
117 |
|
118 return iProfilesNames.InsertInOrder( |
|
119 aProfileName, TLinearOrder<CProfileNameImpl>( SortOrder ) ); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CProfilesNamesArrayImpl::Append |
|
124 // |
|
125 // (other items were commented in a header). |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CProfilesNamesArrayImpl::Append( |
|
129 const CProfileNameImpl* aProfileName ) |
|
130 { |
|
131 __ASSERT_DEBUG( aProfileName, |
|
132 ProfileEngPanic::Panic( EProfileEngPanicNullPointer ) ); |
|
133 |
|
134 return iProfilesNames.Append( aProfileName ); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CProfilesNamesArrayImpl::FindNameById |
|
139 // |
|
140 // (other items were commented in a header). |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 const TDesC& CProfilesNamesArrayImpl::FindNameById( |
|
144 TInt aId ) |
|
145 { |
|
146 const MProfileName* profileName = ProfileName( FindById( aId ) ); |
|
147 if( profileName ) |
|
148 { |
|
149 return profileName->Name(); |
|
150 } |
|
151 return iNullName; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CProfilesNamesArrayImpl::ProfileName |
|
156 // |
|
157 // (other items were commented in a header). |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 const MProfileName* CProfilesNamesArrayImpl::ProfileName( |
|
161 TInt aIndex ) const |
|
162 { |
|
163 TInt count( iProfilesNames.Count() ); |
|
164 if( aIndex < 0 || |
|
165 aIndex >= count ) |
|
166 { |
|
167 return NULL; |
|
168 } |
|
169 return iProfilesNames[aIndex]; |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CProfilesNamesArrayImpl::FindById |
|
174 // |
|
175 // (other items were commented in a header). |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CProfilesNamesArrayImpl::FindById( |
|
179 TInt aId ) const |
|
180 { |
|
181 TInt count( iProfilesNames.Count() ); |
|
182 for( TInt i( 0 ) ; i < count ; ++i ) |
|
183 { |
|
184 if( iProfilesNames[i]->Id() == aId ) |
|
185 { |
|
186 return i; |
|
187 } |
|
188 } |
|
189 return KErrNotFound; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CProfilesNamesArrayImpl::FindByName |
|
194 // |
|
195 // (other items were commented in a header). |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CProfilesNamesArrayImpl::FindByName( |
|
199 const TDesC& aProfileName ) const |
|
200 { |
|
201 TInt count( iProfilesNames.Count() ); |
|
202 for( TInt i( 0 ) ; i < count ; ++i ) |
|
203 { |
|
204 if( aProfileName.Compare( iProfilesNames[i]->Name() ) == 0 ) |
|
205 { |
|
206 return i; |
|
207 } |
|
208 } |
|
209 return KErrNotFound; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CProfilesNamesArrayImpl::MdcaCount |
|
214 // |
|
215 // (other items were commented in a header). |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TInt CProfilesNamesArrayImpl::MdcaCount() const |
|
219 { |
|
220 return iProfilesNames.Count(); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CProfilesNamesArrayImpl::MdcaPoint |
|
225 // |
|
226 // (other items were commented in a header). |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TPtrC CProfilesNamesArrayImpl::MdcaPoint( |
|
230 TInt aIndex ) const |
|
231 { |
|
232 TInt count( iProfilesNames.Count() ); |
|
233 if( aIndex < 0 || |
|
234 aIndex >= count ) |
|
235 { |
|
236 return iNullName; |
|
237 } |
|
238 return iProfilesNames[aIndex]->Name(); |
|
239 } |
|
240 |
|
241 // End of File |