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