pimappsupport/vcardandvcal/rec/VersitRecog.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <apmrec.h>
       
    17 #include <apmstd.h>
       
    18 
       
    19 #include "VersitRecog.h"
       
    20 
       
    21 #include <ecom/implementationproxy.h>
       
    22 
       
    23 const TInt KVersitRecognizerValue=0x100047EB;
       
    24 const TUid KUidMimeTxtRecognizer={KVersitRecognizerValue};
       
    25 
       
    26 _LIT8(KDataTypevCardPlain,"text/X-vCard");
       
    27 _LIT8(KDataTypevCalendarPlain,"text/X-vCalendar");
       
    28 _LIT(KRVersitPanic, "RVERSIT");
       
    29 const TInt KMaxBufferLength=256;
       
    30 
       
    31 
       
    32 enum TRversitPanic
       
    33 	{
       
    34 	EDInvalidIndex
       
    35 	};
       
    36 
       
    37 GLDEF_C void Panic(TRversitPanic aPanic)
       
    38 //
       
    39 // Panic the process with RECAPP as the category.
       
    40 //
       
    41 	{
       
    42 	User::Panic(KRVersitPanic,aPanic);
       
    43 	}
       
    44 
       
    45 CApaVersitRecognizer::CApaVersitRecognizer()
       
    46 	:CApaDataRecognizerType(KUidMimeTxtRecognizer,CApaDataRecognizerType::ENormal)
       
    47 	{
       
    48 	iCountDataTypes=2;
       
    49 	}
       
    50 
       
    51 TUint CApaVersitRecognizer::PreferredBufSize()
       
    52 	{
       
    53 	return KMaxBufferLength;
       
    54 	}
       
    55 
       
    56 TDataType CApaVersitRecognizer::SupportedDataTypeL(TInt aIndex) const
       
    57 	{
       
    58 	__ASSERT_DEBUG(aIndex>=0 && aIndex<2,Panic(EDInvalidIndex));
       
    59 	switch (aIndex)
       
    60 		{
       
    61 	case 0:
       
    62 		return TDataType(KDataTypevCardPlain);
       
    63 	default:
       
    64 		return TDataType(KDataTypevCalendarPlain);
       
    65 		}
       
    66 	}
       
    67 
       
    68 void CApaVersitRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
       
    69 	{
       
    70 	if (aName.Length()<4)
       
    71 		return;
       
    72 	_LIT(KvCardExt,".vcf");
       
    73 	_LIT(KvCalendarExt,".vcs");
       
    74 	if (aName.Right(4).CompareF(KvCardExt)==0)
       
    75 		DoRecognizeVCard(aBuffer);
       
    76 	else if (aName.Right(4).CompareF(KvCalendarExt)==0)
       
    77 		DoRecognizeVCalendar(aBuffer);
       
    78 	}
       
    79 
       
    80 void CApaVersitRecognizer::DoRecognizeVCard(const TDesC8& aBuffer)
       
    81 	{
       
    82 	_LIT8(KvCardMagicString,"BEGIN:VCARD");
       
    83 	TInt result=aBuffer.FindF(KvCardMagicString);
       
    84 	iDataType=TDataType(KDataTypevCardPlain);
       
    85 	if (result!=KErrNotFound)
       
    86 		iConfidence=ECertain;
       
    87 	else
       
    88 		iConfidence=EPossible;
       
    89 	}
       
    90 
       
    91 void CApaVersitRecognizer::DoRecognizeVCalendar(const TDesC8& aBuffer)
       
    92 	{
       
    93 	_LIT8(KvCalMagicString,"BEGIN:VCALENDAR");
       
    94 	TInt result=aBuffer.FindF(KvCalMagicString);
       
    95 	iDataType=TDataType(KDataTypevCalendarPlain);
       
    96 	if (result!=KErrNotFound)
       
    97 		iConfidence=ECertain;
       
    98 	else
       
    99 		iConfidence=EPossible;
       
   100 	}
       
   101 
       
   102 
       
   103 const TImplementationProxy ImplementationTable[]=
       
   104 	{
       
   105     IMPLEMENTATION_PROXY_ENTRY(0x100047EB,CApaVersitRecognizer::CreateDataRecognizerL)
       
   106 	};
       
   107 
       
   108 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   109     {
       
   110     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   111     return ImplementationTable;
       
   112     }
       
   113 
       
   114 CApaDataRecognizerType* CApaVersitRecognizer::CreateDataRecognizerL()
       
   115 	{
       
   116     return new (ELeave) CApaVersitRecognizer();
       
   117     }
       
   118 
       
   119