videofeeds/utils/src/CIptvUtil.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2005-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 the License "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:    Utility class and constants used by Iptv application.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <e32debug.h>
       
    23 #include <f32file.h>    // RFs
       
    24 #include <apgcli.h>     // RApaLsSession
       
    25 #include <s32mem.h>
       
    26 #include <centralrepository.h>
       
    27 #include <pathinfo.h> 
       
    28 //#include <oem/mplayerconstants.h> // Some Mime types used by player.
       
    29 #include <bautils.h>
       
    30 #include <bldvariant.hrh>
       
    31 
       
    32 #include "CIptvUtil.h"
       
    33 #include "IptvDebug.h"
       
    34 #include <WlanCdbCols.h>
       
    35 #include "CIptvDriveMonitor.h"
       
    36 #include "IptvExternalFolderInfo.h"
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 _LIT(KIptvRootPathC, ":\\data\\videocenter");  // System drive
       
    41 _LIT(KIptvRootPathE, ":\\data\\videocenter");  // E drive and other drives
       
    42 
       
    43 // Permanent folders. Beginning of path is generated dynamically.
       
    44 _LIT( KMyVideosExternalFolderOwn, "My Videos" );
       
    45 
       
    46 _LIT(KSlash,"\\");
       
    47 _LIT(KColonAndSlash, ":\\");
       
    48 
       
    49 static const TInt KNumberOfLanguages = 96;
       
    50 
       
    51 typedef struct
       
    52 	{
       
    53 	TLanguage iLanguage;
       
    54 	char* iLanguageCode;
       
    55 	} SLanguageItem;
       
    56 
       
    57 static const SLanguageItem languageArray[ KNumberOfLanguages ] =
       
    58 	{
       
    59 		{ ELangEnglish, "en" },
       
    60 		{ ELangFrench, "fr" },
       
    61 		{ ELangGerman, "de" },
       
    62 		{ ELangSpanish, "es" },
       
    63 		{ ELangItalian, "it" },
       
    64 		{ ELangSwedish, "sv" },
       
    65 		{ ELangDanish, "da" },
       
    66 		{ ELangNorwegian, "nn" },
       
    67 		{ ELangFinnish, "fi" },
       
    68 		{ ELangAmerican, "am" },
       
    69 		{ ELangSwissFrench, "sf" },
       
    70 		{ ELangSwissGerman, "sg" },
       
    71 		{ ELangPortuguese, "pt" },
       
    72 		{ ELangTurkish, "tr" },
       
    73 		{ ELangIcelandic, "is" },
       
    74 		{ ELangRussian, "ru" },
       
    75 		{ ELangHungarian, "hu" },
       
    76 		{ ELangDutch, "nl" },
       
    77 		{ ELangBelgianFlemish, "bl" },
       
    78 		{ ELangAustralian, "au" },
       
    79 		{ ELangBelgianFrench, "bf" },
       
    80 		{ ELangAustrian, "as" },
       
    81 		{ ELangNewZealand, "nz" },
       
    82 		{ ELangInternationalFrench, "if" },
       
    83 		{ ELangCzech, "cs" },
       
    84 		{ ELangSlovak, "sk" },
       
    85 		{ ELangPolish, "pl" },
       
    86 		{ ELangSlovenian, "sl" },
       
    87 		{ ELangTaiwanChinese, "tc" },
       
    88 		{ ELangHongKongChinese, "hk" },
       
    89 		{ ELangPrcChinese, "zh" },
       
    90 		{ ELangJapanese, "ja" },
       
    91 		{ ELangThai, "th" },
       
    92 		{ ELangAfrikaans, "af" },
       
    93 		{ ELangAlbanian, "sq" },
       
    94 		{ ELangAmharic, "ah" },
       
    95 		{ ELangArabic, "ar" },
       
    96 		{ ELangArmenian, "hy" },
       
    97 		{ ELangTagalog, "tl" },
       
    98 		{ ELangBelarussian, "be" },
       
    99 		{ ELangBengali, "bn" },
       
   100 		{ ELangBulgarian, "bg" },
       
   101 		{ ELangBurmese, "my" },
       
   102 		{ ELangCatalan, "ca" },
       
   103 		{ ELangCroatian, "hr" },
       
   104 		{ ELangCanadianEnglish, "ce" },
       
   105 		{ ELangInternationalEnglish, "ie" },
       
   106 		{ ELangSouthAfricanEnglish, "sa" },
       
   107 		{ ELangEstonian, "et" },
       
   108 		{ ELangFarsi, "fa" },
       
   109 		{ ELangCanadianFrench, "cf" },
       
   110 		{ ELangScotsGaelic, "gd" },
       
   111 		{ ELangGeorgian, "ka" },
       
   112 		{ ELangGreek, "el" },
       
   113 		{ ELangCyprusGreek, "gr" },
       
   114 		{ ELangGujarati, "gu" },
       
   115 		{ ELangHebrew, "he" },
       
   116 		{ ELangHindi, "hi" },
       
   117 		{ ELangIndonesian, "id" },
       
   118 		{ ELangIrish, "ga" },
       
   119 		{ ELangSwissItalian, "sz" },
       
   120 		{ ELangKannada, "kn" },
       
   121 		{ ELangKazakh, "kk" },
       
   122 		{ ELangKhmer, "km" },
       
   123 		{ ELangKorean, "ko" },
       
   124 		{ ELangLao, "lo" },
       
   125 		{ ELangLatvian, "lv" },
       
   126 		{ ELangLithuanian, "lt" },
       
   127 		{ ELangMacedonian, "mk" },
       
   128 		{ ELangMalay, "ms" },
       
   129 		{ ELangMalayalam, "ml" },
       
   130 		{ ELangMarathi, "mr" },
       
   131 		{ ELangMoldavian, "mo" },
       
   132 		{ ELangMongolian, "mn" },
       
   133 		{ ELangNorwegianNynorsk, "nn" },
       
   134 		{ ELangBrazilianPortuguese, "bp" },
       
   135 		{ ELangPunjabi, "pa" },
       
   136 		{ ELangRomanian, "ro" },
       
   137 		{ ELangSerbian, "sr" },
       
   138 		{ ELangSinhalese, "si" },
       
   139 		{ ELangSomali, "so" },
       
   140 		{ ELangInternationalSpanish, "os" },
       
   141 		{ ELangLatinAmericanSpanish, "ls" },
       
   142 		{ ELangSwahili, "sw" },
       
   143 		{ ELangFinlandSwedish, "fs" },
       
   144 		{ ELangTamil, "ta" },
       
   145 		{ ELangTelugu, "te" },
       
   146 		{ ELangTibetan, "bo" },
       
   147 		{ ELangTigrinya, "ti" },
       
   148 		{ ELangCyprusTurkish, "ct" },
       
   149 		{ ELangTurkmen, "tk" },
       
   150 		{ ELangUkrainian, "uk" },
       
   151 		{ ELangUrdu, "ur" },
       
   152 		{ ELangVietnamese, "vi" },
       
   153 		{ ELangWelsh, "cy" },
       
   154 		{ ELangZulu, "zu" }
       
   155 	};    
       
   156 
       
   157 // ============================ MEMBER FUNCTIONS ===============================
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CIptvUtil::LongPrintL()
       
   161 // -----------------------------------------------------------------------------
       
   162 // 		        
       
   163 #if IPTV_LOGGING_METHOD != 0
       
   164 EXPORT_C void CIptvUtil::LongPrintL( TDesC& aData )
       
   165     {
       
   166     const TInt KMaxLength = 80;
       
   167     TInt length = aData.Length();
       
   168                 
       
   169     if ( length > KMaxLength )
       
   170         {                
       
   171         for ( TInt i = 0; i <= length; i += KMaxLength )
       
   172             {
       
   173             HBufC* temp = HBufC::NewLC( KMaxLength );
       
   174             TInt counter = length - i;
       
   175             if ( counter < KMaxLength )
       
   176                 {
       
   177                 temp->Des().Copy( aData.Mid( i, counter ) );
       
   178                 }
       
   179             else
       
   180                 {                                                    
       
   181                 temp->Des().Copy( aData.Mid( i, KMaxLength ) );
       
   182                 }
       
   183                     
       
   184             IPTVLOGSTRING2_HIGH_LEVEL("Value = %S", temp);
       
   185             CleanupStack::PopAndDestroy( temp );
       
   186             }
       
   187         }
       
   188     else
       
   189         {            
       
   190         IPTVLOGSTRING2_HIGH_LEVEL("Value = %S", &aData);
       
   191         }
       
   192     }    
       
   193 #else
       
   194 EXPORT_C void CIptvUtil::LongPrintL( TDesC& /*aData*/ )
       
   195     {
       
   196     }
       
   197 #endif
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CIptvUtil::StringToInt()
       
   201 // -----------------------------------------------------------------------------
       
   202 // 
       
   203 EXPORT_C TUint32 CIptvUtil::StringToInt(TDesC& value)
       
   204     {
       
   205     TUint32 id = 0;
       
   206     if (value.Compare(_L("")) != 0)
       
   207         {
       
   208         TLex l(value);
       
   209         l.Val(id, EDecimal);
       
   210         }                
       
   211     return id;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CIptvUtil::GetPathL()
       
   216 // -----------------------------------------------------------------------------
       
   217 //   
       
   218 EXPORT_C void CIptvUtil::GetPathL( RFs& aFs,
       
   219                                    TIptvPathSelection aSelection,
       
   220                                    TDes& aPath,
       
   221                                    TDriveNumber aDrive,
       
   222                                    TBool aCreatePath )
       
   223     {
       
   224 	IPTVLOGSTRING_HIGH_LEVEL( "CIptvUtil::GetPathL(1) - Enter" );
       
   225 
       
   226 	TChar driveChar;
       
   227     TUint driveDoubleChar;
       
   228 
       
   229 	aFs.DriveToChar( aDrive, driveChar );
       
   230     driveDoubleChar = driveChar;
       
   231 
       
   232     // Most of the data is stored to "private" folder that is hidden so that 
       
   233     // harvesters don't find possible thumbnail pictures, etc. in them.
       
   234     if ( aSelection != EIptvPathMyVideosVideo )
       
   235         {
       
   236     	if ( aDrive == EDriveC )
       
   237     	   {
       
   238     	   aPath.Format( _L("%c%S"), driveDoubleChar, &KIptvRootPathC );
       
   239     	   }
       
   240     	else
       
   241     	   {
       
   242     	   aPath.Format( _L("%c%S"), driveDoubleChar, &KIptvRootPathE );
       
   243     	   }
       
   244 
       
   245         if ( aCreatePath )
       
   246             {
       
   247         	EnsureAndHidePathL( aFs, aPath, ETrue );
       
   248             }
       
   249         }
       
   250     // Videos and their thumbnails are stored under \My Videos.
       
   251     else
       
   252         {
       
   253         if ( aDrive == EDriveC )
       
   254             {
       
   255             TFileName cRoot = PathInfo::PhoneMemoryRootPath();
       
   256             aPath.Format( _L("%S%S"), &cRoot, &KMyVideosExternalFolderOwn );
       
   257             }
       
   258     	else
       
   259             {
       
   260             aPath.Format( _L("%c%S%S"), driveDoubleChar,
       
   261                                         &KColonAndSlash,
       
   262                                         &KMyVideosExternalFolderOwn );
       
   263             }
       
   264 
       
   265         if ( aCreatePath )
       
   266             {        
       
   267             EnsureAndHidePathL( aFs, aPath, EFalse );
       
   268             }
       
   269         }
       
   270 
       
   271 	// Add subfolder based on the exact path requested.
       
   272     switch ( aSelection )
       
   273         {
       
   274         case EIptvPathWritableRoot:
       
   275             {
       
   276             }
       
   277         	break;
       
   278 
       
   279         case EIptvPathTmp:
       
   280             {
       
   281         	_LIT( KTempSuffix, "\\tmp" );
       
   282             aPath.Append( KTempSuffix );
       
   283             }
       
   284             break;
       
   285 
       
   286         case EIptvPathMyVideosDb:
       
   287             {
       
   288         	_LIT( KMyVideosDbSuffix, "\\mv" );
       
   289             aPath.Append( KMyVideosDbSuffix );
       
   290             }
       
   291             break;
       
   292 
       
   293         case EIptvPathMyVideosVideo:
       
   294             {
       
   295         	_LIT( KMyVideosVideoSuffix, "\\Downloads" );
       
   296             aPath.Append( KMyVideosVideoSuffix );
       
   297             }
       
   298             break;
       
   299 
       
   300         case EIptvPathEcg:
       
   301             {
       
   302         	_LIT( KContentGuideSuffix, "\\ecg" );
       
   303             aPath.Append( KContentGuideSuffix );
       
   304             }
       
   305             break;
       
   306 
       
   307         case EIptvPathService:
       
   308             {
       
   309         	_LIT( KServicePathSuffix, "\\srv" );
       
   310             aPath.Append( KServicePathSuffix );
       
   311             }
       
   312             break;
       
   313 
       
   314         case EIptvPathEcgLive:
       
   315             {
       
   316         	_LIT( KEcgLiveSuffix, "\\ecg\\live" );
       
   317         	aPath.Append( KEcgLiveSuffix );
       
   318             }
       
   319         	break;
       
   320 
       
   321         case EIptvPathTmpLive:
       
   322             {
       
   323         	_LIT( KTmpLiveSuffix, "\\tmp\\live" );
       
   324         	aPath.Append( KTmpLiveSuffix );
       
   325             }
       
   326         	break;
       
   327 
       
   328         default:
       
   329             {
       
   330 		    IPTVLOGSTRING_HIGH_LEVEL("CIptvUtil::GetPathL(1) - Invalid argument!" );            
       
   331             User::Leave( KErrPathNotFound );
       
   332             }
       
   333             break;
       
   334         }
       
   335 
       
   336     // Add trailing slash.
       
   337     aPath.Append( KSlash );
       
   338     
       
   339     // Ensure / hide the path, depending on exact path.
       
   340     if ( aCreatePath )
       
   341         {
       
   342         if ( aSelection == EIptvPathMyVideosVideo )
       
   343             {
       
   344             EnsureAndHidePathL( aFs, aPath, EFalse );
       
   345             }
       
   346         else
       
   347             {
       
   348             EnsureAndHidePathL( aFs, aPath, ETrue );
       
   349             }
       
   350         }
       
   351 
       
   352     IPTVLOGSTRING2_HIGH_LEVEL( "CIptvUtil::GetPathL(1) - Exit (%S)", &aPath );
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CIptvUtil::GetPathL()
       
   357 // -----------------------------------------------------------------------------
       
   358 //  
       
   359 EXPORT_C void CIptvUtil::GetPathL( RFs& aFs,
       
   360                                    TIptvPathSelection aSelection,
       
   361 								   TUint32 aServiceId,
       
   362 								   TDes& aPath,
       
   363 								   TBool aCreatePath )
       
   364 	{
       
   365 	IPTVLOGSTRING_HIGH_LEVEL("CIptvUtil::GetPathL(2) - Enter" );
       
   366 
       
   367 	switch ( aSelection )
       
   368 		{
       
   369 		case EIptvPathEcgLive:
       
   370 		case EIptvPathTmpLive:
       
   371 			{
       
   372 			// First get normal path based on TIptvPathSelection
       
   373 			GetPathL( aFs, aSelection, aPath, EDriveC, aCreatePath );
       
   374 			// Append serviceId directory at the end of the path as a directory
       
   375 			aPath.AppendNum( aServiceId );
       
   376 			// Finally add '\' at the end of the path
       
   377 			aPath.Append( KSlash );
       
   378 			}
       
   379 			break;
       
   380 
       
   381 		case EIptvPathRssSearchThumbnail:
       
   382 		case EIptvPathRssThumbnail:
       
   383 			{
       
   384 			// First of all get the ecg path for thumbnails.
       
   385 			// Thumbnail path is c:\data\videocenter\ecg\<serviceId>\(stbn/tbn)
       
   386 			GetPathL( aFs, EIptvPathEcg, aPath, EDriveC, aCreatePath );
       
   387 
       
   388 			// Append serviceid and slash
       
   389 			aPath.AppendNum( aServiceId );
       
   390 			aPath.Append( KSlash );
       
   391 
       
   392             if ( aCreatePath )
       
   393                 {
       
   394                 EnsureAndHidePathL( aFs, aPath, ETrue );
       
   395                 }
       
   396 
       
   397 			// Select thumbnail dir based on what client requested
       
   398 			if ( aSelection == EIptvPathRssThumbnail )
       
   399 				{
       
   400 				_LIT( KIptvVodThumbnailDir, "tbn\\" );
       
   401 				aPath.Append( KIptvVodThumbnailDir );
       
   402 				}
       
   403 			else
       
   404 				{
       
   405 				_LIT( KSearchThumbnailDir, "stbn\\");
       
   406 				aPath.Append( KSearchThumbnailDir );
       
   407 				}
       
   408 
       
   409 			// Now in aPath we have either
       
   410 			// \\data\\videocenter\\ecg\\<serviceId>\\tbn\\
       
   411 			// or
       
   412 			// \\data\\videocenter\\ecg\\<serviceId>\\stbn\\
       
   413 			// First one is for vod, second one is for search
       
   414 			}
       
   415 			break;
       
   416 
       
   417 		default:
       
   418 		    {
       
   419 		    IPTVLOGSTRING_HIGH_LEVEL("CIptvUtil::GetPathL(2) - Invalid argument!" );
       
   420 		    User::Leave( KErrPathNotFound );
       
   421 		    }
       
   422 			break;
       
   423 		}
       
   424 
       
   425     if ( aCreatePath )
       
   426         {
       
   427         EnsureAndHidePathL( aFs, aPath, ETrue );
       
   428         }
       
   429 
       
   430     IPTVLOGSTRING2_HIGH_LEVEL("CIptvUtil::GetPathL(2) - Exit (%S)", &aPath );
       
   431 	}
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // CIptvUtil::ReadDes
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C void CIptvUtil::ReadDesFromStreamL(TDes& aDes, RReadStream& aStream)
       
   438     {
       
   439     TInt i;
       
   440     TInt length = aStream.ReadUint16L();
       
   441     
       
   442     aDes.Zero();
       
   443     
       
   444     if ( aDes.MaxLength() < length )
       
   445         {
       
   446         User::Leave( KErrArgument );
       
   447         }
       
   448     
       
   449     for(i = 0; i < length; i++)
       
   450         {
       
   451         aDes.Append(aStream.ReadUint16L());
       
   452         }
       
   453     }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CIptvUtil::WriteDes
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 EXPORT_C void CIptvUtil::WriteDesToStreamL(const TDesC& aDes, RWriteStream& aStream)
       
   460     {
       
   461     TInt i;
       
   462     TInt length = aDes.Length();
       
   463     
       
   464     aStream.WriteUint16L(length);
       
   465     for(i = 0; i < length; i++)
       
   466         {
       
   467         aStream.WriteUint16L(aDes[i]);
       
   468         }
       
   469     }
       
   470 // -----------------------------------------------------------------------------
       
   471 // CIptvUtil::ReadDes8
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 EXPORT_C void CIptvUtil::ReadDes8FromStreamL(TDes8& aDes, RReadStream& aStream)
       
   475     {
       
   476     TInt i;
       
   477     TInt length = aStream.ReadUint16L();
       
   478     
       
   479     aDes.Zero();
       
   480     
       
   481     if ( aDes.MaxLength() < length )
       
   482         {
       
   483         User::Leave( KErrArgument );
       
   484         }    
       
   485     
       
   486     for(i = 0; i < length; i++)
       
   487         {
       
   488         aDes.Append(aStream.ReadUint8L());
       
   489         }
       
   490     }
       
   491     
       
   492 // -----------------------------------------------------------------------------
       
   493 // CIptvUtil::WriteDes8
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 EXPORT_C void CIptvUtil::WriteDes8ToStreamL(const TDesC8& aDes, RWriteStream& aStream)
       
   497     {
       
   498     TInt i;
       
   499     TInt length = aDes.Length();
       
   500     
       
   501     aStream.WriteUint16L(length);
       
   502     for(i = 0; i < length; i++)
       
   503         {
       
   504         aStream.WriteUint8L(aDes[i]);
       
   505         }
       
   506     }
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // CIptvUtil::ReadUint64FromStream
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 EXPORT_C void CIptvUtil::ReadUint64FromStreamL(TUint64& aData, RReadStream& aStream)
       
   513     {
       
   514     TUint low  = static_cast<TUint>(aStream.ReadUint32L());
       
   515     TUint high = static_cast<TUint>(aStream.ReadUint32L());
       
   516     aData  = high;
       
   517     aData  = aData << 32;
       
   518     aData |= low;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CIptvUtil::WriteTUint64ToStreamL
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 EXPORT_C void CIptvUtil::WriteUint64ToStreamL(const TUint64 aData, RWriteStream& aStream)
       
   526     {
       
   527     aStream.WriteUint32L( aData & 0x00000000FFFFFFFFULL);
       
   528     aStream.WriteUint32L( (aData & 0xFFFFFFFF00000000ULL) >> 32);
       
   529     }
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CIptvUtil::ReadHBufCFromStreamL
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 EXPORT_C HBufC* CIptvUtil::ReadHBufCFromStreamL( RReadStream& aStream )
       
   536     {
       
   537     TUint32 length  = aStream.ReadUint32L();
       
   538 
       
   539     HBufC* data = HBufC::NewL( length );
       
   540     CleanupStack::PushL( data ); // 1->
       
   541     
       
   542     TPtr dataPtr( data->Des() );
       
   543     
       
   544     for ( TInt i = 0; i < length; i++ )
       
   545         {
       
   546         dataPtr.Append( aStream.ReadUint16L() );
       
   547         }
       
   548 
       
   549     CleanupStack::Pop( data ); // <-1
       
   550     return data;
       
   551     }
       
   552 
       
   553 // -----------------------------------------------------------------------------
       
   554 // CIptvUtil::WriteHBufCToStreamL
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 EXPORT_C void CIptvUtil::WriteHBufCToStreamL( HBufC* aData, RWriteStream& aStream )
       
   558     {
       
   559     aStream.WriteUint32L( aData->Length() );
       
   560     
       
   561     TPtrC dataPtr( aData->Des() );
       
   562     
       
   563     for ( TInt i = 0; i < aData->Length(); i++ )
       
   564         {
       
   565         aStream.WriteUint16L( dataPtr[i] );
       
   566         }
       
   567     }
       
   568 
       
   569 // -----------------------------------------------------------------------------
       
   570 // CIptvUtil::GetLanguageByCountryCode
       
   571 // -----------------------------------------------------------------------------
       
   572 //
       
   573 EXPORT_C TLanguage CIptvUtil::GetLanguageByCountryCode( const TDesC& aLanguageCode )
       
   574 	{
       
   575     IPTVLOGSTRING_LOW_LEVEL("CIptvUtil::GetLanguageByCountryCode");
       
   576 
       
   577 	TLanguage language = ELangNone;
       
   578 	for( TInt i = 0; i < KNumberOfLanguages; i++ )
       
   579 		{
       
   580 		SLanguageItem item = languageArray[i];
       
   581 		TBuf8<10> buf;
       
   582 		buf.Copy( (unsigned char*) item.iLanguageCode );
       
   583 		TBuf16<10> buf2;
       
   584 		buf2.Copy( buf );
       
   585 		if( buf2.Compare( aLanguageCode ) == 0 )
       
   586 			{
       
   587 			language = item.iLanguage;
       
   588 			i = KNumberOfLanguages;
       
   589 			}
       
   590 		}
       
   591 
       
   592 	IPTVLOGSTRING2_LOW_LEVEL("CIptvUtil::GetLanguageByCountryCode Language to be used = %d (65535 = ELangNone)", language);
       
   593 	return language;
       
   594 	}
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // Runs recognizers on the given file to determine its mime type
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 EXPORT_C TInt CIptvUtil::RecognizeFile(
       
   601     RFs& aFsSession,
       
   602     const TDesC& aFilePath, 
       
   603     TDataType& aDataType )
       
   604     {
       
   605     TBuf8<200> buffer; // Enough file content to recognize the type
       
   606     RFile file;
       
   607     TInt err = file.Open( aFsSession, aFilePath, EFileRead | EFileShareAny );
       
   608     if ( err == KErrNone )
       
   609         {
       
   610         err = file.Read( buffer );
       
   611         file.Close();
       
   612 
       
   613         if ( err == KErrNone )
       
   614             {
       
   615             RApaLsSession apaSession;
       
   616             err = apaSession.Connect();
       
   617             if ( err == KErrNone )
       
   618                 {
       
   619                 TDataRecognitionResult result;
       
   620                 err = apaSession.RecognizeData( aFilePath, buffer, result );
       
   621                 if ( result.iConfidence >= CApaDataRecognizerType::EProbable )
       
   622                     {
       
   623                     aDataType = result.iDataType;
       
   624                     }
       
   625 
       
   626                 apaSession.Close();
       
   627                 }
       
   628             }
       
   629         }
       
   630 
       
   631     return err;
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // Runs recognizers on the given file to determine its mime type
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 EXPORT_C TInt CIptvUtil::RecognizeFile(
       
   639     const RFile& aFileHandle,
       
   640     TDataType& aDataType )
       
   641     {
       
   642 #ifdef __S60_30__
       
   643 
       
   644     IPTVLOGSTRING_HIGH_LEVEL( "CIptvUtil::RecognizeFile() returns KErrNotSupported" );
       
   645     ( void )aFileHandle;
       
   646     return KErrNotSupported;
       
   647     
       
   648 #else // __S60_30__
       
   649 
       
   650     RApaLsSession apaSession;
       
   651     TInt err( apaSession.Connect() );
       
   652     if ( err == KErrNone )
       
   653         {
       
   654         TDataRecognitionResult result;
       
   655         err = apaSession.RecognizeData( const_cast<RFile&>( aFileHandle ), result );         
       
   656         if ( result.iConfidence >= CApaDataRecognizerType::EProbable )
       
   657             {
       
   658             aDataType = result.iDataType;
       
   659             }
       
   660 
       
   661         apaSession.Close();
       
   662         }
       
   663 
       
   664     return err;
       
   665 
       
   666 #endif // __S60_30__
       
   667     }
       
   668     
       
   669 // -----------------------------------------------------------------------------
       
   670 // CIptvUtil::RemoveTrailingBackSlashesL()
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CIptvUtil::RemoveTrailingBackSlashesL( HBufC* & aString )
       
   674     {
       
   675     while ( aString->LocateReverse( '\\' ) == ( aString->Length() - 1 ) )
       
   676         {
       
   677         aString->Des().SetLength( aString->Length() - 1 );
       
   678         }
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CIptvUtil::ConnectionTypeL
       
   683 // -----------------------------------------------------------------------------
       
   684 //    
       
   685 EXPORT_C CIptvUtil::TConnectionType CIptvUtil::ConnectionTypeL(TUint32 aIapId)
       
   686     {
       
   687     TBool isHiddenWlanIap;
       
   688     return ConnectionTypeL(aIapId, isHiddenWlanIap);
       
   689     }
       
   690 
       
   691 // -----------------------------------------------------------------------------
       
   692 // CIptvUtil::ConnectionTypeL
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 EXPORT_C CIptvUtil::TConnectionType CIptvUtil::ConnectionTypeL( TUint32 aIapId,
       
   696                                                      TBool& aIsHiddenWlanIap )
       
   697     {
       
   698     TConnectionType connectionType = EUnknown;
       
   699 
       
   700     CCommsDatabase* commsDbIap = CCommsDatabase::NewL();
       
   701     CleanupStack::PushL(commsDbIap);                    // 1->
       
   702     CCommsDbTableView* iapTableView;
       
   703     iapTableView = commsDbIap->OpenTableLC(TPtrC(IAP)); // 2->
       
   704     
       
   705     //Search correct iap and pick connection type
       
   706     TInt err = iapTableView->GotoFirstRecord();
       
   707     while(err == KErrNone)
       
   708         {
       
   709         TUint32 iapId;
       
   710         iapTableView->ReadUintL(TPtrC(COMMDB_ID), iapId);
       
   711 
       
   712         if ( aIapId == iapId )
       
   713             {
       
   714             TBuf<KIptvUtilMaxTextFieldLengthInDb> colText;
       
   715             TUint32 serviceId;
       
   716                     
       
   717             iapTableView->ReadUintL(TPtrC(IAP_SERVICE), serviceId);
       
   718             iapTableView->ReadTextL(TPtrC(IAP_SERVICE_TYPE), colText); 
       
   719 
       
   720             if ( colText == KIptvUtilLanService )
       
   721                 {
       
   722                 //was lan service
       
   723                 if ( IsWlanIapL( serviceId, aIsHiddenWlanIap ) )
       
   724                     {
       
   725                     //was wlan iap
       
   726                     connectionType = EWlan;
       
   727                     }
       
   728                 }           
       
   729             else if ( colText == KIptvUtilOutGoingGprs )
       
   730                 {
       
   731                 connectionType = EGprs;
       
   732                 }
       
   733             else if( colText == KIptvUtilDialOutISP )
       
   734                 {
       
   735                 connectionType = ECsd;
       
   736                 }
       
   737             break;
       
   738             }
       
   739         err = iapTableView->GotoNextRecord();
       
   740         }
       
   741 
       
   742     CleanupStack::PopAndDestroy(iapTableView); //<-2
       
   743     CleanupStack::PopAndDestroy(commsDbIap);   //<-1
       
   744    
       
   745     return connectionType;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CIptvUtil::IsWlanIapL
       
   750 // -----------------------------------------------------------------------------
       
   751 //    
       
   752 #ifndef __WINSCW__
       
   753 
       
   754 EXPORT_C TBool CIptvUtil::IsWlanIapL(TUint32 aIapService)
       
   755     {
       
   756     TBool isHiddenWlanIap;
       
   757     return IsWlanIapL( aIapService, isHiddenWlanIap );
       
   758     }
       
   759     
       
   760 #else
       
   761 
       
   762 EXPORT_C TBool CIptvUtil::IsWlanIapL(TUint32 /*aIapService*/)
       
   763     {
       
   764     return EFalse;
       
   765     }
       
   766 
       
   767 #endif
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // CIptvUtil::IsWlanIapL
       
   771 // -----------------------------------------------------------------------------
       
   772 //
       
   773 #ifdef __WINSCW__
       
   774 
       
   775 EXPORT_C TBool CIptvUtil::IsWlanIapL( TUint32 /*aIapService*/, TBool& /*aIsHiddenWlanIap*/)
       
   776     {
       
   777     return EFalse;
       
   778     }
       
   779 
       
   780 #else
       
   781     
       
   782 EXPORT_C TBool CIptvUtil::IsWlanIapL( TUint32 aIapService, TBool& aIsHiddenWlanIap )
       
   783     {
       
   784     TBool retval;
       
   785     
       
   786     CCommsDbTableView* wlantable = NULL;
       
   787     CCommsDatabase* commsDbWlan = CCommsDatabase::NewL( EDatabaseTypeUnspecified );
       
   788     CleanupStack::PushL( commsDbWlan ); // 1->
       
   789     wlantable = commsDbWlan->OpenViewMatchingUintLC( TPtrC(WLAN_SERVICE),
       
   790                                                      TPtrC(WLAN_SERVICE_ID),
       
   791                                                      aIapService ); // 2->
       
   792                                              
       
   793     TInt err = wlantable->GotoFirstRecord();
       
   794     if ( err == KErrNotFound )
       
   795         {
       
   796         //is not a wlan iap
       
   797         retval = EFalse;
       
   798         }
       
   799     else
       
   800         {
       
   801         User::LeaveIfError( err );
       
   802         //is a wlan iap
       
   803         TUint32 scanSsid = 0;
       
   804         wlantable->ReadUintL( TPtrC(WLAN_SCAN_SSID), scanSsid );
       
   805         aIsHiddenWlanIap = static_cast<TBool>( scanSsid );
       
   806         retval = ETrue;
       
   807         }
       
   808 
       
   809     CleanupStack::PopAndDestroy( wlantable );   // <-2
       
   810     CleanupStack::PopAndDestroy( commsDbWlan ); // <-1
       
   811     
       
   812     return retval;
       
   813     }
       
   814 #endif
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // CIptvUtil::GetAllowedIapsListL
       
   818 // -----------------------------------------------------------------------------
       
   819 //
       
   820 EXPORT_C void CIptvUtil::GetAllowedIapsListL( RArray<TUint32>& aAllowedIaps )
       
   821     {
       
   822     IPTVLOGSTRING_LOW_LEVEL( "CIptvUtil::GetAllowedIapsListL() - Enter" );
       
   823 
       
   824     CCommsDatabase* database = NULL;
       
   825     CCommsDbTableView* view = NULL;
       
   826     TInt result = KErrNotFound;
       
   827     TUint32 iapId = 0;
       
   828 
       
   829     aAllowedIaps.Reset();
       
   830 
       
   831     database = CCommsDatabase::NewL();
       
   832     CleanupStack::PushL( database );
       
   833 
       
   834 // For ARMV5 we do the check as we should, by taking IAPs from WAP_ACCESS_POINT table.
       
   835 #if !defined(__WINS__) && !defined(__WINSCW__)
       
   836 
       
   837     TUint32 wapId = 0;    
       
   838     CCommsDbTableView* wapbearer = NULL;
       
   839 
       
   840     view = database->OpenTableLC( TPtrC( WAP_ACCESS_POINT ) );
       
   841     result = view->GotoFirstRecord();
       
   842 
       
   843     while ( result == KErrNone )
       
   844         {
       
   845         view->ReadUintL( TPtrC( COMMDB_ID ), wapId );
       
   846 
       
   847         wapbearer = database->OpenViewMatchingUintLC( TPtrC( WAP_IP_BEARER ),
       
   848                                                       TPtrC( WAP_ACCESS_POINT_ID ),
       
   849                                                       wapId );
       
   850         wapbearer->GotoFirstRecord();
       
   851         wapbearer->ReadUintL( TPtrC( WAP_IAP ), iapId );
       
   852 
       
   853 #ifdef _DEBUG
       
   854 
       
   855         TBuf<40> name;
       
   856         wapbearer->ReadTextL( TPtrC( COMMDB_NAME ), name );
       
   857         IPTVLOGSTRING3_LOW_LEVEL(
       
   858             "CIptvUtil::GetAllowedIapsListL(ARMV5) adding IAP ID %d (%S).",
       
   859             iapId,
       
   860             &name );
       
   861 
       
   862 #endif // _DEBUG        
       
   863 
       
   864         CleanupStack::PopAndDestroy( wapbearer );
       
   865         aAllowedIaps.AppendL( iapId );
       
   866         result = view->GotoNextRecord();
       
   867         }
       
   868 
       
   869 // For WINSCW we read IAP table as WAP_ACCESS_POINT table is not normally configured.
       
   870 #else
       
   871 
       
   872     view = database->OpenTableLC( TPtrC( IAP ) );
       
   873     result = view->GotoFirstRecord();
       
   874 
       
   875     while ( result == KErrNone )
       
   876         {
       
   877         view->ReadUintL( TPtrC( COMMDB_ID ), iapId );
       
   878 
       
   879 #ifdef _DEBUG
       
   880 
       
   881         TBuf<40> name;
       
   882         view->ReadTextL( TPtrC( COMMDB_NAME ), name );
       
   883         IPTVLOGSTRING3_LOW_LEVEL(
       
   884             "CIptvUtil::GetAllowedIapsListL(WINSCW) adding IAP ID %d (%S).",
       
   885             iapId,
       
   886             &name );
       
   887 
       
   888 #endif // _DEBUG     
       
   889 
       
   890         aAllowedIaps.AppendL( iapId );
       
   891         result = view->GotoNextRecord();
       
   892         }
       
   893 
       
   894 #endif // if !defined(__WINS__) && !defined(__WINSCW__)
       
   895 
       
   896     CleanupStack::PopAndDestroy( view );
       
   897     CleanupStack::PopAndDestroy( database );
       
   898 
       
   899     IPTVLOGSTRING_LOW_LEVEL( "CIptvUtil::GetAllowedIapsListL() - Exit" );
       
   900     }
       
   901 
       
   902 // -----------------------------------------------------------------------------
       
   903 // CIptvUtil::IsAllowedIapL
       
   904 // -----------------------------------------------------------------------------
       
   905 //    
       
   906 EXPORT_C TBool CIptvUtil::IsAllowedIapL( TUint32 aIapId, RArray<TUint32>& aAllowedIaps )
       
   907     {
       
   908     TBool allowed = EFalse;
       
   909     
       
   910     for ( TInt i = 0; i < aAllowedIaps.Count(); i++ )
       
   911         {
       
   912         if ( aIapId == aAllowedIaps[i] )
       
   913             {
       
   914             allowed = ETrue;
       
   915             break;
       
   916             }
       
   917         }
       
   918 
       
   919     IPTVLOGSTRING3_LOW_LEVEL( "CIptvUtil::IsAllowedIapL() returning %d for IAP %d",
       
   920         static_cast<TInt>( allowed ),
       
   921         aIapId );
       
   922 
       
   923     return allowed;
       
   924     }
       
   925 
       
   926 // -----------------------------------------------------------------------------
       
   927 // CIptvUtil::EnsureAndHidePathL
       
   928 // -----------------------------------------------------------------------------
       
   929 //   
       
   930 EXPORT_C void CIptvUtil::EnsureAndHidePathL( RFs& aFsSession,
       
   931                                              const TDesC& aPath,
       
   932                                              TBool aHide )
       
   933     {
       
   934     if ( aPath.Length() == 0 )
       
   935         {
       
   936         IPTVLOGSTRING_LOW_LEVEL(
       
   937             "CIptvUtil::EnsureAndHidePathL() empty path supplied!" );
       
   938         User::Leave( KErrArgument );
       
   939         }
       
   940 
       
   941     // Ensure that the path exists.
       
   942     TRAPD( baflError, BaflUtils::EnsurePathExistsL( aFsSession, aPath ) );
       
   943 
       
   944     if ( baflError != KErrNone && 
       
   945          ( aPath[0] == 'c' || aPath[0] == 'C' ) )
       
   946          {
       
   947          IPTVLOGSTRING2_LOW_LEVEL(
       
   948             "CIptvUtil::EnsureAndHidePathL() problem %d with C-drive!", baflError );
       
   949          User::Leave( baflError );
       
   950          }
       
   951 
       
   952     // Hide the path if requested.
       
   953     if ( aHide && baflError == KErrNone )
       
   954         {
       
   955         TUint attValue = 0;
       
   956         if ( aFsSession.Att( aPath, attValue ) == KErrNone )
       
   957             {
       
   958             if ( ! ( attValue & KEntryAttHidden ) )
       
   959                 {
       
   960                 User::LeaveIfError( aFsSession.SetAtt( aPath, KEntryAttHidden, 0 ) );
       
   961                 }
       
   962             }
       
   963         }
       
   964     }
       
   965 
       
   966 // ----------------------------------------------------------------------------
       
   967 // CIptvUtil::LastPlaybackPositionFeatureSupported
       
   968 // ----------------------------------------------------------------------------
       
   969 //    
       
   970 EXPORT_C TBool CIptvUtil::LastPlaybackPositionFeatureSupported()
       
   971     {
       
   972     IPTVLOGSTRING_LOW_LEVEL( "CIptvUtil::LastPlaybackPositionFeatureSupported() - Enter" );
       
   973 
       
   974 	TBool isSupported( ETrue );
       
   975     
       
   976     CRepository* cenRep( NULL );
       
   977     TRAP_IGNORE( cenRep = CRepository::NewL( KIptvCenRepUid ) );
       
   978     
       
   979     if ( cenRep )
       
   980         {
       
   981         cenRep->Get( KIptvCenRepLastPlaybackPositionFeatureKey, isSupported );    
       
   982         delete cenRep;
       
   983         }
       
   984 	IPTVLOGSTRING2_LOW_LEVEL( 
       
   985        "CIptvUtil::LastPlaybackPositionFeatureSupported() - Exit, return value = %b", isSupported );	
       
   986     
       
   987 	return isSupported;
       
   988     }