|
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 CPhoneBubbleMapping class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cphonebubblemapping.h" |
|
21 #include "pevirtualengine.h" |
|
22 #include "phoneui.pan" |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CPhoneBubbleMapping::CPhoneBubbleMapping |
|
28 // C++ default constructor can NOT contain any code, that |
|
29 // might leave. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CPhoneBubbleMapping::CPhoneBubbleMapping() |
|
33 { |
|
34 } |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPhoneBubbleMapping::ConstructL |
|
38 // Symbian 2nd phase constructor can leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 void CPhoneBubbleMapping::ConstructL( TInt aMaximumAmount ) |
|
42 { |
|
43 iMappingReserve = aMaximumAmount; |
|
44 iMapping = new ( ELeave ) CMappingArray( aMaximumAmount ); |
|
45 iMapping->SetReserveL( aMaximumAmount ); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CPhoneBubbleMapping::NewL |
|
50 // Two-phased constructor. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CPhoneBubbleMapping* CPhoneBubbleMapping::NewL( |
|
54 TInt aMaximumAmount ) |
|
55 { |
|
56 CPhoneBubbleMapping* self = |
|
57 new ( ELeave ) CPhoneBubbleMapping; |
|
58 |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL( aMaximumAmount ); |
|
61 CleanupStack::Pop( self ); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 CPhoneBubbleMapping::~CPhoneBubbleMapping() |
|
67 { |
|
68 delete iMapping; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------- |
|
72 // CPhoneBubbleMapping::FindBubbleByCall |
|
73 // --------------------------------------------------------- |
|
74 // |
|
75 TBool CPhoneBubbleMapping::FindBubbleByCall( |
|
76 TInt aCallId, |
|
77 CBubbleManager::TBubbleId& aId ) const |
|
78 { |
|
79 const TInt count = iMapping->Count(); |
|
80 TInt index; |
|
81 TBool result = EFalse; |
|
82 |
|
83 for ( index = 0; index < count; index++ ) |
|
84 { |
|
85 TMappingItem& item = iMapping->At( index ); |
|
86 |
|
87 if ( aCallId == item.iCallId ) |
|
88 { |
|
89 result = ETrue; |
|
90 aId = item.iBubbleId; |
|
91 break; |
|
92 } |
|
93 |
|
94 } |
|
95 |
|
96 return result; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CPhoneBubbleMapping::FindCallByBubble |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 TBool CPhoneBubbleMapping::FindCallByBubble( |
|
104 CBubbleManager::TBubbleId aId, |
|
105 TInt& aCallId ) const |
|
106 { |
|
107 const TInt count = iMapping->Count(); |
|
108 TInt index; |
|
109 TBool result = EFalse; |
|
110 |
|
111 for ( index = 0; index < count; index++ ) |
|
112 { |
|
113 TMappingItem& item = iMapping->At( index ); |
|
114 |
|
115 if ( aId == item.iBubbleId ) |
|
116 { |
|
117 result = ETrue; |
|
118 aCallId = item.iCallId; |
|
119 break; |
|
120 } |
|
121 } |
|
122 |
|
123 return result; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CPhoneBubbleMapping::FindThumbnailByCall |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 const CFbsBitmap* CPhoneBubbleMapping::FindThumbnailByCall( |
|
131 TInt aCallId ) const |
|
132 { |
|
133 TInt index; |
|
134 const CFbsBitmap* thumbnail = NULL; |
|
135 |
|
136 if ( FindIndexByCall( aCallId, index ) ) |
|
137 { |
|
138 thumbnail = ThumbnailAt( index ); |
|
139 } |
|
140 |
|
141 return thumbnail; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CPhoneBubbleMapping::AddToMappingL |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 void CPhoneBubbleMapping::AddToMappingL( |
|
149 CBubbleManager::TBubbleId aId, |
|
150 TInt aCallId, |
|
151 CBubbleManager::TPhoneCallState aCallState, |
|
152 CFbsBitmap* aThumbnail ) |
|
153 { |
|
154 CBubbleManager::TBubbleId bubbleId; |
|
155 |
|
156 if ( !FindBubbleByCall( aCallId, bubbleId ) ) |
|
157 { |
|
158 TMappingItem item; |
|
159 item.iBubbleId = aId; |
|
160 item.iCallId = aCallId; |
|
161 item.iThumbnail = aThumbnail; |
|
162 item.iCallState = aCallState; |
|
163 |
|
164 if ( iMapping->Count() < iMappingReserve ) |
|
165 { |
|
166 iMapping->AppendL( item ); // Doesn't leave. |
|
167 return; |
|
168 } |
|
169 } |
|
170 Panic( EPhoneViewInvariant ); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CPhoneBubbleMapping::RemoveFromMapping |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CPhoneBubbleMapping::RemoveFromMapping( |
|
178 TInt aCallId ) |
|
179 { |
|
180 const TInt count = iMapping->Count(); |
|
181 TInt index; |
|
182 |
|
183 for ( index = 0; index < count; index++ ) |
|
184 { |
|
185 TMappingItem& item = iMapping->At( index ); |
|
186 |
|
187 if ( aCallId == item.iCallId ) |
|
188 { |
|
189 iMapping->Delete( index ); |
|
190 iMapping->Compress(); |
|
191 return; |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CPhoneBubbleMapping::ItemCount |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 TInt CPhoneBubbleMapping::ItemCount() const |
|
201 { |
|
202 return iMapping->Count(); |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CPhoneBubbleMapping::BubbleAt |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 CBubbleManager::TBubbleId CPhoneBubbleMapping::BubbleAt( |
|
210 TInt aIndex ) const |
|
211 { |
|
212 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iMapping->Count(), |
|
213 Panic( EPhoneViewIndexOutOfBounds ) ); |
|
214 return iMapping->At( aIndex ).iBubbleId; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------- |
|
218 // CPhoneBubbleMapping::CallAt |
|
219 // --------------------------------------------------------- |
|
220 // |
|
221 TInt CPhoneBubbleMapping::CallIdAt( |
|
222 TInt aIndex ) const |
|
223 { |
|
224 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iMapping->Count(), |
|
225 Panic( EPhoneViewIndexOutOfBounds ) ); |
|
226 return iMapping->At( aIndex ).iCallId; |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------- |
|
230 // CPhoneBubbleMapping::ThumbnailAt |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 const CFbsBitmap* CPhoneBubbleMapping::ThumbnailAt( |
|
234 TInt aIndex ) const |
|
235 { |
|
236 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iMapping->Count(), |
|
237 Panic( EPhoneViewIndexOutOfBounds ) ); |
|
238 return iMapping->At( aIndex ).iThumbnail; |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------- |
|
242 // CPhoneBubbleMapping::SetThumbnailAt |
|
243 // --------------------------------------------------------- |
|
244 // |
|
245 void CPhoneBubbleMapping::SetThumbnailAt( |
|
246 TInt aIndex, |
|
247 CFbsBitmap* aThumbnail ) |
|
248 { |
|
249 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iMapping->Count(), |
|
250 Panic( EPhoneViewIndexOutOfBounds ) ); |
|
251 |
|
252 TMappingItem& item = iMapping->At( aIndex ); |
|
253 item.iThumbnail = aThumbnail; |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------- |
|
257 // CPhoneBubbleMapping::SetThumbnailByCall |
|
258 // --------------------------------------------------------- |
|
259 // |
|
260 void CPhoneBubbleMapping::SetThumbnailByCall( |
|
261 TInt aCallId, |
|
262 CFbsBitmap* aThumbnail ) |
|
263 { |
|
264 TInt index; |
|
265 |
|
266 // if a matching bubble is found |
|
267 if ( FindIndexByCall( aCallId, index ) ) |
|
268 { |
|
269 SetThumbnailAt( index, aThumbnail ); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // CPhoneBubbleMapping::CallStateAt |
|
275 // --------------------------------------------------------- |
|
276 // |
|
277 CBubbleManager::TPhoneCallState CPhoneBubbleMapping::CallStateAt( |
|
278 TInt aIndex ) const |
|
279 { |
|
280 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iMapping->Count(), |
|
281 Panic( EPhoneViewIndexOutOfBounds ) ); |
|
282 return iMapping->At( aIndex ).iCallState; |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------- |
|
286 // CPhoneBubbleMapping::SetCallStateAt |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 void CPhoneBubbleMapping::SetCallStateAt( |
|
290 TInt aIndex, |
|
291 CBubbleManager::TPhoneCallState aCallState ) |
|
292 { |
|
293 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iMapping->Count(), |
|
294 Panic( EPhoneViewIndexOutOfBounds ) ); |
|
295 TMappingItem& item = iMapping->At( aIndex ); |
|
296 item.iCallState = aCallState; |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------- |
|
300 // CPhoneBubbleMapping::SetCallStateByCall |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 void CPhoneBubbleMapping::SetCallStateByCall( |
|
304 TInt aCallId, |
|
305 CBubbleManager::TPhoneCallState aCallState ) |
|
306 { |
|
307 TInt index; |
|
308 |
|
309 // if a matching bubble is found |
|
310 if ( FindIndexByCall( aCallId, index ) ) |
|
311 { |
|
312 SetCallStateAt( index, aCallState ); |
|
313 } |
|
314 } |
|
315 |
|
316 // --------------------------------------------------------- |
|
317 // CPhoneBubbleMapping::FindCallStateByCall |
|
318 // --------------------------------------------------------- |
|
319 // |
|
320 CBubbleManager::TPhoneCallState CPhoneBubbleMapping::FindCallStateByCall( |
|
321 TInt aCallId ) const |
|
322 { |
|
323 TInt index; |
|
324 CBubbleManager::TPhoneCallState callState = CBubbleManager::ENone; |
|
325 |
|
326 if ( FindIndexByCall( aCallId, index ) ) |
|
327 { |
|
328 callState = CallStateAt( index ); |
|
329 } |
|
330 |
|
331 return callState; |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------- |
|
335 // CPhoneBubbleMapping::FindCallIdByCallState |
|
336 // --------------------------------------------------------- |
|
337 // |
|
338 TInt CPhoneBubbleMapping::FindCallIdByCallState ( |
|
339 CBubbleManager::TPhoneCallState aCallState ) |
|
340 { |
|
341 const TInt count = iMapping->Count(); |
|
342 TInt index; |
|
343 |
|
344 for ( index = 0; index < count; index++ ) |
|
345 { |
|
346 if ( CallStateAt( index ) == aCallState ) |
|
347 { |
|
348 return CallIdAt( index ); |
|
349 } |
|
350 } |
|
351 return KErrNotFound; // Not found CallId by this callState |
|
352 } |
|
353 |
|
354 // --------------------------------------------------------- |
|
355 // CPhoneBubbleMapping::FindIndexByCall |
|
356 // --------------------------------------------------------- |
|
357 // |
|
358 TBool CPhoneBubbleMapping::FindIndexByCall( |
|
359 TInt aCallId, |
|
360 TInt& aIndex ) const |
|
361 { |
|
362 TBool result = EFalse; |
|
363 |
|
364 for ( aIndex = 0; aIndex < iMapping->Count(); aIndex ++ ) |
|
365 { |
|
366 TMappingItem& item = iMapping->At( aIndex ); |
|
367 |
|
368 if ( aCallId == item.iCallId ) |
|
369 { |
|
370 // Horray, we found it |
|
371 result = ETrue; |
|
372 break; |
|
373 } |
|
374 } |
|
375 |
|
376 return result; |
|
377 } |
|
378 |
|
379 // End of File |