phonebookui/Phonebook/View/src/CPbkMemoryEntryDefaultsDlg.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *       Phonebook Memory entry Defaults dialog methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkMemoryEntryDefaultsDlg.h"
       
    22 #include <aknlists.h>    // EikControlFactory
       
    23 #include <StringLoader.h>
       
    24 #include <featmgr.h>
       
    25 
       
    26 #include <PbkView.rsg>
       
    27 #include "MPbkClipListBoxText.h"
       
    28 #include "CPbkFieldListBoxModel.h"
       
    29 #include <CPbkIconArray.h>
       
    30 
       
    31 // PbkEng classes
       
    32 #include <CPbkContactEngine.h>
       
    33 #include <CPbkFieldInfo.h>
       
    34 #include <CPbkConstants.h>
       
    35 #include <CPbkContactItem.h>
       
    36 #include <DigCleanupResetPointer.h>
       
    37 #include <CPbkExtGlobals.h>
       
    38 #include <MPbkExtensionFactory.h>
       
    39 
       
    40 #include <PbkDebug.h>
       
    41 
       
    42 // Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 // LOCAL CONSTANTS AND MACROS
       
    46 
       
    47 /**
       
    48  * Enum for default field types. Defines also order of items in list.
       
    49  *
       
    50  * Because the list returns the index of the currently displayed item,
       
    51  * it's been decided to treat the two versions of SMS (regular SMS versus
       
    52  * the enhanced email-over-sms version) the same when populating the list,
       
    53  * and differentiate between the two when an SMS operation is selected.
       
    54  */
       
    55 enum TDefaults
       
    56     {
       
    57     EPbkCallDefault = 0,
       
    58     EPbkVideoDefault,
       
    59     EPbkVoipDefault,
       
    60     EPbkPocDefault,
       
    61     EPbkSmsDefault,
       
    62     EPbkMmsDefault,
       
    63     EPbkEmailDefault,
       
    64     KPbkNumberOfDefaults
       
    65     };
       
    66 
       
    67 static const TInt KMaxIntLength = 15;
       
    68 
       
    69 #ifdef _DEBUG
       
    70 enum TPanicCode
       
    71     {
       
    72     EPanicPostCond_Constructor = 1,
       
    73     EPanicPostCond_ConstructL,
       
    74     EPanicPreCond_FixIndex
       
    75     };
       
    76 static void Panic(TPanicCode aReason)
       
    77     {
       
    78     _LIT(KPanicText, "CPbkMemoryEntryDefaultsDlg");
       
    79     User::Panic(KPanicText, aReason);
       
    80     }
       
    81 #endif // _DEBUG
       
    82 
       
    83 } // namespace
       
    84 
       
    85 
       
    86 // MODULE DATA STRUCTURES
       
    87 
       
    88 NONSHARABLE_CLASS(CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultAssignDlg) :
       
    89         public CBase,
       
    90         public MPbkClipListBoxText
       
    91     {
       
    92     public:  // Interface
       
    93         CPbkMemoryEntryDefaultAssignDlg();
       
    94         TInt ExecuteLD(CPbkFieldArray& aArray);
       
    95         ~CPbkMemoryEntryDefaultAssignDlg();
       
    96 
       
    97     public:  // from MPbkClipListBoxText
       
    98         TBool ClipFromBeginning(TDes& aBuffer, TInt aItemIndex,
       
    99             TInt aSubCellNumber);
       
   100 
       
   101     private: // Data
       
   102         /// Own: field selection listbox
       
   103         CEikFormattedCellListBox* iListBox;
       
   104         /// Own: popup list for the listbox
       
   105         CAknPopupList* iPopupList;
       
   106         /// Ref: Referred TBool is set ETrue in destructor
       
   107         TBool* iDestroyedPtr;
       
   108     };
       
   109 
       
   110 /**
       
   111  * Returns default field identified by aDefaultIndex from aContact
       
   112  * or NULL if the default is not set.
       
   113  */
       
   114 TPbkContactItemField* DefaultField
       
   115         (const CPbkContactItem& aContact, TInt aDefaultIndex)
       
   116     {
       
   117     TPbkContactItemField* result = NULL;
       
   118     switch (aDefaultIndex)
       
   119         {
       
   120         case EPbkCallDefault:
       
   121             {
       
   122             result = aContact.DefaultPhoneNumberField();
       
   123             break;
       
   124             }
       
   125         case EPbkVideoDefault:
       
   126             {
       
   127             result = aContact.DefaultVideoNumberField();
       
   128             break;
       
   129             }
       
   130         case EPbkMmsDefault:
       
   131             {
       
   132             result = aContact.DefaultMmsField();
       
   133             break;
       
   134             }
       
   135         case EPbkSmsDefault:
       
   136             {
       
   137             if (FeatureManager::FeatureSupported(KFeatureIdEmailOverSms))
       
   138                 {
       
   139                 result = aContact.DefaultEmailOverSmsField();
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 result = aContact.DefaultSmsField();
       
   144                 }
       
   145             break;
       
   146             }
       
   147         case EPbkEmailDefault:
       
   148             {
       
   149             result = aContact.DefaultEmailField();
       
   150             break;
       
   151             }
       
   152         case EPbkVoipDefault:
       
   153             {
       
   154             result = aContact.DefaultVoipField();
       
   155             break;
       
   156             }
       
   157         case EPbkPocDefault:
       
   158             {
       
   159             result = aContact.DefaultPocField();
       
   160             break;
       
   161             }
       
   162         default:
       
   163             {
       
   164             break;
       
   165             }
       
   166         }
       
   167     return result;
       
   168     }
       
   169 
       
   170 /**
       
   171  * Returns the default UI text for default field identified by aDefaultIndex.
       
   172  */
       
   173 HBufC* DefaultFieldTextLC(TInt aDefaultIndex)
       
   174     {
       
   175     HBufC* result = NULL;
       
   176     switch (aDefaultIndex)
       
   177         {
       
   178         case EPbkCallDefault:
       
   179             {
       
   180             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_CALL_DEFAULT);
       
   181             break;
       
   182             }
       
   183         case EPbkVideoDefault:
       
   184             {
       
   185             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_VIDEO_DEFAULT);
       
   186             break;
       
   187             }
       
   188         case EPbkMmsDefault:
       
   189             {
       
   190             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_MMS_DEFAULT);
       
   191             break;
       
   192             }
       
   193         case EPbkSmsDefault:
       
   194             {
       
   195             // this is the same text for either SMS or EmailOverSms
       
   196             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_SMS_DEFAULT);
       
   197             break;
       
   198             }
       
   199         case EPbkEmailDefault:
       
   200             {
       
   201             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_EMAIL_DEFAULT);
       
   202             break;
       
   203             }
       
   204         case EPbkVoipDefault:
       
   205             {
       
   206             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_VOIP_DEFAULT);
       
   207             break;
       
   208             }
       
   209         case EPbkPocDefault:
       
   210             {
       
   211             result = StringLoader::LoadLC(R_QTN_PHOB_SETI_POC_DEFAULT);
       
   212             break;
       
   213             }
       
   214         default:
       
   215             {
       
   216             break;
       
   217             }
       
   218         }
       
   219     return result;
       
   220     }
       
   221 
       
   222 /**
       
   223  * Returns true if aField is an applicable default field of type identified
       
   224  * by aDefaultIndex.
       
   225  */
       
   226 TBool IsApplicableDefaultField
       
   227         (const TPbkContactItemField& aField, TInt aDefaultIndex)
       
   228     {
       
   229     TBool result = EFalse;
       
   230 
       
   231     switch (aDefaultIndex)
       
   232         {
       
   233         case EPbkCallDefault:
       
   234             {
       
   235             if ( aField.FieldInfo().IsPhoneNumberField() &&
       
   236                  aField.Text().Length() > 0 )
       
   237                 {
       
   238                 result = ETrue;
       
   239                 }
       
   240             break;
       
   241             }
       
   242 
       
   243         case EPbkVideoDefault:
       
   244             {
       
   245             if ( aField.FieldInfo().IsPhoneNumberField() &&
       
   246                  aField.Text().Length() > 0 )
       
   247                 {
       
   248                 if ( ( aField.FieldInfo().FieldId() != EPbkFieldIdFaxNumber ) &&
       
   249                      ( aField.FieldInfo().FieldId() != EPbkFieldIdPagerNumber ) )
       
   250                     {
       
   251                     result = ETrue;
       
   252                     }
       
   253                 }
       
   254             break;
       
   255             }
       
   256 
       
   257         case EPbkSmsDefault:
       
   258             {
       
   259             if (FeatureManager::FeatureSupported(KFeatureIdEmailOverSms))
       
   260                 {
       
   261                 if (aField.FieldInfo().IsEmailOverSmsField() &&
       
   262                     aField.Text().Length() > 0)
       
   263                     {
       
   264                     result = ETrue;
       
   265                     }
       
   266                 }
       
   267             else
       
   268                 {
       
   269                 if (aField.FieldInfo().IsPhoneNumberField() &&
       
   270                     aField.Text().Length() > 0)
       
   271                     {
       
   272                     result = ETrue;
       
   273                     }
       
   274                 }
       
   275             break;
       
   276             }
       
   277 
       
   278         case EPbkMmsDefault:
       
   279             {
       
   280             if (aField.FieldInfo().IsMmsField() &&
       
   281                 aField.Text().Length() > 0)
       
   282                 {
       
   283                 result = ETrue;
       
   284                 }
       
   285             break;
       
   286             }
       
   287         case EPbkEmailDefault:
       
   288             {
       
   289             if (aField.FieldInfo().FieldId()==EPbkFieldIdEmailAddress &&
       
   290                 aField.Text().Length() > 0)
       
   291                 {
       
   292                 result = ETrue;
       
   293                 }
       
   294             break;
       
   295             }
       
   296         case EPbkVoipDefault:
       
   297             {
       
   298             if ( aField.FieldInfo().IsVoipField() &&
       
   299                  aField.Text().Length() > 0 )
       
   300                 {
       
   301                 result = ETrue;
       
   302 
       
   303                 }
       
   304             break;
       
   305             }
       
   306         case EPbkPocDefault:
       
   307             {
       
   308             if (aField.FieldInfo().IsPocField() &&
       
   309                 aField.Text().Length() > 0)
       
   310                 {
       
   311                 result = ETrue;
       
   312                 }
       
   313             break;
       
   314             }
       
   315         default:
       
   316             {
       
   317             break;
       
   318             }
       
   319         }
       
   320 
       
   321     // Check that the field contains something
       
   322     if (aField.IsEmptyOrAllSpaces())
       
   323         {
       
   324         result = EFalse;
       
   325         }
       
   326 
       
   327     return result;
       
   328     }
       
   329 
       
   330 /**
       
   331  * Sets aField as the default field for aContact identified by aField.
       
   332  */
       
   333 TBool SetDefaultL
       
   334         (CPbkContactItem& aContact,
       
   335         TInt aDefaultIndex,
       
   336         TPbkContactItemField* aField)
       
   337     {
       
   338     TBool result = EFalse;
       
   339     switch (aDefaultIndex)
       
   340         {
       
   341         case EPbkCallDefault:
       
   342             {
       
   343             aContact.SetDefaultPhoneNumberFieldL(aField);
       
   344             result = ETrue;
       
   345             break;
       
   346             }
       
   347         case EPbkVideoDefault:
       
   348             {
       
   349             aContact.SetDefaultVideoNumberFieldL(aField);
       
   350             result = ETrue;
       
   351             break;
       
   352             }
       
   353         case EPbkMmsDefault:
       
   354             {
       
   355             aContact.SetDefaultMmsFieldL(aField);
       
   356             result = ETrue;
       
   357             break;
       
   358             }
       
   359         case EPbkSmsDefault:
       
   360             {
       
   361             if (FeatureManager::FeatureSupported(KFeatureIdEmailOverSms))
       
   362                 {
       
   363                 aContact.SetDefaultEmailOverSmsFieldL(aField);
       
   364                 }
       
   365             else
       
   366                 {
       
   367                 aContact.SetDefaultSmsFieldL(aField);
       
   368                 }
       
   369 
       
   370             result = ETrue;
       
   371             break;
       
   372             }
       
   373         case EPbkEmailDefault:
       
   374             {
       
   375             aContact.SetDefaultEmailFieldL(aField);
       
   376             result = ETrue;
       
   377             break;
       
   378             }
       
   379         case EPbkVoipDefault:
       
   380             {
       
   381             aContact.SetDefaultVoipFieldL(aField);
       
   382             result = ETrue;
       
   383             break;
       
   384             }
       
   385         case EPbkPocDefault:
       
   386             {
       
   387             aContact.SetDefaultPocFieldL(aField);
       
   388             result = ETrue;
       
   389             break;
       
   390             }
       
   391         default:
       
   392             {
       
   393             break;
       
   394             }
       
   395         }
       
   396     return result;
       
   397     }
       
   398 
       
   399 
       
   400 // ================= MEMBER FUNCTIONS =======================
       
   401 
       
   402 inline CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultsDlg
       
   403         (CPbkContactEngine& aEngine, TContactItemId aContactId) :
       
   404         iContactId(aContactId),
       
   405         iEngine(aEngine)
       
   406     {
       
   407     __ASSERT_DEBUG(
       
   408         iContactId==aContactId && &iEngine==&aEngine && !iListBox &&
       
   409         !iDefaultAssignDlg && !iDestroyedPtr,
       
   410         Panic(EPanicPostCond_Constructor));
       
   411     }
       
   412 
       
   413 EXPORT_C CPbkMemoryEntryDefaultsDlg* CPbkMemoryEntryDefaultsDlg::NewL
       
   414         (TContactItemId aContactId,
       
   415         CPbkContactEngine& aEngine)
       
   416     {
       
   417     CPbkMemoryEntryDefaultsDlg* self = new(ELeave)
       
   418         CPbkMemoryEntryDefaultsDlg(aEngine, aContactId);
       
   419     CleanupStack::PushL(self);
       
   420     self->ConstructL();
       
   421     CleanupStack::Pop(); // self
       
   422     return self;
       
   423     }
       
   424 
       
   425 EXPORT_C void CPbkMemoryEntryDefaultsDlg::ExecuteLD()
       
   426     {
       
   427     CAknPopupList::ExecuteLD();
       
   428     }
       
   429 
       
   430 CPbkMemoryEntryDefaultsDlg::~CPbkMemoryEntryDefaultsDlg()
       
   431     {
       
   432     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   433         ("CPbkMemoryEntryDefaultsDlg destructor start"));
       
   434     if (iDestroyedPtr)
       
   435         {
       
   436         *iDestroyedPtr = ETrue;
       
   437         }
       
   438     delete iDefaultAssignDlg;
       
   439     delete iListBox;
       
   440 
       
   441     FeatureManager::UnInitializeLib();
       
   442 
       
   443     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   444         ("CPbkMemoryEntryDefaultsDlg destructor end"));
       
   445     }
       
   446 
       
   447 void CPbkMemoryEntryDefaultsDlg::ProcessCommandL(TInt aCommandId)
       
   448     {
       
   449     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   450         ("CPbkMemoryEntryDefaultsDlg::ProcessCommandL start"));
       
   451 
       
   452     switch (aCommandId)
       
   453         {
       
   454         case EAknSoftkeyOk:
       
   455             {
       
   456             if (DefaultsAssignPopupL(iListBox->CurrentItemIndex()))
       
   457                 {
       
   458                 CreateLinesL();
       
   459                 iListBox->DrawDeferred();
       
   460                 }
       
   461                 //  If DefaultsAssignPopupL returns false, this object
       
   462                 //  might be destroyed
       
   463             break;
       
   464             }
       
   465 
       
   466         default:
       
   467             {
       
   468             PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   469                 ("About to call CAknPopupList::ProcessCommandL"));
       
   470             CAknPopupList::ProcessCommandL(aCommandId);
       
   471             PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   472                 ("Called CAknPopupList::ProcessCommandL"));
       
   473             break;
       
   474             }
       
   475         }
       
   476     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   477         ("CPbkMemoryEntryDefaultsDlg::ProcessCommandL end"));
       
   478     }
       
   479 
       
   480 void CPbkMemoryEntryDefaultsDlg::HandleListBoxEventL
       
   481         (CEikListBox* aListBox, TListBoxEvent aEventType)
       
   482     {
       
   483     // Respond to events from listboxitem
       
   484     if (aListBox == iListBox)
       
   485         {
       
   486         if (aEventType == MEikListBoxObserver::EEventEnterKeyPressed)
       
   487             {
       
   488             // Ok/Enter key pressed, command is same as EAknSoftkeyOk
       
   489             ProcessCommandL(EAknSoftkeyOk);
       
   490             }
       
   491         }
       
   492     }
       
   493 
       
   494 void CPbkMemoryEntryDefaultsDlg::CreateLinesL() const
       
   495     {
       
   496     CPbkContactItem* item = iEngine.ReadContactLC(iContactId);
       
   497 
       
   498     CDesCArray* lines = static_cast<CDesCArray*>
       
   499         (iListBox->Model()->ItemTextArray());
       
   500     lines->Reset();
       
   501 
       
   502     _LIT(KFormat, "%S\t%S");
       
   503     HBufC* noDefault = StringLoader::LoadLC(R_QTN_PHOB_SETI_NO_DEFAULT);
       
   504 
       
   505     for (TInt row=0; row < KPbkNumberOfDefaults; ++row)
       
   506         {
       
   507         // Only supported lines are created
       
   508         if (IsSupported(row))
       
   509             {
       
   510             HBufC* defaultFieldText = DefaultFieldTextLC(row);
       
   511             const TPbkContactItemField* field = DefaultField(*item, row);
       
   512             TPtrC label;
       
   513             if(field)
       
   514                 {
       
   515                 label.Set(field->Label());
       
   516                 }
       
   517             else
       
   518                 {
       
   519                 label.Set(*noDefault);
       
   520                 }
       
   521 
       
   522             // Allocate and format the listbox line
       
   523             HBufC* lineBuf = HBufC::NewLC(KFormat().Length()
       
   524                 + defaultFieldText->Length() + label.Length());
       
   525             TPtr line(lineBuf->Des());
       
   526             line.Format(KFormat, defaultFieldText, &label);
       
   527 
       
   528             lines->AppendL(line);
       
   529 
       
   530             // Cleanup
       
   531             CleanupStack::PopAndDestroy(2);  // lineBuf, defaultFieldText
       
   532             }
       
   533         }
       
   534 
       
   535     CleanupStack::PopAndDestroy(2); // noDefault, item
       
   536     }
       
   537 
       
   538 TBool CPbkMemoryEntryDefaultsDlg::DefaultsAssignPopupL(TInt aDefaultIndex)
       
   539     {
       
   540     TBool thisDestroyed = EFalse;
       
   541     iDestroyedPtr = &thisDestroyed;
       
   542 
       
   543     CPbkContactItem* item = iEngine.OpenContactL(iContactId);
       
   544     CleanupStack::PushL(item);
       
   545 
       
   546     CPbkFieldArray* fields = new(ELeave) CPbkFieldArray(4 /*granularity*/);
       
   547     CleanupStack::PushL(fields);
       
   548     const TInt fieldCount = item->CardFields().Count();
       
   549     for (TInt i=0; i < fieldCount; ++i)
       
   550         {
       
   551         TPbkContactItemField& field = item->CardFields()[i];
       
   552         TInt theIndex = FixIndex(aDefaultIndex); // we have to fix the index
       
   553         if (IsApplicableDefaultField(field, theIndex))
       
   554             {
       
   555             fields->AppendL(field);
       
   556             }
       
   557         }
       
   558 
       
   559     iDefaultAssignDlg = new(ELeave) CPbkMemoryEntryDefaultAssignDlg;
       
   560     TInt fieldIndex = 0;
       
   561     TRAPD(err, fieldIndex = iDefaultAssignDlg->ExecuteLD(*fields));
       
   562     iDefaultAssignDlg = NULL;
       
   563     if (err)
       
   564         {
       
   565         User::Leave(err);
       
   566         }
       
   567 
       
   568     TBool result = EFalse;
       
   569     if (!thisDestroyed && fieldIndex >= 0)
       
   570         {
       
   571         TPbkContactItemField* field = NULL;
       
   572         if (fieldIndex < fields->Count())
       
   573             {
       
   574             field = &(*fields)[fieldIndex];
       
   575             }
       
   576             TInt theIndex = FixIndex(aDefaultIndex); // we have to fix the index
       
   577             result = SetDefaultL(*item, theIndex, field);
       
   578         }
       
   579 
       
   580     CleanupStack::PopAndDestroy(fields);
       
   581 
       
   582     if (result)
       
   583         {
       
   584         iEngine.CommitContactL(*item);
       
   585         }
       
   586     else
       
   587         {
       
   588         iEngine.CloseContactL(iContactId);
       
   589         }
       
   590 
       
   591     CleanupStack::PopAndDestroy(item);
       
   592 
       
   593     return result;
       
   594     }
       
   595 
       
   596 void CPbkMemoryEntryDefaultsDlg::ConstructL()
       
   597     {
       
   598     // initialize feature manager
       
   599     FeatureManager::InitializeLibL();
       
   600 
       
   601     // Create a list box
       
   602     iListBox = static_cast<CEikColumnListBox*>
       
   603         (EikControlFactory::CreateByTypeL
       
   604             (EAknCtMenuDoublePopupMenuListBox).iControl);
       
   605 
       
   606     CAknPopupList::ConstructL
       
   607         (iListBox, R_PBK_SOFTKEYS_ASSIGN_BACK,
       
   608         AknPopupLayouts::EMenuDoubleWindow);
       
   609 
       
   610     // Init list box
       
   611     iListBox->ConstructL(this, CEikListBox::ELeftDownInViewRect);
       
   612     iListBox->CreateScrollBarFrameL(ETrue);
       
   613     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   614         (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   615 
       
   616     // set title of popuplist
       
   617     HBufC* heading = StringLoader::LoadLC(R_QTN_PHOB_TITLE_DEFAULT_SETTINGS);
       
   618     SetTitleL(*heading);
       
   619     CleanupStack::PopAndDestroy(heading);
       
   620 
       
   621     CreateLinesL();
       
   622 
       
   623     __ASSERT_DEBUG(
       
   624         iListBox && !iDefaultAssignDlg && !iDestroyedPtr,
       
   625         Panic(EPanicPostCond_ConstructL));
       
   626     }
       
   627 
       
   628 
       
   629 ////////////////////////////////////////////////////////////
       
   630 // CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultAssignDlg
       
   631 
       
   632 inline CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultAssignDlg::
       
   633         CPbkMemoryEntryDefaultAssignDlg()
       
   634     {
       
   635     // CBase::operator new(TLeave) will reset members
       
   636     }
       
   637 
       
   638 TInt CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultAssignDlg::ExecuteLD
       
   639         (CPbkFieldArray& aArray)
       
   640     {
       
   641     CleanupStack::PushL(this);
       
   642     TBool thisDestroyed = EFalse;
       
   643     iDestroyedPtr = &thisDestroyed;
       
   644 
       
   645     // Create a list box
       
   646     iListBox = static_cast<CEikFormattedCellListBox*>
       
   647         (EikControlFactory::CreateByTypeL
       
   648             (EAknCtDoubleGraphicPopupMenuListBox).iControl);
       
   649 
       
   650     // Create a popup list
       
   651     CAknPopupList* popupList = CAknPopupList::NewL
       
   652         (iListBox, R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT,
       
   653             AknPopupLayouts::EMenuDoubleLargeGraphicWindow);
       
   654 
       
   655     CleanupStack::PushL(popupList);
       
   656 
       
   657     // Init list box
       
   658     iListBox->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
   659     iListBox->CreateScrollBarFrameL(ETrue);
       
   660     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   661         (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   662 
       
   663     // set title of popuplist
       
   664     // Select number §qtn.phob.title.select.default§
       
   665     HBufC* heading = StringLoader::LoadLC(R_QTN_PHOB_TITLE_SELECT_DEFAULT);
       
   666     popupList->SetTitleL(*heading);
       
   667     CleanupStack::PopAndDestroy(heading);
       
   668 
       
   669     CPbkIconArray* iconArray = new(ELeave) CPbkIconArray(4 /*granularity*/);
       
   670     CleanupStack::PushL(iconArray);
       
   671     iconArray->ConstructFromResourceL(R_PBK_FIELDTYPE_ICONS);
       
   672 
       
   673     // get extension factory for setting extension icons
       
   674     CPbkExtGlobals* extGlobal = CPbkExtGlobals::InstanceL();
       
   675     extGlobal->PushL();
       
   676     MPbkExtensionFactory& factory = extGlobal->FactoryL();
       
   677     factory.AddPbkFieldIconsL(NULL, iconArray);
       
   678     CleanupStack::PopAndDestroy(extGlobal);
       
   679 
       
   680     CleanupStack::Pop();  // iconArray
       
   681     iListBox->ItemDrawer()->ColumnData()->SetIconArray(iconArray);
       
   682 
       
   683     // create model
       
   684     HBufC* timeFormat = CCoeEnv::Static()->AllocReadResourceLC
       
   685         (R_QTN_DATE_USUAL);
       
   686 
       
   687     CPbkFieldListBoxModel::TParams params(aArray, *timeFormat, *iconArray);
       
   688     CPbkFieldListBoxModel* listBoxModel = CPbkFieldListBoxModel::NewL(params);
       
   689     CleanupStack::PopAndDestroy(timeFormat);
       
   690     listBoxModel->SetClipper(*this);
       
   691 
       
   692     // insert TEXT_NO_DEFAULT as the last item to the array
       
   693     CPbkFieldListBoxRow* row = CPbkFieldListBoxRow::NewL();
       
   694     CleanupStack::PushL(row);
       
   695     TBuf<KMaxIntLength> iconBuffer;
       
   696     _LIT(KIcon, "%d");
       
   697     iconBuffer.Format(KIcon, iconArray->FindIcon(EPbkqgn_prop_nrtyp_empty));
       
   698     row->AppendColumnL(iconBuffer);
       
   699     HBufC* text = StringLoader::LoadLC(R_QTN_PHOB_SETI_NO_DEFAULT);  // LC
       
   700     row->AppendColumnL(*text);
       
   701     CleanupStack::PopAndDestroy(text);
       
   702     row->AppendColumnL(KNullDesC); // empty data field
       
   703     listBoxModel->AppendRowL(row);
       
   704     CleanupStack::Pop(row);
       
   705 
       
   706     iListBox->Model()->SetItemTextArray(listBoxModel);
       
   707     iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
   708     iListBox->Reset();
       
   709 
       
   710     // show popuplist dialog
       
   711     TInt index = -1;
       
   712     TBool res = EFalse;
       
   713     CleanupStack::Pop();  // popupList
       
   714     iPopupList = popupList;
       
   715     TRAPD(err, res = iPopupList->ExecuteLD());
       
   716 
       
   717     // Reset iPopupList member
       
   718     if (!thisDestroyed)
       
   719         {
       
   720         iPopupList = NULL;
       
   721         }
       
   722     // Rethrow any error
       
   723     if (err != KErrNone)
       
   724         {
       
   725         User::Leave(err);
       
   726         }
       
   727 
       
   728     if (thisDestroyed)
       
   729         {
       
   730         // this object has been destroyed
       
   731         index = KErrNotFound;
       
   732         CleanupStack::Pop();  // this
       
   733         }
       
   734     else
       
   735         {
       
   736         if (res)
       
   737             {
       
   738             index = iListBox->CurrentItemIndex();
       
   739             }
       
   740         CleanupStack::PopAndDestroy(); // this
       
   741         }
       
   742 
       
   743     return index;
       
   744     }
       
   745 
       
   746 CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultAssignDlg::
       
   747         ~CPbkMemoryEntryDefaultAssignDlg()
       
   748     {
       
   749     if (iDestroyedPtr)
       
   750         {
       
   751         *iDestroyedPtr = ETrue;
       
   752         }
       
   753     if (iPopupList)
       
   754         {
       
   755         iPopupList->CancelPopup();
       
   756         }
       
   757     delete iListBox;
       
   758     }
       
   759 
       
   760 TBool CPbkMemoryEntryDefaultsDlg::CPbkMemoryEntryDefaultAssignDlg::
       
   761         ClipFromBeginning (TDes& aBuffer, TInt aItemIndex,
       
   762             TInt aSubCellNumber)
       
   763     {
       
   764     return AknTextUtils::ClipToFit
       
   765         (aBuffer, AknTextUtils::EClipFromBeginning, iListBox,
       
   766         aItemIndex, aSubCellNumber);
       
   767     }
       
   768 
       
   769 
       
   770 TBool CPbkMemoryEntryDefaultsDlg::IsSupported(TInt aDefaults) const
       
   771     {
       
   772     TBool ret(ETrue);
       
   773 
       
   774     // Skip the line if MMS field not supported
       
   775     if ( aDefaults == EPbkMmsDefault &&
       
   776         !FeatureManager::FeatureSupported(KFeatureIdMMS))
       
   777         {
       
   778         ret = EFalse;
       
   779         }
       
   780     // Skip the line if Email field not supported
       
   781     else if ( aDefaults == EPbkEmailDefault &&
       
   782         !FeatureManager::FeatureSupported(KFeatureIdEmailUi))
       
   783         {
       
   784         ret = EFalse;
       
   785         }
       
   786     // Do not add video fields if they are not enabled
       
   787     else if ( aDefaults == EPbkVideoDefault &&
       
   788             !iEngine.Constants()->LocallyVariatedFeatureEnabled
       
   789                 (EPbkLVAddVideoTelephonyFields))
       
   790         {
       
   791         ret = EFalse;
       
   792         }
       
   793     // Do not add Voip fields if they are not enabled
       
   794     else if ( aDefaults == EPbkVoipDefault &&
       
   795               !FeatureManager::FeatureSupported(KFeatureIdCommonVoip) )
       
   796         {
       
   797         ret = EFalse;
       
   798         }
       
   799     // Do not add POC fields if they are not enabled
       
   800     else if ( aDefaults == EPbkPocDefault &&
       
   801             !iEngine.Constants()->LocallyVariatedFeatureEnabled(EPbkLVPOC) )
       
   802         {
       
   803         ret = EFalse;
       
   804         }
       
   805 
       
   806     return ret;
       
   807     }
       
   808 
       
   809 /**
       
   810  * This method corrects the given focus index to map with TDefaults enum.
       
   811  */
       
   812 inline TInt CPbkMemoryEntryDefaultsDlg::FixIndex(TInt aIndex) const
       
   813     {
       
   814     __ASSERT_DEBUG(aIndex < KPbkNumberOfDefaults,
       
   815         Panic(EPanicPreCond_FixIndex));
       
   816 
       
   817     TInt ret = aIndex;
       
   818 
       
   819     for (TInt i=0; i <= ret; ++i)
       
   820         {
       
   821         // If the default in question is not supported,
       
   822         // add one to the index, since there was a missing row
       
   823         if (!IsSupported(i))
       
   824             {
       
   825             ++ret;
       
   826             }
       
   827         }
       
   828     return ret;
       
   829     }
       
   830 
       
   831 //  End of File