You Are Here:

Community: Wiki

This page was last modified on 13 October 2008, at 20:07.

CS001051 - Creating a handler application for a MIME type

From Forum Nokia Wiki



ID CS001051 Creation date July 1, 2008
Platform S60 3rd Edition, MR Tested on devices Nokia N95 8GB
Category Symbian C++ Subcategory Files/Data


Keywords (APIs, classes, methods, functions): CAknDocument, CAknDocument::OpenFileL()

Overview

It is sometimes necessary to launch a handler application (such as a viewer) for files selected, for example, through the File manager. This code snippet demonstrates how to write a handler for TeX files (MIME type: application/x-tex).

Note: If the MIME type of the file is not known, the handler application cannot be launched. In this case, you need to write a data recognizer that identifies the MIME type of the file. For more information about implementing a data recognizer, see CS001050 - Creating a recognizer plug-in for a MIME type.

Resource file: CTeXHandler_reg.rss

The data handler is registered to handle that particular MIME type by adding a datatype_list section to the application's reg.rss file. The section lists the MIME types that the application is able to handle, and the priority of support for each MIME type. The priority can be one of the following four values:

  • EDataTypePriorityHigh
  • EDataTypePriorityNormal
  • EDataTypePriorityLow
  • EDataTypePriorityLastResort

Symbian OS launches the application that has the highest priority support for the data type in question.

Here is the relevant part of the reg.rss file:

RESOURCE APP_REGISTRATION_INFO
{
app_file = "CTeXHandler";
localisable_resource_file = qtn_loc_resource_file;
localisable_resource_id = R_LOCALISABLE_APP_INFO;
 
embeddability = KAppEmbeddable;
datatype_list =
{
DATATYPE
{
priority = EDataTypePriorityHigh;
type = "application/x-tex";
}
};
}

Header file: CTeXHandlerDocument.h

#include <akndoc.h>  // CAknDocument
 
class CTeXHandlerDocument : public CAknDocument
{
// ...
 
public: // Functions from base classes
/**
* From CAknDocument.
* Create a CTeXHandlerAppUI object and return a pointer to it.
* The object returned is owned by the Uikon framework.
* @return a pointer to the created instance of AppUI.
*/

CEikAppUi* CreateAppUiL();
 
/**
* From CAknDocument.
* Opens a file.
*/

void OpenFileL(CFileStore*& aFileStore, RFile& aFile);
 
private: // Data
CEikAppUi* iAppUI;
};

Source file: CTeXHandlerDocument.cpp

CEikAppUi* CTeXHandlerDocument::CreateAppUiL()
{
// Create the application user interface, and return a pointer to it;
// the framework takes ownership of this object
iAppUI = new (ELeave) CTeXHandlerAppUI();
return iAppUI;
}
 
void CTeXHandlerDocument::OpenFileL(CFileStore*& aFileStore, RFile& aFile)
{
// Store the filename in a local variable
TFileName filename;
aFile.Name(filename);
 
// Store the first few characters of the file contents in a local variable
const TInt KCharsToRead = 20;
TBuf8<KCharsToRead> contents;
User::LeaveIfError(aFile.Read(contents, KCharsToRead));
 
// Delegate file handling to the application UI
CTeXHandlerAppUI *appUI = static_cast<CTeXHandlerAppUI*>(iAppUI);
appUI->SetFileData(filename, contents);
}

Header file: CTeXHandlerAppUI.h

#include <aknappui.h>
 
class CTeXHandlerAppUI : public CAknAppUi
{
// ...
 
public: // New functions
/**
* Handles the file.
*/

void SetFileData(TDes& aFileName, TDes8& aData);
 
private: // Data
/**
* The application view.
* Owned by CTeXHandlerAppUI.
*/

CTeXHandlerAppView* iAppView;
};

Source file: CTeXHandlerAppUI.cpp

void CTeXHandlerAppUI::SetFileData(TDes& aFileName, TDes8& aData)
{
if (iAppView)
{
iAppView->SetFileData(aFileName, aData);
}
}

Header file: CTeXHandlerAppView.h

#include <coecntrl.h>
 
class CTeXHandlerAppView : public CCoeControl
{
// ...
 
public: // New functions
/**
* Handles the file.
*/

void SetFileData(TDes& aFileName, TDes8& aData);
 
// ...
};

Source file: CTeXHandlerAppView.cpp

void CTeXHandlerAppView::SetFileData(TDes& aFileName, TDes8& aData)
{
// Handle the TeX file: Draw its contents onto the screen etc.
}

Postconditions

A handler for TeX files is implemented. If the file of type application/x-tex is opened for example from the File manager, the CTeXHandlerDocument::OpenFileL() method is called. It delegates file handling to the view object: CTeXHandlerAppView::SetFileData().

See also

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fJ2ME45E5fE52SSE5fParserE5fwithE5fKE58mlX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxJ2ME45E20E52SSE20ParserE20withE20KE58mlE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZupdatedQDx2008E2d10E2d02X qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ