idlefw/plugins/shortcutplugin/src/caiscutsettingscontainer.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-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:  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 <csxhelp/ai.hlp.hrh>
       
    26 #include <aknradiobuttonsettingpage.h>
       
    27 #include <akntextsettingpage.h>
       
    28 #include <centralrepository.h>
       
    29 #include <StringLoader.h>
       
    30 
       
    31 #include <aiscutsettingsres.rsg>
       
    32 #include <aiscuttexts.rsg>
       
    33 
       
    34 #include "caiscutsettingscontainer.h"
       
    35 #include "caiscutsettingsmodel.h"
       
    36 #include "caiscutsettingsbkmlist.h"
       
    37 #include "caiscutsettingsitem.h"
       
    38 #include "aiscutpluginprivatecrkeys.h"
       
    39 #include "aiscutdefs.h"
       
    40 
       
    41 const TUid KUidAI = { 0x101F8701 }; // Active Standby Shortcuts help uid
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CAiScutSettingsContainer::CAiScutSettingsContainer()
       
    50 {
       
    51 }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CAiScutSettingsContainer::ConstructL(const TRect& aRect)
       
    58 {
       
    59     iListBox = new (ELeave) CAknSettingStyleListBox;
       
    60     BaseConstructL(aRect, R_SCUT_SETTINGS_VIEW_TITLE, NULL);
       
    61 
       
    62     iOldType = EAiScutSettingTypeUndefined;
       
    63 
       
    64     CheckMiddleSoftkeyLabelL();
       
    65 
       
    66     iModel->ActivateObservers(ETrue);
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CAiScutSettingsContainer::~CAiScutSettingsContainer()
       
    74 {
       
    75     HideWaitNoteDialog();
       
    76 }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // Sets pointer to settings plug-in model.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CAiScutSettingsContainer::SetModel(CAiScutSettingsModel* aModel)
       
    83 {
       
    84     iModel = aModel;
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Chandles a setting change command.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CAiScutSettingsContainer::HandleChangeCommandL()
       
    92 {       
       
    93     if ( iChangeProcessInProgress )
       
    94         {
       
    95         return;
       
    96         }
       
    97     TBool changed = EFalse;
       
    98     TInt current = iListBox->CurrentItemIndex();
       
    99     CAiScutSettingsItem* item = iModel->Item(current);
       
   100     if (!item)
       
   101     {
       
   102         return ;
       
   103     }
       
   104 
       
   105     TUint32 key = item->Key();
       
   106     TBool locked = (0 != (key & KScutFlagBitLocked));
       
   107 
       
   108     if (locked)
       
   109     {
       
   110         HBufC* text = iCoeEnv->AllocReadResourceLC(R_SCUT_SETTINGS_TXT_FIXED_ITEM);
       
   111         CAknInformationNote* note = new (ELeave) CAknInformationNote(ETrue);
       
   112         note->ExecuteLD(*text);
       
   113         CleanupStack::PopAndDestroy(text);
       
   114     }
       
   115     else
       
   116     {
       
   117         TAiScutSettingType oldType = item->Type();
       
   118         TInt newType = oldType;
       
   119 
       
   120         CDesCArrayFlat* array = iCoeEnv->ReadDesC16ArrayResourceL(
       
   121             R_SCUT_CHANGE_TO_PAGE_LBX);
       
   122         CleanupStack::PushL(array);
       
   123 
       
   124         CAknListQueryDialog* dialog = new(ELeave)CAknListQueryDialog(&newType);
       
   125         CleanupStack::PushL(dialog);
       
   126     	dialog->PrepareLC(R_SCUT_LISTQUERY_CHANGE_TO_PAGE);
       
   127     	CleanupStack::Pop(dialog);
       
   128         dialog->SetItemTextArray(array);
       
   129 	    dialog->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   130 	    iChangeProcessInProgress = ETrue;
       
   131         if (dialog->RunLD())
       
   132         {
       
   133             item = iModel->Item(current);
       
   134             if (newType == EAiScutSettingTypeUrl)
       
   135             {
       
   136                 changed = HandleUrlChangeCommandL(*item, (newType != oldType));
       
   137             }
       
   138             else if (newType == EAiScutSettingTypeBookmark)
       
   139             {
       
   140                 changed = HandleBookmarkChangeCommandL(*item, (newType != oldType));
       
   141             }
       
   142             else
       
   143             {
       
   144                 changed = HandleAppListChangeCommandL(*item, (newType != oldType));
       
   145             }
       
   146             if ( changed )
       
   147                 {
       
   148                 ResetCurrentListL(current);    
       
   149                 }
       
   150 
       
   151         }
       
   152         iChangeProcessInProgress = EFalse;
       
   153         CleanupStack::PopAndDestroy(array);
       
   154     }
       
   155 }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 TBool CAiScutSettingsContainer::IsChangeDialogShowing()
       
   162 {
       
   163     return (iAppListDialog || iBkmListDialog || iEditDialog);
       
   164 }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CAiScutSettingsContainer::CloseChangeDialog()
       
   171 {
       
   172     TKeyEvent keyEvent;
       
   173 
       
   174     keyEvent.iCode      = EKeyEscape;
       
   175     keyEvent.iScanCode  = EStdKeyEscape;
       
   176     keyEvent.iModifiers = 0;
       
   177     keyEvent.iRepeats   = 0;
       
   178 
       
   179     CCoeControl* dialog = NULL;
       
   180 
       
   181     if (iAppListDialog)
       
   182     {
       
   183         dialog = static_cast<CCoeControl*>(iAppListDialog);
       
   184     }
       
   185     else if (iBkmListDialog)
       
   186     {
       
   187         dialog = static_cast<CCoeControl*>(iBkmListDialog);
       
   188     }
       
   189     else if (iEditDialog)
       
   190     {
       
   191         dialog = static_cast<CCoeControl*>(iEditDialog);
       
   192     }
       
   193 
       
   194     if (dialog)
       
   195     {
       
   196         TRAP_IGNORE(dialog->OfferKeyEventL(keyEvent, EEventKey));
       
   197     }
       
   198 }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CAiScutSettingsContainer::ResetCurrentListL(TInt aIndex)
       
   205 {
       
   206     if (iModel->MdcaCount() == 0)
       
   207     {
       
   208         iListBox->HandleItemRemovalL();
       
   209     }
       
   210     else
       
   211     {
       
   212         iListBox->HandleItemAdditionL();
       
   213     }
       
   214 
       
   215     iListBox->SetCurrentItemIndex(aIndex);
       
   216 
       
   217     CheckMiddleSoftkeyLabelL();
       
   218 }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // From CGSBaseContainer
       
   222 // Constructs the settings listbox.
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CAiScutSettingsContainer::ConstructListBoxL(TInt /*aResLbxId*/)
       
   226 {
       
   227     iListBox->ConstructL(this, EAknListBoxSelectionList);
       
   228 
       
   229     // Set empty listbox's text.
       
   230     HBufC* text = iCoeEnv->AllocReadResourceLC(R_SCUT_SETTINGS_TXT_ALL_FIXED);
       
   231     iListBox->View()->SetListEmptyTextL(*text);
       
   232     CleanupStack::PopAndDestroy(text);
       
   233 
       
   234     iListBox->Model()->SetItemTextArray(iModel);
       
   235     iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   236 }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // Chandles a setting change command to select application from a list.
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 TBool CAiScutSettingsContainer::HandleAppListChangeCommandL(CAiScutSettingsItem& aItem,
       
   243     TBool /*aNew*/)
       
   244 {
       
   245     
       
   246     TBool changed = EFalse;
       
   247     
       
   248     iChangeProcessStopped = EFalse;
       
   249     
       
   250     if (!iModel->AppList()->IsReady())
       
   251     {
       
   252         ShowWaitNoteDialogL(); // Blocks until applist reports that it is ready.
       
   253     }
       
   254     // If wait note was "killed" then don't continue the change process
       
   255     // If the process is not stopped here it could lead to situation where
       
   256     // self is deleted before the ShowWaitNoteDialogL() returns
       
   257     if ( iChangeProcessStopped )
       
   258         {
       
   259         return EFalse;
       
   260         }
       
   261 
       
   262     TUint32 key = aItem.Key();
       
   263     TBool optional  = (0 != (key & KScutFlagBitOptionallyVisible));
       
   264     TBool scrollkey = (0 != ((key & 0xFFFF) < EAiScutSoftKeyLeft));
       
   265 
       
   266     if (optional && scrollkey)
       
   267     {
       
   268         iModel->AppList()->AddExtraItemsL();
       
   269     }
       
   270 
       
   271     TInt index = iModel->AppList()->FindIndex(aItem);
       
   272     TInt oldIndex = index;
       
   273 
       
   274     iAppListDialog = new (ELeave) CAknRadioButtonSettingPage(
       
   275         R_SCUT_SETTINGS_APPLIST_PAGE, index, iModel->AppList());
       
   276 
       
   277     iAppListDialog->SetSettingTextL(aItem.Title());
       
   278     iAppListDialog->ConstructL();
       
   279 
       
   280     if (iAppListDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) &&
       
   281         index != oldIndex)
       
   282     {
       
   283         TUid uid;
       
   284         TPtrC params;
       
   285         TPtrC caption;
       
   286         TAiScutSettingType type;
       
   287         if (iModel->AppList()->GetDataByIndex(index, uid, params, caption, type) == KErrNone)
       
   288         {
       
   289             if ( type == EAiScutSettingTypeUrl )
       
   290                 {
       
   291                 aItem.ChangeUrlL( params );
       
   292                 }
       
   293             else
       
   294                 {                
       
   295                 aItem.ChangeApplicationL(uid, params, caption);
       
   296                 }
       
   297             iModel->SaveItemL(aItem);
       
   298             changed = ETrue;
       
   299         }
       
   300     }
       
   301 
       
   302     if (optional && scrollkey)
       
   303     {
       
   304         iModel->AppList()->RemoveExtraItemsL();
       
   305     }
       
   306 
       
   307     iAppListDialog = NULL;
       
   308     return changed;
       
   309 }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // Chandles a setting change command to select bookmark from a list.
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 TBool CAiScutSettingsContainer::HandleBookmarkChangeCommandL(CAiScutSettingsItem& aItem,
       
   316     TBool /*aNew*/)
       
   317 {
       
   318 
       
   319     TBool changed = EFalse;
       
   320     iModel->BkmList()->GetBookmarkListL();
       
   321     TInt index = iModel->BkmList()->FindIndex(aItem);
       
   322     TInt oldIndex = index;
       
   323 
       
   324     iBkmListDialog = new (ELeave) CAknRadioButtonSettingPage(
       
   325         R_SCUT_SETTINGS_APPLIST_PAGE, index, iModel->BkmList());
       
   326 
       
   327     iBkmListDialog->SetSettingTextL(aItem.Title());
       
   328     iBkmListDialog->ConstructL();
       
   329 
       
   330     if (iBkmListDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) &&
       
   331         index != oldIndex)
       
   332     {
       
   333         TPtrC params;
       
   334         TPtrC caption;
       
   335         if (iModel->BkmList()->GetDataByIndex(index, params, caption) == KErrNone)
       
   336         {
       
   337             aItem.ChangeBookmarkL(params, caption);
       
   338             iModel->SaveItemL(aItem);
       
   339             changed = ETrue;
       
   340         }
       
   341     }
       
   342 
       
   343     iBkmListDialog = NULL;
       
   344     return changed;
       
   345 }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // Chandles a setting change command to edit an URL.
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 TBool CAiScutSettingsContainer::HandleUrlChangeCommandL(CAiScutSettingsItem& aItem,
       
   352     TBool aNew)
       
   353 {
       
   354     TBool changed = EFalse;
       
   355     HBufC* newUrl = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   356     TPtr urlPtr = newUrl->Des();
       
   357 
       
   358     if (!aNew)
       
   359     {
       
   360         urlPtr.Copy(aItem.Value());
       
   361     }
       
   362 
       
   363     if (EditTextL(R_SCUT_TYPE_URL_PAGE , urlPtr))
       
   364     {
       
   365         aItem.ChangeUrlL(urlPtr);
       
   366         iModel->SaveItemL(aItem);
       
   367         changed = ETrue;
       
   368     }
       
   369 
       
   370     CleanupStack::PopAndDestroy(newUrl);
       
   371     return changed;
       
   372 }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 TBool CAiScutSettingsContainer::EditTextL(TInt aResId, TDes& aDes)
       
   379 {
       
   380     TBool ret = EFalse;
       
   381 
       
   382     iEditDialog = new (ELeave) CAknTextSettingPage(aResId, aDes);
       
   383 
       
   384     if (iEditDialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged))
       
   385     {
       
   386         if (aDes.Length())
       
   387         {
       
   388             ret = ETrue;
       
   389         }
       
   390     }
       
   391 
       
   392     iEditDialog = NULL;
       
   393 
       
   394     return ret;
       
   395 }
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // Shows the wait note dialog.
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 void CAiScutSettingsContainer::ShowWaitNoteDialogL()
       
   402 {
       
   403     if (!iWaitDialog)
       
   404     {
       
   405         iWaitDialog = new (ELeave) CAknWaitDialog(
       
   406             (reinterpret_cast<CEikDialog**> (&iWaitDialog)),
       
   407             ETrue                                               // aVisibilityDelayOff
       
   408         );
       
   409         iWaitDialog->ExecuteLD(R_SCUT_WAIT_NOTE);
       
   410     }
       
   411 }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // Hides the wait note dialog.
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void CAiScutSettingsContainer::HideWaitNoteDialog()
       
   418 {
       
   419     if (iWaitDialog)
       
   420     {
       
   421         TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); // deletes the dialog.
       
   422         iWaitDialog = NULL;
       
   423     }
       
   424 }
       
   425 
       
   426 void CAiScutSettingsContainer::StopShortcutChangeProcess()
       
   427 {
       
   428     iChangeProcessStopped = ETrue;
       
   429     HideWaitNoteDialog();
       
   430     if ( IsChangeDialogShowing() )
       
   431         {
       
   432         CloseChangeDialog();    
       
   433         }    
       
   434 }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // Gets Help
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 void CAiScutSettingsContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   441 {
       
   442     aContext.iMajor   = KUidAI;
       
   443     //aContext.iContext = KSET_HLP_PERSONAL_SHORTCUTS; // This is specified in HRH file
       
   444 }
       
   445 
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 // ---------------------------------------------------------------------------
       
   449 //
       
   450 TKeyResponse CAiScutSettingsContainer::OfferKeyEventL(
       
   451     const TKeyEvent& aKeyEvent, TEventCode aType)
       
   452 {
       
   453     switch (aKeyEvent.iCode)
       
   454     {
       
   455     case EKeyUpArrow:
       
   456     case EKeyDownArrow:
       
   457         {
       
   458             TKeyResponse resp = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   459             return resp;
       
   460         }
       
   461 
       
   462     case EKeyLeftArrow:
       
   463     case EKeyRightArrow:
       
   464         // Listbox takes all event even if it doesn't use them:
       
   465         return EKeyWasNotConsumed;
       
   466 		
       
   467     default:
       
   468         break;
       
   469     }
       
   470 
       
   471     // Now it's iListBox's job to process the key event
       
   472     return iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   473 }
       
   474 
       
   475 // ---------------------------------------------------------------------------
       
   476 // Checks if there is a need to update the middle softkey label.
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 void CAiScutSettingsContainer::CheckMiddleSoftkeyLabelL()
       
   480 {
       
   481     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   482     if (cba)
       
   483     {
       
   484         cba->MakeCommandVisible(EAiScutSettingsCmdChange, (iModel->MdcaCount() != 0));
       
   485     }
       
   486 }
       
   487 
       
   488 // End of File.