00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "SMSExampleAppui.h"
00032 #include <SMSExample.rsg>
00033 #include "SMSExample.hrh"
00034 #include "SMSExampleLogView.h"
00035 #include "SMSExampleListboxView.h"
00036 #include "SmsExamplePanics.pan"
00037 #include "SMSExampleParser.h"
00038
00039 #include <AknQueryDialog.h>
00040 #include <msvids.h>
00041 #include <txtrich.h>
00042 #include <smut.h>
00043 #include <AknGlobalNote.h>
00044
00045 #ifdef __WINS__
00046 const TMsvId KObservedFolderId = KMsvDraftEntryId;
00047 #else
00048 const TMsvId KObservedFolderId = KMsvGlobalInBoxIndexEntryId;
00049 #endif
00050
00051 const TMsvId KInbox = KMsvGlobalInBoxIndexEntryId;
00052 const TMsvId KOutbox = KMsvGlobalOutBoxIndexEntryId;
00053 const TMsvId KDrafts = KMsvDraftEntryId;
00054
00055 _LIT(KCouldNotSendSMS, "Message not sent");
00056 _LIT(KSentMessageToAddress, "Sent message to address: ");
00057 _LIT(KNoBodyText, "No body text");
00058 _LIT(KAutomaticDeletedMesssageText, "Deleted arrived message!");
00059 _LIT(KAutomaticDeleteActivatedText, "Automatic delete activated");
00060 _LIT(KAutomaticDeleteDeActivatedText, "Automatic delete deactivated");
00061 _LIT(KSendingMsgTxt,"Sending msg");
00062 _LIT(KErrText,"Error:");
00063 _LIT(KEngineInitializedTxt,"Engine initialized");
00064 _LIT(KMessageSentTxt,"Message sent");
00065 _LIT(KMsgReceivedTxt,"Received message");
00066
00067 const TInt KDelayTime = 1000*3000;
00068 const TInt KErrMsgLength = 20;
00069
00070 #define KErrMsgLength 30
00071
00072 void CSMSExampleAppUi::ConstructL()
00073 {
00074 BaseConstructL(EAknEnableSkin);
00075
00076 iAutomaticDelete = EFalse;
00077
00078 iSmsEngine = CSmsEngine::NewL(*this);
00079
00080 iLogView = CLogView::NewL();
00081 iListboxView = CListboxView::NewL(iSmsEngine, iLogView);
00082
00083 AddViewL(iLogView);
00084 AddViewL(iListboxView);
00085
00086 SetDefaultViewL(*iLogView);
00087
00088
00089 iParser = CSMSExampleParser::NewL();
00090 }
00091
00092
00093 CSMSExampleAppUi::~CSMSExampleAppUi()
00094 {
00095 delete iParser;
00096 iParser = NULL;
00097
00098 delete iSmsEngine;
00099 iSmsEngine = NULL;
00100 }
00101
00102
00103
00104
00105
00106 void CSMSExampleAppUi::DynInitMenuPaneL(
00107 TInt ,CEikMenuPane* )
00108 {
00109 }
00110
00111
00112 TKeyResponse CSMSExampleAppUi::HandleKeyEventL(
00113 const TKeyEvent& ,TEventCode )
00114 {
00115 return EKeyWasNotConsumed;
00116 }
00117
00118
00119 TInt CSMSExampleAppUi::GetAddressL()
00120 {
00121 CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(iAddress,
00122 CAknQueryDialog::ENoTone);
00123
00124 return dlg->ExecuteLD(R_MTMS_EXAMPLE_ADDRESS_QUERY);
00125 }
00126
00127
00128 TInt CSMSExampleAppUi::QueryMessageL()
00129 {
00130 CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(iMessage,
00131 CAknQueryDialog::ENoTone);
00132
00133 return dlg->ExecuteLD(R_MTMS_EXAMPLE_MESSAGE_QUERY);
00134 }
00135
00136
00137 void CSMSExampleAppUi::HandleCommandL(TInt aCommand)
00138 {
00139 switch ( aCommand )
00140 {
00141 case EAknSoftkeyExit:
00142 case EEikCmdExit:
00143 {
00144 Exit();
00145 break;
00146 }
00147
00148 case ESMSExampleCmdSendMessage:
00149 {
00150
00151 if (!GetAddressL())
00152 {
00153 return;
00154 }
00155
00156
00157 if (!QueryMessageL())
00158 {
00159 return;
00160 }
00161
00162 iLogView->LogEventBeginningL();
00163
00164 iSmsEngine->SendSmsL(iAddress, iMessage);
00165
00166 break;
00167 }
00168
00169
00170 case ESMSExampleCmdMoveMessageFromInboxToDrafts:
00171 {
00172 QueryMessagesAndExecuteL( ESMSExampleMove, KInbox, KDrafts );
00173 break;
00174 }
00175 case ESMSExampleCmdMoveMessageFromInboxToOutbox:
00176 {
00177 QueryMessagesAndExecuteL( ESMSExampleMove, KInbox, KOutbox );
00178 break;
00179 }
00180 case ESMSExampleCmdMoveMessageFromDraftsToInbox:
00181 {
00182 QueryMessagesAndExecuteL( ESMSExampleMove, KDrafts, KInbox );
00183 break;
00184 }
00185 case ESMSExampleCmdMoveMessageFromDraftsToOutbox:
00186 {
00187 QueryMessagesAndExecuteL( ESMSExampleMove, KDrafts, KOutbox );
00188 break;
00189 }
00190 case ESMSExampleCmdMoveMessageFromOutboxToInbox:
00191 {
00192 QueryMessagesAndExecuteL( ESMSExampleMove, KOutbox, KInbox );
00193 break;
00194 }
00195 case ESMSExampleCmdMoveMessageFromOutboxToDrafts:
00196 {
00197 QueryMessagesAndExecuteL( ESMSExampleMove, KOutbox, KDrafts );
00198 break;
00199 }
00200
00201
00202 case ESMSExampleCmdCopyMessageFromDraftsToInbox:
00203 {
00204 QueryMessagesAndExecuteL( ESMSExampleModeCopy, KDrafts, KInbox );
00205 break;
00206 }
00207 case ESMSExampleCmdCopyMessageFromDraftsToOutbox:
00208 {
00209 QueryMessagesAndExecuteL( ESMSExampleModeCopy, KDrafts, KOutbox );
00210 break;
00211 }
00212 case ESMSExampleCmdCopyMessageFromInboxToOutbox:
00213 {
00214 QueryMessagesAndExecuteL( ESMSExampleModeCopy, KInbox, KOutbox );
00215 break;
00216 }
00217 case ESMSExampleCmdCopyMessageFromInboxToDrafts:
00218 {
00219 QueryMessagesAndExecuteL( ESMSExampleModeCopy, KInbox, KDrafts );
00220 break;
00221 }
00222 case ESMSExampleCmdCopyMessageFromOutboxToInbox:
00223 {
00224 QueryMessagesAndExecuteL( ESMSExampleModeCopy, KOutbox, KInbox );
00225 break;
00226 }
00227 case ESMSExampleCmdCopyMessageFromOutboxToDrafts:
00228 {
00229 QueryMessagesAndExecuteL( ESMSExampleModeCopy, KOutbox, KDrafts );
00230 break;
00231 }
00232
00233
00234 case ESMSExampleCmdDeleteMessageFromDrafts:
00235 {
00236 QueryMessagesAndExecuteL( ESMSExampleDelete, KDrafts, 0 );
00237 break;
00238 }
00239 case ESMSExampleCmdDeleteMessageFromOutbox:
00240 {
00241 QueryMessagesAndExecuteL( ESMSExampleDelete, KOutbox, 0 );
00242 break;
00243 }
00244 case ESMSExampleCmdDeleteMessageFromInbox:
00245 {
00246 QueryMessagesAndExecuteL(ESMSExampleDelete, KInbox, 0 );
00247 break;
00248 }
00249
00250
00251 case ESMSExampleListBoxSetAutomaticDeleteOn:
00252 {
00253 CAknQueryDialog* conf = CAknQueryDialog::NewL(
00254 CAknQueryDialog::EWarningTone );
00255
00256 TInt retCode =
00257 conf->ExecuteLD(R_AUTOMATIC_DELETE_CONFIRMATION_QUERY_DIALOG);
00258
00259 if ( retCode )
00260 {
00261 iLogView->LogEventBeginningL();
00262 iLogView->DrawTextL( KAutomaticDeleteActivatedText );
00263 iSmsEngine->SetAutomaticDeletetion(ETrue);
00264 }
00265 break;
00266 }
00267 case ESMSExampleListBoxSetAutomaticDeleteOff:
00268 {
00269 iLogView->LogEventBeginningL();
00270 iLogView->DrawTextL( KAutomaticDeleteDeActivatedText );
00271 iSmsEngine->SetAutomaticDeletetion(EFalse);
00272 break;
00273 }
00274
00275 default:
00276 break;
00277 }
00278 }
00279
00280
00281
00282 void CSMSExampleAppUi::QueryMessagesAndExecuteL(TInt aMode,
00283 TMsvId aOriginFolderID,
00284 TMsvId aDestinationFolderID)
00285 {
00286 iListboxView->SetListBoxMode( aMode );
00287 iListboxView->SetFolderID( aOriginFolderID );
00288 iListboxView->SetTargetFolderID( aDestinationFolderID );
00289
00290
00291
00292
00293
00294 ActivateLocalViewL(TUid::Uid(EListboxViewId));
00295 }
00296
00297
00298 void CSMSExampleAppUi::ShowErrorL(TInt aErrorCode) const
00299 {
00300 _LIT(KErrMsg,"Error occured:");
00301 TBuf<KErrMsgLength> errorMsg (KErrMsg);
00302 errorMsg.AppendNum(aErrorCode);
00303 ShowMessageL(errorMsg);
00304 }
00305
00306 void CSMSExampleAppUi::ShowMessageL(const TDesC& aMsg) const
00307 {
00308 CAknGlobalNote* note = CAknGlobalNote::NewLC();
00309 note->ShowNoteL(EAknGlobalConfirmationNote, aMsg);
00310 CleanupStack::PopAndDestroy(note);
00311 }
00312
00313 void CSMSExampleAppUi::HandleResourceChangeL(TInt aType)
00314 {
00315 CAknAppUi::HandleResourceChangeL(aType);
00316
00317
00318
00319 if ( aType == KEikDynamicLayoutVariantSwitch )
00320 {
00321
00322 if( iLogView )
00323 iLogView->SizeChanged();
00324 if( iListboxView )
00325 iListboxView->SizeChanged();
00326 }
00327
00328
00329
00330 }
00331
00332 void CSMSExampleAppUi::SendingMessage()
00333 {
00334 TRAPD(err,iLogView->DrawTextL(KSendingMsgTxt));
00335 }
00336
00337 void CSMSExampleAppUi::MessageSent()
00338 {
00339 TRAPD(err,iLogView->DrawTextL( KMessageSentTxt ) );
00340 }
00341
00342 void CSMSExampleAppUi::MessageReceived(const TDesC& aAddress, const TDesC& aMessage)
00343 {
00344 TRAPD(err, HandleReceivedMessageL(aAddress, aMessage) );
00345 if( err )
00346 {
00347 TRAP(err, ShowErrorL(err) );
00348 }
00349 }
00350
00351 void CSMSExampleAppUi::SmsEngineInitialized()
00352 {
00353 TRAPD(err,iLogView->DrawTextL(KEngineInitializedTxt));
00354 }
00355
00356 void CSMSExampleAppUi::SmsEngineError(TInt aErrorCode)
00357 {
00358
00359
00360 TBuf<KErrMsgLength> err = KErrText();
00361 err.AppendNum(aErrorCode);
00362 TRAPD(error,iLogView->DrawTextL(err));
00363 }
00364
00365
00366 void CSMSExampleAppUi::MessageDeleted()
00367 {
00368 TRAPD(err,iLogView->LogEventBeginningL());
00369 TRAP(err,iLogView->DrawTextL( KAutomaticDeletedMesssageText ) );
00370 }
00371
00372 void CSMSExampleAppUi::HandleReceivedMessageL(const TDesC& aAddress, const TDesC& aMessage)
00373 {
00374 if (aMessage.Length() > 0)
00375 {
00376 iLogView->DrawTextL( KMsgReceivedTxt );
00377 iLogView->DrawTextL( aAddress );
00378
00379 TPtrC ptr = aMessage.Ptr();
00380 TBuf<KSmsMessageLength> number;
00381
00382
00383
00384 if ( iParser->ParseMessage( ptr, number ))
00385 {
00386
00387 TInt pos = aMessage.Find( number );
00388
00389 iLogView->DrawTextWithoutCarriageL(
00390 aMessage.Left(pos)
00391 );
00392
00393 iLogView->DrawUnderlinedTextL( aMessage.Mid(pos, number.Length()) );
00394
00395 iLogView->DrawTextWithoutCarriageL(
00396 aMessage.Right( aMessage.Length() - pos - number.Length() ));
00397 }
00398 else
00399 {
00400 iLogView->DrawTextL( aMessage );
00401 }
00402 }
00403 else
00404 {
00405 iLogView->DrawTextL( KNoBodyText );
00406 }
00407 }
00408
00409