idlefw/plugins/mcsplugin/settings/src/mcspluginsettingscontainer.cpp
changeset 0 79c6a41cd166
child 1 844b978f8d5e
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Shortcut settings plug-in container.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknlists.h>
       
    20 #include <AknWaitDialog.h>
       
    21 #include <aknnotewrappers.h>
       
    22 #include <eikbtgpc.h>
       
    23 #include <gslistbox.h>
       
    24 #include <gsfwviewuids.h>
       
    25 #include <aknradiobuttonsettingpage.h>
       
    26 #include <akntextsettingpage.h>
       
    27 #include <centralrepository.h>
       
    28 #include <StringLoader.h>
       
    29 #include <hlplch.h>
       
    30 
       
    31 // For CActiveFavouritesDbNotifier
       
    32 #include <ActiveFavouritesDbNotifier.h> 
       
    33 #include <mcspluginsettingsres.rsg>
       
    34 
       
    35 #include "mcspluginsettingscontainer.h"
       
    36 #include "mcspluginsettingsmodel.h"
       
    37 #include "mcspluginsettingsbkmlist.h"
       
    38 #include "mcspluginsettings.hrh"
       
    39 
       
    40 const TUid KUidAI = { 0x102750FB }; // Active Standby Shortcuts help uid
       
    41 
       
    42 _LIT(KSET_HLP_HOME_SCREEN_SHORTCUTS, "SET_HLP_HOME_SCREEN_SHORTCUTS"); 
       
    43 _LIT( KMyMenuData, "matrixmenudata" );
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // First-phase construction
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CMCSPluginSettingsContainer::CMCSPluginSettingsContainer()
       
    52 {
       
    53 }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Second-phase construction
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CMCSPluginSettingsContainer::ConstructL( const TRect& aRect )
       
    60     {
       
    61     iListBox = new (ELeave) CAknSettingStyleListBox;
       
    62     BaseConstructL(aRect, R_AI_MCS_SETTINGS_VIEW_TITLE, NULL);
       
    63     StartObservingL();
       
    64     CheckMiddleSoftkeyLabelL();
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // Tells the settings container to start observing for changes
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CMCSPluginSettingsContainer::StartObservingL()
       
    72     {
       
    73     // registering to bookmarks db. changes observing
       
    74     User::LeaveIfError( iBookmarkSession.Connect() );
       
    75     User::LeaveIfError( iBookmarkDb.Open( iBookmarkSession, KBrowserBookmarks ) );
       
    76 
       
    77     iBookmarkDbObserver = new (ELeave) CActiveFavouritesDbNotifier(
       
    78                                         iBookmarkDb, *this );
       
    79     iBookmarkDbObserver->Start();
       
    80 
       
    81     // registering to mailbox db. changes observing
       
    82     iMsvSession = CMsvSession::OpenAsObserverL( *this );
       
    83     
       
    84     // registering to matrix menu events observing
       
    85     iMenu.OpenL( KMyMenuData );
       
    86     TInt err = iNotifier.Open( iMenu ); 
       
    87     if ( err == KErrNone )
       
    88         {
       
    89         iNotifyWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::ENotify );
       
    90         iNotifier.Notify( 0,
       
    91             RMenuNotifier::EItemsAddedRemoved | RMenuNotifier::EItemsReordered,
       
    92         iNotifyWatcher->iStatus );
       
    93         iNotifyWatcher->WatchNotify( this );
       
    94         }
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Tells the settings container to stop observing for changes
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CMCSPluginSettingsContainer::StopObserving()
       
   102     {
       
   103     if( iBookmarkDbObserver )
       
   104         {
       
   105         delete iBookmarkDbObserver;
       
   106         iBookmarkDbObserver = NULL;
       
   107         }
       
   108     iBookmarkDb.Close();
       
   109     iBookmarkSession.Close();
       
   110 
       
   111     if( iMsvSession )
       
   112         {
       
   113         delete iMsvSession;
       
   114         iMsvSession = NULL;
       
   115         }
       
   116     
       
   117     iNotifier.Close();
       
   118     iMenu.Close();
       
   119     
       
   120     if ( iNotifyWatcher )
       
   121         {
       
   122         if ( iNotifyWatcher->IsActive() )
       
   123         	{
       
   124             iNotifyWatcher->Cancel();
       
   125         	}
       
   126         delete iNotifyWatcher;
       
   127         iNotifyWatcher = NULL;
       
   128         }
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Destructor
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CMCSPluginSettingsContainer::~CMCSPluginSettingsContainer()
       
   136     {
       
   137     StopObserving();
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Sets pointer to settings plug-in model.
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CMCSPluginSettingsContainer::SetModel( CMCSPluginSettingsModel* aModel )
       
   145 {
       
   146     iModel = aModel;
       
   147 }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Handles a setting change command.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CMCSPluginSettingsContainer::HandleChangeCommandL()
       
   154 {       
       
   155     TInt current = iListBox->CurrentItemIndex();
       
   156     TInt appListIndex = iModel->ItemId( current );
       
   157     if ( appListIndex < -1 )
       
   158     {
       
   159         appListIndex = -1;
       
   160     }
       
   161 
       
   162     if ( iModel->Item( current ).locked )
       
   163         {
       
   164         HBufC* text = iCoeEnv->AllocReadResourceLC( R_AI_MCS_SETTINGS_TXT_FIXED_ITEM );
       
   165         CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   166         note->ExecuteLD( *text );
       
   167         CleanupStack::PopAndDestroy( text );
       
   168         }
       
   169     else
       
   170         {
       
   171         TInt selection( KErrNotFound );
       
   172         TBool changed( EFalse );
       
   173         CDesCArrayFlat* array = iCoeEnv->ReadDesC16ArrayResourceL(
       
   174             R_AI_MCS_CHANGE_TO_PAGE_LBX );
       
   175         CleanupStack::PushL( array );
       
   176 
       
   177         CAknListQueryDialog* dialog = new ( ELeave ) CAknListQueryDialog( &selection );
       
   178         CleanupStack::PushL( dialog );
       
   179         dialog->PrepareLC( R_AI_MCS_LISTQUERY_CHANGE_TO_PAGE );
       
   180         CleanupStack::Pop( dialog );
       
   181         dialog->SetItemTextArray( array );
       
   182         dialog->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   183         if ( dialog->RunLD() )
       
   184             {
       
   185 
       
   186             TSettingItem itm = iModel->Item( current );
       
   187 
       
   188             // user wants to select bookmark
       
   189             if ( selection == 1 )
       
   190                 {
       
   191 
       
   192                 // if the last selected item was application, set selected item to -1
       
   193                 if ( itm.type == EApplication )
       
   194                     {
       
   195                         appListIndex = -1;
       
   196                     }
       
   197 
       
   198                 changed = HandleBookmarkChangeCommandL( appListIndex, current );
       
   199 
       
   200                 }
       
   201             // user wants to select application
       
   202             else if ( selection == 0 )
       
   203                 {
       
   204 
       
   205                 // if the last selected item was bookmark, set selected item to -1
       
   206                 if ( itm.type == EBookmark )
       
   207                     {
       
   208                         appListIndex = -1;
       
   209                     }
       
   210 
       
   211                 changed = HandleAppListChangeCommandL( appListIndex, current );
       
   212 
       
   213                 }
       
   214             if ( changed )
       
   215                 {
       
   216                     ResetCurrentListL( current );
       
   217                 }
       
   218 
       
   219             }
       
   220         CleanupStack::PopAndDestroy( array );
       
   221         }
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // Handles a help command.
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CMCSPluginSettingsContainer::HandleHelpCommandL()
       
   229 {
       
   230     CArrayFixFlat<TCoeHelpContext>* array = 
       
   231         new ( ELeave ) CArrayFixFlat<TCoeHelpContext>( 1 );
       
   232     CleanupStack::PushL( array );
       
   233     array->AppendL( GetHelpContext() );
       
   234     HlpLauncher::LaunchHelpApplicationL( CCoeEnv::Static()->WsSession(), array );
       
   235     CleanupStack::Pop( array );
       
   236 }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // Helper method which indicates if the Applist or Bkmlist is showing
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 TBool CMCSPluginSettingsContainer::IsChangeDialogShowing()
       
   243 {
       
   244     return ( iAppListDialog || iBkmListDialog );
       
   245 }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // Method for closing change dialog (app or bkm) if it is beeing shown
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CMCSPluginSettingsContainer::CloseChangeDialog()
       
   252 {
       
   253     TKeyEvent keyEvent;
       
   254 
       
   255     keyEvent.iCode      = EKeyEscape;
       
   256     keyEvent.iScanCode  = EStdKeyEscape;
       
   257     keyEvent.iModifiers = 0;
       
   258     keyEvent.iRepeats   = 0;
       
   259 
       
   260     CCoeControl* dialog = NULL;
       
   261 
       
   262     if ( iAppListDialog )
       
   263     {
       
   264         dialog = static_cast< CCoeControl* >( iAppListDialog );
       
   265     }
       
   266     else if ( iBkmListDialog )
       
   267     {
       
   268         dialog = static_cast< CCoeControl* >( iBkmListDialog );
       
   269     }
       
   270 
       
   271     if ( dialog )
       
   272     {
       
   273         TRAP_IGNORE( dialog->OfferKeyEventL( keyEvent, EEventKey ) );
       
   274     }
       
   275 }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // Refreshes current list..
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CMCSPluginSettingsContainer::ResetCurrentListL( TInt aIndex )
       
   282 {
       
   283     if (iModel->MdcaCount() == 0)
       
   284     {
       
   285         iListBox->HandleItemRemovalL();
       
   286     }
       
   287     else
       
   288     {
       
   289         iListBox->HandleItemAdditionL();
       
   290     }
       
   291 
       
   292     iListBox->SetCurrentItemIndex( aIndex );
       
   293     CheckMiddleSoftkeyLabelL();
       
   294 }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // From class MMsvSessionObserver.
       
   298 // Handles an event from the message server.
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CMCSPluginSettingsContainer::HandleSessionEventL(
       
   302                                                      TMsvSessionEvent aEvent,
       
   303                                                      TAny* /*aArg1*/,
       
   304                                                      TAny* /*aArg2*/,
       
   305                                                      TAny* /*aArg3*/ )
       
   306     {
       
   307     switch ( aEvent )
       
   308         {
       
   309     case EMsvEntriesCreated:
       
   310         // fall-through intended here
       
   311     case EMsvEntriesDeleted:
       
   312         // fall-through intended here
       
   313     case EMsvEntriesChanged:
       
   314         {
       
   315         if ( IsChangeDialogShowing() )
       
   316             {
       
   317             CloseChangeDialog();
       
   318             }
       
   319         iModel->UpdateAppListL();
       
   320         }
       
   321         break;
       
   322     default:
       
   323         break;
       
   324         }
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // From CGSBaseContainer
       
   329 // Constructs the settings listbox.
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CMCSPluginSettingsContainer::ConstructListBoxL(TInt /*aResLbxId*/)
       
   333 {
       
   334     iListBox->ConstructL(this, EAknListBoxSelectionList);
       
   335 
       
   336     // Set empty listbox's text.
       
   337     HBufC* text = iCoeEnv->AllocReadResourceLC(R_AI_MCS_SETTINGS_TXT_ALL_FIXED);
       
   338     iListBox->View()->SetListEmptyTextL(*text);
       
   339     CleanupStack::PopAndDestroy(text);
       
   340 
       
   341     iListBox->Model()->SetItemTextArray(iModel);
       
   342     iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   343 }
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // Chandles a setting change command to select application from a list.
       
   347 // ---------------------------------------------------------------------------
       
   348 //
       
   349 TBool CMCSPluginSettingsContainer::HandleAppListChangeCommandL( const TInt& aIndex,
       
   350                                                                 const TInt& aSettingIndex )
       
   351 {
       
   352     
       
   353     TBool changed = EFalse;
       
   354 
       
   355     TInt index = aIndex;
       
   356     TInt oldIndex = index;
       
   357 
       
   358     iAppListDialog = new (ELeave) CAknRadioButtonSettingPage(
       
   359         R_AI_MCS_SETTINGS_APPLIST_PAGE, index, iModel->AppList());
       
   360 
       
   361     HBufC* title = StringLoader::LoadLC( R_AI_MCS_SETTINGS_TXT_LINKN, aSettingIndex + 1, iCoeEnv );
       
   362     iAppListDialog->SetSettingTextL( title->Des() );
       
   363     iAppListDialog->ConstructL();
       
   364 
       
   365     if (iAppListDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) &&
       
   366         index != oldIndex)
       
   367         {
       
   368         changed = iModel->ReplaceItemL( iListBox->CurrentItemIndex(), index , EApplication );
       
   369         }
       
   370 
       
   371     CleanupStack::PopAndDestroy( title );
       
   372     iAppListDialog = NULL;
       
   373 
       
   374     return changed;
       
   375 }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // Chandles a setting change command to select bookmark from a list.
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 TBool CMCSPluginSettingsContainer::HandleBookmarkChangeCommandL( const TInt& aIndex, 
       
   382                                                                  const TInt& aSettingIndex )
       
   383     {
       
   384     TBool changed = EFalse;
       
   385 
       
   386     TInt index = aIndex;
       
   387     TInt oldIndex = index;
       
   388 
       
   389     iBkmListDialog = new (ELeave) CAknRadioButtonSettingPage(
       
   390         R_AI_MCS_SETTINGS_APPLIST_PAGE, index, iModel->BkmList());
       
   391 
       
   392     HBufC* title = StringLoader::LoadLC( R_AI_MCS_SETTINGS_TXT_LINKN, aSettingIndex + 1, iCoeEnv );
       
   393     iBkmListDialog->SetSettingTextL( title->Des() );
       
   394     iBkmListDialog->ConstructL();
       
   395 
       
   396     if (iBkmListDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) &&
       
   397         index != oldIndex)
       
   398         {
       
   399         changed = iModel->ReplaceItemL( iListBox->CurrentItemIndex(), index , EBookmark );
       
   400         }
       
   401 
       
   402     CleanupStack::PopAndDestroy( title );
       
   403     iBkmListDialog = NULL;
       
   404     return changed;
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // Gets Help
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 TCoeHelpContext CMCSPluginSettingsContainer::GetHelpContext() const
       
   412 {
       
   413     TCoeContextName helpString;
       
   414 
       
   415     helpString.Copy( KSET_HLP_HOME_SCREEN_SHORTCUTS );
       
   416 
       
   417     // set UID and topic of Help to display
       
   418     return TCoeHelpContext( KUidAI, helpString );
       
   419 }
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // Offers a key event.
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 TKeyResponse CMCSPluginSettingsContainer::OfferKeyEventL(
       
   426     const TKeyEvent& aKeyEvent, TEventCode aType)
       
   427 {
       
   428     switch (aKeyEvent.iCode)
       
   429     {
       
   430     case EKeyLeftArrow:
       
   431     case EKeyRightArrow:
       
   432         // Listbox takes all event even if it doesn't use them:
       
   433         return EKeyWasNotConsumed;
       
   434 
       
   435     default:
       
   436         break;
       
   437     }
       
   438     // Now it's iListBox's job to process the key event
       
   439     return iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   440 }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // Checks if there is a need to update the middle softkey label.
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 void CMCSPluginSettingsContainer::CheckMiddleSoftkeyLabelL()
       
   447 {
       
   448     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   449     if (cba)
       
   450     {
       
   451         cba->MakeCommandVisible(EAiScutSettingsCmdChange, (iModel->MdcaCount() != 0));
       
   452     }
       
   453 }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // From class MFavouritesDbObserver.
       
   457 // Handles database event.
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 void CMCSPluginSettingsContainer::HandleFavouritesDbEventL(RDbNotifier::TEvent aEvent)
       
   461     {
       
   462     switch ( aEvent )
       
   463         {
       
   464         case RDbNotifier::ECommit   :
       
   465             // fall-through intended here
       
   466         case RDbNotifier::ERecover  :
       
   467             // fall-through intended here
       
   468         case RDbNotifier::ERollback :
       
   469             {
       
   470             if ( IsChangeDialogShowing() )
       
   471                 {
       
   472                 CloseChangeDialog();
       
   473                 }
       
   474             iModel->UpdateBkmListL();
       
   475             }
       
   476             break;
       
   477         default:
       
   478             break;
       
   479         }
       
   480     }
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // From class MMCSPluginWatcherObserver.
       
   484 // Handles matrix menu event.
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 void CMCSPluginSettingsContainer::HandleNotifyL()
       
   488     {
       
   489     if ( IsChangeDialogShowing() )
       
   490         {
       
   491         CloseChangeDialog();
       
   492         }
       
   493     iModel->UpdateAppListL();
       
   494     
       
   495     // Notification must be activated again
       
   496     iNotifyWatcher->Cancel();
       
   497     iNotifier.Notify( 0,
       
   498         RMenuNotifier::EItemsAddedRemoved | RMenuNotifier::EItemsReordered,
       
   499         iNotifyWatcher->iStatus );
       
   500     iNotifyWatcher->WatchNotify( this );
       
   501     }
       
   502 
       
   503 // End of File.