|
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 menu filtering helper. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "Pbk2NlxMenuFiltering.h" |
|
21 |
|
22 #include <MPbk2ContactUiControl.h> |
|
23 #include <MPbk2ContactUiControl2.h> |
|
24 #include <CPbk2AppUiBase.h> |
|
25 #include <MPbk2ApplicationServices.h> |
|
26 #include <CVPbkContactManager.h> |
|
27 #include <VPbkContactStoreUris.h> |
|
28 #include <CVPbkTopContactManager.h> |
|
29 #include <MVPbkContactLink.h> |
|
30 #include <MVPbkBaseContact.h> |
|
31 #include <MVPbkContactStore.h> |
|
32 #include <MVPbkContactStoreProperties.h> |
|
33 #include <CPbk2StoreConfiguration.h> |
|
34 #include <CVPbkContactStoreUriArray.h> |
|
35 #include <MVPbkContactView.h> |
|
36 #include <MPbk2ContactViewSupplier.h> |
|
37 #include <MPbk2ContactViewSupplier2.h> |
|
38 #include <MPbk2ContactLinkIterator.h> |
|
39 #include <MPbk2UiControlCmdItem.h> |
|
40 #include <Pbk2Commands.hrh> |
|
41 #include "Pbk2NamesListEx.hrh" |
|
42 |
|
43 |
|
44 const TInt KMinNumberOfTopContactsForRearranging = 2; |
|
45 |
|
46 TBool Pbk2NlxMenuFiltering::OpenReady( MPbk2ContactUiControl& aControl ) |
|
47 { |
|
48 |
|
49 MPbk2ContactUiControl2* tempControl = |
|
50 reinterpret_cast<MPbk2ContactUiControl2*> |
|
51 (aControl.ContactUiControlExtension(KMPbk2ContactUiControlExtension2Uid )); |
|
52 |
|
53 return (!(tempControl->FocusedCommandItem()) && (aControl.NumberOfContacts() > 0) && |
|
54 !aControl.ContactsMarked()); |
|
55 } |
|
56 |
|
57 TBool Pbk2NlxMenuFiltering::AddToFavoritesCmdSelected( MPbk2ContactUiControl& aControl ) |
|
58 { |
|
59 MPbk2ContactUiControl2* tempControl = |
|
60 reinterpret_cast<MPbk2ContactUiControl2*> |
|
61 (aControl.ContactUiControlExtension(KMPbk2ContactUiControlExtension2Uid )); |
|
62 |
|
63 const MPbk2UiControlCmdItem* cmdItem = tempControl->FocusedCommandItem(); |
|
64 if ( cmdItem ) |
|
65 { |
|
66 return cmdItem->CommandId() == EPbk2CmdAddFavourites; |
|
67 } |
|
68 return EFalse; |
|
69 } |
|
70 |
|
71 TBool Pbk2NlxMenuFiltering::MyCardCmdSelected( MPbk2ContactUiControl& aControl ) |
|
72 { |
|
73 MPbk2ContactUiControl2* tempControl = |
|
74 reinterpret_cast<MPbk2ContactUiControl2*> |
|
75 (aControl.ContactUiControlExtension(KMPbk2ContactUiControlExtension2Uid )); |
|
76 |
|
77 const MPbk2UiControlCmdItem* cmdItem = tempControl->FocusedCommandItem(); |
|
78 if ( cmdItem ) |
|
79 { |
|
80 return cmdItem->CommandId() == EPbk2CmdOpenMyCard; |
|
81 } |
|
82 return EFalse; |
|
83 } |
|
84 |
|
85 TBool Pbk2NlxMenuFiltering::RclCmdSelectOptSelected( MPbk2ContactUiControl& aControl ) |
|
86 { |
|
87 MPbk2ContactUiControl2* tempControl = |
|
88 reinterpret_cast<MPbk2ContactUiControl2*> |
|
89 (aControl.ContactUiControlExtension(KMPbk2ContactUiControlExtension2Uid )); |
|
90 |
|
91 const MPbk2UiControlCmdItem* cmdItem = tempControl->FocusedCommandItem(); |
|
92 if ( cmdItem ) |
|
93 { |
|
94 return cmdItem->CommandId() == EPbk2CmdRcl; |
|
95 } |
|
96 return EFalse; |
|
97 } |
|
98 |
|
99 TBool Pbk2NlxMenuFiltering::ReadOnlyContactSelectedL( MPbk2ContactUiControl& aControl ) |
|
100 { |
|
101 TBool result = EFalse; |
|
102 const MVPbkBaseContact* contact = aControl.FocusedContactL(); |
|
103 |
|
104 if (contact) |
|
105 { |
|
106 // create link to get store |
|
107 MVPbkContactLink* link = contact->CreateLinkLC(); |
|
108 result = link->ContactStore().StoreProperties().ReadOnly(); |
|
109 CleanupStack::PopAndDestroy(); |
|
110 } |
|
111 |
|
112 return result; |
|
113 } |
|
114 |
|
115 TBool Pbk2NlxMenuFiltering::TopReadyL( MPbk2ContactUiControl& aControl ) |
|
116 { |
|
117 CVPbkContactStoreUriArray* currentConfig = |
|
118 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
119 StoreConfiguration().CurrentConfigurationL(); |
|
120 TBool phMemOk = currentConfig->IsIncluded( |
|
121 VPbkContactStoreUris::DefaultCntDbUri() ); |
|
122 delete currentConfig; |
|
123 |
|
124 return phMemOk && |
|
125 NonTopContactSelectedL( aControl ) && |
|
126 !ReadOnlyContactSelectedL( aControl ); |
|
127 } |
|
128 |
|
129 TBool Pbk2NlxMenuFiltering::TopContactSelectedL( MPbk2ContactUiControl& aControl ) |
|
130 { |
|
131 TBool result = EFalse; |
|
132 const MVPbkBaseContact* contact = aControl.FocusedContactL(); |
|
133 |
|
134 if (contact) |
|
135 { |
|
136 result = CVPbkTopContactManager::IsTopContact( *contact ); |
|
137 } |
|
138 return result; |
|
139 } |
|
140 |
|
141 TBool Pbk2NlxMenuFiltering::NonTopContactSelectedL( MPbk2ContactUiControl& aControl ) |
|
142 { |
|
143 TBool result = EFalse; |
|
144 const MVPbkBaseContact* contact = aControl.FocusedContactL(); |
|
145 |
|
146 if (contact) |
|
147 { |
|
148 result = !CVPbkTopContactManager::IsTopContact( *contact ); |
|
149 } |
|
150 return result; |
|
151 } |
|
152 |
|
153 TBool Pbk2NlxMenuFiltering::TopRearrangingReadyL(MPbk2ContactUiControl& aControl ) |
|
154 { |
|
155 MPbk2ContactViewSupplier2* viewSupplierExtension = |
|
156 reinterpret_cast<MPbk2ContactViewSupplier2*>( |
|
157 Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier(). |
|
158 MPbk2ContactViewSupplierExtension( |
|
159 KMPbk2ContactViewSupplierExtension2Uid )); |
|
160 |
|
161 if ( viewSupplierExtension != NULL && TopContactSelectedL( aControl ) ) |
|
162 { |
|
163 const MVPbkContactViewBase* topView = viewSupplierExtension-> |
|
164 TopContactsViewL(); |
|
165 if ( topView ) |
|
166 { |
|
167 return topView->ContactCountL() >= KMinNumberOfTopContactsForRearranging; |
|
168 } |
|
169 } |
|
170 return EFalse; |
|
171 } |
|
172 |
|
173 TBool Pbk2NlxMenuFiltering::TopContactMarkedL( MPbk2ContactUiControl& aControl ) |
|
174 { |
|
175 MPbk2ContactViewSupplier2* viewSupplierExtension = |
|
176 reinterpret_cast<MPbk2ContactViewSupplier2*>( |
|
177 Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier(). |
|
178 MPbk2ContactViewSupplierExtension( |
|
179 KMPbk2ContactViewSupplierExtension2Uid )); |
|
180 |
|
181 MVPbkContactViewBase* topView = NULL; |
|
182 if ( viewSupplierExtension != NULL ) |
|
183 { |
|
184 topView = viewSupplierExtension->TopContactsViewL(); |
|
185 } |
|
186 |
|
187 TBool topIncluded = EFalse; |
|
188 if ( topView ) |
|
189 { |
|
190 MPbk2ContactLinkIterator* iterator = |
|
191 aControl.SelectedContactsIteratorL(); |
|
192 |
|
193 if ( iterator ) |
|
194 { |
|
195 CleanupDeletePushL( iterator ); |
|
196 |
|
197 while( iterator->HasNext()&& !topIncluded ) |
|
198 { |
|
199 MVPbkContactLink* link = iterator->NextL(); |
|
200 CleanupDeletePushL( link ); |
|
201 if ( topView->IndexOfLinkL( *link ) >= 0 ) |
|
202 { |
|
203 topIncluded = ETrue; |
|
204 } |
|
205 |
|
206 CleanupStack::PopAndDestroy(); |
|
207 } |
|
208 CleanupStack::PopAndDestroy(); // iterator |
|
209 } |
|
210 } |
|
211 |
|
212 return topIncluded; |
|
213 } |
|
214 |
|
215 TBool Pbk2NlxMenuFiltering::NonTopContactMarkedL( MPbk2ContactUiControl& aControl ) |
|
216 { |
|
217 MPbk2ContactViewSupplier2* viewSupplierExtension = |
|
218 reinterpret_cast<MPbk2ContactViewSupplier2*>( |
|
219 Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier(). |
|
220 MPbk2ContactViewSupplierExtension( |
|
221 KMPbk2ContactViewSupplierExtension2Uid )); |
|
222 |
|
223 MVPbkContactViewBase* topView = NULL; |
|
224 if ( viewSupplierExtension != NULL ) |
|
225 { |
|
226 topView = viewSupplierExtension->TopContactsViewL(); |
|
227 } |
|
228 |
|
229 TBool nonTopIncluded = EFalse; |
|
230 if ( topView ) |
|
231 { |
|
232 MPbk2ContactLinkIterator* iterator = |
|
233 aControl.SelectedContactsIteratorL(); |
|
234 |
|
235 if ( iterator ) |
|
236 { |
|
237 CleanupDeletePushL( iterator ); |
|
238 |
|
239 while( iterator->HasNext()&& !nonTopIncluded ) |
|
240 { |
|
241 MVPbkContactLink* link = iterator->NextL(); |
|
242 CleanupDeletePushL( link ); |
|
243 if ( topView->IndexOfLinkL( *link ) == KErrNotFound ) |
|
244 { |
|
245 nonTopIncluded = ETrue; |
|
246 } |
|
247 CleanupStack::PopAndDestroy(); |
|
248 } |
|
249 CleanupStack::PopAndDestroy(); // iterator |
|
250 } |
|
251 } |
|
252 else |
|
253 { |
|
254 nonTopIncluded = ETrue; |
|
255 } |
|
256 |
|
257 return nonTopIncluded; |
|
258 } |
|
259 |
|
260 TBool Pbk2NlxMenuFiltering::CheckDeletableInMarkedContactsL( |
|
261 MPbk2ContactUiControl& aControl ) |
|
262 { |
|
263 MPbk2ContactLinkIterator* iterator = |
|
264 aControl.SelectedContactsIteratorL(); |
|
265 |
|
266 TBool result = EFalse; |
|
267 |
|
268 if ( iterator ) |
|
269 { |
|
270 CleanupDeletePushL( iterator ); |
|
271 |
|
272 while( iterator->HasNext() && !result ) |
|
273 { |
|
274 MVPbkContactLink* link = iterator->NextL(); |
|
275 if ( link && |
|
276 !link->ContactStore().StoreProperties().ReadOnly() ) |
|
277 { |
|
278 result = ETrue; |
|
279 } |
|
280 delete link; |
|
281 } |
|
282 CleanupStack::PopAndDestroy(); // iterator |
|
283 } |
|
284 |
|
285 return result; |
|
286 } |
|
287 |
|
288 // End of File |