|
1 /* |
|
2 * Copyright (c) 2002 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 CWmlBrowserFavouritesIncrementalDelete. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <AknWaitDialog.h> |
|
24 #include <favouritesdb.h> |
|
25 #include <BrowserNG.rsg> |
|
26 #include "BrowserFavouritesIncrementalDelete.h" |
|
27 #include "BrowserFavouritesModel.h" |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 /// Granularity of the folder-contents array. |
|
32 LOCAL_D const TInt KGranularity = 4; |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CBrowserFavouritesIncrementalDelete::NewL |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 CBrowserFavouritesIncrementalDelete* |
|
41 CBrowserFavouritesIncrementalDelete::NewL |
|
42 ( |
|
43 CBrowserFavouritesModel& aModel, |
|
44 CArrayFix<TInt>& aUids, |
|
45 CArrayFix<TInt>& aNotDeletedUids, |
|
46 TInt aPriority /*=CActive::EPriorityStandard*/ |
|
47 ) |
|
48 { |
|
49 CBrowserFavouritesIncrementalDelete* incDel = |
|
50 new (ELeave) CBrowserFavouritesIncrementalDelete |
|
51 ( aModel, aUids, aNotDeletedUids, aPriority ); |
|
52 CleanupStack::PushL( incDel ); |
|
53 incDel->ConstructL(); |
|
54 CleanupStack::Pop(); // incDel |
|
55 return incDel; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // CBrowserFavouritesIncrementalDelete::~CBrowserFavouritesIncrementalDelete |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 CBrowserFavouritesIncrementalDelete::~CBrowserFavouritesIncrementalDelete() |
|
63 { |
|
64 delete iFolderContents; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CBrowserFavouritesIncrementalDelete::CBrowserFavouritesIncrementalDelete |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 CBrowserFavouritesIncrementalDelete::CBrowserFavouritesIncrementalDelete |
|
72 ( |
|
73 CBrowserFavouritesModel& aModel, |
|
74 CArrayFix<TInt>& aUids, |
|
75 CArrayFix<TInt>& aNotDeletedUids, |
|
76 TInt aPriority |
|
77 ) |
|
78 : CBrowserFavouritesIncrementalOp( aModel, aPriority ), iUids( &aUids ), |
|
79 iNotDeletedUids( &aNotDeletedUids ), iFolderPending( EFalse ), iIndex( 0 ) |
|
80 { |
|
81 } |
|
82 |
|
83 // CBrowserFavouritesIncrementalDelete::ConstructL |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 void CBrowserFavouritesIncrementalDelete::ConstructL() |
|
87 { |
|
88 CBrowserFavouritesIncrementalOp::ConstructL(); |
|
89 iFolderContents = new (ELeave) CArrayFixFlat<TInt>( KGranularity ); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // CBrowserFavouritesIncrementalDelete::StepL |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 TInt CBrowserFavouritesIncrementalDelete::StepL() |
|
97 { |
|
98 if ( iFolderContents->Count() ) |
|
99 { |
|
100 // Deleting one item from folder. |
|
101 (void)iModel->Database().Delete( iFolderContents->At( 0 ) ); |
|
102 iFolderContents->Delete( 0 ); |
|
103 } |
|
104 else if ( iIndex < iUids->Count() ) |
|
105 { |
|
106 // Still have item in the main list to delete. |
|
107 TInt uid = iUids->At( iIndex ); |
|
108 // Check if it is a non-empty folder: get contents. |
|
109 // |
|
110 // The variable iFolderPending is a performance optimization: avoid |
|
111 // querying contents of a folder twice. (If iFolderPending == ETrue, |
|
112 // and we reach this point, that means that the last item in a folder |
|
113 // was deleted in the last StepL. The contents of this folder were |
|
114 // already queried). |
|
115 if ( !iFolderPending ) |
|
116 { |
|
117 // The contents of this folder were not queried yet: do it now. |
|
118 iModel->Database().GetUids( *iFolderContents, uid ); |
|
119 } |
|
120 if ( iFolderContents->Count() ) |
|
121 { |
|
122 // Folder is not empty, do nothing now. iIndex is not incremented |
|
123 // (deletion of this folder becomes pending) and next StepL will |
|
124 // begin deleting the contents. |
|
125 iFolderPending = ETrue; |
|
126 } |
|
127 else |
|
128 { |
|
129 // Deleting an empty (pending) folder or an ordinary item. |
|
130 iFolderPending = EFalse; |
|
131 if ( iModel->Database().Delete( uid ) != KErrNone ) |
|
132 { |
|
133 // Error deleting. |
|
134 iNotDeletedUids->AppendL( uid ); |
|
135 } |
|
136 iIndex++; |
|
137 } |
|
138 } |
|
139 return iUids->Count() - iIndex; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CBrowserFavouritesIncrementalDelete::CreateWaitNoteLC |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 void CBrowserFavouritesIncrementalDelete::CreateWaitNoteLC() |
|
147 { |
|
148 iWaitNote = new (ELeave) CAknWaitDialog |
|
149 ( REINTERPRET_CAST( CEikDialog**, &iWaitNote ) ); |
|
150 iWaitNote->PrepareLC( R_WMLBROWSER_FAVOURITES_NOTE_DELETING ); |
|
151 } |
|
152 |
|
153 // End of File |