taskswitcher/testapplications/generator/generator/pattern/src/helloworldbasicappui.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <avkon.hrh>
       
    20 #include <aknnotewrappers.h>
       
    21 #include <stringloader.h>
       
    22 #include <HelloWorldBasic1.rsg>
       
    23 #include <f32file.h>
       
    24 #include <s32file.h>
       
    25 
       
    26 #include "HelloWorldBasic.pan"
       
    27 #include "HelloWorldBasicAppUi.h"
       
    28 #include "HelloWorldBasicAppView.h"
       
    29 #include "HelloWorldBasic.hrh"
       
    30 #include "HelloWorldBasicQueryDialog.h"
       
    31 
       
    32 _LIT( KHelloFileName, "Hello.txt" );
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CHelloWorldBasicAppUi::ConstructL()
       
    39 // Symbian 2nd phase constructor can leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 void CHelloWorldBasicAppUi::ConstructL()
       
    43     {
       
    44     // Initialise app UI with standard value.
       
    45     BaseConstructL(CAknAppUi::EAknEnableSkin);
       
    46 
       
    47     // Here the Hello.txt file is created. Because HelloWorld application is
       
    48     // localized to various languages, the Hello.txt-file is created every time
       
    49     // with current localization language
       
    50     //
       
    51     RFs fsSession;
       
    52     User::LeaveIfError(fsSession.Connect());
       
    53     CleanupClosePushL( fsSession );
       
    54     TInt objectsInStack = 1;
       
    55 
       
    56     #if defined(__WINS__) || defined(__WINSCW__)
       
    57     // create private folder, when testing in emulator.
       
    58     // ignore the return value; if this fails, then file.Replace() will fail
       
    59     // and a warning note will be printed.
       
    60     //
       
    61     fsSession.CreatePrivatePath(EDriveC);
       
    62     #endif
       
    63 
       
    64     RFile file;
       
    65 
       
    66     // Create a file to write the text to
       
    67     TInt err = file.Replace(fsSession, KHelloFileName, EFileWrite );
       
    68     if (KErrNone == err)
       
    69         {
       
    70         CleanupClosePushL( file );
       
    71 
       
    72         RFileWriteStream outputFileStream( file );
       
    73         CleanupClosePushL( outputFileStream );
       
    74 
       
    75         // Load a string from the resource file and stream it to file
       
    76         HBufC* textResource = StringLoader::LoadLC( R_HEWB_FILE_TEXT );
       
    77         objectsInStack += 3; // file, outputFileStream, testResource
       
    78 
       
    79         outputFileStream << *textResource;
       
    80         }
       
    81     else
       
    82         {
       
    83         _LIT(KFileWriteFailed,"Writing file %S failed: error %d");
       
    84         CAknWarningNote* note = new ( ELeave ) CAknWarningNote(ETrue);
       
    85 
       
    86         TBuf<64> text;
       
    87         text.Format(KFileWriteFailed, &KHelloFileName, err);
       
    88         note->ExecuteLD( text );
       
    89         }
       
    90 
       
    91     CleanupStack::PopAndDestroy(objectsInStack, &fsSession);
       
    92 
       
    93     // Create view object
       
    94     iAppView = CHelloWorldBasicAppView::NewL( ClientRect() );
       
    95     RProcess::Rendezvous(KErrNone);
       
    96 
       
    97     }
       
    98 // -----------------------------------------------------------------------------
       
    99 // CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
       
   100 // C++ default constructor can NOT contain any code, that might leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
       
   104     {
       
   105     // No implementation required
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
       
   110 // Destructor.
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
       
   114     {
       
   115     if ( iAppView )
       
   116         {
       
   117         delete iAppView;
       
   118         iAppView = NULL;
       
   119         }
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CHelloWorldBasicAppUi::HandleCommandL()
       
   124 // Takes care of command handling.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CHelloWorldBasicAppUi::HandleCommandL( TInt aCommand )
       
   128     {
       
   129     // clear possible old user-given text
       
   130     if (iAppView->GetText().Size() > 0)
       
   131         {
       
   132         iAppView->GetText().Zero();
       
   133         iAppView->DrawNow();
       
   134         }
       
   135 
       
   136     switch( aCommand )
       
   137         {
       
   138         case EEikCmdExit:
       
   139         case EAknSoftkeyExit:
       
   140             Exit();
       
   141             break;
       
   142 
       
   143         case EHelloWorldBasicCommand1:
       
   144             {
       
   145             // Load a string from the resource file and display it
       
   146             HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT );
       
   147             CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
   148 
       
   149             // Show the information Note with
       
   150             // textResource loaded with StringLoader.
       
   151             note->ExecuteLD( *textResource );
       
   152 
       
   153             // Pop HBuf from CleanUpStack and Destroy it.
       
   154             CleanupStack::PopAndDestroy( textResource );
       
   155             }
       
   156             break;
       
   157 
       
   158         case EHelloWorldBasicCommand2:
       
   159             {
       
   160             RFs fsSession;
       
   161             RFile rFile;
       
   162 
       
   163             // Connects a client process to the fileserver
       
   164             User::LeaveIfError(fsSession.Connect());
       
   165             CleanupClosePushL(fsSession);
       
   166 
       
   167             //Open file where the stream text is
       
   168             User::LeaveIfError(rFile.Open(fsSession,KHelloFileName, EFileStreamText));
       
   169             CleanupClosePushL(rFile);
       
   170 
       
   171             // copy stream from file to RFileStream object
       
   172             RFileReadStream inputFileStream(rFile);
       
   173             CleanupClosePushL(inputFileStream);
       
   174 
       
   175             // HBufC descriptor is created from the RFileStream object.
       
   176             HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
       
   177 
       
   178             CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
   179 
       
   180             // Show the information Note
       
   181             note->ExecuteLD( *fileData );
       
   182 
       
   183             // Pop loaded resources from the cleanup stack:
       
   184             // filedata, inputFileStream, rFile, fsSession
       
   185             CleanupStack::PopAndDestroy(4, &fsSession);
       
   186             }
       
   187             break;
       
   188 
       
   189         case EHelloWorldBasicCommand3:
       
   190             {
       
   191             // Load a string from the resources and use it as a default value
       
   192             HBufC* defaultText = StringLoader::LoadLC( R_HEWB_FILE_TEXT );
       
   193 
       
   194             CHelloWorldQueryDialog *dlg = new (ELeave)
       
   195                 CHelloWorldQueryDialog( iAppView->GetText(), defaultText );
       
   196 
       
   197             dlg->ExecuteLD( R_DIALOG_TEXT_EDIT_QUERY );
       
   198             iAppView->DrawNow();
       
   199 
       
   200             // Pop HBuf from CleanUpStack and Destroy it.
       
   201             CleanupStack::PopAndDestroy( defaultText );
       
   202             }
       
   203             break;
       
   204 
       
   205         default:
       
   206             break;
       
   207         }
       
   208     }
       
   209 // -----------------------------------------------------------------------------
       
   210 //  Called by framework when layout is changed.
       
   211 //  Passes the new client rectangle to the AppView
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CHelloWorldBasicAppUi::HandleResourceChangeL( TInt aType )
       
   215 {
       
   216     // base-class call also
       
   217     CAknAppUi::HandleResourceChangeL(aType);
       
   218     if (aType == KEikDynamicLayoutVariantSwitch)
       
   219         {
       
   220         if (iAppView)
       
   221             iAppView->SetRect( ClientRect() );
       
   222         }
       
   223 }
       
   224 
       
   225 // End of File
       
   226