X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=symbian%2FPerlApp.cpp;h=ffca7afc52c2674b7fcf09baa5feeb4e5b442603;hb=9487c2fc1a7c5851aa2ef68b55b8b1db0cffa826;hp=f5fa29ee0791ff7330616be20b9498bf0e828bc6;hpb=ed76c0e43f6496020fbf49e22ea9651b31346e91;p=p5sagit%2Fp5-mst-13.2.git diff --git a/symbian/PerlApp.cpp b/symbian/PerlApp.cpp index f5fa29e..ffca7af 100644 --- a/symbian/PerlApp.cpp +++ b/symbian/PerlApp.cpp @@ -1,26 +1,12 @@ /* Copyright (c) 2004-2005 Nokia. All rights reserved. */ /* The PerlApp application is licensed under the same terms as Perl itself. - * Note that this PerlApp is for Symbian/Series 60/80 smartphones and it has - * nothing whatsoever to do with the ActiveState PerlApp. */ + * + * Note that this PerlApp is for Symbian/Series 60/80/UIQ smartphones + * and it has nothing whatsoever to do with the ActiveState PerlApp. */ #include "PerlApp.h" -#ifdef __SERIES60__ -# include -# include -# include -# ifndef __SERIES60_1X__ -# include -# endif -#endif /* #ifdef __SERIES60__ */ - -#ifdef __SERIES80__ -# include -# include -# include -#endif /* #ifdef __SERIES80__ */ - #include #include #include @@ -32,21 +18,27 @@ #include -#ifndef PerlMin +#ifndef PerlAppMinimal #include "PerlApp.hrh" -#include "PerlApp.rsg" +#endif //#ifndef PerlAppMinimal -#endif //#ifndef PerlMin +#define PERL_GLOBAL_STRUCT +#define PERL_GLOBAL_STRUCT_PRIVATE #include "EXTERN.h" #include "perl.h" +#include "XSUB.h" + #include "PerlBase.h" +#include "PerlUtil.h" + +#define symbian_get_vars() Dll::Tls() // Not visible from perlXYZ.lib? const TUid KPerlAppUid = { -#ifdef PerlMinUid - PerlMinUid +#ifdef PerlAppMinimalUid + PerlAppMinimalUid #else 0x102015F6 #endif @@ -54,20 +46,13 @@ const TUid KPerlAppUid = { _LIT(KDefaultScript, "default.pl"); -// This is like the Symbian _LIT() but without the embedded L prefix, -// which enables using #defined constants (which need to carry their -// own L prefix). -#ifndef _LIT_NO_L -# define _LIT_NO_L(n, s) static const TLitC n={sizeof(s)/2-1,s} -#endif // #ifndef _LIT_NO_L - -#ifdef PerlMinName -_LIT_NO_L(KAppName, PerlMinName); +#ifdef PerlAppMinimalName +_LIT_NO_L(KAppName, PerlAppMinimalName); #else _LIT(KAppName, "PerlApp"); #endif -#ifndef PerlMin +#ifndef PerlAppMinimal _LIT_NO_L(KFlavor, PERL_SYMBIANSDK_FLAVOR); _LIT(KAboutFormat, @@ -83,12 +68,7 @@ typedef TBuf<256> TMessageBuffer; typedef TBuf8<256> TPeekBuffer; typedef TBuf8<256> TFileName8; -#endif // #ifndef PerlMin - -// Usage: DEBUG_PRINTF((_L("%S"), &aStr)) -#if 1 -#define DEBUG_PRINTF(s) {TMessageBuffer message; message.Format s; YesNoDialogL(message);} -#endif +#endif // #ifndef PerlAppMinimal static void DoRunScriptL(TFileName aScriptName); @@ -97,7 +77,7 @@ TUid CPerlAppApplication::AppDllUid() const return KPerlAppUid; } -enum TPerlAppPanic +enum TPerlAppPanic { EPerlAppCommandUnknown = 1 }; @@ -107,125 +87,7 @@ void Panic(TPerlAppPanic aReason) User::Panic(KAppName, aReason); } -void CPerlAppUi::ConstructL() -{ - BaseConstructL(); - iAppView = CPerlAppView::NewL(ClientRect()); - AddToStackL(iAppView); - iFs = NULL; - CEikonEnv::Static()->DisableExitChecks(ETrue); // Symbian FAQ-0577. -} - -CPerlAppUi::~CPerlAppUi() -{ - if (iAppView) { - iEikonEnv->RemoveFromStack(iAppView); - delete iAppView; - iAppView = NULL; - } - if (iFs) { - delete iFs; - iFs = NULL; - } - if (iDoorObserver) // Otherwise the embedding application waits forever. - iDoorObserver->NotifyExit(MApaEmbeddedDocObserver::EEmpty); -} - -#ifndef PerlMin - -#ifdef __SERIES60__ - -static TBool DlgOk(CAknNoteDialog* dlg) -{ - return dlg && dlg->RunDlgLD() == EAknSoftkeyOk; -} - -#endif /* #ifdef __SERIES60__ */ - -static TBool OkCancelDialogL(TDesC& aMessage) -{ -#ifdef __SERIES60__ - CAknNoteDialog* dlg = - new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone); - dlg->PrepareLC(R_OK_CANCEL_DIALOG); - dlg->SetTextL(aMessage); - return DlgOk(dlg); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - return CCknFlashingDialog::RunDlgLD(_L("OK/Cancel"), aMessage, NULL, - CCknFlashingDialog::EShort, - NULL); -#endif /* #ifdef __SERIES80__ */ -} - -static TBool YesNoDialogL(TDesC& aMessage) -{ -#ifdef __SERIES60__ - CAknNoteDialog* dlg = - new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone); - dlg->PrepareLC(R_YES_NO_DIALOG); - dlg->SetTextL(aMessage); - return DlgOk(dlg); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - return CCknFlashingDialog::RunDlgLD(_L("Yes/No"), aMessage, NULL, - CCknFlashingDialog::EShort, - NULL); -#endif /* #ifdef __SERIES80__ */ -} - -static TInt InformationNoteL(TDesC& aMessage) -{ -#ifdef __SERIES60__ - CAknInformationNote* note = new (ELeave) CAknInformationNote; - return note->ExecuteLD(aMessage); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - return CCknFlashingDialog::RunDlgLD(_L("Info"), aMessage, NULL, - CCknFlashingDialog::ENormal, - NULL); -#endif /* #ifdef __SERIES80__ */ -} - -static TInt ConfirmationNoteL(TDesC& aMessage) -{ -#ifdef __SERIES60__ - CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote; - return note->ExecuteLD(aMessage); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - return CCknFlashingDialog::RunDlgLD(_L("Confirmation"), aMessage, NULL, - CCknFlashingDialog::ENormal, - NULL); -#endif /* #ifdef __SERIES80__ */ -} - -static TInt WarningNoteL(TDesC& aMessage) -{ -#ifdef __SERIES60__ - CAknWarningNote* note = new (ELeave) CAknWarningNote; - return note->ExecuteLD(aMessage); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - CEikonEnv::Static()->AlertWin(aMessage); - return ETrue; -#endif /* #ifdef __SERIES80__ */ -} - -static TInt TextQueryDialogL(const TDesC& aPrompt, TDes& aData, const TInt aMaxLength) -{ -#ifdef __SERIES60__ - CAknTextQueryDialog* dlg = - new (ELeave) CAknTextQueryDialog(aData); - dlg->SetPromptL(aPrompt); - dlg->SetMaxLength(aMaxLength); - return dlg->ExecuteLD(R_TEXT_QUERY_DIALOG); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - /* TODO */ - return ETrue; -#endif -} +#ifndef PerlAppMinimal // The isXXX() come from the Perl headers. #define FILENAME_IS_ABSOLUTE(n) \ @@ -253,12 +115,12 @@ static TBool IsInInbox(TFileName aFileName) static TBool IsPerlModule(TParsePtrC aParsed) { - return aParsed.Ext().CompareF(_L(".pm")) == 0; + return aParsed.Ext().CompareF(_L(".pm")) == 0; } static TBool IsPerlScript(TParsePtrC aParsed) { - return aParsed.Ext().CompareF(_L(".pl")) == 0; + return aParsed.Ext().CompareF(_L(".pl")) == 0; } static void CopyFromInboxL(RFs aFs, const TFileName& aSrc, const TFileName& aDst) @@ -267,12 +129,12 @@ static void CopyFromInboxL(RFs aFs, const TFileName& aSrc, const TFileName& aDst TMessageBuffer message; message.Format(_L("%S is untrusted. Install only if you trust provider."), &aDst); - if (OkCancelDialogL(message)) { + if (CPerlUi::OkCancelDialogL(message)) { message.Format(_L("Install as %S?"), &aDst); - if (OkCancelDialogL(message)) { + if (CPerlUi::OkCancelDialogL(message)) { if (BaflUtils::FileExists(aFs, aDst)) { message.Format(_L("Replace old %S?"), &aDst); - if (!OkCancelDialogL(message)) + if (!CPerlUi::OkCancelDialogL(message)) proceed = EFalse; } if (proceed) { @@ -280,11 +142,11 @@ static void CopyFromInboxL(RFs aFs, const TFileName& aSrc, const TFileName& aDst TInt err = BaflUtils::CopyFile(aFs, aSrc, aDst); if (err == KErrNone) { message.Format(_L("Installed %S"), &aDst); - ConfirmationNoteL(message); + CPerlUi::InformationNoteL(message); } else { message.Format(_L("Failure %d installing %S"), err, &aDst); - WarningNoteL(message); + CPerlUi::WarningNoteL(message); } } } @@ -320,7 +182,7 @@ static TBool FindPerlPackageName(TPeekBuffer aPeekBuffer, TInt aOff, TFileName& isALPHA(aPeekBuffer[j])) { while (j < n && isALNUM(aPeekBuffer[j]) && - i < m) + i < m) aFn[i++] = aPeekBuffer[j++]; } } @@ -376,7 +238,7 @@ static TBool InstallStuffL(const TFileName &aSrc, TParse aDrive, TParse aFile, T { TFileName aDst; TPtrC drive = aDrive.Drive(); - TPtrC namext = aFile.NameAndExt(); + TPtrC namext = aFile.NameAndExt(); aDst.Format(_L("%S%S%S"), &drive, &KScriptPrefix, &namext); if (!IsPerlScript(aDst) && !LooksLikePerlL(aPeekBuffer)) { @@ -404,18 +266,17 @@ static TBool RunStuffL(const TFileName& aScriptName, TPeekBuffer aPeekBuffer) if (isModule) message.Format(_L("Really run module %S?"), &aScriptName); - else + else message.Format(_L("Run %S?"), &aScriptName); - if (YesNoDialogL(message)) + if (CPerlUi::YesNoDialogL(message)) DoRunScriptL(aScriptName); - return ETrue; } return EFalse; } -void CPerlAppUi::InstallOrRunL(const TFileName& aFileName) +void CPerlAppAppUi::InstallOrRunL(const TFileName& aFileName) { TParse aFile; TParse aDrive; @@ -442,15 +303,15 @@ void CPerlAppUi::InstallOrRunL(const TFileName& aFileName) InstallStuffL(aFileName, aDrive, aFile, aPeekBuffer, *iFs) : RunStuffL(aFileName, aPeekBuffer))) { message.Format(_L("Failed for file %S"), &aFileName); - WarningNoteL(message); + CPerlUi::WarningNoteL(message); } } else { message.Format(_L("Error %d reading %S"), err, &aFileName); - WarningNoteL(message); + CPerlUi::WarningNoteL(message); } } else { message.Format(_L("Error %d opening %S"), err, &aFileName); - WarningNoteL(message); + CPerlUi::WarningNoteL(message); } if (iDoorObserver) delete CEikonEnv::Static()->EikAppUi(); @@ -458,33 +319,48 @@ void CPerlAppUi::InstallOrRunL(const TFileName& aFileName) Exit(); } -#endif // #ifndef PerlMin +#endif /* #ifndef PerlAppMinimal */ + +CPerlAppAppUi::~CPerlAppAppUi() +{ + if (iAppView) { + iEikonEnv->RemoveFromStack(iAppView); + delete iAppView; + iAppView = NULL; + } + if (iFs) { + delete iFs; + iFs = NULL; + } + if (iDoorObserver) // Otherwise the embedding application waits forever. + iDoorObserver->NotifyExit(MApaEmbeddedDocObserver::EEmpty); +} static void DoRunScriptL(TFileName aScriptName) { CPerlBase* perl = CPerlBase::NewInterpreterLC(); TRAPD(error, perl->RunScriptL(aScriptName)); -#ifndef PerlMin +#ifndef PerlAppMinimal if (error != KErrNone) { TMessageBuffer message; message.Format(_L("Error %d"), error); - YesNoDialogL(message); + CPerlUi::YesNoDialogL(message); } -#endif // #ifndef PerlMin +#endif // #ifndef PerlAppMinimal CleanupStack::PopAndDestroy(perl); } -#ifndef PerlMin +#ifndef PerlAppMinimal -void CPerlAppUi::OpenFileL(const TDesC& aFileName) +void CPerlAppAppUi::OpenFileL(const TDesC& aFileName) { InstallOrRunL(aFileName); return; } -#endif // #ifndef PerlMin +#endif // #ifndef PerlAppMinimal -TBool CPerlAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& /* aDocumentName */, const TDesC8& /* aTail */) +TBool CPerlAppAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& /* aDocumentName */, const TDesC8& /* aTail */) { if (aCommand == EApaCommandRun) { TFileName appName = Application()->AppFullName(); @@ -501,23 +377,23 @@ TBool CPerlAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& /* return aCommand == EApaCommandOpen ? ETrue : EFalse; } -#ifndef PerlMin +#ifndef PerlAppMinimal -void CPerlAppUi::SetFs(const RFs& aFs) +void CPerlAppAppUi::SetFs(const RFs& aFs) { iFs = (RFs*) &aFs; } -#endif // #ifndef PerlMin +#endif // #ifndef PerlAppMinimal -static void DoHandleCommandL(TInt aCommand) { -#ifndef PerlMin +void CPerlAppAppUi::DoHandleCommandL(TInt aCommand) { +#ifndef PerlAppMinimal TMessageBuffer message; -#endif // #ifndef PerlMin +#endif // #ifndef PerlAppMinimal switch(aCommand) { -#ifndef PerlMin +#ifndef PerlAppMinimal case EPerlAppCommandAbout: { message.Format(KAboutFormat, @@ -531,7 +407,7 @@ static void DoHandleCommandL(TInt aCommand) { PERL_SYMBIANSDK_MAJOR, PERL_SYMBIANSDK_MINOR ); - InformationNoteL(message); + CPerlUi::InformationNoteL(message); } break; case EPerlAppCommandTime: @@ -544,57 +420,56 @@ static void DoHandleCommandL(TInt aCommand) { CleanupStack::PopAndDestroy(perl); } break; +#ifndef __UIQ__ case EPerlAppCommandRunFile: { TFileName aScriptUtf16; -#ifdef __SERIES60__ - if (AknCommonDialogs::RunSelectDlgLD(aScriptUtf16, - R_MEMORY_SELECTION_DIALOG)) - DoRunScriptL(aScriptUtf16); -#endif /* #ifdef __SERIES60__ */ -#ifdef __SERIES80__ - aScriptUtf16.Copy(_L("C:\\")); - if (CCknOpenFileDialog::RunDlgLD(aScriptUtf16, - CCknOpenFileDialog::EShowSystemFilesAndFolders | - CCknOpenFileDialog::EShowHiddenFilesAndFolders | - CCknOpenFileDialog::EShowAllDrives | - CCknOpenFileDialog::EShowExtendedView | - CCknOpenFileDialog::EShowNoFilesText) { - /* TODO: despite all the above flags still does not seem - * to allow navigating outside the default directory. */ - TEntry aEntry; - RFs aFs; - aFs.Connect(); - if (aFs.Entry(aScriptUtf16, aEntry) == KErrNone) - DoRunScriptL(aScriptUtf16); - /* else show error message? */ - } -#endif /* #ifdef __SERIES80__ */ - } + aScriptUtf16.Copy(_L("C:\\")); + if (CPerlUi::FileQueryDialogL(aScriptUtf16)) + DoRunScriptL(aScriptUtf16); + } break; +#endif case EPerlAppCommandOneLiner: { +#ifdef __SERIES60__ _LIT(prompt, "Oneliner:"); - CPerlAppUi* cAppUi = - STATIC_CAST(CPerlAppUi*, CEikonEnv::Static()->EikAppUi()); - if (TextQueryDialogL(prompt, - cAppUi->iOneLiner, - KPerlAppOneLinerSize)) { - const TUint KPerlAppUtf8Multi = 3; - TBuf8 utf8; - - CnvUtfConverter::ConvertFromUnicodeToUtf8(utf8, cAppUi->iOneLiner); +#endif /* #ifdef __SERIES60__ */ +#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) + _LIT(prompt, "Code:"); // The title has "Oneliner" already. +#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */ + CPerlAppAppUi* cAppUi = + static_cast(CEikonEnv::Static()->EikAppUi()); + if (CPerlUi::TextQueryDialogL(_L("Oneliner"), + prompt, + cAppUi->iOneLiner, + KPerlUiOneLinerSize)) { + const TUint KPerlUiUtf8Multi = 3; // Expansion multiplier. + TBuf8 utf8; + + CnvUtfConverter::ConvertFromUnicodeToUtf8(utf8, + cAppUi->iOneLiner); CPerlBase* perl = CPerlBase::NewInterpreterLC(); - int argc = 3; - char **argv = (char**) malloc(argc * sizeof(char *)); +#ifdef __SERIES90__ + int argc = 5; +#else + int argc = 3; +#endif + char **argv = (char**) malloc(argc * sizeof(char *)); User::LeaveIfNull(argv); TCleanupItem argvCleanupItem = TCleanupItem(free, argv); CleanupStack::PushL(argvCleanupItem); argv[0] = (char *) "perl"; argv[1] = (char *) "-le"; +#ifdef __SERIES90__ + argv[2] = (char *) "unshift @INC, 'C:/Mydocs';"; + argv[3] = (char *) "-e"; + argv[4] = (char *) utf8.PtrZ(); +#else argv[2] = (char *) utf8.PtrZ(); - perl->ParseAndRun(argc, argv); +#endif + perl->ParseAndRun(argc, argv); CleanupStack::PopAndDestroy(2, perl); } } @@ -602,135 +477,64 @@ static void DoHandleCommandL(TInt aCommand) { case EPerlAppCommandCopyright: { message.Format(KCopyrightFormat); - InformationNoteL(message); + CPerlUi::InformationNoteL(message); } break; case EPerlAppCommandAboutCopyright: { - TMessageBuffer m1; - TMessageBuffer m2; + TMessageBuffer m1; + TMessageBuffer m2; m1.Format(KAboutFormat, - PERL_REVISION, - PERL_VERSION, - PERL_SUBVERSION, - PERL_SYMBIANPORT_MAJOR, - PERL_SYMBIANPORT_MINOR, - PERL_SYMBIANPORT_PATCH, - &KFlavor, - PERL_SYMBIANSDK_MAJOR, - PERL_SYMBIANSDK_MINOR - ); - InformationNoteL(message); + PERL_REVISION, + PERL_VERSION, + PERL_SUBVERSION, + PERL_SYMBIANPORT_MAJOR, + PERL_SYMBIANPORT_MINOR, + PERL_SYMBIANPORT_PATCH, + &KFlavor, + PERL_SYMBIANSDK_MAJOR, + PERL_SYMBIANSDK_MINOR + ); + CPerlUi::InformationNoteL(m1); + User::After((TTimeIntervalMicroSeconds32) (1000*1000)); // 1 sec. m2.Format(KCopyrightFormat); - message.Format(_L("%S %S"), &m1, &m2); - InformationNoteL(message); + CPerlUi::InformationNoteL(m2); } break; -#endif // #ifndef PerlMin +#endif // #ifndef PerlAppMinimal default: Panic(EPerlAppCommandUnknown); } } -#ifdef __SERIES60__ - -void CPerlAppUi::HandleCommandL(TInt aCommand) -{ - switch(aCommand) - { - case EEikCmdExit: - case EAknSoftkeyExit: - Exit(); - break; - default: - DoHandleCommandL(aCommand); - break; - } -} - -#endif /* #ifdef __SERIES60__ */ - -#ifdef __SERIES80__ - -void CPerlAppView::HandleCommandL(TInt aCommand) { - DoHandleCommandL(aCommand); -} - -void CPerlAppUi::HandleCommandL(TInt aCommand) { - switch(aCommand) - { - case EEikCmdExit: - Exit(); - break; - default: - iAppView->HandleCommandL(aCommand); - break; - } -} - -#endif /* #ifdef __SERIES80__ */ - -CPerlAppView* CPerlAppView::NewL(const TRect& aRect) -{ - CPerlAppView* self = CPerlAppView::NewLC(aRect); - CleanupStack::Pop(self); - return self; -} - -CPerlAppView* CPerlAppView::NewLC(const TRect& aRect) -{ - CPerlAppView* self = new (ELeave) CPerlAppView; - CleanupStack::PushL(self); - self->ConstructL(aRect); - return self; -} - -void CPerlAppView::ConstructL(const TRect& aRect) -{ - CreateWindowL(); - SetRect(aRect); - ActivateL(); -} - -CPerlAppView::~CPerlAppView() -{ -} - -void CPerlAppView::Draw(const TRect& /*aRect*/) const -{ - CWindowGc& gc = SystemGc(); - TRect rect = Rect(); - gc.Clear(rect); -} - -CApaDocument* CPerlAppApplication::CreateDocumentL() +CApaDocument* CPerlAppApplication::CreateDocumentL() { - CPerlAppDocument* document = new (ELeave) CPerlAppDocument(*this); - return document; + CPerlAppDocument* cDoc = new (ELeave) CPerlAppDocument(*this); + return cDoc; } CEikAppUi* CPerlAppDocument::CreateAppUiL() { - CPerlAppUi* appui = new (ELeave) CPerlAppUi(); - return appui; + CPerlAppAppUi* cAppUi = new (ELeave) CPerlAppAppUi(); + return cAppUi; } -#ifndef PerlMin +#ifndef PerlAppMinimal CFileStore* CPerlAppDocument::OpenFileL(TBool aDoOpen, const TDesC& aFileName, RFs& aFs) { - CPerlAppUi* appui = - STATIC_CAST(CPerlAppUi*, CEikonEnv::Static()->EikAppUi()); - appui->SetFs(aFs); + CPerlAppAppUi* cAppUi = + static_cast(CEikonEnv::Static()->EikAppUi()); + cAppUi->SetFs(aFs); if (aDoOpen) - appui->OpenFileL(aFileName); + cAppUi->OpenFileL(aFileName); return NULL; } -#endif // #ifndef PerlMin +#endif // #ifndef PerlAppMinimal -EXPORT_C CApaApplication* NewApplication() +EXPORT_C CApaApplication* NewApplication() { return new CPerlAppApplication; }