|
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 "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: GSFW implementation for Presence Settings UI GS plugin. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <bautils.h> |
|
23 #include <gsprivatepluginproviderids.h> |
|
24 #include <GSFWViewUIDs.h> |
|
25 #include <psuigspluginrsc.rsg> |
|
26 #include <psuigsplugin.mbg> |
|
27 #include <GSBaseView.h> |
|
28 #include <eiktxlbx.h> |
|
29 #include <eikmenup.h> |
|
30 #include <eiktxlbm.h> |
|
31 #include <featmgr.h> |
|
32 #include <hlplch.h> |
|
33 #include <coeaui.h> |
|
34 #include <aknlists.h> |
|
35 #include <aknPopup.h> |
|
36 #include <StringLoader.h> |
|
37 #include <AknQueryDialog.h> |
|
38 |
|
39 #include "psuigsplugin.h" |
|
40 #include "psuigsplugin.hrh" |
|
41 #include "psuigsplugincontainer.h" |
|
42 #include "psuigspluginids.hrh" |
|
43 #include "psuigspluginmodel.h" |
|
44 #include "psuigspluginsettingview.h" |
|
45 |
|
46 // CONSTANTS |
|
47 _LIT( KPSUIGSPluginResourceFileName, "z:\\resource\\psuigspluginrsc.rsc" ); |
|
48 |
|
49 #ifdef __SCALABLE_ICONS |
|
50 // bitmap |
|
51 _LIT( KPSUIGSPluginIconFileName, "\\resource\\apps\\psuigsplugin.mif"); |
|
52 #else //__SCALABLE_ICONS |
|
53 // svg file |
|
54 _LIT( KPSUIGSPluginIconFileName, "\\resource\\apps\\psuigsplugin.mbm"); |
|
55 #endif //__SCALABLE_ICONS |
|
56 |
|
57 // ========================= MEMBER FUNCTIONS ================================ |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CPSUIGSPlugin::CPSUIGSPlugin() |
|
61 // C++ default constructor can NOT contain any code, that |
|
62 // might leave. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CPSUIGSPlugin::CPSUIGSPlugin() |
|
66 : iClosing ( EFalse ) |
|
67 { |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CPSUIGSPlugin::~CPSUIGSPlugin() |
|
72 // Destructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CPSUIGSPlugin::~CPSUIGSPlugin() |
|
76 { |
|
77 delete iPSModel; |
|
78 FeatureManager::UnInitializeLib(); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CPSUIGSPlugin::ConstructL |
|
83 // Symbian 2nd phase constructor can leave. |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CPSUIGSPlugin::ConstructL() |
|
87 { |
|
88 // preparing resources for use |
|
89 TFileName fileName( KPSUIGSPluginResourceFileName ); |
|
90 BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName ); |
|
91 iResourceLoader.OpenL( fileName ); |
|
92 // base construct (base needs the resources to be loaded 1st) |
|
93 BaseConstructL( R_PSUI_MAIN_VIEW ); |
|
94 FeatureManager::InitializeLibL(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CPSUIGSPlugin::NewL() |
|
99 // Two-phased constructor. |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CPSUIGSPlugin* CPSUIGSPlugin::NewL( TAny* /*aAppUi*/ ) |
|
103 { |
|
104 CPSUIGSPlugin* self = new( ELeave ) CPSUIGSPlugin(); |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL(); |
|
107 CleanupStack::Pop( self ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CPSUIGSPlugin::Id() |
|
113 // See header for details. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 TUid CPSUIGSPlugin::Id() const |
|
117 { |
|
118 return TUid::Uid( PSUIGSPluginImplUid ); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CPSUIGSPlugin::NewContainerL() |
|
123 // See header for details. |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CPSUIGSPlugin::NewContainerL() |
|
127 { |
|
128 iContainer = new ( ELeave ) CPSUIGSPluginContainer( this ); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CPSUIGSPlugin::DoActivateL() |
|
133 // See header for details. |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CPSUIGSPlugin::DoActivateL( const TVwsViewId& aPrevViewId, |
|
137 TUid aCustomMessageId, |
|
138 const TDesC8& aCustomMessage ) |
|
139 { |
|
140 if ( KPreSettingViewId != aPrevViewId.iViewUid ) |
|
141 { |
|
142 iPSUIGSPrevViewId = aPrevViewId; |
|
143 } |
|
144 |
|
145 // model & observer constructed only when needed |
|
146 if ( !iPSModel ) |
|
147 { |
|
148 iPSModel = CPSUIGSPluginModel::NewL(); |
|
149 iAppUi->AddViewDeactivationObserverL( this ); |
|
150 } |
|
151 |
|
152 const TInt id = iPSModel->SettingsId(); |
|
153 if ( id ) |
|
154 {// readjust the focus |
|
155 SetCurrentItem( iPSModel->SettingsIDArray().Find( id )); |
|
156 } |
|
157 |
|
158 iClosing = EFalse; |
|
159 CGSBaseView::DoActivateL( aPrevViewId, aCustomMessageId, aCustomMessage ); |
|
160 UpdateMSK(); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CPSUIGSPlugin::DoDeactivate() |
|
165 // See header for details. |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CPSUIGSPlugin::DoDeactivate() |
|
169 { |
|
170 CGSBaseView::DoDeactivate(); |
|
171 if ( iClosing ) |
|
172 {// PSUI plugin is going to be closed so it is safe to free some memory |
|
173 delete iPSModel; |
|
174 iPSModel = NULL; |
|
175 delete iSettingView; |
|
176 iSettingView = NULL; |
|
177 } |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CPSUIGSPlugin::HandleViewDeactivation() |
|
182 // See header for details. |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CPSUIGSPlugin::HandleViewDeactivation( |
|
186 const TVwsViewId& aViewIdToBeDeactivated, |
|
187 const TVwsViewId& aNewlyActivatedViewId) |
|
188 { |
|
189 if ( TUid::Uid( PSUIGSPluginImplUid ) == aViewIdToBeDeactivated.iViewUid && |
|
190 iPSUIGSPrevViewId.iViewUid == aNewlyActivatedViewId.iViewUid ) |
|
191 { |
|
192 iClosing = ETrue; |
|
193 iAppUi->RemoveViewDeactivationObserver( this ); |
|
194 } |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CPSUIGSPlugin::HandleCommandL() |
|
199 // See header for details. |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CPSUIGSPlugin::HandleCommandL( TInt aCommand ) |
|
203 { |
|
204 switch ( aCommand ) |
|
205 { |
|
206 case EAknSoftkeyBack: |
|
207 { |
|
208 RemoveSettingView(); |
|
209 iAppUi->ActivateLocalViewL( iPSUIGSPrevViewId.iViewUid ); |
|
210 break; |
|
211 } |
|
212 case EPSUICmdEdit: |
|
213 { |
|
214 HandleListBoxSelectionL(); |
|
215 break; |
|
216 } |
|
217 case EPSUICmdDelete: |
|
218 { |
|
219 DeleteSettingsL(); |
|
220 break; |
|
221 } |
|
222 case EPSUICmdNewSettingsDefault: |
|
223 { |
|
224 CreateNewDefaultSettingsL(); |
|
225 break; |
|
226 } |
|
227 case EPSUICmdNewSettingsExisting: |
|
228 { |
|
229 CreateCopyOfExistingSettingsL(); |
|
230 break; |
|
231 } |
|
232 case EAknCmdHelp: |
|
233 { |
|
234 if( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
235 { |
|
236 HlpLauncher::LaunchHelpApplicationL( |
|
237 iEikonEnv->WsSession(), iAppUi->AppHelpContextL() ); |
|
238 } |
|
239 break; |
|
240 } |
|
241 default: |
|
242 { |
|
243 iAppUi->HandleCommandL( aCommand ); |
|
244 break; |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CPSUIGSPlugin::SettingCountAndIndex() |
|
251 // See header for details. |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 TInt CPSUIGSPlugin::SettingCountAndIndex( TInt& aIndex ) |
|
255 { |
|
256 CEikTextListBox* listbox = Container()->iListBox;// not owned |
|
257 TInt count = listbox->Model()->NumberOfItems(); |
|
258 aIndex = count ? listbox->CurrentItemIndex() : KErrNotFound; |
|
259 |
|
260 return count; |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CPSUIGSPlugin::HandleListBoxSelectionL() |
|
265 // See header for details. |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void CPSUIGSPlugin::HandleListBoxSelectionL() |
|
269 { |
|
270 TInt index = KErrNotFound; |
|
271 if ( SettingCountAndIndex( index )) |
|
272 { |
|
273 iPSModel->EditSettingsL( index ); |
|
274 |
|
275 ConstructSettingViewL(); |
|
276 iAppUi->ActivateLocalViewL( KPreSettingViewId ); |
|
277 } |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // CPSUIGSPlugin::DeleteSettingsL() |
|
282 // See header for details. |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 void CPSUIGSPlugin::DeleteSettingsL() |
|
286 { |
|
287 TInt index = KErrNotFound; |
|
288 TInt count = SettingCountAndIndex( index ); |
|
289 if ( count ) |
|
290 { |
|
291 if ( AcceptDeletionL( count, index )) |
|
292 { |
|
293 iPSModel->DeleteSettingsL( index, ETrue ); |
|
294 CEikTextListBox* listbox = Container()->iListBox;// not owned |
|
295 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( |
|
296 listbox, index, ETrue ); |
|
297 listbox->DrawNow(); |
|
298 UpdateMSK(); |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // CPSUIGSPlugin::AcceptDeletionL() |
|
305 // See header for details. |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 TBool CPSUIGSPlugin::AcceptDeletionL( TInt aCount, TInt aIndex ) |
|
309 { |
|
310 HBufC* currentName = iPSModel->SettingNameLC( aIndex ); |
|
311 HBufC* string = NULL; |
|
312 if ( aCount == 1 ) |
|
313 { |
|
314 string = StringLoader::LoadLC( R_QTN_PRESENCE_SETTINGS_DELETE_LAST, *currentName ); |
|
315 } |
|
316 else |
|
317 { |
|
318 string = StringLoader::LoadLC( R_QTN_QUERY_COMMON_CONF_DELETE, *currentName ); |
|
319 } |
|
320 |
|
321 CAknQueryDialog* query = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone ); |
|
322 TInt ok = query->ExecuteLD( R_PSUI_CONF_QUERY, *string ); |
|
323 |
|
324 CleanupStack::PopAndDestroy( 2, currentName );//currentName, string |
|
325 |
|
326 return ( ok ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // CPSUIGSPlugin::GetCaptionL() |
|
331 // See header for details. |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 void CPSUIGSPlugin::GetCaptionL( TDes& aCaption ) const |
|
335 { |
|
336 StringLoader::Load( aCaption, R_QTN_SET_FOLDER_PRESENCE ); |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // CPSUIGSPlugin::PluginProviderCategory() |
|
341 // See header for details. |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 TInt CPSUIGSPlugin::PluginProviderCategory() const |
|
345 { |
|
346 return KGSPluginProviderInternal; |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // CPSUIGSPlugin::CreateIconL() |
|
351 // See header for details. |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 CGulIcon* CPSUIGSPlugin::CreateIconL( const TUid aIconType ) |
|
355 { |
|
356 CGulIcon* icon = NULL; |
|
357 if( aIconType == KGSIconTypeLbxItem ) |
|
358 { |
|
359 icon = AknsUtils::CreateGulIconL( |
|
360 AknsUtils::SkinInstance(), |
|
361 KAknsIIDQgnPropSetConnPresence, |
|
362 KPSUIGSPluginIconFileName, |
|
363 EMbmPsuigspluginQgn_prop_set_conn_presence, |
|
364 EMbmPsuigspluginQgn_prop_set_conn_presence_mask ); |
|
365 } |
|
366 else |
|
367 { |
|
368 icon = CGSPluginInterface::CreateIconL( aIconType ); |
|
369 } |
|
370 |
|
371 return icon; |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // CPSUIGSPlugin::DynInitMenuPaneL() |
|
376 // See header for details. |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CPSUIGSPlugin::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane *aMenuPane ) |
|
380 { |
|
381 // remove some of the items if no settings available |
|
382 const TInt count = Container()->iListBox->Model()->NumberOfItems(); |
|
383 if ( aResourceId == R_PSUI_MAINVIEW_MENUPANE && |
|
384 0 == count ) |
|
385 { |
|
386 aMenuPane->DeleteMenuItem( EPSUICmdEdit ); |
|
387 aMenuPane->DeleteMenuItem( EPSUICmdDelete ); |
|
388 } |
|
389 if ( aResourceId == R_PSUI_NEWSETTINGS_MENU && |
|
390 0 == count ) |
|
391 { |
|
392 aMenuPane->DeleteMenuItem( EPSUICmdNewSettingsExisting ); |
|
393 } |
|
394 |
|
395 // help-item handling |
|
396 if ( aResourceId == R_PSUI_MAINVIEW_MENUPANE && |
|
397 !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
398 { |
|
399 aMenuPane->DeleteMenuItem( EAknCmdHelp ); |
|
400 } |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // CPSUIGSPlugin::PSModel() |
|
405 // See header for details. |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 CPSUIGSPluginModel* CPSUIGSPlugin::PSModel() |
|
409 { |
|
410 __ASSERT_DEBUG( iPSModel,User::Panic( KPSUIGSPluginPanicCategory, KErrNotFound )); |
|
411 return iPSModel; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // CPSUIGSPlugin::ConstructSettingViewL() |
|
416 // See header for details. |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void CPSUIGSPlugin::ConstructSettingViewL() |
|
420 { |
|
421 if ( !iSettingView ) |
|
422 {// no view yet, construct it |
|
423 CAknView* view = CPSUIGSPluginSettingView::NewL( this ); |
|
424 CleanupStack::PushL( view ); |
|
425 iAppUi->AddViewL( view ); |
|
426 CleanupStack::Pop( view ); |
|
427 iSettingView = view; |
|
428 } |
|
429 } |
|
430 |
|
431 // --------------------------------------------------------------------------- |
|
432 // CPSUIGSPlugin::RemoveSettingView() |
|
433 // See header for details. |
|
434 // --------------------------------------------------------------------------- |
|
435 // |
|
436 void CPSUIGSPlugin::RemoveSettingView() |
|
437 { |
|
438 // Remove view from iAppUi -> View is deleted by iAppUi automatically. |
|
439 if ( iSettingView ) |
|
440 { |
|
441 iAppUi->RemoveView( KPreSettingViewId ); |
|
442 iSettingView = NULL; |
|
443 } |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // CPSUIGSPlugin::CreateNewDefaultSettingsL() |
|
448 // See header for details. |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 void CPSUIGSPlugin::CreateNewDefaultSettingsL() |
|
452 { |
|
453 iPSModel->CreateDefaultSettingsL(); |
|
454 ConstructSettingViewL(); |
|
455 iAppUi->ActivateLocalViewL( KPreSettingViewId ); |
|
456 } |
|
457 |
|
458 // --------------------------------------------------------------------------- |
|
459 // CPSUIGSPlugin::CreateCopyOfExistingSettingsL() |
|
460 // See header for details. |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 void CPSUIGSPlugin::CreateCopyOfExistingSettingsL() |
|
464 { |
|
465 CAknSinglePopupMenuStyleListBox* list = |
|
466 new ( ELeave ) CAknSinglePopupMenuStyleListBox; |
|
467 CleanupStack::PushL( list ); |
|
468 |
|
469 CAknPopupList* popupList = |
|
470 CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL ); |
|
471 CleanupStack::PushL( popupList ); |
|
472 |
|
473 HBufC* title = StringLoader::LoadLC( R_QTN_PRESENCE_PROPMT_USE_EXIST ); |
|
474 popupList->SetTitleL( *title ); |
|
475 CleanupStack::PopAndDestroy( title ); |
|
476 |
|
477 list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
478 list->CreateScrollBarFrameL( ETrue ); |
|
479 list->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
480 CEikScrollBarFrame::EOff, |
|
481 CEikScrollBarFrame::EAuto ); |
|
482 |
|
483 CTextListBoxModel* model = list->Model(); |
|
484 model->SetItemTextArray( iPSModel->SettingNames() );// setting names not owned |
|
485 model->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
486 list->HandleItemAdditionL(); |
|
487 |
|
488 CleanupStack::Pop( popupList ); |
|
489 TInt keyPress = popupList->ExecuteLD(); |
|
490 |
|
491 if ( keyPress ) |
|
492 { |
|
493 iPSModel->DuplicateExistingSettingsL( list->CurrentItemIndex() ); |
|
494 ConstructSettingViewL(); |
|
495 iAppUi->ActivateLocalViewL( KPreSettingViewId ); |
|
496 } |
|
497 |
|
498 CleanupStack::PopAndDestroy( list ); |
|
499 } |
|
500 |
|
501 // --------------------------------------------------------------------------- |
|
502 // CPSUIGSPlugin::UpdateMSK() |
|
503 // See header for details. |
|
504 // --------------------------------------------------------------------------- |
|
505 // |
|
506 void CPSUIGSPlugin::UpdateMSK() |
|
507 { |
|
508 if ( !Cba() ) |
|
509 { |
|
510 return; |
|
511 } |
|
512 |
|
513 TBool showEdit = ( 0 < Container()->iListBox->Model()->NumberOfItems()); |
|
514 CEikCba* cba = static_cast< CEikCba* >( Cba()->ButtonGroup() ); |
|
515 cba->MakeCommandVisible( EPSUICmdEdit, showEdit ); |
|
516 cba->DrawNow(); |
|
517 } |
|
518 |
|
519 // --------------------------------------------------------------------------- |
|
520 // CPSUIGSPlugin::HandleListBoxEventL() |
|
521 // --------------------------------------------------------------------------- |
|
522 // |
|
523 void CPSUIGSPlugin::HandleListBoxEventL( |
|
524 CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent) |
|
525 { |
|
526 // if the Select Key has been pressed |
|
527 if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) || |
|
528 (aListBoxEvent == MEikListBoxObserver::EEventItemSingleClicked)) |
|
529 { |
|
530 HandleListBoxSelectionL(); |
|
531 } |
|
532 } |
|
533 |
|
534 // End of file |