85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: causifscanner.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32property.h>
|
|
19 |
#include <f32file.h>
|
|
20 |
#include <badesca.h>
|
|
21 |
#include <usif/sif/sif.h>
|
|
22 |
#include <usif/scr/scr.h>
|
|
23 |
#include <usif/sif/sifcommon.h>
|
|
24 |
|
|
25 |
#include "causifscanner.h"
|
|
26 |
#include "cainnerentry.h"
|
|
27 |
#include "cainnerquery.h"
|
|
28 |
#include "cadef.h"
|
|
29 |
#include "castorageproxy.h"
|
|
30 |
#include "caarraycleanup.inl"
|
|
31 |
|
|
32 |
using namespace Usif;
|
|
33 |
|
|
34 |
_LIT( KUsifPluginCollection, "Usif collection");
|
|
35 |
_LIT( KCaAttrComponentId, "component_id" );
|
|
36 |
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CCaUsifScanner* CCaUsifScanner::NewL( TPluginParams* aPluginParams )
|
|
42 |
{
|
|
43 |
CCaUsifScanner* self = new ( ELeave )
|
|
44 |
CCaUsifScanner( *aPluginParams->storageProxy );
|
|
45 |
CleanupStack::PushL( self );
|
|
46 |
self->ConstructL();
|
|
47 |
CleanupStack::Pop( self );
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
CCaUsifScanner::CCaUsifScanner( CCaStorageProxy& aStorageProxy ) :
|
|
56 |
iStorageProxy( aStorageProxy )
|
|
57 |
{
|
|
58 |
|
|
59 |
}
|
|
60 |
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
// ---------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
void CCaUsifScanner::ConstructL()
|
|
66 |
{
|
|
67 |
AddCollectionUsifL();
|
|
68 |
AddNativeAppsL();
|
|
69 |
}
|
|
70 |
|
|
71 |
// ---------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
CCaUsifScanner::~CCaUsifScanner()
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
void CCaUsifScanner::InstallL( const TDesC& aFileName )
|
|
84 |
{
|
|
85 |
RSoftwareInstall sif;
|
|
86 |
CleanupClosePushL( sif );
|
|
87 |
User::LeaveIfError( sif.Connect());
|
|
88 |
|
|
89 |
// Install the component
|
|
90 |
TRequestStatus status;
|
|
91 |
sif.Install( aFileName, status, EFalse );
|
|
92 |
User::WaitForRequest( status );
|
|
93 |
User::LeaveIfError(status.Int());
|
|
94 |
|
|
95 |
// Disconnect from the SIF server
|
|
96 |
CleanupStack::PopAndDestroy( &sif );
|
|
97 |
}
|
|
98 |
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
//
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
void CCaUsifScanner::AddCollectionUsifL()
|
|
104 |
{
|
|
105 |
if( GetCollectionUsifIdL() == 0 )
|
|
106 |
{
|
|
107 |
CCaInnerEntry *entry = CCaInnerEntry::NewLC();
|
|
108 |
entry->SetRole( EGroupEntryRole );
|
|
109 |
entry->SetEntryTypeNameL( KCaTypeCollection );
|
|
110 |
entry->SetFlags( ERemovable | EVisible );
|
|
111 |
entry->SetTextL( KUsifPluginCollection );
|
|
112 |
iStorageProxy.AddL( entry );
|
|
113 |
iCollectionUsifId = entry->GetId();
|
|
114 |
CleanupStack::PopAndDestroy( entry );
|
|
115 |
|
|
116 |
TCaOperationParams params =
|
|
117 |
{
|
|
118 |
TCaOperationParams::EPrepend, 2, 0
|
|
119 |
};
|
|
120 |
RArray<TInt> ids;
|
|
121 |
CleanupClosePushL( ids );
|
|
122 |
ids.AppendL( iCollectionUsifId );
|
|
123 |
iStorageProxy.OrganizeL( ids, params );
|
|
124 |
CleanupStack::PopAndDestroy( &ids );
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
TInt CCaUsifScanner::GetCollectionUsifIdL()
|
|
133 |
{
|
|
134 |
if( iCollectionUsifId == 0 )
|
|
135 |
{
|
|
136 |
RPointerArray<CCaInnerEntry> resultArray;
|
|
137 |
CleanupResetAndDestroyPushL( resultArray );
|
|
138 |
CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
|
|
139 |
CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 );
|
|
140 |
CleanupStack::PushL( appType );
|
|
141 |
appType->AppendL( KCaTypeCollection );
|
|
142 |
allAppQuery->SetEntryTypeNames( appType );
|
|
143 |
allAppQuery->SetRole(CCaInnerQuery::Group);
|
|
144 |
CleanupStack::Pop( appType );
|
|
145 |
iStorageProxy.GetEntriesL( allAppQuery, resultArray );
|
|
146 |
CleanupStack::PopAndDestroy( allAppQuery );
|
|
147 |
for(TInt i(0); i< resultArray.Count(); i++ )
|
|
148 |
{
|
|
149 |
if(!resultArray[i]->GetText().Compare(KUsifPluginCollection))
|
|
150 |
iCollectionUsifId = resultArray[i]->GetId();
|
|
151 |
}
|
|
152 |
CleanupStack::PopAndDestroy( &resultArray );
|
|
153 |
}
|
|
154 |
return iCollectionUsifId;
|
|
155 |
}
|
|
156 |
|
|
157 |
// ---------------------------------------------------------------------------
|
|
158 |
//
|
|
159 |
// ---------------------------------------------------------------------------
|
|
160 |
//
|
|
161 |
void CCaUsifScanner::CreateCaEntryFromEntryL(
|
|
162 |
const CComponentEntry* aEntry, CCaInnerEntry* aCaEntry )
|
|
163 |
{
|
|
164 |
aCaEntry->SetRole( EItemEntryRole );
|
|
165 |
aCaEntry->SetEntryTypeNameL(KCaTypeApp);
|
|
166 |
if( aEntry->Name().Compare(KNullDesC))
|
|
167 |
{
|
|
168 |
aCaEntry->SetTextL(aEntry->Name());
|
|
169 |
}
|
|
170 |
if( !aEntry->IsHidden() )
|
|
171 |
{
|
|
172 |
aCaEntry->SetFlags( EVisible );
|
|
173 |
}
|
|
174 |
if( aEntry->IsRemovable() )
|
|
175 |
{
|
|
176 |
aCaEntry->SetFlags( aCaEntry->GetFlags() | ERemovable );
|
|
177 |
}
|
|
178 |
if( aEntry->GlobalId().Compare( KNullDesC ) )
|
|
179 |
{
|
|
180 |
TLex lex( aEntry->GlobalId() );
|
|
181 |
TUint uint( 0 );
|
|
182 |
User::LeaveIfError( lex.Val( uint, EHex ) );
|
|
183 |
aCaEntry->SetUid( uint );
|
|
184 |
}
|
|
185 |
RBuf compIdDesc;
|
|
186 |
CleanupClosePushL(compIdDesc);
|
|
187 |
compIdDesc.CreateL(KCaMaxAttrValueLen);
|
|
188 |
compIdDesc.Num(aEntry->ComponentId());
|
|
189 |
aCaEntry->AddAttributeL( KCaAttrComponentId, compIdDesc );
|
|
190 |
CleanupStack::PopAndDestroy( &compIdDesc );
|
|
191 |
|
|
192 |
}
|
|
193 |
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
//
|
|
198 |
void CCaUsifScanner::AddNativeAppsL()
|
|
199 |
{
|
|
200 |
TLanguage locale = TLanguage(-1);
|
|
201 |
|
|
202 |
CComponentFilter *filter = CComponentFilter::NewL();
|
|
203 |
CleanupStack::PushL(filter);
|
|
204 |
filter->SetSoftwareTypeL( KSoftwareTypeNative );
|
|
205 |
filter->SetRemovable(ETrue);
|
|
206 |
|
|
207 |
// Connect to the SCR server
|
|
208 |
RSoftwareComponentRegistry *scr = new RSoftwareComponentRegistry();
|
|
209 |
CleanupClosePushL(*scr);
|
|
210 |
User::LeaveIfError( scr->Connect() );
|
|
211 |
|
|
212 |
// Create an SCR view
|
|
213 |
RSoftwareComponentRegistryView *scrView =
|
|
214 |
new RSoftwareComponentRegistryView();
|
|
215 |
CleanupClosePushL(*scrView);
|
|
216 |
scrView->OpenViewL( *scr, filter );
|
|
217 |
|
|
218 |
// Iterate over the matching components
|
|
219 |
CComponentEntry* entry = CComponentEntry::NewLC();
|
|
220 |
|
|
221 |
RPointerArray<CCaInnerEntry> entries;
|
|
222 |
CleanupResetAndDestroyPushL( entries );
|
|
223 |
GetCaAppEntriesL(entries);
|
|
224 |
|
|
225 |
RArray<TInt> entryIds;
|
|
226 |
CleanupClosePushL(entryIds);
|
|
227 |
while( scrView->NextComponentL( *entry, locale ) )
|
|
228 |
{
|
|
229 |
CCaInnerEntry *caEntry = CCaInnerEntry::NewLC();
|
|
230 |
CreateCaEntryFromEntryL( entry, caEntry );
|
|
231 |
|
|
232 |
if( !AppExist(entries, caEntry))
|
|
233 |
{
|
|
234 |
iStorageProxy.AddL( caEntry );
|
|
235 |
entryIds.Append( caEntry->GetId() );
|
|
236 |
}
|
|
237 |
CleanupStack::PopAndDestroy( caEntry );
|
|
238 |
}
|
|
239 |
TCaOperationParams params =
|
|
240 |
{
|
|
241 |
TCaOperationParams::EAppend, iCollectionUsifId, 0
|
|
242 |
};
|
|
243 |
iStorageProxy.OrganizeL( entryIds, params );
|
|
244 |
|
|
245 |
CleanupStack::PopAndDestroy( &entryIds );
|
|
246 |
CleanupStack::PopAndDestroy( &entries );
|
|
247 |
CleanupStack::PopAndDestroy( entry );
|
|
248 |
CleanupStack::PopAndDestroy(scrView);
|
|
249 |
CleanupStack::PopAndDestroy(scr);
|
|
250 |
CleanupStack::PopAndDestroy(filter);
|
|
251 |
}
|
|
252 |
|
|
253 |
// ---------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
// ---------------------------------------------------------------------------
|
|
256 |
//
|
|
257 |
void CCaUsifScanner::GetCaAppEntriesL(
|
|
258 |
RPointerArray<CCaInnerEntry>& aArray )
|
|
259 |
{
|
|
260 |
CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
|
|
261 |
CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 );
|
|
262 |
CleanupStack::PushL( appType );
|
|
263 |
appType->AppendL( KCaTypeApp );
|
|
264 |
allAppQuery->SetEntryTypeNames( appType );
|
|
265 |
CleanupStack::Pop( appType );
|
|
266 |
iStorageProxy.GetEntriesL( allAppQuery, aArray );
|
|
267 |
CleanupStack::PopAndDestroy( allAppQuery );
|
|
268 |
}
|
|
269 |
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
// ---------------------------------------------------------------------------
|
|
273 |
//
|
|
274 |
TInt CCaUsifScanner::AppExist( RPointerArray<CCaInnerEntry>& aArray,
|
|
275 |
CCaInnerEntry* aEntry )
|
|
276 |
{
|
|
277 |
for (TInt i(0); i < aArray.Count(); i++)
|
|
278 |
{
|
|
279 |
if( aArray[i]->GetUid() == aEntry->GetUid())
|
|
280 |
return KErrAlreadyExists;
|
|
281 |
}
|
|
282 |
return KErrNone;
|
|
283 |
}
|