|
1 /* |
|
2 * Copyright (c) 2002-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 the License "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: |
|
15 * Implementation of CBrowserFavouritesView. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <aknsfld.h> |
|
23 #include <eikbtgpc.h> |
|
24 #include <eikmenub.h> |
|
25 #include <aknviewappui.h> |
|
26 #include <Avkon.hrh> |
|
27 #include <Uikon.hrh> |
|
28 #include <eikmenup.h> |
|
29 #include <AknForm.h> |
|
30 #include <AknQueryDialog.h> |
|
31 #include <BrowserNG.rsg> |
|
32 #include <avkon.rsg> |
|
33 #include <FavouritesLimits.h> |
|
34 #include <FavouritesDb.h> |
|
35 #include <FavouritesItem.h> |
|
36 #include <FavouritesItemList.h> |
|
37 #include <InternetConnectionManager.h> |
|
38 #include <FeatMgr.h> |
|
39 #include <centralrepository.h> |
|
40 #include <nifman.h> |
|
41 |
|
42 #include "BrowserUiPrivateCRKeys.h" |
|
43 #include "BrowserUtil.h" |
|
44 #include "BrowserDialogs.h" |
|
45 #include "BrowserFavouritesView.h" |
|
46 #include "BrowserFavouritesFolderSelector.h" |
|
47 #include "BrowserFavouritesContainer.h" |
|
48 #include "BrowserFavouritesListbox.h" |
|
49 #include "BrowserFavouritesListboxState.h" |
|
50 #include "BrowserFavouritesModel.h" |
|
51 #include "Browser.hrh" |
|
52 #include "BrowserAppUi.h" |
|
53 #include "BrowserApplication.h" |
|
54 #include "BrowserFavouritesIncrementalDelete.h" |
|
55 #include "BrowserFavouritesIncrementalMove.h" |
|
56 #include "BrowserUIVariant.hrh" |
|
57 #include "BrowserWindowManager.h" |
|
58 #include "CommandVisibility.h" |
|
59 #include "CommonConstants.h" |
|
60 #include "CommsModel.h" |
|
61 #include "Display.h" |
|
62 #include "Preferences.h" |
|
63 |
|
64 #include "eikon.hrh" |
|
65 |
|
66 |
|
67 // MACROS |
|
68 |
|
69 /** |
|
70 * Defining this macro shows "Unmark all", even if nothing is marked (except |
|
71 * if there are no items at all). |
|
72 */ |
|
73 //#define SHOW_UNMARK_ALL_ALWAYS |
|
74 /** |
|
75 * Defining this macro shows "Mark all", even if all is marked (except |
|
76 * if there are no items at all). |
|
77 */ |
|
78 //#define SHOW_MARK_ALL_ALWAYS |
|
79 |
|
80 /// Cosmetic purpose macro (resource names are overly too long). |
|
81 #define _R(str) R_BROWSER_FAVOURITES_ ## str |
|
82 |
|
83 // CONSTANTS |
|
84 /// Granularity of Uid lists used in managing multiple bookmarks. |
|
85 LOCAL_C const TInt KGranularityUids = 4; |
|
86 |
|
87 /// Estimated FFS overhead for deleting (in bytes). |
|
88 LOCAL_C const TInt KEstimatedDeleteFfsOverhead = 16 * 1024; |
|
89 |
|
90 // ==================== LOCAL FUNCTIONS ==================== |
|
91 |
|
92 /** |
|
93 * Create a new empty list for Uids and push it on the cleanup stack. |
|
94 * @return The constructed empty list. |
|
95 */ |
|
96 LOCAL_C CArrayFix<TInt>* NewUidListLC() |
|
97 { |
|
98 // Not inline - go for size, not speed. |
|
99 CArrayFixFlat<TInt>* list; |
|
100 list = new (ELeave) CArrayFixFlat<TInt> ( KGranularityUids ); |
|
101 CleanupStack::PushL( list ); |
|
102 return list; |
|
103 } |
|
104 |
|
105 // ================= MEMBER FUNCTIONS ======================= |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CBrowserFavouritesView::~CBrowserFavouritesView |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 CBrowserFavouritesView::~CBrowserFavouritesView() |
|
112 { |
|
113 delete iIncrementalOp; |
|
114 delete iContainer; |
|
115 delete iModel; |
|
116 delete iSavedListboxState; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CBrowserFavouritesView::CommandSetResourceIdL |
|
121 // --------------------------------------------------------------------------- |
|
122 TInt CBrowserFavouritesView::CommandSetResourceIdL() |
|
123 { |
|
124 // for 5.0, BrowserBookmarksView takes over cba-assignment duties |
|
125 // this function should not be called. We now route though BrowserBookmarksView. |
|
126 return R_AVKON_SOFTKEYS_EMPTY; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CBrowserFavouritesView::HandleCommandL |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 void CBrowserFavouritesView::HandleCommandL( TInt aCommand ) |
|
134 { |
|
135 switch ( aCommand ) |
|
136 { |
|
137 case EWmlCmdBackFromFolder: |
|
138 { |
|
139 if ( ApiProvider().IsEmbeddedModeOn() ) |
|
140 { |
|
141 AppUi()->HandleCommandL( EWmlCmdCloseBrowser ); |
|
142 } |
|
143 else |
|
144 { |
|
145 CloseCurrentFolderL(); |
|
146 } |
|
147 break; |
|
148 } |
|
149 |
|
150 case EWmlCmdOpenFolder: |
|
151 { |
|
152 OpenCurrentFolderL(); |
|
153 break; |
|
154 } |
|
155 |
|
156 case EWmlCmdOpenMarkedFolder: |
|
157 { |
|
158 OpenMarkedFolderL(); |
|
159 break; |
|
160 } |
|
161 |
|
162 case EWmlCmdFavourites: |
|
163 { |
|
164 ApiProvider().SetViewToBeActivatedIfNeededL( KUidBrowserBookmarksViewId ); |
|
165 break; |
|
166 } |
|
167 |
|
168 case EWmlCmdMark: |
|
169 case EWmlCmdUnmark: |
|
170 case EWmlCmdMarkAll: |
|
171 case EWmlCmdUnmarkAll: |
|
172 { |
|
173 iContainer->Listbox()->HandleMarkableListCommandL( aCommand ); |
|
174 iContainer->HandleCursorChangedL( iContainer->Listbox() ); |
|
175 UpdateCbaL(); |
|
176 break; |
|
177 } |
|
178 |
|
179 case EWmlCmdDelete: |
|
180 { |
|
181 DeleteMarkedItemsL(); |
|
182 break; |
|
183 } |
|
184 |
|
185 case EWmlCmdNewFolder: |
|
186 { |
|
187 (void)AddNewFolderL(); |
|
188 break; |
|
189 } |
|
190 |
|
191 case EWmlCmdMoveToFolder: |
|
192 { |
|
193 MoveMarkedItemsL(); |
|
194 break; |
|
195 } |
|
196 |
|
197 |
|
198 case EWmlCmdRename: |
|
199 { |
|
200 RenameCurrentItemL(); |
|
201 break; |
|
202 } |
|
203 |
|
204 case EWmlCmdSetPreferredBookmark: |
|
205 { |
|
206 SetPreferedCurrentItemL(); |
|
207 break; |
|
208 } |
|
209 |
|
210 case EWmlCmdSetUnPreferredBookmark: |
|
211 { |
|
212 SetUnPreferedCurrentItemL(); |
|
213 break; |
|
214 } |
|
215 |
|
216 case EWmlCmdPreferences: |
|
217 { |
|
218 iSaveStateOnDeactivate = ETrue; |
|
219 AppUi()->HandleCommandL( aCommand ); |
|
220 break; |
|
221 } |
|
222 default : |
|
223 { |
|
224 AppUi()->HandleCommandL( aCommand ); |
|
225 break; |
|
226 } |
|
227 } |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // CBrowserFavouritesView::CBrowserFavouritesView |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 CBrowserFavouritesView::CBrowserFavouritesView( MApiProvider& aApiProvider, |
|
235 TInt aInitialFolderId ) |
|
236 : CBrowserViewBase( aApiProvider ), |
|
237 iPreferredHighlightUid( KFavouritesNullUid ), |
|
238 iShowOkOptions( EFalse ), |
|
239 iCurrentFolder( aInitialFolderId ), |
|
240 iIsActivated( EFalse ), |
|
241 iLastSelection( 0 ), |
|
242 iUpdatePending( EFalse ), |
|
243 iRefresh( ETrue ) |
|
244 { |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // CBrowserFavouritesView::ConstructL |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 void CBrowserFavouritesView::ConstructL( TInt aViewResourceId ) |
|
252 { |
|
253 BaseConstructL( aViewResourceId ); |
|
254 iModel = CreateModelL(); |
|
255 iInitialFolder = iCurrentFolder; |
|
256 // Ap model cannot be created without opening it; so that's not done here. |
|
257 // DoActivateL / DoDecativateL does that. |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CBrowserFavouritesView::GetItemsLC |
|
262 // --------------------------------------------------------- |
|
263 // |
|
264 CFavouritesItemList* CBrowserFavouritesView::GetItemsLC( TInt aFolder ) |
|
265 { |
|
266 CFavouritesItemList* items = new (ELeave) CFavouritesItemList(); |
|
267 CleanupStack::PushL( items ); |
|
268 iModel->Database().GetAll( *items, aFolder ); |
|
269 iModel->SortL( *items ); |
|
270 return items; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // CBrowserFavouritesView::GetSeamlessFolderResourceID |
|
275 // --------------------------------------------------------- |
|
276 // |
|
277 TInt CBrowserFavouritesView::GetSeamlessFolderResourceID( TInt aContextID ) |
|
278 { |
|
279 TInt resId = 0; |
|
280 |
|
281 switch( aContextID ) // Check if the item is a seamless link folder |
|
282 { |
|
283 case KFavouritesApplicationContextId: |
|
284 { |
|
285 resId = R_BROWSERBM_FOLDER_DOWNLOAD_APPLICATIONS; |
|
286 break; |
|
287 } |
|
288 case KFavouritesImageContextId: |
|
289 { |
|
290 resId = R_BROWSERBM_FOLDER_DOWNLOAD_IMAGES; |
|
291 break; |
|
292 } |
|
293 case KFavouritesAudioContextId: |
|
294 { |
|
295 resId = R_BROWSERBM_FOLDER_DOWNLOAD_TONES; |
|
296 break; |
|
297 } |
|
298 case KFavouritesVideoContextId: |
|
299 { |
|
300 resId = R_BROWSERBM_FOLDER_DOWNLOAD_VIDEOS; |
|
301 break; |
|
302 } |
|
303 case KFavouritesSkinContextId: |
|
304 { |
|
305 resId = R_BROWSERBM_FOLDER_DOWNLOAD_SKINS; |
|
306 break; |
|
307 } |
|
308 case KFavouritesMusicContextId: |
|
309 { |
|
310 resId = R_BROWSERBM_FOLDER_DOWNLOAD_MUSIC; |
|
311 break; |
|
312 } |
|
313 default: |
|
314 { |
|
315 break; // not a seamless link folder. |
|
316 } |
|
317 } |
|
318 |
|
319 return resId; |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------- |
|
324 // CBrowserFavouritesView::GetSeamlessFolderTitleResourceID |
|
325 // --------------------------------------------------------- |
|
326 // |
|
327 TInt CBrowserFavouritesView::GetSeamlessFolderTitleResourceID( TInt aContextID ) |
|
328 { |
|
329 TInt resId = 0; |
|
330 |
|
331 switch( aContextID ) // Check if the item is a seamless link folder |
|
332 { |
|
333 case KFavouritesApplicationContextId: |
|
334 { |
|
335 resId = R_BROWSERBM_FOLDER_TITLE_DOWNLOAD_APPLICATIONS; |
|
336 break; |
|
337 } |
|
338 case KFavouritesImageContextId: |
|
339 { |
|
340 resId = R_BROWSERBM_FOLDER_TITLE_DOWNLOAD_IMAGES; |
|
341 break; |
|
342 } |
|
343 case KFavouritesAudioContextId: |
|
344 { |
|
345 resId = R_BROWSERBM_FOLDER_TITLE_DOWNLOAD_TONES; |
|
346 break; |
|
347 } |
|
348 case KFavouritesVideoContextId: |
|
349 { |
|
350 resId = R_BROWSERBM_FOLDER_TITLE_DOWNLOAD_VIDEOS; |
|
351 break; |
|
352 } |
|
353 case KFavouritesSkinContextId: |
|
354 { |
|
355 resId = R_BROWSERBM_FOLDER_TITLE_DOWNLOAD_SKINS; |
|
356 break; |
|
357 } |
|
358 case KFavouritesMusicContextId: |
|
359 { |
|
360 resId = R_BROWSERBM_FOLDER_TITLE_DOWNLOAD_MUSIC; |
|
361 break; |
|
362 } |
|
363 default: |
|
364 { |
|
365 break; // not a seamless link folder. |
|
366 } |
|
367 } |
|
368 |
|
369 return resId; |
|
370 } |
|
371 |
|
372 |
|
373 // --------------------------------------------------------- |
|
374 // CBrowserFavouritesView::IsSeamlessFolder |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 TInt CBrowserFavouritesView::IsSeamlessFolder( TInt aContextID ) |
|
378 { |
|
379 return GetSeamlessFolderResourceID( aContextID ) != 0 ? ETrue : EFalse; |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------- |
|
383 // CBrowserFavouritesView::HighlightPreferredL |
|
384 // --------------------------------------------------------- |
|
385 // |
|
386 void CBrowserFavouritesView::HighlightPreferredL() |
|
387 { |
|
388 if (( iContainer->Listbox()->HighlightUidNow( iPreferredHighlightUid ) ) && |
|
389 ( iPreferredHighlightUid != KFavouritesNullUid )) |
|
390 { |
|
391 // Have a preferred uid... |
|
392 // Successfully highlighted; clear preferred now. |
|
393 iPreferredHighlightUid = KFavouritesNullUid; |
|
394 iContainer->HandleCursorChangedL( iContainer->Listbox() ); |
|
395 } |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------- |
|
399 // CBrowserFavouritesView::RefreshL |
|
400 // --------------------------------------------------------- |
|
401 // |
|
402 void CBrowserFavouritesView::RefreshL( TBool aDbErrorNote /*=EFalse*/ ) |
|
403 { |
|
404 // Do the refresh only if activated; otherwise ignore. |
|
405 // (This is a sanity-check like functionality, but is really used. |
|
406 // Bookmarks View observes changes in active and default AP-s, even if |
|
407 // not activated (and tries to refresh); but this "activated-check" is |
|
408 // made here, not in Bookmarks View, because it makes things more safe and |
|
409 // "future-proof".) |
|
410 if ( iIsActivated ) |
|
411 { |
|
412 iUpdatePending = ETrue; |
|
413 if ( !iIncrementalOp ) |
|
414 { |
|
415 // During an incremental operation we should never do the update |
|
416 // and refill the listbox because some of the operations holds |
|
417 // pointers to listbox items. Update is pending then. |
|
418 if ( iModel->BeginL( /*aWrite=*/EFalse, aDbErrorNote ) == |
|
419 KErrNone ) |
|
420 { |
|
421 TInt folderExists; |
|
422 iModel->Database().FolderExists( iCurrentFolder, folderExists ); |
|
423 if ( folderExists ) |
|
424 { |
|
425 // Current folder is still OK. Refresh. |
|
426 FillListboxL( iCurrentFolder, /*aKeepState=*/ETrue ); |
|
427 } |
|
428 else |
|
429 { |
|
430 // Cannot access current folder (maybe deleted). |
|
431 // Go to root. |
|
432 OpenFolderL( KFavouritesRootUid ); |
|
433 } |
|
434 iModel->CommitL(); |
|
435 iUpdatePending = EFalse; |
|
436 } |
|
437 // iUpdatePending stays ETrue if unsuccessful. |
|
438 } |
|
439 } |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------- |
|
443 // CBrowserFavouritesView::DoActivateL |
|
444 // --------------------------------------------------------- |
|
445 // |
|
446 void CBrowserFavouritesView::DoActivateL( |
|
447 const TVwsViewId& /*aPrevViewId*/, |
|
448 TUid /*aCustomMessageId*/, |
|
449 const TDesC8& /*aCustomMessage*/ ) |
|
450 { |
|
451 iPreviousViewID = ApiProvider().LastActiveViewId( ); |
|
452 ApiProvider().SetLastActiveViewId( Id() ); |
|
453 ApiProvider().CommsModel().AddObserverL( *this ); |
|
454 iContainer = CreateContainerL(); |
|
455 iModel->AddObserverL( *this ); |
|
456 AppUi()->AddToViewStackL( *this, iContainer ); |
|
457 |
|
458 ApiProvider().StartProgressAnimationL(); |
|
459 |
|
460 if ( iModel->BeginL( /*aWrite=*/EFalse, /*aDbErrorNote=*/ETrue ) |
|
461 == KErrNone ) |
|
462 { |
|
463 // Disable redraw to avoid flickering. |
|
464 // (OpenFolderL and the listbox's SetStateL both |
|
465 // wants to redraw the listbox. Do it once only.) |
|
466 TBool redrawDisabled = |
|
467 iContainer->Listbox()->View()->RedrawDisabled(); |
|
468 iContainer->Listbox()->View()->SetDisableRedraw( ETrue ); |
|
469 // Open folder first. |
|
470 OpenFolderL( iCurrentFolder ); |
|
471 iModel->CommitL(); |
|
472 |
|
473 // Now set back redraw and draw the listbox. |
|
474 if ( (iLastSelection >=0 )) |
|
475 { |
|
476 if ( iLastSelection > iContainer->Listbox()->BottomItemIndex() ) |
|
477 { |
|
478 iLastSelection = 0; |
|
479 } |
|
480 iContainer->Listbox()->SetCurrentItemIndex( iLastSelection ); |
|
481 UpdateGotoPaneL(); |
|
482 } |
|
483 |
|
484 iContainer->Listbox()->View()->SetDisableRedraw( redrawDisabled ); |
|
485 iContainer->Listbox()->DrawNow(); |
|
486 } |
|
487 else |
|
488 { |
|
489 // No folder is opened; update CBA and Navi Pane now. |
|
490 if ( iLastSelection >=0 ) |
|
491 { |
|
492 iContainer->Listbox()->SetCurrentItemIndex( iLastSelection ); |
|
493 UpdateGotoPaneL(); |
|
494 } |
|
495 UpdateCbaL(); |
|
496 UpdateNaviPaneL(); |
|
497 } |
|
498 |
|
499 if (iSavedListboxState) |
|
500 { |
|
501 iContainer->Listbox()->SetStateL(*iSavedListboxState); |
|
502 } |
|
503 iIsActivated = ETrue; |
|
504 } |
|
505 |
|
506 // ---------------------------------------------------------------------------- |
|
507 // CBrowserFavouritesView::ResetStateInDeActivation |
|
508 // ---------------------------------------------------------------------------- |
|
509 // |
|
510 void CBrowserFavouritesView::ResetStateInDeActivation() |
|
511 { |
|
512 //Set iLastSelection to zero if there will be a folder change |
|
513 if ( iCurrentFolder != iInitialFolder ) |
|
514 { |
|
515 iLastSelection = 0; |
|
516 } |
|
517 } |
|
518 |
|
519 // --------------------------------------------------------- |
|
520 // CBrowserFavouritesView::DoDeactivate |
|
521 // --------------------------------------------------------- |
|
522 // |
|
523 void CBrowserFavouritesView::DoDeactivate() |
|
524 { |
|
525 iIsActivated = EFalse; |
|
526 TRAP_IGNORE(ApiProvider().StopProgressAnimationL()); |
|
527 if ( iContainer ) |
|
528 { |
|
529 iLastSelection = iContainer->Listbox()->CurrentItemIndex(); |
|
530 } |
|
531 |
|
532 if ( !iSaveStateOnDeactivate ) |
|
533 { |
|
534 ResetStateInDeActivation(); // entering root directory |
|
535 iSaveStateOnDeactivate = EFalse; |
|
536 } |
|
537 else |
|
538 { |
|
539 CBrowserFavouritesListboxState *temp = NULL; |
|
540 TInt err( KErrNone ); |
|
541 TInt tempUid( KFavouritesNullUid ); |
|
542 |
|
543 temp = new CBrowserFavouritesListboxState; |
|
544 if ( temp!=NULL ) |
|
545 { |
|
546 delete iSavedListboxState; |
|
547 iSavedListboxState = temp; |
|
548 // folder might be empty, no CurrentItem at all |
|
549 if ( iContainer->Listbox()->CurrentItem() ) |
|
550 { |
|
551 tempUid = iContainer->Listbox()->CurrentItem()->Uid(); |
|
552 } |
|
553 iSavedListboxState->iHighlightUid = tempUid; |
|
554 TRAP( err, { |
|
555 iSavedListboxState->iMarkUids = iContainer->Listbox()->MarkedUidsLC(); |
|
556 CleanupStack::Pop(); // Uid list; ownership is now in the state. |
|
557 } ) |
|
558 } |
|
559 if ( !err ) |
|
560 { |
|
561 iSavedListboxState->iTopItemUid = tempUid; |
|
562 } |
|
563 else |
|
564 { |
|
565 delete iSavedListboxState; |
|
566 } |
|
567 } |
|
568 |
|
569 if ( !ApiProvider().ExitInProgress() ) |
|
570 { |
|
571 ApiProvider().CommsModel().RemoveObserver( *this ); |
|
572 } |
|
573 iModel->RemoveObserver( *this ); |
|
574 |
|
575 if ( iContainer ) |
|
576 { |
|
577 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
578 delete iContainer; |
|
579 iContainer = NULL; |
|
580 } |
|
581 iModel->CloseDb(); |
|
582 } |
|
583 |
|
584 // --------------------------------------------------------- |
|
585 // CBrowserFavouritesView::HandleClientRectChange |
|
586 // --------------------------------------------------------- |
|
587 // |
|
588 void CBrowserFavouritesView::HandleClientRectChange() |
|
589 { |
|
590 if ( iContainer ) |
|
591 { |
|
592 iContainer->SetRect( ClientRect() ); |
|
593 } |
|
594 } |
|
595 |
|
596 // --------------------------------------------------------- |
|
597 // CBrowserFavouritesView::DynInitMenuPaneL |
|
598 // --------------------------------------------------------- |
|
599 // |
|
600 void CBrowserFavouritesView::DynInitMenuPaneL |
|
601 ( TInt aResourceId, CEikMenuPane* aMenuPane ) |
|
602 { |
|
603 if ( iContainer && iContainer->Listbox() ) |
|
604 { |
|
605 TBrowserFavouritesSelectionState state = |
|
606 iContainer->Listbox()->SelectionStateL(); |
|
607 TCommandVisibility::TIndex index = |
|
608 TCommandVisibility::Index( state, iShowOkOptions ); |
|
609 DynInitMenuPaneL( aResourceId, aMenuPane, index, state ); |
|
610 } |
|
611 } |
|
612 |
|
613 // --------------------------------------------------------- |
|
614 // CBrowserFavouritesView::HandleForegroundEventL |
|
615 // --------------------------------------------------------- |
|
616 // |
|
617 void CBrowserFavouritesView::HandleForegroundEventL( TBool aForeground ) |
|
618 { |
|
619 // If another thread made changes to database, sometimes we could not |
|
620 // refresh when the notifcation comes in (most likely the other thread |
|
621 // closes the database and that performs an automatic compact(?)). |
|
622 // When coming foreground, check for missed updates. |
|
623 // Also, when coming to foreground Refresh if Skin has changed |
|
624 if ( aForeground && (iUpdatePending || iContainer->Listbox()->IsSkinUpdated())) |
|
625 { |
|
626 RefreshL(); |
|
627 if (iContainer->Listbox()->IsSkinUpdated()) |
|
628 { |
|
629 iContainer->Listbox()->SetSkinUpdated(EFalse); |
|
630 } |
|
631 } |
|
632 } |
|
633 |
|
634 // --------------------------------------------------------- |
|
635 // CBrowserFavouritesView::HandleListBoxEventL |
|
636 // --------------------------------------------------------- |
|
637 // |
|
638 void CBrowserFavouritesView::HandleListBoxEventL |
|
639 ( CEikListBox* aListBox, MEikListBoxObserver::TListBoxEvent aEventType ) |
|
640 { |
|
641 if ( aListBox == iContainer->Listbox() ) |
|
642 { |
|
643 switch ( aEventType ) |
|
644 { |
|
645 case MEikListBoxObserver::EEventEnterKeyPressed: |
|
646 case MEikListBoxObserver::EEventItemDoubleClicked: |
|
647 { |
|
648 if ( iContainer->Listbox()->CurrentItem() ) |
|
649 { |
|
650 if ( iContainer->Listbox()->CurrentItem()->IsFolder() ) |
|
651 { |
|
652 OpenCurrentFolderL(); |
|
653 } |
|
654 } |
|
655 break; |
|
656 } |
|
657 |
|
658 default: |
|
659 { |
|
660 break; |
|
661 } |
|
662 } |
|
663 } |
|
664 } |
|
665 |
|
666 // --------------------------------------------------------- |
|
667 // CBrowserFavouritesView::CloseCurrentFolderL |
|
668 // --------------------------------------------------------- |
|
669 // |
|
670 void CBrowserFavouritesView::CloseCurrentFolderL() |
|
671 { |
|
672 if ( iCurrentFolder != KFavouritesRootUid ) |
|
673 { |
|
674 // Folders are one level deep. Closing any folder takes us to root. |
|
675 if ( iModel->BeginL( /*aWrite=*/EFalse, /*aDbErrorNote=*/ETrue ) |
|
676 == KErrNone ) |
|
677 { |
|
678 if ( iContainer && iContainer->Listbox() ) |
|
679 { |
|
680 // After closing, the highlight should be |
|
681 // on the folder just being closed. |
|
682 iPreferredHighlightUid = iCurrentFolder; |
|
683 OpenFolderL( KFavouritesRootUid ); |
|
684 } |
|
685 iModel->CommitL(); |
|
686 } |
|
687 } |
|
688 } |
|
689 |
|
690 // --------------------------------------------------------- |
|
691 // CBrowserFavouritesView::OpenCurrentFolderL |
|
692 // --------------------------------------------------------- |
|
693 // |
|
694 void CBrowserFavouritesView::OpenCurrentFolderL() |
|
695 { |
|
696 if ( iContainer && iContainer->Listbox() ) |
|
697 { |
|
698 const CFavouritesItem* folder = |
|
699 iContainer->Listbox()->CurrentItem(); |
|
700 if ( folder && folder->IsFolder() ) |
|
701 { |
|
702 if ( iModel->BeginL( /*aWrite=*/EFalse, /*aDbErrorNote=*/ETrue ) |
|
703 == KErrNone ) |
|
704 { |
|
705 OpenFolderL( folder->Uid() ); |
|
706 iModel->CommitL(); |
|
707 } |
|
708 } |
|
709 } |
|
710 } |
|
711 |
|
712 // --------------------------------------------------------- |
|
713 // CBrowserFavouritesView::OpenMarkedFolderL |
|
714 // --------------------------------------------------------- |
|
715 // |
|
716 void CBrowserFavouritesView::OpenMarkedFolderL() |
|
717 { |
|
718 if ( iContainer && iContainer->Listbox() ) |
|
719 { |
|
720 const CFavouritesItem* folder = |
|
721 iContainer->Listbox()->MarkedItemL(); |
|
722 if ( folder && folder->IsFolder() ) |
|
723 { |
|
724 if ( iModel->BeginL( /*aWrite=*/EFalse, /*aDbErrorNote=*/ETrue ) |
|
725 == KErrNone ) |
|
726 { |
|
727 OpenFolderL( folder->Uid() ); |
|
728 iModel->CommitL(); |
|
729 } |
|
730 } |
|
731 } |
|
732 } |
|
733 |
|
734 // --------------------------------------------------------- |
|
735 // CBrowserFavouritesView::DeleteMarkedItemsL |
|
736 // --------------------------------------------------------- |
|
737 // |
|
738 void CBrowserFavouritesView::DeleteMarkedItemsL() |
|
739 { |
|
740 CArrayPtr<const CFavouritesItem>* items = |
|
741 iContainer->Listbox()->SelectedItemsLC(); |
|
742 // Permormance optimization: keep a separate list for folders. |
|
743 // (Make the "non-empty folder" check only for folders; this speeds up |
|
744 // things considerably when many items are selected.) |
|
745 CArrayFix<TInt>* uids = NewUidListLC(); |
|
746 CArrayFix<TInt>* folderUids = NewUidListLC(); |
|
747 TInt i; |
|
748 TInt count = items->Count(); |
|
749 const CFavouritesItem* item = NULL; |
|
750 |
|
751 for ( i = 0; i < count; i++ ) |
|
752 { |
|
753 item = items->At( i ); |
|
754 uids->AppendL( item->Uid() ); |
|
755 if ( item->IsFolder() ) |
|
756 { |
|
757 folderUids->AppendL( item->Uid() ); |
|
758 } |
|
759 } |
|
760 // Cannot delete the "items" pointer list, as other objects were pushed |
|
761 // after it. But DO NOT USE it after this point! The call to ConfirmDeleteL |
|
762 // allows other active objects to run, and the listbox may be updated. |
|
763 // If listbox is updated, all pointers in "items" point to deleted objects. |
|
764 |
|
765 if ( ConfirmDeleteL( *uids, *folderUids ) ) |
|
766 { |
|
767 |
|
768 if (count ==1) |
|
769 { |
|
770 CFavouritesItemList* allItems = GetItemsLC( KFavouritesRootUid ); |
|
771 item = items->At(0); |
|
772 iPreferredHighlightUid = item->Uid(); |
|
773 TInt index = allItems->UidToIndex(iPreferredHighlightUid); |
|
774 index++; |
|
775 if (allItems->IndexToUid(index) != NULL) |
|
776 { |
|
777 iPreferredHighlightUid = allItems->IndexToUid(index); |
|
778 } |
|
779 else |
|
780 { |
|
781 iPreferredHighlightUid = allItems->IndexToUid(index-2); |
|
782 } |
|
783 CleanupStack::PopAndDestroy(); //allItems |
|
784 } |
|
785 |
|
786 |
|
787 CArrayFix<TInt>* notDeletedUids = NewUidListLC(); |
|
788 |
|
789 // OOD handling. If disk space is low, we try to get some spare. |
|
790 |
|
791 CRepository* repository = CRepository::NewL( KCRUidBrowser ); |
|
792 |
|
793 TBool diskLow = Util::FFSSpaceBelowCriticalLevelL |
|
794 ( /*aShowErrorNote=*/EFalse, KEstimatedDeleteFfsOverhead ); |
|
795 if ( diskLow ) |
|
796 { |
|
797 // Using disk space requests is not supported by CenRep. |
|
798 delete repository; |
|
799 } |
|
800 |
|
801 if ( !iModel->BeginL |
|
802 ( |
|
803 /*aWrite=*/ETrue, |
|
804 /*aDbErrorNote=*/ETrue, |
|
805 /*aLffsCheck=*/EFalse |
|
806 ) |
|
807 ) |
|
808 { |
|
809 __ASSERT_DEBUG( !iIncrementalOp, Util::Panic |
|
810 ( Util::EIncrementalOperationAlreadyRunning ) ); |
|
811 // Seems we have to give lower priority to the delete operation, |
|
812 // or else the wait note does not show up. |
|
813 iIncrementalOp = CBrowserFavouritesIncrementalDelete::NewL |
|
814 ( |
|
815 *iModel, |
|
816 *uids, |
|
817 *notDeletedUids, |
|
818 CActive::EPriorityStandard - 1 |
|
819 ); |
|
820 iIncrementalOp->ExecuteL(); |
|
821 delete iIncrementalOp; |
|
822 iIncrementalOp = NULL; |
|
823 iModel->CommitL(); |
|
824 |
|
825 if ( diskLow ) |
|
826 { |
|
827 // Compact database now. |
|
828 iModel->Database().Compact(); |
|
829 // Make a manual refresh. When we get notification about the |
|
830 // commit, database is most likely busy with compact, and |
|
831 // the refresh is missed. |
|
832 RefreshL(); |
|
833 } |
|
834 |
|
835 // Everything that can be deleted, is deleted by now. |
|
836 // Let the user know the outcome. |
|
837 DisplayResultOfDeleteL( *uids, *notDeletedUids ); |
|
838 // Refresh the view only in embedded mode because in standalone mode Refresh is called by |
|
839 // HandleFavouritesModelChangeL causing the view to refresh twice and lose the cursor position |
|
840 if ( ApiProvider().IsEmbeddedModeOn() ) |
|
841 { |
|
842 RefreshL(); |
|
843 } |
|
844 } |
|
845 |
|
846 for ( TInt ii = 0; ii< uids->Count(); ii++ ) |
|
847 { |
|
848 TInt prefUid; |
|
849 iModel->Database().PreferredUid( iCurrentFolder, prefUid ); |
|
850 if ( prefUid == uids->At( ii ) ) |
|
851 { |
|
852 iModel->Database().SetPreferredUid( iCurrentFolder,NULL ); |
|
853 break; |
|
854 } |
|
855 } |
|
856 |
|
857 CleanupStack::PopAndDestroy(); // notDeletedUids |
|
858 } |
|
859 CleanupStack::PopAndDestroy( 3 ); // folderUids, uids, items |
|
860 } |
|
861 |
|
862 // --------------------------------------------------------- |
|
863 // CBrowserFavouritesView::AddNewFolderL |
|
864 // --------------------------------------------------------- |
|
865 // |
|
866 TInt CBrowserFavouritesView::AddNewFolderL() |
|
867 { |
|
868 TInt uid = KFavouritesNullUid; |
|
869 // Make an item and fill it with default values. |
|
870 CFavouritesItem* folder = CFavouritesItem::NewLC(); |
|
871 folder->SetType( CFavouritesItem::EFolder ); |
|
872 folder->SetParentFolder( KFavouritesRootUid ); |
|
873 iModel->SetNameToDefaultL( *folder ); |
|
874 TInt err = iModel->MakeUniqueNameL( *folder ); |
|
875 if ( !err ) |
|
876 { |
|
877 // We have the folder with a default unique name. |
|
878 // Let the user rename it. |
|
879 if ( iModel->RenameQueryL( *folder, ETrue )) |
|
880 { |
|
881 // Rename accepted. |
|
882 err = iModel->AddL( *folder, /*aDbErrorNote=*/ETrue, |
|
883 CBrowserFavouritesModel::EAskIfRename ); |
|
884 if ( !err ) |
|
885 { |
|
886 // Succesfully created. Set highlight to new folder (by setting |
|
887 // preferred highlight uid - we have not see the new folder |
|
888 // yet, until db notification kicks in. |
|
889 uid = iPreferredHighlightUid = folder->Uid(); |
|
890 } |
|
891 } |
|
892 } |
|
893 CleanupStack::PopAndDestroy(); // folder |
|
894 return uid; |
|
895 } |
|
896 |
|
897 // --------------------------------------------------------- |
|
898 // CBrowserFavouritesView::MoveMarkedItemsL |
|
899 // --------------------------------------------------------- |
|
900 // |
|
901 void CBrowserFavouritesView::MoveMarkedItemsL() |
|
902 { |
|
903 TInt targetFolder = SelectTargetFolderL( iCurrentFolder ); |
|
904 |
|
905 // If we have the target folder, do the move. |
|
906 if ( targetFolder != KFavouritesNullUid ) |
|
907 { |
|
908 CArrayFix<TInt>* uids = iContainer->Listbox()->SelectedUidsLC(); |
|
909 CArrayFix<TInt>* unmovableUids = NewUidListLC(); |
|
910 CArrayFix<TInt>* conflictingNameUids = NewUidListLC(); |
|
911 if ( !iModel->BeginL( /*aWrite=*/ETrue, /*aDbErrorNote=*/ETrue ) ) |
|
912 { |
|
913 __ASSERT_DEBUG( !iIncrementalOp, Util::Panic |
|
914 ( Util::EIncrementalOperationAlreadyRunning ) ); |
|
915 // Seems we have to give lower priority to the move operation, |
|
916 // or else the wait note does not show up. |
|
917 iIncrementalOp = CBrowserFavouritesIncrementalMove::NewL |
|
918 ( |
|
919 *iModel, |
|
920 *uids, |
|
921 *unmovableUids, |
|
922 *conflictingNameUids, |
|
923 targetFolder, |
|
924 CActive::EPriorityStandard - 1 |
|
925 ); |
|
926 iIncrementalOp->ExecuteL(); |
|
927 delete iIncrementalOp; |
|
928 iIncrementalOp = NULL; |
|
929 iModel->CommitL(); |
|
930 // Everything that can be moved, is moved by now. |
|
931 // If some items could not be moved, see why. |
|
932 HandleMoveResultL |
|
933 ( targetFolder, *uids, *unmovableUids, *conflictingNameUids ); |
|
934 |
|
935 for ( TInt ii = 0; ii< uids->Count(); ii++ ) |
|
936 { |
|
937 TInt prefUid; |
|
938 iModel->Database().PreferredUid( iCurrentFolder, prefUid ); |
|
939 if ( prefUid == uids->At( ii ) ) |
|
940 { |
|
941 iModel->Database().SetPreferredUid( iCurrentFolder,NULL ); |
|
942 break; |
|
943 } |
|
944 } |
|
945 |
|
946 CBrowserBookmarksOrder* bmOrder = CBrowserBookmarksOrder::NewLC(); |
|
947 CArrayFixFlat<TInt>* orderArray = new (ELeave) CArrayFixFlat<TInt>(KGranularityHigh); |
|
948 CleanupStack::PushL( orderArray ); |
|
949 if ( Model().Database().GetData( CurrentFolder() ,*bmOrder ) == KErrNone) |
|
950 { |
|
951 if ( bmOrder->GetBookMarksOrder().Count() ) |
|
952 { |
|
953 orderArray->AppendL( &( bmOrder->GetBookMarksOrder()[0] ), bmOrder->GetBookMarksOrder().Count()); |
|
954 TInt swapTo = 0; |
|
955 TInt swappedItem; |
|
956 for ( TInt i=0; i<orderArray->Count();i++ ) |
|
957 { |
|
958 TInt swapFrom=0; |
|
959 while (swapFrom<uids->Count() && ( (*uids)[swapFrom] != ( *orderArray )[i]) ) |
|
960 { |
|
961 swapFrom++; |
|
962 } |
|
963 if (swapFrom<uids->Count()) |
|
964 { |
|
965 if ((swapFrom != swapTo) && (swapTo < uids->Count() ) ) |
|
966 { |
|
967 swappedItem = ( *uids )[swapFrom]; |
|
968 ( *uids )[swapFrom] = ( *uids )[swapTo]; |
|
969 ( *uids )[swapTo] = swappedItem; |
|
970 } |
|
971 swapTo++; |
|
972 } |
|
973 } |
|
974 } |
|
975 } |
|
976 |
|
977 orderArray->Reset(); |
|
978 if ( Model().Database().GetData( targetFolder ,*bmOrder ) == KErrNone) |
|
979 { |
|
980 if ( bmOrder->GetBookMarksOrder().Count() ) |
|
981 { |
|
982 orderArray->AppendL( &( bmOrder->GetBookMarksOrder()[0] ), bmOrder->GetBookMarksOrder().Count()); |
|
983 if ( orderArray->Count() ) |
|
984 { |
|
985 for ( TInt i = 0; i < uids->Count(); i++ ) |
|
986 { |
|
987 for (TInt j = 0; j < orderArray->Count(); j++ ) |
|
988 { |
|
989 if ( orderArray->At( j ) == uids->At( i )) |
|
990 { |
|
991 orderArray->Delete( j ); |
|
992 } |
|
993 } |
|
994 Model().AddUidToLastPlaceL(uids->At( i ), orderArray, bmOrder); |
|
995 } |
|
996 bmOrder->SetBookMarksOrderL( *orderArray ); |
|
997 Model().Database().SetData( targetFolder , *bmOrder ); |
|
998 } |
|
999 } |
|
1000 } |
|
1001 |
|
1002 CleanupStack::PopAndDestroy( ); //orderArray |
|
1003 CleanupStack::PopAndDestroy( ); //bmOrder |
|
1004 } |
|
1005 CleanupStack::PopAndDestroy( 3 ); // conflictingNameUids, |
|
1006 // unmovableUids, uids |
|
1007 } |
|
1008 } |
|
1009 |
|
1010 // --------------------------------------------------------- |
|
1011 // CBrowserFavouritesView::RenameCurrentItemL |
|
1012 // --------------------------------------------------------- |
|
1013 // |
|
1014 void CBrowserFavouritesView::RenameCurrentItemL() |
|
1015 { |
|
1016 if ( iContainer && iContainer->Listbox() ) |
|
1017 { |
|
1018 const CFavouritesItem* listboxItem = |
|
1019 iContainer->Listbox()->CurrentItem(); |
|
1020 if ( listboxItem ) |
|
1021 { |
|
1022 CFavouritesItem* item = CFavouritesItem::NewLC(); |
|
1023 *item = *listboxItem; |
|
1024 if ( iModel->RenameQueryL( *item, EFalse ) ) |
|
1025 { |
|
1026 iModel->UpdateL |
|
1027 ( |
|
1028 *item, |
|
1029 listboxItem->Uid(), |
|
1030 /*aDbErrorNote=*/ETrue, |
|
1031 CBrowserFavouritesModel::EAskIfRename |
|
1032 ); |
|
1033 |
|
1034 iPreferredHighlightUid = item->Uid(); |
|
1035 |
|
1036 // Show infonote "Unable to rename" if read-only item |
|
1037 if ( listboxItem->IsReadOnly() ) |
|
1038 { |
|
1039 TBrowserDialogs::InfoNoteL |
|
1040 ( |
|
1041 R_BROWSER_INFO_NOTE, |
|
1042 _R(TEXT_PRMPT_CANT_RENAME), |
|
1043 listboxItem->Name() |
|
1044 ); |
|
1045 } |
|
1046 } |
|
1047 CleanupStack::PopAndDestroy(); // item |
|
1048 } |
|
1049 } |
|
1050 } |
|
1051 |
|
1052 // --------------------------------------------------------- |
|
1053 // CBrowserFavouritesView::SetRootFolderForAdaptiveBookmarks |
|
1054 // --------------------------------------------------------- |
|
1055 // |
|
1056 void CBrowserFavouritesView::SetRootFolderForAdaptiveBookmarks() |
|
1057 { |
|
1058 iCurrentFolder = KFavouritesRootUid; |
|
1059 } |
|
1060 |
|
1061 // --------------------------------------------------------- |
|
1062 // CBrowserFavouritesView::OpenFolderL |
|
1063 // --------------------------------------------------------- |
|
1064 // |
|
1065 void CBrowserFavouritesView::OpenFolderL( TInt aFolder ) |
|
1066 { |
|
1067 |
|
1068 CFavouritesItem* folder = CFavouritesItem::NewLC(); |
|
1069 if ( iModel->Database().Get( aFolder, *folder ) == KErrNone ) |
|
1070 { |
|
1071 iContainer->Listbox()->GetDefaultData().iPreferedId = NULL; |
|
1072 iContainer->Listbox()->GetDefaultData().iInSeamlessFolder = EFalse; |
|
1073 // Set title. |
|
1074 if ( aFolder == KFavouritesRootUid ) |
|
1075 { |
|
1076 UpdateNaviPaneL(); // remove NaviPane before setting title - SetTitleL redraws |
|
1077 ApiProvider().Display().SetTitleL( RootTitleResourceId() ); |
|
1078 } |
|
1079 else |
|
1080 { |
|
1081 // Next get localized title text if the folder is a seamless link folder. |
|
1082 TInt resId = CBrowserFavouritesView::GetSeamlessFolderTitleResourceID( |
|
1083 folder->ContextId() ); |
|
1084 HBufC* name; |
|
1085 |
|
1086 if (resId) |
|
1087 { |
|
1088 iContainer->Listbox()->GetDefaultData().iInSeamlessFolder = ETrue; |
|
1089 TInt prefUid; |
|
1090 iModel->Database().PreferredUid( aFolder, prefUid ); |
|
1091 iContainer->Listbox()->GetDefaultData().iPreferedId = prefUid; |
|
1092 name = iCoeEnv->AllocReadResourceLC( resId ); |
|
1093 folder->SetNameL(name->Des()); // set the localized name |
|
1094 CleanupStack::PopAndDestroy(); // name |
|
1095 } |
|
1096 |
|
1097 ApiProvider().Display().SetTitleL( folder->Name() ); |
|
1098 } |
|
1099 |
|
1100 iCurrentFolder = aFolder; |
|
1101 FillListboxL( aFolder, /*aKeepState=*/EFalse ); |
|
1102 Container()->Listbox()->ClearSelection(); |
|
1103 UpdateCbaL(); |
|
1104 UpdateNaviPaneL(); |
|
1105 } |
|
1106 CleanupStack::PopAndDestroy(); // folder |
|
1107 } |
|
1108 |
|
1109 // --------------------------------------------------------- |
|
1110 // CBrowserFavouritesView::OpenNextFolderL |
|
1111 // --------------------------------------------------------- |
|
1112 // |
|
1113 void CBrowserFavouritesView::OpenNextFolderL( TBool aForward ) |
|
1114 { |
|
1115 __ASSERT_DEBUG( iCurrentFolder != KFavouritesRootUid, |
|
1116 Util::Panic( Util::ERootLevel ) ); |
|
1117 |
|
1118 if ( iModel->BeginL( /*aWrite=*/EFalse, /*aDbErrorNote=*/ETrue ) |
|
1119 == KErrNone ) |
|
1120 { |
|
1121 TInt nextFolder = iModel->NextFolderL( iCurrentFolder, aForward ); |
|
1122 if ( nextFolder != KFavouritesNullUid ) |
|
1123 { |
|
1124 OpenFolderL( nextFolder ); |
|
1125 } |
|
1126 iModel->CommitL(); |
|
1127 } |
|
1128 } |
|
1129 |
|
1130 // --------------------------------------------------------- |
|
1131 // CBrowserFavouritesView::FillListboxL |
|
1132 // --------------------------------------------------------- |
|
1133 // |
|
1134 void CBrowserFavouritesView::FillListboxL( TInt aFolder, TBool aKeepState ) |
|
1135 { |
|
1136 // During an incremental operation we should never update the listbox |
|
1137 // because some of them holds pointers to listbox items. |
|
1138 // |
|
1139 // If we have an incremental operation, we should never get here: |
|
1140 // 1) Any change notification (faves db, ap db, preferences) handling is |
|
1141 // skipped in RefreshL, where all change handling comes |
|
1142 // together. |
|
1143 // 2) All incremental operations have an empty CBA, so we cannot get here |
|
1144 // by user input either. |
|
1145 // But to make this safe from potential errors (e.g. user activity due to |
|
1146 // some error in wait notes, CBA, key handling etc., and also from bugs in |
|
1147 // this code), we double-check here. |
|
1148 // In release build do nothing (avoid the crash), in debug build panic. |
|
1149 if ( iIncrementalOp ) |
|
1150 { |
|
1151 #ifdef _DEBUG |
|
1152 Util::Panic( Util::ECannotUpdateDataInUse ); |
|
1153 #else |
|
1154 return; |
|
1155 #endif |
|
1156 } |
|
1157 |
|
1158 CBrowserFavouritesListbox* listbox = iContainer->Listbox(); |
|
1159 |
|
1160 // Disable redraw to avoid flickering. |
|
1161 TBool redrawDisabled = listbox->View()->RedrawDisabled(); |
|
1162 listbox->View()->SetDisableRedraw( ETrue ); |
|
1163 |
|
1164 // Change the data. |
|
1165 CFavouritesItemList* items = GetItemsLC( aFolder ); |
|
1166 |
|
1167 // Next take localized item names for seamless links. |
|
1168 TInt contextId; |
|
1169 TInt resId = 0; |
|
1170 HBufC* name; |
|
1171 for (int i=0; i<items->Count(); i++) |
|
1172 { |
|
1173 if (!items->At(i)->IsHidden()) |
|
1174 { |
|
1175 contextId = items->At(i)->ContextId(); |
|
1176 resId = CBrowserFavouritesView::GetSeamlessFolderResourceID( |
|
1177 contextId ); |
|
1178 |
|
1179 if (resId) |
|
1180 { |
|
1181 name = iCoeEnv->AllocReadResourceLC( resId ); |
|
1182 items->At(i)->SetNameL(name->Des()); |
|
1183 CleanupStack::PopAndDestroy(); // name |
|
1184 } |
|
1185 } |
|
1186 else |
|
1187 { |
|
1188 items->Delete(i); |
|
1189 i--; |
|
1190 } |
|
1191 } |
|
1192 |
|
1193 CleanupStack::Pop(); // items: passing ownership to listbox. |
|
1194 iContainer->Listbox()->SetDataL |
|
1195 ( items, /*ApiProvider().CommsModel(),*/ aKeepState ); |
|
1196 CAknColumnListBoxView *aknview = STATIC_CAST(CAknColumnListBoxView*, iContainer->Listbox()->View() ); |
|
1197 |
|
1198 if ( !items->Count() ) |
|
1199 { |
|
1200 iContainer->Listbox()->UpdateFilterL(); // ...and tell to listbox. |
|
1201 aknview->SetFindEmptyListState(EFalse); |
|
1202 } |
|
1203 else |
|
1204 { |
|
1205 aknview->SetFindEmptyListState(ETrue); |
|
1206 } |
|
1207 |
|
1208 iContainer->SizeChanged(); // Needed to show/hide Find Pane! |
|
1209 iCurrentFolder = aFolder; |
|
1210 |
|
1211 HighlightPreferredL(); |
|
1212 iContainer->HandleCursorChangedL( listbox ); |
|
1213 listbox->View()->SetDisableRedraw( redrawDisabled ); |
|
1214 listbox->DrawNow(); |
|
1215 |
|
1216 UpdateCbaL(); |
|
1217 UpdateNaviPaneL(); |
|
1218 } |
|
1219 |
|
1220 // ---------------------------------------------------------------------------- |
|
1221 // CBrowserFavouritesView::ConfirmDeleteL |
|
1222 // ---------------------------------------------------------------------------- |
|
1223 // |
|
1224 TBool CBrowserFavouritesView::ConfirmDeleteL |
|
1225 ( CArrayFix<TInt>& aUids, CArrayFix<TInt>& aFolderUids ) |
|
1226 { |
|
1227 CBrowserFavouritesModel::TDbQuery anyNonEmptyFolders; |
|
1228 TInt ret = EFalse; |
|
1229 |
|
1230 anyNonEmptyFolders = iModel->AnyNonEmptyFoldersL( aFolderUids ); |
|
1231 switch ( anyNonEmptyFolders ) |
|
1232 { |
|
1233 case CBrowserFavouritesModel::EYes: |
|
1234 { |
|
1235 // At least one non-empty folder is selected. |
|
1236 ret = TBrowserDialogs::ConfirmQueryYesNoL( |
|
1237 _R(TEXT_DEL_FULL_FLDRS_QUERY) ); |
|
1238 break; |
|
1239 } |
|
1240 |
|
1241 case CBrowserFavouritesModel::ENo: |
|
1242 { |
|
1243 // No non-empty folders are selected. |
|
1244 TInt count = aUids.Count(); |
|
1245 switch ( count ) |
|
1246 { |
|
1247 case 0: |
|
1248 { |
|
1249 // Empty selection (???); |
|
1250 ret = EFalse; |
|
1251 break; |
|
1252 } |
|
1253 |
|
1254 case 1: |
|
1255 { |
|
1256 // One item is selected (item or empty folder). |
|
1257 // Get its name. |
|
1258 const CFavouritesItem* item = iContainer->Listbox()-> |
|
1259 ItemByUid( aUids.At( 0 ) ); |
|
1260 if ( item ) |
|
1261 { |
|
1262 ret = TBrowserDialogs::ConfirmQueryYesNoL( |
|
1263 _R(TEXT_QUERY_COMMON_CONF_DELETE), item->Name() ); |
|
1264 } |
|
1265 else |
|
1266 { |
|
1267 // Could not get item (maybe listbox has been updated). |
|
1268 ret = EFalse; |
|
1269 } |
|
1270 break; |
|
1271 } |
|
1272 |
|
1273 default: |
|
1274 { |
|
1275 // More items are selected (items or/and empty folders). |
|
1276 ret = TBrowserDialogs::ConfirmQueryYesNoL( |
|
1277 _R(TEXT_DEL_ITEMS_QUERY), count ); |
|
1278 break; |
|
1279 } |
|
1280 |
|
1281 } |
|
1282 break; |
|
1283 } |
|
1284 |
|
1285 case CBrowserFavouritesModel::EError: |
|
1286 default: |
|
1287 { |
|
1288 // Could not access database. |
|
1289 ret = EFalse; |
|
1290 break; |
|
1291 } |
|
1292 } |
|
1293 |
|
1294 return ret; |
|
1295 } |
|
1296 |
|
1297 // --------------------------------------------------------- |
|
1298 // CBrowserFavouritesView::DisplayResultOfDeleteL |
|
1299 // --------------------------------------------------------- |
|
1300 // |
|
1301 void CBrowserFavouritesView::DisplayResultOfDeleteL |
|
1302 ( const CArrayFix<TInt>& /*aUids*/, const CArrayFix<TInt>& aNotDeletedUids ) |
|
1303 { |
|
1304 switch ( aNotDeletedUids.Count() ) |
|
1305 { |
|
1306 case 0: |
|
1307 { |
|
1308 // All items deleted successfully. |
|
1309 // Display nothing. |
|
1310 break; |
|
1311 } |
|
1312 case 1: |
|
1313 { |
|
1314 // One item is not deleted. |
|
1315 const CFavouritesItem* item = iContainer->Listbox()-> |
|
1316 ItemByUid( aNotDeletedUids.At( 0 ) ); |
|
1317 if ( item ) |
|
1318 { |
|
1319 TBrowserDialogs::InfoNoteL |
|
1320 ( |
|
1321 R_BROWSER_INFO_NOTE, |
|
1322 _R(TEXT_CANT_DELETE_ITEM), |
|
1323 item->Name() |
|
1324 ); |
|
1325 } |
|
1326 // else |
|
1327 // this item is not found in the listbox (so it does not exist, |
|
1328 // most likely got deleted somehow) - keep quiet. |
|
1329 break; |
|
1330 } |
|
1331 default: |
|
1332 { |
|
1333 // More items are not deleted. |
|
1334 TBrowserDialogs::InfoNoteL |
|
1335 ( |
|
1336 R_BROWSER_INFO_NOTE, |
|
1337 _R(TEXT_CANT_DELETE_ITEMS), |
|
1338 aNotDeletedUids.Count() |
|
1339 ); |
|
1340 break; |
|
1341 } |
|
1342 } |
|
1343 } |
|
1344 |
|
1345 // --------------------------------------------------------- |
|
1346 // CBrowserFavouritesView::SelectTargetFolderL |
|
1347 // --------------------------------------------------------- |
|
1348 // |
|
1349 TInt CBrowserFavouritesView::SelectTargetFolderL( TInt aExcludeFolder ) |
|
1350 { |
|
1351 TInt targetFolder = KFavouritesNullUid; |
|
1352 |
|
1353 switch ( iModel->AnyFoldersL() ) |
|
1354 { |
|
1355 case CBrowserFavouritesModel::EYes: |
|
1356 { |
|
1357 // Select from existing folders. |
|
1358 CBrowserFavouritesFolderSelector* selector = |
|
1359 CBrowserFavouritesFolderSelector::NewL |
|
1360 ( *iModel, ApiProvider(), aExcludeFolder ); |
|
1361 targetFolder = selector->ExecuteLD(); |
|
1362 break; |
|
1363 } |
|
1364 case CBrowserFavouritesModel::ENo: |
|
1365 { |
|
1366 break; |
|
1367 } |
|
1368 case CBrowserFavouritesModel::EError: |
|
1369 default: |
|
1370 { |
|
1371 // Some error; quit. |
|
1372 break; |
|
1373 } |
|
1374 } |
|
1375 return targetFolder; |
|
1376 } |
|
1377 |
|
1378 // --------------------------------------------------------- |
|
1379 // CBrowserFavouritesView::HandleMoveResultL |
|
1380 // --------------------------------------------------------- |
|
1381 // |
|
1382 void CBrowserFavouritesView::HandleMoveResultL |
|
1383 ( |
|
1384 TInt aFolder, |
|
1385 const CArrayFix<TInt>& /*aUids*/, |
|
1386 const CArrayFix<TInt>& aUnmovableUids, |
|
1387 const CArrayFix<TInt>& aConflictingNameUids |
|
1388 ) |
|
1389 { |
|
1390 // See if some items has to be renamed to do the move. |
|
1391 if ( aConflictingNameUids.Count() ) |
|
1392 { |
|
1393 if ( aConflictingNameUids.Count() == 1 ) |
|
1394 { |
|
1395 // One item needs to be renamed if the user wants to move them. |
|
1396 // Let the user know and ask if replace. |
|
1397 const CFavouritesItem* item = iContainer->Listbox()-> |
|
1398 ItemByUid( aConflictingNameUids.At( 0 ) ); |
|
1399 if ( item ) |
|
1400 { |
|
1401 TBrowserDialogs::InfoNoteL |
|
1402 ( |
|
1403 R_BROWSER_INFO_NOTE, |
|
1404 _R(TEXT_FLDR_NAME_ALREADY_USED), |
|
1405 item->Name() |
|
1406 ); |
|
1407 RenameAndMoveItemsL( aConflictingNameUids, aFolder ); |
|
1408 } |
|
1409 } |
|
1410 else |
|
1411 { |
|
1412 // Some items needs to be renamed if the user wants to move them. |
|
1413 // Let the user know and ask for each if replace. |
|
1414 TBrowserDialogs::InfoNoteL( R_BROWSER_INFO_NOTE, |
|
1415 _R(TEXT_FLDR_NAMES_IN_USE_RENAME) ); |
|
1416 RenameAndMoveItemsL( aConflictingNameUids, aFolder ); |
|
1417 } |
|
1418 } |
|
1419 |
|
1420 // Check unmovable items. |
|
1421 if ( aUnmovableUids.Count() ) |
|
1422 { |
|
1423 if ( aUnmovableUids.Count() == 1 ) |
|
1424 { |
|
1425 // One item is not moved. |
|
1426 const CFavouritesItem* item = iContainer->Listbox()-> |
|
1427 ItemByUid( aUnmovableUids.At( 0 ) ); |
|
1428 if ( item ) |
|
1429 { |
|
1430 TBrowserDialogs::InfoNoteL |
|
1431 ( |
|
1432 R_BROWSER_INFO_NOTE, |
|
1433 _R(TEXT_ITEM_CANNOT_BE_MOVED), |
|
1434 item->Name() |
|
1435 ); |
|
1436 } |
|
1437 } |
|
1438 else |
|
1439 { |
|
1440 // More items could not be moved. |
|
1441 TBrowserDialogs::InfoNoteL |
|
1442 ( |
|
1443 R_BROWSER_INFO_NOTE, |
|
1444 _R(TEXT_SOME_ITEMS_CANT_MOVE), |
|
1445 aUnmovableUids.Count() |
|
1446 ); |
|
1447 } |
|
1448 } |
|
1449 // else |
|
1450 // All is well: all moved succesfully. Display nothing. |
|
1451 } |
|
1452 |
|
1453 // --------------------------------------------------------- |
|
1454 // CBrowserFavouritesView::RenameAndMoveItemsL |
|
1455 // --------------------------------------------------------- |
|
1456 // |
|
1457 void CBrowserFavouritesView::RenameAndMoveItemsL |
|
1458 ( const CArrayFix<TInt>& aUids, TInt aFolder ) |
|
1459 { |
|
1460 TInt err = KErrNone; |
|
1461 TInt i; |
|
1462 TInt uid; |
|
1463 TInt count = aUids.Count(); |
|
1464 TInt itemErr; |
|
1465 |
|
1466 CFavouritesItem* item = CFavouritesItem::NewLC(); |
|
1467 |
|
1468 for ( i = 0; i < count && !err; i++ ) |
|
1469 { |
|
1470 // Get each item in turn from db (ignore if any of them is not found). |
|
1471 // Let the user rename each. Quit on the first Cancel from the user. |
|
1472 // All database manipulating methods, which are called here, retry on |
|
1473 // failure, so if we ever get an error value, that means that the user |
|
1474 // cancelled something. |
|
1475 uid = aUids.At( i ); |
|
1476 err = iModel->BeginL( /*aWrite=*/ETrue, /*aDbErrorNote=*/ETrue ); |
|
1477 if ( !err ) |
|
1478 { |
|
1479 // Check if we have the item. |
|
1480 itemErr = iModel->Database().Get( uid, *item ); |
|
1481 iModel->CommitL(); |
|
1482 if ( !itemErr ) |
|
1483 { |
|
1484 // We have this item. Ask the user to rename it. |
|
1485 if ( iModel->RenameQueryL( *item, EFalse) ) |
|
1486 { |
|
1487 // The user renamed the item: try to update and go on. |
|
1488 item->SetParentFolder( aFolder ); |
|
1489 err = iModel->UpdateL( *item, uid, /*aDbErrorNote=*/ETrue, |
|
1490 CBrowserFavouritesModel::EAskIfRename ); |
|
1491 } |
|
1492 else |
|
1493 { |
|
1494 // Cancelled. Quit. |
|
1495 err = KErrCancel; |
|
1496 } |
|
1497 } |
|
1498 } |
|
1499 } |
|
1500 CleanupStack::PopAndDestroy(); // item |
|
1501 } |
|
1502 |
|
1503 // --------------------------------------------------------- |
|
1504 // CBrowserFavouritesView::UpdateNaviPaneL |
|
1505 // --------------------------------------------------------- |
|
1506 // |
|
1507 void CBrowserFavouritesView::UpdateNaviPaneL() |
|
1508 { |
|
1509 if ( iCurrentFolder == KFavouritesRootUid ) |
|
1510 { |
|
1511 // In root folder show the tabs. |
|
1512 iContainer->ShowRootNaviPane(); |
|
1513 } |
|
1514 else |
|
1515 { |
|
1516 // In other folder, show "1/4" style text. |
|
1517 TInt folderIndex; |
|
1518 TInt folderCount; |
|
1519 TInt err; |
|
1520 err = iModel->FolderInfoL( iCurrentFolder, folderCount, folderIndex ); |
|
1521 if ( !err ) |
|
1522 { |
|
1523 iContainer->ShowFolderNaviPaneL( folderIndex, folderCount ); |
|
1524 } |
|
1525 } |
|
1526 } |
|
1527 |
|
1528 // --------------------------------------------------------- |
|
1529 // CBrowserFavouritesView::OfferKeyEventL |
|
1530 // --------------------------------------------------------- |
|
1531 // |
|
1532 TKeyResponse CBrowserFavouritesView::OfferKeyEventL |
|
1533 ( const TKeyEvent& aKeyEvent, TEventCode /*aType*/ ) |
|
1534 { |
|
1535 // This method is called back from the container, to process the keypresses |
|
1536 // that cannot be handled by the container. Those are (currently) the |
|
1537 // left/right arrow keypresses, since the container does not know anything |
|
1538 // about what folder is open, which knowledge is required to process |
|
1539 // arrow presses. So we do that here. |
|
1540 // Any other key processing is still in the container. |
|
1541 TKeyResponse result = EKeyWasNotConsumed; |
|
1542 switch ( aKeyEvent.iCode ) |
|
1543 { |
|
1544 |
|
1545 case EKeyLeftArrow: // West |
|
1546 { |
|
1547 if ( iCurrentFolder != KFavouritesRootUid ) |
|
1548 { |
|
1549 // We are in some folder. Move between subfolders in the |
|
1550 // leftward direction. |
|
1551 if ( !ApiProvider().IsEmbeddedModeOn() ) |
|
1552 { |
|
1553 OpenNextFolderL( /*aForward=*/EFalse ); |
|
1554 } |
|
1555 //return EKeyWasConsumed anyway, since in embedded mode user can access only the launch folder |
|
1556 result = EKeyWasConsumed; |
|
1557 } |
|
1558 break; |
|
1559 } |
|
1560 |
|
1561 case EKeyRightArrow: // East |
|
1562 { |
|
1563 if ( iCurrentFolder != KFavouritesRootUid ) |
|
1564 { |
|
1565 // We are in some folder. Move between subfolders in the |
|
1566 // rightward direction. |
|
1567 if ( !ApiProvider().IsEmbeddedModeOn() ) |
|
1568 { |
|
1569 OpenNextFolderL( /*aForward=*/ETrue ); |
|
1570 } |
|
1571 //return EKeyWasConsumed anyway, since in embedded mode user can access only the launch folder |
|
1572 result = EKeyWasConsumed; |
|
1573 } |
|
1574 break; |
|
1575 } |
|
1576 |
|
1577 case EKeyRightUpArrow: // Northeast |
|
1578 case EStdKeyDevice11: // : Extra KeyEvent supports diagonal event simulator wedge |
|
1579 case EKeyRightDownArrow: // Southeast |
|
1580 case EStdKeyDevice12: // : Extra KeyEvent supports diagonal event simulator wedge |
|
1581 case EKeyLeftDownArrow: // Southwest |
|
1582 case EStdKeyDevice13: // : Extra KeyEvent supports diagonal event simulator wedge |
|
1583 case EKeyLeftUpArrow: // Northwest |
|
1584 case EStdKeyDevice10: // : Extra KeyEvent supports diagonal event simulator wedge |
|
1585 { // Here, "eat" all of the diagonals so they have no effect |
|
1586 result = EKeyWasConsumed; |
|
1587 break; |
|
1588 } |
|
1589 |
|
1590 |
|
1591 case EKeyBackspace: |
|
1592 case EKeyDelete: |
|
1593 { |
|
1594 TBrowserFavouritesSelectionState state = |
|
1595 iContainer->Listbox()->SelectionStateL(); |
|
1596 if ( state.AnyDeletable() ) |
|
1597 { |
|
1598 // We don't editing (not in Goto Pane), |
|
1599 // and have something to delete. In this case, Clear key |
|
1600 // deletes the selection (or highlighted items). |
|
1601 if ( ((iContainer->Listbox()->CurrentItem()->ContextId() == NULL ) && |
|
1602 (iContainer->Listbox()->CurrentItem()->Uid() != KFavouritesAdaptiveItemsFolderUid) || |
|
1603 state.AnyMarked() ) |
|
1604 ) |
|
1605 { |
|
1606 DeleteMarkedItemsL(); |
|
1607 } |
|
1608 result = EKeyWasConsumed; |
|
1609 } |
|
1610 break; |
|
1611 } |
|
1612 |
|
1613 case EKeyOK: |
|
1614 // OK key is handled through MSK handling |
|
1615 result = EKeyWasConsumed; |
|
1616 break; |
|
1617 |
|
1618 case EKeyEnter: |
|
1619 { |
|
1620 if ( !(aKeyEvent.iModifiers & EModifierShift) ) |
|
1621 { |
|
1622 TBrowserFavouritesSelectionState state = |
|
1623 iContainer->Listbox()->SelectionStateL(); |
|
1624 if ( state.IsEmpty() || state.AnyMarked() ) |
|
1625 { |
|
1626 // Selection key (alone) pressed when there are marked |
|
1627 // items or the list is empty. Bring up context sensitive |
|
1628 // (OK-Options) menu. |
|
1629 MenuBar( )-> |
|
1630 SetMenuTitleResourceId( OkOptionsMenuResourceId() ); |
|
1631 iShowOkOptions = ETrue; |
|
1632 // Call to menu activation is trapped - to make sure that |
|
1633 // iShowOkOptions and bad menu doesn't stick in. |
|
1634 TRAP_IGNORE( ProcessCommandL( EAknSoftkeyOptions ) ); |
|
1635 iShowOkOptions = EFalse; |
|
1636 MenuBar( )-> |
|
1637 SetMenuTitleResourceId( OptionsMenuResourceId() ); |
|
1638 |
|
1639 // Update CBA to include context menu MSK icon |
|
1640 UpdateCbaL(); |
|
1641 |
|
1642 result = EKeyWasConsumed; |
|
1643 } |
|
1644 } |
|
1645 break; |
|
1646 } |
|
1647 |
|
1648 default: |
|
1649 { |
|
1650 break; |
|
1651 } |
|
1652 } |
|
1653 |
|
1654 return result; |
|
1655 } |
|
1656 |
|
1657 // --------------------------------------------------------- |
|
1658 // CBrowserFavouritesView::HandleFavouritesModelChangeL |
|
1659 // --------------------------------------------------------- |
|
1660 // |
|
1661 void CBrowserFavouritesView::HandleFavouritesModelChangeL() |
|
1662 { |
|
1663 // Change in favourites database. |
|
1664 if ( iRefresh ) |
|
1665 { |
|
1666 RefreshL(); |
|
1667 } |
|
1668 iRefresh = ETrue; |
|
1669 } |
|
1670 |
|
1671 // --------------------------------------------------------- |
|
1672 // CBrowserFavouritesView::HandleCommsModelChangeL |
|
1673 // --------------------------------------------------------- |
|
1674 // |
|
1675 void CBrowserFavouritesView::HandleCommsModelChangeL() |
|
1676 { |
|
1677 // Change in AP-s (CommsDb). |
|
1678 RefreshL( /*aDbErrorNote=*/EFalse ); |
|
1679 } |
|
1680 |
|
1681 void CBrowserFavouritesView::OpenFixedFolderL(TInt aUid) |
|
1682 { |
|
1683 OpenFolderL(aUid); |
|
1684 } |
|
1685 |
|
1686 // --------------------------------------------------------- |
|
1687 // CBrowserFavouritesView::SetPreferedCurrentItemL |
|
1688 // --------------------------------------------------------- |
|
1689 // |
|
1690 void CBrowserFavouritesView::SetPreferedCurrentItemL() |
|
1691 { |
|
1692 // check the current item is exist |
|
1693 if ( iContainer->Listbox()->CurrentItem() ) |
|
1694 { |
|
1695 iContainer->Listbox()->GetDefaultData().iPreferedId = |
|
1696 iContainer->Listbox()->CurrentItem()->Uid(); |
|
1697 iModel->Database().SetPreferredUid( |
|
1698 iCurrentFolder,iContainer->Listbox()->CurrentItem()->Uid() ); |
|
1699 iRefresh = ETrue; |
|
1700 } |
|
1701 } |
|
1702 |
|
1703 // --------------------------------------------------------- |
|
1704 // CBrowserFavouritesView::SetUnPreferedCurrentItemL |
|
1705 // --------------------------------------------------------- |
|
1706 // |
|
1707 void CBrowserFavouritesView::SetUnPreferedCurrentItemL() |
|
1708 { |
|
1709 // check the current item is exist |
|
1710 if ( iContainer->Listbox()->CurrentItem() ) |
|
1711 { |
|
1712 iContainer->Listbox()->GetDefaultData().iPreferedId = NULL; |
|
1713 iModel->Database().SetPreferredUid( iCurrentFolder,NULL ); |
|
1714 iRefresh = ETrue; |
|
1715 } |
|
1716 } |
|
1717 |
|
1718 // --------------------------------------------------------- |
|
1719 // CBrowserFavouritesView::ConfigContextMenu |
|
1720 // --------------------------------------------------------- |
|
1721 // |
|
1722 void CBrowserFavouritesView::ConfigContextMenu() |
|
1723 { |
|
1724 // Config Context Sensitive Menu Resource and Type when items are marked |
|
1725 |
|
1726 MenuBar()->SetContextMenuTitleResourceId( OkOptionsMenuResourceId()); |
|
1727 MenuBar()->SetMenuType(CEikMenuBar::EMenuContext); |
|
1728 MenuBar()->SetMenuTitleResourceId( OptionsMenuResourceId()); |
|
1729 MenuBar()->SetMenuType(CEikMenuBar::EMenuOptions); // adds task swapper menu item first |
|
1730 } |
|
1731 |
|
1732 // End of File |