|         |      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 interface implementation  | 
|         |     16 *      for mmsto: scheme | 
|         |     17 * | 
|         |     18 */ | 
|         |     19  | 
|         |     20  | 
|         |     21  | 
|         |     22 // INCLUDE FILES | 
|         |     23  | 
|         |     24 #include "MmsToHandler.h" | 
|         |     25 #include "SchemeDefs.h" | 
|         |     26 #include "SchemeDispLogger.h" | 
|         |     27 #include "LocalAppHandler.h" | 
|         |     28 #include <ecom.h>		// For REComSession | 
|         |     29 #include <apgcli.h> | 
|         |     30 #include <apparc.h> | 
|         |     31 #include <eikdoc.h> | 
|         |     32 #include <eikproc.h> | 
|         |     33 #include <f32file.h> | 
|         |     34 #include <s32file.h> // RFileWriteStream | 
|         |     35 #include <sendui.h> // CSendUi | 
|         |     36 #include <SenduiMtmUids.h>  | 
|         |     37 #include <txtrich.h> | 
|         |     38 #include <CMessageData.h> | 
|         |     39  | 
|         |     40  | 
|         |     41 // ================= CONSTANTS ======================= | 
|         |     42  | 
|         |     43     | 
|         |     44  | 
|         |     45 // ================= MEMBER FUNCTIONS ======================= | 
|         |     46  | 
|         |     47 // --------------------------------------------------------- | 
|         |     48 // CMmsToHandler::NewL() | 
|         |     49 // --------------------------------------------------------- | 
|         |     50 // | 
|         |     51 CMmsToHandler* CMmsToHandler::NewL( const TDesC& aUrl ) | 
|         |     52 	{ | 
|         |     53 	CLOG_ENTERFN( "CMmsToHandler::NewL()" ); | 
|         |     54  | 
|         |     55 	CMmsToHandler* self = new( ELeave ) CMmsToHandler(); | 
|         |     56 	CleanupStack::PushL( self ); | 
|         |     57 	self->ConstructL( aUrl ); | 
|         |     58 	CleanupStack::Pop( self ); | 
|         |     59  | 
|         |     60 	CLOG_LEAVEFN( "CMmsToHandler::NewL()" ); | 
|         |     61  | 
|         |     62 	return self; | 
|         |     63 	} | 
|         |     64  | 
|         |     65 // --------------------------------------------------------- | 
|         |     66 // CMmsToHandler::~CMmsToHandler() | 
|         |     67 // --------------------------------------------------------- | 
|         |     68 // | 
|         |     69 CMmsToHandler::~CMmsToHandler() | 
|         |     70 	{ | 
|         |     71 	CLOG_ENTERFN( "CMmsToHandler::~CMmsToHandler()" ); | 
|         |     72  | 
|         |     73     delete iSendUi; | 
|         |     74     iFs.Close(); | 
|         |     75  | 
|         |     76 	CLOG_LEAVEFN( "CMmsToHandler::~CMmsToHandler()" ); | 
|         |     77 	} | 
|         |     78  | 
|         |     79 // --------------------------------------------------------- | 
|         |     80 // CMmsToHandler::CMmsToHandler() | 
|         |     81 // --------------------------------------------------------- | 
|         |     82 // | 
|         |     83 CMmsToHandler::CMmsToHandler() : CBaseHandler() | 
|         |     84 	{ | 
|         |     85 	// Deliberately do nothing here :  | 
|         |     86 	// See ConstructL() for initialisation completion. | 
|         |     87 	} | 
|         |     88  | 
|         |     89 // --------------------------------------------------------- | 
|         |     90 // CMmsToHandler::ConstructL() | 
|         |     91 // --------------------------------------------------------- | 
|         |     92 // | 
|         |     93 void CMmsToHandler::ConstructL( const TDesC& aUrl ) | 
|         |     94 	{ | 
|         |     95 	CLOG_ENTERFN( "CMmsToHandler::ConstructL()" ); | 
|         |     96  | 
|         |     97 	BaseConstructL( aUrl ); | 
|         |     98      | 
|         |     99     User::LeaveIfError( iFs.Connect() ); | 
|         |    100 	CLOG_LEAVEFN( "CMmsToHandler::ConstructL()" ); | 
|         |    101 	} | 
|         |    102  | 
|         |    103 // --------------------------------------------------------- | 
|         |    104 // CMmsToHandler::HandleUrlEmbeddedL() | 
|         |    105 // --------------------------------------------------------- | 
|         |    106 // | 
|         |    107 void CMmsToHandler::HandleUrlEmbeddedL() | 
|         |    108 	{ | 
|         |    109 	CLOG_ENTERFN( "CMmsToHandler::HandleUrlEmbeddedL()" ); | 
|         |    110     HandleUrlL( ETrue );  | 
|         |    111     NotifyClient(); | 
|         |    112 	CLOG_LEAVEFN( "CMmsToHandler::HandleUrlEmbeddedL()" ); | 
|         |    113 	} | 
|         |    114  | 
|         |    115 // --------------------------------------------------------- | 
|         |    116 // CMmsToHandler::HandleUrlStandaloneL() | 
|         |    117 // --------------------------------------------------------- | 
|         |    118 // | 
|         |    119 void CMmsToHandler::HandleUrlStandaloneL() | 
|         |    120 	{ | 
|         |    121 	CLOG_ENTERFN( "CMmsToHandler::HandleUrlStandaloneL()" ); | 
|         |    122     LaunchSchemeAppWithCommandLineL(); | 
|         |    123 	CLOG_LEAVEFN( "CMmsToHandler::HandleUrlStandaloneL()" ); | 
|         |    124 	} | 
|         |    125  | 
|         |    126 // --------------------------------------------------------- | 
|         |    127 // CMmsToHandler::HandleUrlL() | 
|         |    128 // --------------------------------------------------------- | 
|         |    129 //     | 
|         |    130 void CMmsToHandler::HandleUrlL(TBool aLaunchEmbedded) | 
|         |    131     { | 
|         |    132     // Parse url | 
|         |    133 	TPtrC mmsto = GetField( KMmsto ); | 
|         |    134     TPtrC to = GetField( KTo ); | 
|         |    135 	TPtrC subject = GetField( KSubject ); | 
|         |    136 	TPtrC msgBody = GetField( KBody ); | 
|         |    137 	TPtrC cc = GetField( KCc ); | 
|         |    138 	 | 
|         |    139 	CMessageData* messageData = CMessageData::NewLC(); | 
|         |    140  | 
|         |    141     CParaFormatLayer* paraFormat = CParaFormatLayer::NewL(); | 
|         |    142     CleanupStack::PushL( paraFormat ); | 
|         |    143  | 
|         |    144     CCharFormatLayer* charFormat = CCharFormatLayer::NewL();  | 
|         |    145     CleanupStack::PushL( charFormat ); | 
|         |    146  | 
|         |    147     CRichText* body = CRichText::NewL( paraFormat, charFormat ); | 
|         |    148     CleanupStack::PushL( body ); | 
|         |    149     if( msgBody.Length() ) | 
|         |    150 	    { | 
|         |    151         body->InsertL( 0, msgBody ); | 
|         |    152 	    } | 
|         |    153     else | 
|         |    154 	    { | 
|         |    155         body->InsertL( 0, KNullDesC ); | 
|         |    156 	    } | 
|         |    157     messageData->SetBodyTextL(body); | 
|         |    158  | 
|         |    159     // Add subject | 
|         |    160     if ( subject.Length() ) | 
|         |    161         { | 
|         |    162         messageData->SetSubjectL( &subject ); | 
|         |    163         } | 
|         |    164  | 
|         |    165     // Add addresses to messageData | 
|         |    166     if( mmsto.Length() ) | 
|         |    167 		{ | 
|         |    168 		SeparateAndAppendAddressL(KComma, mmsto, *messageData); | 
|         |    169 		} | 
|         |    170     else | 
|         |    171         { | 
|         |    172         } | 
|         |    173     if ( to.Length() ) | 
|         |    174         { | 
|         |    175         SeparateAndAppendAddressL(KComma, to, *messageData, KToRecipient); | 
|         |    176         } | 
|         |    177     if ( cc.Length() ) | 
|         |    178         { | 
|         |    179         SeparateAndAppendAddressL(KComma, cc, *messageData, KCcRecipient ); | 
|         |    180         } | 
|         |    181             | 
|         |    182     if ( !iSendUi ) | 
|         |    183         { | 
|         |    184         iSendUi = CSendUi::NewL(); | 
|         |    185         } | 
|         |    186  | 
|         |    187     iSendUi->CreateAndSendMessageL( | 
|         |    188         KSenduiMtmMmsUid, messageData, KNullUid, aLaunchEmbedded); | 
|         |    189  | 
|         |    190     CleanupStack::PopAndDestroy(4, messageData);	 | 
|         |    191     } | 
|         |    192  | 
|         |    193 // --------------------------------------------------------- | 
|         |    194 // CMmsToHandler::GetField() | 
|         |    195 // --------------------------------------------------------- | 
|         |    196 // | 
|         |    197 TPtrC CMmsToHandler::GetField(const TDesC& aHeader) | 
|         |    198 	{ | 
|         |    199 	CLOG_ENTERFN( "CMmsToHandler::GetField()" ); | 
|         |    200  | 
|         |    201 	TPtrC path = iParsedUrl->Des(); | 
|         |    202  | 
|         |    203 	TInt start = 0; | 
|         |    204 	TInt end = 0; | 
|         |    205  | 
|         |    206 	CMmsToHandler::TSchemeMmsToFields posHeader = GetHeaderPos( aHeader ); | 
|         |    207 	// field start from; and end at  | 
|         |    208 	switch( posHeader ) | 
|         |    209 		{ | 
|         |    210 		case ESchemeMmsTo: // MmsTo | 
|         |    211 			{ | 
|         |    212 			start = FieldStart( KMmsto ); | 
|         |    213 			end = FieldEnd( KMmsto ); | 
|         |    214 			break; | 
|         |    215 			} | 
|         |    216 		case ESchemeSubject: // Subject | 
|         |    217 			{ | 
|         |    218 			start = FieldStart( KSubject ); | 
|         |    219 			end = FieldEnd( KSubject ); | 
|         |    220 			break; | 
|         |    221 			} | 
|         |    222 		case ESchemeMsgBody: // Msg Body | 
|         |    223 			{ | 
|         |    224 			start = FieldStart( KBody ); | 
|         |    225 			end = FieldEnd( KBody ); | 
|         |    226 			break; | 
|         |    227 			} | 
|         |    228 		case ESchemeCc: // Cc | 
|         |    229 			{ | 
|         |    230 			start = FieldStart( KCc ); | 
|         |    231 			end = FieldEnd( KCc ); | 
|         |    232 			break; | 
|         |    233 			} | 
|         |    234         case ESchemeTo: // To | 
|         |    235             { | 
|         |    236             start = FieldStart( KTo ); | 
|         |    237             end = FieldEnd( KTo ); | 
|         |    238             break; | 
|         |    239             } | 
|         |    240 		case ESchemeNoMore: | 
|         |    241 			{ | 
|         |    242 			break; | 
|         |    243 			} | 
|         |    244 		default: | 
|         |    245 			{ | 
|         |    246 			break; | 
|         |    247 			} | 
|         |    248 		} | 
|         |    249  | 
|         |    250 	CLOG_LEAVEFN( "CMmsToHandler::GetField()" ); | 
|         |    251  | 
|         |    252 	return path.Mid( start, end-start ); | 
|         |    253 	} | 
|         |    254  | 
|         |    255 // --------------------------------------------------------- | 
|         |    256 // CMmsToHandler::IsHeader() | 
|         |    257 // --------------------------------------------------------- | 
|         |    258 // | 
|         |    259 TBool CMmsToHandler::IsHeader(const TDesC& aHeader) | 
|         |    260 	{ | 
|         |    261 	CLOG_ENTERFN( "CMmsToHandler::IsHeader()" ); | 
|         |    262  | 
|         |    263 	TBool retVal = EFalse; | 
|         |    264  | 
|         |    265 	TPtrC path = iParsedUrl->Des(); | 
|         |    266  | 
|         |    267 	/* is the field in the mmsto sheme */ | 
|         |    268 	if( KErrNotFound != path.FindF( aHeader ) ) | 
|         |    269 		{ | 
|         |    270 		retVal = ETrue; | 
|         |    271 		} | 
|         |    272  | 
|         |    273 	CLOG_LEAVEFN( "CMmsToHandler::IsHeader()" ); | 
|         |    274  | 
|         |    275 	return retVal; | 
|         |    276 	} | 
|         |    277  | 
|         |    278 // --------------------------------------------------------- | 
|         |    279 // CMmsToHandler::FieldStart() | 
|         |    280 // --------------------------------------------------------- | 
|         |    281 // | 
|         |    282 TInt CMmsToHandler::FieldStart(const TDesC& aHeader) | 
|         |    283 	{ | 
|         |    284 	CLOG_ENTERFN( "CMmsToHandler::FieldStart()" ); | 
|         |    285  | 
|         |    286 	TPtrC path = iParsedUrl->Des(); | 
|         |    287 	TInt retVal = path.Length(); | 
|         |    288  | 
|         |    289 	/* find the starting position of the specific filed */ | 
|         |    290 	if( IsHeader( aHeader ) ) | 
|         |    291 		{ | 
|         |    292 		retVal = path.FindF( aHeader ) + aHeader.Length(); | 
|         |    293 		} | 
|         |    294  | 
|         |    295 	CLOG_LEAVEFN( "CMmsToHandler::FieldStart()" ); | 
|         |    296  | 
|         |    297 	return retVal; | 
|         |    298 	} | 
|         |    299  | 
|         |    300 // --------------------------------------------------------- | 
|         |    301 // CMmsToHandler::FieldEnd() | 
|         |    302 // --------------------------------------------------------- | 
|         |    303 // | 
|         |    304 TInt CMmsToHandler::FieldEnd(const TDesC& aHeader) | 
|         |    305 	{ | 
|         |    306 	CLOG_ENTERFN( "CMmsToHandler::FieldEnd()" ); | 
|         |    307  | 
|         |    308 	TPtrC path = iParsedUrl->Des(); | 
|         |    309 	TInt length = path.Length(); // length of the scheme | 
|         |    310     TInt retVal = length; | 
|         |    311  | 
|         |    312     TInt startPos = FieldStart( aHeader ); | 
|         |    313  | 
|         |    314 	if( IsHeader( aHeader ) ) | 
|         |    315 		{ | 
|         |    316         TInt temp = GetNextField( startPos ); | 
|         |    317         /* we need to subtract 1 if the result is  | 
|         |    318            not equal to length because of the & or ? */ | 
|         |    319         retVal = ( temp == length ) ? length : ( temp - 1); | 
|         |    320 		} | 
|         |    321  | 
|         |    322 	CLOG_LEAVEFN( "CMmsToHandler::FieldEnd()" ); | 
|         |    323  | 
|         |    324 	return retVal; | 
|         |    325 	} | 
|         |    326  | 
|         |    327 // --------------------------------------------------------- | 
|         |    328 // CMmsToHandler::GetHeaderPos() | 
|         |    329 // --------------------------------------------------------- | 
|         |    330 // | 
|         |    331 CMmsToHandler::TSchemeMmsToFields CMmsToHandler::GetHeaderPos(const TDesC& aHeader) | 
|         |    332 	{ | 
|         |    333 	CLOG_ENTERFN( "CMmsToHandler::GetHeaderPos()" ); | 
|         |    334  | 
|         |    335 	TSchemeMmsToFields retVal = ESchemeMmsTo; | 
|         |    336  | 
|         |    337 	if( 0 == aHeader.Compare( KMmsto ) ) | 
|         |    338 		{ | 
|         |    339 		retVal = ESchemeMmsTo; | 
|         |    340 		} | 
|         |    341 	else if ( 0 == aHeader.Compare( KSubject ) ) | 
|         |    342 		{ | 
|         |    343 		retVal = ESchemeSubject; | 
|         |    344 		} | 
|         |    345 	else if ( 0 == aHeader.Compare( KBody ) ) | 
|         |    346 		{ | 
|         |    347 		retVal = ESchemeMsgBody; | 
|         |    348 		} | 
|         |    349 	else if ( 0 == aHeader.Compare( KCc ) ) | 
|         |    350 		{ | 
|         |    351 		retVal = ESchemeCc; | 
|         |    352 		} | 
|         |    353     else if ( 0 == aHeader.Compare( KTo ) ) | 
|         |    354 		{ | 
|         |    355 		retVal = ESchemeTo; | 
|         |    356 		} | 
|         |    357  | 
|         |    358 	CLOG_LEAVEFN( "CMmsToHandler::GetHeaderPos()" ); | 
|         |    359  | 
|         |    360 	return retVal; | 
|         |    361 	} | 
|         |    362  | 
|         |    363 // --------------------------------------------------------- | 
|         |    364 // CMmsToHandler::GetNextField() | 
|         |    365 // --------------------------------------------------------- | 
|         |    366 // | 
|         |    367 TInt CMmsToHandler::GetNextField( TInt aStart ) | 
|         |    368     { | 
|         |    369 	TPtrC path = iParsedUrl->Des(); | 
|         |    370 	TInt retVal = path.Length(); | 
|         |    371     TPtrC scheme; | 
|         |    372     RArray<TInt> array; | 
|         |    373  | 
|         |    374     //KSubject KBody KCc KTo | 
|         |    375     if( aStart < retVal ) | 
|         |    376         { | 
|         |    377         scheme.Set( path.Right( retVal - aStart ) ); | 
|         |    378         } | 
|         |    379     else | 
|         |    380         { | 
|         |    381         return retVal; | 
|         |    382         } | 
|         |    383  | 
|         |    384     TInt subjPos = scheme.FindF( KSubject ); | 
|         |    385     subjPos = ( subjPos == KErrNotFound ) ? retVal : subjPos; | 
|         |    386     array.Append( subjPos ); | 
|         |    387  | 
|         |    388     TInt bodyPos = scheme.FindF( KBody ); | 
|         |    389     bodyPos = ( bodyPos == KErrNotFound ) ? retVal : bodyPos; | 
|         |    390     array.Append( bodyPos ); | 
|         |    391  | 
|         |    392     TInt ccPos = scheme.FindF( KCc ); | 
|         |    393     ccPos = ( ccPos == KErrNotFound ) ? retVal : ccPos; | 
|         |    394     array.Append( ccPos ); | 
|         |    395  | 
|         |    396     TInt toPos = scheme.FindF( KTo ); | 
|         |    397     toPos = ( toPos == KErrNotFound ) ? retVal : toPos; | 
|         |    398     array.Append( toPos );     | 
|         |    399  | 
|         |    400     TInt temp = Minimum( array ); | 
|         |    401     retVal = ( temp < retVal) ? temp + aStart : retVal; | 
|         |    402  | 
|         |    403     return retVal; | 
|         |    404     } | 
|         |    405  | 
|         |    406 // End of file | 
|         |    407  |