customization/OperatorLogoAdapter/src/OperatorLogoAdapter.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  DM Operator Logo Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /*
       
    20 
       
    21 ./Customization -+--> OperatorLogo -+--> LogoData
       
    22 
       
    23 */
       
    24 
       
    25 #include "OperatorLogoAdapter.h"
       
    26 
       
    27 #include <implementationproxy.h> // For TImplementationProxy definition
       
    28 #include <coemain.h>
       
    29 #include <imageconversion.h>
       
    30 #include <bitmaptransforms.h>
       
    31 #include <RPhCltServer.h>
       
    32 
       
    33 #include <CPhCltImageHandler.h>
       
    34 #include <CPhCltBaseImageParams.h>
       
    35 
       
    36 //#ifdef __SAP_POLICY_MANAGEMENT
       
    37 #include <PolicyEngineXACML.h>
       
    38 //#endif
       
    39 
       
    40 #include "nsmldmuri.h"
       
    41 #include "FileCoderB64.h"
       
    42 #include "debug.h"
       
    43 #include <featmgr.h>
       
    44 
       
    45 const TInt KLogoMaxWidthPixels      = 97;
       
    46 const TInt KLogoMaxHeightPixels     = 25;
       
    47 _LIT( KOperatorLogoAdapterTmpFilePath, "c:\\system\\temp\\DM_OPLogo.bin" );
       
    48 
       
    49 class CWaitScheduler : public CActive
       
    50 	{
       
    51 	// Functions
       
    52 	public:
       
    53 		static CWaitScheduler* NewL( TInt aPriority = EPriorityStandard );
       
    54 
       
    55 		TInt WaitForRequest();
       
    56 
       
    57 	private:
       
    58 		CWaitScheduler( TInt aPriority );
       
    59 		void ConstructL();
       
    60 		virtual ~CWaitScheduler();
       
    61 
       
    62 		void RunL();
       
    63 		void DoCancel();
       
    64 
       
    65 	// Data
       
    66 	private:
       
    67 		CActiveSchedulerWait iScheduler;
       
    68 
       
    69 	};
       
    70 // ------------------------------------------------------------------------------------------------
       
    71 
       
    72 CWaitScheduler* CWaitScheduler::NewL( TInt aPriority )
       
    73 	{
       
    74 	CWaitScheduler* self = new( ELeave ) CWaitScheduler( aPriority );
       
    75 	CleanupStack::PushL( self );
       
    76 	self->ConstructL( );
       
    77 	CleanupStack::Pop( self );
       
    78 	return self;
       
    79 	}
       
    80 
       
    81 CWaitScheduler::CWaitScheduler( TInt aPriority )
       
    82 	: CActive( aPriority )
       
    83 	{
       
    84 	CActiveScheduler::Add( this );
       
    85 	}
       
    86 
       
    87 void CWaitScheduler::ConstructL()
       
    88 	{
       
    89 	}
       
    90 
       
    91 CWaitScheduler::~CWaitScheduler()
       
    92 	{
       
    93 	if ( IsActive() )
       
    94 		{
       
    95 		User::Panic( _L("CSyncWait"), 1 );
       
    96 		}
       
    97 	}
       
    98 
       
    99 TInt CWaitScheduler::WaitForRequest()
       
   100 	{
       
   101 	SetActive();
       
   102 	iScheduler.Start();
       
   103 	return iStatus.Int();
       
   104 	}
       
   105 
       
   106 void CWaitScheduler::RunL()
       
   107 	{
       
   108 	iScheduler.AsyncStop();
       
   109 	}
       
   110 
       
   111 void CWaitScheduler::DoCancel()
       
   112 	{
       
   113 	User::Panic( _L("CSyncWait"), 2 );
       
   114 	}
       
   115 
       
   116 
       
   117 // ------------------------------------------------------------------------------------------------
       
   118 // COperatorLogoAdapter* COperatorLogoAdapter::NewL( )
       
   119 // ------------------------------------------------------------------------------------------------
       
   120 COperatorLogoAdapter* COperatorLogoAdapter::NewL( MSmlDmCallback* aDmCallback )
       
   121 	{
       
   122 	RDEBUG("COperatorLogoAdapter::NewL(): begin");
       
   123 
       
   124 	COperatorLogoAdapter* self = NewLC( aDmCallback );
       
   125 	CleanupStack::Pop();
       
   126 	return self;
       
   127 	}
       
   128 
       
   129 // ------------------------------------------------------------------------------------------------
       
   130 // COperatorLogoAdapter* COperatorLogoAdapter::NewLC( )
       
   131 // ------------------------------------------------------------------------------------------------
       
   132 COperatorLogoAdapter* COperatorLogoAdapter::NewLC( MSmlDmCallback* aDmCallback )
       
   133 	{
       
   134 	COperatorLogoAdapter* self = new( ELeave ) COperatorLogoAdapter( aDmCallback );
       
   135 	CleanupStack::PushL( self );
       
   136 	self->ConstructL( );
       
   137 	return self;
       
   138 	}
       
   139 
       
   140 
       
   141 // ------------------------------------------------------------------------------------------------
       
   142 // COperatorLogoAdapter::COperatorLogoAdapter()
       
   143 // ------------------------------------------------------------------------------------------------
       
   144 
       
   145 COperatorLogoAdapter::COperatorLogoAdapter( MSmlDmCallback* aDmCallback )
       
   146 	: CTARMDmAdapter( aDmCallback )
       
   147 	, iCallBack( aDmCallback )
       
   148 	{
       
   149 	}
       
   150 
       
   151 // -------------------------------------------------------------------------------------------------
       
   152 //
       
   153 // ------------------------------------------------------------------------------------------------
       
   154 void COperatorLogoAdapter::ConstructL( )
       
   155 	{
       
   156 	
       
   157 		TRAPD( errf, FeatureManager::InitializeLibL() );
       
   158 		if( errf != KErrNone )
       
   159 		{
       
   160 			User::Leave(errf);
       
   161 		}
       
   162 		
       
   163 		
       
   164 	    if(FeatureManager::FeatureSupported(KFeatureIdSapOperatorLogoAdapter))
       
   165 		{
       
   166 	    User::LeaveIfError( RFbsSession::Connect() );
       
   167 		}
       
   168 		else
       
   169 		{
       
   170 			FeatureManager::UnInitializeLib();
       
   171 	   		User::Leave( KErrNotSupported );
       
   172 		}
       
   173 	}
       
   174 
       
   175 // ------------------------------------------------------------------------------------------------
       
   176 // COperatorLogoAdapter::~COperatorLogoAdapter()
       
   177 // ------------------------------------------------------------------------------------------------
       
   178 
       
   179 
       
   180 COperatorLogoAdapter::~COperatorLogoAdapter()
       
   181 	{
       
   182 	
       
   183 	FeatureManager::UnInitializeLib();
       
   184 	RFbsSession::Disconnect();
       
   185 	}
       
   186 
       
   187 // ------------------------------------------------------------------------------------------------
       
   188 //  COperatorLogoAdapter::DDFVersionL()
       
   189 // ------------------------------------------------------------------------------------------------
       
   190 void COperatorLogoAdapter::DDFVersionL( CBufBase& aDDFVersion )
       
   191 	{
       
   192 	aDDFVersion.InsertL( 0, KOperatorLogoDDFVersion );
       
   193 	}
       
   194 
       
   195 
       
   196 // ------------------------------------------------------------------------------------------------
       
   197 //  COperatorLogoAdapter::DDFStructureL()
       
   198 //
       
   199 // ------------------------------------------------------------------------------------------------
       
   200 void COperatorLogoAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
   201 	{
       
   202 	RDEBUG( "COperatorLogoAdapter::DDFStructureL(): begin" );
       
   203 	
       
   204 	TSmlDmAccessTypes accessTypesGet;
       
   205 	accessTypesGet.SetGet();
       
   206 	
       
   207 	TSmlDmAccessTypes accessTypesGetReplace;
       
   208 	accessTypesGetReplace.SetGet();
       
   209 	accessTypesGetReplace.SetReplace();
       
   210 
       
   211 
       
   212 	/*
       
   213 	Node: ./Customzation
       
   214 	This interior node is the common parent to all customization..
       
   215 	Status: Required
       
   216 	Occurs: One
       
   217 	Format: Node
       
   218 	Access Types: Get
       
   219 	Values: N/A
       
   220 	*/
       
   221 	MSmlDmDDFObject& customization = aDDF.AddChildObjectL( KOperatorLogoCustomization );
       
   222 	FillNodeInfoL(customization, accessTypesGet, MSmlDmDDFObject::EOne, MSmlDmDDFObject::EPermanent,
       
   223 		MSmlDmDDFObject::ENode, KOperatorLogoCustomizationD, ETrue );
       
   224 	
       
   225 	/*
       
   226 	Node: ./Customization/OperatorLogo
       
   227 	This interior node acts as a placeholder for one or more update packages within a same content provider group.
       
   228 	Status: Required
       
   229 	Occurs: One
       
   230 	Format: Node
       
   231 	Access Types: Get
       
   232 	Values: N/A
       
   233 	*/
       
   234 	MSmlDmDDFObject& operatorLogo = customization.AddChildObjectL( KOperatorLogoOperatorLogo );
       
   235 	FillNodeInfoL( operatorLogo, accessTypesGet, MSmlDmDDFObject::EOne, MSmlDmDDFObject::EPermanent,
       
   236 		MSmlDmDDFObject::ENode, KOperatorLogoOperatorLogoD, ETrue );
       
   237 	
       
   238 	/*
       
   239 	Node: ./Customization/OperatorLogo/Data
       
   240 	Status: Optional
       
   241 	Occurs: One
       
   242 	Format: bin
       
   243 	Access Types: Get, Replace
       
   244 	Values: N/A
       
   245 	*/
       
   246 
       
   247 	MSmlDmDDFObject& logoData = operatorLogo.AddChildObjectL(KOperatorLogoLogoData);
       
   248 	FillNodeInfoL( logoData, accessTypesGetReplace, MSmlDmDDFObject::EOne, MSmlDmDDFObject::EPermanent,
       
   249 		MSmlDmDDFObject::EBin, KOperatorLogoLogoDataD, EFalse);
       
   250 	logoData.AddDFTypeMimeTypeL( KNSmlDMTextPlain );
       
   251 	logoData.AddDFTypeMimeTypeL( KNSmlDMImageAny );
       
   252 	}
       
   253 
       
   254 // ------------------------------------------------------------------------------------------------
       
   255 //  COperatorLogoAdapter::UpdateLeafObjectL()
       
   256 //  
       
   257 // ------------------------------------------------------------------------------------------------
       
   258 void COperatorLogoAdapter::_UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& /*aLUID*/, const TDesC8& aObject, const TDesC8& aType, const TInt aStatusRef )
       
   259 	{
       
   260 	RDEBUG( "COperatorLogoAdapter::UpdateLeafObjectL(): begin" );
       
   261 
       
   262 	TError ret = EOk ;
       
   263 	
       
   264 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   265 	TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   266 	TNodeId nodeId = NodeId( uriPtrc );
       
   267 #else
       
   268 	TNodeId nodeId = NodeId( aURI );
       
   269 #endif	
       
   270 	
       
   271 	switch( nodeId )
       
   272 		{
       
   273 	case ENodeLogoData:
       
   274 		ret = SetOperatorLogoL( aObject, aType );
       
   275 		break;
       
   276 
       
   277 	case ENodeUnknown:
       
   278 		ret = ENotFound;
       
   279 		break;
       
   280 
       
   281 	default:
       
   282 		ret = EError;
       
   283 		break;
       
   284 		}
       
   285 
       
   286 	iCallBack->SetStatusL( aStatusRef, ret );
       
   287 	}
       
   288 
       
   289 // ------------------------------------------------------------------------------------------------
       
   290 //
       
   291 // ------------------------------------------------------------------------------------------------
       
   292 void COperatorLogoAdapter::_UpdateLeafObjectL( const TDesC8& /*aURI*/, const TDesC8& /*aLUID*/, RWriteStream*& /*aStream*/, const TDesC8& /*aType*/, TInt aStatusRef )
       
   293 	{
       
   294 	RDEBUG( "COperatorLogoAdapter::UpdateLeafObjectL(...RWriteStream...): begin" );
       
   295 	// Not supported
       
   296 	TError ret = EError;
       
   297 	iCallBack->SetStatusL( aStatusRef, ret );
       
   298 	}
       
   299 
       
   300 // ------------------------------------------------------------------------------------------------
       
   301 // COperatorLogoAdapter::DeleteObjectL( const TDesC& aURI, const TDesC& aLUID )
       
   302 // ------------------------------------------------------------------------------------------------
       
   303 void COperatorLogoAdapter::_DeleteObjectL( const TDesC8& /*aURI*/, const TDesC8& /*aLUID*/, const TInt aStatusRef )
       
   304 	{
       
   305 	RDEBUG( "COperatorLogoAdapter::DeleteObjectL(): begin" );
       
   306 	// Not supported
       
   307 	TError ret = EError;
       
   308 	iCallBack->SetStatusL( aStatusRef, ret );
       
   309 	}
       
   310 
       
   311 
       
   312 // ------------------------------------------------------------------------------------------------
       
   313 //  COperatorLogoAdapter::FetchLeafObjectL( const TDesC& aURI, const TDesC& aLUID, const TDesC& aType, CBufBase& aObject )
       
   314 // ------------------------------------------------------------------------------------------------
       
   315 void COperatorLogoAdapter::_FetchLeafObjectL( const TDesC8& aURI, const TDesC8& /*aLUID*/, const TDesC8& /*aType*/, const TInt /*aResultsRef*/, const TInt aStatusRef )
       
   316 	{
       
   317 	RDEBUG("COperatorLogoAdapter::FetchLeafObjectL(): begin");
       
   318 
       
   319 	TError ret = EOk ;
       
   320 	
       
   321 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   322 	TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   323 	TNodeId nodeId = NodeId( uriPtrc );
       
   324 #else
       
   325 	TNodeId nodeId = NodeId( aURI );
       
   326 #endif	
       
   327 
       
   328 	switch( nodeId )
       
   329 		{
       
   330 	case ENodeLogoData:
       
   331 		// Get not supported for operator logo
       
   332 		ret = EError;
       
   333 		break;
       
   334 
       
   335 	case ENodeUnknown:
       
   336 		ret = ENotFound;
       
   337 		break;
       
   338 
       
   339 	default:
       
   340 		ret = EError;
       
   341 		break;
       
   342 		}
       
   343 
       
   344 	iCallBack->SetStatusL( aStatusRef, ret );
       
   345 
       
   346 }
       
   347 
       
   348 // ------------------------------------------------------------------------------------------------
       
   349 //
       
   350 // ------------------------------------------------------------------------------------------------
       
   351 void COperatorLogoAdapter::_FetchLeafObjectSizeL( const TDesC8& aURI, const TDesC8& /*aLUID*/, const TDesC8& /*aType*/, TInt /*aResultsRef*/, TInt aStatusRef )
       
   352 	{
       
   353 	RDEBUG("COperatorLogoAdapter::FetchLeafObjectSizeL(): begin");
       
   354 
       
   355 	TError ret = EOk ;
       
   356 	
       
   357 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   358 	TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   359 	TNodeId nodeId = NodeId( uriPtrc );
       
   360 #else
       
   361 	TNodeId nodeId = NodeId( aURI );
       
   362 #endif	
       
   363 
       
   364 	switch( nodeId )
       
   365 		{
       
   366 	case ENodeLogoData:
       
   367 		// Get not supported for operator logo
       
   368 		ret = EError;
       
   369 		break;
       
   370 
       
   371 	case ENodeUnknown:
       
   372 		ret = ENotFound;
       
   373 		break;
       
   374 	default:
       
   375 		ret = EError;
       
   376 		break;
       
   377 		}
       
   378 
       
   379 
       
   380 	iCallBack->SetStatusL( aStatusRef, ret );
       
   381 
       
   382 	}
       
   383 
       
   384 // ------------------------------------------------------------------------------------------------
       
   385 //  COperatorLogoAdapter::ChildURIListL( const TDesC& aURI, const TDesC& aParentLUID, const CArrayFix<TNSmlDmMappingInfo>& aPreviousURISegmentList, CArrayFix<TPtrC>& aCurrentURISegmentList )
       
   386 // ------------------------------------------------------------------------------------------------
       
   387 void COperatorLogoAdapter::_ChildURIListL( const TDesC8& aURI, const TDesC8& /*aParentLUID*/, const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/, TInt aResultsRef, TInt aStatusRef  )
       
   388 	{
       
   389 	RDEBUG("COperatorLogoAdapter::ChildURIListL(): begin");
       
   390 
       
   391 	TError ret = EOk ;
       
   392 	
       
   393 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   394 	TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   395 	TNodeId nodeId = NodeId( uriPtrc );
       
   396 #else
       
   397 	TNodeId nodeId = NodeId( aURI );
       
   398 #endif	
       
   399 
       
   400 	CBufBase *currentList = CBufFlat::NewL( 128 );
       
   401 	CleanupStack::PushL( currentList );
       
   402 
       
   403 	switch( nodeId )
       
   404 		{
       
   405 	case ENodeCustomization:
       
   406 		currentList->InsertL( currentList->Size(), KOperatorLogoOperatorLogo() );
       
   407 		break;
       
   408 
       
   409 	case ENodeOperatorLogo:
       
   410 		currentList->InsertL( currentList->Size(), KOperatorLogoLogoData );
       
   411 		break;
       
   412 
       
   413 	case ENodeLogoData:
       
   414 		// No children, leave list empty
       
   415 		break;
       
   416 
       
   417 	case ENodeUnknown:
       
   418 		ret = ENotFound;
       
   419 		break;
       
   420 
       
   421 	default:
       
   422 		ret = EError;
       
   423 		break;
       
   424 		}
       
   425 
       
   426 	if( ret == EOk )
       
   427 		{
       
   428 		iCallBack->SetResultsL( aResultsRef, *currentList, KNullDesC8 );
       
   429 		}
       
   430 
       
   431 	iCallBack->SetStatusL( aStatusRef, ret );
       
   432 
       
   433 	CleanupStack::PopAndDestroy(currentList); //currentList
       
   434 	}
       
   435 
       
   436 
       
   437 // ------------------------------------------------------------------------------------------------
       
   438 // COperatorLogoAdapter::AddNodeObjectL( const TDesC& aURI, const TDesC& aParentLUID )
       
   439 // ------------------------------------------------------------------------------------------------
       
   440 void COperatorLogoAdapter::_AddNodeObjectL( const TDesC8& /*aURI*/, const TDesC8& /*aParentLUID*/, const TInt aStatusRef )
       
   441 	{
       
   442 	RDEBUG("COperatorLogoAdapter::AddNodeObjectL(): begin");
       
   443 	// Not supported
       
   444 	TError ret = EError;
       
   445 	iCallBack->SetStatusL( aStatusRef, ret );
       
   446 	}
       
   447 
       
   448 // ------------------------------------------------------------------------------------------------
       
   449 //
       
   450 // ------------------------------------------------------------------------------------------------
       
   451 void COperatorLogoAdapter::_ExecuteCommandL( const TDesC8& /*aURI*/, const TDesC8& /*aLUID*/, const TDesC8& /*aArgument*/, const TDesC8& /*aType*/, TInt aStatusRef )
       
   452 	{
       
   453 	RDEBUG("COperatorLogoAdapter::ExecuteCommandL(): begin");
       
   454 	// Not supported
       
   455 	TError ret = EError;
       
   456 	iCallBack->SetStatusL( aStatusRef, ret );
       
   457 	}
       
   458 
       
   459 // ------------------------------------------------------------------------------------------------
       
   460 //
       
   461 // ------------------------------------------------------------------------------------------------
       
   462 void COperatorLogoAdapter::_ExecuteCommandL( const TDesC8& /*aURI*/, const TDesC8& /*aLUID*/, RWriteStream*& /*aStream*/, const TDesC8& /*aType*/, TInt aStatusRef )
       
   463 	{
       
   464 	RDEBUG("COperatorLogoAdapter::ExecuteCommandL(...RWriteStream...): begin");
       
   465 	//Not supported
       
   466 	TError ret = EError;
       
   467 	iCallBack->SetStatusL( aStatusRef, ret );
       
   468 	}
       
   469 	
       
   470 // ------------------------------------------------------------------------------------------------
       
   471 //
       
   472 // ------------------------------------------------------------------------------------------------
       
   473 void COperatorLogoAdapter::_CopyCommandL( const TDesC8& /*aTargetURI*/, const TDesC8& /*aTargetLUID*/, const TDesC8& /*aSourceURI*/, const TDesC8& /*aSourceLUID*/, const TDesC8& /*aType*/, TInt aStatusRef )
       
   474 	{
       
   475 	RDEBUG("COperatorLogoAdapter::CopyCommandL(): begin");
       
   476 	//Not supported
       
   477 	TError ret = EError;
       
   478 	iCallBack->SetStatusL( aStatusRef, ret );
       
   479 	}
       
   480 
       
   481 // ------------------------------------------------------------------------------------------------
       
   482 //
       
   483 // ------------------------------------------------------------------------------------------------
       
   484 void COperatorLogoAdapter::StartAtomicL()
       
   485 	{
       
   486 	RDEBUG("COperatorLogoAdapter::StartAtomicL(): begin");
       
   487 	//Not supported
       
   488 	}
       
   489 
       
   490 // ------------------------------------------------------------------------------------------------
       
   491 //
       
   492 // ------------------------------------------------------------------------------------------------
       
   493 void COperatorLogoAdapter::CommitAtomicL()
       
   494 	{
       
   495 	RDEBUG("COperatorLogoAdapter::CommitAtomicL(): begin");
       
   496 	//Not supported
       
   497 	}
       
   498 
       
   499 // ------------------------------------------------------------------------------------------------
       
   500 //
       
   501 // ------------------------------------------------------------------------------------------------
       
   502 void COperatorLogoAdapter::RollbackAtomicL()
       
   503 	{
       
   504 	RDEBUG("COperatorLogoAdapter::RollbackAtomicL(): begin");
       
   505 	//Not supported
       
   506 	}
       
   507 
       
   508 // ------------------------------------------------------------------------------------------------
       
   509 //
       
   510 // ------------------------------------------------------------------------------------------------
       
   511 TBool COperatorLogoAdapter::StreamingSupport( TInt& /*aItemSize*/ )
       
   512 	{
       
   513 	RDEBUG("COperatorLogoAdapter::StreamingSupport(): begin");
       
   514 	return EFalse;
       
   515 	}
       
   516 
       
   517 // ------------------------------------------------------------------------------------------------
       
   518 //
       
   519 // ------------------------------------------------------------------------------------------------
       
   520 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
   521 void COperatorLogoAdapter::StreamCommittedL( RWriteStream& /*aStream*/ )
       
   522 #else
       
   523 void COperatorLogoAdapter::StreamCommittedL()
       
   524 #endif	
       
   525 	{	
       
   526 	RDEBUG("COperatorLogoAdapter::StreamCommittedL(): begin");
       
   527 	RDEBUG("COperatorLogoAdapter::StreamCommittedL(): end");
       
   528 	}
       
   529 
       
   530 // ------------------------------------------------------------------------------------------------
       
   531 //
       
   532 // ------------------------------------------------------------------------------------------------
       
   533 void COperatorLogoAdapter::CompleteOutstandingCmdsL()
       
   534 	{
       
   535 	RDEBUG("COperatorLogoAdapter::CompleteOutstandingCmdsL(): begin");
       
   536 	}
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // 
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 //#ifdef __SAP_POLICY_MANAGEMENT
       
   543 TPtrC8 COperatorLogoAdapter::PolicyRequestResourceL( const TDesC8& /*aURI*/ )
       
   544 	{
       
   545 	if(!FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement ))
       
   546 	{
       
   547 		User::Leave(KErrNotSupported);
       
   548 		
       
   549 	}
       
   550 	
       
   551 	return PolicyEngineXACML::KCustomizationManagement();	
       
   552 
       
   553 	}
       
   554 //#endif
       
   555 // ------------------------------------------------------------------------------------------------
       
   556 //
       
   557 // ------------------------------------------------------------------------------------------------
       
   558 COperatorLogoAdapter::TNodeId COperatorLogoAdapter::NodeId( const TDesC8& aURI )
       
   559 	{
       
   560 	TNodeId id = ENodeUnknown;
       
   561 
       
   562 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   563 	TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   564 	TInt cnt = NSmlDmURI::NumOfURISegs( uriPtrc );
       
   565 	TPtrC8 app = NSmlDmURI::LastURISeg( uriPtrc );
       
   566 #else
       
   567 	TInt cnt = NSmlDmURI::NumOfURISegs( aURI );
       
   568 	TPtrC8 app = NSmlDmURI::LastURISeg( aURI );
       
   569 #endif	
       
   570 
       
   571 	if ( cnt == 1 )
       
   572 		{
       
   573 		if (app == KOperatorLogoCustomization)
       
   574 			{
       
   575 			id = ENodeCustomization;
       
   576 			}
       
   577 		}
       
   578 	else if ( cnt == 2 ) 
       
   579 		{
       
   580 		if (app == KOperatorLogoOperatorLogo)
       
   581 			{
       
   582 			id = ENodeOperatorLogo;
       
   583 			}
       
   584 		}
       
   585 	else if ( cnt == 3 ) 
       
   586 		{
       
   587 		if (app == KOperatorLogoLogoData)
       
   588 			{
       
   589 			id = ENodeLogoData;
       
   590 			}
       
   591 		}
       
   592 
       
   593 	return id;
       
   594 	}
       
   595 
       
   596 // ------------------------------------------------------------------------------------------------
       
   597 //
       
   598 // ------------------------------------------------------------------------------------------------
       
   599 const TImplementationProxy ImplementationTable[] = 
       
   600 	{
       
   601 	{ {KOperatorLogoAdapterImplUid}, (TProxyNewLPtr)COperatorLogoAdapter::NewL }
       
   602 	};
       
   603 
       
   604 // ------------------------------------------------------------------------------------------------
       
   605 //
       
   606 // ------------------------------------------------------------------------------------------------
       
   607 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   608 	{
       
   609 	aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   610 	return ImplementationTable;
       
   611 	}
       
   612 
       
   613 
       
   614 
       
   615 // -------------------------------------------------------------------------------------
       
   616 // COperatorLogoAdapter::FillNodeInfoL()
       
   617 // Fills the node info in ddf structure
       
   618 // -------------------------------------------------------------------------------------
       
   619 void COperatorLogoAdapter::FillNodeInfoL( MSmlDmDDFObject& aNode,TSmlDmAccessTypes aAccTypes,
       
   620 										MSmlDmDDFObject::TOccurence aOccurrence, MSmlDmDDFObject::TScope aScope, 
       
   621 										MSmlDmDDFObject::TDFFormat aFormat,const TDesC8& aDescription,TBool /*aObjectGroup*/)
       
   622 	{
       
   623 	aNode.SetAccessTypesL(aAccTypes);
       
   624 	aNode.SetOccurenceL(aOccurrence);
       
   625 	aNode.SetScopeL(aScope);
       
   626 	aNode.SetDFFormatL(aFormat);
       
   627 	if(aFormat!=MSmlDmDDFObject::ENode)
       
   628 		{
       
   629 		aNode.AddDFTypeMimeTypeL(KNSmlDMTextPlain);
       
   630 		}
       
   631 	aNode.SetDescriptionL(aDescription);
       
   632 	}
       
   633 
       
   634 // -------------------------------------------------------------------------------------
       
   635 // COperatorLogoAdapter::IsText()
       
   636 // Checks whether the given mime type is text format (that we support)
       
   637 // -------------------------------------------------------------------------------------
       
   638 TBool COperatorLogoAdapter::IsText(const TDesC8& aMime)
       
   639 	{
       
   640 	TBool ret = EFalse;
       
   641 	if (aMime == _L8("text/plain") || aMime == _L8("text/*"))
       
   642 		{
       
   643 			ret = ETrue;
       
   644 		}
       
   645 	return ret;
       
   646 	}
       
   647 
       
   648 // -------------------------------------------------------------------------------------
       
   649 // COperatorLogoAdapter::IsImage()
       
   650 // Checks whether the given mime type is image format (that we support)
       
   651 // -------------------------------------------------------------------------------------
       
   652 TBool COperatorLogoAdapter::IsImage(const TDesC8& aMime)
       
   653 	{
       
   654 	TBool ret = EFalse;
       
   655 	if (aMime == _L8("image/jpeg") || aMime == _L8("image/gif"))
       
   656 		{
       
   657 			ret = ETrue;
       
   658 		}
       
   659 	return ret;
       
   660 	}
       
   661 
       
   662 
       
   663 
       
   664 
       
   665 
       
   666 // ------------------------------------------------------------------------------------------------
       
   667 //  COperatorLogoAdapter::SetOperatorLogoL()
       
   668 // ------------------------------------------------------------------------------------------------
       
   669 MSmlDmAdapter::TError COperatorLogoAdapter::SetOperatorLogoL(const TDesC8& aData, const TDesC8& aMime) 
       
   670 	{
       
   671 	TError ret = EOk;
       
   672 
       
   673 	if (aData.Length() > 0)
       
   674 		{
       
   675 		ret = SetOperatorLogoImageL( aData, aMime );
       
   676 		}
       
   677 	else
       
   678 		{
       
   679 		ret = DeleteOperatorLogoImageL();
       
   680 		}
       
   681 
       
   682 	return ret;
       
   683 	}
       
   684 
       
   685 // ------------------------------------------------------------------------------------------------
       
   686 //  COperatorLogoAdapter::SetOperatorLogoImageL()
       
   687 // ------------------------------------------------------------------------------------------------
       
   688 MSmlDmAdapter::TError COperatorLogoAdapter::SetOperatorLogoImageL(const TDesC8& aData, const TDesC8& /*aMime*/) 
       
   689 	{
       
   690 	RDEBUG("COperatorLogoAdapter::SetOperatorLogoImageL(): begin");
       
   691 	TError ret = EOk;
       
   692 
       
   693 	TInt mcc = 0;
       
   694 	TInt mnc = 0;
       
   695 
       
   696 
       
   697 	TFileCoderB64 decoder;
       
   698 	TPtrC fileName( KOperatorLogoAdapterTmpFilePath );
       
   699 
       
   700 	RFs fs;
       
   701 	User::LeaveIfError( fs.Connect() );
       
   702 	CleanupClosePushL( fs );
       
   703 
       
   704 	TBool isEncoded = TFileCoderB64::CheckB64Encode( aData );
       
   705 	if( isEncoded )
       
   706 		{
       
   707 		decoder.DecodeToL( aData, fileName );
       
   708 		}
       
   709 	else
       
   710 		{
       
   711 		// aData is original data, save it to fileName
       
   712 		RFile file;
       
   713 		User::LeaveIfError( file.Replace( fs, fileName, EFileWrite));
       
   714 		CleanupClosePushL( file );
       
   715 		User::LeaveIfError( file.Write( aData ) );
       
   716 		
       
   717 		CleanupStack::PopAndDestroy();//file
       
   718 		}
       
   719 		
       
   720 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   721 	CleanupStack::PushL( bitmap );
       
   722 
       
   723 	LoadBitmapL( fileName, *bitmap );
       
   724 
       
   725 #ifndef TEST_CODE_LOAD_AND_SCALE
       
   726 	TSize bmpSize = bitmap->SizeInPixels();
       
   727 	if (bmpSize.iWidth > KLogoMaxWidthPixels ||
       
   728 		bmpSize.iHeight > KLogoMaxHeightPixels)
       
   729 		{
       
   730 		ScaleBitmapL( *bitmap, KLogoMaxWidthPixels, KLogoMaxHeightPixels );
       
   731 		}
       
   732 #endif // !TEST_CODE_LOAD_AND_SCALE
       
   733 
       
   734 	GetOpInfoL( mcc, mnc );
       
   735 	SaveOperatorLogoBitmapL( bitmap->Handle(), mcc, mnc );
       
   736 
       
   737 	CleanupStack::PopAndDestroy( bitmap );
       
   738 
       
   739 	fs.Delete( fileName );
       
   740 	CleanupStack::PopAndDestroy();//fs
       
   741 
       
   742 
       
   743 	RDEBUG("COperatorLogoAdapter::SetOperatorLogoImageL(): end");
       
   744 	return ret;
       
   745 	}
       
   746 
       
   747 // ------------------------------------------------------------------------------------------------
       
   748 //  COperatorLogoAdapter::DeleteOperatorLogoImageL()
       
   749 // ------------------------------------------------------------------------------------------------
       
   750 MSmlDmAdapter::TError COperatorLogoAdapter::DeleteOperatorLogoImageL()
       
   751 	{
       
   752 	TError ret = EOk;
       
   753 	TInt bmpHandle = 0;
       
   754 	TInt mcc = 0;
       
   755 	TInt mnc = 0;
       
   756 
       
   757 	GetOpInfoL( mcc, mnc );
       
   758 	// Setting operatorlogo bitmap handle to zero will delete it
       
   759 	SaveOperatorLogoBitmapL( bmpHandle, mcc, mnc );
       
   760 
       
   761 	return ret;
       
   762 	}
       
   763 
       
   764 
       
   765 
       
   766 // ------------------------------------------------------------------------------------------------
       
   767 //  COperatorLogoAdapter::
       
   768 // ------------------------------------------------------------------------------------------------
       
   769 void COperatorLogoAdapter::LoadBitmapL( const TDesC& aFileName, CFbsBitmap& aBitmap )
       
   770 	{
       
   771 	RFs fs;
       
   772 	User::LeaveIfError( fs.Connect() );
       
   773 	CleanupClosePushL( fs );
       
   774 
       
   775 	const CImageDecoder::TOptions opt =
       
   776 		(CImageDecoder::TOptions)
       
   777 			(
       
   778 			CImageDecoder::EOptionAlwaysThread
       
   779 #ifndef TEST_CODE_LOAD_AND_DITHER
       
   780 			| CImageDecoder::EOptionNoDither
       
   781 #endif // !TEST_CODE_LOAD_AND_DITHER
       
   782 			);
       
   783 	CImageDecoder* decoder = CImageDecoder::FileNewL( fs, aFileName, opt );
       
   784 	CleanupStack::PushL( decoder );
       
   785 
       
   786 	TInt frameCount = decoder->FrameCount();
       
   787 	TFrameInfo frameInfo = decoder->FrameInfo();
       
   788 
       
   789 	TSize bmpSize = frameInfo.iOverallSizeInPixels;
       
   790 	TDisplayMode bmpDispMode = frameInfo.iFrameDisplayMode;
       
   791 
       
   792 	// Adjust Display Mode
       
   793 	if (bmpDispMode > EColor64K)
       
   794 		{
       
   795 		bmpDispMode = EColor64K;
       
   796 		}
       
   797 
       
   798 	// Check target bitmap size
       
   799 	const TSize KLogoMaxSize( KLogoMaxWidthPixels, KLogoMaxHeightPixels );
       
   800 
       
   801 #ifdef TEST_CODE_LOAD_AND_SCALE
       
   802 	TUint32 ratioX = (static_cast<TUint32>( (KLogoMaxSize.iWidth) << 16) ) / bmpSize.iWidth;
       
   803 	TUint32 ratioY = (static_cast<TUint32>( (KLogoMaxSize.iHeight) << 16) ) / bmpSize.iHeight;
       
   804 	TUint32 ratio = Min( ratioX, ratioY );
       
   805 
       
   806 	if ( (frameInfo.iFlags & TFrameInfo::EFullyScaleable) == 0 )
       
   807 		{
       
   808 		if (ratio < (1<<13) )
       
   809 			{
       
   810 			ratio = (1<<13); // 1/8;
       
   811 			}
       
   812 		else if (ratio < (1<<14) )
       
   813 			{
       
   814 			ratio = (1<<14); // 1/4;
       
   815 			}
       
   816 		else if (ratio < (1<<15) )
       
   817 			{
       
   818 			ratio = (1<<15); // 1/2;
       
   819 			}
       
   820 		else
       
   821 			{
       
   822 			ratio = (1<<16); // 1/1;
       
   823 			}
       
   824 		}
       
   825 
       
   826 	bmpSize.iWidth = (((bmpSize.iWidth << 1) + 1) * ratio) >> 17;
       
   827 	bmpSize.iHeight = (((bmpSize.iHeight << 1) + 1) * ratio) >> 17;
       
   828 #endif // TEST_CODE_LOAD_AND_SCALE
       
   829 
       
   830 #ifdef TEST_CODE_LOAD_AND_DITHER
       
   831 	GetScreenDisplayModeL( bmpDispMode );
       
   832 	if (bmpDispMode == EColor16MA)
       
   833 		{
       
   834 		bmpDispMode = EColor16M;
       
   835 		}
       
   836 #endif // TEST_CODE_LOAD_AND_DITHER
       
   837 
       
   838 	aBitmap.Reset();
       
   839 	TInt err = aBitmap.Create( bmpSize, bmpDispMode );
       
   840 	User::LeaveIfError( err );
       
   841 
       
   842 	TRequestStatus reqStatus = KRequestPending;
       
   843 
       
   844 	decoder->Convert( &reqStatus, aBitmap );
       
   845 	User::WaitForRequest( reqStatus );
       
   846 
       
   847 	err = reqStatus.Int();
       
   848 	User::LeaveIfError( err );
       
   849 
       
   850 	CleanupStack::PopAndDestroy( decoder );
       
   851 	CleanupStack::PopAndDestroy( &fs );
       
   852 	}
       
   853 
       
   854 
       
   855 // ------------------------------------------------------------------------------------------------
       
   856 //  COperatorLogoAdapter::
       
   857 // ------------------------------------------------------------------------------------------------
       
   858 void COperatorLogoAdapter::ScaleBitmapL( CFbsBitmap& aBitmap, TInt aX, TInt aY )
       
   859 	{
       
   860 	CBitmapScaler* scaler = CBitmapScaler::NewL();
       
   861 	CleanupStack::PushL( scaler );
       
   862 
       
   863 	CWaitScheduler* waitScheduler = CWaitScheduler::NewL();
       
   864 	CleanupStack::PushL( waitScheduler );
       
   865 
       
   866 	TSize dstSize = aBitmap.SizeInPixels();
       
   867 	if (dstSize.iWidth > aX || dstSize.iHeight > aY)
       
   868 		{
       
   869 		dstSize.iWidth = aX;
       
   870 		dstSize.iHeight = aY;
       
   871 
       
   872 		scaler->Scale( &waitScheduler->iStatus, aBitmap, dstSize );//, TBool aMaintainAspectRatio=ETrue);
       
   873 		waitScheduler->WaitForRequest();
       
   874 		}
       
   875 
       
   876 	// Cleanup
       
   877 	CleanupStack::PopAndDestroy( waitScheduler );
       
   878 	CleanupStack::PopAndDestroy( scaler );
       
   879 	}
       
   880 
       
   881 
       
   882 // ------------------------------------------------------------------------------------------------
       
   883 //  COperatorLogoAdapter::
       
   884 // ------------------------------------------------------------------------------------------------
       
   885 void COperatorLogoAdapter::GetScreenDisplayModeL( TDisplayMode &aDisplayMode )
       
   886 	{
       
   887 	// Device display mode
       
   888 	RWsSession ws;
       
   889 	User::LeaveIfError( ws.Connect() );
       
   890 	CleanupClosePushL( ws );
       
   891 
       
   892 	CWsScreenDevice* screen = new (ELeave) CWsScreenDevice( ws );
       
   893 	CleanupStack::PushL( screen );
       
   894 	User::LeaveIfError( screen->Construct() );
       
   895 
       
   896 	aDisplayMode = screen->DisplayMode();
       
   897 
       
   898 	CleanupStack::PopAndDestroy( screen );
       
   899 	screen = 0;
       
   900 
       
   901 	CleanupStack::PopAndDestroy( &ws );
       
   902 	}
       
   903 
       
   904 
       
   905 
       
   906 // ------------------------------------------------------------------------------------------------
       
   907 //  COperatorLogoAdapter::
       
   908 // ------------------------------------------------------------------------------------------------
       
   909 void COperatorLogoAdapter::GetOpInfoL( TInt& aMCC, TInt& aMNC )
       
   910 	{
       
   911 	RDEBUG("COperatorLogoAdapter::GetOpInfoL(): begin");
       
   912 	TInt err = KErrNone ;
       
   913 
       
   914 	aMCC = 0; // -1;
       
   915 	aMNC = 0; // -1;
       
   916 
       
   917 	RTelServer telServer ;
       
   918 	RMobilePhone mobilePhone;
       
   919 
       
   920 	CleanupClosePushL( telServer );
       
   921 	CleanupClosePushL( mobilePhone );
       
   922 
       
   923 	err = telServer.Connect();
       
   924 	User::LeaveIfError( err );
       
   925 
       
   926 	TInt phoneCount = 0;
       
   927 	err =  telServer.EnumeratePhones( phoneCount );
       
   928 	User::LeaveIfError( err );
       
   929 
       
   930 	TInt i = 0;
       
   931 	TBool found = EFalse;
       
   932 
       
   933 	for (i = 0 ; i < phoneCount && !found ; i++)
       
   934 		{
       
   935 		RTelServer::TPhoneInfo phoneInfo;
       
   936 		err = telServer.GetPhoneInfo( i, phoneInfo );
       
   937 		User::LeaveIfError( err );
       
   938 
       
   939 		err = mobilePhone.Open( telServer, phoneInfo.iName );
       
   940 
       
   941 		if (err == KErrNone)
       
   942 			{
       
   943 			TRequestStatus status;
       
   944 			RMobilePhone::TMobilePhoneNetworkInfoV1 v1Info;
       
   945 			RMobilePhone::TMobilePhoneNetworkInfoV1Pckg pckgInfo( v1Info );
       
   946 
       
   947 			// There are some problems with GetHomeNetwork() returned MNC when using old SIM-cards that have additional or invalid MNC in them.
       
   948 			// Therefor we prefer using network returned MNC if we are registered to home network.
       
   949 			// Otherwise we try to use MNC originated from SIM, should work but doesn't always because of SIM-errors.
       
   950 			RMobilePhone::TMobilePhoneRegistrationStatus regStatus;
       
   951 			mobilePhone.GetNetworkRegistrationStatus( status, regStatus );
       
   952 			User::WaitForRequest( status );
       
   953 
       
   954 			if (regStatus == RMobilePhone::ERegisteredOnHomeNetwork)
       
   955 				{
       
   956 				mobilePhone.GetCurrentNetwork( status, pckgInfo );
       
   957 				User::WaitForRequest( status );
       
   958 				}
       
   959 			else
       
   960 				{
       
   961 
       
   962 				mobilePhone.GetHomeNetwork( status, pckgInfo );
       
   963 				User::WaitForRequest( status );
       
   964 				}
       
   965 
       
   966 			TLex lex;
       
   967 			lex.Assign( v1Info.iCountryCode );
       
   968 			lex.Val( aMCC );
       
   969 			lex.Assign( v1Info.iNetworkId );
       
   970 			lex.Val( aMNC );
       
   971 
       
   972 			found = ETrue;
       
   973 			}
       
   974 
       
   975 		mobilePhone.Close();
       
   976 		}
       
   977 
       
   978 	telServer.Close();
       
   979 
       
   980 	CleanupStack::Pop( &mobilePhone );
       
   981 	CleanupStack::Pop( &telServer );
       
   982 	RDEBUG("COperatorLogoAdapter::GetOpInfoL(): end");
       
   983 	}
       
   984 
       
   985 
       
   986 
       
   987 
       
   988 // ------------------------------------------------------------------------------------------------
       
   989 //  COperatorLogoAdapter::SaveOperatorLogoBitmapL()
       
   990 // ------------------------------------------------------------------------------------------------
       
   991 void COperatorLogoAdapter::SaveOperatorLogoBitmapL( TInt aBitmapHandle, TInt aMCC, TInt aMNC )
       
   992 	{
       
   993 	TInt err = 0;
       
   994 	// Check parameters
       
   995 	if(aMCC == 0 || aMNC == 0)
       
   996 		{
       
   997 		return;
       
   998 		}
       
   999 		
       
  1000 	
       
  1001     
       
  1002 	CPhCltImageHandler* handler = CPhCltImageHandler::NewL(); 	
       
  1003 	User::LeaveIfNull( handler );
       
  1004 
       
  1005 	// Create image parameter class
       
  1006 	CPhCltImageParams* params = handler->CPhCltBaseImageParamsL( EPhCltTypeOperatorLogo );
       
  1007 	CPhCltExtOperatorLogoParams* imageParams = static_cast<CPhCltExtOperatorLogoParams*>(params);
       
  1008 
       
  1009 	// Specify country and network code
       
  1010 	imageParams->SetCodesL( aMCC, aMNC, EPhCltLogoTypeOTA );
       
  1011 
       
  1012 	// set CFbsBitmap handle of existing logo instance
       
  1013 	if (aBitmapHandle == 0)
       
  1014 		{
       
  1015 		aBitmapHandle = KPhCltDeleteOperatorLogo;
       
  1016 		}
       
  1017 	imageParams->AddImageL( aBitmapHandle );
       
  1018 
       
  1019 	// store image
       
  1020 	err = handler->SaveImages( *imageParams );
       
  1021 	User::LeaveIfError( err );
       
  1022 		
       
  1023     
       
  1024 	}
       
  1025