logsui/logsserviceextension/src/clogsuicontrolextension.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Provides additional functionality to the Logs UI application
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <gulicon.h>
       
    22 #include <aknnotewrappers.h> 
       
    23 #include <aknlists.h>
       
    24 
       
    25 #include "clogsuicontrolextension.h"
       
    26 
       
    27 #include "clogspresencetablemanager.h"
       
    28 #include "clogseventinfomanager.h"
       
    29 #include "clogsextbrandfetcher.h"
       
    30 #include "clogsextpresentityidfetcher.h"
       
    31 #include "tlogseventinfo.h"
       
    32 #include "clogsiconfileprovider.h"
       
    33 #include "clogsextservicehandler.h"
       
    34 
       
    35 #include "LogsConstants.hrh"    // for KLogsBuff128
       
    36 #include "LogsConsts.h"         // for KMaxNbrOfRecentTrailIcons, KTab                        
       
    37 #include "logsextconsts.h"
       
    38 #include "tlogsextutil.h"
       
    39 
       
    40 #include "simpledebug.h"
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // NewL
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CLogsUiControlExtension* CLogsUiControlExtension::NewL()
       
    51     {
       
    52     _LOG("CLogsUiControlExtension::NewL()" )
       
    53     CLogsUiControlExtension* self = CLogsUiControlExtension::NewLC();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // NewLC
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CLogsUiControlExtension* CLogsUiControlExtension::NewLC()
       
    64     {
       
    65     _LOG("CLogsUiControlExtension::NewLC()" )
       
    66     CLogsUiControlExtension* self = new( ELeave ) CLogsUiControlExtension;
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // ConstructL
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CLogsUiControlExtension::ConstructL()
       
    78     {
       
    79     _LOG("CLogsUiControlExtension::ConstructL() begin" )
       
    80     iLogEntryInfoManager = CLogsEventInfoManager::NewL();
       
    81     iPresenceTableManager = CLogsPresenceTableManager::NewL();
       
    82     _LOG("CLogsUiControlExtension::ConstructL() end" )
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Constructor
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CLogsUiControlExtension::CLogsUiControlExtension():    
       
    91     iListBox( NULL ),
       
    92     iLogsExtObserver( NULL ),
       
    93     iBrandFetcherArray( KBrandFetcherArrayGranularity ),    
       
    94     iPresentityIdFetcherArray( KPresentityIdFetcherArrayGranularity ),
       
    95     iServiceHandlerArray( KPresentityIdFetcherArrayGranularity ),
       
    96     iBitmap( NULL ),
       
    97     iBitmask( NULL )    
       
    98     {
       
    99     _LOG("CLogsUiControlExtension::CLogsUiControlExtension()" )
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Destructor
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CLogsUiControlExtension::~CLogsUiControlExtension()
       
   108     {
       
   109     _LOG("CLogsUiControlExtension::~CLogsUiControlExtension() begin" )
       
   110     delete iLogEntryInfoManager;        
       
   111     delete iPresenceTableManager;
       
   112     iBrandFetcherArray.ResetAndDestroy();           
       
   113     iPresentityIdFetcherArray.ResetAndDestroy();
       
   114         
       
   115     delete iBitmap;
       
   116     delete iBitmask;
       
   117     
       
   118     _LOG("CLogsUiControlExtension::~CLogsUiControlExtension()..." )
       
   119     _LOG("...iServiceHandlerArray.ResetAndDestroy")
       
   120     iServiceHandlerArray.ResetAndDestroy();
       
   121     
       
   122     _LOG("CLogsUiControlExtension::~CLogsUiControlExtension() end" )
       
   123     }
       
   124     
       
   125     
       
   126 // ---------------------------------------------------------------------------
       
   127 // Delete member data.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CLogsUiControlExtension::DoRelease()
       
   131     {
       
   132     _LOG("CLogsUiControlExtension::DoRelease() begin" )    
       
   133     delete this;
       
   134     _LOG("CLogsUiControlExtension::DoRelease() end" )
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // functionality not supported by this dll - function does nothing
       
   139 // ---------------------------------------------------------------------------
       
   140 //    
       
   141 void CLogsUiControlExtension::AppendIconsL( CAknIconArray* /*aArray*/ )
       
   142     {
       
   143     _LOG("CLogsUiControlExtension::AppendIconsL begin" )
       
   144     // Reset brand fetcher array. Brand fetchers and icons are reconstructed
       
   145     // again when when HandleAdditionalData() gets called. We cannot load
       
   146     // icons here because we don't know yet which icons to load.
       
   147     iBrandFetcherArray.ResetAndDestroy();
       
   148     iPresenceTableManager->ResetState();
       
   149     iServiceHandlerArray.ResetAndDestroy();
       
   150     _LOG("CLogsUiControlExtension::AppendIconsL end" )
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // functionality not supported by this dll - function does nothing
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 TBool CLogsUiControlExtension::GetIconIndexL( TContactItemId /*aContactId*/,
       
   158                                               TInt& /*aIndex*/ )
       
   159     {
       
   160     _LOG("CLogsUiControlExtension::GetIconIndexL begin" )
       
   161     _LOG("CLogsUiControlExtension::GetIconIndexL end" )
       
   162     return EFalse;
       
   163     }
       
   164     
       
   165 // ---------------------------------------------------------------------------
       
   166 // Sets the observer of the extension (probably a CLogsRecentListView object)
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CLogsUiControlExtension::SetObserver( MLogsExtObserver& aObserver )
       
   170     {
       
   171     _LOG("CLogsUiControlExtension::SetObserver begin" )
       
   172     iLogsExtObserver = &aObserver;
       
   173     _LOG("CLogsUiControlExtension::SetObserver end" )
       
   174     }
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Starts the additional data handling.
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CLogsUiControlExtension::HandleAdditionalData( 
       
   182     MLogsModel& aModel, 
       
   183     CAknDoubleGraphicStyleListBox& aListBox )
       
   184     {
       
   185     _LOG("CLogsUiControlExtension::HandleAdditionalDataL begin" )
       
   186     iListBox = &aListBox;    
       
   187         
       
   188     ResetPresentityIdFetcherArray();    
       
   189     
       
   190     TRAP_IGNORE( DoAdditionalDataHandlingL( aModel ) );    
       
   191     
       
   192     _LOG("CLogsUiControlExtension::HandleAdditionalDataL end" )        
       
   193     }
       
   194     
       
   195 // ---------------------------------------------------------------------------
       
   196 // Creates and starts all the icon fetching processes.
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CLogsUiControlExtension::DoAdditionalDataHandlingL( MLogsModel& aModel )
       
   200     {
       
   201     _LOG("CLogsUiControlExtension::DoAdditionalDataHandlingL begin" )
       
   202     
       
   203     CreateAndStartBrandFetchersL( aModel );    
       
   204     CreateAndStartPresentityIdFetchersL( aModel );           
       
   205     
       
   206     _LOG("CLogsUiControlExtension::DoAdditionalDataHandlingL end" )        
       
   207     }    
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // Creates a service handler for a certain service if it not already 
       
   211 // exists and issues the binding request.
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CLogsUiControlExtension::CreateAndBindServiceHandlerL( TUint32 aServiceId )
       
   215     {
       
   216     _LOG("CLogsUiControlExtension::CreateAndBindServiceHandlerL: begin" )
       
   217         
       
   218     if ( aServiceId && !ServiceHandlerExists( aServiceId ) )
       
   219         {            
       
   220         // create and bind the service handler
       
   221         _LOG("CLogsUiControlExtension::CreateAndBindServiceHandlerL:..." )
       
   222         _LOG("... !ServiceHandlerExists")
       
   223         
       
   224         
       
   225         CLogsExtServiceHandler* serviceHandler = 
       
   226             CLogsExtServiceHandler::NewLC( aServiceId, *this );                
       
   227         
       
   228         _LOG("CLogsUiControlExtension::CreateAndBindServiceHandlerL:..." )
       
   229         _LOG("...iServiceHandlerArray.AppendL( serviceHandler )")
       
   230         
       
   231         iServiceHandlerArray.AppendL( serviceHandler );
       
   232         
       
   233         CleanupStack::Pop( serviceHandler );        
       
   234         }
       
   235     
       
   236     _LOG("CLogsUiControlExtension::CreateAndBindServiceHandlerL: end" )
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // Creates and starts all the brand icon fetching processes.
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CLogsUiControlExtension::CreateAndStartBrandFetchersL( 
       
   244         MLogsModel& aModel )
       
   245     {
       
   246             
       
   247     for ( TInt i = 0 ; i < aModel.Count() ; i++ )
       
   248         {        
       
   249         // Here we go through the list of events an check whether the events
       
   250         // contain a service id or not.Then a brand fetcher is created for 
       
   251         // each service id.
       
   252         
       
   253         // PC-lint errors: #1013, #1055, #64
       
   254         // Explanation: error message occurs because the 'DataField' function
       
   255         // is flagged by __VOIP and RD_VOIP_REL_2_2 flags; as long as the 
       
   256         // entire logsserviceextension is flagged by __VOIP and 
       
   257         // RD_VOIP_REL_2_2 as well this does not cause any problems
       
   258                 
       
   259         // get the serviceId
       
   260         TUint32 serviceId ( aModel.At(i)->LogsEventData()->ServiceId() );
       
   261         
       
   262         if ( serviceId && !BrandFetcherExists( serviceId ) )
       
   263             {
       
   264             // the manager adds a eventInfo object only if it does not
       
   265             // contain an eventinfo object with the given service id
       
   266             // --> this acts as a duplicate-elimination
       
   267             TRAP_IGNORE( iLogEntryInfoManager->AddEventEntryL( serviceId ) );
       
   268             
       
   269             // create and start the fetcher
       
   270             CLogsExtBrandFetcher* brandFetcher = 
       
   271                 CLogsExtBrandFetcher::NewLC( serviceId, *this );
       
   272                 
       
   273             iBrandFetcherArray.AppendL( brandFetcher );
       
   274             CleanupStack::Pop( brandFetcher );
       
   275                 
       
   276             brandFetcher->Fetch();            
       
   277             }        
       
   278         }    
       
   279     }
       
   280 
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // Creates and starts all the presence icon fetching processes.
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CLogsUiControlExtension::CreateAndStartPresentityIdFetchersL( 
       
   287         MLogsModel& aModel )
       
   288     {    
       
   289     _LOG("CLogsUiControlExtension::CreateAndStartPresentityIdFetchersL begin " ) 
       
   290     // go through all the log events and create the status entries 
       
   291     // (iPresenceTableManager takes care for duplication elimination and returns
       
   292     //  KErrAlreadyExists if one tries to add an entry that already exists)
       
   293     // create one presence fetcher for each status table entry and start them.
       
   294     // note: entries to the index table will only be added after the callback 
       
   295     // from the presencefw
       
   296     
       
   297     // the presence table manager decides which mappings are not needed
       
   298     // anymore by comparing the log ids of the current view to the 
       
   299     // log ids in the array of mappings; mappings which contain a log id
       
   300     // that cannot be found from 'aModel' will be deleted.
       
   301     iPresenceTableManager->RemoveUnneededMappings( aModel );
       
   302       
       
   303     for ( TInt i = 0 ; i < aModel.Count() ; i++ )
       
   304         {
       
   305 
       
   306         // PC-lint errors: #1013, #1055
       
   307         // Explanation: error message occurs because the 'DataField' function
       
   308         // is flagged by __VOIP and RD_VOIP_REL_2_2 flags; as long as the 
       
   309         // entire logsserviceextension is flagged by __VOIP and RD_VOIP_REL_2_2
       
   310         // as well this does not cause any problems
       
   311         
       
   312         TUint32 serviceId( aModel.At(i)->LogsEventData()->ServiceId() );
       
   313         TPtrC8 contactLink;
       
   314         TBool contactLinkRetrievalSuccess( EFalse );
       
   315         if ( KErrNone == aModel.At(i)->
       
   316                             LogsEventData()->GetContactLink( contactLink ) )
       
   317             {
       
   318             contactLinkRetrievalSuccess = ETrue;
       
   319             }
       
   320 
       
   321         if ( serviceId && contactLinkRetrievalSuccess )
       
   322             {
       
   323             //create the presentity id fetcher
       
   324             DoPresentityIdFetcherCreationL( serviceId, 
       
   325                                             contactLink, 
       
   326                                             aModel.At(i)->LogId() );
       
   327             }
       
   328         
       
   329         }        
       
   330     _LOG("CLogsUiControlExtension::CreateAndStartPresentityIdFetchersL end " )
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // Modifies the given icon string.
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CLogsUiControlExtension::ModifyIconString ( 
       
   338         TDes& aDes, 
       
   339         const MLogsEventGetter& aLogsEventGetter )
       
   340     {
       
   341     _LOGP("CLogsUiControlExtension::ModifyIconString begin originalstring=%S",
       
   342         &aDes)    
       
   343     
       
   344     // only make changes to log entries that contain a service id and
       
   345     // dont start looking for fetching results before the fetching
       
   346     // process has been started. (Fetching is initiated through 
       
   347     // HandleAdditionalDataL function call)
       
   348     
       
   349     TInt result( KErrNone );
       
   350     TRAP( result, DoIconStringModificationL( aDes, aLogsEventGetter ) );
       
   351         
       
   352     _LOGP("CLogsUiControlExtension::ModifyIconString resulting string=%S",
       
   353     	&aDes )
       
   354     
       
   355     _LOG("CLogsUiControlExtension::ModifyIconString end" )
       
   356     }   
       
   357     
       
   358 // ---------------------------------------------------------------------------
       
   359 // Makes the actual modifications to the string.
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CLogsUiControlExtension::DoIconStringModificationL(  
       
   363     TDes& aDes, 
       
   364     const MLogsEventGetter& aLogsEventGetter )
       
   365     {   
       
   366     _LOG("CLogsUiControlExtension::DoIconStringModificationL begin" )
       
   367     
       
   368     // use the parser to extract e.g. the service id from the data field of a
       
   369     // log event. the information should be tagged like this -> "SI=5", 
       
   370     // whereas "SI" is the identifier for a service id and "5" is its value
       
   371 
       
   372     // PC-lint errors: #1013
       
   373     // Explanation: error message occurs because the 'DataField' function
       
   374     // is flagged by __VOIP and RD_VOIP_REL_2_2 flags; as long as the 
       
   375     // entire logsserviceextension is flagged by __VOIP and RD_VOIP_REL_2_2
       
   376     // as well this does not cause any problems       
       
   377     
       
   378     TUint32 serviceId( aLogsEventGetter.LogsEventData()->ServiceId() );
       
   379     if ( serviceId <= 0 )
       
   380         {
       
   381         // without service id we cannont proceed any further...
       
   382         User::Leave( KErrNotFound );
       
   383         }
       
   384     
       
   385     TBool brandIconIndexAvailable( 
       
   386         iLogEntryInfoManager->BrandIconIndexAvailable( serviceId ) );
       
   387     
       
   388     TBool presenceIconIndexAvailable( EFalse );
       
   389 
       
   390     const TDesC* presentityId = 
       
   391         presentityId = LookupPresentityId( aLogsEventGetter.LogId() ); 
       
   392     //don't leave here: if the presentity id does not exist it means that
       
   393     //we cannot check the availability of that presentity from the 
       
   394     //presencetablemanager - but we can still try to set the 
       
   395     //brandicon index.
       
   396     
       
   397     if ( presentityId )
       
   398         {        
       
   399         _LOG("CLogsUiControlExtension::DoIconStringModificationL ...")
       
   400         _LOGP("...presentityId=%S", presentityId )
       
   401                 
       
   402         if ( iPresenceTableManager )
       
   403             {
       
   404             _LOG("CLogsUiControlExtension::DoIconStringModificationL..." )
       
   405             _LOG("...iPresenceTableManager available")
       
   406             presenceIconIndexAvailable = 
       
   407                 iPresenceTableManager->PresenceIconIndexAvailable( 
       
   408                     serviceId, *presentityId );                
       
   409             }
       
   410         }    
       
   411     
       
   412     // only create the HBufC if either brand- or presence index is available
       
   413     if ( brandIconIndexAvailable || presenceIconIndexAvailable )
       
   414         {
       
   415         // e.g. aDes = '0\ttext1\ttext2' whereas '\t' is the delimiter
       
   416         //create an empty local buffer of the same size as aDes
       
   417         HBufC* temp = HBufC::NewLC( KLogsBuff128 );
       
   418         TPtr tempDes( temp->Des() );
       
   419         
       
   420         //create the new icon string:
       
   421         //if no error occurred while creating the local string data->
       
   422         //update aDes with the modified version of the icon string
       
   423         //otherwise the original data will not be modified
       
   424         
       
   425         if ( brandIconIndexAvailable 
       
   426             && AddBrandIconIndex( tempDes, serviceId ) 
       
   427             && AddNonIndexData( aDes, tempDes ) )
       
   428             {
       
   429             aDes.Copy( *temp );
       
   430             }
       
   431         
       
   432         // make a copy of the original string (that might contain  
       
   433         // the modified brandicon index already)
       
   434         tempDes.Copy( aDes );            
       
   435         
       
   436         if ( presenceIconIndexAvailable 
       
   437             && AddPresenceIconIndex( tempDes, serviceId, *presentityId ) )
       
   438             {
       
   439             aDes.Copy( *temp );
       
   440             }
       
   441         
       
   442         //cleanup the local string buffer
       
   443         CleanupStack::PopAndDestroy( temp );
       
   444         temp = NULL;        
       
   445         }
       
   446             
       
   447     _LOG("CLogsUiControlExtension::DoIconStringModificationL end" )           
       
   448     }
       
   449 
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // Adds the branding icon index.
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 TBool CLogsUiControlExtension::AddBrandIconIndex( TDes& aTempDes, 
       
   456                                                   const TUint32 aServiceId )
       
   457     {
       
   458     _LOG("CLogsUiControlExtension::AddBrandIconIndex begin" )   
       
   459     TBool result( EFalse );        
       
   460     
       
   461     TInt brandIndex( KErrNotFound );
       
   462     // Check if the brand icon for the specified service id can be found
       
   463     if ( iLogEntryInfoManager->GetBrandIconIndex( aServiceId, brandIndex ) )
       
   464         {
       
   465         //Add the brand icon index to the temp string
       
   466         aTempDes.Num( brandIndex );
       
   467         _LOGP("CLogsUiControlExtension::AddBrandIconIndex BrandIndex=%d",
       
   468             brandIndex )
       
   469         // e.g. aTempDes = '7'
       
   470         result = ETrue;
       
   471         }        
       
   472     
       
   473     _LOG("CLogsUiControlExtension::AddBrandIconIndex end" )  
       
   474     return result;
       
   475     }
       
   476 
       
   477 
       
   478 // ---------------------------------------------------------------------------
       
   479 // Copies that part of the global icon string to the local copy which contains
       
   480 // the non-icon index related data.
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 TBool CLogsUiControlExtension::AddNonIndexData( 
       
   484         const TDesC& aDes, 
       
   485         TDes& aTempDes )
       
   486     {
       
   487     _LOG("CLogsUiControlExtension::AddNonIndexData begin" )  
       
   488     TBool result( EFalse );
       
   489     
       
   490     // find the first occurrence of the delimiter in the original
       
   491     // icon string
       
   492     TInt Position( aDes.Find( KTab ) );
       
   493     if ( KErrNotFound != Position )
       
   494         {
       
   495         // position has been found:
       
   496         // now copy 
       
   497         aTempDes.Append( aDes.Mid( Position ) );
       
   498         // e.g. aTempDes = '7\ttext1\ttext2'
       
   499         result = ETrue;
       
   500         }        
       
   501     
       
   502     _LOG("CLogsUiControlExtension::AddNonIndexData end" )  
       
   503     return result;    
       
   504     }
       
   505 
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // Appends the trailing delimiters (if they do not already exist) and the 
       
   509 // presence icon index.
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 TBool CLogsUiControlExtension::AddPresenceIconIndex( 
       
   513         TDes& aTempDes, 
       
   514         const TUint32 aServiceId,
       
   515         const TDesC16& aPresentityId )
       
   516     {
       
   517     _LOGP("CLogsUiControlExtension::AddPresenceIconIndex begin %d" , 
       
   518         aServiceId)     
       
   519     TBool result( EFalse );
       
   520     
       
   521     /// determine the number of trailing delimiters and add missing ones
       
   522     //  e.g. Given a) aTempDes = '7\ttext1\ttext2' and 
       
   523     //             b) KMaxNbrOfRecentTrailIcons == 2 
       
   524     //       --> Add two empty trailing icon indices
       
   525     //       Result: aTempDes = '7\ttext1\ttext2\t\t'
       
   526     
       
   527     // determine the number of delimiters
       
   528     TInt numberDelimiters = DetermineNumberDelimiters( aTempDes );
       
   529     
       
   530     if ( numberDelimiters >= KNumberDelimitersUnmodifiedIconStringMin && 
       
   531          numberDelimiters <= KNumberDelimitersUnmodifiedIconStringMax )
       
   532         {
       
   533         //add the trailing delimiters to the end of the string
       
   534         TInt returnValue( 
       
   535             AppendTrailingDelimiters( 
       
   536                 aTempDes, 
       
   537                 KNumberDelimitersModifiedIconString - numberDelimiters ) );
       
   538         result = ( KErrNone == returnValue ) ? ETrue : EFalse;
       
   539         }
       
   540     else
       
   541         {
       
   542         result = EFalse;        
       
   543         }
       
   544     
       
   545     //if adding the 
       
   546     if ( result ) 
       
   547         {
       
   548         // finally append the presence icon index
       
   549         TInt presenceIndex( KErrNotFound );
       
   550         /// Check, if the presence icon could be retrieved
       
   551         if( KErrNone == iPresenceTableManager->GetIndex( aServiceId, 
       
   552                                                          aPresentityId, 
       
   553                                                          presenceIndex ) )
       
   554             {
       
   555             // Add the presence icon index to the temp string            
       
   556             aTempDes.AppendNum( presenceIndex );       
       
   557             // e.g. aTempDes = '7\ttext1\ttext2\t\t\t8'
       
   558             _LOG("CLogsUiControlExtension::AddPresenceIconIndex ...")
       
   559             _LOGP("...PresenceIndex=%d", presenceIndex )
       
   560             result = ETrue;
       
   561             }
       
   562         else
       
   563             {
       
   564             result = EFalse;
       
   565             }
       
   566         }
       
   567     _LOG("CLogsUiControlExtension::AddPresenceIconIndex end" )     
       
   568     return result;    
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // Appends 'aNumber' delimiters to the end of aTempDes.
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 TInt CLogsUiControlExtension::AppendTrailingDelimiters( TDes& aTempDes, 
       
   576                                                         TInt  aNumber )
       
   577     {
       
   578     _LOG("CLogsUiControlExtension::AppendTrailingDelimiters begin" )     
       
   579     TInt error( KErrNoMemory );
       
   580     
       
   581     //make sure the size of descriptor is big enough, so that appending
       
   582     //won't panic
       
   583     TInt len( aNumber * KTab().Length() );
       
   584     if ( aTempDes.Length() + len <= aTempDes.MaxLength() )
       
   585         {
       
   586         for ( TInt i( 0 ); i < aNumber ; i++ )
       
   587             {
       
   588             aTempDes.Append( KTab );
       
   589             }
       
   590         error = KErrNone;    
       
   591         }
       
   592     else
       
   593         {
       
   594         error = KErrNoMemory;
       
   595         }
       
   596 
       
   597     _LOG("CLogsUiControlExtension::AppendTrailingDelimiters end" )
       
   598     return error;    
       
   599     }
       
   600 
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // Determines the number of delimiters in the specified string
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 TInt CLogsUiControlExtension::DetermineNumberDelimiters( 
       
   607         const TDesC& aTempDes )
       
   608     {
       
   609     _LOG("CLogsUiControlExtension::DetermineNumberDelimiters begin" )     
       
   610 
       
   611     TInt result( 0 );    
       
   612     TPtrC buffer = aTempDes.Left( aTempDes.Length() );    
       
   613     TInt nextTokenStart( KErrNone );
       
   614     
       
   615     while ( buffer.Length() > 0 && nextTokenStart >= 0 )
       
   616         {            
       
   617         nextTokenStart = buffer.Find( KTab );
       
   618         if ( KErrNotFound != nextTokenStart )
       
   619             {
       
   620             result++;
       
   621             buffer.Set( buffer.Mid( nextTokenStart + 1 ));
       
   622             }
       
   623 
       
   624         }    
       
   625 
       
   626     _LOG("CLogsUiControlExtension::DetermineNumberDelimiters end" )     
       
   627     return result;
       
   628     }
       
   629 
       
   630 
       
   631 // ---------------------------------------------------------------------------
       
   632 // Callback function that is called by the fetcher objects after they have 
       
   633 // successfully retrieved the bitmaps of the icon.
       
   634 // ---------------------------------------------------------------------------
       
   635 //
       
   636 void CLogsUiControlExtension::BrandIconFetchDoneL( const TUint32 aServiceId,
       
   637                                                    RFile& aBitmapFile,
       
   638                                                    const TInt aBitmapId,   
       
   639                                                    const TInt aBitmapMaskId )
       
   640     {    
       
   641     _LOGP("CLogsUiControlExtension::BrandIconFetchDoneL begin %d",aServiceId )     
       
   642     
       
   643     // This is the fetcher-callback; handle the fetched data now:
       
   644     //    - take ownership of the file handle
       
   645     //    - create icon
       
   646     //    - add the data to the to the listbox's icon array (in AppIconL)
       
   647     //    - store the icon's index to the event info manager    
       
   648     
       
   649     // take ownership of file handle
       
   650     CleanupClosePushL( aBitmapFile );
       
   651     
       
   652     // File provider duplicates the file handle and close the original.
       
   653     // Duplication is needed because lifetime of image is different than
       
   654     // this plugin's file handle's.
       
   655     CLogsIconFileProvider* ifp = CLogsIconFileProvider::NewL( aBitmapFile );    
       
   656     _LOG("CLogsUiControlExtension::BrandIconFetchDoneL close bitmapfile" );
       
   657     CleanupStack::PopAndDestroy( &aBitmapFile );
       
   658     
       
   659     CFbsBitmap* bitmap = NULL;
       
   660     CFbsBitmap* bitmask = NULL;
       
   661     
       
   662     // create icons            
       
   663     AknIconUtils::CreateIconL ( bitmap,
       
   664                                 bitmask,
       
   665                                 *ifp,
       
   666                                 aBitmapId, 
       
   667                                 aBitmapMaskId );                                          
       
   668 
       
   669     // in case a new icon is added to the icon array of the listbox
       
   670     // 'indexOfAppendedIcon' will contain the index of the added icon
       
   671     // in the icon array
       
   672     TInt indexOfAppendedIcon( 0 );             
       
   673     
       
   674     // ownership of the bitmaps is transferred to AddIconL
       
   675     TRAPD( err, AddIconL( bitmap, bitmask, indexOfAppendedIcon ) );    
       
   676     bitmap = NULL;                              
       
   677     bitmask = NULL;
       
   678     
       
   679     if ( KErrNone == err && indexOfAppendedIcon >= 0 )
       
   680         {        
       
   681         // store index information into the event info manager
       
   682         err = SetBrandIndex( aServiceId, indexOfAppendedIcon );
       
   683         
       
   684         // if setting the index failed, the last icon that was added to the
       
   685         // icon array must be removed again
       
   686         if ( KErrNone != err )
       
   687             {
       
   688             CArrayPtr<CGulIcon>* iconList = 
       
   689                 iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   690             iconList->Delete( indexOfAppendedIcon );
       
   691             iconList->Compress();
       
   692             }        
       
   693         }
       
   694         
       
   695     if ( KErrNone == err )
       
   696         {
       
   697         NotifyObserverL(); // notify the observer (to update the view)
       
   698         }
       
   699     
       
   700     _LOG("CLogsUiControlExtension::BrandIconFetchDoneL end" )     
       
   701    
       
   702     }
       
   703     
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // Add the fetched icon to the listbox' icon array
       
   707 // Returns the index of the appended icon in the icon array.
       
   708 // ---------------------------------------------------------------------------
       
   709 //
       
   710 void CLogsUiControlExtension::AddIconL( CFbsBitmap* aBitmap, 
       
   711                                         CFbsBitmap* aBitmask,
       
   712                                         TInt& aIndex )
       
   713     {
       
   714     _LOG("CLogsUiControlExtension::AddIconL begin" )     
       
   715 
       
   716     // delete bitmaps before saving new bitmaps
       
   717     DeleteBitmaps();
       
   718     
       
   719     // take ownership of the bitmaps       
       
   720     iBitmap = aBitmap;      // Ownership here
       
   721     iBitmask = aBitmask;    // Ownership here
       
   722     CArrayPtr<CGulIcon>* iconList = 
       
   723         iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   724     User::LeaveIfNull( iconList );    
       
   725     iBitmap = NULL;     // ownership will be transferred to CGulIcon
       
   726     iBitmask = NULL;    // ownership will be transferred to CGulIcon
       
   727     CGulIcon* icon = CGulIcon::NewL( aBitmap, aBitmask );
       
   728     CleanupStack::PushL( icon );     
       
   729     iconList->AppendL( icon ); // iconList owns icon now
       
   730     CleanupStack::Pop( icon ); 
       
   731     
       
   732     aIndex = iconList->Count() - 1;
       
   733     _LOG("CLogsUiControlExtension::AddIconL end... ")
       
   734     _LOGP("...index of the appended icon in the icon array==%d",
       
   735         ( iconList->Count() - 1 ) )   
       
   736     }
       
   737     
       
   738 // ---------------------------------------------------------------------------
       
   739 // Sets the index of a brand icon.
       
   740 // ---------------------------------------------------------------------------
       
   741 //
       
   742 TInt CLogsUiControlExtension::SetBrandIndex( const TUint32 aServiceId, 
       
   743                                              const TInt aIndex )
       
   744     {
       
   745     _LOG("CLogsUiControlExtension::SetBrandIndex" )     
       
   746     
       
   747     return iLogEntryInfoManager->SetBrandIndex( aServiceId , aIndex );
       
   748     }
       
   749 
       
   750 
       
   751 // ---------------------------------------------------------------------------
       
   752 // Notifies the observer that an icon was added to the listbox's icon array.
       
   753 // ---------------------------------------------------------------------------
       
   754 //
       
   755 void CLogsUiControlExtension::NotifyObserverL()
       
   756     {
       
   757     _LOG("CLogsUiControlExtension::NotifyObserverL begin" )     
       
   758 
       
   759     iLogsExtObserver->ExtStateChangedL();
       
   760 
       
   761     _LOG("CLogsUiControlExtension::NotifyObserverL end" )     
       
   762     }
       
   763 
       
   764 
       
   765 // ---------------------------------------------------------------------------
       
   766 // Sets the index of a presence icon.
       
   767 // ---------------------------------------------------------------------------
       
   768 //
       
   769 TInt CLogsUiControlExtension::SetPresenceIndex( const TUint32 aServiceId, 
       
   770                                                 const TDesC& aPresenceStatus,
       
   771                                                 const TInt aIndex )
       
   772     {
       
   773     _LOG("CLogsUiControlExtension::SetPresenceIndex" )
       
   774     
       
   775     return iPresenceTableManager->SetIndexInIndexTable( aServiceId, 
       
   776                                                         aPresenceStatus, 
       
   777                                                         aIndex );
       
   778     }
       
   779 
       
   780 
       
   781    
       
   782 // ---------------------------------------------------------------------------
       
   783 // Deletes the icon bitmaps.
       
   784 // ---------------------------------------------------------------------------
       
   785 //   
       
   786 void CLogsUiControlExtension::DeleteBitmaps()
       
   787     {
       
   788     _LOG("CLogsUiControlExtension::DeleteBitmaps begin" )     
       
   789     delete iBitmap;
       
   790     delete iBitmask;
       
   791     iBitmap = NULL;
       
   792     iBitmask = NULL;
       
   793     _LOG("CLogsUiControlExtension::DeleteBitmaps end" )         
       
   794     }
       
   795 
       
   796 // ---------------------------------------------------------------------------
       
   797 // Checks if service handler exists already
       
   798 // ---------------------------------------------------------------------------
       
   799 //  
       
   800 TBool CLogsUiControlExtension::ServiceHandlerExists( const TUint32 aServiceId )
       
   801     {
       
   802     TBool handlerFound( EFalse ); 
       
   803     _LOG("CLogsUiControlExtension::ServiceHandlerExists begin" )     
       
   804     
       
   805     // check if there is already a fetcher for the brand    
       
   806     CLogsExtServiceHandler* serviceHandler = NULL;    
       
   807     if ( KErrNone == GetServiceHandler( aServiceId, serviceHandler ) )
       
   808         {
       
   809         handlerFound = ETrue;
       
   810         }
       
   811     
       
   812 #ifdef _DEBUG
       
   813     if ( handlerFound )
       
   814         {
       
   815         _LOG("CLogsUiControlExtension::ServiceHandlerExists YES" )
       
   816         }
       
   817     else
       
   818         {
       
   819         _LOG("CLogsUiControlExtension::ServiceHandlerExists NO" )
       
   820         }
       
   821 #endif
       
   822 
       
   823     _LOG("CLogsUiControlExtension::ServiceHandlerExists end" )         
       
   824     return handlerFound;    
       
   825     }
       
   826 
       
   827 
       
   828 // ---------------------------------------------------------------------------
       
   829 // Checks if brandfetcher exists already
       
   830 // ---------------------------------------------------------------------------
       
   831 //  
       
   832 TBool CLogsUiControlExtension::BrandFetcherExists( const TUint32 aServiceId )
       
   833     {
       
   834     TBool fetcherFound( EFalse ); 
       
   835     _LOG("CLogsUiControlExtension::BrandFetcherExists begin" )     
       
   836     // check if there is already a fetcher for the brand
       
   837     CLogsExtBrandFetcher* fetcher = NULL;
       
   838     
       
   839     for ( TInt i = 0; i < iBrandFetcherArray.Count() 
       
   840         && fetcherFound == EFalse; i++)
       
   841         {
       
   842         fetcher = iBrandFetcherArray[i];
       
   843         if ( aServiceId == fetcher->ServiceId() )
       
   844             {            
       
   845             fetcherFound = ETrue;    
       
   846             }
       
   847         }
       
   848 
       
   849 #ifdef _DEBUG
       
   850     if ( fetcherFound )
       
   851         {
       
   852         _LOG("CLogsUiControlExtension::BrandFetcherExists YES" )
       
   853         }
       
   854     else
       
   855         {
       
   856         _LOG("CLogsUiControlExtension::BrandFetcherExists NO" )
       
   857         }
       
   858 #endif
       
   859 
       
   860     _LOG("CLogsUiControlExtension::BrandFetcherExists end" )         
       
   861     return fetcherFound;    
       
   862     }
       
   863    
       
   864     
       
   865 // ---------------------------------------------------------------------------
       
   866 // Adds a single presentity to a service handler.
       
   867 // ---------------------------------------------------------------------------
       
   868 // 
       
   869 void CLogsUiControlExtension::AddPresentityToServiceHandlerL( 
       
   870         const TUint32 aServiceId, 
       
   871         const TDesC& aPresentityId )
       
   872     {
       
   873     _LOG("CLogsUiControlExtension::AddPresentityToServiceHandlerL begin" )
       
   874     
       
   875     CLogsExtServiceHandler* serviceHandler = NULL;
       
   876     TInt returnValue( GetServiceHandler( aServiceId, serviceHandler ) );
       
   877         
       
   878     if ( KErrNone == returnValue && serviceHandler )
       
   879             {
       
   880             TInt error( KErrNone );
       
   881             // add status entry to status table
       
   882             error = iPresenceTableManager->AddEntryToStatusTable(
       
   883                 aServiceId,
       
   884                 aPresentityId,
       
   885                 EFalse );
       
   886 
       
   887             if ( KErrNone == error )
       
   888                 {
       
   889                 // adds the presentity to the service handler;
       
   890                 // the service handler will start to observe the 
       
   891                 // status of this presentity and will inform the
       
   892                 // observer in case of status changes of the 
       
   893                 // presentity
       
   894                 serviceHandler->AddPresentityL( aPresentityId );
       
   895                 }
       
   896             }
       
   897         
       
   898     _LOG("CLogsUiControlExtension::AddPresentityToServiceHandlerL end" )
       
   899     }
       
   900  
       
   901             
       
   902 // ---------------------------------------------------------------------------
       
   903 // Creates and starts a single presentity id fetcher.
       
   904 // ---------------------------------------------------------------------------
       
   905 // 
       
   906 void CLogsUiControlExtension::DoPresentityIdFetcherCreationL( 
       
   907         const TUint32 aServiceId, 
       
   908         const TDesC8& aCntLink,
       
   909         const TLogId aLogId )
       
   910     {    
       
   911     _LOG("CLogsUiControlExtension::DoPresentityIdFetcherCreationL begin" )
       
   912     
       
   913     if ( aServiceId )
       
   914         {
       
   915         CLogsExtPresentityIdFetcher* presIdFetcher = 
       
   916             CLogsExtPresentityIdFetcher::NewLC( aServiceId, 
       
   917                                                 aCntLink, 
       
   918                                                 aLogId, 
       
   919                                                 *this );
       
   920                                                 
       
   921         _LOG("CLogsUiControlExtension::DoPresentityIdFetcherCreationL: ...")
       
   922         _LOGP("...presentity id fetcher created-> serviceid==%d ",aServiceId )
       
   923         iPresentityIdFetcherArray.AppendL( presIdFetcher );
       
   924         _LOG("CLogsUiControlExtension::DoPresentityIdFetcherCreationL:...")
       
   925         _LOGP("... #presIdFetcher=%d",iPresentityIdFetcherArray.Count() )
       
   926         CleanupStack::Pop( presIdFetcher );
       
   927         // start the fetcher
       
   928         presIdFetcher->Fetch();            
       
   929         }
       
   930     
       
   931     _LOG("CLogsUiControlExtension::DoPresentityIdFetcherCreationL end" )
       
   932     }
       
   933                         
       
   934 
       
   935 
       
   936 // ---------------------------------------------------------------------------
       
   937 // Callback for the presentity fetchers.
       
   938 // ---------------------------------------------------------------------------
       
   939 //  
       
   940 void CLogsUiControlExtension::PresentityIdFetchDoneL( 
       
   941         const TUint32 aServiceId, 
       
   942         const TDesC& aPresentityId,
       
   943         const TLogId aLogId )
       
   944     {
       
   945     _LOG("CLogsUiControlExtension::PresentityIdFetchDoneL begin" )
       
   946     
       
   947     AddLogIdToPresentityIdMappingL( aLogId, aPresentityId );
       
   948     
       
   949     // create service handler if it not already exists    
       
   950     CreateAndBindServiceHandlerL( aServiceId );
       
   951     
       
   952     // handle the callback from the presentity fetcher:
       
   953     // it only creates a new fetcher if there is not already one fetcher with
       
   954     // the same service id / presentityid    
       
   955     
       
   956     // find the correct service handler and add this presentity
       
   957     AddPresentityToServiceHandlerL( aServiceId, aPresentityId );    
       
   958     
       
   959     _LOG("CLogsUiControlExtension::PresentityIdFetchDoneL end" )    
       
   960     }
       
   961 
       
   962 
       
   963 // ---------------------------------------------------------------------------
       
   964 // Adds another mapping to the collection of mappings.
       
   965 // ---------------------------------------------------------------------------
       
   966 // 
       
   967 void CLogsUiControlExtension::AddLogIdToPresentityIdMappingL( 
       
   968         const TLogId aLogId,
       
   969         const TDesC& aPresentityId )
       
   970     {
       
   971     iPresenceTableManager->AddMappingL( aLogId, aPresentityId );
       
   972     NotifyObserverL();
       
   973     }
       
   974 
       
   975     
       
   976 // ---------------------------------------------------------------------------
       
   977 // Retrieves a presentity id using the specified log id.ownership is not 
       
   978 // transferred.
       
   979 // ---------------------------------------------------------------------------
       
   980 // 
       
   981 const TDesC* CLogsUiControlExtension::LookupPresentityId( 
       
   982         const TLogId aLogId )
       
   983     {   
       
   984     _LOGP("CLogsUiControlExtension::LookupPresentityId =%d",aLogId )
       
   985     return iPresenceTableManager->RetrievePresentityId( aLogId );
       
   986     }
       
   987 
       
   988 
       
   989 // ---------------------------------------------------------------------------
       
   990 // Resets the presentity id fetcher array and also deletes the objects whose
       
   991 // pointers are stored in the array. 
       
   992 // ---------------------------------------------------------------------------
       
   993 // 
       
   994 void CLogsUiControlExtension::ResetPresentityIdFetcherArray()
       
   995     {
       
   996     _LOG("CLogsUiControlExtension::ResetPresentityIdFetcherArray begin...") 
       
   997     _LOGP("...beforeDeletion=%d",iPresentityIdFetcherArray.Count() )            
       
   998 
       
   999     iPresentityIdFetcherArray.ResetAndDestroy();
       
  1000     
       
  1001     _LOG("CLogsUiControlExtension::ResetPresentityIdFetcherArray end...")
       
  1002     _LOGP("...afterDeletion=%d",iPresentityIdFetcherArray.Count() )            
       
  1003     }
       
  1004 
       
  1005 // ---------------------------------------------------------------------------
       
  1006 // Resets the presence status of all entries in the status table. 
       
  1007 // ---------------------------------------------------------------------------
       
  1008 // 
       
  1009 void CLogsUiControlExtension::ResetPresenceStatuses()
       
  1010     {
       
  1011     _LOG("CLogsUiControlExtension::ResetPresenceStatuses begin" )
       
  1012     
       
  1013     iPresenceTableManager->ResetStatusTableEntries();
       
  1014     
       
  1015     _LOG("CLogsUiControlExtension::ResetPresenceStatuses begin" )
       
  1016     }
       
  1017 
       
  1018 // ---------------------------------------------------------------------------
       
  1019 // Gets the service handler of the specified service.
       
  1020 // ---------------------------------------------------------------------------
       
  1021 //
       
  1022 TInt CLogsUiControlExtension::GetServiceHandler( 
       
  1023         TUint32 aServiceId, 
       
  1024         CLogsExtServiceHandler*& aServiceHandler )
       
  1025     {
       
  1026     _LOGP("CLogsUiControlExtension::GetServiceHandler begin : aServiceId=%d", 
       
  1027         aServiceId )
       
  1028     
       
  1029     TInt error( KErrNotFound );    
       
  1030     TBool handlerFound( EFalse );
       
  1031          
       
  1032     // check if there is already a fetcher for the brand
       
  1033     CLogsExtServiceHandler* handler = NULL;
       
  1034 
       
  1035     for ( TInt i = 0 ; i < iServiceHandlerArray.Count() && !handlerFound; i++ )
       
  1036         {
       
  1037         handler = iServiceHandlerArray[i];
       
  1038         if ( handler && aServiceId == handler->ServiceId() )
       
  1039             {            
       
  1040             handlerFound = ETrue;
       
  1041             aServiceHandler = handler;
       
  1042             error = KErrNone;
       
  1043             }
       
  1044         }
       
  1045 
       
  1046     error = handlerFound ? KErrNone : KErrNotFound;    
       
  1047     _LOGP("CLogsUiControlExtension::GetServiceHandler() error=%d",error )
       
  1048 
       
  1049     _LOG("CLogsUiControlExtension::GetServiceHandler end" )         
       
  1050     return error;
       
  1051     }
       
  1052 
       
  1053 // ---------------------------------------------------------------------------
       
  1054 // Handles the service handler's callback.
       
  1055 // ---------------------------------------------------------------------------
       
  1056 //
       
  1057 void CLogsUiControlExtension::HandlePresentityPresenceStatusL( 
       
  1058                                  const TUint32 aServiceId, 
       
  1059                                  const TDesC& aPresentityId,
       
  1060                                  const TDesC& aPresenceStatus,
       
  1061                                  TBool aShowStatus )
       
  1062     {
       
  1063     _LOG("CLogsUiControlExtension::HandlePresentityPresenceStatusL begin" )
       
  1064     
       
  1065 
       
  1066     TInt error( KErrNone );    
       
  1067     // 1. find <serviceId,presentityId> entry in the status table and set the 
       
  1068     //    status entry (that was retrieved by the presence fetcher earlier)
       
  1069     error = 
       
  1070         iPresenceTableManager->SetStatusInStatusTable( aServiceId, 
       
  1071                                                        aPresentityId, 
       
  1072                                                        aPresenceStatus,
       
  1073                                                        aShowStatus );
       
  1074     if( KErrNone == error )
       
  1075         {
       
  1076         // 2. check whether the presence icon index for 
       
  1077         // <serviceId,PresenceStatus> entry from index table is already
       
  1078         // available
       
  1079         TInt presenceIndex ( KErrNotFound );        
       
  1080         const TInt indexRetrievalErrorCode = 
       
  1081             iPresenceTableManager->GetIndexFromIndexTable( aServiceId, 
       
  1082                                                            aPresenceStatus,
       
  1083                                                            presenceIndex );
       
  1084         
       
  1085         //case 0: ( KErrNone == indexRetrievalErrorCode ) && 
       
  1086         //        ( presenceIndex >= 0 )
       
  1087         // -> nothing to do in this case (the icon was added already earlier
       
  1088         //    and the index information was already stored to the index table)
       
  1089         
       
  1090         //case 1: ( KErrNone == indexRetrievalErrorCode && 
       
  1091         //          presenceIndex == KErrNotFound )
       
  1092         //the index entry was found, but the index value in still unchanged.
       
  1093         //needed actions: create icons, add icons to icon list array,determine
       
  1094         //index of the added icon in the icon array,update the index entry in
       
  1095         //the index table
       
  1096     
       
  1097         //case 2: ( KErrNone != indexRetrievalErrorCode )
       
  1098         //the index entry was NOT found at all.
       
  1099         //needed actions: create icons, add icons to icon list array,determine
       
  1100         //index of the added icon in the icon array,CREATE an index entry in 
       
  1101         // the index table,and update the index entry in the index table
       
  1102                         
       
  1103         if ( ( KErrNone == indexRetrievalErrorCode && 
       
  1104                presenceIndex == KErrNotFound ) ||      // case 1
       
  1105              ( KErrNone != indexRetrievalErrorCode ) ) // case 2
       
  1106             {
       
  1107             //get the filehandle and the bitmapIds
       
  1108             RFile bitmapFile;
       
  1109             TInt bitmapId;   
       
  1110             TInt bitmapMaskId;
       
  1111             
       
  1112             FetchBitmapsFromBrandingServerL( aServiceId,
       
  1113                                              aPresenceStatus,
       
  1114                                              bitmapFile,
       
  1115                                              bitmapId,
       
  1116                                              bitmapMaskId );
       
  1117             
       
  1118             // take ownership of the filehandle
       
  1119             CleanupClosePushL( bitmapFile );
       
  1120             _LOG("CLogsUiControlExtension::HandlePresentityPresenceStatusL..")
       
  1121             _LOG("...bitmapFile to cleanupstack" )
       
  1122             
       
  1123             // File provider duplicates the file handle, close the original.
       
  1124             // Duplication is needed because lifetime of image is different 
       
  1125             // than this plugin's file handle's.
       
  1126             CLogsIconFileProvider* ifp = 
       
  1127                 CLogsIconFileProvider::NewL( bitmapFile );
       
  1128             CFbsBitmap* bitmap;
       
  1129             bitmap = NULL;
       
  1130             CFbsBitmap* bitmask;
       
  1131             bitmask = NULL;
       
  1132             
       
  1133             // create icons            
       
  1134             AknIconUtils::CreateIconL ( bitmap,
       
  1135                                         bitmask,
       
  1136                                         *ifp,
       
  1137                                         bitmapId, 
       
  1138                                         bitmapMaskId );
       
  1139     
       
  1140             error = KErrNone;
       
  1141             // in case a new icon is added to the icon array of the listbox
       
  1142             // 'indexOfAppendedIcon' will contain the index of the added icon
       
  1143             // in the icon array
       
  1144             TInt indexOfAppendedIcon( 0 );
       
  1145             
       
  1146             // if AddIconL returns with KErrNone the ownership of the bitmaps
       
  1147             // was successfully transferred
       
  1148             TRAP( error, AddIconL( bitmap, bitmask, indexOfAppendedIcon ) );
       
  1149             bitmap = NULL;
       
  1150             bitmask = NULL;
       
  1151             _LOGP("CLogsUiControlExtension::AddIconL returns==%d",
       
  1152                 error )
       
  1153             
       
  1154             TBool errorAfterIconAddition( EFalse );
       
  1155             
       
  1156             if ( KErrNone == error && KErrNone != indexRetrievalErrorCode )
       
  1157                 {
       
  1158                 // create the missing index entry for case 2
       
  1159                 error = 
       
  1160                     iPresenceTableManager->AddEntryToIndexTable( 
       
  1161                         aServiceId, 
       
  1162                         aPresenceStatus );
       
  1163                 errorAfterIconAddition = 
       
  1164                     ( KErrNone == error || KErrAlreadyExists == error ) ? 
       
  1165                         EFalse : ETrue;
       
  1166                 }
       
  1167             
       
  1168             TInt numberIcons ( indexOfAppendedIcon + 1 );
       
  1169             // update the index entry
       
  1170             if ( KErrNone == error )
       
  1171                 {                
       
  1172                 // store index information into the presence table manager
       
  1173                 error = SetPresenceIndex( aServiceId,
       
  1174                                           aPresenceStatus,
       
  1175                                           indexOfAppendedIcon );
       
  1176                 errorAfterIconAddition = ( KErrNone == error ) ? EFalse:ETrue;
       
  1177                 }
       
  1178             
       
  1179             // if setting the index failed, the last icon that was added to 
       
  1180             // the icon array must be removed again
       
  1181             if ( errorAfterIconAddition && numberIcons > 0 )
       
  1182                 {
       
  1183                 CArrayPtr<CGulIcon>* iconList = 
       
  1184                     iListBox->ItemDrawer()->ColumnData()->IconArray();
       
  1185                 iconList->Delete( indexOfAppendedIcon );
       
  1186                 iconList->Compress();
       
  1187                 }
       
  1188                             
       
  1189             if ( KErrNone == error )
       
  1190                 {
       
  1191                 NotifyObserverL(); // notify the observer (to update the view)
       
  1192                 }
       
  1193 
       
  1194             _LOG("CLogsUiControlExtension::HandlePresentityPresenceStatusL...")
       
  1195             _LOG("...close bitmapfile" )
       
  1196             
       
  1197             CleanupStack::PopAndDestroy( &bitmapFile );
       
  1198             
       
  1199             }
       
  1200         else if ( ( KErrNone == indexRetrievalErrorCode ) && 
       
  1201                   ( presenceIndex >= 0 ) ) // case 0
       
  1202             {
       
  1203             NotifyObserverL(); // notify the observer (to update the view)
       
  1204             }     
       
  1205         }
       
  1206     
       
  1207     _LOG("CLogsUiControlExtension::HandlePresentityPresenceStatusL end" )
       
  1208     }
       
  1209 
       
  1210 // ---------------------------------------------------------------------------
       
  1211 // This function is used to notify the observer of a service handler
       
  1212 // if the presence status of a certain presentity should be displayed
       
  1213 // or not.
       
  1214 // ---------------------------------------------------------------------------
       
  1215 //
       
  1216 void CLogsUiControlExtension::SetDisplayStatusFlag( 
       
  1217         const TUint32 aServiceId, 
       
  1218         const TDesC& aPresentityId,
       
  1219         TBool aDisplayStatus )
       
  1220     {
       
  1221     _LOG("CLogsUiControlExtension::SetDisplayStatusFlag begin" )
       
  1222     
       
  1223     _LOGP("CLogsUiControlExtension::SetDisplayStatusFlag : aServiceId=%d ",
       
  1224             aServiceId)
       
  1225     
       
  1226     _LOGP("CLogsUiControlExtension::SetDisplayStatusFlag : aPresentityId=%S",
       
  1227             &aPresentityId )
       
  1228     
       
  1229     TInt error = 
       
  1230         iPresenceTableManager->UpdateStatusTableEntry( aServiceId, 
       
  1231                                                       aPresentityId,
       
  1232                                                       aDisplayStatus );
       
  1233     
       
  1234     _LOG("CLogsUiControlExtension::SetDisplayStatusFlag : ...")
       
  1235     _LOGP("...UpdateStatusTableEntry error = %d ", error )
       
  1236     
       
  1237     //refresh the view, to make changes visible
       
  1238     if ( KErrNone == error )
       
  1239         {
       
  1240         TRAP_IGNORE( NotifyObserverL(); );
       
  1241         }
       
  1242     
       
  1243     _LOG("CLogsUiControlExtension::SetDisplayStatusFlag end" )
       
  1244     }
       
  1245 
       
  1246 // ---------------------------------------------------------------------------
       
  1247 // Get the icon bitmaps from the branding server.
       
  1248 // ---------------------------------------------------------------------------
       
  1249 //
       
  1250 void CLogsUiControlExtension::FetchBitmapsFromBrandingServerL( 
       
  1251         const TUint aServiceId,
       
  1252         const TDesC& aPresenceStatus,
       
  1253         RFile& aBitmapFile,
       
  1254         TInt& aBitmapId,
       
  1255         TInt& aBitmapMaskId )
       
  1256     {
       
  1257     _LOG("CLogsUiControlExtension::FetchBitmapsFromBrandingServerL(): begin" )
       
  1258     
       
  1259     // create the elementId string; e.g.: "person:offline:image"  
       
  1260     HBufC* elementId = HBufC::NewLC( KPersonPresTmpl().Length() + 
       
  1261                                      aPresenceStatus.Length() );            
       
  1262     TPtr ptr( elementId->Des() );    
       
  1263     ptr.AppendFormat( KPersonPresTmpl(), &aPresenceStatus );
       
  1264     _LOG( "CLogsUiControlExtension::FetchBitmapsFromBrandingServerL():...")
       
  1265     _LOGP("...elementId string=%S", elementId )
       
  1266     
       
  1267     HBufC8* elementId8 = HBufC8::NewLC( ptr.Length() );
       
  1268     TPtr8 elementIdPtr8( elementId8->Des() );
       
  1269     elementIdPtr8.Copy( ptr );
       
  1270     
       
  1271     _LOG("CLogsUiControlExtension::FetchBitmapsFromBrandingServerL(): ...")
       
  1272     _LOGP("...elementId=%S", &ptr )
       
  1273     
       
  1274     CleanupClosePushL( aBitmapFile );        
       
  1275     TLogsExtUtil::GetFileHandleL( aServiceId, 
       
  1276                                   elementIdPtr8, 
       
  1277                                   aBitmapFile, 
       
  1278                                   aBitmapId, 
       
  1279                                   aBitmapMaskId );    
       
  1280     CleanupStack::Pop( &aBitmapFile );
       
  1281 
       
  1282     CleanupStack::PopAndDestroy( elementId8 );
       
  1283     elementId8 = NULL;
       
  1284     CleanupStack::PopAndDestroy( elementId );
       
  1285     elementId = NULL;
       
  1286 
       
  1287     _LOG("CLogsUiControlExtension::FetchBitmapsFromBrandingServerL() end" )
       
  1288     }
       
  1289 
       
  1290 
       
  1291 // End of File