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