S60 3rd Edition SDK for Symbian OS Example Applications Guide

# helloworldbasicappui.cpp

    00001 /*
    00002 * ==============================================================================
    00003 *  Name        : helloworldbasicappui.cpp
    00004 *  Part of     : Helloworldbasic
    00005 *  Interface   :
    00006 *  Description :
    00007 *  Version     :
    00008 *
    00009 *  Copyright (c) 2005-2006 Nokia Corporation.
    00010 *  This material, including documentation and any related
    00011 *  computer programs, is protected by copyright controlled by
    00012 *  Nokia Corporation.
    00013 * ==============================================================================
    00014 */
    00015
    00016 // INCLUDE FILES
    00017 #include <avkon.hrh>
    00018 #include <aknnotewrappers.h>
    00019 #include <stringloader.h>
    00020 #include <HelloWorldBasic.rsg>
    00021 #include <f32file.h>
    00022 #include <s32file.h>
    00023
    00024 #include "HelloWorldBasic.pan"
    00025 #include "HelloWorldBasicAppUi.h"
    00026 #include "HelloWorldBasicAppView.h"
    00027 #include "HelloWorldBasic.hrh"
    00028
    00029 _LIT( KHelloFileName, "\\private\\A000017F\\Hello.txt" );
    00030 _LIT( KHelloText, "HELLO WORLD!");
    00031
    00032 // ============================ MEMBER FUNCTIONS ===============================
    00033
    00034
    00035 // -----------------------------------------------------------------------------
    00036 // CHelloWorldBasicAppUi::ConstructL()
    00037 // Symbian 2nd phase constructor can leave.
    00038 // -----------------------------------------------------------------------------
    00039 //
    00040 void CHelloWorldBasicAppUi::ConstructL()
    00041     {
    00042     // Initialise app UI with standard value.
    00043     BaseConstructL(CAknAppUi::EAknEnableSkin);
    00044 // Here the Hello.txt file can be created, if it is not copied automatically.
    00045 /*
    00046         RFs fsSession;
    00047         User::LeaveIfError(fsSession.Connect());
    00048
    00049     RFile file;
    00050
    00051     // Create a file to write the text to
    00052         if ( file.Replace(fsSession, KHelloFileName, EFileWrite ) != KErrNone )
    00053         {
    00054                 return;
    00055         }
    00056         CleanupClosePushL( file );
    00057
    00058         RFileWriteStream outputFileStream( file );
    00059         CleanupClosePushL( outputFileStream );
    00060         outputFileStream << KHelloText;
    00061
    00062     CleanupStack::PopAndDestroy(2); // file, outputFileStream
    00063
    00064         fsSession.Close();
    00065 */
    00066
    00067     // Create view object
    00068     iAppView = CHelloWorldBasicAppView::NewL( ClientRect() );
    00069
    00070
    00071     }
    00072 // -----------------------------------------------------------------------------
    00073 // CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
    00074 // C++ default constructor can NOT contain any code, that might leave.
    00075 // -----------------------------------------------------------------------------
    00076 //
    00077 CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
    00078     {
    00079     // No implementation required
    00080     }
    00081
    00082 // -----------------------------------------------------------------------------
    00083 // CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
    00084 // Destructor.
    00085 // -----------------------------------------------------------------------------
    00086 //
    00087 CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
    00088     {
    00089     if ( iAppView )
    00090         {
    00091         delete iAppView;
    00092         iAppView = NULL;
    00093         }
    00094
    00095     }
    00096
    00097 // -----------------------------------------------------------------------------
    00098 // CHelloWorldBasicAppUi::HandleCommandL()
    00099 // Takes care of command handling.
    00100 // -----------------------------------------------------------------------------
    00101 //
    00102 void CHelloWorldBasicAppUi::HandleCommandL( TInt aCommand )
    00103     {
    00104     switch( aCommand )
    00105         {
    00106         case EEikCmdExit:
    00107         case EAknSoftkeyExit:
    00108             Exit();
    00109             break;
    00110
    00111         case EHelloWorldBasicCommand1:
    00112             {
    00113
    00114             // Load a string from the resource file and display it
    00115             HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT );
    00116             CAknInformationNote* informationNote;
    00117
    00118             informationNote = new ( ELeave ) CAknInformationNote;
    00119
    00120             // Show the information Note with
    00121             // textResource loaded with StringLoader.
    00122             informationNote->ExecuteLD( *textResource);
    00123
    00124             // Pop HBuf from CleanUpStack and Destroy it.
    00125             CleanupStack::PopAndDestroy( textResource );
    00126             }
    00127             break;
    00128                 case EHelloWorldBasicCommand2:
    00129                         {
    00130
    00131                         RFs fsSession;
    00132                         RFile rFile;
    00133
    00134                         // Connects a client process to the fileserver
    00135                         User::LeaveIfError(fsSession.Connect());
    00136                         CleanupClosePushL(fsSession);
    00137
    00138                         //Open file where the stream text is
    00139                         User::LeaveIfError(rFile.Open(fsSession,KHelloFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
    00140                         CleanupClosePushL(rFile);
    00141
    00142                         // copy stream from file to RFileStream object
    00143                         RFileReadStream inputFileStream(rFile);
    00144                 CleanupClosePushL(inputFileStream);
    00145
    00146                 // HBufC descriptor is created from the RFileStream object.
    00147                 HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
    00148
    00149             CAknInformationNote* informationNote;
    00150
    00151             informationNote = new ( ELeave ) CAknInformationNote;
    00152             // Show the information Note
    00153             informationNote->ExecuteLD( *fileData);
    00154
    00155                         // Pop loaded resources from the cleanup stack
    00156                         CleanupStack::PopAndDestroy(4); // filedata, inputFileStream, rFile, fsSession
    00157                         fsSession.Close();
    00158                         }
    00159                         break;
    00160         default:
    00161             Panic( EHelloWorldBasicUi );
    00162             break;
    00163         }
    00164     }
    00165 // -----------------------------------------------------------------------------
    00166 //  Called by the framework when the application status pane
    00167 //  size is changed.  Passes the new client rectangle to the
    00168 //  AppView
    00169 // -----------------------------------------------------------------------------
    00170 //
    00171 void CHelloWorldBasicAppUi::HandleStatusPaneSizeChange()
    00172 {
    00173         iAppView->SetRect( ClientRect() );
    00174
    00175 }
    00176
    00177 // End of File
    00178

© Nokia 2006 |