|
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: |
|
15 * widget manager plugin implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <eikenv.h> |
|
21 |
|
22 #include "wminstaller.h" |
|
23 #include "wmwidgetdata.h" |
|
24 #include "wmplugin.h" |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 _LIT8( KWrtMime, "application/x-nokia-widget"); |
|
29 |
|
30 /* |
|
31 Note: |
|
32 same mime type as above is used for wgz & wgt in wk9. |
|
33 \ext\mw\cwrt\app\platform\s60\WidgetRecognizer\ |
|
34 Uninstalltion will fail with KErrNotFound for now. |
|
35 */ |
|
36 _LIT8( KCWrtMime, "application/widget"); |
|
37 |
|
38 // --------------------------------------------------------- |
|
39 // CWmInstaller::NewL |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 CWmInstaller* CWmInstaller::NewL( CWmPlugin& aWmPlugin ) |
|
43 { |
|
44 CWmInstaller* self = CWmInstaller::NewLC( aWmPlugin ); |
|
45 CleanupStack::Pop(); // self; |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CWmInstaller::NewLC |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 CWmInstaller* CWmInstaller::NewLC( CWmPlugin& aWmPlugin ) |
|
54 { |
|
55 CWmInstaller* self = new ( ELeave ) CWmInstaller( aWmPlugin ); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CWmInstaller::CWmInstaller |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 CWmInstaller::CWmInstaller( CWmPlugin& aWmPlugin ) : |
|
66 CActive( EPriorityStandard ), |
|
67 iWmPlugin( aWmPlugin ) |
|
68 { |
|
69 iUid = KNullUid; |
|
70 iIdle = NULL; |
|
71 CActiveScheduler::Add( this ); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CWmInstaller::ConstructL |
|
76 // --------------------------------------------------------- |
|
77 // |
|
78 void CWmInstaller::ConstructL() |
|
79 { |
|
80 iIdle = CIdle::NewL( CActive::EPriorityStandard ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------- |
|
84 // CWmInstaller::~CWmInstaller |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 CWmInstaller::~CWmInstaller() |
|
88 { |
|
89 Cancel(); |
|
90 |
|
91 if ( iIdle && iIdle->IsActive() ) |
|
92 { |
|
93 iIdle->Cancel(); |
|
94 } |
|
95 delete iIdle; |
|
96 delete iMime; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CWmInstaller::DoCancel |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CWmInstaller::DoCancel() |
|
104 { |
|
105 if ( IsActive() ) |
|
106 { |
|
107 iInstaller.CancelAsyncRequest( |
|
108 SwiUI::ERequestSilentUninstall ); |
|
109 |
|
110 // close session |
|
111 iInstaller.Close(); |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------- |
|
116 // CWmInstaller::RunL |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 void CWmInstaller::RunL() |
|
120 { |
|
121 // if error has occurred, stop uninstallation animation. |
|
122 CWmWidgetData* widget = |
|
123 iWmPlugin.GetUninstalledWidgetByUid( iUid ); |
|
124 if ( widget ) |
|
125 { |
|
126 widget->StopUninstallAnimation(); |
|
127 } |
|
128 |
|
129 if ( KErrNone != iStatus.Int() ) |
|
130 { |
|
131 // display error note incase of error |
|
132 CEikonEnv::Static()->HandleError( iStatus.Int() ); |
|
133 } |
|
134 |
|
135 // close SWI session |
|
136 if ( iIdle && iIdle->IsActive() ) |
|
137 { |
|
138 iIdle->Cancel(); |
|
139 } |
|
140 iIdle->Start( TCallBack( CloseSwiSession, this ) ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // CWmInstaller::CloseSwiSession |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 TInt CWmInstaller::CloseSwiSession( TAny* aPtr ) |
|
148 { |
|
149 CWmInstaller* self = static_cast< CWmInstaller* >( aPtr ); |
|
150 if ( self->iIdle->IsActive() ) |
|
151 { |
|
152 self->iIdle->Cancel(); |
|
153 } |
|
154 |
|
155 self->iUid = KNullUid; |
|
156 |
|
157 self->iInstaller.Close(); |
|
158 return KErrNone; |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------- |
|
162 // CWmInstaller::RunError |
|
163 // --------------------------------------------------------- |
|
164 // |
|
165 TInt CWmInstaller::RunError(TInt /*aError*/) |
|
166 { |
|
167 // if error has occurred, stop uninstallation animation. |
|
168 CWmWidgetData* widget = |
|
169 iWmPlugin.GetUninstalledWidgetByUid( iUid ); |
|
170 if ( widget ) |
|
171 { |
|
172 widget->StopUninstallAnimation(); |
|
173 } |
|
174 // close SWI session |
|
175 if ( iIdle && iIdle->IsActive() ) |
|
176 { |
|
177 iIdle->Cancel(); |
|
178 } |
|
179 iIdle->Start( TCallBack( CloseSwiSession, this ) ); |
|
180 |
|
181 return KErrNone; |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CWmInstaller::UninstallL |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 void CWmInstaller::UninstallL( CWmWidgetData* aData ) |
|
189 { |
|
190 if ( IsActive() ) |
|
191 { |
|
192 User::Leave( KErrInUse ); |
|
193 } |
|
194 else if ( !aData || aData->PublisherUid() == KNullUid || |
|
195 aData->WrtType() == CWmWidgetData::EUnIdentified ) |
|
196 { |
|
197 User::Leave( KErrArgument ); |
|
198 } |
|
199 else |
|
200 { |
|
201 delete iMime; |
|
202 iMime = NULL; |
|
203 CloseSwiSession( this ); |
|
204 |
|
205 // re-open session to swi server |
|
206 User::LeaveIfError( iInstaller.Connect() ); |
|
207 iMime = ( ( aData->WrtType() == CWmWidgetData::EWgt ) ? |
|
208 KCWrtMime().AllocL() : KWrtMime().AllocL() ); |
|
209 iUid = aData->PublisherUid(); |
|
210 SwiUI::TUninstallOptions optionsUninstall; |
|
211 optionsUninstall.iBreakDependency = SwiUI::EPolicyAllowed; |
|
212 optionsUninstall.iKillApp = SwiUI::EPolicyAllowed; |
|
213 SwiUI::TUninstallOptionsPckg uninstallOptionsPkg( optionsUninstall ); |
|
214 iInstaller.SilentUninstall( iStatus, iUid, |
|
215 uninstallOptionsPkg, *iMime ); |
|
216 |
|
217 aData->VisualizeUninstallL(); |
|
218 SetActive(); |
|
219 } |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------- |
|
223 // CWmInstaller::Uid |
|
224 // --------------------------------------------------------- |
|
225 // |
|
226 TUid CWmInstaller::UninstallUid() |
|
227 { |
|
228 if ( IsActive() ) |
|
229 { |
|
230 return iUid; |
|
231 } |
|
232 else |
|
233 { |
|
234 return KNullUid; |
|
235 } |
|
236 } |