00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <avkon.hrh>
00020 #include <aknnotewrappers.h>
00021 #include <stringloader.h>
00022 #include <HelloWorldBasic.rsg>
00023 #include <f32file.h>
00024 #include <s32file.h>
00025
00026 #include "HelloWorldBasic.pan"
00027 #include "HelloWorldBasicAppUi.h"
00028 #include "HelloWorldBasicAppView.h"
00029 #include "HelloWorldBasic.hrh"
00030 #include "HelloWorldBasicQueryDialog.h"
00031
00032 _LIT( KHelloFileName, "Hello.txt" );
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 void CHelloWorldBasicAppUi::ConstructL()
00043 {
00044
00045 BaseConstructL(CAknAppUi::EAknEnableSkin);
00046
00047
00048
00049
00050
00051 RFs fsSession;
00052 User::LeaveIfError(fsSession.Connect());
00053 CleanupClosePushL( fsSession );
00054 TInt objectsInStack = 1;
00055
00056 #if defined(__WINS__) || defined(__WINSCW__)
00057
00058
00059
00060
00061 fsSession.CreatePrivatePath(EDriveC);
00062 #endif
00063
00064 RFile file;
00065
00066
00067 TInt err = file.Replace(fsSession, KHelloFileName, EFileWrite );
00068 if (KErrNone == err)
00069 {
00070 CleanupClosePushL( file );
00071
00072 RFileWriteStream outputFileStream( file );
00073 CleanupClosePushL( outputFileStream );
00074
00075
00076 HBufC* textResource = StringLoader::LoadLC( R_HEWB_FILE_TEXT );
00077 objectsInStack += 3;
00078
00079 outputFileStream << *textResource;
00080 }
00081 else
00082 {
00083 _LIT(KFileWriteFailed,"Writing file %S failed: error %d");
00084 CAknWarningNote* note = new ( ELeave ) CAknWarningNote(ETrue);
00085
00086 TBuf<64> text;
00087 text.Format(KFileWriteFailed, &KHelloFileName, err);
00088 note->ExecuteLD( text );
00089 }
00090
00091 CleanupStack::PopAndDestroy(objectsInStack, &fsSession);
00092
00093
00094 iAppView = CHelloWorldBasicAppView::NewL( ClientRect() );
00095
00096 }
00097
00098
00099
00100
00101
00102 CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
00103 {
00104
00105 }
00106
00107
00108
00109
00110
00111
00112 CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
00113 {
00114 if ( iAppView )
00115 {
00116 delete iAppView;
00117 iAppView = NULL;
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126 void CHelloWorldBasicAppUi::HandleCommandL( TInt aCommand )
00127 {
00128
00129 if (iAppView->GetText().Size() > 0)
00130 {
00131 iAppView->GetText().Zero();
00132 iAppView->DrawNow();
00133 }
00134
00135 switch( aCommand )
00136 {
00137 case EEikCmdExit:
00138 case EAknSoftkeyExit:
00139 Exit();
00140 break;
00141
00142 case EHelloWorldBasicCommand1:
00143 {
00144
00145 HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT );
00146 CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
00147
00148
00149
00150 note->ExecuteLD( *textResource );
00151
00152
00153 CleanupStack::PopAndDestroy( textResource );
00154 }
00155 break;
00156
00157 case EHelloWorldBasicCommand2:
00158 {
00159 RFs fsSession;
00160 RFile rFile;
00161
00162
00163 User::LeaveIfError(fsSession.Connect());
00164 CleanupClosePushL(fsSession);
00165
00166
00167 User::LeaveIfError(rFile.Open(fsSession,KHelloFileName, EFileStreamText));
00168 CleanupClosePushL(rFile);
00169
00170
00171 RFileReadStream inputFileStream(rFile);
00172 CleanupClosePushL(inputFileStream);
00173
00174
00175 HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
00176
00177 CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
00178
00179
00180 note->ExecuteLD( *fileData );
00181
00182
00183
00184 CleanupStack::PopAndDestroy(4, &fsSession);
00185 }
00186 break;
00187
00188 case EHelloWorldBasicCommand3:
00189 {
00190
00191 HBufC* defaultText = StringLoader::LoadLC( R_HEWB_FILE_TEXT );
00192
00193 CHelloWorldQueryDialog *dlg = new (ELeave)
00194 CHelloWorldQueryDialog( iAppView->GetText(), defaultText );
00195
00196 dlg->ExecuteLD( R_DIALOG_TEXT_EDIT_QUERY );
00197 iAppView->DrawNow();
00198
00199
00200 CleanupStack::PopAndDestroy( defaultText );
00201 }
00202 break;
00203
00204 default:
00205 break;
00206 }
00207 }
00208
00209
00210
00211
00212
00213 void CHelloWorldBasicAppUi::HandleResourceChangeL( TInt aType )
00214 {
00215
00216 CAknAppUi::HandleResourceChangeL(aType);
00217 if (aType == KEikDynamicLayoutVariantSwitch)
00218 {
00219 if (iAppView)
00220 iAppView->SetRect( ClientRect() );
00221 }
00222 }
00223
00224
00225