/* Copyright (c) 2004-2005 Nokia. All rights reserved. */
-/* The PerlApp application is licensed under the same terms as Perl itself. */
+/* The PerlApp application is licensed under the same terms as Perl itself.
+ *
+ * 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"
-#include <avkon.hrh>
-#include <aknnotewrappers.h>
#include <apparc.h>
#include <e32base.h>
#include <e32cons.h>
#include <utf.h>
#include <f32file.h>
-#include <AknCommonDialogs.h>
-
-#ifndef __SERIES60_1X__
-#include <CAknFileSelectionDialog.h>
-#endif
-
#include <coemain.h>
+#ifndef PerlAppMinimal
+
#include "PerlApp.hrh"
-#include "PerlApp.rsg"
-#include "patchlevel.h"
+#endif //#ifndef PerlAppMinimal
+
+#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 = { 0x102015F6 };
+const TUid KPerlAppUid = {
+#ifdef PerlAppMinimalUid
+ PerlAppMinimalUid
+#else
+ 0x102015F6
+#endif
+};
-// 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<sizeof(s)/2> n={sizeof(s)/2-1,s}
-#endif // #ifndef _LIT_NO_L
+_LIT(KDefaultScript, "default.pl");
+#ifdef PerlAppMinimalName
+_LIT_NO_L(KAppName, PerlAppMinimalName);
+#else
_LIT(KAppName, "PerlApp");
+#endif
+
+#ifndef PerlAppMinimal
+
_LIT_NO_L(KFlavor, PERL_SYMBIANSDK_FLAVOR);
_LIT(KAboutFormat,
"Perl %d.%d.%d, Symbian port %d.%d.%d, built for %S SDK %d.%d");
typedef TBuf8<256> TPeekBuffer;
typedef TBuf8<256> TFileName8;
-// 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);
TUid CPerlAppApplication::AppDllUid() const
{
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);
-}
-
-static TBool DlgOk(CAknNoteDialog* dlg)
-{
- return dlg && dlg->RunDlgLD() == EAknSoftkeyOk;
-}
-
-static TBool OkCancelDialogL(TDesC& aMessage)
-{
- CAknNoteDialog* dlg =
- new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone);
- dlg->PrepareLC(R_OK_CANCEL_DIALOG);
- dlg->SetTextL(aMessage);
- return DlgOk(dlg);
-}
-
-static TBool YesNoDialogL(TDesC& aMessage)
-{
- CAknNoteDialog* dlg =
- new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone);
- dlg->PrepareLC(R_YES_NO_DIALOG);
- dlg->SetTextL(aMessage);
- return DlgOk(dlg);
-}
-
-static TInt InformationNoteL(TDesC& aMessage)
-{
- CAknInformationNote* note = new (ELeave) CAknInformationNote;
- return note->ExecuteLD(aMessage);
-}
-
-static TInt ConfirmationNoteL(TDesC& aMessage)
-{
- CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote;
- return note->ExecuteLD(aMessage);
-}
-
-static TInt WarningNoteL(TDesC& aMessage)
-{
- CAknWarningNote* note = new (ELeave) CAknWarningNote;
- return note->ExecuteLD(aMessage);
-}
-
-static TInt TextQueryDialogL(const TDesC& aPrompt, TDes& aData, const TInt aMaxLength)
-{
- CAknTextQueryDialog* dlg =
- new (ELeave) CAknTextQueryDialog(aData);
- dlg->SetPromptL(aPrompt);
- dlg->SetMaxLength(aMaxLength);
- return dlg->ExecuteLD(R_TEXT_QUERY_DIALOG);
-}
+#ifndef PerlAppMinimal
// The isXXX() come from the Perl headers.
#define FILENAME_IS_ABSOLUTE(n) \
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) {
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);
}
}
}
return EFalse;
}
-static void DoRunScriptL(TFileName aScriptName)
-{
- CPerlBase* perl = CPerlBase::NewInterpreterLC();
- TRAPD(error, perl->RunScriptL(aScriptName));
- if (error != KErrNone) {
- TMessageBuffer message;
- message.Format(_L("Error %d"), error);
- YesNoDialogL(message);
- }
- CleanupStack::PopAndDestroy(perl);
-}
-
static TBool RunStuffL(const TFileName& aScriptName, TPeekBuffer aPeekBuffer)
{
TBool isModule = EFalse;
message.Format(_L("Really run module %S?"), &aScriptName);
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;
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();
Exit();
}
-void CPerlAppUi::OpenFileL(const TDesC& aFileName)
+#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 PerlAppMinimal
+ if (error != KErrNone) {
+ TMessageBuffer message;
+ message.Format(_L("Error %d"), error);
+ CPerlUi::YesNoDialogL(message);
+ }
+#endif // #ifndef PerlAppMinimal
+ CleanupStack::PopAndDestroy(perl);
+}
+
+#ifndef PerlAppMinimal
+
+void CPerlAppAppUi::OpenFileL(const TDesC& aFileName)
{
InstallOrRunL(aFileName);
return;
}
-TBool CPerlAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& /* aDocumentName */, const TDesC8& /* aTail */)
+#endif // #ifndef PerlAppMinimal
+
+TBool CPerlAppAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& /* aDocumentName */, const TDesC8& /* aTail */)
{
+ if (aCommand == EApaCommandRun) {
+ TFileName appName = Application()->AppFullName();
+ TParse p;
+ p.Set(KDefaultScript, &appName, NULL);
+ TEntry aEntry;
+ RFs aFs;
+ aFs.Connect();
+ if (aFs.Entry(p.FullName(), aEntry) == KErrNone) {
+ DoRunScriptL(p.FullName());
+ Exit();
+ }
+ }
return aCommand == EApaCommandOpen ? ETrue : EFalse;
}
-void CPerlAppUi::SetFs(const RFs& aFs)
+#ifndef PerlAppMinimal
+
+void CPerlAppAppUi::SetFs(const RFs& aFs)
{
iFs = (RFs*) &aFs;
}
-void CPerlAppUi::HandleCommandL(TInt aCommand)
-{
+#endif // #ifndef PerlAppMinimal
+
+void CPerlAppAppUi::DoHandleCommandL(TInt aCommand) {
+#ifndef PerlAppMinimal
TMessageBuffer message;
+#endif // #ifndef PerlAppMinimal
switch(aCommand)
{
- case EEikCmdExit:
- case EAknSoftkeyExit:
- Exit();
- break;
+#ifndef PerlAppMinimal
case EPerlAppCommandAbout:
{
message.Format(KAboutFormat,
PERL_SYMBIANSDK_MAJOR,
PERL_SYMBIANSDK_MINOR
);
- InformationNoteL(message);
+ CPerlUi::InformationNoteL(message);
}
break;
case EPerlAppCommandTime:
CleanupStack::PopAndDestroy(perl);
}
break;
+#ifndef __UIQ__
case EPerlAppCommandRunFile:
{
- InformationNoteL(message);
TFileName aScriptUtf16;
- if (AknCommonDialogs::RunSelectDlgLD(aScriptUtf16,
- R_MEMORY_SELECTION_DIALOG))
- DoRunScriptL(aScriptUtf16);
+ aScriptUtf16.Copy(_L("C:\\"));
+ if (CPerlUi::FileQueryDialogL(aScriptUtf16))
+ DoRunScriptL(aScriptUtf16);
}
break;
+#endif
case EPerlAppCommandOneLiner:
{
+#ifdef __SERIES60__
_LIT(prompt, "Oneliner:");
- if (TextQueryDialogL(prompt, iOneLiner, KPerlAppOneLinerSize)) {
- const TUint KPerlAppUtf8Multi = 3;
- TBuf8<KPerlAppUtf8Multi * KPerlAppOneLinerSize> utf8;
-
- CnvUtfConverter::ConvertFromUnicodeToUtf8(utf8, iOneLiner);
+#endif /* #ifdef __SERIES60__ */
+#if defined(__SERIES80__) || defined(__UIQ__)
+ _LIT(prompt, "Code:"); // The title has "Oneliner" already.
+#endif /* #if defined(__SERIES80__) || defined(__UIQ__) */
+ CPerlAppAppUi* cAppUi =
+ static_cast<CPerlAppAppUi*>(CEikonEnv::Static()->EikAppUi());
+ if (CPerlUi::TextQueryDialogL(_L("Oneliner"),
+ prompt,
+ cAppUi->iOneLiner,
+ KPerlUiOneLinerSize)) {
+ const TUint KPerlUiUtf8Multi = 3; // Expansion multiplier.
+ TBuf8<KPerlUiUtf8Multi * KPerlUiOneLinerSize> utf8;
+
+ CnvUtfConverter::ConvertFromUnicodeToUtf8(utf8,
+ cAppUi->iOneLiner);
CPerlBase* perl = CPerlBase::NewInterpreterLC();
int argc = 3;
char **argv = (char**) malloc(argc * sizeof(char *));
case EPerlAppCommandCopyright:
{
message.Format(KCopyrightFormat);
- InformationNoteL(message);
+ CPerlUi::InformationNoteL(message);
}
break;
-
+ case EPerlAppCommandAboutCopyright:
+ {
+ 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
+ );
+ CPerlUi::InformationNoteL(m1);
+ User::After((TTimeIntervalMicroSeconds32) (1000*1000)); // 1 sec.
+ m2.Format(KCopyrightFormat);
+ CPerlUi::InformationNoteL(m2);
+ }
+ break;
+#endif // #ifndef PerlAppMinimal
default:
Panic(EPerlAppCommandUnknown);
- break;
}
}
-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();
-}
-
-void CPerlAppView::Draw(const TRect& /*aRect*/) const
-{
- CWindowGc& gc = SystemGc();
- TRect rect = Rect();
- gc.Clear(rect);
-}
-
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;
}
-CFileStore* CPerlAppDocument::OpenFileL(TBool /* aDoOpen */, const TDesC& aFileName, RFs& aFs)
+
+#ifndef PerlAppMinimal
+
+CFileStore* CPerlAppDocument::OpenFileL(TBool aDoOpen, const TDesC& aFileName, RFs& aFs)
{
- CPerlAppUi* appui =
- STATIC_CAST(CPerlAppUi*, CEikonEnv::Static()->EikAppUi());
- appui->SetFs(aFs);
- appui->OpenFileL(aFileName);
+ CPerlAppAppUi* cAppUi =
+ static_cast<CPerlAppAppUi*>(CEikonEnv::Static()->EikAppUi());
+ cAppUi->SetFs(aFs);
+ if (aDoOpen)
+ cAppUi->OpenFileL(aFileName);
return NULL;
}
+#endif // #ifndef PerlAppMinimal
+
EXPORT_C CApaApplication* NewApplication()
{
return new CPerlAppApplication;