|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 contact navigator. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2ContactNavigation.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2IconInfo.h" |
|
23 #include <MPbk2NavigationObserver.h> |
|
24 #include <CPbk2IconFactory.h> |
|
25 #include <CPbk2AppUiBase.h> |
|
26 #include <CPbk2TabGroupContainer.h> |
|
27 #include <CPbk2IconInfoContainer.h> |
|
28 #include <Pbk2UID.h> |
|
29 |
|
30 // Virtual Phonebook |
|
31 #include <MVPbkContactViewBase.h> |
|
32 #include <MVPbkViewContact.h> |
|
33 |
|
34 // System includes |
|
35 #include <aknnavide.h> |
|
36 #include <eikspane.h> |
|
37 #include <StringLoader.h> |
|
38 #include <akntabgrp.h> |
|
39 #include <AknsUtils.h> |
|
40 |
|
41 // Debugging headers |
|
42 #include <Pbk2Debug.h> |
|
43 |
|
44 /// Unnamed namespace for local definitions |
|
45 namespace { |
|
46 |
|
47 // LOCAL CONSTANTS AND MACROS |
|
48 |
|
49 const TInt KOneContact = 1; |
|
50 const TInt KZeroContacts = 0; |
|
51 const TInt KNaviDirectionLeft = -1; |
|
52 const TInt KNaviDirectionRight = 1; |
|
53 const TInt KNaviDirectionNone = 0; |
|
54 const TInt KGranularity( 2 ); |
|
55 |
|
56 #ifdef _DEBUG |
|
57 |
|
58 enum TPanicCode |
|
59 { |
|
60 EPanicPreCond_NavigateContactL = 1, |
|
61 }; |
|
62 |
|
63 void Panic(TPanicCode aReason) |
|
64 { |
|
65 _LIT( KPanicText, "CPbk2ContactNavigation" ); |
|
66 User::Panic( KPanicText, aReason ); |
|
67 } |
|
68 |
|
69 #endif // _DEBUG |
|
70 |
|
71 } /// namespace |
|
72 |
|
73 |
|
74 // -------------------------------------------------------------------------- |
|
75 // CPbk2ContactNavigation::CPbk2ContactNavigation |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 CPbk2ContactNavigation::CPbk2ContactNavigation |
|
79 ( TUid aViewId, MPbk2NavigationObserver& aObserver, |
|
80 MPbk2ContactNavigationLoader& aNavigationLoader, |
|
81 TArray<MVPbkContactStore*> aStoreList, |
|
82 const TInt aNavigatorFormatResourceId ) : |
|
83 CPbk2NavigationBase( aObserver, aNavigationLoader, aStoreList ), |
|
84 iViewId( aViewId ), |
|
85 iNavigatorFormatResourceId( aNavigatorFormatResourceId ) |
|
86 { |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2ContactNavigation::~CPbk2ContactNavigation |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 CPbk2ContactNavigation::~CPbk2ContactNavigation() |
|
94 { |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CPbk2ContactNavigation::NewL |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 CPbk2ContactNavigation* CPbk2ContactNavigation::NewL |
|
102 ( TUid aViewId, MPbk2NavigationObserver& aObserver, |
|
103 MPbk2ContactNavigationLoader& aNavigationLoader, |
|
104 TArray<MVPbkContactStore*> aStoreList, |
|
105 const TInt aNavigatorFormatResourceId ) |
|
106 { |
|
107 CPbk2ContactNavigation* self = new ( ELeave ) CPbk2ContactNavigation |
|
108 ( aViewId, aObserver, aNavigationLoader, aStoreList, |
|
109 aNavigatorFormatResourceId ); |
|
110 CleanupStack::PushL( self ); |
|
111 self->ConstructL(); |
|
112 CleanupStack::Pop( self ); |
|
113 return self; |
|
114 } |
|
115 |
|
116 // -------------------------------------------------------------------------- |
|
117 // CPbk2ContactNavigation::ConstructL |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 void CPbk2ContactNavigation::ConstructL() |
|
121 { |
|
122 BaseConstructL(); |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CPbk2ContactNavigation::UpdateNaviIndicatorsL |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 void CPbk2ContactNavigation::UpdateNaviIndicatorsL |
|
130 ( const MVPbkContactLink& aContactLink ) const |
|
131 { |
|
132 // Get navigation decorator |
|
133 CAknNavigationControlContainer* naviPane = |
|
134 static_cast<CAknNavigationControlContainer*> |
|
135 ( CEikonEnv::Static()->AppUiFactory()->StatusPane()->ControlL |
|
136 ( TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
137 |
|
138 CAknNavigationDecorator* decorator = naviPane->Top(); |
|
139 |
|
140 if ( decorator ) |
|
141 { |
|
142 decorator->SetNaviDecoratorObserver |
|
143 ( const_cast<CPbk2ContactNavigation*>( this ) ); |
|
144 CAknNavigationDecorator::TControlType controlType = |
|
145 decorator->ControlType(); |
|
146 // Set ScrollButtonVisible to ETrue except |
|
147 // the controlType is CAknNavigationDecorator::ENaviLabel |
|
148 if( CAknNavigationDecorator::ENaviLabel != controlType ) |
|
149 { |
|
150 decorator->MakeScrollButtonVisible( ETrue ); |
|
151 } |
|
152 } |
|
153 |
|
154 TInt index = 0; |
|
155 TInt contactCount = 1; |
|
156 if ( ScrollView() ) |
|
157 { |
|
158 index = ScrollView()->IndexOfLinkL( aContactLink ); |
|
159 contactCount = ScrollView()->ContactCountL(); |
|
160 } |
|
161 |
|
162 // Create the navigation text |
|
163 CArrayFixFlat<TInt>* values = |
|
164 new ( ELeave ) CArrayFixFlat<TInt>( KGranularity ); |
|
165 CleanupStack::PushL( values ); |
|
166 values->AppendL( index + 1 ); // current contact |
|
167 values->AppendL( contactCount ); // max scrollable contacts |
|
168 HBufC* buf = StringLoader::LoadLC |
|
169 ( iNavigatorFormatResourceId, *values ); |
|
170 |
|
171 // Update the tabgroup text |
|
172 SetTabTextL( iViewId, *buf ); |
|
173 CleanupStack::PopAndDestroy( 2 ); // values, buf |
|
174 |
|
175 // Set navigation pointers when there's something to scroll |
|
176 if (decorator) |
|
177 { |
|
178 if ( contactCount > KOneContact ) |
|
179 { |
|
180 decorator->SetScrollButtonDimmed( |
|
181 CAknNavigationDecorator::ELeftButton, EFalse ); |
|
182 decorator->SetScrollButtonDimmed( |
|
183 CAknNavigationDecorator::ERightButton, EFalse ); |
|
184 } |
|
185 else |
|
186 { |
|
187 decorator->SetScrollButtonDimmed( |
|
188 CAknNavigationDecorator::ELeftButton, ETrue ); |
|
189 decorator->SetScrollButtonDimmed( |
|
190 CAknNavigationDecorator::ERightButton, ETrue ); |
|
191 } |
|
192 } |
|
193 naviPane->DrawNow(); |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CPbk2ContactNavigation::HandleCommandKeyL |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 TBool CPbk2ContactNavigation::HandleCommandKeyL |
|
201 ( const TKeyEvent& aKeyEvent, TEventCode /*aType*/ ) |
|
202 { |
|
203 TBool ret = EFalse; |
|
204 |
|
205 // Initialize directionality to none |
|
206 TInt dir = KNaviDirectionNone; |
|
207 |
|
208 switch ( aKeyEvent.iCode ) |
|
209 { |
|
210 case EKeyLeftArrow: |
|
211 { |
|
212 dir = KNaviDirectionLeft; |
|
213 ret = ETrue; |
|
214 break; |
|
215 } |
|
216 case EKeyRightArrow: |
|
217 { |
|
218 dir = KNaviDirectionRight; |
|
219 ret = ETrue; |
|
220 break; |
|
221 } |
|
222 } |
|
223 |
|
224 if ( dir != KNaviDirectionNone ) |
|
225 { |
|
226 // Handle mirrored layout by negating the directionality |
|
227 if ( AknLayoutUtils::LayoutMirrored() ) |
|
228 { |
|
229 dir = -1 * dir; |
|
230 } |
|
231 NavigateContactL( dir ); |
|
232 } |
|
233 |
|
234 return ret; |
|
235 } |
|
236 |
|
237 // -------------------------------------------------------------------------- |
|
238 // CPbk2ContactNavigation::ContactAddedToView |
|
239 // -------------------------------------------------------------------------- |
|
240 // |
|
241 void CPbk2ContactNavigation::ContactAddedToView |
|
242 ( MVPbkContactViewBase& aView, TInt aIndex, |
|
243 const MVPbkContactLink& aContactLink ) |
|
244 { |
|
245 CPbk2NavigationBase::ContactAddedToView( aView, aIndex, aContactLink ); |
|
246 |
|
247 TRAPD( err, UpdateAfterViewEventL() ); |
|
248 if ( err != KErrNone ) |
|
249 { |
|
250 CCoeEnv::Static()->HandleError( err ); |
|
251 } |
|
252 } |
|
253 |
|
254 // -------------------------------------------------------------------------- |
|
255 // CPbk2ContactNavigation::ContactRemovedFromView |
|
256 // -------------------------------------------------------------------------- |
|
257 // |
|
258 void CPbk2ContactNavigation::ContactRemovedFromView |
|
259 ( MVPbkContactViewBase& aView, TInt aIndex, |
|
260 const MVPbkContactLink& aContactLink ) |
|
261 { |
|
262 CPbk2NavigationBase::ContactRemovedFromView( aView, aIndex, |
|
263 aContactLink ); |
|
264 |
|
265 TRAPD( err, UpdateAfterViewEventL() ); |
|
266 if ( err != KErrNone ) |
|
267 { |
|
268 CCoeEnv::Static()->HandleError( err ); |
|
269 } |
|
270 } |
|
271 |
|
272 // -------------------------------------------------------------------------- |
|
273 // CPbk2ContactNavigation::HandleNaviDecoratorEventL |
|
274 // -------------------------------------------------------------------------- |
|
275 // |
|
276 void CPbk2ContactNavigation::HandleNaviDecoratorEventL( TInt aEventID ) |
|
277 { |
|
278 if ( AknLayoutUtils::PenEnabled() ) |
|
279 { |
|
280 TInt dir = KNaviDirectionNone; |
|
281 |
|
282 switch ( aEventID ) |
|
283 { |
|
284 case EAknNaviDecoratorEventRightTabArrow: |
|
285 { |
|
286 dir = KNaviDirectionRight; |
|
287 break; |
|
288 } |
|
289 case EAknNaviDecoratorEventLeftTabArrow: |
|
290 { |
|
291 dir = KNaviDirectionLeft; |
|
292 break; |
|
293 } |
|
294 } |
|
295 |
|
296 if ( dir != KNaviDirectionNone ) |
|
297 { |
|
298 // Handle mirrored layout by negating the directionality |
|
299 if ( AknLayoutUtils::LayoutMirrored() ) |
|
300 { |
|
301 dir = -1 * dir; |
|
302 } |
|
303 NavigateContactL( dir ); |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 // -------------------------------------------------------------------------- |
|
309 // CPbk2ContactNavigation::NavigateContactL |
|
310 // -------------------------------------------------------------------------- |
|
311 // |
|
312 void CPbk2ContactNavigation::NavigateContactL( TInt aDirection ) |
|
313 { |
|
314 __ASSERT_DEBUG(ScrollView(), |
|
315 Panic(EPanicPreCond_NavigateContactL)); |
|
316 |
|
317 if (ScrollView()) |
|
318 { |
|
319 // Get the contact link |
|
320 MVPbkContactLink* currentContact = NavigationLoader().ContactLinkLC(); |
|
321 TInt contactIndex = KErrNotSupported; // KErrNotFound can't be used |
|
322 |
|
323 if ( currentContact ) |
|
324 { |
|
325 contactIndex = ScrollView()->IndexOfLinkL |
|
326 ( *currentContact ) + aDirection; |
|
327 } |
|
328 CleanupStack::PopAndDestroy(); // currentContact |
|
329 |
|
330 if ( contactIndex != KErrNotSupported ) |
|
331 { |
|
332 const TInt contactCount = ScrollView()->ContactCountL(); |
|
333 if ( contactCount > KOneContact ) |
|
334 { |
|
335 if ( contactIndex < KZeroContacts ) |
|
336 { |
|
337 contactIndex = contactCount + contactIndex; |
|
338 } |
|
339 else if ( contactIndex >= contactCount ) |
|
340 { |
|
341 contactIndex = contactIndex - contactCount; |
|
342 } |
|
343 |
|
344 MVPbkContactLink* contactLink= |
|
345 ScrollView()->CreateLinkLC( contactIndex ); |
|
346 if ( contactLink ) |
|
347 { |
|
348 NavigationLoader().ChangeContactL( *contactLink ); |
|
349 } |
|
350 CleanupStack::PopAndDestroy(); // contactLink |
|
351 } |
|
352 } |
|
353 } |
|
354 } |
|
355 |
|
356 // -------------------------------------------------------------------------- |
|
357 // CPbk2ContactNavigation::UpdateAfterViewEventL |
|
358 // -------------------------------------------------------------------------- |
|
359 // |
|
360 void CPbk2ContactNavigation::UpdateAfterViewEventL() const |
|
361 { |
|
362 MVPbkContactLink* currentContact = NavigationLoader().ContactLinkLC(); |
|
363 if ( currentContact ) |
|
364 { |
|
365 UpdateNaviIndicatorsL( *currentContact ); |
|
366 } |
|
367 CleanupStack::PopAndDestroy(); // currentContact |
|
368 } |
|
369 |
|
370 // -------------------------------------------------------------------------- |
|
371 // CPbk2ContactNavigation::SetTabTextL |
|
372 // Sets the tab text for a view. |
|
373 // -------------------------------------------------------------------------- |
|
374 // |
|
375 void CPbk2ContactNavigation::SetTabTextL |
|
376 ( const TUid aViewId, const TDesC& aText ) const |
|
377 { |
|
378 MPbk2AppUi* appUi = Phonebook2::Pbk2AppUi(); |
|
379 |
|
380 CPbk2TabGroupContainer* tabGroups = appUi->TabGroups(); |
|
381 |
|
382 TPbk2IconId iconId( TUid::Uid( KPbk2UID3 ), aViewId.iUid ); |
|
383 const CPbk2IconInfo* iconInfo = NULL; |
|
384 |
|
385 if ( tabGroups ) |
|
386 { |
|
387 iconInfo = tabGroups->TabIcons().Find( iconId ); |
|
388 } |
|
389 |
|
390 if ( iconInfo ) |
|
391 { |
|
392 CAknNavigationDecorator* decorator = |
|
393 tabGroups->TabGroupFromViewId( aViewId.iUid ); |
|
394 CAknTabGroup* aknTabGroup = static_cast<CAknTabGroup*> |
|
395 ( decorator->DecoratedControl() ); |
|
396 |
|
397 CFbsBitmap* bitmap = NULL; |
|
398 CFbsBitmap* mask = NULL; |
|
399 |
|
400 CPbk2IconFactory* factory = |
|
401 CPbk2IconFactory::NewLC( tabGroups->TabIcons() ); |
|
402 factory->CreateIconLC( |
|
403 iconId, *AknsUtils::SkinInstance(), bitmap, mask ); |
|
404 |
|
405 aknTabGroup->ReplaceTabL( aViewId.iUid, aText, bitmap, mask ); |
|
406 CleanupStack::Pop( 2 ); // mask, bitmap |
|
407 CleanupStack::PopAndDestroy( factory ); |
|
408 } |
|
409 } |
|
410 |
|
411 // End of File |