85
|
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 |
*
|
93
|
14 |
* Description:
|
85
|
15 |
*
|
|
16 |
*/
|
|
17 |
// INCLUDE FILES
|
|
18 |
|
|
19 |
#include <badesca.h>
|
94
|
20 |
#include <usif/scr/screntries.h>
|
85
|
21 |
#include "widgetscannerutils.h"
|
|
22 |
#include "cawidgetstoragehandler.h"
|
|
23 |
#include "cadef.h"
|
|
24 |
#include "cainnerentry.h"
|
|
25 |
#include "cainnerquery.h"
|
|
26 |
#include "castorageproxy.h"
|
|
27 |
#include "caarraycleanup.inl"
|
|
28 |
|
94
|
29 |
using namespace Usif;
|
|
30 |
|
85
|
31 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
32 |
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
// CCaWidgetStorageHandler::CCaWidgetStorageHandler
|
|
35 |
// C++ default constructor can NOT contain any code, that
|
|
36 |
// might leave.
|
|
37 |
// -----------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
CCaWidgetStorageHandler::CCaWidgetStorageHandler(
|
|
40 |
CCaStorageProxy* aStorage, RFs& aFs )
|
|
41 |
{
|
|
42 |
iStorage = aStorage;
|
|
43 |
iFs = aFs;
|
|
44 |
}
|
|
45 |
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
// CCaWidgetStorageHandler::ConstructL
|
|
48 |
// Symbian 2nd phase constructor can leave.
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
void CCaWidgetStorageHandler::ConstructL()
|
|
52 |
{
|
94
|
53 |
User::LeaveIfError( iSoftwareRegistry.Connect() );
|
85
|
54 |
}
|
|
55 |
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
// CCaWidgetStorageHandler::NewL
|
|
58 |
// Two-phased constructor.
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewL(
|
|
62 |
CCaStorageProxy* aStorage, RFs& aFs )
|
|
63 |
{
|
|
64 |
CCaWidgetStorageHandler* self = NewLC( aStorage, aFs );
|
|
65 |
CleanupStack::Pop( self );
|
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
// CCaWidgetStorageHandler::NewLC
|
|
71 |
// Two-phased constructor.
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewLC(
|
|
75 |
CCaStorageProxy* aStorage, RFs& aFs )
|
|
76 |
{
|
|
77 |
CCaWidgetStorageHandler* self = new ( ELeave ) CCaWidgetStorageHandler(
|
|
78 |
aStorage, aFs );
|
|
79 |
CleanupStack::PushL( self );
|
|
80 |
self->ConstructL();
|
|
81 |
return self;
|
|
82 |
}
|
|
83 |
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// Destructor
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
|
|
89 |
{
|
94
|
90 |
iSoftwareRegistry.Close();
|
85
|
91 |
iWidgets.ResetAndDestroy();
|
|
92 |
iUpdatedIndexes.Close();
|
|
93 |
}
|
|
94 |
|
|
95 |
// ----------------------------------------------------------------------------
|
93
|
96 |
//
|
85
|
97 |
// ----------------------------------------------------------------------------
|
93
|
98 |
//
|
85
|
99 |
void CCaWidgetStorageHandler::SynchronizeL( const RWidgetArray& aWidgets )
|
|
100 |
{
|
|
101 |
FetchWidgetsL();
|
|
102 |
AddWidgetsL( aWidgets );
|
|
103 |
RemoveWidgetsL();
|
|
104 |
}
|
|
105 |
|
|
106 |
// ----------------------------------------------------------------------------
|
93
|
107 |
//
|
85
|
108 |
// ----------------------------------------------------------------------------
|
93
|
109 |
//
|
85
|
110 |
void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
|
|
111 |
{
|
|
112 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
94
|
113 |
UpdateComponentIdL( aWidget->GetManifestFilePathName(), *entry );
|
85
|
114 |
iStorage->AddL( entry );
|
93
|
115 |
if( entry->GetFlags() & ERemovable )
|
85
|
116 |
{
|
|
117 |
AddWidgetToDownloadCollectionL( entry );
|
|
118 |
}
|
|
119 |
CleanupStack::PopAndDestroy( entry );
|
|
120 |
}
|
|
121 |
|
|
122 |
// ----------------------------------------------------------------------------
|
93
|
123 |
//
|
85
|
124 |
// ----------------------------------------------------------------------------
|
93
|
125 |
//
|
85
|
126 |
void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget,
|
|
127 |
TUint aEntryId )
|
|
128 |
{
|
|
129 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
94
|
130 |
UpdateComponentIdL( aWidget->GetManifestFilePathName(), *entry );
|
85
|
131 |
entry->SetId( aEntryId );
|
93
|
132 |
if( !aWidget->IsMissing() && aWidget->IsUsed() )
|
85
|
133 |
{
|
|
134 |
entry->SetFlags( entry->GetFlags() & ~EUsed );
|
|
135 |
}
|
93
|
136 |
TItemAppearance itemAppearanceChange = EItemAppearanceNotChanged;
|
|
137 |
if( ( entry->GetFlags() & EMissing ) ||
|
|
138 |
!( entry->GetFlags() & EVisible ) )
|
87
|
139 |
{
|
93
|
140 |
itemAppearanceChange = EItemAppeared;
|
87
|
141 |
}
|
93
|
142 |
entry->SetFlags( entry->GetFlags() & ~EMissing | EVisible );
|
|
143 |
iStorage->AddL( entry, EFalse, itemAppearanceChange );
|
85
|
144 |
if( !aWidget->IsMissing() )
|
|
145 |
{
|
|
146 |
AddWidgetToDownloadCollectionL( entry );
|
|
147 |
}
|
|
148 |
CleanupStack::PopAndDestroy( entry );
|
|
149 |
}
|
|
150 |
|
|
151 |
// ----------------------------------------------------------------------------
|
93
|
152 |
//
|
85
|
153 |
// ----------------------------------------------------------------------------
|
93
|
154 |
//
|
85
|
155 |
void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
|
|
156 |
{
|
|
157 |
iUpdatedIndexes.Reset();
|
|
158 |
for( TInt i = 0; i < aWidgets.Count(); i++ )
|
|
159 |
{
|
93
|
160 |
TInt index = iWidgets.Find(
|
85
|
161 |
aWidgets[i], CCaWidgetDescription::Compare );
|
|
162 |
if( index != KErrNotFound )
|
|
163 |
{
|
93
|
164 |
if( !iWidgets[index]->Compare( *aWidgets[i] ) ||
|
85
|
165 |
iWidgets[index]->IsMissing() )
|
|
166 |
{
|
|
167 |
aWidgets[i]->SetMissing( iWidgets[index]->IsMissing() );
|
87
|
168 |
aWidgets[i]->SetUsed( iWidgets[index]->IsUsed() );
|
93
|
169 |
aWidgets[i]->SetVisible( iWidgets[index]->IsVisible() );
|
85
|
170 |
UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() );
|
|
171 |
}
|
|
172 |
iUpdatedIndexes.AppendL( index );
|
|
173 |
}
|
|
174 |
else
|
|
175 |
{
|
|
176 |
AddL( aWidgets[i] );
|
|
177 |
}
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
// ----------------------------------------------------------------------------
|
93
|
182 |
//
|
85
|
183 |
// ----------------------------------------------------------------------------
|
93
|
184 |
//
|
85
|
185 |
void CCaWidgetStorageHandler::RemoveWidgetsL()
|
|
186 |
{
|
|
187 |
for( TInt i = 0; i < iWidgets.Count(); i++ )
|
|
188 |
{
|
|
189 |
if( iUpdatedIndexes.Find( i ) == KErrNotFound )
|
|
190 |
{
|
93
|
191 |
if( iWidgets[i]->GetMmcId() != KNullDesC )
|
85
|
192 |
{
|
93
|
193 |
RBuf currentMmcId;
|
|
194 |
currentMmcId.CreateL( KMassStorageIdLength );
|
|
195 |
currentMmcId.CleanupClosePushL();
|
|
196 |
WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
|
|
197 |
if( iWidgets[i]->GetMmcId() == currentMmcId ||
|
|
198 |
( iWidgets[i]->GetMmcId() == KCaMassStorage() &&
|
|
199 |
MassStorageNotInUse() ) )
|
|
200 |
{
|
|
201 |
//item was uninstalled so we remove its mmc id
|
|
202 |
iWidgets[i]->RemoveMmcId();
|
|
203 |
ClearVisibleFlagL( iWidgets[i] );
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
SetMissingFlagL( iWidgets[i] );
|
|
208 |
}
|
|
209 |
CleanupStack::PopAndDestroy(¤tMmcId);
|
85
|
210 |
}
|
|
211 |
else
|
|
212 |
{
|
93
|
213 |
//item was uninstalled so we remove its mmc id
|
|
214 |
ClearVisibleFlagL( iWidgets[i] );
|
85
|
215 |
}
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
// ----------------------------------------------------------------------------
|
93
|
221 |
//
|
85
|
222 |
// ----------------------------------------------------------------------------
|
93
|
223 |
//
|
85
|
224 |
void CCaWidgetStorageHandler::AddWidgetToDownloadCollectionL(
|
|
225 |
const CCaInnerEntry* aEntry )
|
|
226 |
{
|
|
227 |
CCaInnerQuery* queryDownload = CCaInnerQuery::NewLC();
|
|
228 |
CDesC16ArrayFlat* downloadType = new ( ELeave ) CDesC16ArrayFlat(
|
|
229 |
KGranularityOne );
|
|
230 |
CleanupStack::PushL( downloadType );
|
|
231 |
downloadType->AppendL( KCaTypeCollectionDownload );
|
|
232 |
queryDownload->SetEntryTypeNames( downloadType );//query takes ownership
|
|
233 |
CleanupStack::Pop( downloadType );
|
|
234 |
queryDownload->SetRole( EGroupEntryRole );
|
|
235 |
|
|
236 |
RArray<TInt> idsGroup;
|
|
237 |
CleanupClosePushL( idsGroup );
|
|
238 |
iStorage->GetEntriesIdsL( queryDownload, idsGroup );
|
|
239 |
|
|
240 |
TCaOperationParams operParams;
|
|
241 |
operParams.iOperationType = TCaOperationParams::EPrepend;
|
|
242 |
operParams.iGroupId = idsGroup[0];
|
|
243 |
operParams.iBeforeEntryId = 0;
|
|
244 |
CleanupStack::PopAndDestroy( &idsGroup );
|
|
245 |
|
|
246 |
RArray<TInt> idsEntry;
|
|
247 |
CleanupClosePushL( idsEntry );
|
|
248 |
idsEntry.Append( aEntry->GetId() );
|
|
249 |
iStorage->OrganizeL( idsEntry, operParams );
|
|
250 |
|
|
251 |
CleanupStack::PopAndDestroy( &idsEntry );
|
|
252 |
CleanupStack::PopAndDestroy( queryDownload );
|
|
253 |
}
|
|
254 |
|
|
255 |
// ----------------------------------------------------------------------------
|
93
|
256 |
//
|
85
|
257 |
// ----------------------------------------------------------------------------
|
93
|
258 |
//
|
85
|
259 |
void CCaWidgetStorageHandler::FetchWidgetsL()
|
|
260 |
{
|
|
261 |
CCaInnerQuery* query = CCaInnerQuery::NewLC();
|
|
262 |
CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
|
|
263 |
KGranularityOne );
|
|
264 |
CleanupStack::PushL( widgetType );
|
|
265 |
widgetType->AppendL( KCaTypeWidget );
|
|
266 |
query->SetEntryTypeNames( widgetType );//transfers ownership to query
|
|
267 |
CleanupStack::Pop( widgetType );
|
|
268 |
|
|
269 |
RPointerArray<CCaInnerEntry> entries;
|
|
270 |
CleanupResetAndDestroyPushL( entries );
|
|
271 |
iStorage->GetEntriesL( query, entries );
|
|
272 |
iWidgets.ResetAndDestroy();
|
|
273 |
for( TInt i = 0; i < entries.Count(); i++ )
|
|
274 |
{
|
|
275 |
CCaWidgetDescription* widget = CCaWidgetDescription::NewLC(
|
|
276 |
entries[i] );
|
|
277 |
iWidgets.AppendL( widget ); //iWidgets takes ownership
|
|
278 |
CleanupStack::Pop( widget );
|
|
279 |
}
|
|
280 |
CleanupStack::PopAndDestroy( &entries );
|
|
281 |
CleanupStack::PopAndDestroy( query );
|
|
282 |
}
|
|
283 |
|
|
284 |
// ----------------------------------------------------------------------------
|
93
|
285 |
//
|
85
|
286 |
// ----------------------------------------------------------------------------
|
93
|
287 |
//
|
85
|
288 |
void CCaWidgetStorageHandler::SetMissingFlagL(
|
|
289 |
const CCaWidgetDescription* aWidget )
|
|
290 |
{
|
93
|
291 |
if( !aWidget->IsMissing() )
|
87
|
292 |
{
|
93
|
293 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
|
294 |
entry->SetFlags( entry->GetFlags() | EMissing );
|
|
295 |
if( aWidget->IsUsed() )
|
|
296 |
{
|
|
297 |
entry->SetFlags( entry->GetFlags() | EUsed );
|
|
298 |
}
|
|
299 |
iStorage->AddL( entry, EFalse, EItemDisappeared );
|
|
300 |
CleanupStack::PopAndDestroy( entry );
|
87
|
301 |
}
|
85
|
302 |
}
|
|
303 |
|
93
|
304 |
// ----------------------------------------------------------------------------
|
|
305 |
//
|
|
306 |
// ----------------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
void CCaWidgetStorageHandler::ClearVisibleFlagL(
|
|
309 |
const CCaWidgetDescription* aWidget )
|
|
310 |
{
|
|
311 |
if( aWidget->IsVisible() )
|
|
312 |
{
|
|
313 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
|
314 |
entry->SetFlags( entry->GetFlags() & ~EVisible & ~EMissing & ~EUsed );
|
|
315 |
iStorage->AddL( entry, EFalse, EItemDisappeared );
|
|
316 |
CleanupStack::PopAndDestroy( entry );
|
|
317 |
}
|
|
318 |
}
|
|
319 |
|
|
320 |
// ----------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
// ----------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
TBool CCaWidgetStorageHandler::MassStorageNotInUse()
|
|
325 |
{
|
|
326 |
TBool massStorageNotInUse( ETrue );
|
|
327 |
TInt drive;
|
|
328 |
if( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) ==
|
|
329 |
KErrNone )
|
|
330 |
{
|
|
331 |
TUint status;
|
|
332 |
if( DriveInfo::GetDriveStatus( iFs, drive, status ) == KErrNone &&
|
|
333 |
( status & DriveInfo::EDriveInUse ) )
|
|
334 |
{
|
|
335 |
massStorageNotInUse = EFalse;
|
|
336 |
}
|
|
337 |
}
|
|
338 |
return massStorageNotInUse;
|
|
339 |
}
|
|
340 |
|
94
|
341 |
// ----------------------------------------------------------------------------
|
|
342 |
//
|
|
343 |
// ----------------------------------------------------------------------------
|
|
344 |
//
|
|
345 |
|
|
346 |
void CCaWidgetStorageHandler::UpdateComponentIdL(
|
|
347 |
const TDesC& aManifestFilePathName,
|
|
348 |
CCaInnerEntry& aEntry ) const
|
|
349 |
{
|
|
350 |
RArray<TComponentId> componentIds;
|
|
351 |
CleanupClosePushL( componentIds );
|
|
352 |
|
|
353 |
CComponentFilter* const fileNameFilter = CComponentFilter::NewLC();
|
|
354 |
fileNameFilter->SetFileL( aManifestFilePathName );
|
|
355 |
iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
|
|
356 |
|
|
357 |
CleanupStack::PopAndDestroy( fileNameFilter );
|
|
358 |
|
|
359 |
if ( componentIds.Count() == 1 )
|
|
360 |
{
|
|
361 |
RBuf newComponentId;
|
|
362 |
newComponentId.CleanupClosePushL();
|
|
363 |
newComponentId.CreateL( sizeof(TComponentId) + 1 );
|
|
364 |
newComponentId.AppendNum( componentIds[0] );
|
|
365 |
|
|
366 |
RBuf oldComponentId;
|
|
367 |
oldComponentId.CleanupClosePushL();
|
|
368 |
oldComponentId.CreateL( KCaMaxAttrValueLen );
|
|
369 |
|
|
370 |
const TBool componentIdAttributeFound =
|
|
371 |
aEntry.FindAttribute( KCaComponentId, oldComponentId );
|
|
372 |
|
|
373 |
if ( !componentIdAttributeFound
|
|
374 |
|| oldComponentId.Compare( newComponentId ) != 0 )
|
|
375 |
{
|
|
376 |
// 'add' or 'update' the component id attribute value
|
|
377 |
aEntry.AddAttributeL( KCaComponentId,
|
|
378 |
newComponentId );
|
|
379 |
}
|
|
380 |
|
|
381 |
CleanupStack::PopAndDestroy( &oldComponentId );
|
|
382 |
CleanupStack::PopAndDestroy( &newComponentId );
|
|
383 |
}
|
|
384 |
|
|
385 |
CleanupStack::PopAndDestroy( &componentIds );
|
|
386 |
}
|
|
387 |
|
|
388 |
|
93
|
389 |
// End of File
|