cmmanager/cmmgr/Framework/Src/selectdestination.cpp
branchRCL_3
changeset 58 83ca720e2b9a
parent 0 5a93021fdf25
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Shows the "Select destination:" dialog, where the user can 
       
    15 *                select one of the available destinations.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <AknUtils.h>
       
    20 #include <badesca.h>
       
    21 #include <StringLoader.h>
       
    22 #include <cmmanager.rsg>
       
    23 #include "selectdestinationdlg.h"
       
    24 #include <cmcommonconstants.h>
       
    25 #include <cmcommonui.h>
       
    26 #include "cmdestinationimpl.h"
       
    27 #include "cmlogger.h"
       
    28 #include "cmmanagerimpl.h"
       
    29 
       
    30 #include <cmmanagerdef.h>
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // CSelectDestinationDlg::CSelectDestinationDlg
       
    34 // ----------------------------------------------------------------------------
       
    35 //
       
    36 CSelectDestinationDlg::CSelectDestinationDlg( TInt aDummyIndex,
       
    37                                               TUint32& aDestinationId )
       
    38     : CAknListQueryDialog( &aDummyIndex )
       
    39     , iDestinationId( aDestinationId )
       
    40     , iDestinations( KCmArrayMediumGranularity )
       
    41     {
       
    42     CLOG_CREATE;
       
    43     }
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CSelectDestinationDlg::ConstructL
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 void CSelectDestinationDlg::ConstructL( CCmManagerImpl& aCmManager,
       
    50                                         RArray<TUint32>* aDestArray )
       
    51     {
       
    52     LOGGER_ENTERFN( "CSelectDestinationDlg::ConstructL" );
       
    53     RArray<TUint32> destinations( KCmArrayMediumGranularity );
       
    54     CleanupClosePushL( destinations );
       
    55 
       
    56     aCmManager.AllDestinationsL( destinations );
       
    57 
       
    58     TBool mmsFound = EFalse;
       
    59     for ( TInt i = 0; i < destinations.Count(); i++ )
       
    60         {
       
    61         CCmDestinationImpl* dest = aCmManager.DestinationL( destinations[i] );
       
    62         CleanupStack::PushL( dest );   
       
    63              
       
    64         // Don't count the current destination
       
    65         if ( dest->Id() == iDestinationId )
       
    66             {
       
    67             CleanupStack::PopAndDestroy( dest );
       
    68             continue;
       
    69             }
       
    70                
       
    71         // Do not give the option to copy into a Level 1 Protected Destination
       
    72         if ( dest->ProtectionLevel() == CMManager::EProtLevel1 )
       
    73             {
       
    74             CleanupStack::PopAndDestroy( dest );
       
    75             continue;
       
    76             }
       
    77 
       
    78         // check if the destination is valid as parent (e.g. for VPN)
       
    79         if ( aDestArray && aDestArray->Find( dest->Id() ) == KErrNotFound )
       
    80             {
       
    81             CleanupStack::PopAndDestroy( dest );
       
    82             continue;
       
    83             }
       
    84         
       
    85         // Skip the MMS Snap, it it not shown in the list
       
    86         if ( !mmsFound )
       
    87             {
       
    88             TInt snapMetadata = 0;
       
    89             TRAPD(metaErr, snapMetadata = dest->MetadataL( CMManager::ESnapMetadataPurpose ));
       
    90             if ( metaErr == KErrNone && snapMetadata == CMManager::ESnapPurposeMMS )
       
    91                 {
       
    92                 CleanupStack::PopAndDestroy( dest );
       
    93                 mmsFound = ETrue;
       
    94                 continue;
       
    95                 }
       
    96             }
       
    97         
       
    98         iDestinations.AppendL( dest );
       
    99         CleanupStack::Pop( dest );
       
   100         }
       
   101     CleanupStack::PopAndDestroy( &destinations );
       
   102     }
       
   103     
       
   104 // ----------------------------------------------------------------------------
       
   105 // CSelectDestinationDlg::~CSelectDestinationDlg
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 CSelectDestinationDlg::~CSelectDestinationDlg()
       
   109     {
       
   110     for ( TInt i = 0; i < iDestinations.Count(); i++ )
       
   111         {
       
   112         delete iDestinations[i];
       
   113         }
       
   114     iDestinations.Close();
       
   115     CLOG_CLOSE;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CSelectDestinationDlg::NewL
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 CSelectDestinationDlg* CSelectDestinationDlg::NewL( TUint32& aDestinationId,
       
   123                                                     CCmManagerImpl& aCmManager,
       
   124                                                     RArray<TUint32>* aDestArray )
       
   125     {
       
   126     CSelectDestinationDlg* self = NewLC( aDestinationId, aCmManager, aDestArray );
       
   127 
       
   128     CleanupStack::Pop( self );
       
   129 
       
   130     return self;
       
   131     }
       
   132 
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CSelectDestinationDlg::NewLC
       
   136 // ----------------------------------------------------------------------------
       
   137 //
       
   138 CSelectDestinationDlg* CSelectDestinationDlg::NewLC( TUint32& aDestinationId,
       
   139                                                      CCmManagerImpl& aCmManager,
       
   140                                                      RArray<TUint32>* aDestArray )
       
   141     {
       
   142     CSelectDestinationDlg* self =
       
   143                     new (ELeave) CSelectDestinationDlg( 0, aDestinationId );
       
   144 
       
   145     CleanupStack::PushL( self );
       
   146 
       
   147     self->ConstructL( aCmManager, aDestArray );
       
   148 
       
   149     return self;
       
   150     }
       
   151 
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CSelectDestinationDlg::OkToExitL
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 TBool CSelectDestinationDlg::OkToExitL( TInt aButtonId )
       
   158     {
       
   159     TBool result = EFalse;
       
   160     
       
   161     if ( aButtonId == EAknSoftkeySelect || aButtonId == EAknSoftkeyOk )
       
   162         {
       
   163         iDestinationId = iDestinations[ ListBox()->CurrentItemIndex() ]->Id();
       
   164 
       
   165         result = ETrue;
       
   166         }
       
   167     else if ( aButtonId == EAknSoftkeyCancel )
       
   168         {
       
   169         iDestinationId = 0;
       
   170 
       
   171         result = ETrue;
       
   172         }
       
   173 
       
   174     CLOG_WRITE_2( "CSelectDestinationDlg::OkToExitL dest ID: [%d], result: [%d]",
       
   175                    iDestinationId, result );
       
   176 
       
   177     return result;
       
   178     }
       
   179 
       
   180 
       
   181 // ----------------------------------------------------------------------------
       
   182 // CSelectDestinationDlg::PreLayoutDynInitL
       
   183 // ----------------------------------------------------------------------------
       
   184 //
       
   185 void CSelectDestinationDlg::PreLayoutDynInitL()
       
   186     {
       
   187     LOGGER_ENTERFN( "CSelectDestinationDlg::PreLayoutDynInitL" );
       
   188     // Let the base class do its job first
       
   189     CAknListQueryDialog::PreLayoutDynInitL();
       
   190 
       
   191     // Set the description field on the query
       
   192     HBufC* desc =
       
   193               StringLoader::LoadLC( R_CMWIZARD_SELECT_DESTINATION_DESCRIPTION );
       
   194 
       
   195     MessageBox()->SetMessageTextL( desc );
       
   196     CleanupStack::PopAndDestroy( desc );
       
   197 
       
   198     // Specify the item text array
       
   199     CDesCArrayFlat* itemArray =
       
   200                       new (ELeave) CDesCArrayFlat( KCmArrayMediumGranularity );
       
   201     SetItemTextArray( itemArray );
       
   202     SetOwnershipType( ELbmOwnsItemArray );
       
   203 
       
   204     // Note: we don't have to put 'itemArray' on to the cleanup stack, as the
       
   205     // model has already taken this object over.
       
   206     
       
   207     for ( TInt i = 0; i < iDestinations.Count(); i++ )
       
   208         {       
       
   209         // Here we take advantage of the fact that our icon array is ordered.
       
   210         // That is, the indices of the icons in the array will always be
       
   211         // in sync with those in the item text array (i.e. each bearer will
       
   212         // have the right icon associated with it).
       
   213         HBufC* destName = iDestinations[i]->NameLC();
       
   214         HBufC* lineText =
       
   215             TCmCommonUi::FormattedTextForListBoxLC( i, *destName );
       
   216 
       
   217         itemArray->AppendL( *lineText );
       
   218         CleanupStack::PopAndDestroy( 2, destName ); // destName, lineText
       
   219         }
       
   220 
       
   221     // Icons ...
       
   222     SetIconsL();
       
   223     }
       
   224 
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // CSelectDestinationDlg::SetIconsL()
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 void CSelectDestinationDlg::SetIconsL()
       
   231     {
       
   232     CArrayPtr<CGulIcon>* icons =
       
   233              new (ELeave) CArrayPtrFlat<CGulIcon>( KCmArrayMediumGranularity );
       
   234     CleanupStack::PushL( icons );
       
   235 
       
   236     for ( TInt i = 0; i < iDestinations.Count(); i++ )
       
   237         {
       
   238         CGulIcon* icon = iDestinations[i]->IconL();
       
   239         CleanupStack::PushL( icon );
       
   240 
       
   241         icons->AppendL( icon );
       
   242 
       
   243         CleanupStack::Pop( icon );  // icon array took over ownership
       
   244         }
       
   245 
       
   246     SetIconArrayL( icons ); // ownership passed, too
       
   247 
       
   248     CleanupStack::Pop( icons );
       
   249     }
       
   250 
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // void CSelectDestinationDlg::HandleResourceChange
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 void CSelectDestinationDlg::HandleResourceChange( TInt aType )
       
   257     {
       
   258     if ( aType == KAknsMessageSkinChange )
       
   259         {
       
   260         CAknListQueryDialog::HandleResourceChange( aType );
       
   261 
       
   262         TRAP_IGNORE( SetIconsL() );
       
   263 
       
   264         SizeChanged();
       
   265         }
       
   266     else
       
   267         {
       
   268         if ( aType == KEikDynamicLayoutVariantSwitch )
       
   269             {
       
   270             TRect mainPaneRect;
       
   271             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
   272                                                mainPaneRect );
       
   273 
       
   274             TAknLayoutRect layoutRect;
       
   275             layoutRect.LayoutRect( TRect( TPoint( 0, 0 ), 
       
   276                                    mainPaneRect.Size() ),
       
   277                                    AKN_LAYOUT_WINDOW_list_gen_pane( 0 ) );
       
   278 
       
   279             ListBox()->SetRect( layoutRect.Rect() );
       
   280             }
       
   281 
       
   282         // Base call
       
   283         CAknListQueryDialog::HandleResourceChange( aType );
       
   284         }
       
   285     }