installationservices/swi/test/tmimehandler/tmimehandler.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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 the License "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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tmimehandler.h"
       
    20 #include <apacmdln.h>
       
    21 
       
    22 const TInt KUidMimeAppValue=0x1021234d ; 
       
    23 
       
    24 void CMimeAppUi::DoExitL()
       
    25 	{
       
    26 	
       
    27 	CVwsSessionWrapper* ses=CVwsSessionWrapper::NewLC();
       
    28 	ses->EnableServerEventTimeOut(ETrue);
       
    29 	CleanupStack::PopAndDestroy();
       
    30 	Exit();
       
    31 	}
       
    32 
       
    33 CMimeAppUi::CMimeAppUi()
       
    34 	{
       
    35 	}
       
    36 	
       
    37 void CMimeAppUi::ConstructL()
       
    38     {
       
    39 	BaseConstructL();
       
    40 	}
       
    41 
       
    42 CMimeAppUi::~CMimeAppUi()
       
    43 	{
       
    44 	}
       
    45 
       
    46 TBool CMimeAppUi::ProcessCommandParametersL(TApaCommand aCommand, 
       
    47 	TFileName& aDocumentName, const TDesC8& /*aTail*/)
       
    48 	{
       
    49 	switch (aCommand)
       
    50 		{
       
    51 		case EApaCommandOpen:
       
    52 			{
       
    53 			//Open the file for read the path and create the file.
       
    54 			TBuf8 <KMaxFileName> readBuffer;
       
    55 			RFs fs;
       
    56 			User::LeaveIfError(fs.Connect());
       
    57 			CleanupClosePushL(fs);			
       
    58 			RFile file;
       
    59 			User::LeaveIfError(file.Open(fs, aDocumentName, EFileStreamText));
       
    60 			User::LeaveIfError(file.Read(readBuffer));
       
    61 			file.Close();
       
    62 			HBufC* buf1 = HBufC::NewLC(KMaxFileName);
       
    63 			TPtr tptr = buf1->Des();
       
    64 			tptr.Copy(readBuffer);
       
    65 			TInt pos = tptr.Locate(' ');
       
    66 			TInt count1 = tptr.Length();
       
    67 			TInt count2 = count1-pos;
       
    68 			tptr.Delete(pos,count2);
       
    69 			User::LeaveIfError(file.Replace(fs,tptr,EFileWrite));
       
    70 			CleanupStack::PopAndDestroy(2, &fs);
       
    71 			}
       
    72 		break;	   
       
    73 		}
       
    74 		
       
    75 	return ETrue;	
       
    76 	}
       
    77 	
       
    78 TBool CMimeAppUi::ProcessCommandParametersL(CApaCommandLine& aCommandLine)
       
    79 	{
       
    80 	switch (aCommandLine.Command())
       
    81 		{
       
    82 		case EApaCommandOpen:
       
    83 			{		
       
    84 			// Open the file and use the handle to install it
       
    85 			RFile fileHandle;
       
    86 			CleanupClosePushL(fileHandle);
       
    87 			aCommandLine.GetFileByHandleL(fileHandle);
       
    88 			
       
    89 			if (fileHandle.SubSessionHandle() != KNullHandle)
       
    90 				{
       
    91 				HBufC8* buf1 = HBufC8::NewLC(KMaxFileName);
       
    92 				TPtr8 tptr = buf1->Des();
       
    93 				fileHandle.Read(tptr);
       
    94 				TInt pos = tptr.Locate(' ');
       
    95 				TInt count1 = tptr.Length();
       
    96 				TInt count2 = count1-pos;
       
    97 				tptr.Delete(pos,count2);
       
    98 				RFs fs;
       
    99 				User::LeaveIfError(fs.Connect());
       
   100 				CleanupClosePushL(fs);
       
   101 				RFile file;
       
   102 				CleanupClosePushL(file);
       
   103 				TBuf <KMaxFileName> fileName;
       
   104 				fileName.Copy(tptr);				
       
   105 				User::LeaveIfError(file.Replace(fs,fileName,EFileWrite));
       
   106 				CleanupStack::PopAndDestroy(3, buf1); // file, fs, buf1
       
   107 				}
       
   108 			else
       
   109 				{
       
   110 				TFileName name=aCommandLine.DocumentName();
       
   111 				// No file handle, launch by document name
       
   112 				ProcessCommandParametersL(aCommandLine.Command(), name, aCommandLine.TailEnd());
       
   113 				}
       
   114 			CleanupStack::PopAndDestroy(&fileHandle); // fileHandle
       
   115 			
       
   116 			Exit();
       
   117 			}
       
   118 		break;	
       
   119 		}
       
   120 	return ETrue;	
       
   121 	}
       
   122 	
       
   123 	
       
   124 CMimeDocument::CMimeDocument(CMimeApplication& aApp)
       
   125 		: CEikDocument(aApp)
       
   126 	{
       
   127 	__DECLARE_NAME(_S("CMimeDocument"));
       
   128 	}
       
   129 	
       
   130 CEikAppUi* CMimeDocument::CreateAppUiL()
       
   131 	{
       
   132     return(new(ELeave) CMimeAppUi);
       
   133 	} 
       
   134 
       
   135 
       
   136 	
       
   137 // ===========================================================================
       
   138 // CMimeApplication
       
   139 // Main application class
       
   140 // ===========================================================================
       
   141 	
       
   142 TUid CMimeApplication::AppDllUid() const
       
   143 	{
       
   144 	const TUid KUidMimeApp={KUidMimeAppValue};
       
   145 	return(KUidMimeApp);
       
   146 	}
       
   147 	
       
   148 CApaDocument* CMimeApplication::CreateDocumentL()
       
   149 	{
       
   150 	return(new(ELeave) CMimeDocument(*this));
       
   151 	}
       
   152 	
       
   153 
       
   154 // ===========================================================================
       
   155 // Main EPOC app startup
       
   156 // ===========================================================================
       
   157 
       
   158 EXPORT_C CApaApplication* NewApplication()
       
   159 	{
       
   160 	return(new CMimeApplication);
       
   161 	}
       
   162 
       
   163 GLDEF_C TInt E32Main()
       
   164 	{
       
   165 	// Wait 1 second on startup for the benefit of synchronous filerun tests.
       
   166 	// Some tests depend on tmimehandler not completing before an install
       
   167 	// test step finishes.
       
   168 	User::After(1000000);
       
   169 	return EikStart::RunApplication(NewApplication);
       
   170 	}