|
1 /* |
|
2 * Copyright (c) 2006-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: Command helper class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2FieldFocusHelper.h" |
|
20 |
|
21 // VirtualPhonebook |
|
22 #include <MVPbkStoreContactField.h> |
|
23 #include <MVPbkStoreContact.h> |
|
24 |
|
25 // Phonebook2 |
|
26 #include <MPbk2ContactUiControl.h> |
|
27 #include <CPbk2PresentationContact.h> |
|
28 #include <CPbk2PresentationContactFieldCollection.h> |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS ============================ |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CPbk2FieldFocusHelper::CPbk2FieldFocusHelper |
|
34 // -------------------------------------------------------------------------- |
|
35 // |
|
36 inline CPbk2FieldFocusHelper::CPbk2FieldFocusHelper( |
|
37 MPbk2ContactUiControl& aUiControl, |
|
38 MPbk2FieldPropertyArray& aPropertyArray ): |
|
39 iUiControl( aUiControl ), |
|
40 iFieldProperties( aPropertyArray ), |
|
41 iUiControlValid ( ETrue ) |
|
42 { |
|
43 } |
|
44 |
|
45 // -------------------------------------------------------------------------- |
|
46 // CPbk2FieldFocusHelper::NewL |
|
47 // -------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C CPbk2FieldFocusHelper* CPbk2FieldFocusHelper::NewL |
|
50 ( MPbk2ContactUiControl& aUiControl, |
|
51 MPbk2FieldPropertyArray& aPropertyArray ) |
|
52 { |
|
53 CPbk2FieldFocusHelper* self = |
|
54 new ( ELeave ) CPbk2FieldFocusHelper( aUiControl, aPropertyArray ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CPbk2FieldFocusHelper::~CPbk2FieldFocusHelper |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CPbk2FieldFocusHelper::~CPbk2FieldFocusHelper() |
|
63 { |
|
64 delete iFocusedStoreCntField; |
|
65 } |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // CPbk2FieldFocusHelper::SaveInitiallyFocusedFieldL |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C void CPbk2FieldFocusHelper::SaveInitiallyFocusedFieldL |
|
72 ( MVPbkStoreContact& aStoreContact ) |
|
73 { |
|
74 if ( iUiControlValid ) |
|
75 { |
|
76 iStoreContact = &aStoreContact; |
|
77 iUiFieldIndex = iUiControl.FocusedFieldIndex(); |
|
78 if ( iStoreContact && ( iUiFieldIndex != KErrNotFound ) ) |
|
79 { |
|
80 // This command is launched only from contact info view so there |
|
81 // should be store contact |
|
82 CPbk2PresentationContact* pCnt = |
|
83 CPbk2PresentationContact::NewL |
|
84 ( const_cast<MVPbkStoreContact&>( *iStoreContact ), |
|
85 iFieldProperties ); |
|
86 CleanupStack::PushL( pCnt ); |
|
87 TInt storeFieldIndex( |
|
88 pCnt->PresentationFields().StoreIndexOfField( iUiFieldIndex ) ); |
|
89 if ( storeFieldIndex != KErrNotFound ) |
|
90 { |
|
91 if ( iFocusedStoreCntField ) |
|
92 { |
|
93 delete iFocusedStoreCntField; |
|
94 iFocusedStoreCntField = NULL; |
|
95 } |
|
96 iFocusedStoreCntField = iStoreContact->Fields().FieldAtLC |
|
97 ( storeFieldIndex ); |
|
98 CleanupStack::Pop(); // iFocusedStoreCntField |
|
99 } |
|
100 CleanupStack::PopAndDestroy(); // pCnt |
|
101 } |
|
102 } |
|
103 } |
|
104 // -------------------------------------------------------------------------- |
|
105 // CPbk2FieldFocusHelper::RestoreSavedFieldL |
|
106 // -------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C TInt CPbk2FieldFocusHelper::RestoreSavedFieldL() |
|
109 { |
|
110 TInt fieldIndex ( KErrNotFound ); |
|
111 if ( iStoreContact && iUiControlValid ) |
|
112 { |
|
113 iUiControl.SetFocusedContactL( *iStoreContact ); |
|
114 |
|
115 if ( iFocusedStoreCntField ) |
|
116 { |
|
117 CPbk2PresentationContact* presentationCnt = |
|
118 CPbk2PresentationContact::NewL |
|
119 ( *iStoreContact, iFieldProperties ); |
|
120 fieldIndex = presentationCnt->PresentationFields(). |
|
121 FindFieldIndex( *iFocusedStoreCntField ); |
|
122 delete presentationCnt; |
|
123 presentationCnt = NULL; |
|
124 |
|
125 // If the field is added, focused index stays the same. |
|
126 // If the field is removed and the focus is in the |
|
127 // removed field, focus moves upwards by one. |
|
128 if ( fieldIndex == KErrNotFound ) |
|
129 { |
|
130 fieldIndex = --iUiFieldIndex; |
|
131 } |
|
132 iUiControl.SetFocusedFieldIndex( fieldIndex ); |
|
133 } |
|
134 } |
|
135 |
|
136 return fieldIndex; |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // CPbk2FieldFocusHelper::SetUiControlValid |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C void CPbk2FieldFocusHelper::SetUiControlValid( TBool aUiControlValid ) |
|
144 { |
|
145 iUiControlValid = aUiControlValid; |
|
146 } |
|
147 // End of file |