messagingappbase/schemeplugin/src/BaseHandler.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004 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:  
       
    15 *      Implementation of Scheme handler base class
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "BaseHandler.h"
       
    24 #include "SchemeDispLogger.h"
       
    25 #include <e32base.h>
       
    26 #include <AknQueryDialog.h>
       
    27 #include <StringLoader.h>
       
    28 #include <bautils.h>
       
    29 #include <escapeutils.h>
       
    30 #include <apparc.h>
       
    31 #include <apgcli.h>
       
    32 #include <s32mem.h>
       
    33 #include <CMessageData.h>
       
    34 #include <AknServerApp.h>
       
    35 
       
    36 // ================= CONSTANTS =======================
       
    37 LOCAL_D const TUid KUidSchemeApp = { SCHEME_APP_UID };
       
    38 
       
    39 // ================= MEMBER FUNCTIONS =======================
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CBaseHandler::CBaseHandler()
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 CBaseHandler::CBaseHandler() : CSchemeHandler()
       
    47 	{
       
    48 	iSchemeDoc = NULL;
       
    49 	}
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CCtiHandler::~CCtiHandler()
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 CBaseHandler::~CBaseHandler()
       
    56 	{
       
    57 	delete iParsedUrl;
       
    58 	}
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CBaseHandler::ConstructL()
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 void CBaseHandler::BaseConstructL( const TDesC& aUrl )
       
    66 	{
       
    67 	CLOG_ENTERFN( "CBaseHandler::BaseConstructL()" );
       
    68 
       
    69 	iParsedUrl = EscapeUtils::EscapeDecodeL( aUrl );
       
    70 
       
    71 	CLOG_LEAVEFN( "CBaseHandler::BaseConstructL()" );
       
    72 	}
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CBaseHandler::Observer()
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 void CBaseHandler::Observer( MAknServerAppExitObserver* aSchemeDoc )
       
    79 	{
       
    80 	iSchemeDoc = aSchemeDoc;
       
    81 	}
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CBaseHandler::NotifyClient()
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void CBaseHandler::NotifyClient()
       
    88 	{
       
    89 	if( NULL !=iSchemeDoc )
       
    90 		{
       
    91         iSchemeDoc->HandleServerAppExit( KErrNone );
       
    92 		}
       
    93 	}
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CBaseHandler::SeparateAndAppendToAddressL
       
    97 // ---------------------------------------------------------
       
    98 //    
       
    99 void CBaseHandler::SeparateAndAppendAddressL(
       
   100 	const TDesC& aSeparator, 
       
   101 	const TDesC& aString, 
       
   102 	CMessageData& aMessageData,
       
   103 	const TInt aRecipientType ) const
       
   104 	{
       
   105 	if ( aString.Length() == 0 )
       
   106         {
       
   107         return;
       
   108         }
       
   109     TInt endPos = 0;
       
   110     TInt startPos = 0;
       
   111     TInt tmp = 0;
       
   112     TInt tmp2 = 0;
       
   113     TInt length = aString.Length();
       
   114     TInt len = 0;
       
   115     while ( endPos < length )
       
   116         {
       
   117         tmp = aString.Right( length - endPos).FindF( aSeparator );
       
   118         if ( tmp > 0 )
       
   119             {
       
   120             endPos += tmp;
       
   121             }
       
   122         else // tmp == KErrNotFound
       
   123             {
       
   124             endPos = aString.Length();
       
   125             }
       
   126         tmp = startPos;
       
   127         tmp2 = endPos - 1;
       
   128         // remove spaces from the start         
       
   129         while ( aString[tmp] == ' ' && tmp < endPos )
       
   130             {
       
   131             ++tmp;
       
   132             }
       
   133         // remove spaces from the end
       
   134         while ( aString[tmp2] == ' ' && tmp2 > startPos )
       
   135             {
       
   136             --tmp2;
       
   137             }
       
   138         len = tmp2 - tmp + 1;
       
   139         // Append item to array without spaces
       
   140         switch( aRecipientType )
       
   141         	{
       
   142         	case KCcRecipient: aMessageData.AppendCcAddressL( aString.Mid( tmp, len ) );break;
       
   143         	default:; // fall through
       
   144         	case KToRecipient: aMessageData.AppendToAddressL( aString.Mid( tmp, len ) );break;
       
   145         	}
       
   146         
       
   147         ++endPos;
       
   148         startPos = endPos;
       
   149         }    
       
   150 	}   
       
   151 
       
   152 // ---------------------------------------------------------
       
   153 // CBaseHandler::Minimum()
       
   154 // ---------------------------------------------------------
       
   155 //
       
   156 TInt CBaseHandler::Minimum( RArray<TInt>& aArray ) const
       
   157     {
       
   158     // Sort array.
       
   159     aArray.Sort();
       
   160     // Return smallest
       
   161     return aArray[0];
       
   162     }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------
       
   166 // CBaseHandler::LaunchSchemeAppWithCommandLineL
       
   167 // ---------------------------------------------------------
       
   168 //
       
   169 void CBaseHandler::LaunchSchemeAppWithCommandLineL()
       
   170     {
       
   171     // Try launching...
       
   172     RApaLsSession   appArcSession;
       
   173     User::LeaveIfError( appArcSession.Connect() );
       
   174     CleanupClosePushL<RApaLsSession>( appArcSession );
       
   175     TThreadId dummyId;
       
   176 
       
   177     TApaAppInfo appInfo;
       
   178     appArcSession.GetAppInfo( appInfo, KUidSchemeApp );
       
   179 
       
   180     CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   181     #if (defined(SYMBIAN_SUPPORT_UI_FRAMEWORKS_V1) || defined(__SERIES60_27__) || defined(__SERIES60_28__)) 
       
   182     cmdLine->SetLibraryNameL(appInfo.iFullName);
       
   183     #else
       
   184     cmdLine->SetExecutableNameL(appInfo.iFullName);
       
   185     #endif
       
   186     cmdLine->SetDocumentNameL( *iParsedUrl );
       
   187     cmdLine->SetCommandL( EApaCommandCreate );
       
   188 
       
   189     // Get the whole parameter list and put to the command line
       
   190     if ( iParamList )
       
   191         {
       
   192         TInt size = iParamList->Size();
       
   193         CBufFlat* store = CBufFlat::NewL( size );
       
   194         CleanupStack::PushL( store );
       
   195 	    RBufWriteStream outStream;
       
   196 		outStream.Open( *store );
       
   197         CleanupClosePushL<RBufWriteStream>( outStream );
       
   198 		iParamList->ExternalizeL( outStream );
       
   199         cmdLine->SetTailEndL( store->Ptr( 0 ) );
       
   200         CleanupStack::PopAndDestroy( 2 );  // store, close outStream
       
   201         }
       
   202 
       
   203     User::LeaveIfError( appArcSession.StartApp( *cmdLine,dummyId) );
       
   204     CLOG_WRITE( "Launched SchemeApp succesfully" )
       
   205   
       
   206     CleanupStack::PopAndDestroy( 2 ); // close appArcSession, cmdLine
       
   207     }
       
   208 
       
   209 // End of file