pushmtm/MtmUiSrc/PushMessageInfoOp.cpp
changeset 51 48e827313edd
parent 37 481242ead638
child 53 f427d27b98d8
equal deleted inserted replaced
37:481242ead638 51:48e827313edd
     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 CPushMessageInfoOp.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "PushMessageInfoOp.h"
       
    21 #include "PushMessageInfoDialog.h"
       
    22 #include "PushMtmUtil.h"
       
    23 #include "PushMtmUiDef.h"
       
    24 #include "PushMtmUiPanic.h"
       
    25 #include "PushMtmLog.h"
       
    26 #include <AknNoteWrappers.h>
       
    27 #include <PushMtmUi.rsg>
       
    28 #include <data_caging_path_literals.hrh>
       
    29 #include <f32file.h>
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CPushMessageInfoOp::CPushMessageInfoOp
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CPushMessageInfoOp::CPushMessageInfoOp( CMsvSession& aSession, 
       
    38                                         TMsvId aEntryId, 
       
    39                                         TBool aDontShowNotification, 
       
    40                                         TRequestStatus& aObserverStatus ) 
       
    41 :   CPushMtmUiOperation( aSession, aEntryId, aObserverStatus ), 
       
    42     iDontShowNotification( aDontShowNotification ), 
       
    43     iObserverCompleted( EFalse )
       
    44     {
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CPushMessageInfoOp::~CPushMessageInfoOp
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CPushMessageInfoOp::~CPushMessageInfoOp()
       
    52     {
       
    53     Cancel();
       
    54     delete iDialog;
       
    55     if ( iDeletedFlag )
       
    56         {
       
    57 		*iDeletedFlag = ETrue;
       
    58         }
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CPushMessageInfoOp::StartL
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 void CPushMessageInfoOp::StartL()
       
    66     {
       
    67     Cancel();
       
    68     iObserverCompleted = EFalse;
       
    69     CPushMtmOperation::StartL();
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CPushMessageInfoOp::RunL
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CPushMessageInfoOp::RunL()
       
    77     {
       
    78     __ASSERT_DEBUG( !iDialog, UiPanic( EPushMtmUiPanAlreadyInitialized ) );
       
    79 
       
    80     if ( iObserverCompleted )
       
    81         {
       
    82         return;
       
    83         }
       
    84 
       
    85     TBool deleted( EFalse );
       
    86     iDeletedFlag = &deleted;
       
    87 
       
    88     // Time to set up entry observation (delete & replacement case).
       
    89     ObserveEntryEventL();
       
    90 
       
    91     iDialog = new (ELeave) CPushMessageInfoDialog;
       
    92     // Workaround for Cancel(): SetActive() is called.
       
    93     // CMsvSingleOpWatcher::DoCancel() will wait for this observed object to 
       
    94     // complete that. iDialog->ExecuteLD() allows other RunL's to run, so 
       
    95     // that it may happen that CMsvSingleOpWatcher::DoCancel() is called 
       
    96     // when iDialog->ExecuteLD() is running. It means that this object must 
       
    97     // be active in that time in order DoCancel() will be called.
       
    98     iStatus = KRequestPending;
       
    99     SetActive();
       
   100     iDialog->ExecuteLD( iMsvSession, iEntryId );
       
   101 
       
   102     // Ready.
       
   103     if ( !deleted )
       
   104         {
       
   105         iDialog = NULL;
       
   106         iDeletedFlag = NULL;
       
   107         // Consider what happens if this object is cancelled in ExecuteLD!
       
   108         // In this case the observer is already completed (DoCancel), so 
       
   109         // avoid completeing it twice. iObserverCompleted indicates it.
       
   110         if ( !iObserverCompleted )
       
   111             {
       
   112             SignalObserver( KErrNone );
       
   113             iObserverCompleted = ETrue;
       
   114             // Due to SetActive() call RunL again, but it will do nothing 
       
   115             // (see above).
       
   116             InvokeRun();
       
   117             }
       
   118         }
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CPushMessageInfoOp::DoCancel
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 void CPushMessageInfoOp::DoCancel()
       
   126     {
       
   127     PUSHLOG_WRITE("CPushMessageInfoOp::DoCancel");
       
   128     CancelObserveEntryEvent();
       
   129 
       
   130     if ( iDialog )
       
   131         {
       
   132         delete iDialog;
       
   133         iDialog = NULL;
       
   134         // Due to SetActive() in RunL we must call InvokeRun(): the dialog 
       
   135         // does not completes this operation.
       
   136         InvokeRun();
       
   137         }
       
   138     if ( !iObserverCompleted )
       
   139         {
       
   140         SignalObserver( KErrCancel );
       
   141         iObserverCompleted = ETrue;
       
   142         }
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CPushMessageInfoOp::RunError
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 TInt CPushMessageInfoOp::RunError( TInt aError )
       
   150     {
       
   151     PUSHLOG_WRITE_FORMAT("CPushMessageInfoOp::RunError: %d",aError);
       
   152     CancelObserveEntryEvent();
       
   153 
       
   154     if ( !iObserverCompleted )
       
   155         {
       
   156         SignalObserver( aError );
       
   157         iObserverCompleted = ETrue;
       
   158         }
       
   159     return aError;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CPushMessageInfoOp::HandleEntryEventL
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 void CPushMessageInfoOp::HandleEntryEventL( TMsvEntryEvent aEvent, 
       
   167                          TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/ )
       
   168     {
       
   169     PUSHLOG_ENTERFN("CPushMessageInfoOp::HandleEntryEventL");
       
   170 
       
   171     if ( aEvent == EMsvEntryChanged )
       
   172         {
       
   173         PUSHLOG_WRITE(" Changed");
       
   174         HandleEntryChangeL();
       
   175         }
       
   176     else if ( aEvent == EMsvEntryDeleted )
       
   177         {
       
   178         PUSHLOG_WRITE(" Deleted");
       
   179         NotifyAndCancelL( R_PUSHLS_EXPIRED_NOTE );
       
   180         }
       
   181     else
       
   182         {
       
   183         // Nothing to do.
       
   184         }
       
   185 
       
   186     PUSHLOG_LEAVEFN("CPushMessageInfoOp::HandleEntryEventL");
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CPushMessageInfoOp::HandleEntryChangeL
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 void CPushMessageInfoOp::HandleEntryChangeL()
       
   194     {
       
   195     PUSHLOG_ENTERFN("CPushMessageInfoOp::HandleEntryChangeL");
       
   196 
       
   197     // We have to act only in case of such changes where the content 
       
   198     // of the message changes, not only the unread/read flag.
       
   199     // The content handlers and the Push subsystem behave so that 
       
   200     // the content is changed only when the entry becomes 'unread', 
       
   201     // except one case where the CH changes the content, but the 
       
   202     // message becomes 'read' (SL-execute-high). In this case 
       
   203     // a flag indicates that the content was changed.
       
   204 
       
   205     // Get an up-to-date entry and check the necessary flags:
       
   206     TMsvEntry tEntry;
       
   207     TMsvId service;
       
   208     User::LeaveIfError( iMsvSession.GetEntry( iEntryId, service, tEntry ) );
       
   209     TBool isChangeToUnread = tEntry.Unread();
       
   210     TBool contentChangedFlagSet = 
       
   211         CPushMtmUtil::Attrs( tEntry ) & EPushMtmReadButContentChanged;
       
   212 
       
   213     if ( !isChangeToUnread && !contentChangedFlagSet )
       
   214         {
       
   215         // Nothing to do. Somebody has just marked it 'read'.
       
   216         PUSHLOG_WRITE(" Content not changed");
       
   217         }
       
   218     else
       
   219         {
       
   220         NotifyAndCancelL( R_PUSHMISC_INFO_REPLACED );
       
   221         }
       
   222 
       
   223     PUSHLOG_LEAVEFN("CPushMessageInfoOp::HandleEntryChangeL")
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // CPushMessageInfoOp::NotifyAndCancelL
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 void CPushMessageInfoOp::NotifyAndCancelL( TInt aResId )
       
   231     {
       
   232     PUSHLOG_ENTERFN("CPushMessageInfoOp::NotifyAndCancelL");
       
   233 
       
   234     if ( iDontShowNotification )
       
   235         {
       
   236         // Don't show.
       
   237         }
       
   238     else
       
   239         {
       
   240         // Add resource file.
       
   241         TParse* fileParser = new (ELeave) TParse;
       
   242         CleanupStack::PushL( fileParser );
       
   243         fileParser->Set( KPushMtmUiResourceFileAndDrive, &KDC_MTM_RESOURCE_DIR, NULL ); 
       
   244         AssureResourceL( fileParser->FullName() );
       
   245         CleanupStack::PopAndDestroy( fileParser ); // fileParser
       
   246         fileParser = NULL;
       
   247 
       
   248         // Show note about the message deletion.
       
   249         HBufC* noteText = iCoeEnv.AllocReadResourceLC( aResId );
       
   250         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   251         note->ExecuteLD( *noteText );
       
   252         CleanupStack::PopAndDestroy( noteText ); // noteText
       
   253         }
       
   254 
       
   255     // Close the dialog anyway.
       
   256     Cancel();
       
   257 
       
   258     PUSHLOG_LEAVEFN("CPushMessageInfoOp::NotifyAndCancelL");
       
   259     }
       
   260 
       
   261 // End of file.
       
   262