pushmtm/MtmUiSrc/PushViewMessageOp.cpp
branchRCL_3
changeset 64 6385c4c93049
parent 63 4baee4f15982
child 65 8e6fa1719340
equal deleted inserted replaced
63:4baee4f15982 64:6385c4c93049
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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:  Implementation of CPushViewMessageOp.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "PushViewMessageOp.h"
       
    23 #include "PushMtmUiDef.h"
       
    24 #include "PushMtmUiPanic.h"
       
    25 #include "PushMtmLog.h"
       
    26 #include "PushMtmUtil.h"
       
    27 #include <push/CSIPushMsgEntry.h>
       
    28 #include <eikenv.h>
       
    29 #include <aknappui.h>
       
    30 #include <uikon.hrh>
       
    31 #include <apmstd.h>
       
    32 #include <DocumentHandler.h>
       
    33 //#include <PushMtmUi.rsg>
       
    34 #include <AknNoteWrappers.h>
       
    35 #include <data_caging_path_literals.hrh>
       
    36 #include <f32file.h>
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 _LIT8( KTextPlainString, "text/plain" );
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 // CPushLoadServiceOp::NewL
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 CPushViewMessageOp* CPushViewMessageOp::NewL( CMsvSession& aSession,
       
    49                                               TMsvId aEntryId,
       
    50                                               TRequestStatus& aObserverStatus )
       
    51     {
       
    52     PUSHLOG_ENTERFN("CPushViewMessageOp::NewL")
       
    53 
       
    54     CPushViewMessageOp* self =
       
    55         new (ELeave) CPushViewMessageOp( aSession, aEntryId, aObserverStatus );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59 
       
    60     PUSHLOG_LEAVEFN("CPushViewMessageOp::NewL")
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CPushViewMessageOp::~CPushViewMessageOp
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 CPushViewMessageOp::~CPushViewMessageOp()
       
    69     {
       
    70     PUSHLOG_ENTERFN("CPushViewMessageOp::~CPushViewMessageOp")
       
    71 
       
    72     Cancel();
       
    73     delete iDocHandler;
       
    74 
       
    75     PUSHLOG_LEAVEFN("CPushViewMessageOp::~CPushViewMessageOp")
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CPushViewMessageOp::StartL
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 void CPushViewMessageOp::StartL()
       
    83     {
       
    84     PUSHLOG_WRITE("CPushViewMessageOp StartL")
       
    85 
       
    86     Cancel();
       
    87 
       
    88     // Mark service read.
       
    89     iMtmUtil->MarkServiceUnreadL( iEntryId, EFalse );
       
    90 
       
    91     CPushMtmUiOperation::StartL();
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CPushViewMessageOp::CPushViewMessageOp
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 CPushViewMessageOp::CPushViewMessageOp( CMsvSession& aSession,
       
    99                                         TMsvId aEntryId,
       
   100                                         TRequestStatus& aObserverStatus )
       
   101 :   CPushMtmUiOperation( aSession, aEntryId, aObserverStatus ),
       
   102     iIsCancelled( EFalse )
       
   103     {
       
   104     PUSHLOG_WRITE("CPushViewMessageOp constructing")
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CPushViewMessageOp::ConstructL
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 void CPushViewMessageOp::ConstructL()
       
   112     {
       
   113     CPushMtmUiOperation::ConstructL();
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // CPushViewMessageOp::RunL
       
   118 // ---------------------------------------------------------
       
   119 //
       
   120 void CPushViewMessageOp::RunL()
       
   121     {
       
   122     PUSHLOG_ENTERFN("CPushViewMessageOp::RunL");
       
   123 
       
   124     if ( iDocHandler )
       
   125         {
       
   126         // Content handler is running; we just need to close it,
       
   127         // NotifyExit has already been called.
       
   128         delete iDocHandler;
       
   129         iDocHandler = NULL;
       
   130         CancelObserveEntryEvent();
       
   131 
       
   132         // Ready.
       
   133         SignalObserver( KErrNone );
       
   134         }
       
   135     else
       
   136         {
       
   137         // Lauch the content handler.
       
   138         TMsvEntry tEntry;
       
   139         TMsvId service;
       
   140         User::LeaveIfError( iMsvSession.GetEntry( iEntryId, service, tEntry ) );
       
   141 
       
   142         __ASSERT_ALWAYS( tEntry.iMtm == KUidMtmWapPush,
       
   143                          UiPanic( EPushMtmUiPanBadMtm ) );
       
   144 
       
   145         CSIPushMsgEntry* si = NULL;
       
   146         const TInt32 bioType( tEntry.iBioType );
       
   147 
       
   148         if ( bioType == KUidWapPushMsgSI.iUid )
       
   149             {
       
   150             si = CSIPushMsgEntry::NewL();
       
   151             }
       
   152         else
       
   153             {
       
   154             __ASSERT_DEBUG( EFalse, UiPanic( EPushMtmUiPanBadBioType ) );
       
   155             User::Leave( KErrNotSupported );
       
   156             }
       
   157 
       
   158         CleanupStack::PushL( si );
       
   159         si->RetrieveL( iMsvSession, iEntryId );
       
   160 
       
   161         PUSHLOG_WRITE("CPushViewMessageOp SI retrieved")
       
   162 
       
   163         __ASSERT_DEBUG( !iDocHandler, UiPanic( EPushMtmUiPanAlreadyInitialized ) );
       
   164         iDocHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );
       
   165 
       
   166         iDocHandler->SetExitObserver( this );       // (1)
       
   167         const TPtrC text = si->Text();
       
   168         // Copy the text to an 8-bit buffer:
       
   169         HBufC8* text8 = HBufC8::NewMaxLC( text.Length() );
       
   170         text8->Des().Copy( text );
       
   171         TDataType dataType( KTextPlainString );
       
   172 
       
   173         CAiwGenericParamList& paramList = iDocHandler->InParamListL();
       
   174         RFile tempFile;
       
   175         iDocHandler->SaveTempFileL
       
   176             ( *text8, dataType, KNullDesC, tempFile );
       
   177         PUSHLOG_WRITE(" SaveTempFileL OK");
       
   178         CleanupClosePushL( tempFile );
       
   179         iDocHandler->OpenFileEmbeddedL( tempFile, dataType, paramList );
       
   180         PUSHLOG_WRITE(" OpenFileEmbeddedL OK");
       
   181         CleanupStack::PopAndDestroy( &tempFile ); // tempFile
       
   182         PUSHLOG_WRITE(" PopAndDestroy( &tempFile ) OK");
       
   183 
       
   184         CleanupStack::PopAndDestroy( 2, si ); // text8, si
       
   185         PUSHLOG_WRITE(" PopAndDestroy( 2, si ) OK");
       
   186 
       
   187         // Signal the observer when the viewer is terminated.
       
   188         // Until then we are observeing the message
       
   189         // (delete & replacement notification).
       
   190         //ObserveEntryEventL();                       // (2)
       
   191         // Now we are observing two things: the viewer (1) and the entry (2).
       
   192 
       
   193         iStatus = KRequestPending;
       
   194         SetActive();
       
   195         }
       
   196 
       
   197     PUSHLOG_LEAVEFN("CPushViewMessageOp::RunL")
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CPushViewMessageOp::DoCancel
       
   202 // ---------------------------------------------------------
       
   203 //
       
   204 void CPushViewMessageOp::DoCancel()
       
   205     {
       
   206     PUSHLOG_ENTERFN("CPushViewMessageOp::DoCancel");
       
   207 
       
   208     iIsCancelled = ETrue;
       
   209 
       
   210     CancelObserveEntryEvent();
       
   211     // If there is DocHandler, then it means that we are active and
       
   212     // waiting for NotifyExit to be called.
       
   213     if ( iDocHandler )
       
   214         {
       
   215         // Terminate the embedded viewer. TODO
       
   216         // Complete us.
       
   217         InvokeRun();
       
   218         }
       
   219 
       
   220     SignalObserver( KErrCancel );
       
   221 
       
   222     PUSHLOG_LEAVEFN("CPushViewMessageOp::DoCancel");
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------
       
   226 // CPushViewMessageOp::RunError
       
   227 // ---------------------------------------------------------
       
   228 //
       
   229 TInt CPushViewMessageOp::RunError( TInt aError )
       
   230     {
       
   231     PUSHLOG_WRITE_FORMAT("CPushViewMessageOp::RunError: %d",aError);
       
   232 
       
   233     CancelObserveEntryEvent();
       
   234 
       
   235     delete iDocHandler;
       
   236     iDocHandler = NULL;
       
   237 
       
   238     TRAP_IGNORE( ShowGlobalErrorNoteL( aError ) );
       
   239     return CPushMtmUiOperation::RunError( aError );
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CPushViewMessageOp::HandleEntryEventL
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void CPushViewMessageOp::HandleEntryEventL( TMsvEntryEvent aEvent,
       
   247                          TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/ )
       
   248     {
       
   249     PUSHLOG_ENTERFN("CPushViewMessageOp::HandleEntryEventL");
       
   250 
       
   251     if ( aEvent == EMsvEntryChanged )
       
   252         {
       
   253         PUSHLOG_WRITE(" Changed");
       
   254         // We don't have to bother with such case that the
       
   255         // content changes, but the entry is saved as 'read' in
       
   256         // this case, because this operation handles only SI messages.
       
   257         //TODO NotifyAndCancelL( R_PUSHMISC_INFO_REPLACED );
       
   258         }
       
   259     else if ( aEvent == EMsvEntryDeleted )
       
   260         {
       
   261         PUSHLOG_WRITE(" Deleted");
       
   262         //TODO NotifyAndCancelL( R_PUSHLS_EXPIRED_NOTE );
       
   263         }
       
   264     else
       
   265         {
       
   266         // Nothing to do.
       
   267         }
       
   268 
       
   269     PUSHLOG_LEAVEFN("CPushViewMessageOp::HandleEntryEventL");
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------
       
   273 // CPushViewMessageOp::NotifyAndCancelL
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 void CPushViewMessageOp::NotifyAndCancelL( TInt aResId )
       
   277     {
       
   278     PUSHLOG_ENTERFN("CPushViewMessageOp::NotifyAndCancelL");
       
   279 
       
   280     // Add resource file.
       
   281     TParse* fileParser = new (ELeave) TParse;
       
   282     CleanupStack::PushL( fileParser );
       
   283     fileParser->Set( KPushMtmUiResourceFileAndDrive, &KDC_MTM_RESOURCE_DIR, NULL );
       
   284     AssureResourceL( fileParser->FullName() );
       
   285     CleanupStack::PopAndDestroy( fileParser ); // fileParser
       
   286     fileParser = NULL;
       
   287 
       
   288     // Show note about the message deletion.
       
   289     HBufC* noteText = iCoeEnv.AllocReadResourceLC( aResId );
       
   290     CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   291     note->ExecuteLD( *noteText );
       
   292     CleanupStack::PopAndDestroy( noteText ); // noteText
       
   293 
       
   294     // Close the dialog.
       
   295     Cancel();
       
   296 
       
   297     PUSHLOG_LEAVEFN("CPushViewMessageOp::NotifyAndCancelL");
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CPushViewMessageOp::HandleServerAppExit
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CPushViewMessageOp::HandleServerAppExit( TInt LOG_ONLY( aReason ) )
       
   305     {
       
   306     PUSHLOG_WRITE_FORMAT("CPushViewMessageOp::HandleServerAppExit: %d",aReason);
       
   307 
       
   308     if ( !iIsCancelled )
       
   309         {
       
   310         // Ready. The application was terminated normally.
       
   311         InvokeRun();
       
   312         }
       
   313     }
       
   314 
       
   315 // End of file.
       
   316