wlanutilities/wlanplugin/src/wlanplugin.cpp
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     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:  WlanPlugin class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // User includes
       
    22 #include "wlanplugin.h"
       
    23 #include "wlanpluginwlanstate.h"
       
    24 #include "wlanpluginlogger.h"
       
    25 
       
    26 // System includes
       
    27 #include <wlanpluginrsc.rsg>
       
    28 #include <gsparentplugin.h>
       
    29 #include <gsfwviewuids.h>
       
    30 #include <AknNullService.h>
       
    31 #include <bautils.h>
       
    32 #include <StringLoader.h>
       
    33 #include <featmgr.h>
       
    34 #include <AknGlobalNote.h>
       
    35 #include <ErrorUI.h>
       
    36 
       
    37 
       
    38 // Resource file location
       
    39 _LIT( KWlanPluginResourceFileName, "z:wlanpluginrsc.rsc" );
       
    40 
       
    41 // ROM folder
       
    42 _LIT( KDriveZ, "z:" );
       
    43 
       
    44 // Name of the MBM file containing icons
       
    45 _LIT( KFileIcons, "wlanplugin.mif");
       
    46 
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CWlanPlugin::NewL
       
    51 // First phase constructor
       
    52 // ---------------------------------------------------------
       
    53 CWlanPlugin* CWlanPlugin::NewL( TAny* /*aInitParams*/ )
       
    54     {
       
    55     CWlanPlugin* self = new ( ELeave ) CWlanPlugin();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;     
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // Destructor
       
    64 // ---------------------------------------------------------
       
    65 CWlanPlugin::~CWlanPlugin()
       
    66     {
       
    67     CLOG_ENTERFN( "CWlanPlugin::~CWlanPlugin()" );  
       
    68             
       
    69     iResources.Close();
       
    70     
       
    71     if( iNullService )
       
    72         {
       
    73         delete iNullService;
       
    74         }
       
    75     if ( iWlanState )
       
    76         {
       
    77         delete iWlanState;
       
    78         }
       
    79         
       
    80     CLOG_ENTERFN( "CWlanPlugin::~CWlanPlugin()" );    
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CWlanPlugin::ConstructL
       
    85 // ---------------------------------------------------------
       
    86 TAny CWlanPlugin::ConstructL()
       
    87     {
       
    88     CLOG_CREATE;
       
    89     
       
    90     CLOG_ENTERFN( "CWlanPlugin::ConstructL()" );
       
    91     
       
    92     BaseConstructL(); 
       
    93     
       
    94     OpenLocalizedResourceFileL();    
       
    95                                 
       
    96     // Check Wlan support in construction phase to
       
    97     // avoid creating of plugin when it is not necessary. 
       
    98     if( GetWlanSupported() ) 
       
    99         {
       
   100         // This is the parent plugin
       
   101         CGSParentPlugin* parent = static_cast<CGSParentPlugin*>(
       
   102                  AppUi()->View( KGSConPluginUid ) );
       
   103             
       
   104         iWlanState = CWlanPluginWlanState::NewL( parent );
       
   105         }
       
   106     else 
       
   107         {
       
   108         User::Leave( KErrNotSupported );
       
   109         }
       
   110     
       
   111     CLOG_LEAVEFN( "CWlanPlugin::ConstructL()" );
       
   112     }
       
   113     
       
   114 // ---------------------------------------------------------
       
   115 // CWlanPlugin::Id
       
   116 // ---------------------------------------------------------
       
   117 TUid CWlanPlugin::Id() const
       
   118     {
       
   119     CLOG_ENTERFN( "CWlanPlugin::Id()" );
       
   120     
       
   121     CLOG_LEAVEFN( "CWlanPlugin::Id()" );
       
   122     
       
   123     return KWlanPluginUid;
       
   124     
       
   125     }
       
   126         
       
   127 // ---------------------------------------------------------
       
   128 // CWlanPlugin::DoActivateL
       
   129 // ---------------------------------------------------------
       
   130 void CWlanPlugin::DoActivateL( const TVwsViewId& /*aPrevViewId*/, 
       
   131                                        TUid /*aCustomMessageId*/, 
       
   132                                        const TDesC8& /*aCustomMessage*/ )
       
   133     {
       
   134     CLOG_ENTERFN( "CWlanPlugin::DoActivateL()" );
       
   135     //no implementation required
       
   136     CLOG_LEAVEFN( "CWlanPlugin::DoActivateL()" );
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CWlanPlugin::DoDeactivate
       
   141 // ---------------------------------------------------------
       
   142 void CWlanPlugin::DoDeactivate()
       
   143     {
       
   144     CLOG_ENTERFN( "CWlanPlugin::DoDeactivate()" );
       
   145     //no implementation required
       
   146     CLOG_LEAVEFN( "CWlanPlugin::DoDeactivate()" );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CWlanPlugin::GetCaptionL
       
   151 // ---------------------------------------------------------
       
   152 void CWlanPlugin::GetCaptionL( TDes& aCaption ) const
       
   153     {
       
   154     CLOG_ENTERFN( "CWlanPlugin::GetCaptionL()" );
       
   155     
       
   156     StringLoader::Load( aCaption, R_QTN_SET_FOLDER_CONN_WLAN );
       
   157     
       
   158     CLOG_LEAVEFN( "CWlanPlugin::GetCaptionL()" );    
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CWlanPlugin::HasBitmap
       
   163 // ---------------------------------------------------------
       
   164 TBool CWlanPlugin::HasBitmap() const
       
   165     {
       
   166     CLOG_ENTERFN( "CWlanPlugin::HasBitmap()" );
       
   167     
       
   168     CLOG_LEAVEFN( "CWlanPlugin::HasBitmap()" ); 
       
   169     
       
   170     return EFalse;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CWlanPlugin::GetBitmapL
       
   175 // ---------------------------------------------------------
       
   176 void CWlanPlugin::GetBitmapL( CFbsBitmap* /*aBitmap*/, 
       
   177                                       CFbsBitmap* /*aMask*/ ) const
       
   178     {
       
   179     
       
   180     CLOG_ENTERFN( "CWlanPlugin::GetBitmapL()" );
       
   181     CLOG_LEAVEFN( "CWlanPlugin::GetBitmapL()" );    
       
   182     //no bitmap
       
   183     User::Leave( KErrNotFound );
       
   184     }
       
   185     
       
   186 // ---------------------------------------------------------
       
   187 // CWlanPlugin::PluginProviderCategory
       
   188 // ---------------------------------------------------------
       
   189 TInt CWlanPlugin::PluginProviderCategory() const
       
   190     {
       
   191     
       
   192     CLOG_ENTERFN( "CWlanPlugin::PluginProviderCategory()" );
       
   193     CLOG_LEAVEFN( "CWlanPlugin::PluginProviderCategory()" ); 
       
   194        
       
   195     return EGSPluginProviderOEM;
       
   196     }
       
   197     
       
   198 // ---------------------------------------------------------
       
   199 // CWlanPlugin::HandleSelection
       
   200 // ---------------------------------------------------------   
       
   201 void CWlanPlugin::HandleSelection(
       
   202             const TGSSelectionTypes /*aSelectionType*/ )
       
   203     {   
       
   204     CLOG_ENTERFN( "CWlanPlugin::HandleSelection()" );    
       
   205     
       
   206     TRAPD( error, LaunchSnifferAppL() );
       
   207     if( error != KErrNone && 
       
   208     	error != KErrNotFound &&
       
   209     	error != KErrServerTerminated )
       
   210         {
       
   211         ShowErrorNote( error );
       
   212         }
       
   213     
       
   214     CLOG_LEAVEFN( "CWlanPlugin::HandleSelection()" );     
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------
       
   218 // CWlanPlugin::ItemType
       
   219 // ---------------------------------------------------------
       
   220 TGSListboxItemTypes CWlanPlugin::ItemType()
       
   221     {
       
   222     
       
   223     CLOG_ENTERFN( "CWlanPlugin::ItemType()" );    
       
   224     CLOG_LEAVEFN( "CWlanPlugin::ItemType()" );     
       
   225     
       
   226     return EGSItemTypeSettingDialog;
       
   227     }
       
   228     
       
   229 // ---------------------------------------------------------
       
   230 // CWlanPlugin::CreateIconL
       
   231 // ---------------------------------------------------------    
       
   232 CGulIcon* CWlanPlugin::CreateIconL( const TUid aIconType )
       
   233     {
       
   234 
       
   235     CLOG_ENTERFN( "CWlanPlugin::CreateIconL()" );  
       
   236 
       
   237     TFileName iconsFileName;
       
   238 
       
   239     iconsFileName.Append( KDriveZ );
       
   240     iconsFileName.Append( KDC_APP_BITMAP_DIR );
       
   241     iconsFileName.Append( KFileIcons );
       
   242     
       
   243     CGulIcon* icon;
       
   244        
       
   245     TInt pic, picmask;
       
   246     TAknsItemID itemid;
       
   247     //if the main icon is asked   
       
   248     if ( aIconType == KGSIconTypeLbxItem )
       
   249         {
       
   250         if ( iWlanState->GetMainIconL( pic, picmask, itemid ) )
       
   251             {
       
   252             icon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   253                                               itemid, 
       
   254                                               iconsFileName, 
       
   255                                               pic, 
       
   256                                               picmask );
       
   257             }
       
   258         else
       
   259             {
       
   260             icon = CGSPluginInterface::CreateIconL( aIconType );
       
   261             }
       
   262         }
       
   263     //if the secondary icon is asked   
       
   264     else if ( aIconType == KGSIconTypeDColumn )
       
   265         {
       
   266         //if there should be icon
       
   267         if ( iWlanState->GetStrengthIconL( pic, picmask, itemid ) )
       
   268             {
       
   269             icon = CGulIcon::NewLC();
       
   270             CFbsBitmap* bitmap;
       
   271             CFbsBitmap* mask;
       
   272 
       
   273             // Creates bitmap an icon. 
       
   274             AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(), 
       
   275                                          itemid,
       
   276                                          KAknsIIDQsnIconColors, 
       
   277                                          EAknsCIQsnIconColorsCG13, 
       
   278                                          bitmap,
       
   279                                          mask, 
       
   280                                          iconsFileName, 
       
   281                                          pic, 
       
   282                                          picmask, 
       
   283                                          KRgbBlack );
       
   284 
       
   285             icon->SetBitmap( bitmap );
       
   286             icon->SetMask( mask );
       
   287             CleanupStack::Pop( icon );
       
   288             }
       
   289         //if there should be no icons
       
   290         else
       
   291             {
       
   292             icon = CGSPluginInterface::CreateIconL( aIconType );
       
   293             }
       
   294         }
       
   295      //in other case of icons
       
   296      else
       
   297         {
       
   298         icon = CGSPluginInterface::CreateIconL( aIconType );
       
   299         }
       
   300 
       
   301     CLOG_LEAVEFN( "CWlanPlugin::CreateIconL()" );     
       
   302 
       
   303     return icon;
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------
       
   307 // CVWlanPlugin::Visible
       
   308 // ---------------------------------------------------------
       
   309 TBool CWlanPlugin::Visible() const
       
   310     {
       
   311     
       
   312     CLOG_ENTERFN( "CWlanPlugin::Visible()" );    
       
   313     CLOG_LEAVEFN( "CWlanPlugin::Visible()" );     
       
   314     
       
   315     return GetWlanSupported();
       
   316     }
       
   317     
       
   318 // ---------------------------------------------------------
       
   319 // CWlanPlugin::CWlanPlugin
       
   320 // ---------------------------------------------------------
       
   321 CWlanPlugin::CWlanPlugin():
       
   322     iResources( *CCoeEnv::Static() ),
       
   323     iNullService( NULL )
       
   324     {
       
   325     // no implementation required
       
   326     }
       
   327     
       
   328 // ---------------------------------------------------------
       
   329 // CWlanPlugin::GetValue
       
   330 // ---------------------------------------------------------
       
   331 void CWlanPlugin::GetValue( const TGSPluginValueKeys aKey,
       
   332                        TDes& aValue )
       
   333     {    
       
   334     CLOG_ENTERFN( "CWlanPlugin::GetValue()" );    
       
   335     
       
   336     //if the second line of the listbox is asked
       
   337     if( aKey == EGSPluginKeySettingsItemValueString )
       
   338         {     
       
   339         TRAP_IGNORE( iWlanState->GetStateStringL( aValue ) );
       
   340         }
       
   341         
       
   342     CLOG_LEAVEFN( "CWlanPlugin::GetValue()" );     
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------
       
   346 // CWlanPlugin::OpenLocalizedResourceFileL
       
   347 // ---------------------------------------------------------
       
   348 void CWlanPlugin::OpenLocalizedResourceFileL()
       
   349     {
       
   350     CLOG_ENTERFN( "CWlanPlugin::OpenLocalizedResourceFileL()" );    
       
   351     
       
   352     
       
   353     RFs fsSession;
       
   354     User::LeaveIfError( fsSession.Connect() );
       
   355 
       
   356     // Find the resource file:
       
   357     TParse parse;
       
   358     parse.Set( KWlanPluginResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   359     TFileName fileName( parse.FullName() );
       
   360 
       
   361     // Get language of resource file:
       
   362     BaflUtils::NearestLanguageFile( fsSession, fileName );
       
   363 
       
   364     // Open resource file:
       
   365     iResources.OpenL( fileName );
       
   366 
       
   367     // If leave occurs before this, close is called automatically when the
       
   368     // thread exits.
       
   369     fsSession.Close();
       
   370     
       
   371     CLOG_LEAVEFN( "CWlanPlugin::OpenLocalizedResourceFileL()" );     
       
   372     }
       
   373     
       
   374 // ---------------------------------------------------------
       
   375 // CWlanPlugin::LaunchSnifferAppL
       
   376 // ---------------------------------------------------------    
       
   377 void CWlanPlugin::LaunchSnifferAppL()
       
   378     {
       
   379     CLOG_ENTERFN( "CWlanPlugin::LaunchSnifferAppL()" );    
       
   380     
       
   381     // Launch app
       
   382     if ( iNullService )
       
   383         {
       
   384         delete iNullService;
       
   385         iNullService = NULL;
       
   386         }         
       
   387     iNullService = CAknNullService::NewL( KSnifferAppUid, this );
       
   388        
       
   389     CLOG_LEAVEFN( "CWlanPlugin::LaunchSnifferAppL()" );         
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------
       
   393 // CWlanPlugin::GetWlanSupported
       
   394 // ---------------------------------------------------------
       
   395 TBool CWlanPlugin::GetWlanSupported() const
       
   396     {
       
   397     CLOG_ENTERFN( "CWlanPlugin::GetWlanSupported()" );    
       
   398      
       
   399     TBool isWlanSupported = EFalse;
       
   400     
       
   401     TRAPD( error, FeatureManager::InitializeLibL() );
       
   402     
       
   403     if( !error )
       
   404         {
       
   405         isWlanSupported = 
       
   406             FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );
       
   407         
       
   408         FeatureManager::UnInitializeLib();
       
   409         }
       
   410     
       
   411     CLOG_LEAVEFN( "CWlanPlugin::GetWlanSupported()" );         
       
   412     
       
   413     return isWlanSupported;
       
   414     }
       
   415 
       
   416 // ---------------------------------------------------------
       
   417 // CWlanPlugin::ShowErrorNote
       
   418 // ---------------------------------------------------------
       
   419 //
       
   420 void CWlanPlugin::ShowErrorNote(TInt aErrorCode)
       
   421     {
       
   422     CLOG_ENTERFN( "CWlanPlugin::ShowErrorNote()" );    
       
   423 
       
   424     
       
   425     TBool errorNoteShowed = EFalse;
       
   426         
       
   427     TRAPD(error, errorNoteShowed = ShowErrorNoteL(aErrorCode));
       
   428             
       
   429     if(error || !errorNoteShowed) 
       
   430         {
       
   431         TRAP_IGNORE( ShowGeneralErrorNoteL() );
       
   432         } 
       
   433         
       
   434     CLOG_LEAVEFN( "CWlanPlugin::ShowErrorNote()" );           
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------
       
   438 // CWlanPlugin::ShowErrorNoteL
       
   439 // ---------------------------------------------------------
       
   440 //
       
   441 TBool CWlanPlugin::ShowErrorNoteL(TInt aErrorCode)
       
   442     {
       
   443     CLOG_ENTERFN( "CWlanPlugin::ShowErrorNoteL()" );    
       
   444     
       
   445     CErrorUI* errorUi = CErrorUI::NewLC();
       
   446     
       
   447     TBool errorNoteShowed = errorUi->ShowGlobalErrorNoteL( aErrorCode );
       
   448     
       
   449     CleanupStack::PopAndDestroy( errorUi );
       
   450     
       
   451     CLOG_LEAVEFN( "CWlanPlugin::ShowErrorNoteL()" );           
       
   452         
       
   453     return errorNoteShowed;
       
   454     }    
       
   455 
       
   456 // ---------------------------------------------------------
       
   457 // CWlanPlugin::ShowGeneralErrorNoteL
       
   458 // ---------------------------------------------------------
       
   459 //
       
   460 void CWlanPlugin::ShowGeneralErrorNoteL()
       
   461     {
       
   462     CLOG_ENTERFN( "CWlanPlugin::ShowGeneralErrorNoteL()" );    
       
   463     
       
   464     HBufC *msg = StringLoader::LoadLC( R_QTN_ERR_OS_GENERAL );
       
   465     
       
   466     CAknGlobalNote *note = CAknGlobalNote::NewLC(); 
       
   467     
       
   468     note->ShowNoteL( EAknGlobalErrorNote, *msg );
       
   469 
       
   470     CleanupStack::PopAndDestroy( note );
       
   471     CleanupStack::PopAndDestroy( msg );
       
   472     
       
   473     CLOG_LEAVEFN( "CWlanPlugin::ShowGeneralErrorNoteL()" );           
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------
       
   477 // CWlanPlugin::HandleServerAppExit
       
   478 // ---------------------------------------------------------
       
   479 //
       
   480 void CWlanPlugin::HandleServerAppExit(TInt aReason)
       
   481 	{
       
   482 	CLOG_ENTERFN( "CWlanPlugin::HandleServerAppExit()" );  
       
   483 	//MAknServerAppExitObserver::HandleServerAppExit( aReason );
       
   484 	if( aReason == EAknCmdExit )
       
   485 		{
       
   486 		iAvkonViewAppUi->Exit();
       
   487 		}
       
   488 		
       
   489 	CLOG_LEAVEFN( "CWlanPlugin::HandleServerAppExit()" ); 
       
   490 	}
       
   491 
       
   492     
       
   493 //End of file