voipplugins/accountcreationplugin/src/acpquerycontainer.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Implements CAcpProviderSpecificContainer methods
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknlists.h>
       
    20 #include <stringloader.h>
       
    21 #include <accountcreationplugin.rsg>
       
    22 #include <AknTextSettingPage.h>
       
    23 #include <AknPasswordSettingPage.h>
       
    24 
       
    25 #include "acpqueryview.h"
       
    26 #include "acpquerycontainer.h"
       
    27 #include "accountcreationpluginlogger.h"
       
    28 #include "accountcreationpluginconstants.h"
       
    29 
       
    30 const TInt KComponentControlCount = 1;
       
    31 _LIT( KAsterisks, "****" );
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CAcpQueryContainer::CAcpQueryContainer
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CAcpQueryContainer::CAcpQueryContainer()
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CAcpQueryContainer::ConstructL
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 void CAcpQueryContainer::ConstructL( const TRect& aRect )
       
    46     {
       
    47     ACPLOG( "CAcpQueryContainer::ConstructL begin" );
       
    48 
       
    49     // Load "none" from resources to further use.
       
    50     iNone = StringLoader::LoadL( R_ACP_SETTING_PAGE_EMPTY_TEXT );
       
    51 
       
    52     // Default values for setting item texts.
       
    53     iUsername.Copy( *iNone );
       
    54     iPassword.Copy( *iNone );
       
    55 
       
    56     CreateWindowL();
       
    57     ConstructListBoxL();
       
    58     SetRect( aRect );
       
    59     ActivateL();
       
    60 
       
    61     ACPLOG( "CAcpQueryContainer::ConstructL end" );
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CAcpQueryContainer::NewL
       
    66 // ---------------------------------------------------------------------------
       
    67 //      
       
    68 CAcpQueryContainer* CAcpQueryContainer::NewL( const TRect& aRect )
       
    69     {    
       
    70     CAcpQueryContainer* self = CAcpQueryContainer::NewLC( aRect );
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CAcpQueryContainer::NewLC
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CAcpQueryContainer* CAcpQueryContainer::NewLC( const TRect& aRect )
       
    80     {    
       
    81     CAcpQueryContainer* self = new ( ELeave ) CAcpQueryContainer();
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL( aRect );
       
    84     return self;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CAcpQueryContainer::~CAcpQueryContainer
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 CAcpQueryContainer::~CAcpQueryContainer()
       
    92     {
       
    93     ACPLOG( "CAcpQueryContainer::~CAcpQueryContainer begin" );
       
    94     delete iNone;
       
    95     delete iListBox;
       
    96     ACPLOG( "CAcpQueryContainer::~CAcpQueryContainer end" );
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CAcpQueryContainer::ListBox
       
   101 // Returns handle to the listbox.
       
   102 // ---------------------------------------------------------------------------
       
   103 //    
       
   104 CAknSettingStyleListBox* CAcpQueryContainer::ListBox()
       
   105     {
       
   106     return iListBox;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CAcpQueryContainer::CurrentItemIndex
       
   111 // Returns index of selected listbox item. 
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 TInt CAcpQueryContainer::CurrentItemIndex() const
       
   115     {
       
   116     return iListBox->CurrentItemIndex();
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CAcpQueryContainer::ShowUsernameSettingPageL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CAcpQueryContainer::ShowUsernameSettingPageL()
       
   124     {
       
   125     ACPLOG( "CAcpQueryContainer::ShowUsernameSettingPageL" );
       
   126 
       
   127     // Show text setting page.
       
   128     TBuf<KAcpTextPageLength> temporaryText ( iUsername );
       
   129     CAknTextSettingPage* dlg = new(ELeave) CAknTextSettingPage(
       
   130         R_ACP_USERNAME_SETTING_PAGE, temporaryText );
       
   131     if ( dlg->ExecuteLD(CAknSettingPage::EUpdateWhenAccepted ) )
       
   132         {
       
   133         iUsername.Copy( temporaryText );
       
   134         }
       
   135     // Update currently selected list item.
       
   136     UpdateListboxItemL( CurrentItemIndex() );     
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CAcpQueryContainer::ShowPwordSettingPageL
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CAcpQueryContainer::ShowPwordSettingPageL()
       
   144     {
       
   145     ACPLOG( "CAcpQueryContainer::ShowPwordSettingPageL" );
       
   146 
       
   147     // Show password setting page.
       
   148     TBuf<KAcpPasswordPageLength> temporaryPassword ( KNullDesC );
       
   149     temporaryPassword.Copy( iPassword );
       
   150     TBuf<KAcpPasswordPageLength> oldPassword ( KNullDesC );
       
   151     temporaryPassword.Copy( iPassword );
       
   152     
       
   153     CAknSettingPage* dlg = new (ELeave) CAknAlphaPasswordSettingPage(
       
   154         R_ACP_PASSWORD_SETTING_PAGE, temporaryPassword, oldPassword );
       
   155     if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted ) )
       
   156         {
       
   157         iPassword.Copy( temporaryPassword );
       
   158         } 
       
   159     // Update currently selected list item.
       
   160     UpdateListboxItemL( CurrentItemIndex() );     
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CAcpQueryContainer::GetContainerDataL
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CAcpQueryContainer::GetContainerDataL( TDes& aUsername, TDes& aPassword )
       
   168     {
       
   169     // Setting item: Server username.
       
   170     if ( aUsername.Length() > iUsername.Length() )
       
   171         {
       
   172         User::Leave( KErrArgument );
       
   173         }
       
   174     aUsername.Copy( iUsername );
       
   175 
       
   176     // Setting item: Server password.
       
   177     if ( aPassword.Length() > iPassword.Length() )
       
   178         {
       
   179         User::Leave( KErrArgument );
       
   180         }
       
   181     if ( iPassword.Compare( *iNone ) )
       
   182         {
       
   183         aPassword.Copy( iPassword );
       
   184         }
       
   185 
       
   186     ACPLOG( "GetContainerDataL, Items appended" );
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CAcpQueryContainer::ConstructListBoxL
       
   191 // Creates listbox item for provider list items.
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CAcpQueryContainer::ConstructListBoxL()
       
   195     {
       
   196     ACPLOG( "CAcpQueryContainer::ConstructListBoxL begin" );
       
   197 
       
   198     // Create listbox and array for listbox items.
       
   199     iListBox = new( ELeave ) CAknSettingStyleListBox;
       
   200     iListBox->ConstructL( this, EAknListBoxSelectionList );    
       
   201     iListBox->CreateScrollBarFrameL( ETrue );
       
   202     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   203         CEikScrollBarFrame::EOff, 
       
   204         CEikScrollBarFrame::EAuto );
       
   205     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   206 
       
   207     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( KArrayGranuality );  
       
   208     iListBox->Model()->SetItemTextArray( array );
       
   209 
       
   210     // Fill container listbox with setting items.
       
   211     FillListboxWithItemsL();
       
   212 
       
   213     // Set listbox index to first item and draw.
       
   214     iListBox->HandleItemAdditionL();
       
   215     iListBox->SetCurrentItemIndexAndDraw( 0 );
       
   216 
       
   217     ACPLOG( "CAcpQueryContainer::ConstructListBoxL end" );
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CAcpQueryContainer::FillListboxWithItemsL
       
   222 // Fills listbox with items.
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CAcpQueryContainer::FillListboxWithItemsL()
       
   226     {
       
   227     ACPLOG("CAcpQueryContainer::FillListboxWithItemsL");
       
   228 
       
   229     // Get listbox items from model.
       
   230     CTextListBoxModel* model = iListBox->Model();
       
   231     MDesCArray* textArray = model->ItemTextArray();
       
   232     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   233     TBuf<KAcpSettingItemLength> listBoxItemText ( KNullDesC );          
       
   234 
       
   235     // Setting item: Server username.
       
   236     HBufC* caption = StringLoader::LoadLC( R_ACP_USERNAME_SETTING_PAGE_TEXT );
       
   237     listBoxItemText.Format(
       
   238         KAcpSettingItemTextFormat,
       
   239         caption,
       
   240         &iUsername );          
       
   241     listBoxItems->AppendL( listBoxItemText );
       
   242     CleanupStack::PopAndDestroy( caption );    
       
   243     ACPLOG( "FillListboxWithItemsL: Server username appended." );
       
   244 
       
   245     // Setting item: Server password.
       
   246     caption = StringLoader::LoadLC( R_ACP_PASSWORD_SETTING_PAGE_TEXT );
       
   247     listBoxItemText.Format(
       
   248         KAcpSettingItemTextFormat,
       
   249         caption,
       
   250         &iPassword );          
       
   251     listBoxItems->AppendL( listBoxItemText );
       
   252     CleanupStack::PopAndDestroy( caption );    
       
   253     ACPLOG( 
       
   254         "CAcpQueryContainer::FillListboxWithItemsL: Server password appended." 
       
   255         );
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // CAcpQueryContainer::UpdateListboxItemL
       
   260 // Updates setting page items.
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CAcpQueryContainer::UpdateListboxItemL( const TInt aIndex )
       
   264     {
       
   265     ACPLOG("CAcpQueryContainer::UpdateListboxItemL begin");
       
   266 
       
   267     // Get listbox items from model.
       
   268     CTextListBoxModel* model = iListBox->Model();
       
   269     MDesCArray* textArray = model->ItemTextArray();
       
   270     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   271 
       
   272     // Remove edited item from the list.
       
   273     listBoxItems->Delete( aIndex );
       
   274 
       
   275     // Fill line variables with correct data.
       
   276     TBuf<KAcpSettingItemLength> firstLine( KNullDesC );
       
   277     TBuf<KAcpSettingItemLength> secondLine( KNullDesC );
       
   278     TBuf<KAcpSettingItemLength> listBoxItemText( KNullDesC );          
       
   279     FillListboxItemDataL( aIndex, firstLine, secondLine );
       
   280 
       
   281     // Create new lisbox item data and insert it to correct place.
       
   282     listBoxItemText.Format(
       
   283         KAcpSettingItemTextFormat,
       
   284         &firstLine,
       
   285         &secondLine );
       
   286     listBoxItems->InsertL( aIndex, listBoxItemText );
       
   287 
       
   288     // Update listbox.
       
   289     iListBox->HandleItemAdditionL(); 
       
   290 
       
   291     ACPLOG( "CAcpQueryContainer::UpdateListboxItemL end" );
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CAcpQueryContainer::FillListboxItemDataL
       
   296 // Sets selected listbox item with member data.
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CAcpQueryContainer::FillListboxItemDataL( const TInt aIndex,
       
   300     TDes& aFirstLine, TDes& aSecondLine )
       
   301     {
       
   302     HBufC* caption = NULL;
       
   303     switch ( aIndex )
       
   304         {
       
   305         // Setting item: Server username.
       
   306         case CAcpQueryView::EAcpGenericUsername:
       
   307             caption = StringLoader::LoadL( R_ACP_USERNAME_SETTING_PAGE_TEXT );
       
   308             aFirstLine.Copy( caption->Des() );
       
   309             delete caption;
       
   310             aSecondLine.Copy( iUsername );
       
   311             break;
       
   312         // Setting item: Server password.
       
   313         case CAcpQueryView::EAcpGenericPassword:
       
   314             caption = StringLoader::LoadL( R_ACP_PASSWORD_SETTING_PAGE_TEXT );
       
   315             aFirstLine.Copy( caption->Des() );
       
   316             delete caption;
       
   317             // Show asterisks instead of the password.
       
   318             if ( iPassword.Length() )
       
   319                 {
       
   320                 aSecondLine.Copy( KAsterisks );
       
   321                 }
       
   322             else
       
   323                 {
       
   324                 aSecondLine.Copy( *iNone );
       
   325                 }
       
   326             break;
       
   327         default:
       
   328             User::Leave( KErrNotSupported );
       
   329             break;
       
   330         }
       
   331 
       
   332     ACPLOG( "CAcpQueryContainer::FillListboxItemDataL" );
       
   333     ACPLOG2( "FillListboxItemDataL: List item filled: %d", aIndex );
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CAcpQueryContainer::OfferKeyEventL
       
   338 // From class CoeControl.
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 TKeyResponse CAcpQueryContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   342     TEventCode aType )
       
   343     {
       
   344     TKeyResponse response = EKeyWasNotConsumed;
       
   345     if ( aType == EEventKey )
       
   346         {
       
   347         response = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   348         }
       
   349     return response;
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // CAcpQueryContainer::ComponentControl
       
   354 // From class CoeControl.
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 CCoeControl* CAcpQueryContainer::ComponentControl( TInt aIndex ) const
       
   358     {
       
   359     switch ( aIndex )
       
   360         {
       
   361         case 0 :
       
   362             return iListBox;
       
   363         default:
       
   364             return 0;
       
   365         }
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CAcpQueryContainer::CountComponentControls
       
   370 // From class CoeControl.
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 TInt CAcpQueryContainer::CountComponentControls() const
       
   374     {
       
   375     return KComponentControlCount;
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // CAcpQueryContainer::SizeChanged
       
   380 // From class CoeControl.
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 void CAcpQueryContainer::SizeChanged()
       
   384     {
       
   385     iListBox->SetRect( Rect() );
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // CAcpQueryContainer::FocusChanged
       
   390 // From class CoeControl.
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CAcpQueryContainer::FocusChanged( TDrawNow aDrawNow )
       
   394     {
       
   395     CCoeControl::FocusChanged( aDrawNow );
       
   396 
       
   397     if ( iListBox )
       
   398         {
       
   399         iListBox->SetFocus( IsFocused() );
       
   400         }
       
   401     }
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // CAcpQueryContainer::HandleResourceChange
       
   405 // From class CoeControl.
       
   406 // Called by framework when layout is changed.
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 void CAcpQueryContainer::HandleResourceChange( TInt aType )
       
   410     {
       
   411     CCoeControl::HandleResourceChange( aType );
       
   412 
       
   413     // *****************************
       
   414     // ADDED FOR SCALABLE UI SUPPORT
       
   415     // *****************************
       
   416     if ( KEikDynamicLayoutVariantSwitch == aType )
       
   417         {
       
   418         TRect rect;
       
   419         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
       
   420         SetRect( rect );
       
   421         }
       
   422     }
       
   423 
       
   424 // End of file.