|
1 /* |
|
2 * Copyright (c) 2005-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: View for Shortcuts sub-folder |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <bautils.h> |
|
20 #include <eikmenup.h> |
|
21 #include <featmgr.h> |
|
22 #include <gsaccessoryplugin.rsg> |
|
23 #include <gsaccplugin.mbg> |
|
24 #include <gscommon.hrh> |
|
25 #include <gsfwviewuids.h> |
|
26 #include <gsprivatepluginproviderids.h> |
|
27 #include <hlplch.h> // For HlpLauncher |
|
28 #include <StringLoader.h> |
|
29 |
|
30 #include "acclocalviewids.h" |
|
31 #include "gsaccessoryplugin.h" |
|
32 #include "gsaccessoryplugin.hrh" |
|
33 #include "gsaccessorypluginconst.hrh" |
|
34 #include "gsaccessoryplugincontainer.h" |
|
35 #include "gsaccessorypluginmodel.h" |
|
36 #include "gsacchacview.h" |
|
37 #include "gsaccheadphonesview.h" |
|
38 #include "gsaccheadsetview.h" |
|
39 #include "gsaccloopsetview.h" |
|
40 #include "gsaccmusicstandview.h" |
|
41 #include "gsacctextphoneview.h" |
|
42 #include "gsacctvoutview.h" |
|
43 #include "gsaccwiredcarkitview.h" |
|
44 #include "gsaccwirelesscarkitview.h" |
|
45 #include "trace.h" |
|
46 |
|
47 // LOCAL CONSTANTS AND MACROS |
|
48 _LIT( KGSAccessoryPluginResourceFileName, "z:gsaccessoryplugin.rsc" ); |
|
49 |
|
50 #ifdef __SCALABLE_ICONS |
|
51 _LIT( KGSAccPluginIconFileName, "\\resource\\apps\\gsaccplugin.mif" ); // svg file |
|
52 #else //__SCALABLE_ICONS |
|
53 _LIT( KGSAccPluginIconFileName, "\\resource\\apps\\gsaccplugin.mbm" ); // bitmap |
|
54 #endif //__SCALABLE_ICONS |
|
55 |
|
56 // ========================= LOCAL FUNCTIONS ================================ |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // ListIdToViewId |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 static TUid ListIdToViewId( TInt aListId ) |
|
63 { |
|
64 switch ( aListId ) |
|
65 { |
|
66 case EGSHACListItemId: return KAccHACViewId; |
|
67 case EGSHeadphonesListItemId: return KAccHeadphonesViewId; |
|
68 case EGSHeadsetListItemId: return KAccHeadsetViewId; |
|
69 case EGSLoopsetListItemId: return KAccLoopsetViewId; |
|
70 case EGSMusicStandListItemId: return KAccMusicStandViewId; |
|
71 case EGSTextPhoneListItemId: return KAccTextPhoneViewId; |
|
72 case EGSTvOutListItemId: return KAccTvoutViewId; |
|
73 case EGSWiredCarKitListItemId: return KAccWiredCarkitViewId; |
|
74 case EGSWirelessCarKitListItemId: return KAccWirelessCarkitViewId; |
|
75 default: |
|
76 break; |
|
77 } |
|
78 |
|
79 return TUid::Null(); |
|
80 } |
|
81 |
|
82 |
|
83 // ========================= MEMBER FUNCTIONS ================================ |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CGSAccessoryPlugin::NewL() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CGSAccessoryPlugin* CGSAccessoryPlugin::NewL( TAny* /*aInitParams*/ ) |
|
90 { |
|
91 CGSAccessoryPlugin* self = new( ELeave ) CGSAccessoryPlugin(); |
|
92 CleanupStack::PushL( self ); |
|
93 self->ConstructL(); |
|
94 CleanupStack::Pop( self ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CGSAccessoryPlugin::~CGSAccessoryPlugin |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 CGSAccessoryPlugin::~CGSAccessoryPlugin() |
|
104 { |
|
105 FUNC_LOG; |
|
106 |
|
107 // Do not call RemoveLocalViews(), iAppUi has already been deleted. |
|
108 iSubViewIds.Close(); |
|
109 delete iModel; |
|
110 iResourceLoader.Close(); |
|
111 FeatureManager::UnInitializeLib(); |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CGSAccessoryPlugin::NewContainerL() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CGSAccessoryPlugin::NewContainerL() |
|
120 { |
|
121 FUNC_LOG; |
|
122 |
|
123 iContainer = new( ELeave ) CGSAccessoryPluginContainer( *iModel ); |
|
124 } |
|
125 |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CGSAccessoryPlugin::HandleListBoxSelectionL() |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CGSAccessoryPlugin::HandleListBoxSelectionL() |
|
132 { |
|
133 FUNC_LOG; |
|
134 |
|
135 iRockerPress = ETrue; |
|
136 TRAPD( error, SelectLocalViewL() ); |
|
137 ERROR( error, "Failed to select local view" ); |
|
138 iRockerPress = EFalse; |
|
139 User::LeaveIfError( error ); |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CGSAccessoryPlugin::GetCaption |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CGSAccessoryPlugin::GetCaptionL( TDes& aCaption ) const |
|
148 { |
|
149 FUNC_LOG; |
|
150 |
|
151 // The resource file is already opened. |
|
152 HBufC* result = StringLoader::LoadL( R_ACC_MAIN_VIEW_CAPTION ); |
|
153 aCaption.Copy( *result ); |
|
154 delete result; |
|
155 } |
|
156 |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CGSAccessoryPlugin::CreateIconL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 CGulIcon* CGSAccessoryPlugin::CreateIconL( const TUid aIconType ) |
|
163 { |
|
164 FUNC_LOG; |
|
165 |
|
166 CGulIcon* icon( NULL ); |
|
167 if ( aIconType == KGSIconTypeLbxItem ) |
|
168 { |
|
169 icon = AknsUtils::CreateGulIconL( |
|
170 AknsUtils::SkinInstance(), |
|
171 KAknsIIDQgnPropSetAccessorySub, |
|
172 KGSAccPluginIconFileName, |
|
173 EMbmGsaccpluginQgn_prop_set_accessory_sub, |
|
174 EMbmGsaccpluginQgn_prop_set_accessory_sub_mask ); |
|
175 } |
|
176 else |
|
177 { |
|
178 icon = CGSPluginInterface::CreateIconL( aIconType ); |
|
179 } |
|
180 |
|
181 return icon; |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CGSAccessoryPlugin::PluginProviderCategory |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CGSAccessoryPlugin::PluginProviderCategory() const |
|
190 { |
|
191 // To identify internal plug-ins. |
|
192 return KGSPluginProviderInternal; |
|
193 } |
|
194 |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // TUid CGSAccessoryPlugin::Id() |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 TUid CGSAccessoryPlugin::Id() const |
|
201 { |
|
202 return TUid::Uid( KGSAccessoryPluginUid ); |
|
203 } |
|
204 |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CGSAccessoryPlugin::ProcessCommandL |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CGSAccessoryPlugin::ProcessCommandL( TInt aCommand ) |
|
211 { |
|
212 FUNC_LOG; |
|
213 |
|
214 if ( aCommand == EGSCmdAppOpen ) |
|
215 { |
|
216 SelectLocalViewL(); |
|
217 } |
|
218 else |
|
219 { |
|
220 CAknView::ProcessCommandL( aCommand ); |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // CGSAccessoryPlugin::HandleCommandL |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CGSAccessoryPlugin::HandleCommandL( TInt aCommand ) |
|
230 { |
|
231 FUNC_LOG; |
|
232 |
|
233 iRockerPress = EFalse; |
|
234 |
|
235 switch ( aCommand ) |
|
236 { |
|
237 case EAknSoftkeyOpen: |
|
238 SelectLocalViewL(); |
|
239 break; |
|
240 case EAknSoftkeyBack: |
|
241 RemoveLocalViews(); |
|
242 iAppUi->ActivateLocalViewL( KGSGenPluginUid ); |
|
243 break; |
|
244 case EAknCmdHelp: |
|
245 { |
|
246 if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
247 { |
|
248 HlpLauncher::LaunchHelpApplicationL( |
|
249 iEikonEnv->WsSession(), iAppUi->AppHelpContextL() ); |
|
250 } |
|
251 break; |
|
252 } |
|
253 case EGSCmdAppSetasDefault: |
|
254 ChangeDefaultAccessoryL(); |
|
255 break; |
|
256 default: |
|
257 iAppUi->HandleCommandL( aCommand ); |
|
258 break; |
|
259 } |
|
260 } |
|
261 |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CGSAccessoryPlugin::DynInitMenuPaneL() |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CGSAccessoryPlugin::DynInitMenuPaneL( |
|
268 TInt aResourceId, |
|
269 CEikMenuPane* aMenuPane ) |
|
270 { |
|
271 FUNC_LOG; |
|
272 |
|
273 if ( aResourceId == R_GS_MENU_ITEM_HELP ) |
|
274 { |
|
275 User::LeaveIfNull( aMenuPane ); |
|
276 |
|
277 if ( iRockerPress || !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
278 { |
|
279 // Remove help if rocker key is pressed or help is not supported |
|
280 aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue ); |
|
281 } |
|
282 else |
|
283 { |
|
284 aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse ); |
|
285 } |
|
286 } |
|
287 else if ( aResourceId == R_GS_MENU_ITEM_EXIT ) |
|
288 { |
|
289 User::LeaveIfNull( aMenuPane ); |
|
290 |
|
291 if ( iRockerPress ) |
|
292 { |
|
293 // Remove exit if rocker key is pressed |
|
294 aMenuPane->SetItemDimmed( EAknCmdExit, ETrue ); |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // CGSAccessoryPlugin::CGSAccessoryPlugin() |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 CGSAccessoryPlugin::CGSAccessoryPlugin() |
|
305 : iResourceLoader( *iCoeEnv ) |
|
306 { |
|
307 FUNC_LOG; |
|
308 } |
|
309 |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CGSAccessoryPlugin::ConstructL() |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 void CGSAccessoryPlugin::ConstructL() |
|
316 { |
|
317 FUNC_LOG; |
|
318 |
|
319 FeatureManager::InitializeLibL(); |
|
320 |
|
321 // Initialize the Model |
|
322 iModel = CGSAccessoryPluginModel::NewL(); |
|
323 |
|
324 // TParse uses a lot of stack space, so allocate it from heap. |
|
325 TParse* parse = new ( ELeave ) TParse; |
|
326 CleanupStack::PushL( parse ); |
|
327 TInt errorCode = parse->Set( |
|
328 KGSAccessoryPluginResourceFileName, |
|
329 &KDC_RESOURCE_FILES_DIR, |
|
330 NULL ); |
|
331 ERROR( errorCode, "parse::Set() failed" ); |
|
332 User::LeaveIfError( errorCode ); |
|
333 |
|
334 // TFileName uses a lot of stack space, so allocate it from heap. |
|
335 TFileName* fileName = new ( ELeave ) TFileName( parse->FullName() ); |
|
336 CleanupStack::PushL( fileName ); |
|
337 |
|
338 // Get language of resource file |
|
339 BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), *fileName ); |
|
340 |
|
341 // Open resource file |
|
342 iResourceLoader.OpenL( *fileName ); |
|
343 |
|
344 CleanupStack::PopAndDestroy( fileName ); |
|
345 CleanupStack::PopAndDestroy( parse ); |
|
346 |
|
347 BaseConstructL( R_ACC_MAIN_VIEW ); |
|
348 } |
|
349 |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // CGSAccessoryPlugin::SelectLocalViewL() |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CGSAccessoryPlugin::SelectLocalViewL() |
|
356 { |
|
357 FUNC_LOG; |
|
358 |
|
359 CGSAccessoryPluginContainer* container = |
|
360 static_cast<CGSAccessoryPluginContainer*>( iContainer ); |
|
361 TUid viewId = ListIdToViewId( container->CurrentFeatureId() ); |
|
362 |
|
363 if ( !LocalViewExists( viewId ) ) |
|
364 { |
|
365 CGSAccBaseView* view( NULL ); |
|
366 // Unsupported items are already hidden - no need to check them here. |
|
367 switch ( container->CurrentFeatureId() ) |
|
368 { |
|
369 case EGSHeadsetListItemId: |
|
370 view = CGSAccHeadsetView::NewLC( *iModel ); |
|
371 break; |
|
372 case EGSHeadphonesListItemId: |
|
373 view = CGSAccHeadphonesView::NewLC( *iModel ); |
|
374 break; |
|
375 case EGSLoopsetListItemId: |
|
376 view = CGSAccLoopsetView::NewLC( *iModel ); |
|
377 break; |
|
378 case EGSTextPhoneListItemId: |
|
379 view = CGSAccTextPhoneView::NewLC( *iModel ); |
|
380 break; |
|
381 case EGSMusicStandListItemId: |
|
382 view = CGSAccMusicStandView::NewLC( *iModel ); |
|
383 break; |
|
384 case EGSWiredCarKitListItemId: |
|
385 view = CGSAccWiredCarkitView::NewLC( *iModel ); |
|
386 break; |
|
387 case EGSWirelessCarKitListItemId: |
|
388 view = CGSAccWirelessCarkitView::NewLC( *iModel ); |
|
389 break; |
|
390 case EGSTvOutListItemId: |
|
391 view = CGSAccTvoutView::NewLC( *iModel ); |
|
392 break; |
|
393 case EGSHACListItemId: |
|
394 view = CGSAccHACView::NewLC( *iModel ); |
|
395 break; |
|
396 default: |
|
397 break; |
|
398 } |
|
399 |
|
400 if ( view ) |
|
401 { |
|
402 iSubViewIds.AppendL( view->Id() ); // Store id |
|
403 iAppUi->AddViewL( view ); |
|
404 CleanupStack::Pop( view ); |
|
405 } |
|
406 } |
|
407 |
|
408 iAppUi->ActivateLocalViewL( viewId ); // Activate the view |
|
409 } |
|
410 |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // CGSAccessoryPlugin::RemoveLocalViews() |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 void CGSAccessoryPlugin::RemoveLocalViews() |
|
417 { |
|
418 FUNC_LOG; |
|
419 |
|
420 TInt count = iSubViewIds.Count(); |
|
421 for ( TInt i = 0; i < count; i++ ) |
|
422 { |
|
423 iAppUi->RemoveView( iSubViewIds[i] ); // Deletes the object also. |
|
424 } |
|
425 iSubViewIds.Reset(); // No need to close after this. |
|
426 } |
|
427 |
|
428 |
|
429 // --------------------------------------------------------------------------- |
|
430 // CGSAccessoryPlugin::LocalViewExists() |
|
431 // --------------------------------------------------------------------------- |
|
432 // |
|
433 TBool CGSAccessoryPlugin::LocalViewExists( const TUid& aViewId ) const |
|
434 { |
|
435 FUNC_LOG; |
|
436 |
|
437 return ( iSubViewIds.Find( aViewId ) != KErrNotFound ); |
|
438 } |
|
439 |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CGSAccessoryPlugin::ChangeDefaultAccessoryL() |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 void CGSAccessoryPlugin::ChangeDefaultAccessoryL() |
|
446 { |
|
447 FUNC_LOG; |
|
448 |
|
449 CGSAccessoryPluginContainer* container = |
|
450 static_cast<CGSAccessoryPluginContainer*>( iContainer ); |
|
451 |
|
452 TInt currentFeatureId = container->CurrentFeatureId(); |
|
453 TInt oldDefaultItem = iModel->DefaultAccessory(); |
|
454 if ( oldDefaultItem != currentFeatureId ) |
|
455 { |
|
456 // Here we set the item selected as "Set as Default" |
|
457 container->ChangeDefaultItemL( currentFeatureId, oldDefaultItem ); |
|
458 iModel->SetDefaultAccessoryL( currentFeatureId ); |
|
459 container->DrawNow(); |
|
460 } |
|
461 } |