connectionutilities/ConnectionDialogs/cconndlg/src/ActiveSelectExplicit.cpp
branchRCL_3
changeset 57 05bc53fe583b
parent 55 fc7b30ed2058
child 58 83ca720e2b9a
equal deleted inserted replaced
55:fc7b30ed2058 57:05bc53fe583b
     1 /*
       
     2 * Copyright (c) 2002 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:  Implementation of plugins (base & all derived).
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "ActiveSelectExplicit.h"
       
    21 #include "SelectExplicitDialog.h"
       
    22 #include "ConnectionInfo.h"
       
    23 #include "ConnectionInfoArray.h"
       
    24 #include "CConnDlgPrivateCRKeys.h"
       
    25 #include "ConnectionDialogsLogger.h"
       
    26 #include "sortsnaputils.h"
       
    27 
       
    28 #include <commdb.h>
       
    29 #include <StringLoader.h>
       
    30 #include <wlanmgmtcommon.h>
       
    31 #include <cmdestinationext.h>
       
    32 #include <cmpluginwlandef.h>
       
    33 #ifndef __WINS__
       
    34 #include <wlanmgmtclient.h>
       
    35 #endif
       
    36 #include <AknWaitDialog.h>
       
    37 #include <AknIconArray.h>
       
    38 #include <AknsUtils.h>
       
    39 
       
    40 #include <CConnDlgPlugin.rsg>
       
    41 #include <data_caging_path_literals.hrh>
       
    42 #include <cmmanager.mbg>
       
    43 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    44 #include <commsdat.h>
       
    45 #else
       
    46 #include <commsdat.h>
       
    47 #include <commsdat_partner.h>
       
    48 #endif
       
    49 #include <wlancontainer.h>
       
    50 
       
    51 
       
    52 // CONSTANTS
       
    53 
       
    54 LOCAL_D const TInt KMaxEntryLength = CommsDat::KMaxTextLength*2 + 20;
       
    55 LOCAL_D const TInt KIconsGranularity = 4;
       
    56 
       
    57 using namespace CMManager;
       
    58 
       
    59 
       
    60 ///////////////////////////////////////////////////////////////////////////////
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CActiveSelectExplicit::CActiveSelectExplicit()
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CActiveSelectExplicit::CActiveSelectExplicit( 
       
    67                                         CSelectConnectionDialog* aCallerDialog,
       
    68                                         TUint aDestId, 
       
    69                                         TInt aRefreshInterval,
       
    70                                         TUint32 aBearerSet, 
       
    71                                         TBool aIsWLANFeatureSupported, 
       
    72                                         TUint aDefaultCMId )
       
    73 : iCallerDialog( aCallerDialog ),
       
    74   iDestId( aDestId ),
       
    75 //  isDialogDeleting( EFalse ),
       
    76   iRefreshInterval( aRefreshInterval ),
       
    77   iBearerSet( aBearerSet ),
       
    78   iIsWLANFeatureSupported( aIsWLANFeatureSupported ), 
       
    79   iDefaultCMId( aDefaultCMId )
       
    80     {
       
    81     }
       
    82 
       
    83     
       
    84 // ---------------------------------------------------------
       
    85 // CActiveSelectExplicit* CActiveSelectExplicit::NewL()
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 CActiveSelectExplicit* CActiveSelectExplicit::NewL( 
       
    89                                         CSelectConnectionDialog* aCallerDialog,
       
    90                                         TUint aDestId, 
       
    91                                         TInt aRefreshInterval,
       
    92                                         TUint32 aBearerSet, 
       
    93                                         TBool aIsWLANFeatureSupported, 
       
    94                                         TUint aDefaultCMId )
       
    95     {
       
    96     CLOG_ENTERFN( "CActiveSelectExplicit::NewL " );  
       
    97     
       
    98     CActiveSelectExplicit* self = new ( ELeave ) CActiveSelectExplicit(
       
    99                                     aCallerDialog, aDestId, aRefreshInterval,
       
   100                                     aBearerSet, aIsWLANFeatureSupported, 
       
   101                                     aDefaultCMId );
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     CleanupStack::Pop( self );
       
   105     
       
   106     CLOG_LEAVEFN( "CActiveSelectExplicit::NewL " );      
       
   107 
       
   108     return self;        
       
   109     }
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CActiveSelectExplicit::ConstructL()
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CActiveSelectExplicit::ConstructL()
       
   117     {
       
   118     CActiveBase::ConstructL();
       
   119 
       
   120     iItems = new( ELeave ) CConnectionInfoArray();
       
   121     iIcons = new( ELeave ) CAknIconArray( KIconsGranularity );
       
   122 
       
   123     iCmManagerExt.OpenL();
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CActiveSelectExplicit::~CActiveSelectExplicit()
       
   128 // ---------------------------------------------------------
       
   129 //    
       
   130 CActiveSelectExplicit::~CActiveSelectExplicit()
       
   131     {
       
   132     Cancel();
       
   133 
       
   134     if ( iItems )
       
   135         {
       
   136         iItems->ResetAndDestroy();
       
   137         }
       
   138     delete iItems;    
       
   139     iItems = NULL;
       
   140 
       
   141     iCmManagerExt.Close();
       
   142     }
       
   143 
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CActiveSelectExplicit::Cancel()
       
   147 // ---------------------------------------------------------
       
   148 // 
       
   149 void CActiveSelectExplicit::Cancel()
       
   150     {
       
   151     StopTimer();
       
   152     CActive::Cancel();
       
   153 
       
   154     if( iDialog  && !( iDialog->GetOkToExit() ) )
       
   155         {
       
   156         CLOG_WRITEF( _L( "iDialog->GetOkToExit() : %b" ), iDialog->GetOkToExit() );
       
   157         delete iDialog;
       
   158         iDialog = NULL;
       
   159         }
       
   160     }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CActiveSelectExplicit::DoCancel()
       
   165 // ---------------------------------------------------------
       
   166 // 
       
   167 void CActiveSelectExplicit::DoCancel()
       
   168     {
       
   169     CLOG_ENTERFN( "CActiveSelectExplicit::DoCancel " );  
       
   170     
       
   171 /*    if( isDialogDeleting )
       
   172         {
       
   173         CLOG_WRITE( "isDialogDeleting" );
       
   174         
       
   175         delete iDialog;
       
   176         iDialog = NULL;   
       
   177         
       
   178         isDialogDeleting = EFalse;         
       
   179         }
       
   180   */      
       
   181     CLOG_LEAVEFN( "CActiveSelectExplicit::DoCancel " );          
       
   182     }
       
   183 
       
   184     
       
   185 // ---------------------------------------------------------
       
   186 // CActiveSelectExplicit::RunL()
       
   187 // ---------------------------------------------------------
       
   188 //     
       
   189 void CActiveSelectExplicit::RunL()
       
   190     {
       
   191     CLOG_ENTERFN( "CActiveSelectExplicit::RunL " );  
       
   192     
       
   193     if( iStatus == KErrNone )
       
   194         {
       
   195         BuildConnectionListL();
       
   196         iDialog->RefreshDialogL( iItems, iIcons, ETrue );
       
   197         }     
       
   198     
       
   199     CLOG_LEAVEFN( "CActiveSelectExplicit::RunL " );      
       
   200         
       
   201     }
       
   202 
       
   203     
       
   204 // ---------------------------------------------------------
       
   205 // CActiveSelectExplicit::StartSearchIAPsL()
       
   206 // ---------------------------------------------------------
       
   207 //    
       
   208 void CActiveSelectExplicit::ShowSelectExplicitL()
       
   209     {    
       
   210     BuildConnectionListL();
       
   211 
       
   212     iDialog = CSelectExplicitDialog::NewL( iCallerDialog );
       
   213     iDialog->PrepareAndRunLD( iItems, iIcons, EFalse );
       
   214 
       
   215     if( iRefreshInterval )
       
   216         {
       
   217         StartTimerL( iRefreshInterval );
       
   218         }     
       
   219     }
       
   220    
       
   221  
       
   222 // ---------------------------------------------------------
       
   223 // CActiveSelectExplicit::BuildConnectionListL()
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CActiveSelectExplicit::BuildConnectionListL()
       
   227     {
       
   228     CLOG_ENTERFN( "CActiveSelectExplicit::BuildConnectionListL " );  
       
   229 
       
   230     if ( iItems )
       
   231         {
       
   232         iItems->ResetAndDestroy();
       
   233         }
       
   234 
       
   235     if ( iIcons )
       
   236         {
       
   237         iIcons->ResetAndDestroy();
       
   238         }
       
   239 
       
   240     if ( iDefaultCMId != 0 )  
       
   241         {   // It automatically means also that the feature is supported
       
   242         _LIT( KDriveZ, "z:" );  // ROM folder
       
   243         // Name of the MBM file containing icons
       
   244         _LIT( KManagerIconFilename, "cmmanager.mbm" );
       
   245     
       
   246         TFileName iconsFileName;
       
   247 
       
   248         iconsFileName.Append( KDriveZ );
       
   249         iconsFileName.Append( KDC_APP_BITMAP_DIR );
       
   250         iconsFileName.Append( KManagerIconFilename );
       
   251 
       
   252         iIcons->AppendL( AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   253                                     KAknsIIDQgnIndiCbHotAdd,
       
   254                                     iconsFileName, 
       
   255                                     EMbmCmmanagerQgn_indi_cb_hot_add, 
       
   256                                     EMbmCmmanagerQgn_indi_cb_hot_add_mask ) );
       
   257         }
       
   258 
       
   259     TBool easyWlanIsInDb = EFalse;
       
   260 
       
   261 #ifdef _DEBUG
       
   262     if ( iDestId )
       
   263         {   // Real destination, not for uncategorized
       
   264         RCmDestinationExt cmDestExt = iCmManagerExt.DestinationL( iDestId );
       
   265         CleanupClosePushL( cmDestExt );
       
   266         CLOG_WRITEF( _L( "Destination id %d, Total number of methods %d" ),
       
   267                     iDestId, cmDestExt.ConnectionMethodCount() );
       
   268 
       
   269         for ( TInt j = 0; j < cmDestExt.ConnectionMethodCount(); j++ )
       
   270             {
       
   271             RCmConnectionMethodExt cmConnMethodExt;
       
   272             TRAPD( err, cmConnMethodExt = cmDestExt.ConnectionMethodL( j ) );
       
   273             if ( err == KErrNone )
       
   274                 {
       
   275                 CleanupClosePushL( cmConnMethodExt );
       
   276                 HBufC* bufMethod = cmConnMethodExt.GetStringAttributeL(
       
   277                                                                     ECmName );
       
   278                 CleanupStack::PushL( bufMethod );
       
   279                 TBuf<CommsDat::KMaxTextLength+1> nameMethod;
       
   280                 nameMethod = *bufMethod;
       
   281                 nameMethod.ZeroTerminate();
       
   282 
       
   283                 CLOG_WRITEF( _L( "ConnMethod id %d, Method name %s" ), 
       
   284                     cmConnMethodExt.GetIntAttributeL( ECmIapId ), nameMethod.Ptr() );
       
   285 
       
   286                 CleanupStack::PopAndDestroy( 2 ); // bufMethod, cmConnMethodExt
       
   287                 }
       
   288             }
       
   289         CleanupStack::PopAndDestroy();  // cmDestExt
       
   290         }
       
   291 #endif
       
   292         TSortSnapUtils sortSnapUtils( iMPM );
       
   293         TMpmSnapBuffer snapBuffer;
       
   294         TInt err = sortSnapUtils.GetSortSnapData( iDestId, snapBuffer );
       
   295         CLOG_WRITEF( _L( "GetSortSNAPDataL returned = %d. list.Count() = %d" ), err, snapBuffer.Count() );
       
   296 
       
   297         if ( err == KErrNone )
       
   298             {
       
   299             RCmConnectionMethodExt cmConnMethodExt;
       
   300             CleanupClosePushL( cmConnMethodExt );
       
   301             for ( TInt numCM = 0; numCM < snapBuffer.Count(); numCM++ )
       
   302                 {
       
   303                 AddConnectionMethodItemL( snapBuffer.iIapId[numCM], 
       
   304                                           iDestId == 0,
       
   305                                           easyWlanIsInDb, 
       
   306                                           snapBuffer.iIapId[numCM] == iDefaultCMId );
       
   307                 }
       
   308             CleanupStack::PopAndDestroy();  // cmConnMethodExt
       
   309             }   
       
   310 
       
   311     // Add any ad-hoc WLAN iaps to the list
       
   312     if ( ( iBearerSet & ECommDbBearerWLAN ) && ( iDestId == 0 ) && iIsWLANFeatureSupported )
       
   313         {
       
   314         AddAdhocWlanIapsL();	
       
   315         }
       
   316 
       
   317     CLOG_LEAVEFN( "CActiveSelectExplicit::BuildConnectionListL " );
       
   318     }
       
   319 
       
   320 
       
   321 // ---------------------------------------------------------
       
   322 // CActiveSelectExplicit::AddConnectionMethodItemL()
       
   323 // ---------------------------------------------------------
       
   324 //
       
   325 void CActiveSelectExplicit::AddConnectionMethodItemL( TUint32 aId,
       
   326                                                 TBool aCheckForEasyWlan, 
       
   327                                                 TBool& aEasyWlanIsInDb, 
       
   328                                                 TBool aDefaultCM )
       
   329     {
       
   330     CLOG_ENTERFN( "CActiveSelectExplicit::AddConnectionMethodItemL" );  
       
   331 
       
   332     CConnectionInfo* conIn;
       
   333 
       
   334     RCmConnectionMethodExt cmConnMethodExt;
       
   335     CLOG_WRITEF( _L( "Uncat dest id %d" ), aId );
       
   336 
       
   337     TRAPD( err, cmConnMethodExt = iCmManagerExt.ConnectionMethodL( aId ) );
       
   338     CLOG_WRITEF( _L( "err %d" ), err );
       
   339 
       
   340     if ( err == KErrNone )
       
   341         {
       
   342         CleanupClosePushL( cmConnMethodExt );
       
   343 
       
   344         TUint32 bearer = cmConnMethodExt.GetIntAttributeL( 
       
   345                                                         ECmCommsDBBearerType );
       
   346         CLOG_WRITEF( _L( "bearer %d" ), bearer );
       
   347 
       
   348         if ( bearer & iBearerSet )
       
   349             {
       
   350             CLOG_WRITE( "To be listed!" );
       
   351 
       
   352             TBool isCMEasyWlan = EFalse;
       
   353 
       
   354             HBufC* bufName = cmConnMethodExt.GetStringAttributeL(
       
   355                                                                 ECmName );
       
   356 
       
   357             TBuf<CommsDat::KMaxTextLength+1> nameCM;
       
   358             nameCM = *bufName;
       
   359             nameCM.ZeroTerminate();
       
   360             delete bufName;
       
   361 
       
   362             CLOG_WRITEF( _L( "Method name %s. Bearer = %d" ), nameCM.Ptr(), bearer );
       
   363 
       
   364             if ( aCheckForEasyWlan && bearer == KCommDbBearerWLAN && 
       
   365                  iIsWLANFeatureSupported )
       
   366                 {
       
   367                 if ( !aEasyWlanIsInDb )
       
   368                     {
       
   369                     HBufC* bufSSID = cmConnMethodExt.GetStringAttributeL( 
       
   370                                                                 EWlanSSID );
       
   371                     if ( !bufSSID || bufSSID->Des().Length() == 0 )
       
   372                         {
       
   373                         isCMEasyWlan = ETrue;
       
   374                         aEasyWlanIsInDb = ETrue;
       
   375                         }
       
   376                     delete bufSSID;
       
   377                     }
       
   378                 }
       
   379 
       
   380             if ( !isCMEasyWlan )
       
   381                 {
       
   382                 CGulIcon* iconCM = ( CGulIcon* )
       
   383                                     cmConnMethodExt.GetIntAttributeL(
       
   384                                                             ECmBearerIcon );
       
   385                 if ( iconCM )
       
   386                     {
       
   387                     CLOG_WRITEF( _L( "iconCM found" ) );
       
   388                     CleanupStack::PushL( iconCM );
       
   389                     iIcons->AppendL( iconCM );
       
   390 
       
   391                     // icon array took over ownership
       
   392                     CleanupStack::Pop( iconCM );
       
   393                     }
       
   394                 else
       
   395                     {
       
   396                     CLOG_WRITEF( _L( "iconCM not found" ) );
       
   397                     }
       
   398 
       
   399                 TBuf<KMaxEntryLength> temp;
       
   400                 _LIT( KIconIdName, "%d\t%s" );
       
   401                 _LIT( KIconIdNameDefaultConn, "%d\t%s\t0" );
       
   402 
       
   403                 if ( aDefaultCM )
       
   404                     {
       
   405                     temp.Format( KIconIdNameDefaultConn, iIcons->Count()-1,
       
   406                                  nameCM.Ptr() );
       
   407                     }
       
   408                 else
       
   409                     {
       
   410                     temp.Format( KIconIdName, iIcons->Count()-1, 
       
   411                                  nameCM.Ptr() );
       
   412                     }
       
   413 
       
   414                 conIn = CConnectionInfo::NewL( aId, 0, temp );
       
   415                 CleanupStack::PushL( conIn );
       
   416                 iItems->AppendL( conIn );
       
   417                 CleanupStack::Pop( conIn );
       
   418                 }
       
   419             }
       
   420         CleanupStack::PopAndDestroy();  // cmConnMethodExt
       
   421         }
       
   422 
       
   423     CLOG_LEAVEFN( "CActiveSelectExplicit::AddConnectionMethodItemL" );
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------
       
   427 // CActiveSelectExplicit::AddAdhocWlanIapsL()
       
   428 // ---------------------------------------------------------
       
   429 //
       
   430 void CActiveSelectExplicit::AddAdhocWlanIapsL()
       
   431     {
       
   432     CLOG_ENTERFN( "CActiveSelectExplicit::AddAdhocWlanIapsL " );
       
   433     
       
   434     // Creating a session with the latest version
       
   435     CMDBSession* db = CMDBSession::NewLC( CMDBSession::LatestVersion() );
       
   436     db->SetAttributeMask( ECDProtectedWrite );
       
   437     
       
   438     // Create wlan service record set (RArray (or RPtrArray?))
       
   439     CMDBRecordSet<CCDWlanServiceRecord>* wlanSet =
       
   440         new (ELeave)CMDBRecordSet<CCDWlanServiceRecord>(   CCDWlanServiceRecord::TableIdL( *db )   );
       
   441     CleanupStack::PushL( wlanSet ); 
       
   442     
       
   443     // Create wlan service record
       
   444     CCDWlanServiceRecord* wlanRecord =
       
   445         new (ELeave)CCDWlanServiceRecord(   CCDWlanServiceRecord::TableIdL( *db )   );
       
   446     
       
   447     CleanupStack::PushL( wlanRecord );
       
   448     
       
   449     // Set ConnectionMode field in wlan service record (see wlancontainer.h)
       
   450     // This works with EWlanOperatingModeAdhoc, fails with EWlanConnectionModeAdhoc
       
   451     wlanRecord->iWlanConnMode.SetL( EWlanOperatingModeAdhoc );
       
   452     
       
   453     // Append wlan service record to wlan service record set (currently empty)
       
   454     wlanSet->iRecords.AppendL( wlanRecord );
       
   455     CleanupStack::Pop( wlanRecord ); // ownership moved to RPointerArray
       
   456     
       
   457     // Find matcing wlan service records
       
   458     if( wlanSet->FindL( *db ) )
       
   459         {
       
   460         TInt wlanRecordCount( wlanSet->iRecords.Count() );
       
   461         CLOG_WRITEF( _L("wlanSet record count = %d"), wlanRecordCount );
       
   462         
       
   463         TBool easyWlanIsInDb = EFalse;
       
   464         
       
   465         // loop for each record found
       
   466         for ( TInt i = 0; i < wlanRecordCount; i++ )
       
   467             {
       
   468             // Seems we need to specifically load the current record again to be sure all fields are up to date
       
   469             wlanRecord->SetElementId( wlanSet->iRecords[i]->ElementId() );
       
   470             // Load will only look at ElementId and updates the rest of the fields
       
   471             wlanRecord->LoadL( *db );
       
   472             
       
   473             if ( !( wlanRecord->iWLanSSID.IsNull() ) )
       
   474                 {
       
   475                 // Don't include Easy WLAN
       
   476                 // lets print some stuff to log            
       
   477                 CLOG_WRITEF( _L("New ad-hoc WLAN IAP:" ));
       
   478                 CLOG_WRITEF( _L("  iWlanServiceId = %d"), static_cast<TUint>( wlanRecord->iWlanServiceId ) );
       
   479                 CLOG_WRITEF( _L("  iWlanConnMode  = %d"), static_cast<TUint>( wlanRecord->iWlanConnMode ) );
       
   480                 CLOG_WRITEF( _L("  iWLanSSID      = %S"), &(static_cast<TDesC>( wlanRecord->iWLanSSID ) ) );
       
   481             
       
   482                 // Create an iap record
       
   483                 CCDIAPRecord* iapRecord = static_cast<CCDIAPRecord*> ( 
       
   484                     CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
   485                 CleanupStack::PushL( iapRecord );
       
   486             
       
   487                 iapRecord->iServiceType.SetL( TPtrC( KCDTypeNameLANService ) );
       
   488                 // Set the service field to the same value as in the wlan service record we are currently looking
       
   489                 iapRecord->iService = wlanRecord->iWlanServiceId;
       
   490                 // Find the matching iap record
       
   491                 if( iapRecord->FindL( *db ) )
       
   492                     {
       
   493                     TUint iapId( 0 );
       
   494                 
       
   495                     // read the iap id
       
   496                     iapId = iapRecord->RecordId();
       
   497                     CLOG_WRITEF( _L("  iapId          = %d"), iapId );
       
   498                 
       
   499                     AddConnectionMethodItemL( iapId, 
       
   500                                               iDestId == 0,
       
   501                                               easyWlanIsInDb, 
       
   502                                               iapId == iDefaultCMId );
       
   503                     }
       
   504                 CleanupStack::PopAndDestroy( iapRecord );
       
   505                 }
       
   506             }
       
   507         }
       
   508     else
       
   509         {
       
   510         CLOG_WRITEF( _L("no matcing wlan records found." ));
       
   511         }
       
   512         
       
   513     CleanupStack::PopAndDestroy( wlanSet );
       
   514     CleanupStack::PopAndDestroy( db );
       
   515     
       
   516     CLOG_LEAVEFN( "CActiveSelectExplicit::AddAdhocWlanIapsL" );
       
   517     }
       
   518     
       
   519 // End of File