|
1 /* |
|
2 * Copyright (c) 2006 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: This is defines CWidgetRegistrationManager which handles |
|
15 * registration of widgets |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "WidgetRegistrationManager.h" |
|
20 #include "WidgetUIOperationsWatcher.h" |
|
21 #include <apgcli.h> |
|
22 #include <APGICNFL.h> |
|
23 #include <S32MEM.H> |
|
24 #include <WidgetRegistryConstants.h> |
|
25 |
|
26 // CONSTANTS |
|
27 _LIT(KMBMExt, ".mbm"); |
|
28 |
|
29 using namespace SwiUI; |
|
30 |
|
31 // MEMBER FUNCTION DECLARATIONS |
|
32 |
|
33 // ============================================================================ |
|
34 // CWidgetRegistrationManager::NewL() |
|
35 // two-phase constructor |
|
36 // |
|
37 // @since 3.1 |
|
38 // ============================================================================ |
|
39 // |
|
40 CWidgetRegistrationManager* CWidgetRegistrationManager::NewL( RFs& aFs ) |
|
41 { |
|
42 CWidgetRegistrationManager *self = |
|
43 new ( ELeave ) CWidgetRegistrationManager( aFs ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ============================================================================ |
|
51 // CWidgetRegistrationManager::CWidgetRegistrationManager() |
|
52 // C++ constructor |
|
53 // |
|
54 // @since 3.1 |
|
55 // ============================================================================ |
|
56 // |
|
57 CWidgetRegistrationManager::CWidgetRegistrationManager( |
|
58 RFs& aFs ) |
|
59 : iFs( aFs ) |
|
60 { |
|
61 } |
|
62 |
|
63 // ============================================================================ |
|
64 // CWidgetRegistrationManager::~CWidgetRegistrationManager() |
|
65 // destructor |
|
66 // |
|
67 // @since 3.1 |
|
68 // ============================================================================ |
|
69 // |
|
70 CWidgetRegistrationManager::~CWidgetRegistrationManager() |
|
71 { |
|
72 } |
|
73 |
|
74 // ============================================================================ |
|
75 // CWidgetRegistrationManager::CWidgetRegistrationManager() |
|
76 // Symbian second phase constructor |
|
77 // |
|
78 // @since 3.1 |
|
79 // ============================================================================ |
|
80 // |
|
81 void CWidgetRegistrationManager::ConstructL() |
|
82 { |
|
83 } |
|
84 |
|
85 // ============================================================================ |
|
86 // CWidgetRegistrationManager::DeregisterWidgetL() |
|
87 // Deregister installed widget as non native app |
|
88 // |
|
89 // @since 3.1 |
|
90 // ============================================================================ |
|
91 // |
|
92 void CWidgetRegistrationManager::DeregisterWidgetL( const TUid& aUid ) |
|
93 { |
|
94 RApaLsSession apparcSession; |
|
95 User::LeaveIfError( apparcSession.Connect() ); |
|
96 |
|
97 apparcSession.PrepareNonNativeApplicationsUpdatesL(); |
|
98 apparcSession.DeregisterNonNativeApplicationL( aUid ); |
|
99 apparcSession.DeregisterNonNativeApplicationTypeL( aUid ); |
|
100 apparcSession.CommitNonNativeApplicationsUpdatesL(); |
|
101 apparcSession.Close(); |
|
102 } |
|
103 |
|
104 // ============================================================================ |
|
105 // CWidgetRegistrationManager::RegisterWidgetL() |
|
106 // Register installed widget as non native app |
|
107 // |
|
108 // It will leave if registration is impossible or fails. It will not |
|
109 // leave if icon path is KNullDesC or unusable since a default icon |
|
110 // will be used. |
|
111 // |
|
112 // @since 3.1 |
|
113 // ============================================================================ |
|
114 // |
|
115 void CWidgetRegistrationManager::RegisterWidgetL( |
|
116 const TDesC& aMainHTML, |
|
117 const TDesC& aBundleDisplayName, |
|
118 const TDesC& aIconPath, |
|
119 const TDesC& aDriveName, |
|
120 const TUid& aUid ) |
|
121 { |
|
122 RApaLsSession apparcSession; |
|
123 CleanupClosePushL( apparcSession ); |
|
124 User::LeaveIfError( apparcSession.Connect() ); |
|
125 apparcSession.PrepareNonNativeApplicationsUpdatesL(); |
|
126 apparcSession.DeregisterNonNativeApplicationL( KUidWidgetLauncher ); |
|
127 apparcSession.DeregisterNonNativeApplicationTypeL( KUidWidgetLauncher ); |
|
128 apparcSession.CommitNonNativeApplicationsUpdatesL(); |
|
129 |
|
130 // reasonably like an acceptable file name |
|
131 TBuf<KWidgetRegistryVal> appName; |
|
132 appName.Append( aMainHTML ); |
|
133 |
|
134 CApaRegistrationResourceFileWriter* writer = |
|
135 CApaRegistrationResourceFileWriter::NewL( |
|
136 aUid, |
|
137 appName, |
|
138 TApaAppCapability::ENonNative ); |
|
139 CleanupStack::PushL( writer ); |
|
140 |
|
141 TBuf8<KWidgetRegistryVal> opaqueData; |
|
142 RDesWriteStream writeStream( opaqueData ); |
|
143 |
|
144 // le data opaque |
|
145 writeStream.WriteUint32L( aUid.iUid ); |
|
146 writeStream.WriteUint32L( aMainHTML.Length() ); |
|
147 writeStream.WriteL( aMainHTML ); |
|
148 |
|
149 writeStream.CommitL(); |
|
150 writer->SetOpaqueDataL( opaqueData ); |
|
151 |
|
152 // avec nom de plume |
|
153 CApaLocalisableResourceFileWriter* lWriter = |
|
154 CApaLocalisableResourceFileWriter::NewL( |
|
155 KNullDesC, |
|
156 aBundleDisplayName, |
|
157 1 , |
|
158 KNullDesC ); |
|
159 CleanupStack::PushL( lWriter ); |
|
160 |
|
161 // This call deletes any pending registrations which are not commited |
|
162 // in previous installations (ex: power off case). |
|
163 // This must be the first call after session connect, |
|
164 // and before Prepare... call. |
|
165 // This function returns with no effect, if no pending registrations in |
|
166 // previous install. |
|
167 apparcSession.RollbackNonNativeApplicationsUpdates(); |
|
168 |
|
169 // Prepare for Registration & Deregistration. |
|
170 // Actual Registration & Deregistration will be done at Commit call |
|
171 // CommitNonNativeApplicationsUpdatesL. |
|
172 apparcSession.PrepareNonNativeApplicationsUpdatesL(); |
|
173 |
|
174 RFile appArcIconFile; |
|
175 CleanupClosePushL( appArcIconFile ); |
|
176 RFile* toIconFile = NULL; |
|
177 |
|
178 // la petit image (ou non) |
|
179 if ( aIconPath.Length() ) |
|
180 { |
|
181 TFileName mbmIcon; |
|
182 mbmIcon.Append( aIconPath ); |
|
183 mbmIcon.Append( aUid.Name() ); |
|
184 mbmIcon.Append( KMBMExt() ); |
|
185 TInt error = |
|
186 appArcIconFile.Open( |
|
187 iFs, mbmIcon, |
|
188 EFileShareReadersOrWriters|EFileWrite ); |
|
189 if ( KErrNone == error ) |
|
190 { |
|
191 toIconFile = &appArcIconFile; |
|
192 } |
|
193 } |
|
194 |
|
195 apparcSession.RegisterNonNativeApplicationL( |
|
196 KUidWidgetLauncher, |
|
197 aDriveName, |
|
198 *writer, |
|
199 lWriter, |
|
200 toIconFile ); |
|
201 |
|
202 TRAP_IGNORE( apparcSession.RegisterNonNativeApplicationTypeL( |
|
203 KUidWidgetLauncher, |
|
204 KLauncherApp() ) ); |
|
205 |
|
206 apparcSession.CommitNonNativeApplicationsUpdatesL(); |
|
207 |
|
208 // appArcIconFile, writer, lWriter, apparcSession |
|
209 CleanupStack::PopAndDestroy( 4 ); |
|
210 } |
|
211 |
|
212 // End of File |