×
Namespaces

Variants
Actions

为MIME类型生成一个recognizer插件

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 04 Aug 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS001050


设备, 软件 版本: S60 3rd Edition, MR


Contents

详细描述

当我们选择了一个文件时,我们可能需要启动一个相应的程序打开(如一个viewer),例如,通过文件管理器打开。但是如果MIME类型为系统不能识别的话,这个处理程序将无法启动。在这种情况下,你需要写一个数据识别器。这个识别器为一个ECOM插件,它可以通过URI(如文件名)来识别数据的类型或它的内容。下列代码片段演示了如何写一个Tex文件(MIME类型:application/x-tex)的识别器。


注意:数据识别器不能用来处理程序,只用来识别它的类型。一旦该类型别识别,这个数据就可以由相应程序来处理。


MMP文件

需要下列能力和链接库

CAPABILITY  ProtServLIBRARY  apmime.lib  // CApaDataRecognizerType
LIBRARY efsrv.lib // TParse
LIBRARY euser.lib


下面是一个现成的MMP文件

TARGET        RecognizerPlugin.dll
TARGETTYPE PLUGIN
UID 0x10009D8D 0x101FF1EC
 
CAPABILITY ProtServ
VENDORID 0
 
SOURCEPATH ..\data
START RESOURCE 101FF1EC.rss
TARGET RecognizerPlugin.rsc
END
 
USERINCLUDE ..\inc
SYSTEMINCLUDE \epoc32\include
SYSTEMINCLUDE \epoc32\include\ecom
 
SOURCEPATH ..\src
SOURCE CTexRecognizer.cpp
 
LIBRARY apmime.lib // CApaDataRecognizerType
LIBRARY efsrv.lib // TParse
LIBRARY euser.lib

PKG文件

; Language - standard language definitions
&EN
 
; SIS file header
#{"RecognizerPlugin DLL"},(0x10280805),1,0,0
 
; Localized Vendor name
%{"Vendor-EN"}
 
; Unique Vendor Name
:"Vendor"
 
; Supports S60 v 3.0
[0x101F7961], 0, 0, 0, {"Series60ProductID"}
 
; Files to install
"\Symbian\9.1\S60_3rd_MR\Epoc32\release\GCCE\UREL\RecognizerPlugin.dll"
- "!:\sys\bin\RecognizerPlugin.dll"
"\Symbian\9.1\S60_3rd_MR\Epoc32\Data\z\resource\plugins\RecognizerPlugin.rsc"
- "!:\resource\plugins\RecognizerPlugin.rsc"


资源文件:101FF1EC.rss

注意:这个文件的名字必须为该程序的UID3值

#include <RegistryInfo.rh>
 
RESOURCE REGISTRY_INFO r_registry
{
// UID for the DLL
dll_uid = 0x101FF1EC;
interfaces =
{
INTERFACE_INFO
{
// Common for all data recognizers
interface_uid = 0x101F7D87;
implementations =
{
IMPLEMENTATION_INFO
{
implementation_uid = 0x101FF1ED;
version_no = 1;
display_name = "RecognizerPlugin";
default_data = "RecognizerPlugin";
opaque_data = "";
}
};
}
};
}


头文件

#ifndef __CTEXRECOGNIZER_H_
#define __CTEXRECOGNIZER_H_
 
#include <apmrec.h> // CApaDataRecognizerType
 
class CTexRecognizer : public CApaDataRecognizerType
{
public: // Constructors and destructor
CTexRecognizer();
static CApaDataRecognizerType* CreateRecognizerL();
virtual ~CTexRecognizer();
 
public: // Methods from base classes
TUint PreferredBufSize();
TDataType SupportedDataTypeL(TInt aIndex) const;
 
private: // Methods from base classes
void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
};
 
#endif /*__CTEXRECOGNIZER_H_*/


源文件

#include <apmrec.h>   // CApaDataRecognizerType
#include <f32file.h> // TParse
#include <ImplementationProxy.h> // TImplementationProxy
 
#include "CTexRecognizer.h"
 
const TUid KRecognizerUid = {0x101FF1EC};
const TInt KRecognizerImplUid = {0x101FF1ED};
const TInt KMaxBufferSize = 128;
_LIT8(KMIMETex, "application/x-tex");
_LIT(KTexExtension, ".tex");
 
CTexRecognizer::CTexRecognizer()
 : CApaDataRecognizerType(KRecognizerUid, CApaDataRecognizerType::ENormal)
{
iCountDataTypes = 1;
}
 
CTexRecognizer::~CTexRecognizer()
{
// No implementation required
}
 
/**
* From CApaDataRecognizerType.
*/
TUint CTexRecognizer::PreferredBufSize()
{
return KMaxBufferSize;
}
 
/**
* From CApaDataRecognizerType.
* Gets one of the data types that this recognizer can recognize.
*/
TDataType CTexRecognizer::SupportedDataTypeL(TInt /*aIndex*/) const
{
return TDataType(KMIMETex);
}
 
/**
* From CApaDataRecognizerType.
* Attempts to recognize data denoted by aName and residing in aBuffer.
*/
void CTexRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
{
// To keep the code simple, we only check the file name extension: If the
// extension is ".tex", we are "ECertain" that the file is of type
// application/x-tex.
TParse parse;
parse.Set(aName, NULL, NULL);
TPtrC ext = parse.Ext();
if (ext.CompareF(KTexExtension) == 0)
{
iConfidence = ECertain;
iDataType = TDataType(KMIMETex);
}
}
 
// *** ECOM framework code ***
 
CApaDataRecognizerType* CTexRecognizer::CreateRecognizerL()
{
return new (ELeave) CTexRecognizer();
}
 
const TImplementationProxy ImplementationTable[] =
{
IMPLEMENTATION_PROXY_ENTRY(KRecognizerImplUid,
CTexRecognizer::CreateRecognizerL)
};
 
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
TInt& aTableCount)
{
aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
return ImplementationTable;
}

后记

至此Tex文件的识别器就完成了,如果文件的application/x-tex被打开,如从程序管理器中,那么

CTexRecognizer::DoRecognizeL()方法就会被调用,并且application/x-tex的MIME类型也会别识别。

This page was last modified on 15 December 2011, at 08:56.
120 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×