|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Choice list. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknLayout2ScalableDef.h> |
|
20 #include <aipropertyextension.h> |
|
21 |
|
22 #include "aistrcnv.h" |
|
23 #include "aistatuspanetouchui.h" |
|
24 #include "aistatuspanel.h" |
|
25 #include "ainativeuiplugins.h" |
|
26 #include "aifweventhandler.h" |
|
27 #include "aiconsts.h" |
|
28 #include "aidevicestatuscontentmodel.h" |
|
29 #include <aknstyluspopupmenu.h> |
|
30 |
|
31 #include <AiNativeUi.rsg> |
|
32 #include <AknUtils.h> |
|
33 #include <aknnavide.h> |
|
34 #include <akntitle.h> |
|
35 #include <MProfileEngine.h> |
|
36 #include <viewcli.h> |
|
37 #include <aknlayoutscalable_avkon.cdl.h> |
|
38 |
|
39 #ifdef RD_TACTILE_FEEDBACK |
|
40 #include <touchfeedback.h> |
|
41 #endif |
|
42 |
|
43 using namespace AiNativeUiController; |
|
44 |
|
45 _LIT( KProfileSwitchByIndexEvent, "Profile/SwitchProfileByIndex" ); |
|
46 const TInt KProfileSwitchByIndexEventLength = 28; |
|
47 const TInt KRadix = 10; |
|
48 const TText16 KEventParameterTerminator = ')'; |
|
49 const TInt KExtraItems = 2; |
|
50 const TInt KStylusMenuMaxItemsDefault = 0; |
|
51 |
|
52 _LIT( KOpenAppProfiles, "Shortcut/LaunchByValue(localapp:0x100058F8)" ); |
|
53 _LIT( KOpenAppCalendar, "Shortcut/LaunchByValue(localapp:0x10005901)" ); |
|
54 |
|
55 static TInt IndexLength( TInt aIndex ) |
|
56 { |
|
57 TInt length = 0; |
|
58 |
|
59 if ( aIndex < 0 ) |
|
60 { |
|
61 ++length; |
|
62 } |
|
63 |
|
64 do |
|
65 { |
|
66 aIndex /= KRadix; |
|
67 ++length; |
|
68 } |
|
69 while ( aIndex != 0 ); |
|
70 return length; |
|
71 } |
|
72 |
|
73 // ======== MEMBER FUNCTIONS ======== |
|
74 |
|
75 |
|
76 CAiStatusPaneTouchUi* CAiStatusPaneTouchUi::NewL( CAiStatusPanel& aStatusPanel, |
|
77 MAiFwEventHandler& aEventHandler ) |
|
78 { |
|
79 CAiStatusPaneTouchUi* self = CAiStatusPaneTouchUi::NewLC( aStatusPanel, aEventHandler ); |
|
80 CleanupStack::Pop( self ); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 CAiStatusPaneTouchUi* CAiStatusPaneTouchUi::NewLC( CAiStatusPanel& aStatusPanel, |
|
86 MAiFwEventHandler& aEventHandler ) |
|
87 { |
|
88 CAiStatusPaneTouchUi* self = new (ELeave) CAiStatusPaneTouchUi( aStatusPanel, aEventHandler ); |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL(); |
|
91 |
|
92 return self; |
|
93 } |
|
94 |
|
95 CAiStatusPaneTouchUi::CAiStatusPaneTouchUi( CAiStatusPanel& aStatusPanel, |
|
96 MAiFwEventHandler& aEventHandler ) |
|
97 : |
|
98 iStatusPane( aStatusPanel ), |
|
99 iEventHandler( aEventHandler ) |
|
100 { |
|
101 // no implementation required |
|
102 } |
|
103 |
|
104 CAiStatusPaneTouchUi::~CAiStatusPaneTouchUi() |
|
105 { |
|
106 delete iEventBuffer; |
|
107 delete iMenu; |
|
108 iProfileNamePointerArray.ResetAndDestroy(); |
|
109 } |
|
110 |
|
111 void CAiStatusPaneTouchUi::ConstructL() |
|
112 { |
|
113 if( AknLayoutUtils::PenEnabled() ) |
|
114 { |
|
115 iStatusPane.SetNaviDecoratorObserver( this ); |
|
116 } |
|
117 } |
|
118 |
|
119 void CAiStatusPaneTouchUi::LoadUIDefinitionL() |
|
120 { |
|
121 // If profile popup exists, for example, when screendevicechange occurs, |
|
122 // the popup is closed |
|
123 if( iMenu ) |
|
124 { |
|
125 delete iMenu; |
|
126 iMenu = NULL; |
|
127 } |
|
128 } |
|
129 |
|
130 void CAiStatusPaneTouchUi::ProcessCommandL( TInt aCommandId ) |
|
131 { |
|
132 if( aCommandId == EAIGotoCalendarCmdLink ) |
|
133 { |
|
134 //Open calendar application |
|
135 iEventHandler.HandlePluginEvent( KOpenAppCalendar ); |
|
136 } |
|
137 else if( aCommandId == EAIShowAllProfileCmdLink ) |
|
138 { |
|
139 //Open profile application |
|
140 iEventHandler.HandlePluginEvent( KOpenAppProfiles ); |
|
141 } |
|
142 else |
|
143 { |
|
144 |
|
145 // Calculate event buffer length |
|
146 TInt length = KProfileSwitchByIndexEventLength |
|
147 + KPluginEventSeparatorLength |
|
148 + IndexLength( aCommandId - EAIProfileCmdLink ) |
|
149 + KEventParameterSeparatorLength; |
|
150 |
|
151 // Allocate event buffer |
|
152 TPtr event = AiUtility::EnsureBufMaxLengthL( iEventBuffer, length ); |
|
153 |
|
154 // Create event string |
|
155 event.Zero(); |
|
156 event.Append( KProfileSwitchByIndexEvent ); |
|
157 event.Append( KEventParameterSeparator ); |
|
158 event.AppendNum( aCommandId - EAIProfileCmdLink ); |
|
159 event.Append( KEventParameterTerminator ); |
|
160 |
|
161 iEventHandler.HandlePluginEvent( event ); |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 void CAiStatusPaneTouchUi::HandleNaviDecoratorEventL( TInt aEventID ) |
|
168 { |
|
169 if( aEventID == EAknNaviDecoratorEventNaviLabel ) |
|
170 { |
|
171 #ifdef RD_TACTILE_FEEDBACK |
|
172 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
173 if ( feedback ) |
|
174 { |
|
175 feedback->InstantFeedback( ETouchFeedbackBasic ); |
|
176 } |
|
177 #endif |
|
178 |
|
179 TBool isShowAllProfilesItem = EFalse; |
|
180 TInt count = iProfileNamePointerArray.Count(); |
|
181 |
|
182 if ( !count ) |
|
183 { |
|
184 //profile plugin is not ready! |
|
185 return; |
|
186 } |
|
187 |
|
188 TInt aiStylusMenuMaxItems = KStylusMenuMaxItemsDefault; |
|
189 TPoint tapPoint(0,0); |
|
190 TRect clientRect; |
|
191 TRect naviRect; |
|
192 |
|
193 // Check screen sizes |
|
194 TInt isMainPane = AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect ); |
|
195 TInt isNaviPane = AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ENaviPane, naviRect ); |
|
196 |
|
197 // Calculating how many items fits into menu, using font height |
|
198 TAknLayoutText layoutText; |
|
199 layoutText.LayoutText( naviRect, |
|
200 AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine()); |
|
201 |
|
202 TInt txtHeight = layoutText.Font()->HeightInPixels(); |
|
203 // More additional space for marginals |
|
204 txtHeight += txtHeight + txtHeight/2; |
|
205 |
|
206 if( isNaviPane ) |
|
207 { |
|
208 if ( AknLayoutUtils::LayoutMirrored() ) |
|
209 { |
|
210 tapPoint.SetXY( naviRect.iBr.iX, naviRect.iBr.iY ); |
|
211 } |
|
212 else |
|
213 { |
|
214 tapPoint.SetXY( naviRect.iTl.iX, naviRect.iBr.iY ); |
|
215 } |
|
216 } |
|
217 |
|
218 if ( iMenu ) |
|
219 { |
|
220 delete iMenu; |
|
221 iMenu = NULL; |
|
222 } |
|
223 |
|
224 iMenu = CAknStylusPopUpMenu::NewL( this, tapPoint ); |
|
225 |
|
226 if( isMainPane ) |
|
227 { |
|
228 // Count how many menu items would fit into screen |
|
229 aiStylusMenuMaxItems = clientRect.Height() / txtHeight; |
|
230 } |
|
231 |
|
232 HBufC* caleText = StringLoader::LoadLC( R_IDLE_NAVI_TAPPED_CALE ); |
|
233 iMenu->AddMenuItemL( *caleText, EAIGotoCalendarCmdLink ); |
|
234 CleanupStack::PopAndDestroy( caleText ); |
|
235 count++; |
|
236 |
|
237 // Space for 2 extra items GotoCalendar and ShowAllProfiles |
|
238 if( count > aiStylusMenuMaxItems ) |
|
239 { |
|
240 count = aiStylusMenuMaxItems - KExtraItems; |
|
241 isShowAllProfilesItem = ETrue; |
|
242 } |
|
243 else |
|
244 { |
|
245 count -= 1; |
|
246 } |
|
247 |
|
248 for( TInt i = 0; i < count; i++ ) |
|
249 { |
|
250 iMenu->AddMenuItemL( iProfileNamePointerArray[i]->Des(), i + EAIProfileCmdLink ); |
|
251 } |
|
252 |
|
253 if( isShowAllProfilesItem ) |
|
254 { |
|
255 HBufC* allProfilesText = StringLoader::LoadLC( R_IDLE_NAVI_TAPPED_ALL_PROF ); |
|
256 iMenu->AddMenuItemL( *allProfilesText, EAIShowAllProfileCmdLink ); |
|
257 CleanupStack::PopAndDestroy( allProfilesText ); |
|
258 } |
|
259 |
|
260 iMenu->ShowMenu(); |
|
261 } |
|
262 } |
|
263 |
|
264 |
|
265 void CAiStatusPaneTouchUi::DoPublishL( MAiPropertyExtension& aPlugin, |
|
266 TInt aContent, |
|
267 const TDesC16& aText, |
|
268 TInt aIndex ) |
|
269 { |
|
270 if( aPlugin.PublisherInfoL()->iUid == KProfilePluginUid ) |
|
271 { |
|
272 switch( aContent ) |
|
273 { |
|
274 case EAiProfileContentProfileName: |
|
275 { |
|
276 if( aIndex - 1 == 0 ) |
|
277 { |
|
278 iProfileNamePointerArray.ResetAndDestroy(); |
|
279 } |
|
280 |
|
281 TInt count = iProfileNamePointerArray.Count(); |
|
282 |
|
283 if( count >= aIndex ) |
|
284 { |
|
285 delete iProfileNamePointerArray[ aIndex - 1 ]; |
|
286 iProfileNamePointerArray.Remove( aIndex - 1); |
|
287 } |
|
288 |
|
289 HBufC* name = aText.AllocL(); |
|
290 iProfileNamePointerArray.Insert( name, aIndex - 1 ); |
|
291 break; |
|
292 } |
|
293 default: |
|
294 { |
|
295 break; |
|
296 } |
|
297 }; |
|
298 } |
|
299 |
|
300 else |
|
301 { |
|
302 User::Leave( KErrNotFound ); |
|
303 } |
|
304 } |
|
305 |
|
306 void CAiStatusPaneTouchUi::SetEmphasis( CCoeControl* /*aMenuControl*/, TBool /*aEmphasis*/ ) |
|
307 { |
|
308 } |
|
309 |
|
310 |