wlanutilities/wlansniffer/wlaninfosorting/src/wsfwlaninfosortingbrand.cpp
branchRCL_3
changeset 24 63be7eb3fc78
parent 23 b852595f5cbe
child 25 f28ada11abbf
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
     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 CWsfWlanInfoSortingBrand
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <eikenv.h>
       
    22 #include <barsread.h>
       
    23 #include <gulicon.h>
       
    24 #include <AknIconArray.h>
       
    25 #include <AknIconUtils.h>
       
    26 #include <mifconvdefs.h>
       
    27 #include <wsfwlaninfosorting.rsg>
       
    28 
       
    29 //  CLASS HEADER
       
    30 #include "wsfwlaninfosortingbrand.h"
       
    31 
       
    32 
       
    33 
       
    34 /**
       
    35 * Compare result: left-hand item goes first
       
    36 */
       
    37 static const TInt KLeftFirst = -1;
       
    38 
       
    39 /**
       
    40 * Compare result: right-hand item goes first
       
    41 */
       
    42 static const TInt KRightFirst = 1;
       
    43 
       
    44 
       
    45 
       
    46 #ifdef _DEBUG
       
    47     // Add own assert debug 
       
    48     // implementation if needed
       
    49 	#define __ASSERTD( cond )
       
    50 #else
       
    51     #define __ASSERTD( cond )
       
    52 #endif //_DEBUG
       
    53 
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CWsfWlanInfoSortingBrand::TBrandableItem::TBrandableItem
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CWsfWlanInfoSortingBrand::TBrandableItem::TBrandableItem():
       
    61 	iSsid( KNullDesC8 ),
       
    62 	iBrandId( 0 )
       
    63 	{
       
    64 	}
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CWsfWlanInfoSortingBrand::TBrandableItem::TBrandableItem
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CWsfWlanInfoSortingBrand::TBrandableItem::TBrandableItem( const TDesC8& aSsid, 
       
    72                                                         const TInt8 aBrandId ):
       
    73 	iSsid( aSsid ),
       
    74 	iBrandId( aBrandId )
       
    75 	{
       
    76 	}
       
    77 	
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CWsfWlanInfoSortingBrand::TBrandableItem::Match
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 TBool CWsfWlanInfoSortingBrand::TBrandableItem::Match(
       
    84                                             const TBrandableItem& aItemLeft, 
       
    85                                             const TBrandableItem& aItemRight )
       
    86 	{
       
    87 	return aItemLeft.iSsid.Compare( aItemRight.iSsid ) == 0;
       
    88 	}
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CWsfWlanInfoSortingBrand::TBrandableItem::SortByBrandId
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 TInt CWsfWlanInfoSortingBrand::TBrandableItem::SortByBrandId( 
       
    96                                             const TBrandableItem& aItemLeft, 
       
    97                                             const TBrandableItem& aItemRight )
       
    98 	{
       
    99 	return aItemLeft.iBrandId - aItemRight.iBrandId;
       
   100 	}
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CWsfWlanInfoSortingBrand::TBrandableItem::SortBySsid
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 TInt CWsfWlanInfoSortingBrand::TBrandableItem::SortBySsid( 
       
   108                                             const TBrandableItem& aItemLeft, 
       
   109                                             const TBrandableItem& aItemRight )
       
   110 	{
       
   111 	return aItemLeft.iSsid.Compare( aItemRight.iSsid );	
       
   112 	}
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CWsfWlanInfoSortingBrand::NewLC
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CWsfWlanInfoSortingBrand* CWsfWlanInfoSortingBrand::NewLC()
       
   120 	{
       
   121 	CWsfWlanInfoSortingBrand* thisPtr = 
       
   122 	                                new (ELeave) CWsfWlanInfoSortingBrand();
       
   123 	CleanupStack::PushL( thisPtr );
       
   124 	thisPtr->ConstructL();
       
   125 	return thisPtr;
       
   126 	}
       
   127 
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CWsfWlanInfoSortingBrand::NewL
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 CWsfWlanInfoSortingBrand* CWsfWlanInfoSortingBrand::NewL()
       
   134 	{
       
   135 	CWsfWlanInfoSortingBrand* thisPtr = NewLC();
       
   136 	CleanupStack::Pop( thisPtr );
       
   137 	return thisPtr;
       
   138 	}
       
   139 
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CWsfWlanInfoSortingBrand::CWsfWlanInfoSortingBrand
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 CWsfWlanInfoSortingBrand::CWsfWlanInfoSortingBrand():
       
   146 	iBitmapFileName( NULL ),
       
   147 	iBrandingDataOk( EFalse )
       
   148 	{
       
   149 	}
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CWsfWlanInfoSortingBrand::~CWsfWlanInfoSortingBrand
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 CWsfWlanInfoSortingBrand::~CWsfWlanInfoSortingBrand()
       
   157 	{
       
   158 	delete iBitmapFileName;
       
   159 	iBrandItemArray.ResetAndDestroy();
       
   160 	}
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CWsfWlanInfoSortingBrand::ConstructL
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CWsfWlanInfoSortingBrand::ConstructL()
       
   168 	{
       
   169 	// nothing to do...
       
   170 	}
       
   171 
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CWsfWlanInfoSortingBrand::Compare
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 TInt CWsfWlanInfoSortingBrand::Compare( const TWsfWlanInfo& aLeft, 
       
   178                                         const TWsfWlanInfo& aRight )
       
   179 	{
       
   180 	TInt ret( 0 );
       
   181 	
       
   182     // connected goes first 
       
   183  	if ( aLeft.Connected() )
       
   184  	    {
       
   185  	    ret = KLeftFirst;
       
   186  	    }
       
   187  	else if ( aRight.Connected() )
       
   188  	    {
       
   189  	    ret = KRightFirst;
       
   190  	    }
       
   191  	
       
   192  	// then customer favourite networks
       
   193  	else if ( aLeft.BrandId() )
       
   194  	    {
       
   195  	    if ( aRight.BrandId() )
       
   196  	        {
       
   197  	        // smaller brand id first
       
   198  	        ret = aLeft.BrandId() - aRight.BrandId();
       
   199  	        }
       
   200  	    else
       
   201  	        {
       
   202  	        ret = KLeftFirst;
       
   203  	        }
       
   204  	    }
       
   205  	else if ( aRight.BrandId() )
       
   206  	    {
       
   207  	    ret = KRightFirst;
       
   208  	    }
       
   209  	
       
   210  	
       
   211  	// then known networks
       
   212  	else if ( aLeft.Known() && !aRight.Known() )
       
   213  	    {
       
   214  	    ret = KLeftFirst;
       
   215  	    }
       
   216  	else if ( !aLeft.Known() && aRight.Known() )
       
   217  	    {
       
   218  	    ret = KRightFirst;
       
   219  	    }
       
   220  	    
       
   221  	// finally SSID alphabetic order decides
       
   222  	else
       
   223  	    {
       
   224  	    if ( ( aLeft.iNetworkName.Length() ) && 
       
   225  	         ( aRight.iNetworkName.Length() ) )
       
   226  	        {
       
   227  	        ret = aLeft.iNetworkName.CompareC( aRight.iNetworkName );
       
   228  	        }
       
   229  	    else if ( aLeft.iNetworkName.Length() )
       
   230  	        {
       
   231  	        ret = aLeft.iNetworkName.CompareC( aRight.iSsid );
       
   232  	        }
       
   233  	    else if ( aRight.iNetworkName.Length() )
       
   234  	        {
       
   235  	        ret = aLeft.iSsid.CompareC( aRight.iNetworkName );
       
   236  	        }
       
   237         else
       
   238             {
       
   239             ret = aLeft.iSsid.CompareC( aRight.iSsid );
       
   240             }
       
   241  	    }
       
   242  	    
       
   243  	return ret;
       
   244 	}
       
   245 
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CWsfWlanInfoSortingBrand::SetupOnRuleMatch
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 TBool CWsfWlanInfoSortingBrand::SetupOnRuleMatch( TWsfWlanInfo& aInfoLeft )
       
   252 	{
       
   253 	TBool ret( EFalse );
       
   254 	// check if the entry already has an branding flag on - return ETrue
       
   255 	
       
   256 	if ( iBrandingDataOk && !aInfoLeft.BrandId() )
       
   257 		{
       
   258     	// using the ssid... try to find the ssid from iBrandItemArray
       
   259     	TBrandableItem item;
       
   260     	item.iSsid = aInfoLeft.iSsid;
       
   261     	
       
   262     	TLinearOrder<TBrandableItem> findBinarySsid( 
       
   263                     CWsfWlanInfoSortingBrand::TBrandableItem::SortBySsid );
       
   264     	
       
   265     	TInt entryFindValue = iBrandItemArray.FindInOrder( &item, 
       
   266     	                                                  findBinarySsid );
       
   267     	if ( entryFindValue != KErrNotFound )
       
   268     		{
       
   269     		// mark the entry...
       
   270     		aInfoLeft.SetBrand( 
       
   271     		                iBrandItemArray[entryFindValue]->iBrandId );
       
   272     		ret = ETrue;
       
   273     		}
       
   274 
       
   275 		}
       
   276 		
       
   277 	return ret;
       
   278 	}
       
   279 
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CWsfWlanInfoSortingBrand::MarkMatchedFilterL
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CWsfWlanInfoSortingBrand::MarkMatchedFilterL( 
       
   286                                               TWsfWlanInfo& /*aFilterEntry*/ )
       
   287 	{
       
   288 	// we do not modify the contents in default filter...
       
   289 	}
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CWsfWlanInfoSortingBrand::EditFilterDefsL
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CWsfWlanInfoSortingBrand::EditFilterDefsL( 
       
   297                                            CWsfWlanInfoArray& /*aInfoArray*/ )
       
   298 	{
       
   299 	// we have hardcoded rules... we don't need editui..
       
   300 	}
       
   301 
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // CWsfWlanInfoSortingBrand::ReadFilterDefsL
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 void CWsfWlanInfoSortingBrand::ReadFilterDefsL()
       
   308 	{
       
   309 	ReadBrandedSsidsL();
       
   310 	}
       
   311 
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CWsfWlanInfoSortingBrand::ReadBrandedSsidsL
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 void CWsfWlanInfoSortingBrand::ReadBrandedSsidsL()
       
   318 	{
       
   319 	iBrandItemArray.ResetAndDestroy();
       
   320 	iBrandingDataOk = EFalse;
       
   321 
       
   322 	TResourceReader reader;
       
   323 	CEikonEnv& env = *CEikonEnv::Static();
       
   324 	env.CreateResourceReaderLC( reader, R_QTN_SSID_BRANDING );
       
   325 	
       
   326 	delete iBitmapFileName;
       
   327 	iBitmapFileName = NULL;
       
   328 
       
   329 	// ok - lets read the filename...
       
   330 	iBitmapFileName = reader.ReadHBufCL();
       
   331 	
       
   332 	if ( iBitmapFileName ) // not iconfilename defined.... 
       
   333 		{
       
   334     	// try to locate the icon file 
       
   335     	TFindFile finder( env.FsSession() );
       
   336     	
       
   337     	TParsePtrC parser( *iBitmapFileName );
       
   338 
       
   339         TInt findError = finder.FindByDir( parser.NameAndExt(), 
       
   340                                            parser.Path() );
       
   341 
       
   342     	delete iBitmapFileName;
       
   343     	iBitmapFileName = NULL;
       
   344 
       
   345         if ( !findError )
       
   346         	{
       
   347         	iBitmapFileName = finder.File().AllocL();
       
   348         	
       
   349         	TInt brandedItemCount = reader.ReadInt16();
       
   350         	TBrandableItem* brandableItem = NULL;
       
   351 
       
   352         	CDesC8ArrayFlat* ssidArray = NULL;
       
   353         	TInt iconId( 0 );
       
   354         	TInt maskId( 0 );
       
   355 
       
   356         	for ( TInt readCount( 0 ); readCount < brandedItemCount; 
       
   357         	                                                      ++readCount )
       
   358         		{
       
   359         		ssidArray = reader.ReadDesC8ArrayL();
       
   360         		CleanupStack::PushL( ssidArray );
       
   361 
       
   362         		iconId = reader.ReadInt16();
       
   363         		maskId = reader.ReadInt16();
       
   364 
       
   365         		TInt ssidCount( ssidArray->Count() );
       
   366         		
       
   367         		for ( TInt ssidIter( 0 ); ssidIter < ssidCount; ssidIter++ )
       
   368         			{
       
   369         			brandableItem = new (ELeave) TBrandableItem;
       
   370         			brandableItem->iSsid = ssidArray->MdcaPoint( ssidIter );
       
   371         			brandableItem->iBrandId = readCount + 1;
       
   372         			brandableItem->iIconId = iconId;
       
   373         			brandableItem->iMaskId = maskId;
       
   374         			iBrandItemArray.AppendL( brandableItem );
       
   375         			}		
       
   376         		CleanupStack::PopAndDestroy( ssidArray );
       
   377         		}
       
   378 
       
   379         	// and to speed up the ssid match sort the array by ssid
       
   380         	TLinearOrder<TBrandableItem> sortingRuleSSId( 
       
   381         	            CWsfWlanInfoSortingBrand::TBrandableItem::SortBySsid );
       
   382         	
       
   383         	iBrandItemArray.Sort( sortingRuleSSId );
       
   384         	iBrandingDataOk = ( iBrandItemArray.Count() > 0 );
       
   385         	}
       
   386     		
       
   387 		}
       
   388         
       
   389 	CleanupStack::PopAndDestroy(); //reader	        
       
   390 	}
       
   391 
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CWsfWlanInfoSortingBrand::AppendBrandIconsL
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CWsfWlanInfoSortingBrand::AppendBrandIconsL( CAknIconArray& aIconArray )
       
   398 	{
       
   399 	if ( iBrandingDataOk )
       
   400 		{
       
   401     	// sort the array by brandid	
       
   402     	TLinearOrder<TBrandableItem> sortingRule( 
       
   403     	             CWsfWlanInfoSortingBrand::TBrandableItem::SortByBrandId );
       
   404     	
       
   405     	iBrandItemArray.Sort( sortingRule );
       
   406     		
       
   407     		
       
   408     	// loop here - load icon and append to array....
       
   409     	TBrandableItem* item;
       
   410     	TInt brandArrayCount( iBrandItemArray.Count() );
       
   411     	TInt brandId( 0 );
       
   412     	for ( TInt loopCounter( 0 ); loopCounter < brandArrayCount; 
       
   413     	                                                        ++loopCounter )
       
   414     		{
       
   415     		item = iBrandItemArray[ loopCounter ];
       
   416     		if ( item->iBrandId > brandId ) 
       
   417     			{
       
   418         		brandId	= item->iBrandId;
       
   419         		aIconArray.AppendL( MakeIconLC( item->iIconId, 
       
   420         		                                             item->iMaskId ) );
       
   421         		CleanupStack::Pop(); // icon
       
   422     			}
       
   423     		}
       
   424     		
       
   425     	// and to speed up the ssid match sort the array by ssid
       
   426     	TLinearOrder<TBrandableItem> sortingRuleSSId( 
       
   427     	                CWsfWlanInfoSortingBrand::TBrandableItem::SortBySsid );
       
   428     	
       
   429     	iBrandItemArray.Sort( sortingRuleSSId );
       
   430 
       
   431 		}
       
   432 		
       
   433 	}
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CWsfWlanInfoSortingBrand::MakeIconLC
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 CGulIcon* CWsfWlanInfoSortingBrand::MakeIconLC( const TInt aIconId, 
       
   441                                                 const TInt aMaskId )
       
   442 	{
       
   443 	CGulIcon* icon = CGulIcon::NewLC();
       
   444 	CFbsBitmap* bitmap( NULL );   
       
   445 	CFbsBitmap* mask( NULL );   
       
   446       
       
   447 	// Creates bitmap an icon.
       
   448     AknIconUtils::CreateIconL( bitmap, mask, *iBitmapFileName, 
       
   449                                aIconId, aMaskId );
       
   450 
       
   451    	icon->SetBitmap( bitmap );   
       
   452    	icon->SetMask( mask ); 
       
   453     return icon;    		  	
       
   454 	}
       
   455 
       
   456 
       
   457 
       
   458