25 #include <AknBidiTextUtils.h> |
25 #include <AknBidiTextUtils.h> |
26 #include <AknsFrameBackgroundControlContext.h> |
26 #include <AknsFrameBackgroundControlContext.h> |
27 #include <gulicon.h> |
27 #include <gulicon.h> |
28 #include <avkon.mbg> |
28 #include <avkon.mbg> |
29 #include <widgetmanager.mbg> |
29 #include <widgetmanager.mbg> |
|
30 #include <apgcli.h> |
|
31 #include <apgtask.h> |
|
32 #include <widgetregistryclient.h> // widgetreqistry |
|
33 |
30 |
34 |
31 #include "wmportalbutton.h" |
35 #include "wmportalbutton.h" |
32 #include "wmcommon.h" |
36 #include "wmcommon.h" |
33 #include "wmplugin.h" |
37 #include "wmplugin.h" |
34 #include "wmresourceloader.h" |
38 #include "wmresourceloader.h" |
35 #include "wmmaincontainer.h" |
39 #include "wmmaincontainer.h" |
|
40 #include "wmconfiguration.h" |
|
41 |
|
42 // CONSTANTS |
|
43 _LIT( KBrowserPrefix, "4 "); |
36 |
44 |
37 // MEMBER FUNCTIONS |
45 // MEMBER FUNCTIONS |
38 |
46 |
39 // --------------------------------------------------------- |
47 // --------------------------------------------------------- |
40 // CWmPortalButton::NewL |
48 // CWmPortalButton::NewL |
41 // --------------------------------------------------------- |
49 // --------------------------------------------------------- |
42 // |
50 // |
43 CWmPortalButton* CWmPortalButton::NewL( |
51 CWmPortalButton* CWmPortalButton::NewL( |
44 const CCoeControl* aParent, |
52 const CCoeControl* aParent, |
45 const TDesC& aText, |
53 TInt aPortalButtonIndex ) |
46 const TDesC& aUrl, |
|
47 TWmUiControlIds aButtonCtrlId ) |
|
48 { |
54 { |
49 CWmPortalButton* self = new (ELeave) CWmPortalButton( |
55 CWmPortalButton* self = new (ELeave) CWmPortalButton( |
50 KAknButtonTextInsideFrame, aButtonCtrlId ); |
56 KAknButtonTextInsideFrame, aPortalButtonIndex ); |
51 CleanupStack::PushL( self ); |
57 |
52 self->ConstructL( aParent,aText, aUrl ); |
58 CleanupStack::PushL( self ); |
|
59 |
|
60 CWmMainContainer* mainContainer = |
|
61 static_cast <CWmMainContainer*>( |
|
62 const_cast <CCoeControl*>( aParent ) ); |
|
63 |
|
64 self->ConstructL( mainContainer, |
|
65 mainContainer->Configuration().PortalButtonText( aPortalButtonIndex ), |
|
66 mainContainer->Configuration().PortalButtonIcon( aPortalButtonIndex ) ); |
|
67 |
53 CleanupStack::Pop( self ); |
68 CleanupStack::Pop( self ); |
54 return self; |
69 return self; |
55 } |
70 } |
56 |
71 |
57 // --------------------------------------------------------- |
72 // --------------------------------------------------------- |
58 // CWmPortalButton::~CWmPortalButton |
73 // CWmPortalButton::~CWmPortalButton |
59 // --------------------------------------------------------- |
74 // --------------------------------------------------------- |
60 // |
75 // |
61 CWmPortalButton::~CWmPortalButton() |
76 CWmPortalButton::~CWmPortalButton() |
62 { |
77 { |
63 delete iText; |
78 delete iButtonIcon; |
64 delete iUrl; |
79 delete iButtonIconMask; |
|
80 |
|
81 // if MAknIconFileProvider was used to create image from icon string |
|
82 // then it'll try accessing imageconverter after bitmap deletion |
|
83 // for de-reference open file count, so it should be deleted last. |
65 delete iImageConverter; |
84 delete iImageConverter; |
66 } |
85 } |
67 |
86 |
68 // --------------------------------------------------------- |
87 // --------------------------------------------------------- |
69 // CWmPortalButton::CWmPortalButton |
88 // CWmPortalButton::CWmPortalButton |
70 // --------------------------------------------------------- |
89 // --------------------------------------------------------- |
71 // |
90 // |
72 CWmPortalButton::CWmPortalButton( |
91 CWmPortalButton::CWmPortalButton( |
73 const TInt aFlags, |
92 const TInt aFlags, |
74 TWmUiControlIds aButtonCtrlId ) |
93 TInt aPortalButtonIndex ) |
75 :CAknButton( aFlags ), |
94 :CAknButton( aFlags ), |
76 iButtonCtrlId( aButtonCtrlId ) |
95 iPortalButtonIndex( aPortalButtonIndex ) |
77 { |
96 { |
|
97 iButtonIcon = NULL; |
|
98 iButtonIconMask = NULL; |
78 } |
99 } |
79 |
100 |
80 // --------------------------------------------------------- |
101 // --------------------------------------------------------- |
81 // CWmPortalButton::ConstructL |
102 // CWmPortalButton::ConstructL |
82 // --------------------------------------------------------- |
103 // --------------------------------------------------------- |
83 // |
104 // |
84 void CWmPortalButton::ConstructL( |
105 void CWmPortalButton::ConstructL( |
85 const CCoeControl* aParent, |
106 CWmMainContainer* aParent, |
86 const TDesC& aText, const TDesC& aUrl ) |
107 const TDesC& aText, |
|
108 const TDesC& aIcon ) |
87 { |
109 { |
88 if ( !aParent ) |
110 if ( !aParent ) |
89 { |
111 { |
90 User::Leave( KErrArgument ); |
112 User::Leave( KErrArgument ); |
91 } |
113 } |
92 else if ( iButtonCtrlId != EOviPortal ) |
114 else if ( iPortalButtonIndex != 0 ) |
93 { |
115 { |
94 // operator button not supported until layout available. |
116 // operator button not supported until layout available. |
95 User::Leave( KErrNotSupported ); |
117 User::Leave( KErrNotSupported ); |
96 } |
118 } |
97 |
119 |
98 SetContainerWindowL( *aParent ); |
120 SetContainerWindowL( *aParent ); |
99 |
121 |
100 // Obtain pointer to main container. |
122 // Obtain pointer to main container. |
101 iWmMainContainer = |
123 iWmMainContainer = aParent; |
102 static_cast <CWmMainContainer*>( |
124 |
103 const_cast <CCoeControl*>( aParent ) ); |
125 // construct the button |
104 |
126 CAknButton::ConstructL( NULL, NULL, NULL, NULL, aText, KNullDesC, 0 ); |
105 CGulIcon* icon = AknsUtils::CreateGulIconL( |
127 |
106 AknsUtils::SkinInstance(), KAknsIIDQgnMenuOviStore, |
128 TAknsItemID frameId = KAknsIIDQgnHomeWmButton; |
107 iWmMainContainer->WmPlugin().ResourceLoader().IconFilePath(), |
129 TAknsItemID frameCenterId = KAknsIIDQgnHomeWmButtonCenter; |
108 EMbmWidgetmanagerQgn_menu_ovistore, |
130 TAknsItemID framePressedId = KAknsIIDQgnHomeWmButtonPressed; |
109 EMbmWidgetmanagerQgn_menu_ovistore_mask ); |
131 TAknsItemID framePressedCenterId = KAknsIIDQgnHomeWmButtonPressedCenter; |
110 |
|
111 CleanupStack::PushL( icon ); |
|
112 CAknButton::ConstructL( icon, NULL, NULL, NULL, |
|
113 aText, KNullDesC, 0 ); |
|
114 CleanupStack::Pop( icon ); // ownership taken |
|
115 |
|
116 TAknsItemID frameId = ((iButtonCtrlId == EOviPortal) ? |
|
117 KAknsIIDQgnHomeWmButton : KAknsIIDQsnFrButtonNormal); |
|
118 TAknsItemID frameCenterId = ((iButtonCtrlId == EOviPortal) ? |
|
119 KAknsIIDQgnHomeWmButtonCenter : KAknsIIDQsnFrButtonCenterNormal ); |
|
120 TAknsItemID framePressedId = ((iButtonCtrlId == EOviPortal) ? |
|
121 KAknsIIDQgnHomeWmButtonPressed : KAknsIIDQsnFrButtonPressed ); |
|
122 TAknsItemID framePressedCenterId = ((iButtonCtrlId == EOviPortal) ? |
|
123 KAknsIIDQgnHomeWmButtonPressedCenter : KAknsIIDQsnFrButtonCenterPressed ); |
|
124 |
|
125 iText = aText.AllocL(); |
|
126 iUrl = aUrl.AllocL(); |
|
127 |
132 |
128 SetFocusing( ETrue ); |
133 SetFocusing( ETrue ); |
129 SetBackgroundIds( frameId, |
134 SetBackgroundIds( frameId, |
130 framePressedId, |
135 framePressedId, |
131 KAknsIIDQsnFrButtonInactive, |
136 KAknsIIDQsnFrButtonInactive, |
141 framePressedId, |
146 framePressedId, |
142 framePressedCenterId, |
147 framePressedCenterId, |
143 KAknsIIDDefault, |
148 KAknsIIDDefault, |
144 KAknsIIDDefault ); |
149 KAknsIIDDefault ); |
145 |
150 |
|
151 // start image converter for the icon |
|
152 iImageConverter = CWmImageConverter::NewL( this ); |
|
153 TSize iconsize( LayoutIconSize() ); |
|
154 iImageConverter->HandleIconString( |
|
155 iconsize.iWidth, iconsize.iHeight, aIcon ); |
|
156 // observe our own press events |
|
157 SetObserver( this ); |
|
158 |
146 // ready to be drawn |
159 // ready to be drawn |
147 ActivateL(); |
160 ActivateL(); |
148 } |
161 } |
149 |
162 |
150 // --------------------------------------------------------- |
163 // --------------------------------------------------------------------------- |
151 // CWmPortalButton::HandlePointerEventL |
164 // Runs HTTP method: (starts browser or brongs browser to foreground) |
152 // --------------------------------------------------------- |
165 // --------------------------------------------------------------------------- |
153 // |
166 // |
154 void CWmPortalButton::HandlePointerEventL( |
167 void TryRunHttpL( const TDesC& aParam ) |
155 const TPointerEvent& aPointerEvent ) |
168 { |
156 { |
169 RApaLsSession session; |
157 CAknButton::HandlePointerEventL( aPointerEvent); |
170 User::LeaveIfError( session.Connect() ); |
158 |
171 CleanupClosePushL( session ); |
159 if ( AknLayoutUtils::PenEnabled() ) |
172 |
160 { |
173 // browser start parameters |
161 switch ( aPointerEvent.iType ) |
174 const TUid KOSSBrowserUidValue = { 0x10008D39 }; |
|
175 HBufC* param = HBufC::NewLC( aParam.Length() + |
|
176 KBrowserPrefix().Length() ); |
|
177 |
|
178 param->Des().Copy( KBrowserPrefix ); |
|
179 param->Des().Append( aParam ); |
|
180 |
|
181 TUid id( KOSSBrowserUidValue ); |
|
182 |
|
183 TApaTaskList taskList( CEikonEnv::Static()->WsSession() ); |
|
184 TApaTask task = taskList.FindApp( id ); |
|
185 if( task.Exists() ) |
|
186 { |
|
187 task.BringToForeground(); |
|
188 HBufC8* param8 = HBufC8::NewLC(param->Length()); |
|
189 param8->Des().Append(*param); |
|
190 task.SendMessage(TUid::Uid(0), *param8); // UID not used |
|
191 CleanupStack::PopAndDestroy(param8); |
|
192 } |
|
193 else |
|
194 { |
|
195 if( !session.Handle() ) |
162 { |
196 { |
163 case TPointerEvent::EButton1Down: |
197 User::LeaveIfError( session.Connect() ); |
164 { |
|
165 break; |
|
166 } |
|
167 case TPointerEvent::EButton1Up: |
|
168 { |
|
169 if ( iWmMainContainer && |
|
170 iButtonCtrlId == EOviPortal ) |
|
171 { |
|
172 iWmMainContainer->OpenOviPortalL(); |
|
173 } |
|
174 break; |
|
175 } |
|
176 default: |
|
177 break; |
|
178 } |
198 } |
179 } |
199 TThreadId thread; |
180 } |
200 User::LeaveIfError(session.StartDocument(*param, KOSSBrowserUidValue, thread)); |
181 |
201 } |
182 // --------------------------------------------------------- |
202 |
183 // CWmPortalButton::OfferKeyEventL |
203 CleanupStack::PopAndDestroy( param ); |
184 // --------------------------------------------------------- |
204 CleanupStack::PopAndDestroy( &session ); |
185 // |
205 } |
186 TKeyResponse CWmPortalButton::OfferKeyEventL( |
206 |
187 const TKeyEvent& aKeyEvent, |
207 // --------------------------------------------------------------------------- |
188 TEventCode aType ) |
208 // Runs WIDGET method: (launches given widget with parameters) |
189 { |
209 // --------------------------------------------------------------------------- |
190 TKeyResponse keyResponse( EKeyWasNotConsumed ); |
210 // |
191 keyResponse = CAknButton::OfferKeyEventL( aKeyEvent, aType ); |
211 void TryRunWidgetL( const TDesC& aParam, const TDesC& aBundleId ) |
192 |
212 { |
193 if ( ( aType == EEventKey ) && |
213 RApaLsSession session; |
194 ( aKeyEvent.iScanCode == EStdKeyDevice3 || |
214 User::LeaveIfError( session.Connect() ); |
195 aKeyEvent.iScanCode == EStdKeyEnter ) ) |
215 CleanupClosePushL( session ); |
196 { |
216 TApaAppInfo appInfo; |
197 if ( iWmMainContainer && |
217 TUid launchUid; |
198 iButtonCtrlId == EOviPortal ) |
218 |
199 { |
219 // Get widget uid |
200 iWmMainContainer->OpenOviPortalL(); |
220 RWidgetRegistryClientSession widgetSession; |
201 } |
221 User::LeaveIfError( widgetSession.Connect() ); |
202 |
222 CleanupClosePushL( widgetSession ); |
203 keyResponse = EKeyWasConsumed; |
223 launchUid.iUid = widgetSession.GetWidgetUidL( aBundleId ); |
204 } |
224 CleanupStack::PopAndDestroy( &widgetSession ); |
205 |
225 |
206 return keyResponse; |
226 // prepare widget start params |
|
227 User::LeaveIfError( session.GetAppInfo( appInfo, launchUid ) ); |
|
228 CApaCommandLine* commandLine = CApaCommandLine::NewLC(); |
|
229 commandLine->SetExecutableNameL( appInfo.iFullName ); |
|
230 HBufC8* buf8 = HBufC8::NewLC( aParam.Length() ); |
|
231 buf8->Des().Copy( aParam ); |
|
232 |
|
233 // do the launch |
|
234 commandLine->SetTailEndL( *buf8 ); |
|
235 User::LeaveIfError( session.StartApp( *commandLine ) ); |
|
236 |
|
237 CleanupStack::PopAndDestroy( buf8 ); |
|
238 CleanupStack::PopAndDestroy( commandLine ); |
|
239 CleanupStack::PopAndDestroy( &session ); |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // Tries to open a portal with given method and parameters. |
|
244 // this method may be called twice on a portal button, if a primary |
|
245 // method fails. |
|
246 // --------------------------------------------------------------------------- |
|
247 // |
|
248 void TryOpenPortalL( |
|
249 CWmConfiguration::TMethod aMethod, const TDesC& aParam, |
|
250 const TDesC& aBundleId ) |
|
251 { |
|
252 // open portal according to the method. |
|
253 if ( aMethod == CWmConfiguration::EHttp ) |
|
254 { TryRunHttpL( aParam ); } |
|
255 else if ( aMethod == CWmConfiguration::EWidget ) |
|
256 { TryRunWidgetL( aParam, aBundleId ); } |
|
257 else |
|
258 { /* do nothing */ } |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // Opens a portal. Called when user presses a portal button. tries the |
|
263 // primary method, and if if fails, tries the secondary. If it fails, |
|
264 // gives up. |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void OpenPortalL( |
|
268 CWmConfiguration& aConfiguration, TInt aPortalIndex ) |
|
269 { |
|
270 TRAPD( err, |
|
271 TryOpenPortalL( |
|
272 aConfiguration.PortalButtonPrimaryMethod( aPortalIndex ), |
|
273 aConfiguration.PortalButtonPrimaryParams( aPortalIndex ), |
|
274 aConfiguration.PortalButtonBundleId( aPortalIndex ) ); ); |
|
275 if ( err != KErrNone ) |
|
276 { |
|
277 // if secondary method fails, leave will be propagated. |
|
278 TryOpenPortalL( |
|
279 aConfiguration.PortalButtonSecondaryMethod( aPortalIndex ), |
|
280 aConfiguration.PortalButtonSecondaryParams( aPortalIndex ), |
|
281 aConfiguration.PortalButtonBundleId( aPortalIndex ) ); |
|
282 } |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------- |
|
286 // CWmPortalButton::ExecuteL |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 void CWmPortalButton::ExecuteL() |
|
290 { |
|
291 OpenPortalL( iWmMainContainer->Configuration(), iPortalButtonIndex ); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // CWmPortalButton::HandleControlEventL |
|
296 // --------------------------------------------------------- |
|
297 // |
|
298 void CWmPortalButton::HandleControlEventL( CCoeControl* /*aControl*/, |
|
299 TCoeEvent aEventType ) |
|
300 { |
|
301 // execute portal action when button pressed (short or long press) |
|
302 if ( aEventType == EEventStateChanged || |
|
303 aEventType == ELongPressEndedEvent ) |
|
304 { |
|
305 ExecuteL(); |
|
306 } |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------- |
|
310 // CWmPortalButton::LayoutIconSize |
|
311 // --------------------------------------------------------- |
|
312 // |
|
313 TSize CWmPortalButton::LayoutIconSize() const |
|
314 { |
|
315 TBool landscape = Layout_Meta_Data::IsLandscapeOrientation(); |
|
316 TAknLayoutRect imageLayout; |
|
317 imageLayout.LayoutRect( Rect(), |
|
318 AknLayoutScalable_Apps::wgtman_btn_pane_g1( |
|
319 landscape ? 1 : 0).LayoutLine() ); |
|
320 return imageLayout.Rect().Size(); |
207 } |
321 } |
208 |
322 |
209 // --------------------------------------------------------- |
323 // --------------------------------------------------------- |
210 // CWmPortalButton::SizeChanged |
324 // CWmPortalButton::SizeChanged |
211 // --------------------------------------------------------- |
325 // --------------------------------------------------------- |
212 // |
326 // |
213 void CWmPortalButton::SizeChanged() |
327 void CWmPortalButton::SizeChanged() |
214 { |
328 { |
215 CAknButton::SizeChanged(); |
329 CAknButton::SizeChanged(); |
216 |
330 |
|
331 SetTextVerticalAlignment( CAknButton::ECenter ); |
|
332 |
|
333 // resize icon |
|
334 if ( iButtonIcon && iButtonIconMask ) |
|
335 { |
|
336 TSize size = LayoutIconSize(); |
|
337 AknIconUtils::SetSize( |
|
338 iButtonIcon, size, EAspectRatioPreserved ); |
|
339 AknIconUtils::SetSize( |
|
340 iButtonIconMask, size, EAspectRatioPreserved ); |
|
341 } |
|
342 |
217 TBool landscape = Layout_Meta_Data::IsLandscapeOrientation(); |
343 TBool landscape = Layout_Meta_Data::IsLandscapeOrientation(); |
218 TRect rect = Rect(); |
|
219 TAknLayoutRect imageLayout; |
|
220 if ( iButtonCtrlId == EOviPortal ) |
|
221 { |
|
222 imageLayout.LayoutRect( rect, |
|
223 AknLayoutScalable_Apps::wgtman_btn_pane_g1( |
|
224 landscape ? 1 : 0).LayoutLine() ); |
|
225 } |
|
226 SetTextVerticalAlignment( CAknButton::ECenter ); |
|
227 SetIconSize( imageLayout.Rect().Size() ); |
|
228 SetTextAndIconAlignment( |
344 SetTextAndIconAlignment( |
229 landscape ? CAknButton::EIconOverText : CAknButton::EIconBeforeText ); |
345 landscape ? CAknButton::EIconOverText : CAknButton::EIconBeforeText ); |
230 } |
346 } |
231 |
347 |
232 // --------------------------------------------------------- |
348 // --------------------------------------------------------- |
233 // CWmPortalButton::NotifyCompletion |
349 // CWmPortalButton::NotifyCompletion |
234 // --------------------------------------------------------- |
350 // --------------------------------------------------------- |
235 // |
351 // |
236 void CWmPortalButton::NotifyCompletion( TInt aError ) |
352 void CWmPortalButton::NotifyCompletion( TInt aError ) |
237 { |
353 { |
238 if ( KErrNone != aError ) |
354 if ( KErrNone == aError ) |
239 { |
355 { |
240 // no image available. Do nothing. |
356 // take ownership of icon |
241 } |
357 delete iButtonIcon; |
242 else |
358 iButtonIcon = NULL; |
243 { |
359 iButtonIcon = iImageConverter->Bitmap(); |
244 CGulIcon* icon = NULL; |
360 delete iButtonIconMask; |
245 TRAPD( err, icon = CGulIcon::NewL( |
361 iButtonIconMask = NULL; |
246 iImageConverter->Bitmap(), iImageConverter->Mask() ) ); |
362 iButtonIconMask = iImageConverter->Mask(); |
247 if ( KErrNone == err && icon ) |
363 if ( iButtonIcon && iButtonIconMask ) |
248 { |
364 { |
249 // Ownership transfered |
365 TSize size = LayoutIconSize(); |
250 State()->SetIcon( icon ); |
366 AknIconUtils::SetSize( |
|
367 iButtonIcon, size, EAspectRatioPreserved ); |
|
368 AknIconUtils::SetSize( |
|
369 iButtonIconMask, size, EAspectRatioPreserved ); |
251 DrawDeferred(); |
370 DrawDeferred(); |
252 } |
371 } |
|
372 } |
|
373 else |
|
374 { |
|
375 // no image available. Do nothing. |
253 } |
376 } |
254 } |
377 } |
255 |
378 |
256 // --------------------------------------------------------- |
379 // --------------------------------------------------------- |
257 // CWmPortalButton::Draw |
380 // CWmPortalButton::Draw |