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>
|
98
|
21 |
#include <hbtextresolversymbian.h>
|
|
22 |
|
85
|
23 |
#include "widgetscannerutils.h"
|
|
24 |
#include "cawidgetstoragehandler.h"
|
|
25 |
#include "cadef.h"
|
|
26 |
#include "cainnerentry.h"
|
|
27 |
#include "cainnerquery.h"
|
|
28 |
#include "castorageproxy.h"
|
|
29 |
#include "caarraycleanup.inl"
|
96
|
30 |
#include "calocalizationentry.h"
|
98
|
31 |
#include "cawidgetscannerparser.h"
|
96
|
32 |
#include "cawidgetscannerdef.h"
|
|
33 |
|
94
|
34 |
using namespace Usif;
|
|
35 |
|
98
|
36 |
// ============================ MEMBER FUNCTIONS ============================z===
|
85
|
37 |
|
|
38 |
// -----------------------------------------------------------------------------
|
98
|
39 |
//
|
85
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
//
|
98
|
42 |
CCaWidgetStorageHandler::CCaWidgetStorageHandler( CCaStorageProxy* aStorage,
|
102
|
43 |
Usif::RSoftwareComponentRegistry& aSoftwareRegistry, RFs& aFs ) :
|
|
44 |
iSoftwareRegistry(aSoftwareRegistry)
|
85
|
45 |
{
|
|
46 |
iStorage = aStorage;
|
|
47 |
iFs = aFs;
|
|
48 |
}
|
|
49 |
|
|
50 |
// -----------------------------------------------------------------------------
|
98
|
51 |
//
|
85
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
void CCaWidgetStorageHandler::ConstructL()
|
|
55 |
{
|
98
|
56 |
iParser = CCaWidgetScannerParser::NewL( iFs );
|
85
|
57 |
}
|
|
58 |
|
|
59 |
// -----------------------------------------------------------------------------
|
98
|
60 |
//
|
85
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewL(
|
102
|
64 |
CCaStorageProxy* aStorage,
|
|
65 |
Usif::RSoftwareComponentRegistry& aSoftwareRegistry, RFs& aFs )
|
85
|
66 |
{
|
102
|
67 |
CCaWidgetStorageHandler* self = NewLC( aStorage, aSoftwareRegistry, aFs );
|
85
|
68 |
CleanupStack::Pop( self );
|
|
69 |
return self;
|
|
70 |
}
|
|
71 |
|
|
72 |
// -----------------------------------------------------------------------------
|
98
|
73 |
//
|
85
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CCaWidgetStorageHandler* CCaWidgetStorageHandler::NewLC(
|
102
|
77 |
CCaStorageProxy* aStorage,
|
|
78 |
Usif::RSoftwareComponentRegistry& aSoftwareRegistry, RFs& aFs )
|
85
|
79 |
{
|
|
80 |
CCaWidgetStorageHandler* self = new ( ELeave ) CCaWidgetStorageHandler(
|
102
|
81 |
aStorage, aSoftwareRegistry, aFs );
|
85
|
82 |
CleanupStack::PushL( self );
|
|
83 |
self->ConstructL();
|
|
84 |
return self;
|
|
85 |
}
|
|
86 |
|
|
87 |
// -----------------------------------------------------------------------------
|
98
|
88 |
//
|
85
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
|
|
92 |
{
|
98
|
93 |
delete iParser;
|
85
|
94 |
iWidgets.ResetAndDestroy();
|
|
95 |
}
|
|
96 |
|
|
97 |
// ----------------------------------------------------------------------------
|
93
|
98 |
//
|
85
|
99 |
// ----------------------------------------------------------------------------
|
93
|
100 |
//
|
98
|
101 |
void CCaWidgetStorageHandler::SynchronizeL()
|
85
|
102 |
{
|
|
103 |
FetchWidgetsL();
|
98
|
104 |
AddWidgetsL( iParser->WidgetsScanL( iWidgets ) );
|
85
|
105 |
RemoveWidgetsL();
|
|
106 |
}
|
|
107 |
|
|
108 |
// ----------------------------------------------------------------------------
|
93
|
109 |
//
|
85
|
110 |
// ----------------------------------------------------------------------------
|
93
|
111 |
//
|
85
|
112 |
void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
|
|
113 |
{
|
|
114 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
106
|
115 |
UpdateCompIdAndRemovableFlagL( aWidget->GetManifestFilePathName(), *entry );
|
85
|
116 |
iStorage->AddL( entry );
|
96
|
117 |
|
|
118 |
SetLocalizationsL( aWidget, entry->GetId() );
|
98
|
119 |
|
|
120 |
if ( entry->GetFlags() & ERemovable )
|
85
|
121 |
{
|
|
122 |
AddWidgetToDownloadCollectionL( entry );
|
|
123 |
}
|
|
124 |
CleanupStack::PopAndDestroy( entry );
|
|
125 |
}
|
|
126 |
|
|
127 |
// ----------------------------------------------------------------------------
|
93
|
128 |
//
|
85
|
129 |
// ----------------------------------------------------------------------------
|
93
|
130 |
//
|
85
|
131 |
void CCaWidgetStorageHandler::UpdateL( const CCaWidgetDescription* aWidget,
|
|
132 |
TUint aEntryId )
|
|
133 |
{
|
|
134 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
106
|
135 |
UpdateCompIdAndRemovableFlagL( aWidget->GetManifestFilePathName(), *entry );
|
85
|
136 |
entry->SetId( aEntryId );
|
98
|
137 |
if ( !aWidget->IsMissing() && aWidget->IsUsed() )
|
85
|
138 |
{
|
|
139 |
entry->SetFlags( entry->GetFlags() & ~EUsed );
|
|
140 |
}
|
93
|
141 |
TItemAppearance itemAppearanceChange = EItemAppearanceNotChanged;
|
98
|
142 |
if ( ( entry->GetFlags() & EMissing ) || !( entry->GetFlags() & EVisible ) )
|
87
|
143 |
{
|
93
|
144 |
itemAppearanceChange = EItemAppeared;
|
87
|
145 |
}
|
93
|
146 |
entry->SetFlags( entry->GetFlags() & ~EMissing | EVisible );
|
|
147 |
iStorage->AddL( entry, EFalse, itemAppearanceChange );
|
98
|
148 |
|
96
|
149 |
SetLocalizationsL( aWidget, entry->GetId() );
|
98
|
150 |
|
106
|
151 |
if ( !aWidget->IsMissing() && ( entry->GetFlags() & ERemovable ) )
|
85
|
152 |
{
|
|
153 |
AddWidgetToDownloadCollectionL( entry );
|
|
154 |
}
|
|
155 |
CleanupStack::PopAndDestroy( entry );
|
|
156 |
}
|
|
157 |
|
|
158 |
// ----------------------------------------------------------------------------
|
93
|
159 |
//
|
85
|
160 |
// ----------------------------------------------------------------------------
|
93
|
161 |
//
|
85
|
162 |
void CCaWidgetStorageHandler::AddWidgetsL( const RWidgetArray& aWidgets )
|
|
163 |
{
|
98
|
164 |
for ( TInt i = 0; i < aWidgets.Count(); i++ )
|
85
|
165 |
{
|
96
|
166 |
aWidgets[i]->LocalizeTextsL();
|
98
|
167 |
TInt index = iWidgets.Find( aWidgets[i], CCaWidgetDescription::Compare );
|
|
168 |
if ( index != KErrNotFound )
|
85
|
169 |
{
|
98
|
170 |
iWidgets[index]->SetValid( ETrue );
|
|
171 |
if ( !iWidgets[index]->Compare( *aWidgets[i] )
|
|
172 |
|| iWidgets[index]->IsMissing() )
|
85
|
173 |
{
|
98
|
174 |
aWidgets[i]->SetFlag( EMissing, iWidgets[index]->IsMissing() );
|
|
175 |
aWidgets[i]->SetFlag( EUsed, iWidgets[index]->IsUsed() );
|
|
176 |
aWidgets[i]->SetFlag( EVisible, iWidgets[index]->IsVisible() );
|
85
|
177 |
UpdateL( aWidgets[i], iWidgets[index]->GetEntryId() );
|
|
178 |
}
|
|
179 |
}
|
|
180 |
else
|
|
181 |
{
|
|
182 |
AddL( aWidgets[i] );
|
|
183 |
}
|
|
184 |
}
|
98
|
185 |
HbTextResolverSymbian::Init( _L(""), KLocalizationFilepathZ );
|
85
|
186 |
}
|
|
187 |
|
|
188 |
// ----------------------------------------------------------------------------
|
93
|
189 |
//
|
85
|
190 |
// ----------------------------------------------------------------------------
|
93
|
191 |
//
|
85
|
192 |
void CCaWidgetStorageHandler::RemoveWidgetsL()
|
|
193 |
{
|
98
|
194 |
for ( TInt i = 0; i < iWidgets.Count(); i++ )
|
85
|
195 |
{
|
98
|
196 |
if ( !iWidgets[i]->IsValid() )
|
85
|
197 |
{
|
98
|
198 |
if ( iWidgets[i]->GetMmcId() != KNullDesC )
|
85
|
199 |
{
|
93
|
200 |
RBuf currentMmcId;
|
|
201 |
currentMmcId.CreateL( KMassStorageIdLength );
|
|
202 |
currentMmcId.CleanupClosePushL();
|
|
203 |
WidgetScannerUtils::CurrentMmcId( iFs, currentMmcId );
|
|
204 |
if( iWidgets[i]->GetMmcId() == currentMmcId ||
|
|
205 |
( iWidgets[i]->GetMmcId() == KCaMassStorage() &&
|
|
206 |
MassStorageNotInUse() ) )
|
|
207 |
{
|
|
208 |
//item was uninstalled so we remove its mmc id
|
|
209 |
iWidgets[i]->RemoveMmcId();
|
|
210 |
ClearVisibleFlagL( iWidgets[i] );
|
|
211 |
}
|
|
212 |
else
|
|
213 |
{
|
|
214 |
SetMissingFlagL( iWidgets[i] );
|
|
215 |
}
|
98
|
216 |
CleanupStack::PopAndDestroy( ¤tMmcId );
|
85
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
93
|
220 |
//item was uninstalled so we remove its mmc id
|
98
|
221 |
ClearVisibleFlagL( iWidgets[i] );
|
85
|
222 |
}
|
|
223 |
}
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|
|
227 |
// ----------------------------------------------------------------------------
|
93
|
228 |
//
|
85
|
229 |
// ----------------------------------------------------------------------------
|
93
|
230 |
//
|
85
|
231 |
void CCaWidgetStorageHandler::AddWidgetToDownloadCollectionL(
|
|
232 |
const CCaInnerEntry* aEntry )
|
|
233 |
{
|
|
234 |
CCaInnerQuery* queryDownload = CCaInnerQuery::NewLC();
|
|
235 |
CDesC16ArrayFlat* downloadType = new ( ELeave ) CDesC16ArrayFlat(
|
|
236 |
KGranularityOne );
|
|
237 |
CleanupStack::PushL( downloadType );
|
|
238 |
downloadType->AppendL( KCaTypeCollectionDownload );
|
|
239 |
queryDownload->SetEntryTypeNames( downloadType );//query takes ownership
|
|
240 |
CleanupStack::Pop( downloadType );
|
|
241 |
queryDownload->SetRole( EGroupEntryRole );
|
|
242 |
|
|
243 |
RArray<TInt> idsGroup;
|
|
244 |
CleanupClosePushL( idsGroup );
|
|
245 |
iStorage->GetEntriesIdsL( queryDownload, idsGroup );
|
|
246 |
|
|
247 |
TCaOperationParams operParams;
|
|
248 |
operParams.iOperationType = TCaOperationParams::EPrepend;
|
|
249 |
operParams.iGroupId = idsGroup[0];
|
|
250 |
operParams.iBeforeEntryId = 0;
|
|
251 |
CleanupStack::PopAndDestroy( &idsGroup );
|
|
252 |
|
|
253 |
RArray<TInt> idsEntry;
|
|
254 |
CleanupClosePushL( idsEntry );
|
|
255 |
idsEntry.Append( aEntry->GetId() );
|
|
256 |
iStorage->OrganizeL( idsEntry, operParams );
|
|
257 |
|
|
258 |
CleanupStack::PopAndDestroy( &idsEntry );
|
|
259 |
CleanupStack::PopAndDestroy( queryDownload );
|
|
260 |
}
|
|
261 |
|
|
262 |
// ----------------------------------------------------------------------------
|
93
|
263 |
//
|
85
|
264 |
// ----------------------------------------------------------------------------
|
93
|
265 |
//
|
85
|
266 |
void CCaWidgetStorageHandler::FetchWidgetsL()
|
|
267 |
{
|
|
268 |
CCaInnerQuery* query = CCaInnerQuery::NewLC();
|
|
269 |
CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
|
|
270 |
KGranularityOne );
|
|
271 |
CleanupStack::PushL( widgetType );
|
|
272 |
widgetType->AppendL( KCaTypeWidget );
|
|
273 |
query->SetEntryTypeNames( widgetType );//transfers ownership to query
|
|
274 |
CleanupStack::Pop( widgetType );
|
|
275 |
|
|
276 |
RPointerArray<CCaInnerEntry> entries;
|
|
277 |
CleanupResetAndDestroyPushL( entries );
|
|
278 |
iStorage->GetEntriesL( query, entries );
|
98
|
279 |
|
85
|
280 |
iWidgets.ResetAndDestroy();
|
98
|
281 |
for ( TInt i = 0; i < entries.Count(); i++ )
|
85
|
282 |
{
|
98
|
283 |
CCaWidgetDescription* widget = CCaWidgetDescription::NewLC( entries[i] );
|
85
|
284 |
iWidgets.AppendL( widget ); //iWidgets takes ownership
|
|
285 |
CleanupStack::Pop( widget );
|
|
286 |
}
|
|
287 |
CleanupStack::PopAndDestroy( &entries );
|
|
288 |
CleanupStack::PopAndDestroy( query );
|
|
289 |
}
|
|
290 |
|
|
291 |
// ----------------------------------------------------------------------------
|
93
|
292 |
//
|
85
|
293 |
// ----------------------------------------------------------------------------
|
93
|
294 |
//
|
85
|
295 |
void CCaWidgetStorageHandler::SetMissingFlagL(
|
|
296 |
const CCaWidgetDescription* aWidget )
|
|
297 |
{
|
98
|
298 |
if ( !aWidget->IsMissing() )
|
87
|
299 |
{
|
93
|
300 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
98
|
301 |
entry->SetFlags( ( entry->GetFlags() | EMissing ) & ~EUninstall );
|
|
302 |
if ( aWidget->IsUsed() )
|
93
|
303 |
{
|
|
304 |
entry->SetFlags( entry->GetFlags() | EUsed );
|
|
305 |
}
|
|
306 |
iStorage->AddL( entry, EFalse, EItemDisappeared );
|
|
307 |
CleanupStack::PopAndDestroy( entry );
|
87
|
308 |
}
|
85
|
309 |
}
|
|
310 |
|
93
|
311 |
// ----------------------------------------------------------------------------
|
|
312 |
//
|
|
313 |
// ----------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
void CCaWidgetStorageHandler::ClearVisibleFlagL(
|
|
316 |
const CCaWidgetDescription* aWidget )
|
|
317 |
{
|
98
|
318 |
if ( aWidget->IsVisible() )
|
|
319 |
{
|
|
320 |
CCaInnerEntry* entry = aWidget->GetEntryLC();
|
|
321 |
entry->SetFlags( entry->GetFlags()
|
|
322 |
& ~EUninstall
|
|
323 |
& ~EVisible
|
|
324 |
& ~EMissing
|
|
325 |
& ~EUsed );
|
|
326 |
iStorage->AddL( entry, EFalse, EItemDisappeared );
|
|
327 |
CleanupStack::PopAndDestroy( entry );
|
|
328 |
}
|
93
|
329 |
}
|
|
330 |
|
|
331 |
// ----------------------------------------------------------------------------
|
|
332 |
//
|
|
333 |
// ----------------------------------------------------------------------------
|
|
334 |
//
|
|
335 |
TBool CCaWidgetStorageHandler::MassStorageNotInUse()
|
|
336 |
{
|
|
337 |
TBool massStorageNotInUse( ETrue );
|
|
338 |
TInt drive;
|
|
339 |
if( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) ==
|
|
340 |
KErrNone )
|
|
341 |
{
|
|
342 |
TUint status;
|
|
343 |
if( DriveInfo::GetDriveStatus( iFs, drive, status ) == KErrNone &&
|
|
344 |
( status & DriveInfo::EDriveInUse ) )
|
|
345 |
{
|
|
346 |
massStorageNotInUse = EFalse;
|
|
347 |
}
|
|
348 |
}
|
|
349 |
return massStorageNotInUse;
|
|
350 |
}
|
96
|
351 |
// ----------------------------------------------------------------------------
|
|
352 |
//
|
|
353 |
// ----------------------------------------------------------------------------
|
|
354 |
//
|
|
355 |
|
98
|
356 |
void CCaWidgetStorageHandler::SetLocalizationsL(
|
|
357 |
const CCaWidgetDescription* aWidget, TInt aEntryId )
|
96
|
358 |
{
|
|
359 |
RBuf filename;
|
99
|
360 |
filename.CreateL( aWidget->GetTranslationFileName().Length() + 1 ); //1 for _
|
96
|
361 |
CleanupClosePushL( filename );
|
99
|
362 |
filename.Copy( aWidget->GetTranslationFileName() );
|
96
|
363 |
filename.Append( KWidgetScannerUnderline );
|
98
|
364 |
|
96
|
365 |
// prepare localizations
|
98
|
366 |
if ( aWidget->GetTitle().Length() > 0 && aWidget->GetTitle().Compare(
|
|
367 |
aWidget->GetStringIdTitle() ) )
|
|
368 |
// lets do not add localization when key and value are identical
|
96
|
369 |
{
|
|
370 |
CCaLocalizationEntry* titleEntry = CCaLocalizationEntry::NewL();
|
|
371 |
CleanupStack::PushL( titleEntry );
|
98
|
372 |
titleEntry->SetTableNameL( KLocalizationCaEntry );
|
|
373 |
titleEntry->SetAttributeNameL( KLocalizationEnText );
|
96
|
374 |
titleEntry->SetStringIdL( aWidget->GetStringIdTitle() );
|
|
375 |
titleEntry->SetQmFilenameL( filename );
|
|
376 |
titleEntry->SetRowId( aEntryId );
|
|
377 |
iStorage->AddLocalizationL( *titleEntry );
|
|
378 |
CleanupStack::PopAndDestroy( titleEntry );
|
|
379 |
}
|
|
380 |
if ( aWidget->GetDescription().Length() > 0 &&
|
|
381 |
aWidget->GetDescription().Compare(
|
|
382 |
aWidget->GetStringIdDescription() ) )
|
98
|
383 |
// lets do not add localization when key and value are identical
|
96
|
384 |
{
|
|
385 |
CCaLocalizationEntry* descEntry = CCaLocalizationEntry::NewL();
|
|
386 |
CleanupStack::PushL( descEntry );
|
98
|
387 |
descEntry->SetTableNameL( KLocalizationCaEntry );
|
|
388 |
descEntry->SetAttributeNameL( KLocalizationEnDescription );
|
96
|
389 |
descEntry->SetStringIdL( aWidget->GetStringIdDescription() );
|
|
390 |
descEntry->SetQmFilenameL( filename );
|
|
391 |
descEntry->SetRowId( aEntryId );
|
|
392 |
iStorage->AddLocalizationL( *descEntry );
|
|
393 |
CleanupStack::PopAndDestroy( descEntry );
|
|
394 |
}
|
|
395 |
CleanupStack::PopAndDestroy( &filename );
|
|
396 |
}
|
93
|
397 |
|
94
|
398 |
// ----------------------------------------------------------------------------
|
|
399 |
//
|
|
400 |
// ----------------------------------------------------------------------------
|
|
401 |
//
|
|
402 |
|
106
|
403 |
void CCaWidgetStorageHandler::UpdateCompIdAndRemovableFlagL(
|
98
|
404 |
const TDesC& aManifestFilePathName, CCaInnerEntry& aEntry ) const
|
94
|
405 |
{
|
|
406 |
RArray<TComponentId> componentIds;
|
|
407 |
CleanupClosePushL( componentIds );
|
98
|
408 |
|
94
|
409 |
CComponentFilter* const fileNameFilter = CComponentFilter::NewLC();
|
|
410 |
fileNameFilter->SetFileL( aManifestFilePathName );
|
|
411 |
iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
|
|
412 |
|
|
413 |
CleanupStack::PopAndDestroy( fileNameFilter );
|
98
|
414 |
|
106
|
415 |
if( componentIds.Count() == 1 )
|
94
|
416 |
{
|
|
417 |
RBuf newComponentId;
|
|
418 |
newComponentId.CleanupClosePushL();
|
|
419 |
newComponentId.CreateL( sizeof(TComponentId) + 1 );
|
|
420 |
newComponentId.AppendNum( componentIds[0] );
|
98
|
421 |
|
94
|
422 |
RBuf oldComponentId;
|
|
423 |
oldComponentId.CleanupClosePushL();
|
|
424 |
oldComponentId.CreateL( KCaMaxAttrValueLen );
|
98
|
425 |
|
|
426 |
const TBool componentIdAttributeFound = aEntry.FindAttribute(
|
|
427 |
KCaComponentId, oldComponentId );
|
|
428 |
|
106
|
429 |
if( !componentIdAttributeFound || oldComponentId.Compare(
|
98
|
430 |
newComponentId ) != 0 )
|
94
|
431 |
{
|
|
432 |
// 'add' or 'update' the component id attribute value
|
98
|
433 |
aEntry.AddAttributeL( KCaComponentId, newComponentId );
|
94
|
434 |
}
|
106
|
435 |
CComponentEntry* entry = CComponentEntry::NewLC();
|
|
436 |
iSoftwareRegistry.GetComponentL( componentIds[0] , *entry );
|
|
437 |
if( entry->IsRemovable() )
|
|
438 |
{
|
|
439 |
aEntry.SetFlags( aEntry.GetFlags() | ERemovable );
|
|
440 |
}
|
|
441 |
CleanupStack::PopAndDestroy( entry );
|
94
|
442 |
CleanupStack::PopAndDestroy( &oldComponentId );
|
|
443 |
CleanupStack::PopAndDestroy( &newComponentId );
|
|
444 |
}
|
|
445 |
|
|
446 |
CleanupStack::PopAndDestroy( &componentIds );
|
|
447 |
}
|
|
448 |
|
93
|
449 |
// End of File
|