|
1 /* |
|
2 * Copyright (c) 2006 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 for CxSPSortViewControl. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CxSPSortViewControl.h" |
|
21 |
|
22 // System includes |
|
23 #include <aknlists.h> // CAknSingleStyleListBox |
|
24 #include <avkon.mbg> |
|
25 #include <eikclbd.h> |
|
26 #include <gulicon.h> |
|
27 #include <AknGlobalNote.h> |
|
28 #include <StringLoader.h> |
|
29 |
|
30 // internal includes |
|
31 #include "CxSPLoader.h" |
|
32 #include "MxSPFactory.h" |
|
33 #include "CxSPViewIdChanger.h" |
|
34 #include "CxSPViewInfo.h" |
|
35 #include <ExtensionManagerRes.rsg> |
|
36 #include "xSPOrderOrganizer.h" |
|
37 #include "CGlobalNoteObserver.h" |
|
38 #include <MPbk2ApplicationServices2.h> |
|
39 #include <MPbk2ApplicationServices.h> |
|
40 #include <CPbk2ServiceManager.h> |
|
41 #include <MPbk2AppUi.h> |
|
42 |
|
43 // CONSTANTS |
|
44 _LIT( KTab, "\t" ); |
|
45 const TUint KMaxListBoxBufSize( 256 ); // Maximum listbox item text size |
|
46 |
|
47 |
|
48 void CleanUpResetAndDestroy( TAny* aArray ) |
|
49 { |
|
50 if( aArray ) |
|
51 { |
|
52 CArrayPtrFlat<TDesC>* array = (CArrayPtrFlat<TDesC>*)aArray; |
|
53 array->ResetAndDestroy(); |
|
54 delete array; |
|
55 } |
|
56 } |
|
57 |
|
58 // ================= MEMBER FUNCTIONS ======================= |
|
59 |
|
60 CxSPSortViewControl::CxSPSortViewControl( CxSPViewIdChanger& aViewIdChanger, |
|
61 CxSPArray& aExtensions ) : |
|
62 iViewIdChanger( aViewIdChanger ), |
|
63 iExtensions(aExtensions), |
|
64 iGlobalNote(0), |
|
65 iGlobalNoteObserver(0) |
|
66 { |
|
67 } |
|
68 |
|
69 void CxSPSortViewControl::ConstructL() |
|
70 { |
|
71 CreateWindowL(); |
|
72 |
|
73 // Initialize the list box |
|
74 iListBox = new (ELeave) CAknSingleGraphicStyleListBox; |
|
75 TInt flags = EAknListBoxLoopScrolling | EAknListBoxMarkableList; |
|
76 iListBox->ConstructL(this, flags); |
|
77 iListBox->SetContainerWindowL(*this); |
|
78 iListBox->CreateScrollBarFrameL(ETrue); |
|
79 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL |
|
80 (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
81 SetListBoxContentsL(); |
|
82 } |
|
83 |
|
84 CxSPSortViewControl* CxSPSortViewControl::NewL( CxSPViewIdChanger& aViewIdChanger, |
|
85 CxSPArray& aExtensions ) |
|
86 { |
|
87 CxSPSortViewControl* self = NewLC( aViewIdChanger, aExtensions ); |
|
88 CleanupStack::Pop(self); |
|
89 return self; |
|
90 } |
|
91 |
|
92 CxSPSortViewControl* CxSPSortViewControl::NewLC( CxSPViewIdChanger& aViewIdChanger, |
|
93 CxSPArray& aExtensions ) |
|
94 { |
|
95 CxSPSortViewControl* self = |
|
96 new (ELeave) CxSPSortViewControl( aViewIdChanger, aExtensions ); |
|
97 CleanupStack::PushL(self); |
|
98 self->ConstructL(); |
|
99 return self; |
|
100 } |
|
101 |
|
102 CxSPSortViewControl::~CxSPSortViewControl() |
|
103 { |
|
104 delete iListBox; |
|
105 iSortedOrder.Close(); |
|
106 delete iGlobalNote; |
|
107 delete iGlobalNoteObserver; |
|
108 } |
|
109 |
|
110 TKeyResponse CxSPSortViewControl::OfferKeyEventL |
|
111 (const TKeyEvent& aKeyEvent,TEventCode aType) |
|
112 { |
|
113 TKeyResponse result = EKeyWasNotConsumed; |
|
114 if( iListBox ) |
|
115 { |
|
116 result = iListBox->OfferKeyEventL(aKeyEvent, aType); |
|
117 } |
|
118 return result; |
|
119 } |
|
120 |
|
121 void CxSPSortViewControl::SizeChanged() |
|
122 { |
|
123 if ( iListBox ) |
|
124 { |
|
125 iListBox->SetRect(Rect()); |
|
126 } |
|
127 } |
|
128 |
|
129 TInt CxSPSortViewControl::CountComponentControls() const |
|
130 { |
|
131 TInt controls = 0; |
|
132 if (iListBox) ++controls; |
|
133 return controls; |
|
134 } |
|
135 |
|
136 CCoeControl* CxSPSortViewControl::ComponentControl |
|
137 (TInt /*aIndex*/) const |
|
138 { |
|
139 return iListBox; |
|
140 } |
|
141 |
|
142 void CxSPSortViewControl::SetListBoxContentsL() |
|
143 { |
|
144 _LIT( KFormat, "%d" ); |
|
145 |
|
146 CArrayPtr<CGulIcon>* icons = new(ELeave) CArrayPtrFlat<CGulIcon>( 1 ); |
|
147 CleanupStack::PushL( TCleanupItem( CleanUpResetAndDestroy, icons )); |
|
148 |
|
149 CFbsBitmap* bitmap = NULL; |
|
150 CFbsBitmap* mask = NULL; |
|
151 // Load the avkon "mark" icon |
|
152 AknIconUtils::CreateIconLC( bitmap, mask, AknIconUtils::AvkonIconFileName(), |
|
153 EMbmAvkonQgn_indi_marked_add, |
|
154 EMbmAvkonQgn_indi_marked_add_mask ); |
|
155 |
|
156 CGulIcon* icon = CGulIcon::NewL(bitmap,mask); |
|
157 CleanupStack::Pop( 2 ); // mask, bitmap |
|
158 CleanupStack::PushL( icon ); |
|
159 icons->AppendL( icon ); |
|
160 CleanupStack::Pop( icon ); |
|
161 |
|
162 |
|
163 RPointerArray<CxSPViewInfo> infoArray; |
|
164 CleanupClosePushL( infoArray ); |
|
165 iViewIdChanger.GetTabViewInfoL( infoArray ); |
|
166 const TInt count = infoArray.Count(); |
|
167 CDesC16ArrayFlat* texts = new (ELeave) CDesC16ArrayFlat( count ); |
|
168 CleanupStack::PushL(texts); |
|
169 |
|
170 for( TInt i = 0; i < count; i++ ) |
|
171 { |
|
172 const CxSPViewInfo& info = *infoArray[i]; |
|
173 TBool found( EFalse ); |
|
174 for( TInt j = 0; j < iExtensions.Count() && !found; j++ ) |
|
175 { |
|
176 if( info.Id() == iExtensions.At( j )->ExtensionFactory()->Id() ) |
|
177 { |
|
178 TBuf<KMaxListBoxBufSize> buf; |
|
179 CFbsBitmap* bitmap = NULL; |
|
180 CFbsBitmap* mask = NULL; |
|
181 //info->Name() denotes the ServiceName of the Service in SpSettings |
|
182 //PBK2 ServiceManager has the brandicons of all the services installed |
|
183 //to the device. |
|
184 //So iterate thro the PBK2ServiceManager, to find the service which matches |
|
185 //the info->Name() |
|
186 //If matches use this icon else use the default icon for the tabs |
|
187 //get the XSP ServiceName |
|
188 |
|
189 // CPbk2ServiceManager stores all the brandinfo |
|
190 // related to the services configured to the phone |
|
191 // use this to show uniform icon throughout PhoneBook |
|
192 MPbk2ApplicationServices2* servicesExtension = |
|
193 reinterpret_cast<MPbk2ApplicationServices2*> |
|
194 ( Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
195 MPbk2ApplicationServicesExtension( |
|
196 KMPbk2ApplicationServicesExtension2Uid ) ); |
|
197 CPbk2ServiceManager& servMan = servicesExtension->ServiceManager(); |
|
198 const CPbk2ServiceManager::RServicesArray& services = servMan.Services(); |
|
199 for ( TInt i = 0; i < services.Count(); i++ ) |
|
200 { |
|
201 const CPbk2ServiceManager::TService& service = services[i]; |
|
202 //Found the appropriate service info |
|
203 if ( service.iName == info.Name() ) |
|
204 { |
|
205 if ( service.iBitmap && service.iMask ) |
|
206 { |
|
207 TSize size( 25, 25 ); //default size used in PB |
|
208 |
|
209 AknIconUtils::SetSize( |
|
210 service.iBitmap, |
|
211 size ); |
|
212 AknIconUtils::SetSize( |
|
213 service.iMask, |
|
214 size ); |
|
215 |
|
216 bitmap = new (ELeave) CFbsBitmap; |
|
217 CleanupStack::PushL( bitmap ); |
|
218 bitmap->Duplicate( service.iBitmap->Handle() ); |
|
219 |
|
220 mask = new (ELeave) CFbsBitmap; |
|
221 CleanupStack::PushL( mask ); |
|
222 mask->Duplicate( service.iMask->Handle() ); |
|
223 } |
|
224 break; |
|
225 } |
|
226 } |
|
227 |
|
228 buf.Format( KFormat, icons->Count() ); |
|
229 |
|
230 if ( !bitmap ) |
|
231 { |
|
232 AknIconUtils::CreateIconLC( bitmap, mask, info.SortIconFile(), |
|
233 info.SortIconId(), info.SortMaskId() ); |
|
234 } |
|
235 |
|
236 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
237 CleanupStack::Pop( 2 ); // mask, bitmap |
|
238 CleanupStack::PushL( icon ); |
|
239 icons->AppendL( icon ); |
|
240 CleanupStack::Pop( icon ); |
|
241 |
|
242 buf.Append( KTab ); |
|
243 buf.Append( info.Name() ); |
|
244 buf.Append( KTab ); |
|
245 buf.Append( KTab ); |
|
246 texts->AppendL( buf ); |
|
247 iSortedOrder.AppendL( i ); // create the initial sort order |
|
248 found = ETrue; |
|
249 } |
|
250 } |
|
251 } |
|
252 |
|
253 |
|
254 iListBox->Model()->SetItemTextArray( texts ); |
|
255 iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray); |
|
256 CleanupStack::Pop(texts); |
|
257 iListBox->HandleItemAdditionL(); |
|
258 |
|
259 CleanupStack::PopAndDestroy(); // infoArray |
|
260 |
|
261 CleanupStack::Pop( icons ); |
|
262 |
|
263 iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons ); |
|
264 } |
|
265 |
|
266 |
|
267 void CxSPSortViewControl::SetCurrentItemMarkedL( TBool aMark ) |
|
268 { |
|
269 if( aMark ) |
|
270 { |
|
271 AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark, iListBox ); |
|
272 } |
|
273 else |
|
274 { |
|
275 AknSelectionService::HandleMarkableListProcessCommandL( EAknUnmarkAll, iListBox ); |
|
276 } |
|
277 iListBox->DrawNow(); |
|
278 } |
|
279 |
|
280 |
|
281 void CxSPSortViewControl::MoveMarkedItemL() |
|
282 { |
|
283 TInt currentIndex = iListBox->CurrentItemIndex(); |
|
284 TInt markedIndex = -1; |
|
285 |
|
286 const CListBoxView::CSelectionIndexArray* inds = iListBox->SelectionIndexes(); |
|
287 TInt count = inds->Count(); |
|
288 if( count == 1 ) // sanity check, single selection list should have only one selection |
|
289 { |
|
290 markedIndex = (*inds)[0]; |
|
291 if( markedIndex == currentIndex ) |
|
292 { |
|
293 AknSelectionService::HandleMarkableListProcessCommandL( EAknUnmarkAll, iListBox ); |
|
294 iListBox->DrawNow(); |
|
295 return; |
|
296 } |
|
297 } |
|
298 else |
|
299 { |
|
300 AknSelectionService::HandleMarkableListProcessCommandL( EAknUnmarkAll, iListBox ); |
|
301 iListBox->DrawNow(); |
|
302 return; |
|
303 } |
|
304 |
|
305 CTextListBoxModel* model = iListBox->Model(); |
|
306 CDesCArray* texts = static_cast<CDesCArray*>( model->ItemTextArray() ); |
|
307 if(( texts->Count() > markedIndex ) && ( markedIndex >= 0 )) |
|
308 { |
|
309 TBuf<KMaxListBoxBufSize> markedText = (*texts)[markedIndex]; |
|
310 texts->Delete( markedIndex ); |
|
311 iListBox->HandleItemRemovalL(); |
|
312 |
|
313 TUint32 moveItem = iSortedOrder[markedIndex]; |
|
314 iSortedOrder.Remove( markedIndex ); |
|
315 |
|
316 texts->InsertL( currentIndex, markedText ); |
|
317 iListBox->HandleItemAdditionL(); |
|
318 User::LeaveIfError( iSortedOrder.Insert( moveItem, currentIndex )); |
|
319 } |
|
320 else if( markedIndex < 0 ) |
|
321 { |
|
322 User::Leave( KErrUnderflow ); |
|
323 } |
|
324 else |
|
325 { |
|
326 User::Leave( KErrOverflow ); |
|
327 } |
|
328 |
|
329 AknSelectionService::HandleMarkableListProcessCommandL( EAknUnmarkAll, iListBox ); |
|
330 iListBox->DrawNow(); |
|
331 } |
|
332 |
|
333 |
|
334 TBool CxSPSortViewControl::CommitSortL( MGlobalNoteObserver* aObserver ) |
|
335 { |
|
336 TBool changes = EFalse; |
|
337 for( TInt i=0; i<iSortedOrder.Count(); i++) |
|
338 { |
|
339 // check if the order has really changed |
|
340 if( i != iSortedOrder[i] ) |
|
341 { |
|
342 changes = ETrue; |
|
343 break; |
|
344 } |
|
345 } |
|
346 |
|
347 if( changes ) |
|
348 { |
|
349 // new re-sorted array of extension IDs |
|
350 RArray<TxSPOrderUnit> idArray; |
|
351 CleanupClosePushL( idArray ); |
|
352 RPointerArray<CxSPViewInfo> infoArray; |
|
353 CleanupClosePushL( infoArray ); |
|
354 iViewIdChanger.GetTabViewInfoL( infoArray ); |
|
355 |
|
356 for( TInt i = 0; i < iSortedOrder.Count(); i++ ) |
|
357 { |
|
358 const CxSPViewInfo& info = *infoArray[iSortedOrder[i]]; |
|
359 TxSPOrderUnit orderUnit; |
|
360 orderUnit.iId = info.Id(); |
|
361 orderUnit.iViewId = info.OldViewId(); |
|
362 idArray.AppendL( orderUnit ); |
|
363 } |
|
364 |
|
365 xSPOrderOrganizer::Reorganize( idArray ); |
|
366 |
|
367 CleanupStack::PopAndDestroy( 2 ); // infoArray, idArray |
|
368 |
|
369 // Load the used text label from resource |
|
370 HBufC* stringholder = StringLoader::LoadLC |
|
371 ( R_QTN_EXTENSION_MANAGER_SHUTDOWN_NOTE, iEikonEnv ); |
|
372 |
|
373 // Create observer for listening global note dismissal |
|
374 delete iGlobalNoteObserver; |
|
375 iGlobalNoteObserver = 0; |
|
376 iGlobalNoteObserver = CGlobalNoteObserver::NewL( aObserver ); |
|
377 |
|
378 // Create and show global note |
|
379 // The note cannot be deleted immediately because deleting it also |
|
380 // causes the observer to be notified with KErrCancel |
|
381 delete iGlobalNote; |
|
382 iGlobalNote = 0; |
|
383 iGlobalNote = CAknGlobalNote::NewL(); |
|
384 iGlobalNote->SetSoftkeys( R_AVKON_SOFTKEYS_OK_EMPTY ); |
|
385 iGlobalNote->ShowNoteL( |
|
386 iGlobalNoteObserver->iStatus, |
|
387 EAknGlobalInformationNote, |
|
388 *stringholder ); |
|
389 |
|
390 CleanupStack::PopAndDestroy( stringholder ); |
|
391 } |
|
392 return changes; |
|
393 } |
|
394 |
|
395 // End of file |