Doubt in CEikDocument::OpenFileL()...
| Mon, 2005-06-13 11:39 | |
|
Hi,
![]() I created an application which should be opened when i select a file named abc.txt.xxx from File Manager. In my application's CEikDocument::OpenFileL() function, i will do some processing on my file to convert it into abc.txt. After doing that processing i want to display the file in the default application. I am able to launch the application when my recogniser recognises the .xxx file type. But i am not able to display the contents in that file using it's default application. How to do it? Any Pointers??? This is the code i have used in OpenFileL() function: CFileStore* CSampleEditorDocument::OpenFileL(TBool aDoOpen, const TDesC& aFilename,RFs& aFs) { /*aFilename will have the file name like abc.txt.xxx. * After doing some processing I will convert that file into abc.txt. * / return CEikDocument::OpenFileL(aDoOpen,filename,aFs);//here I am just sending that file, say abc.txt. } Thanks for the time. ![]() Pooja. |
|







Forum posts: 68
The source:
* ============================================================================
*  Name   : Editor.cpp
*  Part of  : Editor
*  Created  : 09.06.2005 by
* Â Description:
* Â Â Editor.cpp DLL entry point
* Â Copyright:
* ============================================================================
*/
#include "EditorApplication.h"
// DLL entry point, return that everything is ok
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
  {
  return KErrNone;
  }
// Create an application, and return a pointer to it
EXPORT_C CApaApplication* NewApplication()
  {
  return (new CEditorApplication);
  }
* ============================================================================
*  Name   : EditorApplication.cpp
*  Part of  : Editor
*  Created  : 09.06.2005 by
* Â Description:
* Â Â CEditorApplication implementation
* Â Copyright:
* ============================================================================
*/
#include "EditorDocument.h"
#include "EditorApplication.h"
// UID for the application, this should correspond to the uid defined in the mmp file
static const TUid KUidEditorApp = {0x08086736};
CApaDocument* CEditorApplication::CreateDocumentL()
  { Â
  // Create an Editor document, and return a pointer to it
  CApaDocument* document = CEditorDocument::NewL(*this);
  return document;
  }
TUid CEditorApplication::AppDllUid() const
  {
  // Return the UID for the Editor application
  return KUidEditorApp;
  }
* ============================================================================
*  Name   : EditorAppUi.cpp
*  Part of  : Editor
*  Created  : 09.06.2005 by
* Â Description:
* Â Â CEditorAppUi implementation
* Â Copyright:
* ============================================================================
*/
#include <eikenv.h>
#include <ckninfo.h>
#include <eikrted.h>
#include <txtrich.h>
#include <ckntitle.h>
#include <eiktbar.h>
#include <eikaufty.h>
#include <eikspane.h>
#include <eikdoc.h>
#include "Editor.pan"
#include "EditorAppUi.h"
#include "EditorDocument.h"
#include "Editor.hrh"
const TInt KDefaultTextGranularity=256;
// ConstructL is called by the application framework
void CEditorAppUi::ConstructL()
  {
  BaseConstructL();
  iEditor = new (ELeave) CEikRichTextEditor();
iRichText = CRichText::NewL( CEikonEnv::Static()->SystemParaFormatLayerL(), CEikonEnv::Static()->SystemCharFormatLayerL(),
CEditableText::ESegmentedStorage, KDefaultTextGranularity);
  const TInt flags=EEikEdwinOwnsWindow|EEikEdwinKeepDocument|EEikEdwinInclusiveSizeFixed|EEikEdwinUserSuppliedText|
EEikEdwinNoAutoSelection|EEikEdwinAlwaysShowSelection;
iEditor->ConstructL(NULL,0,0, flags);
iEditor->CreateScrollBarFrameL();
iEditor->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iEditor->SetAdjacent(EGulAdjLeft | EGulAdjRight | EGulAdjTop | EGulAdjBottom);
TRect clientRect=ClientRect();
 Â
iEditor->SetDocumentContentL( *iRichText, CEikEdwin::EUseText );
iEditor->SetRect(clientRect);
iEditor->ActivateL();
iEditor->SetFocus(ETrue);
iEditor->SetAllowBorders(ETrue);
  }
CEditorAppUi::CEditorAppUi() Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
  {
  Register() ;
  }
CEditorAppUi::~CEditorAppUi()
  {
  delete iEditor;
  iEditor = NULL;
  delete iRichText;
  iRichText = NULL;
  }
// Changes normal view to full screen or vice versa.
void CEditorAppUi::ChangeFullScreenL()
{
MEikAppUiFactory* factory = iEikonEnv->AppUiFactory();
CEikButtonGroupContainer* bar = factory->ToolBar(); // CBA
CEikToolBar* band = factory->ToolBand(); // Title
CEikToolBar* titleband = factory->TitleBand(); // This is not used
CEikStatusPane* pane = factory->StatusPane(); // left hand status pane
CCknAppTitle* title = static_cast<CCknAppTitle*>( band->ControlById(EEditorAppTitle) ); // title control
TInt titleBarAdjacent = EGulAdjNone;
if ( titleband )
{
titleband->MakeVisible(EFalse);
}
bar->SetComponentsToInheritVisibility(ETrue);
bar->MakeVisible(!bar->IsVisible());
band->SetComponentsToInheritVisibility(ETrue);
if ( pane )
{
pane->MakeVisible(!pane->IsVisible());
}
band->MakeVisible(!band->IsVisible());
TRect clientRect = ClientRect();
TRect bandRect = band->Rect();
bandRect.iTl.iX = clientRect.iTl.iX;
bandRect.iBr.iX = clientRect.iBr.iX;
bandRect.iBr.iY = bandRect.iTl.iY + title->MinimumSize().iHeight;
band->SetRect(bandRect);
title->SetRect(band->Rect());
band->SetAdjacent(titleBarAdjacent);
band->DrawDeferred();
bar->DrawDeferred();
title->DrawDeferred();
iEditor->SetRect(clientRect);
iEditor->ForceScrollBarUpdateL();
iEditor->DrawDeferred();
}
TKeyResponse CEditorAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
return iEditor->OfferKeyEventL(aKeyEvent, aType);
}
// handle any menu commands
void CEditorAppUi::HandleCommandL(TInt aCommand)
{
  switch(aCommand)
{
case EEikCmdExit:
{
CBaActiveScheduler::Exit();
}
break;
case EEditorCopy:
{
iEditor->ClipboardL(CEikEdwin::ECopy);
}
break;
case EEditorCut:
{
iEditor->ClipboardL( CEikEdwin::ECut );
}
break;
case EEditorPaste:
{
iEditor->ClipboardL( CEikEdwin::EPaste );
      }
      break;
case EEditorFullScreen:
{
ChangeFullScreenL();
}
break;
case EEditorSelectAll:
{
iEditor->SelectAllL();
}
break;
case EEditorOpen:
{
//iDocument->NewDocumentL() ;
}
break;
case EEditorSave:
{
iDocument->SaveL() ;
}
break;
    default:
{
      Panic(EEditorUi);
      break;
}
    }
  }
TBool CEditorAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName, const TDesC8& aTail)
{
// TBool ret = CEikAppUi::ProcessCommandParametersL(aCommand, aDocumentName, aTail) ;
// ProcessCommandParametersL function to enables processing shell commands.
return ETrue ; //CEikAppUi::ProcessCommandParametersL(aCommand, aDocumentName, aTail) ; ;
}
void CEditorAppUi::OpenFileL(const TDesC8 d)
{
}
TStreamId CEditorAppUi::StoreL(CStreamStore& aStore) const
{
RStoreWriteStream stream ;
TStreamId id = stream.CreateLC(aStore) ;
stream << *this ;
stream.CommitL() ;
CleanupStack::PopAndDestroy() ;
return id ;
}
void CEditorAppUi::ExternalizeL(RWriteStream& aStream) const
{
HBufC16* Â text = iEditor->GetTextInHBufL() ;
CleanupStack::PushL(text);
  aStream << *text;
 Â
  CleanupStack::PopAndDestroy(text) ;
}
void CEditorAppUi::RestoreL(const CStreamStore& aStore, TStreamId aStreamId)
{
RStoreReadStream stream ;
stream.OpenLC(aStore, aStreamId) ;
stream >> *this ;
CleanupStack::PopAndDestroy() ;
}
void CEditorAppUi::InternalizeL(RReadStream& aStream)
{
HBufC16* text = HBufC16::NewLC(aStream, 50) ;
iEditor->SetTextL(text) ;
CleanupStack::PopAndDestroy() ;
}
void CEditorAppUi::Register()
{
#if 0
CTypeStoreManager* db = CTypeStoreManager::NewL(iEikonEnv->FsSession());
CleanupStack::PushL(db);
_LIT8(KMimeType, "application/x-ctxtest");
// EOF is an expected error if the file does not exist...
TRAPD(err,db->RestoreL());
if (err != KErrNone && err != KErrEof)
{
User::Leave(err);
}
static const TUid KUidEditorApp = {0x08086736};
db->InsertDataMappingL(TDataType(KMimeType),
           KDataTypePriorityUserSpecified,
           KUidEditorApp);
db->StoreL();
CleanupStack::PopAndDestroy(); //db
#endif
}
continued on next post...
If we fall down it's so we can learn to pick ourselves up.
Forum posts: 68
* ============================================================================
* Name : EditorDocument.cpp
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* CEditorDocument implementation
* Copyright:
* ============================================================================
*/
#include <txtrich.h>
#include <eikenv.h> // CEikEnv
#include <cknenv.h> // CknEnv
#include "EditorAppUi.h"
#include "EditorDocument.h"
// Standard Symbian OS construction sequence
CEditorDocument* CEditorDocument::NewL(CEikApplication& aApp)
{
CEditorDocument* self = NewLC(aApp);
CleanupStack::Pop(self);
return self;
}
CEditorDocument* CEditorDocument::NewLC(CEikApplication& aApp)
{
CEditorDocument* self = new (ELeave) CEditorDocument(aApp);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CEditorDocument::ConstructL()
{
}
CEditorDocument::CEditorDocument(CEikApplication& aApp) : CEikDocument(aApp)
{
// no implementation required
}
CEditorDocument::~CEditorDocument()
{
}
CEikAppUi* CEditorDocument::CreateAppUiL()
{
// Create the application user interface, and return a pointer to it,
// the framework takes ownership of this object
CEikAppUi* appUi = new (ELeave) CEditorAppUi;
return appUi;
}
CFileStore* CEditorDocument::OpenFileL(TBool aDoOpen, const TDesC& aFilename, RFs& aFs)
{
return CEikDocument::OpenFileL(aDoOpen, aFilename, aFs) ;
}
void CEditorDocument::StoreL(CStreamStore& aStore, CStreamDictionary& aStreamDic) const
{
TStreamId id = ((CEditorAppUi*)iAppUi)->StoreL(aStore) ;
aStreamDic.AssignL(Application()->AppDllUid(), id) ;
}
void CEditorDocument::RestoreL(const CStreamStore& aStore, const CStreamDictionary& aStreamDic)
{
TStreamId id = aStreamDic.At(Application()->AppDllUid()) ;
((CEditorAppUi*)iAppUi)->RestoreL(aStore,id) ;
}
void CEditorDocument::Register()
{
}
The headers:
* ============================================================================
* Name : EditorApplication.h
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* CEditorApplication header
* Copyright:
* ============================================================================
*/
#ifndef __EDITOR_APPLICATION_H__
#define __EDITOR_APPLICATION_H__
#include <eikapp.h>
class CEditorApplication : public CEikApplication
{
public: // from CEikApplication
TUid AppDllUid() const;
protected: // from CEikApplication
CApaDocument* CreateDocumentL();
};
#endif // __EDITOR_APPLICATION_H__
* ============================================================================
* Name : EditorDocument.h
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* CEditorDocument header
* Copyright:
* ============================================================================
*/
#ifndef __EDITOR_DOCUMENT_H__
#define __EDITOR_DOCUMENT_H__
#include <eikdoc.h>
#include <e32cons.h>
#include <f32file.h>
#include <s32file.h>
// Forward references
class CEditorAppUi;
class CEikApplication;
class CEditorDocument : public CEikDocument
{
public:
static CEditorDocument* NewL(CEikApplication& aApp);
static CEditorDocument* NewLC(CEikApplication& aApp);
~CEditorDocument();
public: // from CEikDocument
CEikAppUi* CreateAppUiL();
// my methods
virtual CFileStore* OpenFileL(TBool aDoOpen, const TDesC& aFilename, RFs& aFs) ;
void StoreL(CStreamStore& aStore, CStreamDictionary& aStreamDic) const ;
void RestoreL(const CStreamStore& aStore, const CStreamDictionary& aStreamDic) ;
void Register() ;
private:
void ConstructL();
CEditorDocument(CEikApplication& aApp);
};
#endif // __EDITOR_DOCUMENT_H__
* ============================================================================
* Name : EditorAppUi.h
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* CEditorAppUi header
* Copyright:
* ============================================================================
*/
#ifndef __EDITOR_APPUI_H__
#define __EDITOR_APPUI_H__
#include <eikappui.h>
// Forward reference
class CEditorAppView;
class CEikRichTextEditor;
class CEditorAppUi : public CEikAppUi
{
public:
void ConstructL();
CEditorAppUi();
~CEditorAppUi();
public: // from CEikAppUi
void HandleCommandL(TInt aCommand);
TKeyResponse HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
TBool ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName, const TDesC8& aTail);
// my methods
TStreamId StoreL(CStreamStore& aStore) const ;
void ExternalizeL(RWriteStream& aStream) const ;
void RestoreL(const CStreamStore& aStore, TStreamId aStreamId) ;
void InternalizeL(RReadStream& aStream) ;
void OpenFileL(const TDesC8 d) ;
void Register() ;
private:
void ChangeFullScreenL();
private:
CEikRichTextEditor* iEditor;
CRichText* iRichText;
};
#endif // __EDITOR_APPUI_H__
* ============================================================================
* Name : Editor.hrh
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* Command codes and control ids
* Copyright:
* ============================================================================
*/
#ifndef __EDITOR_HRH__
#define __EDITOR_HRH__
// Editor enumerate command codes
enum TEditorIds
{
EEditorOpen = 1,
EEditorCopy,
EEditorCut,
EEditorPaste,
EEditorSave,
EEditorAppTitle,
EEditorFullScreen,
EEditorSelectAll
};
#endif // __EDITOR_HRH__
* ============================================================================
* Name : Editor.pan
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* Panic codes
* Copyright:
* ============================================================================
*/
#ifndef __EDITOR_PAN__
#define __EDITOR_PAN__
/** Editor application panic codes */
enum TEditorPanics
{
EEditorUi = 1
// add further panics here
};
inline void Panic(TEditorPanics aReason)
{
_LIT(applicationName,"Editor");
User::Panic(applicationName, aReason);
}
#endif // __EDITOR_PAN__
the mmp:
/*
* ============================================================================
* Name : Editor.mmp
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* Project definition file
* Copyright:
* ============================================================================
*/
TARGET Editor.app
TARGETTYPE app
UID 0x100039CE 0x08086736
TARGETPATH \system\apps\editor
LANG SC
SOURCEPATH ..\src
SOURCE Editor.cpp
SOURCE EditorApplication.cpp
SOURCE EditorAppUi.cpp
SOURCE EditorDocument.cpp
SOURCEPATH ..\group
RESOURCE Editor.rss
USERINCLUDE ..\inc
SYSTEMINCLUDE \epoc32\include
AIF editor.aif ..\group editoraif.rss
LIBRARY euser.lib
LIBRARY apparc.lib
LIBRARY cone.lib
LIBRARY eikcore.lib
LIBRARY eikcoctl.lib
LIBRARY eikctl.lib
LIBRARY bafl.lib
LIBRARY etext.lib
LIBRARY efsrv.lib
LIBRARY estor.lib
The rss:
* ============================================================================
* Name : Editor.rss
* Part of : Editor
* Created : 09.06.2005 by
* Description:
* Captions and icons
* Copyright:
* ============================================================================
*/
NAME EDIT
#include <eikon.rh>
#include <uikon.rh>
#include <ckon.hrh>
#include <cknctl.rh>
#include "Editor.hrh"
// ---------------------------------------------------------
//
// Define the resource file signature
// This resource should be empty.
//
// ---------------------------------------------------------
//
RESOURCE RSS_SIGNATURE { }
// This is mandatory here.
RESOURCE TBUF { buf=""; }
// ---------------------------------------------------------
//
// Define default menu, hotkeys and CBA keys.
//
// ---------------------------------------------------------
//
RESOURCE EIK_APP_INFO
{
menubar = r_editor_menubar;
cba = r_editor_cba;
hotkeys = r_editor_hotkeys;
toolband = r_editor_titlebar;
}
// ---------------------------------------------------------
//
// r_editor_titlebar
// Toolband (titlebar) for editor example
//
// ---------------------------------------------------------
//
RESOURCE TOOLBAND r_editor_titlebar
{
breadth=32;
controls=
{
APPTITLE
{
id=EEditorAppTitle;
maintitle = "Editor";
titletype = ECknAppTitleTypeEditor;
}
};
}
// ---------------------------------------------------------
//
// r_editor_hotkeys
// Hotkeys for editor example
//
// ---------------------------------------------------------
//
RESOURCE HOTKEYS r_editor_hotkeys
{
control =
{
HOTKEY
{
command = EEikCmdExit;
key = 'e';
},
HOTKEY
{
command = EEditorOpen;
key = 'o';
},
HOTKEY
{
command = EEditorCut;
key = 'x';
},
HOTKEY
{
command = EEditorCopy;
key = 'c';
},
HOTKEY
{
command = EEditorFullScreen;
key = 't';
},
HOTKEY
{
command = EEditorPaste;
key = 'v';
},
HOTKEY
{
command = EEditorSelectAll;
key = 'a';
}
};
}
// ---------------------------------------------------------
//
// r_editor_cba
// CBA for editor example
//
// ---------------------------------------------------------
//
RESOURCE CBA r_editor_cba
{
buttons=
{
CBA_BUTTON
{
txt="";
},
CBA_BUTTON
{
txt="";
},
CBA_BUTTON
{
txt="";
},
CBA_BUTTON
{
id=EEikCmdExit;
txt="Exit";
}
};
}
// ---------------------------------------------------------
//
// r_editor_menubar
// Menubar for editor example
//
// ---------------------------------------------------------
//
RESOURCE MENU_BAR r_editor_menubar
{
titles =
{
MENU_TITLE {menu_pane = r_editor_menu_file; txt = "File";},
MENU_TITLE {menu_pane = r_editor_menu_edit; txt = "Edit";},
MENU_TITLE {menu_pane = r_editor_menu_view; txt = "View";}
};
}
// ---------------------------------------------------------
//
// r_editor_menu_file
// Menu for "File"
//
// ---------------------------------------------------------
//
RESOURCE MENU_PANE r_editor_menu_file
{
items =
{
MENU_ITEM {command = EEditorOpen; txt = "Open";},
MENU_ITEM {command = EEditorSave; txt = "Save";},
MENU_ITEM {command = EEikCmdExit; txt = "Exit";}
};
}
// ---------------------------------------------------------
//
// r_editor_menu_view
// Menu for "View"
//
// ---------------------------------------------------------
//
RESOURCE MENU_PANE r_editor_menu_view
{
items =
{
MENU_ITEM {command = EEditorFullScreen; txt = "Full Screen";}
};
}
// ---------------------------------------------------------
//
// r_editor_menu_edit
// Menu for "Edit"
//
// ---------------------------------------------------------
//
RESOURCE MENU_PANE r_editor_menu_edit
{
items =
{
MENU_ITEM {command = EEditorCopy; txt = "Copy";},
MENU_ITEM {command = EEditorCut; txt = "Cut";},
MENU_ITEM {command = EEditorPaste; txt = "Paste";},
MENU_ITEM {command = EEditorSelectAll; txt = "Select All";}
};
}
I think thats all you need...
If we fall down it's so we can learn to pick ourselves up.
Forum posts: 68
However I've realized that if you don't have a default file then it doesn't work... If you come up with better code let me know.
Thanks,
Nikolas.
If we fall down it's so we can learn to pick ourselves up.
Forum posts: 53
I am sorry for the delay...
I am not able to solve...
I want to know why Register function is used in the code you have provided....
I have registered my application for the MIME type in my AIF file...
Do i still need to implement the register function?
Thanks for your help...
Pooja...
Forum posts: 68
However here is something you might find useful about OpenFileL:
The CEikDocument::OpenFileL function only works for files containing a filestore. A standard text file for example doesn't have a filestore so you can't use OpenFileL.
Now you can either create a filestore for your file and return it in OpenFileL (something which i don't know how to do) or you can just read the file by simply opening the file with Open method in RFile and reading the contents out in the OpenFileL method.
Thanks,
Nikolas.
Nikolas.
If we fall down it's so we can learn to pick ourselves up.
Forum posts: 4
is it possible to send me the code which you've written for the Editor?
I mean as a projectfile?
So I can compile it and take the useful parts for my Plain Text Editor.
I've already added the filelist example into my plaintexteditor.
But I need some hints to save and open a file into the editor.
Thank you
MY E-Mail funnyfrish(at)gmx(dot)at