uiservicetab/vimpstdetailsviewplugin/src/cvimpstdetailsviewbrandhandler.cpp
changeset 0 5e5d6b214f4f
child 9 9fdee5e1da30
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 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 detailsview contact brand data
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include	"cvimpstdetailsviewbrandhandler.h"
       
    21 
       
    22 #include 	"vimpstdetailsview.hrh"
       
    23 #include 	"vimpstui.h"
       
    24 #include    "conversations.h"
       
    25 #include 	"tvimpstconsts.h"
       
    26 #include 	<vimpstui.mbg>
       
    27 #include    <conversations.mbg>
       
    28 // branding server
       
    29 #include 	<cbsfactory.h>
       
    30 #include 	<mbsaccess.h>
       
    31 #include 	<mbselement.h>
       
    32 // system includes
       
    33 #include    <AknIconUtils.h>
       
    34 // settings
       
    35 #include 	<spsettings.h>
       
    36 #include 	<spentry.h>
       
    37 #include 	<spproperty.h>
       
    38 
       
    39 #include    <cch.h>
       
    40 #include "vimpstdebugtrace.h"
       
    41 
       
    42 _LIT8(KAppIdForBrand,"xsp");
       
    43 _LIT8(KDefaultBrandIdForBrand,"xsp");
       
    44 
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 // ---------------------------------------------------------------------------
       
    47 // CVIMPSTDetailsViewBrandHandler::CVIMPSTDetailsViewBrandHandler()
       
    48 // ---------------------------------------------------------------------------
       
    49 // Two-phased constructor.
       
    50 CVIMPSTDetailsViewBrandHandler* CVIMPSTDetailsViewBrandHandler::NewL(TInt aServiceId )
       
    51     {
       
    52     CVIMPSTDetailsViewBrandHandler* self = new (ELeave) CVIMPSTDetailsViewBrandHandler( aServiceId);
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CVIMPSTDetailsViewBrandHandler::~CVIMPSTDetailsViewBrandHandler()
       
    61 // ---------------------------------------------------------------------------
       
    62 //  Destructor
       
    63 CVIMPSTDetailsViewBrandHandler::~CVIMPSTDetailsViewBrandHandler()
       
    64     {
       
    65      if(iBrandingAccess)
       
    66     	{
       
    67         iBrandingAccess->Close();
       
    68     	}
       
    69     delete iBrandingFactory;
       
    70     iBrandingFactory = NULL; 
       
    71    	delete iBrandId;
       
    72    	delete iSettings;
       
    73     delete iServiceStoreUri;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CVIMPSTDetailsViewBrandHandler::CVIMPSTDetailsViewBrandHandler()
       
    78 // ---------------------------------------------------------------------------
       
    79 // C++ default constructor can NOT contain any code, that
       
    80 // might leave.
       
    81 //
       
    82 CVIMPSTDetailsViewBrandHandler::CVIMPSTDetailsViewBrandHandler(TInt aServiceId) :
       
    83 	iAppId(KAppIdForBrand),
       
    84 	iServiceId( aServiceId)
       
    85     {
       
    86     iBrandingAccess = NULL;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CVIMPSTDetailsViewBrandHandler::ConstructL()
       
    91 // ---------------------------------------------------------------------------
       
    92 //  Symbian OS default constructor can leave.
       
    93 void CVIMPSTDetailsViewBrandHandler::ConstructL()
       
    94 	{
       
    95 	
       
    96 	iBrandId = HBufC8::NewL( KVIMPSTUISPSMaxPropertyLength );
       
    97     TPtr8 brandIdPtr( iBrandId->Des() );    
       
    98     
       
    99     TInt version = 1 ; // default
       
   100     
       
   101     iSettings = CSPSettings::NewL();
       
   102     
       
   103     // ELangInternationalEnglish is selected as Default Brand Language Id.
       
   104     iLanguageId = ELangInternationalEnglish;  
       
   105     	
       
   106     GetBrandInfoL(iLanguageId, version, brandIdPtr);	
       
   107     
       
   108 	iBrandingFactory = CBSFactory::NewL( KDefaultBrandIdForBrand, iAppId ); 
       
   109 	
       
   110 	
       
   111 	//Get the default MBM path
       
   112     Dll::FileName(iDefaultMbmPath); //get the location of the dll
       
   113     
       
   114     TDriveName drive( TParsePtrC( iDefaultMbmPath ).Drive( ) ); // solve drive
       
   115 
       
   116     // leave to stack, LC method
       
   117     HBufC* resourceFilePath = HBufC::NewLC( KMaxResourcePathLength );
       
   118     TPtr ptr( resourceFilePath->Des() );
       
   119     ptr.Append( KDefaultIconFile() ); // without drive
       
   120     ptr.Insert( 0, drive ); // insert drive
       
   121 
       
   122     // NearestLanguageFile takes only TFileName
       
   123     iDefaultMbmPath.Zero();
       
   124     iDefaultMbmPath.Append( *resourceFilePath );
       
   125 
       
   126 	CleanupStack::PopAndDestroy();//resourceFilePath
       
   127 	
       
   128 	// Leaves if no brand for service, therefore trap
       
   129     PrepareBrandingAccess();
       
   130     
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CVIMPSTDetailsViewBrandHandler::PrepareBrandingAccess()
       
   135 // ---------------------------------------------------------------------------
       
   136 // 
       
   137 TInt CVIMPSTDetailsViewBrandHandler::PrepareBrandingAccess()
       
   138     {
       
   139     
       
   140     TRAPD(err, iBrandingAccess = iBrandingFactory->CreateAccessL( *iBrandId, iLanguageId ));
       
   141     
       
   142     return err;
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------
       
   147 // CVIMPSTDetailsViewBrandHandler::LoadIconsLC
       
   148 // Loads necessary icons
       
   149 // (other items were commented in a header).
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 CAknIconArray* CVIMPSTDetailsViewBrandHandler::LoadIconsLC( )
       
   153     {
       
   154     //Fetching bitmaps from the server.
       
   155     if( !iBrandingAccess )
       
   156 	    {
       
   157 	    if( KErrNone != PrepareBrandingAccess() )
       
   158 	    //brand was not found so load the default data
       
   159 		    {
       
   160 		    return 	LoadDefaultIconsLC(iDefaultMbmPath);
       
   161 		    }	    	    
       
   162 	    }
       
   163 	//brand data is available
       
   164 	return LoadBrandIconsLC();		    
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CVIMPSTDetailsViewBrandHandler::LoadBitMapL
       
   169 // Loads necessary icons
       
   170 // (other items were commented in a header).
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CVIMPSTDetailsViewBrandHandler::LoadBitMapLC(CFbsBitmap*& aBitmap,
       
   174 									            CFbsBitmap*& aMask,
       
   175 									            TInt aBitmapId,
       
   176 									            TInt aMaskId  )
       
   177     {
       
   178     if( !iBrandingAccess )
       
   179 	    {
       
   180 	    if( KErrNone != PrepareBrandingAccess() )
       
   181 	    //brand was not found so load the default data
       
   182 		    {
       
   183 		    AknIconUtils::CreateIconLC( aBitmap,aMask, iDefaultMbmPath, aBitmapId, aMaskId  );
       
   184 		    return;
       
   185 		    }	    	    
       
   186 	    }
       
   187 	//brand data is available
       
   188 	 CGulIcon* icon = NULL;
       
   189 	 icon = LoadBrandBitmapL( KEMbmConversationsQgnpropservicedefaultavatar );	
       
   190      aBitmap = icon->Bitmap();
       
   191      aMask = icon->Mask();	
       
   192      // this is remove the memory leak
       
   193      icon->SetBitmapsOwnedExternally( ETrue );
       
   194      delete icon ;     
       
   195      CleanupStack::PushL( aBitmap );
       
   196      CleanupStack::PushL( aMask );
       
   197      }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CVIMPSTDetailsViewBrandHandler::LoadBrandIconsLC
       
   201 // Loads necessary icons
       
   202 // (other items were commented in a header).
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 CAknIconArray* CVIMPSTDetailsViewBrandHandler::LoadBrandIconsLC( )
       
   206     {
       
   207     // array granularity is 12, because 12 icons are added to array
       
   208     CAknIconArray* icons = new( ELeave )CAknIconArray( 12);
       
   209     CleanupStack::PushL( icons );
       
   210     
       
   211     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimfriendoff) );//0
       
   212     		
       
   213     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimfriendon) );//1
       
   214     
       
   215   	icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimfriendaway ) );//2
       
   216 	
       
   217     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimfriendbusy ) );//3
       
   218 
       
   219    	icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimfriendinvisible ) );//4
       
   220     
       
   221     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimimsg ) );//5
       
   222     
       
   223     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimimsgnew ) );//6
       
   224     
       
   225     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropservicedefaultavatar ) );//7
       
   226     
       
   227     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropservicefriendrequestreceived ) );//8
       
   228     
       
   229     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropservicefriendrequestsent ) );//9
       
   230     
       
   231     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropserviceofffriendrequestreceived ) );//10
       
   232     
       
   233     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropserviceofffriendrequestsent ) );//11
       
   234     
       
   235     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimuserblocked ) );//12
       
   236     
       
   237     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimfriendonmobile ) );//13
       
   238     
       
   239     icons->AppendL( LoadBrandBitmapL(KEMbmConversationsQgnpropimusercallforward ) );//14
       
   240     
       
   241     return icons;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CVIMPSTDetailsViewBrandHandler::LoadBrandBitmapL
       
   246 // (other items were commented in a header).
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 CGulIcon* CVIMPSTDetailsViewBrandHandler::LoadBrandBitmapL( const TDesC8& aId )
       
   250 	{
       
   251     
       
   252     CFbsBitmap* bitmap = NULL;
       
   253     CFbsBitmap* mask = NULL;
       
   254     
       
   255     //Fetching bitmaps from the server.
       
   256     if(!iBrandingAccess)
       
   257 	    {
       
   258 	    PrepareBrandingAccess();	
       
   259 	    }
       
   260     iBrandingAccess->GetBitmapL( aId, bitmap, mask );
       
   261     CleanupStack::PushL( bitmap );
       
   262     CleanupStack::PushL( mask );
       
   263     //	bitmap, mask ownership passed to gulIcon	
       
   264     CGulIcon* icon = CGulIcon::NewL(bitmap, mask);
       
   265     icon->SetBitmapsOwnedExternally( EFalse );
       
   266 	CleanupStack::Pop(2); // bitmap, mask 
       
   267     return icon;
       
   268     }
       
   269 
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // CVIMPSTDetailsViewBrandHandler::LoadDefaultIconsLC
       
   273 // Loads necessary icons
       
   274 // (other items were commented in a header).
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 CAknIconArray* CVIMPSTDetailsViewBrandHandler::LoadDefaultIconsLC( const TDesC& aMbmFile)
       
   278     {
       
   279     // array granularity is 5
       
   280     CAknIconArray* icons = new( ELeave )CAknIconArray( 5);
       
   281     CleanupStack::PushL( icons );
       
   282 			
       
   283     icons->AppendL( LoadDefaultBitmapL( // 0
       
   284     	EMbmVimpstuiQgn_prop_im_friend_off,
       
   285 		EMbmVimpstuiQgn_prop_im_friend_off_mask,
       
   286 		aMbmFile ) );
       
   287     icons->AppendL( LoadDefaultBitmapL( // 1
       
   288 		EMbmVimpstuiQgn_prop_im_friend_on,
       
   289 		EMbmVimpstuiQgn_prop_im_friend_on_mask,
       
   290 		aMbmFile ) );
       
   291 		
       
   292 	icons->AppendL( LoadDefaultBitmapL( // 2
       
   293 		EMbmVimpstuiQgn_prop_im_friend_away,
       
   294 		EMbmVimpstuiQgn_prop_im_friend_away_mask,
       
   295 		aMbmFile ) );
       
   296 	icons->AppendL( LoadDefaultBitmapL( // 3
       
   297 		EMbmVimpstuiQgn_prop_im_friend_busy,
       
   298 		EMbmVimpstuiQgn_prop_im_friend_busy_mask,
       
   299 		aMbmFile ) );
       
   300 	icons->AppendL( LoadDefaultBitmapL( // 4
       
   301 		EMbmVimpstuiQgn_prop_im_friend_invisible,
       
   302 		EMbmVimpstuiQgn_prop_im_friend_invisible_mask,
       
   303 		aMbmFile ) );
       
   304 	icons->AppendL( LoadDefaultBitmapL( // 5
       
   305 		EMbmVimpstuiQgn_prop_im_imsg,
       
   306 		EMbmVimpstuiQgn_prop_im_imsg_mask,
       
   307 		aMbmFile ) );
       
   308 	icons->AppendL( LoadDefaultBitmapL( // 6
       
   309 		EMbmVimpstuiQgn_prop_im_imsg_new,
       
   310 		EMbmVimpstuiQgn_prop_im_imsg_new_mask,
       
   311 		aMbmFile ) );	
       
   312 	icons->AppendL( LoadDefaultBitmapL( // 7
       
   313 	    EMbmVimpstuiQgn_prop_service_default_avatar,
       
   314 	    EMbmVimpstuiQgn_prop_service_default_avatar_mask,
       
   315         aMbmFile ) );  
       
   316     icons->AppendL( LoadDefaultBitmapL( // 8
       
   317             EMbmVimpstuiQgn_prop_service_friend_request_received,
       
   318             EMbmVimpstuiQgn_prop_service_friend_request_received_mask,
       
   319             aMbmFile ) );  
       
   320     icons->AppendL( LoadDefaultBitmapL( // 9
       
   321             EMbmVimpstuiQgn_prop_service_friend_request_sent,
       
   322             EMbmVimpstuiQgn_prop_service_friend_request_sent_mask,
       
   323                aMbmFile ) );  
       
   324     icons->AppendL( LoadDefaultBitmapL( // 10
       
   325             EMbmVimpstuiQgn_prop_service_off_friend_request_received,
       
   326             EMbmVimpstuiQgn_prop_service_off_friend_request_received_mask,
       
   327             aMbmFile ) );  
       
   328     icons->AppendL( LoadDefaultBitmapL( // 11
       
   329             EMbmVimpstuiQgn_prop_service_off_friend_request_sent,
       
   330             EMbmVimpstuiQgn_prop_service_off_friend_request_sent_mask,
       
   331                aMbmFile ) );    
       
   332     icons->AppendL( LoadDefaultBitmapL( // 12
       
   333             EMbmVimpstuiQgn_servtab_avatar_blocked,
       
   334             EMbmVimpstuiQgn_servtab_avatar_blocked_mask,
       
   335                    aMbmFile ) ); //12   
       
   336 
       
   337     icons->AppendL( LoadDefaultBitmapL( // 13
       
   338             EMbmVimpstuiQgn_prop_im_friend_on_mobile,
       
   339             EMbmVimpstuiQgn_prop_im_friend_on_mobile_mask,
       
   340                aMbmFile ) );    
       
   341     
       
   342     return icons;
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CVIMPSTDetailsViewBrandHandler::LoadDefaultBitmapL
       
   347 // (other items were commented in a header).
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 CGulIcon* CVIMPSTDetailsViewBrandHandler::LoadDefaultBitmapL( TInt aBitmapId, TInt aMaskId, 
       
   351                                       const TDesC& aFullPath )
       
   352 	{
       
   353     CFbsBitmap* bitmap = NULL;
       
   354     CFbsBitmap* mask = NULL;
       
   355     AknIconUtils::CreateIconLC( bitmap,mask, aFullPath,aBitmapId,aMaskId  ); 
       
   356     //	bitmap, mask ownership passed to gulIcon				  
       
   357     CGulIcon* gulIcon = CGulIcon::NewL( bitmap, mask );
       
   358     CleanupStack::Pop( 2 ); // bitmap, mask
       
   359     return gulIcon;
       
   360     }
       
   361 
       
   362  // ---------------------------------------------------------------------------
       
   363 // CVIMPSTDetailsViewBrandHandler::PropertyBrandVersionL()
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void CVIMPSTDetailsViewBrandHandler::PropertyReadBrandL( TUint32 aServiceId ,TInt &aBrand, TServicePropertyName aPropertyName ) 
       
   367     {
       
   368     CSPProperty* property = CSPProperty::NewLC();
       
   369     iSettings->FindPropertyL( aServiceId,
       
   370                                 aPropertyName,
       
   371                                 *property );    
       
   372     if ( property )
       
   373         {
       
   374         property->GetValue( aBrand );
       
   375         }
       
   376     CleanupStack::PopAndDestroy( property );
       
   377    
       
   378     }
       
   379 
       
   380 // ---------------------------------------------------------
       
   381 // CVIMPSTDetailsViewBrandHandler::GetBrandInfo
       
   382 // 
       
   383 // ---------------------------------------------------------
       
   384 TInt CVIMPSTDetailsViewBrandHandler::GetBrandInfoL(TLanguage& aBrandLanguage, 
       
   385 				TInt &aBrandVersion, TDes8& aBrandId)
       
   386 
       
   387 	{
       
   388 
       
   389     CSPProperty* property = CSPProperty::NewLC();
       
   390     iSettings->FindPropertyL( iServiceId,
       
   391                                 EPropertyBrandId,
       
   392                                 *property );    
       
   393     if ( property )
       
   394         {
       
   395         HBufC* brandId = HBufC::NewLC( KVIMPSTUISPSMaxPropertyLength );
       
   396     	TPtr brandIdPtr( brandId->Des() ); 
       
   397         property->GetValue( brandIdPtr );
       
   398         aBrandId.Copy(brandIdPtr);
       
   399         CleanupStack::PopAndDestroy( brandId );
       
   400         }
       
   401     CleanupStack::PopAndDestroy( property ); 
       
   402     
       
   403     TInt language = ELangInternationalEnglish; 
       
   404    	PropertyReadBrandL( iServiceId, language , EPropertyBrandLanguage );
       
   405    	aBrandLanguage = ( TLanguage) language;
       
   406    	
       
   407 	PropertyReadBrandL( iServiceId, aBrandVersion , EPropertyBrandVersion) ;
       
   408 	
       
   409 	return KErrNone;
       
   410 	}
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CVIMPSTDetailsViewBrandHandler::GetServiceNameL()
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void CVIMPSTDetailsViewBrandHandler::GetServiceNameL( TDes& aServiceName )
       
   417     {
       
   418     CSPEntry* entry = CSPEntry::NewLC();
       
   419     TRAPD( err, iSettings->FindEntryL( iServiceId, *entry ) );
       
   420     if ( !err )
       
   421         {
       
   422         aServiceName = entry->GetServiceName();
       
   423         }
       
   424     CleanupStack::PopAndDestroy( entry );    
       
   425     }
       
   426  
       
   427  // ---------------------------------------------------------------------------
       
   428 // CVIMPSTDetailsViewBrandHandler::ServiceStoreUriL()
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 const TDesC& CVIMPSTDetailsViewBrandHandler::ServiceStoreUriL()
       
   432     {
       
   433     if( !iServiceStoreUri )
       
   434         {       
       
   435         iServiceStoreUri = HBufC::NewL( KVIMPST_MAX_LENGTH );       
       
   436         TPtr  serviceStorePtr( iServiceStoreUri->Des() );
       
   437 
       
   438         CSPProperty* property = CSPProperty::NewLC();
       
   439         iSettings->FindPropertyL( iServiceId,
       
   440                 EPropertyContactStoreId,
       
   441                 *property ); 
       
   442 
       
   443         property->GetValue( serviceStorePtr );
       
   444         CleanupStack::PopAndDestroy( property );
       
   445          }
       
   446     return *iServiceStoreUri;
       
   447     } 
       
   448 // ---------------------------------------------------------------------------
       
   449 // CVIMPSTDetailsViewBrandHandler::ServiceSupportedL( )
       
   450 // ---------------------------------------------------------------------------
       
   451 //
       
   452 TBool CVIMPSTDetailsViewBrandHandler::ServiceSupportedL( )
       
   453     {
       
   454     TBool ret = EFalse;
       
   455     CCch* cchClient = CCch::NewLC();
       
   456     if (cchClient)
       
   457         {       
       
   458         CCchService* service = cchClient->GetService( iServiceId ); 
       
   459         TCchServiceStatus status;
       
   460         status.SetState(ECCHUninitialized);
       
   461         TInt err = service->GetStatus( TCCHSubserviceType(ECCHPresenceSub), status );
       
   462         if (KErrNone == err)
       
   463            {
       
   464            ret = ETrue; 
       
   465            }
       
   466         CleanupStack::PopAndDestroy(); // cchClient
       
   467         }
       
   468     return ret;
       
   469     }
       
   470 //  End of File