|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 // INCLUDE FILES |
|
18 |
|
19 #include <badesca.h> |
|
20 #include "widgetscannerutils.h" |
|
21 #include "cawidgetstoragehandler.h" |
|
22 #include "cadef.h" |
|
23 #include "cainnerentry.h" |
|
24 #include "cainnerquery.h" |
|
25 #include "castorageproxy.h" |
|
26 #include "caarraycleanup.inl" |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CCaWidgetStorageHandler::CCaWidgetStorageHandler |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CCaWidgetStorageHandler::CCaWidgetStorageHandler( |
|
37 CCaStorageProxy* aStorage, RFs& aFs ) |
|
38 { |
|
39 iStorage = aStorage; |
|
40 iFs = aFs; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CCaWidgetStorageHandler::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CCaWidgetStorageHandler::ConstructL() |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCaWidgetStorageHandler::NewL |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewL( |
|
58 CCaStorageProxy* aStorage, RFs& aFs ) |
|
59 { |
|
60 CCaWidgetStorageHandler* self = NewLC( aStorage, aFs ); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CCaWidgetStorageHandler::NewLC |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewLC( |
|
71 CCaStorageProxy* aStorage, RFs& aFs ) |
|
72 { |
|
73 CCaWidgetStorageHandler* self = new ( ELeave ) CCaWidgetStorageHandler( |
|
74 aStorage, aFs ); |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // Destructor |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CCaWidgetStorageHandler::~CCaWidgetStorageHandler() |
|
85 { |
|
86 iWidgets.ResetAndDestroy(); |
|
87 iUpdatedIndexes.Close(); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 void CCaWidgetStorageHandler::SynchronizeL( const RWidgetArray& aWidgets ) |
|
95 { |
|
96 FetchWidgetsL(); |
|
97 AddWidgetsL( aWidgets ); |
|
98 RemoveWidgetsL(); |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // |
|
103 // ---------------------------------------------------------------------------- |
|
104 // |
|
105 void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget ) |
|
106 { |
|
107 CCaInnerEntry* entry = aWidget->GetEntryLC(); |
|
108 iStorage->AddL( entry ); |
|
109 if( ( entry->GetFlags() & ERemovable ) != 0 ) |
|
110 { |
|
111 AddWidgetToDownloadCollectionL( entry ); |
|
112 } |
|
113 CleanupStack::PopAndDestroy( entry ); |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget, |
|
121 TUint aEntryId ) |
|
122 { |
|
123 CCaInnerEntry* entry = aWidget->GetEntryLC(); |
|
124 entry->SetId( aEntryId ); |
|
125 if( !aWidget->IsMissing() ) |
|
126 { |
|
127 entry->SetFlags( entry->GetFlags() & ~EUsed ); |
|
128 } |
|
129 entry->SetFlags( entry->GetFlags() & ~EMissing ); |
|
130 iStorage->AddL( entry ); |
|
131 if( !aWidget->IsMissing() ) |
|
132 { |
|
133 AddWidgetToDownloadCollectionL( entry ); |
|
134 } |
|
135 CleanupStack::PopAndDestroy( entry ); |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets ) |
|
143 { |
|
144 iUpdatedIndexes.Reset(); |
|
145 for( TInt i = 0; i < aWidgets.Count(); i++ ) |
|
146 { |
|
147 TInt index = iWidgets.Find( |
|
148 aWidgets[i], CCaWidgetDescription::Compare ); |
|
149 if( index != KErrNotFound ) |
|
150 { |
|
151 if( !iWidgets[index]->Compare( *aWidgets[i] ) || |
|
152 iWidgets[index]->IsMissing() ) |
|
153 { |
|
154 aWidgets[i]->SetMissing( iWidgets[index]->IsMissing() ); |
|
155 UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() ); |
|
156 } |
|
157 iUpdatedIndexes.AppendL( index ); |
|
158 } |
|
159 else |
|
160 { |
|
161 AddL( aWidgets[i] ); |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 void CCaWidgetStorageHandler::RemoveWidgetsL() |
|
171 { |
|
172 RArray<TInt> widgetsToRemove; |
|
173 CleanupClosePushL( widgetsToRemove ); |
|
174 for( TInt i = 0; i < iWidgets.Count(); i++ ) |
|
175 { |
|
176 if( iUpdatedIndexes.Find( i ) == KErrNotFound ) |
|
177 { |
|
178 if( iWidgets[i]->GetMmcId() && |
|
179 ( iWidgets[i]->GetMmcId() != |
|
180 WidgetScannerUtils::CurrentMmcId( iFs ) ) ) |
|
181 { |
|
182 SetMissingFlagL( iWidgets[i] ); |
|
183 } |
|
184 else |
|
185 { |
|
186 widgetsToRemove.AppendL( iWidgets[i]->GetEntryId() ); |
|
187 } |
|
188 } |
|
189 } |
|
190 if( widgetsToRemove.Count() > 0 ) |
|
191 { |
|
192 iStorage->RemoveL( widgetsToRemove ); |
|
193 } |
|
194 CleanupStack::PopAndDestroy( &widgetsToRemove ); |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 void CCaWidgetStorageHandler::AddWidgetToDownloadCollectionL( |
|
202 const CCaInnerEntry* aEntry ) |
|
203 { |
|
204 CCaInnerQuery* queryDownload = CCaInnerQuery::NewLC(); |
|
205 CDesC16ArrayFlat* downloadType = new ( ELeave ) CDesC16ArrayFlat( |
|
206 KGranularityOne ); |
|
207 CleanupStack::PushL( downloadType ); |
|
208 downloadType->AppendL( KCaTypeCollectionDownload ); |
|
209 queryDownload->SetEntryTypeNames( downloadType );//query takes ownership |
|
210 CleanupStack::Pop( downloadType ); |
|
211 queryDownload->SetRole( EGroupEntryRole ); |
|
212 |
|
213 RArray<TInt> idsGroup; |
|
214 CleanupClosePushL( idsGroup ); |
|
215 iStorage->GetEntriesIdsL( queryDownload, idsGroup ); |
|
216 |
|
217 TCaOperationParams operParams; |
|
218 operParams.iOperationType = TCaOperationParams::EPrepend; |
|
219 operParams.iGroupId = idsGroup[0]; |
|
220 operParams.iBeforeEntryId = 0; |
|
221 CleanupStack::PopAndDestroy( &idsGroup ); |
|
222 |
|
223 RArray<TInt> idsEntry; |
|
224 CleanupClosePushL( idsEntry ); |
|
225 idsEntry.Append( aEntry->GetId() ); |
|
226 iStorage->OrganizeL( idsEntry, operParams ); |
|
227 |
|
228 CleanupStack::PopAndDestroy( &idsEntry ); |
|
229 CleanupStack::PopAndDestroy( queryDownload ); |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 // ---------------------------------------------------------------------------- |
|
235 // |
|
236 void CCaWidgetStorageHandler::FetchWidgetsL() |
|
237 { |
|
238 CCaInnerQuery* query = CCaInnerQuery::NewLC(); |
|
239 CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat( |
|
240 KGranularityOne ); |
|
241 CleanupStack::PushL( widgetType ); |
|
242 widgetType->AppendL( KCaTypeWidget ); |
|
243 query->SetEntryTypeNames( widgetType );//transfers ownership to query |
|
244 CleanupStack::Pop( widgetType ); |
|
245 |
|
246 RPointerArray<CCaInnerEntry> entries; |
|
247 CleanupResetAndDestroyPushL( entries ); |
|
248 iStorage->GetEntriesL( query, entries ); |
|
249 iWidgets.ResetAndDestroy(); |
|
250 for( TInt i = 0; i < entries.Count(); i++ ) |
|
251 { |
|
252 CCaWidgetDescription* widget = CCaWidgetDescription::NewLC( |
|
253 entries[i] ); |
|
254 iWidgets.AppendL( widget ); //iWidgets takes ownership |
|
255 CleanupStack::Pop( widget ); |
|
256 } |
|
257 CleanupStack::PopAndDestroy( &entries ); |
|
258 CleanupStack::PopAndDestroy( query ); |
|
259 } |
|
260 |
|
261 // ---------------------------------------------------------------------------- |
|
262 // |
|
263 // ---------------------------------------------------------------------------- |
|
264 // |
|
265 void CCaWidgetStorageHandler::SetMissingFlagL( |
|
266 const CCaWidgetDescription* aWidget ) |
|
267 { |
|
268 CCaInnerEntry* entry = aWidget->GetEntryLC(); |
|
269 entry->SetFlags( entry->GetFlags() | EMissing ); |
|
270 iStorage->AddL( entry ); |
|
271 CleanupStack::PopAndDestroy( entry ); |
|
272 } |
|
273 |
|
274 // End of File |