// -----------------------------------------------------------------------------
// CSIPSettListSIPProfSetADestListItem::EditItemL
// Called before the pop-up list is shown. Updates it, if there was a 
// non-matching destination UID at the start-up 
// -----------------------------------------------------------------------------
//
void CSIPSettListSIPProfSetDestListItem::EditItemL( 
    TBool aCalledFromMenu )
    {
    __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::EditItemL" )
    // Set backup value.
    iBackupValue = iEnumValue;
        
    if ( iEnumValue == KUnknownAPUID )
        {
        // destination was not found, create list for user to change the 
        // destination.
        // The destination will be anyway changed; no matter does the user
        // press Cancel or not..(Chosen destination will be the first one 
        // on the list, if user presses Cancel)        
        CArrayPtr<CAknEnumeratedText>* textArray = NULL;
        CArrayPtr<HBufC>* nullTextArray = NULL;
        InitializeListL( textArray, nullTextArray );     

        if ( textArray->Count() > KErrNone )
            {
            // There might be situation that no destinationss exist.
            iEnumValue = textArray->At( KErrNone )->EnumerationValue();
            }

        SetEnumeratedTextArrays( textArray, nullTextArray );    
        HandleTextArrayUpdateL();
        }
    
    CAknEnumeratedTextPopupSettingItem::EditItemL( aCalledFromMenu );
    }
// -----------------------------------------------------------------------------
// CSIPSettListSIPProfSetDestListItem::CompleteConstructionL
// Fetches and changes the lists after the construction is completed
// -----------------------------------------------------------------------------
//
void CSIPSettListSIPProfSetDestListItem::CompleteConstructionL()
    {
    __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::CompleteConstructionL" )
    CArrayPtr<CAknEnumeratedText>* textArray = NULL;
    CArrayPtr<HBufC>* nullTextArray = NULL;

    CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();    

    // Read the AP list
    InitializeListL( textArray, nullTextArray );    

    // Check that we are pointing to an actual thing, otherwise
    // we need to modify this
    if ( textArray->Count() > KErrNone && !ValueMatches( textArray ) )
        {
        // Should display text 'None' when the AP is not found
        textArray->ResetAndDestroy();
        iEnumValue = KUnknownAPUID;
        }

    // Set new text arrays
    SetEnumeratedTextArrays( textArray, nullTextArray );
    
    // Update the lists internally
    HandleTextArrayUpdateL();
    }
// -----------------------------------------------------------------------------
// CSIPSettListSIPProfSetTypeListItem::CompleteConstructionL
// Fetches and changes the lists after the construction is completed
// -----------------------------------------------------------------------------
//
void CSIPSettListSIPProfSetTypeListItem::CompleteConstructionL()
    {
    __GSLOGSTRING("CSIPSettListSIPProfSetTypeListItem::CompleteConstructionL" )
    CArrayPtr<CAknEnumeratedText>* textArray = NULL;
    CArrayPtr<HBufC>* nullTextArray = NULL;

    CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();    

    // Read the AP list
    InitializeListL( textArray, nullTextArray );    

    // Set new text arrays
    SetEnumeratedTextArrays( textArray, nullTextArray );
    
    // Update the lists internally
    HandleTextArrayUpdateL();
    }
// ----------------------------------------------------------------------------
// CLanguageSettingItem::CompleteConstructionL()
// Update the Language list
// ----------------------------------------------------------------------------
void CLanguageSettingItem::CompleteConstructionL()
{
   CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();

   class CLanguageList * langList = 
      CLanguageList::NewLC(R_WAYFINDER_LANGUAGE_LIST_NEW,
                           *(iData->m_resourceNoExt),
                           *(iData->m_audioBasePath),
                           *(iData->m_audioFormatPrefix),
                           iData->iAllowedLangs
                           );

   CArrayPtr<CAknEnumeratedText> *langs = 
      new (ELeave) CArrayPtrSeg<CAknEnumeratedText>(10);
   CleanupStack::PushL(langs);

   // Left empty to use texts from langs.
   CArrayPtr<HBufC> *poppedUp = new(ELeave) CArrayPtrSeg<HBufC>(10);
   CleanupStack::PushL(poppedUp);

   class TParse * parser = new (ELeave) TParse();
   CleanupStack::PushL(parser);

   class RFs fs;
   fs.Connect();
   CleanupClosePushL(fs);

   // Remember the first shown value
   TInt symbian_code_for_first_element = -1;

   // Only show languages for which we have an .rXX file.
   // Optionally only show those with audio as well.
   for (TInt i = 0; i < langList->Count(); ++i) {
      struct CLanguageList::TWfLanguageList & elem = langList->Get(i);
      
      if (! elem.isAllowed) {
         elem.handle = -1;
         continue;
      }

      if (!iData->m_showLangsWithoutResource) {
         if (!elem.hasRXX) {
            elem.handle = -1;
            continue;
         }
      }

      if ( ! elem.hasAudio ) {
         // Not found, ignore or mark this language
         if (iData->m_showLangsWithoutVoice) {
            _LIT(KStar, "*");
            HBufC * name = HBufC::NewLC(elem.fullname.Length()+1);
            TPtr name_ptr = name->Des();
            name_ptr.Copy(KStar);
            name_ptr.Append(elem.fullname);  
            AddEnumeratedLanguageL(*langs, elem.symbianCode, name);
            CleanupStack::Pop(name); 
            name = NULL;
            if (symbian_code_for_first_element < 0) {
               symbian_code_for_first_element = elem.symbianCode;
            }
         } else {
            elem.handle = -1;
         }
         continue; //continue for loop
      }

      HBufC * name = elem.fullname.AllocLC();
      AddEnumeratedLanguageL(*langs, elem.symbianCode, name);
      CleanupStack::Pop(name);  // FIXME - Is this right? Does
      name = NULL;              // AppendL take over ownership of
                                // the name?
      if (symbian_code_for_first_element < 0) {
         symbian_code_for_first_element = elem.symbianCode;
      }
   }

   fs.Close();
   CleanupStack::PopAndDestroy(/*fs*/); 

   SetEnumeratedTextArrays(langs, poppedUp);

   CleanupStack::PopAndDestroy(parser);

   CleanupStack::Pop(poppedUp);
   CleanupStack::Pop(langs);

   // Does the (old) specified value still exist? Default to 
   // the first element which is "system default" unless prohibited.
   if (IndexFromValue(ExternalValue()) < 0) {
      SetInternalValue(symbian_code_for_first_element);
      SetExternalValue(symbian_code_for_first_element);
   }
   CleanupStack::PopAndDestroy(langList);
}
void CIAPSettingItem::CompleteConstructionL()
{
   _LIT(KmRouter, "mroute");

   CArrayPtr<CAknEnumeratedText> * iaps = new(ELeave) CArrayPtrSeg<CAknEnumeratedText>(10);
   CleanupStack::PushL(iaps);
   CArrayPtr<HBufC> * poppedUp = new(ELeave) CArrayPtrSeg<HBufC>(10);
   CleanupStack::PushL(poppedUp);

   CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();

   // The selection of IAP that indicates "always ask"
   HBufC * buf;
   buf = CEikonEnv::Static()->AllocReadResourceL( R_SETTINGS_IAP_ALWAYS_ASK );
   iaps->AppendL(new(ELeave) CAknEnumeratedText(-1, buf ));
   // The selection of IAP that indicates "system default is only shown in
   // development mode, not in release mode.
   if ( ! iRelease ) {
      buf = CEikonEnv::Static()->AllocReadResourceL( R_SETTINGS_IAP_SYSTEM_DEFAULT );
      iaps->AppendL(new(ELeave) CAknEnumeratedText(-2, buf ));
   }


#ifdef NAV2_CLIENT_SERIES60_V2
   CCommsDatabase * comdb = CCommsDatabase::NewL();
#else
   CCommsDatabase * comdb = CCommsDatabase::NewL(EDatabaseTypeUnspecified);
#endif
   CleanupStack::PushL(comdb);
   CCommsDbTableView * iaptable = comdb->OpenTableLC( TPtrC( IAP ) );

   TInt retval;
   retval = iaptable->GotoFirstRecord();

   // display all IAPs except mrouter
   while (retval == KErrNone) {
      HBufC * iap_name = iaptable->ReadLongTextLC( TPtrC( COMMDB_NAME) );
      if ( KErrNotFound == iap_name->FindF(KmRouter) ) {
         TUint32 iap_id;
         iaptable->ReadUintL( TPtrC( COMMDB_ID), iap_id );
         iaps->AppendL(new(ELeave) CAknEnumeratedText(iap_id, iap_name ));
      }
      CleanupStack::Pop(iap_name);   // FIXME - Is this right? Does AppendL take over ownership of the iap name?
      retval = iaptable->GotoNextRecord();
   }

   CleanupStack::PopAndDestroy(iaptable);
   CleanupStack::PopAndDestroy(comdb);

   SetEnumeratedTextArrays(iaps, poppedUp);
   CleanupStack::Pop(poppedUp);
   CleanupStack::Pop(iaps);

   // Does the (old) specified iap still exist? Default to 
   // "always ask" otherwise.
   if (IndexFromValue(ExternalValue()) < 0) {
      SetInternalValue(-1);
      SetExternalValue(-1);
   }


}