author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:15:33 +0300 | |
branch | RCL_3 |
changeset 85 | 38bb213f60ba |
parent 63 | f4a778e096c2 |
permissions | -rw-r--r-- |
63 | 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 ) ); |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
144 |
decorator->MakeScrollButtonVisible( ETrue ); |
63 | 145 |
} |
146 |
||
147 |
TInt index = 0; |
|
148 |
TInt contactCount = 1; |
|
149 |
if ( ScrollView() ) |
|
150 |
{ |
|
151 |
index = ScrollView()->IndexOfLinkL( aContactLink ); |
|
152 |
contactCount = ScrollView()->ContactCountL(); |
|
153 |
} |
|
154 |
||
155 |
// Create the navigation text |
|
156 |
CArrayFixFlat<TInt>* values = |
|
157 |
new ( ELeave ) CArrayFixFlat<TInt>( KGranularity ); |
|
158 |
CleanupStack::PushL( values ); |
|
159 |
values->AppendL( index + 1 ); // current contact |
|
160 |
values->AppendL( contactCount ); // max scrollable contacts |
|
161 |
HBufC* buf = StringLoader::LoadLC |
|
162 |
( iNavigatorFormatResourceId, *values ); |
|
163 |
||
164 |
// Update the tabgroup text |
|
165 |
SetTabTextL( iViewId, *buf ); |
|
166 |
CleanupStack::PopAndDestroy( 2 ); // values, buf |
|
167 |
||
168 |
// Set navigation pointers when there's something to scroll |
|
169 |
if (decorator) |
|
170 |
{ |
|
171 |
if ( contactCount > KOneContact ) |
|
172 |
{ |
|
173 |
decorator->SetScrollButtonDimmed( |
|
174 |
CAknNavigationDecorator::ELeftButton, EFalse ); |
|
175 |
decorator->SetScrollButtonDimmed( |
|
176 |
CAknNavigationDecorator::ERightButton, EFalse ); |
|
177 |
} |
|
178 |
else |
|
179 |
{ |
|
180 |
decorator->SetScrollButtonDimmed( |
|
181 |
CAknNavigationDecorator::ELeftButton, ETrue ); |
|
182 |
decorator->SetScrollButtonDimmed( |
|
183 |
CAknNavigationDecorator::ERightButton, ETrue ); |
|
184 |
} |
|
185 |
} |
|
186 |
naviPane->DrawNow(); |
|
187 |
} |
|
188 |
||
189 |
// -------------------------------------------------------------------------- |
|
190 |
// CPbk2ContactNavigation::HandleCommandKeyL |
|
191 |
// -------------------------------------------------------------------------- |
|
192 |
// |
|
193 |
TBool CPbk2ContactNavigation::HandleCommandKeyL |
|
194 |
( const TKeyEvent& aKeyEvent, TEventCode /*aType*/ ) |
|
195 |
{ |
|
196 |
TBool ret = EFalse; |
|
197 |
||
198 |
// Initialize directionality to none |
|
199 |
TInt dir = KNaviDirectionNone; |
|
200 |
||
201 |
switch ( aKeyEvent.iCode ) |
|
202 |
{ |
|
203 |
case EKeyLeftArrow: |
|
204 |
{ |
|
205 |
dir = KNaviDirectionLeft; |
|
206 |
ret = ETrue; |
|
207 |
break; |
|
208 |
} |
|
209 |
case EKeyRightArrow: |
|
210 |
{ |
|
211 |
dir = KNaviDirectionRight; |
|
212 |
ret = ETrue; |
|
213 |
break; |
|
214 |
} |
|
215 |
} |
|
216 |
||
217 |
if ( dir != KNaviDirectionNone ) |
|
218 |
{ |
|
219 |
// Handle mirrored layout by negating the directionality |
|
220 |
if ( AknLayoutUtils::LayoutMirrored() ) |
|
221 |
{ |
|
222 |
dir = -1 * dir; |
|
223 |
} |
|
224 |
NavigateContactL( dir ); |
|
225 |
} |
|
226 |
||
227 |
return ret; |
|
228 |
} |
|
229 |
||
230 |
// -------------------------------------------------------------------------- |
|
231 |
// CPbk2ContactNavigation::ContactAddedToView |
|
232 |
// -------------------------------------------------------------------------- |
|
233 |
// |
|
234 |
void CPbk2ContactNavigation::ContactAddedToView |
|
235 |
( MVPbkContactViewBase& aView, TInt aIndex, |
|
236 |
const MVPbkContactLink& aContactLink ) |
|
237 |
{ |
|
238 |
CPbk2NavigationBase::ContactAddedToView( aView, aIndex, aContactLink ); |
|
239 |
||
240 |
TRAPD( err, UpdateAfterViewEventL() ); |
|
241 |
if ( err != KErrNone ) |
|
242 |
{ |
|
243 |
CCoeEnv::Static()->HandleError( err ); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
// -------------------------------------------------------------------------- |
|
248 |
// CPbk2ContactNavigation::ContactRemovedFromView |
|
249 |
// -------------------------------------------------------------------------- |
|
250 |
// |
|
251 |
void CPbk2ContactNavigation::ContactRemovedFromView |
|
252 |
( MVPbkContactViewBase& aView, TInt aIndex, |
|
253 |
const MVPbkContactLink& aContactLink ) |
|
254 |
{ |
|
255 |
CPbk2NavigationBase::ContactRemovedFromView( aView, aIndex, |
|
256 |
aContactLink ); |
|
257 |
||
258 |
TRAPD( err, UpdateAfterViewEventL() ); |
|
259 |
if ( err != KErrNone ) |
|
260 |
{ |
|
261 |
CCoeEnv::Static()->HandleError( err ); |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
// -------------------------------------------------------------------------- |
|
266 |
// CPbk2ContactNavigation::HandleNaviDecoratorEventL |
|
267 |
// -------------------------------------------------------------------------- |
|
268 |
// |
|
269 |
void CPbk2ContactNavigation::HandleNaviDecoratorEventL( TInt aEventID ) |
|
270 |
{ |
|
271 |
if ( AknLayoutUtils::PenEnabled() ) |
|
272 |
{ |
|
273 |
TInt dir = KNaviDirectionNone; |
|
274 |
||
275 |
switch ( aEventID ) |
|
276 |
{ |
|
277 |
case EAknNaviDecoratorEventRightTabArrow: |
|
278 |
{ |
|
279 |
dir = KNaviDirectionRight; |
|
280 |
break; |
|
281 |
} |
|
282 |
case EAknNaviDecoratorEventLeftTabArrow: |
|
283 |
{ |
|
284 |
dir = KNaviDirectionLeft; |
|
285 |
break; |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
if ( dir != KNaviDirectionNone ) |
|
290 |
{ |
|
291 |
// Handle mirrored layout by negating the directionality |
|
292 |
if ( AknLayoutUtils::LayoutMirrored() ) |
|
293 |
{ |
|
294 |
dir = -1 * dir; |
|
295 |
} |
|
296 |
NavigateContactL( dir ); |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
// -------------------------------------------------------------------------- |
|
302 |
// CPbk2ContactNavigation::NavigateContactL |
|
303 |
// -------------------------------------------------------------------------- |
|
304 |
// |
|
305 |
void CPbk2ContactNavigation::NavigateContactL( TInt aDirection ) |
|
306 |
{ |
|
307 |
__ASSERT_DEBUG(ScrollView(), |
|
308 |
Panic(EPanicPreCond_NavigateContactL)); |
|
309 |
||
310 |
if (ScrollView()) |
|
311 |
{ |
|
312 |
// Get the contact link |
|
313 |
MVPbkContactLink* currentContact = NavigationLoader().ContactLinkLC(); |
|
314 |
TInt contactIndex = KErrNotSupported; // KErrNotFound can't be used |
|
315 |
||
316 |
if ( currentContact ) |
|
317 |
{ |
|
318 |
contactIndex = ScrollView()->IndexOfLinkL |
|
319 |
( *currentContact ) + aDirection; |
|
320 |
} |
|
321 |
CleanupStack::PopAndDestroy(); // currentContact |
|
322 |
||
323 |
if ( contactIndex != KErrNotSupported ) |
|
324 |
{ |
|
325 |
const TInt contactCount = ScrollView()->ContactCountL(); |
|
326 |
if ( contactCount > KOneContact ) |
|
327 |
{ |
|
328 |
if ( contactIndex < KZeroContacts ) |
|
329 |
{ |
|
330 |
contactIndex = contactCount + contactIndex; |
|
331 |
} |
|
332 |
else if ( contactIndex >= contactCount ) |
|
333 |
{ |
|
334 |
contactIndex = contactIndex - contactCount; |
|
335 |
} |
|
336 |
||
337 |
MVPbkContactLink* contactLink= |
|
338 |
ScrollView()->CreateLinkLC( contactIndex ); |
|
339 |
if ( contactLink ) |
|
340 |
{ |
|
341 |
NavigationLoader().ChangeContactL( *contactLink ); |
|
342 |
} |
|
343 |
CleanupStack::PopAndDestroy(); // contactLink |
|
344 |
} |
|
345 |
} |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
// -------------------------------------------------------------------------- |
|
350 |
// CPbk2ContactNavigation::UpdateAfterViewEventL |
|
351 |
// -------------------------------------------------------------------------- |
|
352 |
// |
|
353 |
void CPbk2ContactNavigation::UpdateAfterViewEventL() const |
|
354 |
{ |
|
355 |
MVPbkContactLink* currentContact = NavigationLoader().ContactLinkLC(); |
|
356 |
if ( currentContact ) |
|
357 |
{ |
|
358 |
UpdateNaviIndicatorsL( *currentContact ); |
|
359 |
} |
|
360 |
CleanupStack::PopAndDestroy(); // currentContact |
|
361 |
} |
|
362 |
||
363 |
// -------------------------------------------------------------------------- |
|
364 |
// CPbk2ContactNavigation::SetTabTextL |
|
365 |
// Sets the tab text for a view. |
|
366 |
// -------------------------------------------------------------------------- |
|
367 |
// |
|
368 |
void CPbk2ContactNavigation::SetTabTextL |
|
369 |
( const TUid aViewId, const TDesC& aText ) const |
|
370 |
{ |
|
371 |
MPbk2AppUi* appUi = Phonebook2::Pbk2AppUi(); |
|
372 |
||
373 |
CPbk2TabGroupContainer* tabGroups = appUi->TabGroups(); |
|
374 |
||
375 |
TPbk2IconId iconId( TUid::Uid( KPbk2UID3 ), aViewId.iUid ); |
|
376 |
const CPbk2IconInfo* iconInfo = NULL; |
|
377 |
||
378 |
if ( tabGroups ) |
|
379 |
{ |
|
380 |
iconInfo = tabGroups->TabIcons().Find( iconId ); |
|
381 |
} |
|
382 |
||
383 |
if ( iconInfo ) |
|
384 |
{ |
|
385 |
CAknNavigationDecorator* decorator = |
|
386 |
tabGroups->TabGroupFromViewId( aViewId.iUid ); |
|
387 |
CAknTabGroup* aknTabGroup = static_cast<CAknTabGroup*> |
|
388 |
( decorator->DecoratedControl() ); |
|
389 |
||
390 |
CFbsBitmap* bitmap = NULL; |
|
391 |
CFbsBitmap* mask = NULL; |
|
392 |
||
393 |
CPbk2IconFactory* factory = |
|
394 |
CPbk2IconFactory::NewLC( tabGroups->TabIcons() ); |
|
395 |
factory->CreateIconLC( |
|
396 |
iconId, *AknsUtils::SkinInstance(), bitmap, mask ); |
|
397 |
||
398 |
aknTabGroup->ReplaceTabL( aViewId.iUid, aText, bitmap, mask ); |
|
399 |
CleanupStack::Pop( 2 ); // mask, bitmap |
|
400 |
CleanupStack::PopAndDestroy( factory ); |
|
401 |
} |
|
402 |
} |
|
403 |
||
404 |
// End of File |