wlanutilities/wlansniffer/wlaninfosorting/src/wsfwlaninfoarrayvisitor.cpp
branchRCL_3
changeset 55 f28ada11abbf
parent 0 56b72877c1cb
equal deleted inserted replaced
54:63be7eb3fc78 55:f28ada11abbf
       
     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:  Implementation of CWsfWlanInfoArrayVisitor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <badesca.h> 
       
    22 #include <e32base.h> 
       
    23 #include <eikenv.h>
       
    24 #include <bautils.h>
       
    25 #include <data_caging_path_literals.hrh>
       
    26 
       
    27 //  CLASS HEADER
       
    28 #include "wsfwlaninfoarrayvisitor.h"
       
    29 
       
    30 //INTERNAL INCLUDES
       
    31 #include "wsfwlaninfosortingbrand.h"
       
    32 #include "wsfwlaninfosortingdefault.h"
       
    33 #include "wsfwlaninfosortingblacklist.h"
       
    34 #include "wsfwlaninfoarray.h"
       
    35 #include "wsfwlaninfosortingdbchangenotifier.h"
       
    36 
       
    37 
       
    38 /**
       
    39 * Blacklist database identifier
       
    40 */
       
    41 _LIT( KBlacklistDbFormat, "SECURE[2000cf30]" );
       
    42 
       
    43 /**
       
    44 * Blacklist database file name
       
    45 */
       
    46 _LIT( KBlacklistDbName, "c:wsfblacklist.db" );
       
    47 
       
    48 /**
       
    49 * ROM folder
       
    50 */
       
    51 _LIT( KDriveZ, "z:" );
       
    52 
       
    53 /**
       
    54 * Resource file name
       
    55 */
       
    56 _LIT( KResourceFileName, "wsfwlaninfosorting.rsc" );
       
    57 
       
    58 
       
    59 #ifdef _DEBUG
       
    60     _LIT( KCWsfWlanInfoArrayVisitor, "arrayvisitor" );
       
    61 	#define __ASSERTD( cond ) __ASSERT_DEBUG( (cond),  User::Panic( KCWsfWlanInfoArrayVisitor, __LINE__) )
       
    62 #else
       
    63     #define __ASSERTD( cond )
       
    64 #endif //_DEBUG
       
    65 
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CWsfWlanInfoArrayVisitor::NewLC
       
    69 // ----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CWsfWlanInfoArrayVisitor* CWsfWlanInfoArrayVisitor::NewLC( 
       
    72                                                         const TBool aReadOnly )
       
    73 	{
       
    74 	CWsfWlanInfoArrayVisitor* thisPtr = new (ELeave) CWsfWlanInfoArrayVisitor( 
       
    75 	                                                               aReadOnly );
       
    76 	CleanupStack::PushL( thisPtr );
       
    77 	thisPtr->ConstructL();
       
    78 	return thisPtr;
       
    79 	}
       
    80 
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CWsfWlanInfoArrayVisitor::NewL
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C CWsfWlanInfoArrayVisitor* CWsfWlanInfoArrayVisitor::NewL( 
       
    87                                                         const TBool aReadOnly ) 
       
    88 	{
       
    89 	CWsfWlanInfoArrayVisitor* thisPtr = NewLC( aReadOnly );
       
    90 	CleanupStack::Pop();
       
    91 	return thisPtr;
       
    92 	}
       
    93 
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // CWsfWlanInfoArrayVisitor::~CWsfWlanInfoArrayVisitor
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C CWsfWlanInfoArrayVisitor::~CWsfWlanInfoArrayVisitor()  
       
   100 	{
       
   101 	delete iDbChangeNotifier;
       
   102 	delete iBlackListSorting;
       
   103 	delete iBrandSorting; 
       
   104 	delete iDefaultSorting;
       
   105 	
       
   106 	iFilterDb.Close();
       
   107 	
       
   108 	
       
   109 	iDbms.Close();
       
   110 	iFileServer.Close();
       
   111 	
       
   112 	// let the resourcefile go..
       
   113 	if ( iResourceFileOffset != -1 )
       
   114 		{
       
   115 		iCoeEnv.DeleteResourceFile( iResourceFileOffset );			
       
   116 		}
       
   117 
       
   118 	}
       
   119 
       
   120 
       
   121 // ----------------------------------------------------------------------------
       
   122 // CWsfWlanInfoArrayVisitor::CWsfWlanInfoArrayVisitor
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 CWsfWlanInfoArrayVisitor::CWsfWlanInfoArrayVisitor( const TBool aReadOnly ): 
       
   126     TKeyArrayFix( 0, ECmpNormal ),
       
   127 	iCoeEnv( *CEikonEnv::Static() ),
       
   128 	iResourceFileOffset( -1 ),
       
   129 	iReadOnly( aReadOnly )
       
   130 	{
       
   131 	}
       
   132 
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CWsfWlanInfoArrayVisitor::ConstructL
       
   136 // ----------------------------------------------------------------------------
       
   137 //
       
   138 void CWsfWlanInfoArrayVisitor::ConstructL()
       
   139 	{
       
   140     TFileName resourceFileName;
       
   141 
       
   142     resourceFileName.Append( KDriveZ );
       
   143     resourceFileName.Append( KDC_RESOURCE_FILES_DIR );   
       
   144     resourceFileName.Append( KResourceFileName );
       
   145 
       
   146     BaflUtils::NearestLanguageFile( iCoeEnv.FsSession(), resourceFileName );
       
   147     iResourceFileOffset = iCoeEnv.AddResourceFileL( resourceFileName );
       
   148 
       
   149 	
       
   150 	User::LeaveIfError( iFileServer.Connect() );
       
   151 	User::LeaveIfError( iDbms.Connect() );
       
   152 	
       
   153 	OpenDataBaseL();
       
   154 
       
   155 	
       
   156 	iDefaultSorting = CWsfWlanInfoSortingDefault::NewL();
       
   157 	iBrandSorting = CWsfWlanInfoSortingBrand::NewL();
       
   158 	iBlackListSorting = CWsfWlanInfoSortingBlackList::NewL( iFilterDb );
       
   159 	
       
   160 	iDbChangeNotifier = CWsfWlanInfoSortingDbChangeNotifier::NewL( iFilterDb );
       
   161 	iDbChangeNotifier->AppendDbRelatedFilterL( iBlackListSorting );
       
   162 	}
       
   163 
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CWsfWlanInfoArrayVisitor::FilterPreSortL
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C void CWsfWlanInfoArrayVisitor::FilterPreSortL( 
       
   170                                         CWsfWlanInfoArray* aArrayToBeFiltered )
       
   171 	{
       
   172 	__ASSERTD( aArrayToBeFiltered );
       
   173 	
       
   174 	// go through the filters  
       
   175 	// store the array ref
       
   176 	
       
   177 	TInt arrayLoopCount( aArrayToBeFiltered->Count() );
       
   178 	TWsfWlanInfo* wlanInfo;
       
   179 	
       
   180 	for ( TInt arrayLoop( 0 ); arrayLoop < arrayLoopCount; ++arrayLoop )
       
   181 		{
       
   182 		wlanInfo = aArrayToBeFiltered->At( arrayLoop );
       
   183 		
       
   184 		// blacklist sorting must come first to be able to filter out 
       
   185 		// customer favourite networks, too
       
   186 		if ( !iBlackListSorting->SetupOnRuleMatch( *wlanInfo ) )
       
   187 			{
       
   188 		    iBrandSorting->SetupOnRuleMatch( *wlanInfo );
       
   189 			}
       
   190 		}
       
   191 	
       
   192 	iInfoArray = aArrayToBeFiltered;
       
   193 	}
       
   194 
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CWsfWlanInfoArrayVisitor::FilterPostSortL
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 EXPORT_C void CWsfWlanInfoArrayVisitor::FilterPostSortL( 
       
   201                                         CWsfWlanInfoArray* aArrayToBeFiltered )
       
   202 	{
       
   203 	__ASSERTD( aArrayToBeFiltered );
       
   204 	
       
   205 	// go through the filters....
       
   206 	
       
   207 	// we could remove the entries which are marked as blacklist entries...
       
   208 	TInt arrayLoopCount( aArrayToBeFiltered->Count() );
       
   209 	TWsfWlanInfo* wlanInfo;
       
   210 
       
   211 	for ( TInt arrayLoop( arrayLoopCount - 1); arrayLoop >= 0; --arrayLoop )
       
   212 		{
       
   213 		wlanInfo =  aArrayToBeFiltered->At( arrayLoop );
       
   214 		if ( wlanInfo->BlackListEntry() && !wlanInfo->Connected() )
       
   215 			{
       
   216 			// filter out only non-connected items
       
   217 			aArrayToBeFiltered->Delete( wlanInfo );
       
   218 			}
       
   219 		}
       
   220 	// and let the iInfoArray expire..
       
   221 	iInfoArray = NULL;
       
   222 	}
       
   223 
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CWsfWlanInfoArrayVisitor::SortingKey
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TKeyArrayFix& CWsfWlanInfoArrayVisitor::SortingKey() 
       
   230 	{
       
   231 	return *this;
       
   232 	}
       
   233 
       
   234 
       
   235 // ----------------------------------------------------------------------------
       
   236 // CWsfWlanInfoArrayVisitor::LoadFilterDefinitionsL
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 EXPORT_C void CWsfWlanInfoArrayVisitor::LoadFilterDefinitionsL()
       
   240 	{
       
   241 	// filter by filter - call the load
       
   242 	iDefaultSorting->ReadFilterDefsL();
       
   243 	iBrandSorting->ReadFilterDefsL();
       
   244 	iBlackListSorting->ReadFilterDefsL();
       
   245 	if ( iReadOnly && !iDbChangeNotifier->IsActive() )
       
   246 		{
       
   247 		iDbChangeNotifier->StartDbObservation();
       
   248 		}
       
   249 	}
       
   250 
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // CWsfWlanInfoArrayVisitor::AppendBrandingIconsL
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 EXPORT_C void CWsfWlanInfoArrayVisitor::AppendBrandingIconsL( 
       
   257                                                     CAknIconArray& aIconArray )
       
   258 	{
       
   259 	iBrandSorting->AppendBrandIconsL( aIconArray );
       
   260 	}
       
   261 
       
   262 
       
   263 // ----------------------------------------------------------------------------
       
   264 // CWsfWlanInfoArrayVisitor::EditBlackListL
       
   265 // ----------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CWsfWlanInfoArrayVisitor::EditBlackListL( 
       
   268                                             CWsfWlanInfoArray& aInfoItemArray )
       
   269 	{
       
   270 	iBlackListSorting->EditFilterDefsL( aInfoItemArray );
       
   271 	}
       
   272 
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 // CWsfWlanInfoArrayVisitor::BlackListItemCount
       
   276 // ----------------------------------------------------------------------------
       
   277 //
       
   278 EXPORT_C TInt CWsfWlanInfoArrayVisitor::BlackListItemCount() const
       
   279     {
       
   280     return iBlackListSorting->BlackListItemCount();
       
   281     }
       
   282     
       
   283 	
       
   284 // ----------------------------------------------------------------------------
       
   285 // CWsfWlanInfoArrayVisitor::Compare
       
   286 // ----------------------------------------------------------------------------
       
   287 //
       
   288 TInt CWsfWlanInfoArrayVisitor::Compare( TInt aLeft, TInt aRight ) const
       
   289 	{
       
   290 	TWsfWlanInfo* left = iInfoArray->At( aLeft );
       
   291 	TWsfWlanInfo* right = iInfoArray->At( aRight );
       
   292 	
       
   293 	__ASSERTD( left );
       
   294 	__ASSERTD( right );	
       
   295 	
       
   296 	return iDefaultSorting->Compare( *left, *right );
       
   297 	}
       
   298 
       
   299 
       
   300 // ----------------------------------------------------------------------------
       
   301 // CWsfWlanInfoArrayVisitor::OpenDataBaseL
       
   302 // ----------------------------------------------------------------------------
       
   303 //
       
   304 void CWsfWlanInfoArrayVisitor::OpenDataBaseL()
       
   305 	{
       
   306     if ( iFilterDb.Open( iDbms, KBlacklistDbName, KBlacklistDbFormat ) != 
       
   307                                                                      KErrNone )
       
   308         {
       
   309 		User::LeaveIfError( iFilterDb.Create( iDbms, 
       
   310 		                                      KBlacklistDbName, 
       
   311 		                                      KBlacklistDbFormat ) );
       
   312 		
       
   313 		// create tables in the new database
       
   314 		CWsfWlanInfoSortingBlackList::NewLC( iFilterDb );
       
   315 		CleanupStack::PopAndDestroy();
       
   316 		}
       
   317 	}
       
   318 
       
   319