imstutils/imconversationview/imcvuiapp/src/cimcvappmessageextensionshandler.cpp
branchRCL_3
changeset 29 9a48e301e94b
parent 0 5e5d6b214f4f
equal deleted inserted replaced
28:3104fc151679 29:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  message extention class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cimcvappmessageextensionshandler.h"
       
    20 #include "cimcvenginefactory.h"
       
    21 #include <eikrted.h>
       
    22 #include <txtrich.h>
       
    23 #include "imcvlogger.h"
       
    24 #include "cimcvappsmileyutil.h"
       
    25 #include "imcvuiliterals.h"
       
    26 #include "cimcvengine.h"
       
    27 
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CIMCVAppMessageExtensionsHandler::CIMCVAppMessageExtensionsHandler
       
    31 // Constructor
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CIMCVAppMessageExtensionsHandler::CIMCVAppMessageExtensionsHandler( MIMCVUiAppSkinVariant& aSkinVariant, 
       
    35                                                                     MIMCVAppUi& aAppUi,
       
    36                                                                     MIMCVEngineFactory& aEngineFactory )
       
    37     :iSkinVariant( aSkinVariant ),
       
    38     iAppUi( aAppUi ),
       
    39     iEngineFactory( aEngineFactory )
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CIMCVAppMessageExtensionsHandler::~CIMCVAppMessageExtensionsHandler
       
    45 // Destructor
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CIMCVAppMessageExtensionsHandler::~CIMCVAppMessageExtensionsHandler()
       
    49     {
       
    50     iExtensionArray.ResetAndDestroy();
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CIMCVAppMessageExtensionsHandler::NewL
       
    55 // Symbian two phased constructor
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CIMCVAppMessageExtensionsHandler* CIMCVAppMessageExtensionsHandler::NewL(
       
    59                                 MIMCVUiAppSkinVariant& aSkinVariant,
       
    60                                 MIMCVAppUi& aAppUi,
       
    61                                 MIMCVEngineFactory& aEngineFactory,
       
    62                                 TBool /*aAddSmileyHandler = ETrue */)
       
    63     {
       
    64     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::CIMCVAppMessageExtensionsHandler()    start" ));
       
    65     CIMCVAppMessageExtensionsHandler* self = 
       
    66                 new ( ELeave ) CIMCVAppMessageExtensionsHandler(aSkinVariant,aAppUi,aEngineFactory);
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::CIMCVAppMessageExtensionsHandler()    end" ));
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CIMCVAppMessageExtensionsHandler::ConstructL
       
    76 // Symbian OS Constructor
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CIMCVAppMessageExtensionsHandler::ConstructL()
       
    80     {
       
    81     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConstructL()	start" ));
       
    82     //get the count of number of services
       
    83     RPointerArray<CIMCVEngine>& serviceEngines = iEngineFactory.GetServiceEngines();
       
    84     for(TInt i=0; i<serviceEngines.Count() ; i++)
       
    85         {
       
    86         CIMCVAppSmileyUtil* smiley = CIMCVAppSmileyUtil::NewL(iSkinVariant, iAppUi, EMessageExtensionSmiley, *serviceEngines[i] );
       
    87         CleanupStack::PushL( smiley );
       
    88         User::LeaveIfError( iExtensionArray.Append( smiley ));
       
    89         CleanupStack::Pop( smiley ); 
       
    90         } 
       
    91    IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConstructL()	end" ));
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CIMCVAppMessageExtensionsHandler::CreateServiceSmileyL
       
    96 // Symbian OS Constructor
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CIMCVAppMessageExtensionsHandler::CreateServiceSmileyL( TInt aServiceId )
       
   100     {
       
   101     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::HandleNewServiceL()  start" ));
       
   102     TInt error = KErrNone;
       
   103     CIMCVEngine& engine = iEngineFactory.GetServiceEngineL( aServiceId );
       
   104     //get the count of number of services
       
   105     TInt count = iExtensionArray.Count();
       
   106     for(TInt i=0; i<count ; i++)
       
   107         {
       
   108         if( iExtensionArray[i]->ServiceId() == aServiceId )
       
   109             {
       
   110 			IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::CREATE SERVICE SMILEY ALREADY EXISTS" ));
       
   111 			error = KErrAlreadyExists;
       
   112             break;
       
   113             }
       
   114         }
       
   115     if( error == KErrNone )
       
   116         {
       
   117         CIMCVAppSmileyUtil* smiley = CIMCVAppSmileyUtil::NewL(iSkinVariant, iAppUi, EMessageExtensionSmiley, engine );
       
   118         CleanupStack::PushL( smiley );
       
   119         User::LeaveIfError( iExtensionArray.Append( smiley ));
       
   120         CleanupStack::Pop( smiley ); 
       
   121         }
       
   122     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::HandleNewServiceL()  end" ));
       
   123     }
       
   124 // -----------------------------------------------------------------------------
       
   125 // CIMCVAppMessageExtensionsHandler::DeleteServiceSmileyL
       
   126 // Symbian OS Constructor
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CIMCVAppMessageExtensionsHandler::DeleteServiceSmileyL( TInt aServiceId )
       
   130     {
       
   131     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::HandleServiceDeletedL()  start" ));
       
   132     TInt count = iExtensionArray.Count();
       
   133     for(TInt i=0; i<count ; i++)
       
   134         {
       
   135         if( iExtensionArray[i]->ServiceId() == aServiceId )
       
   136             {
       
   137 			IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::DELET SMILEY SERVICES" ));
       
   138             MIMCVAppMessageExtension* smiley = iExtensionArray[ i ];
       
   139             iExtensionArray.Remove( i );
       
   140             delete smiley;
       
   141             smiley = NULL;
       
   142             iExtensionArray.Compress();
       
   143             break;
       
   144             }
       
   145         }
       
   146     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::HandleServiceDeletedL()  end" ));
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CIMCVAppMessageExtensionsHandler::ProcessMessageLC
       
   151 // Process messages trough extensions.
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 HBufC* CIMCVAppMessageExtensionsHandler::ProcessMessageLC( 
       
   155                                             CEikRichTextEditor& aEditor,
       
   156                                             TInt aServiceId )
       
   157     {
       
   158     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ProcessMessageLC()	start" ));
       
   159     HBufC* msg = ExtensionToStringLC( aEditor, aServiceId );
       
   160     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   161         {
       
   162         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   163             {
       
   164             iExtensionArray[ a ]->Reset( );
       
   165             break;
       
   166             }
       
   167         }
       
   168     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ProcessMessageLC()	end" ));
       
   169     return msg;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CIMCVAppMessageExtensionsHandler::ExtensionToStringL
       
   174 // Convert extensions to strings.
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 HBufC* CIMCVAppMessageExtensionsHandler::ExtensionToStringLC( 
       
   178                                             CEikRichTextEditor& aEditor,
       
   179                                             TInt aServiceId )
       
   180     {
       
   181     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ExtensionToStringLC()	start" ));
       
   182     HBufC* text = HBufC::NewMaxLC(KDefaultMsgLength );
       
   183     TPtr tBuf( text->Des() );
       
   184 
       
   185     HBufC* msgBuf = aEditor.GetTextInHBufL();
       
   186     if(!msgBuf)
       
   187         {
       
   188         tBuf.Zero();
       
   189         return text;	
       
   190         }
       
   191     CleanupStack::PushL( msgBuf );
       
   192     TPtr msgPtr( msgBuf->Des() );
       
   193    
       
   194     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   195         {
       
   196         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   197             {
       
   198             tBuf = msgPtr;
       
   199             iExtensionArray[ a ]->ExtensionToStringL( aEditor, tBuf );
       
   200             CleanupStack::PopAndDestroy( msgBuf );
       
   201             msgBuf = NULL;
       
   202             msgBuf = tBuf.AllocLC();
       
   203             TPtr newPtr( msgBuf->Des() );
       
   204             msgPtr.Set( newPtr );
       
   205             break;
       
   206             }       
       
   207         }
       
   208     
       
   209     // Remove all CEditableText::EZeroWidthNoBreakSpace characters
       
   210     // which are used to go around CRichText editor bug
       
   211     // when msg contains only smiley pictures
       
   212     // These rows below can be removed when CRichText editor
       
   213     // don't need anyrmore this "hack"
       
   214     tBuf = msgPtr;
       
   215 
       
   216     TInt length = tBuf.Length();
       
   217 	for( TInt i = length-1; i >=0 ; --i )
       
   218 		{
       
   219 		if( tBuf[ i ] ==  CEditableText::EZeroWidthNoBreakSpace )
       
   220 			{
       
   221 			tBuf.Delete( i, 1 ); // removing 1 character
       
   222 			}
       
   223 		}
       
   224     CleanupStack::PopAndDestroy( msgBuf );
       
   225     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ExtensionToStringLC()	end" ));
       
   226     return text;
       
   227     }
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CIMCVAppMessageExtensionsHandler::DeleteExtensionIcon
       
   232 // Find right extension handler and delete extension
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CIMCVAppMessageExtensionsHandler::DeleteExtensionL( CEikRichTextEditor& aEditor,
       
   236         TInt aServiceId ,
       
   237         TMessageExtensionTypes /*aType*/,
       
   238         TInt aPos )
       
   239     {
       
   240     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::DeleteExtensionL()	start" ));
       
   241     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   242         {
       
   243         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   244             {
       
   245             iExtensionArray[ a ]->DeleteExtensionL( aEditor, aPos );
       
   246             break;
       
   247             }
       
   248         }
       
   249     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::DeleteExtensionL()	end" ));
       
   250 	}
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL
       
   254 // Convert all extensions from strings to extensions in area.
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL( 
       
   258                                                 CEikRichTextEditor& aEditor,
       
   259                                                 TInt aServiceId )
       
   260     {
       
   261     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL()	start" ));
       
   262     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   263         {
       
   264         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   265             {
       
   266             iExtensionArray[ a ]->ConvertSelectionToExtensionL( aEditor );
       
   267             break;
       
   268             }
       
   269         }
       
   270     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL()	end" ));
       
   271     }
       
   272     
       
   273 // -----------------------------------------------------------------------------
       
   274 // CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL
       
   275 // Convert all extensions from strings to extensions in area.
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL( 
       
   279                        CRichText& aRichText, 
       
   280                        TCursorSelection& aSelection,
       
   281                        TInt aServiceId )
       
   282     {
       
   283     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL()	start" ));
       
   284     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   285         {
       
   286         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   287             {
       
   288             iExtensionArray[ a ]->ConvertSelectionToExtensionL( aRichText, aSelection );
       
   289             break;
       
   290             }
       
   291         }
       
   292     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToExtensionL()	end" ));
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL
       
   297 // Convert all extensions from extensions to strings in area.
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL( 
       
   301                     CEikRichTextEditor& aEditor, 
       
   302                     TInt aServiceId,
       
   303                     TBool aPreserve /*= EFalse*/ )
       
   304     {
       
   305     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL()	start" ));
       
   306     
       
   307     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   308         {
       
   309         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   310             {
       
   311             iExtensionArray[ a ]->ConvertSelectionToStringL( aEditor, aPreserve );
       
   312             break;
       
   313             }
       
   314         }
       
   315     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL()	end" ));
       
   316     }
       
   317 
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CIMCVAppMessageExtensionsHandler::SizeChanged
       
   321 // Convert all extensions from extensions to strings in area.
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CIMCVAppMessageExtensionsHandler::SizeChanged( TSize& aSize,
       
   325         TInt aServiceId )
       
   326     {
       
   327     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::SizeChanged()	start" ));
       
   328    
       
   329     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   330         {
       
   331         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   332             {
       
   333             iExtensionArray[ a ]->SizeChanged( aSize );
       
   334             break;
       
   335             }
       
   336         }
       
   337     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::SizeChanged()	end" ));
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL
       
   342 // Convert all extensions from extensions to strings in area.
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL(
       
   346     CEikRichTextEditor& aEditor,
       
   347     TInt aServiceId ,
       
   348     TDes& aResultString,
       
   349     TCursorSelection& aSelectionAfterConversion,
       
   350     TBool aPreserve )
       
   351     {
       
   352     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL()	start" ));
       
   353     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   354         {
       
   355         if( aServiceId == iExtensionArray[a]->ServiceId() )
       
   356             {
       
   357             iExtensionArray[ a ]->ConvertSelectionToStringL(
       
   358                     aEditor, aResultString, aSelectionAfterConversion, aPreserve );
       
   359             break;
       
   360             }
       
   361         }
       
   362     IM_CV_LOGS(TXT("CIMCVAppMessageExtensionsHandler::ConvertSelectionToStringL()	end" ));
       
   363     }
       
   364     
       
   365 // -----------------------------------------------------------------------------
       
   366 // CIMCVAppMessageExtensionsHandler::InsertExtensionIcon
       
   367 // Find right extension handler and insert extension
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 void CIMCVAppMessageExtensionsHandler::InsertExtensionL( CEikRichTextEditor& aEditor,
       
   371                                                     TInt aServiceId ,
       
   372                                                     TMessageExtensionTypes aType,                                                    
       
   373                                                     TBool& aCancelled,
       
   374                                                     TSize size)
       
   375     {
       
   376     for( TInt a( 0 ); a < iExtensionArray.Count(); ++a )
       
   377         {
       
   378         if( aType == iExtensionArray[ a ]->Type() && aServiceId == iExtensionArray[a]->ServiceId() )
       
   379             {
       
   380             iExtensionArray[ a ]->InsertExtensionL( aEditor, aCancelled, size );
       
   381             break;
       
   382             }
       
   383         }
       
   384     }
       
   385     
       
   386 // end of file