sipplugins/sippsipsettingsui/src/sipsettlistsipprofsetdestlistitem.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2007 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:  The modified list item for the destinations
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include    <akntitle.h>
       
    23 #include    <StringLoader.h>
       
    24 #include    <gssipsettingspluginrsc.rsg> //GUI Resource
       
    25 #include    <aknnotewrappers.h>
       
    26 #include    "sipsettlistsipprofsetdestlistitem.h"
       
    27 #include    "sipsettlistsipprofsetmodel.h"
       
    28 #include    "gssippluginlogger.h"
       
    29 // LOCAL CONSTANTS AND MACROS
       
    30 
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CSIPSettListSIPProfSetDestListItem::CSIPSettListSIPProfSetDestListItem
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSIPSettListSIPProfSetDestListItem::CSIPSettListSIPProfSetDestListItem(         
       
    42     TInt aResourceId, 
       
    43 	TInt& aIndex,
       
    44     CSIPSettListSIPProfSetModel* aModel ) :
       
    45     CAknEnumeratedTextPopupSettingItem( aResourceId, aIndex ),
       
    46 	iModel( aModel ),
       
    47     iEnumValue( aIndex ),
       
    48     iBackupValue( aIndex )
       
    49     {
       
    50     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::CSIPSettListSIPProfSetDestListItem" )
       
    51     }
       
    52    
       
    53 // Destructor
       
    54 CSIPSettListSIPProfSetDestListItem::~CSIPSettListSIPProfSetDestListItem()
       
    55     {
       
    56     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::~CSIPSettListSIPProfSetDestListItem" )  
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CSIPSettListSIPProfSetDestListItem::ValueMatches
       
    61 // Compares enumeration values to see if a match can be found from
       
    62 // the list of current destinations
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 TBool CSIPSettListSIPProfSetDestListItem::ValueMatches(
       
    66     CArrayPtr<CAknEnumeratedText>* aArray )
       
    67     {
       
    68     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::ValueMatches" )
       
    69     TInt i( 0 );
       
    70     TBool found = EFalse;
       
    71     TInt count( aArray->Count() );
       
    72 
       
    73     for ( i = 0; i < count; i++ )
       
    74         {
       
    75         if ( aArray->At( i )->EnumerationValue() == iEnumValue )
       
    76             {
       
    77             found = ETrue;
       
    78             i = count;
       
    79             }
       
    80         }
       
    81 
       
    82     return found;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CSIPSettListSIPProfSetDestListItem::InitializeListL()
       
    87 // Initializes the enumeration list/txt pairs for the pop-up list
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CSIPSettListSIPProfSetDestListItem::InitializeListL( 
       
    91     CArrayPtr<CAknEnumeratedText>*& aTextArray,
       
    92     CArrayPtr<HBufC>*& aNullTextArray )
       
    93     {
       
    94     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::InitializeListL" )
       
    95     // The text-enumerated thing pair
       
    96     aTextArray = new ( ELeave ) CArrayPtrFlat<CAknEnumeratedText>( KTextArray );
       
    97     TCleanupItem clItem( ResetAndDestroy, aTextArray );
       
    98     CleanupStack::PushL( clItem );
       
    99 
       
   100     // This must be valid, but is empty
       
   101 	aNullTextArray = new ( ELeave ) CArrayPtrFlat<HBufC>( KNullTextArray );
       
   102     CleanupStack::PushL( aNullTextArray );
       
   103 
       
   104     iModel->GetDestinationsListL( aTextArray, iEnumValue );
       
   105     
       
   106     // Ownership has changed, we can pop the arrays
       
   107     CleanupStack::Pop( aNullTextArray );
       
   108     CleanupStack::Pop();    // clItem
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSIPSettListSIPProfSetDestListItem::CompleteConstructionL
       
   113 // Fetches and changes the lists after the construction is completed
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CSIPSettListSIPProfSetDestListItem::CompleteConstructionL()
       
   117     {
       
   118     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::CompleteConstructionL" )
       
   119     CArrayPtr<CAknEnumeratedText>* textArray = NULL;
       
   120     CArrayPtr<HBufC>* nullTextArray = NULL;
       
   121 
       
   122     CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();    
       
   123 
       
   124     // Read the AP list
       
   125     InitializeListL( textArray, nullTextArray );    
       
   126 
       
   127     // Check that we are pointing to an actual thing, otherwise
       
   128     // we need to modify this
       
   129     if ( textArray->Count() > KErrNone && !ValueMatches( textArray ) )
       
   130         {
       
   131         // Should display text 'None' when the AP is not found
       
   132         textArray->ResetAndDestroy();
       
   133         iEnumValue = KUnknownAPUID;
       
   134         }
       
   135 
       
   136     // Set new text arrays
       
   137     SetEnumeratedTextArrays( textArray, nullTextArray );
       
   138     
       
   139     // Update the lists internally
       
   140     HandleTextArrayUpdateL();
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSIPSettListSIPProfSetADestListItem::EditItemL
       
   145 // Called before the pop-up list is shown. Updates it, if there was a 
       
   146 // non-matching destination UID at the start-up 
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CSIPSettListSIPProfSetDestListItem::EditItemL( 
       
   150     TBool aCalledFromMenu )
       
   151     {
       
   152     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::EditItemL" )
       
   153     // Set backup value.
       
   154     iBackupValue = iEnumValue;
       
   155         
       
   156     if ( iEnumValue == KUnknownAPUID )
       
   157         {
       
   158         // destination was not found, create list for user to change the 
       
   159         // destination.
       
   160         // The destination will be anyway changed; no matter does the user
       
   161         // press Cancel or not..(Chosen destination will be the first one 
       
   162         // on the list, if user presses Cancel)        
       
   163         CArrayPtr<CAknEnumeratedText>* textArray = NULL;
       
   164         CArrayPtr<HBufC>* nullTextArray = NULL;
       
   165         InitializeListL( textArray, nullTextArray );     
       
   166 
       
   167         if ( textArray->Count() > KErrNone )
       
   168             {
       
   169             // There might be situation that no destinationss exist.
       
   170             iEnumValue = textArray->At( KErrNone )->EnumerationValue();
       
   171             }
       
   172 
       
   173         SetEnumeratedTextArrays( textArray, nullTextArray );    
       
   174         HandleTextArrayUpdateL();
       
   175         }
       
   176     
       
   177     CAknEnumeratedTextPopupSettingItem::EditItemL( aCalledFromMenu );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CSIPSettListSIPProfSetDestListItem::ResetAndDestroy
       
   182 // For deleting array in case of leave
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CSIPSettListSIPProfSetDestListItem::ResetAndDestroy( TAny* aPointerArray )
       
   186     {
       
   187     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::ResetAndDestroy" )
       
   188     CArrayPtrFlat<CAknEnumeratedText>* array =
       
   189         static_cast<CArrayPtrFlat<CAknEnumeratedText>*>( aPointerArray );
       
   190     array->ResetAndDestroy();
       
   191     delete array;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CGSSettListSIPProfSetAPListItem::HandleSettingPageEventL
       
   196 // From MAknSettingPageObserver
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CSIPSettListSIPProfSetDestListItem::HandleSettingPageEventL(
       
   200     CAknSettingPage* /*aSettingPage*/, TAknSettingPageEvent aEventType )
       
   201     {
       
   202     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::HandleSettingPageEventL Start" )
       
   203     if ( aEventType == EEventSettingCancelled )
       
   204         {
       
   205         // If new profile or access point was not defined.
       
   206         if ( iBackupValue == KUnknownAPUID )
       
   207             {
       
   208             // Set text to setting page.
       
   209             CArrayPtr<CAknEnumeratedText>* textArray = NULL;
       
   210             CArrayPtr<HBufC>* nullTextArray = NULL;
       
   211             
       
   212             InitializeListL( textArray, nullTextArray );
       
   213             textArray->ResetAndDestroy();
       
   214             
       
   215             SetEnumeratedTextArrays( textArray, nullTextArray );    
       
   216             HandleTextArrayUpdateL();
       
   217             }
       
   218         
       
   219         // Setting page cancelled.
       
   220         iEnumValue = iBackupValue;
       
   221         
       
   222         // Update internal value.
       
   223         this->LoadL();
       
   224         }
       
   225     else if ( iBackupValue == KUnknownAPUID )
       
   226         { //if not defined before && now defined && 'ok' pressed
       
   227         // Load and initialize the dialog text
       
   228         HBufC* dlgTxt = StringLoader::LoadLC( 
       
   229             R_SIP_QUERY_SELECT_DESTINATION );
       
   230 
       
   231         CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   232         CleanupStack::PushL( dlg );
       
   233         dlg->SetPromptL( *dlgTxt );
       
   234         CleanupStack::Pop( dlg );
       
   235         
       
   236         if ( !dlg->ExecuteLD( R_SIP_DESTINATION_CONFIRMATION_DLG ) )
       
   237             {
       
   238             // Set text to setting page.
       
   239             CArrayPtr<CAknEnumeratedText>* textArray = NULL;
       
   240             CArrayPtr<HBufC>* nullTextArray = NULL;
       
   241             
       
   242             InitializeListL( textArray, nullTextArray );
       
   243             textArray->ResetAndDestroy();
       
   244             
       
   245             SetEnumeratedTextArrays( textArray, nullTextArray );    
       
   246             HandleTextArrayUpdateL();
       
   247 
       
   248             // Setting page cancelled.
       
   249             iEnumValue = iBackupValue;
       
   250         
       
   251             // Update internal value.
       
   252             this->LoadL();
       
   253             }
       
   254         else
       
   255             {
       
   256             if ( iModel->APUID() != TUint32(KUnknownAPUID) )
       
   257                 {
       
   258                 iModel->CleanAPUid();
       
   259                 }
       
   260             }
       
   261         
       
   262         CleanupStack::PopAndDestroy( dlgTxt );      
       
   263         } 
       
   264     __GSLOGSTRING("CSIPSettListSIPProfSetDestListItem::HandleSettingPageEventL End" )
       
   265     }
       
   266 
       
   267 //  End of File