mobilemessaging/smum/src/BioOpenOp.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 "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:  
       
    15 *     Bio message opening operation.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <coemain.h>    // CCoeEnv needed for file session
       
    23 // Messaging includes
       
    24 #include <MTMStore.h>   // for CMtmStore
       
    25 #include <bioscmds.h>   // for KBiosMtmParse
       
    26 #include <biodb.h>      // CBIODatabase
       
    27 // Local includes
       
    28 #include "BioOpenOp.h"
       
    29 #include "SMSU.H"       // for CSmsMtmUi
       
    30 #include "smsui.pan"    // SMUM panic codes
       
    31 
       
    32 // CONSTANTS
       
    33 const TUid KUidSmsMtm={0x1000102c};
       
    34 const TUid KUidBioMtm={0x10001262};
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CBioOpenOp::NewL
       
    40 //
       
    41 // ---------------------------------------------------------
       
    42 CBioOpenOp* CBioOpenOp::NewL(CMsvSession& aSession, TRequestStatus& aObserverStatus, TMsvId aId, TUint aFlags)
       
    43     {
       
    44     CBioOpenOp* self=new(ELeave) CBioOpenOp(aSession,aObserverStatus,aId);
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL(aFlags);
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CBioOpenOp::CBioOpenOp
       
    53 //
       
    54 // ---------------------------------------------------------
       
    55 CBioOpenOp::CBioOpenOp(CMsvSession& aSession,TRequestStatus& aObserverStatus, TMsvId aId)
       
    56     : CMsvOperation(aSession,CActive::EPriorityStandard,aObserverStatus),
       
    57       iMsvId(aId), iState(EUnknown)
       
    58     {
       
    59     CActiveScheduler::Add(this);
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CBioOpenOp::ConstructL
       
    64 //
       
    65 // ---------------------------------------------------------
       
    66 void CBioOpenOp::ConstructL(TUint aFlags)
       
    67     {
       
    68     iMtmStore=CMtmStore::NewL(iMsvSession);
       
    69     
       
    70     // Get SMS MTM UI and set its context
       
    71     iSmsMtmUi=&(iMtmStore->ClaimMtmUiL(KUidSmsMtm));
       
    72     iSmsMtmUiClaimed=ETrue;
       
    73     iSmsMtmUi->SetPreferences(aFlags);
       
    74     iSmsMtmUi->BaseMtm().SetCurrentEntryL(iMsvSession.GetEntryL(iMsvId));
       
    75 
       
    76     // Get Bio MTM UI and set its context
       
    77     iBioMtmUi=&(iMtmStore->ClaimMtmUiL(KUidBioMtm));
       
    78     iBioMtmUiClaimed=ETrue;
       
    79     iBioMtmUi->BaseMtm().SetCurrentEntryL(iMsvSession.GetEntryL(iMsvId));
       
    80 
       
    81     //
       
    82     // Check if needs parsing
       
    83     //
       
    84     CBIODatabase* bioDb = CBIODatabase::NewLC(CCoeEnv::Static()->FsSession());
       
    85     CMsvEntry* entry = iMsvSession.GetEntryL(iMsvId);
       
    86     CleanupStack::PushL(entry);
       
    87     TMsvEntry tentry = entry->Entry(); 
       
    88     TUid bioUid;
       
    89     bioUid.iUid = tentry.iBioType;
       
    90 
       
    91     TBool parserAvailable( EFalse );    
       
    92     if ( bioDb->GetBioParserNameL( bioUid ).Length() )
       
    93         {
       
    94         parserAvailable = ETrue;
       
    95         }
       
    96     // Set the description
       
    97     TInt bioDbIndex;
       
    98     bioDb->GetBioIndexWithMsgIDL(bioUid, bioDbIndex);
       
    99     HBufC* descr = bioDb->BifReader(bioDbIndex).Description().AllocLC();
       
   100     tentry.iDescription.Set(*descr);
       
   101     // save entry, because description was changed
       
   102     entry->ChangeL(tentry);
       
   103     CleanupStack::PopAndDestroy(descr);
       
   104 
       
   105     CleanupStack::PopAndDestroy(2, bioDb); // entry bioDatabase
       
   106     if ( parserAvailable )
       
   107         {
       
   108         // Start off first operation
       
   109         DoParseL(); // (after parsing it calls DoEditL() )
       
   110         }
       
   111     else
       
   112         {
       
   113         DoEditL();
       
   114         }
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CBioOpenOp::~CBioOpenOp
       
   119 //
       
   120 // ---------------------------------------------------------
       
   121 CBioOpenOp::~CBioOpenOp()
       
   122     {
       
   123     Cancel();
       
   124     delete iOperation;
       
   125 
       
   126     if(iMtmStore)
       
   127         {
       
   128         if(iSmsMtmUiClaimed)
       
   129             {
       
   130             iMtmStore->ReleaseMtmUi(KUidSmsMtm);
       
   131             }
       
   132         if(iBioMtmUiClaimed)
       
   133             {
       
   134             iMtmStore->ReleaseMtmUi(KUidBioMtm);
       
   135             }
       
   136         delete iMtmStore;
       
   137         }
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // CBioOpenOp::DoParseL
       
   142 //
       
   143 // ---------------------------------------------------------
       
   144 void CBioOpenOp::DoParseL()
       
   145     {
       
   146     __ASSERT_DEBUG(iOperation==NULL,Panic(EBioOperationNotNull));
       
   147 
       
   148     // Set iMtm of message as BIO MTM
       
   149     CMsvEntry* entry=iMsvSession.GetEntryL(iMsvId);
       
   150     CleanupStack::PushL(entry);
       
   151     TMsvEntry tentry;
       
   152     tentry=entry->Entry(); 
       
   153     tentry.iMtm=KUidBioMtm;
       
   154     entry->ChangeL(tentry);
       
   155     CleanupStack::PopAndDestroy();      // entry
       
   156 
       
   157     // Parse message
       
   158     TBuf8<1> blankParams;
       
   159     CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection();
       
   160     CleanupStack::PushL(sel);
       
   161     sel->AppendL(iMsvId);   // Message Server will use UID of 1st message to load in MTM server.
       
   162 
       
   163     SetActive();  
       
   164     iOperation=iBioMtmUi->InvokeAsyncFunctionL(KBiosMtmParse,*sel,iStatus,blankParams);
       
   165     CleanupStack::PopAndDestroy(); // sel
       
   166 
       
   167     iState=EParsing;
       
   168     iObserverRequestStatus = KRequestPending;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // CBioOpenOp::DoEditL
       
   173 //
       
   174 // ---------------------------------------------------------
       
   175 void CBioOpenOp::DoEditL()
       
   176     {
       
   177     delete iOperation;
       
   178     iOperation=NULL;
       
   179     
       
   180     // Launch SMS editor
       
   181     SetActive();
       
   182     iOperation=STATIC_CAST(CSmsMtmUi*,iSmsMtmUi)->LaunchEditorApplicationL(iStatus,iMsvSession,CSmsMtmUi::EEditExisting);
       
   183     iState=EEditing;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CBioOpenOp::RunL
       
   188 //
       
   189 // ---------------------------------------------------------    
       
   190 void CBioOpenOp::RunL()
       
   191     {
       
   192     __ASSERT_DEBUG(iOperation,Panic(EBioOperationDoesNotExist));
       
   193 
       
   194     switch(iState)
       
   195         {
       
   196     case EParsing:      // The parse has completed.
       
   197         {
       
   198         // Set iMtm of message back to SMS MTM
       
   199         {
       
   200         CMsvEntry* entry=iMsvSession.GetEntryL(iMsvId);
       
   201         CleanupStack::PushL(entry);
       
   202         TMsvEntry tentry(entry->Entry()); 
       
   203         tentry.iMtm=KUidSmsMtm;
       
   204         tentry.SetReadOnly(EFalse);
       
   205         entry->ChangeL(tentry);
       
   206         CleanupStack::PopAndDestroy();      // entry
       
   207         }
       
   208 
       
   209         TBuf<CBaseMtmUi::EProgressStringMaxLen> bufNotUsed1;
       
   210         TInt intNotUsed2;
       
   211         TInt intNotUsed3;
       
   212         TInt intNotUsed4;
       
   213         TInt intNotUsed5;
       
   214         const TInt err=iBioMtmUi->GetProgress(iOperation->FinalProgress(),bufNotUsed1,intNotUsed2,intNotUsed3,intNotUsed4,intNotUsed5);
       
   215 
       
   216         if(KErrNone==err)
       
   217             {
       
   218             DoEditL();
       
   219             }
       
   220         else
       
   221             {
       
   222             CompleteObserver();
       
   223             }
       
   224         }
       
   225         break;
       
   226     case EEditing:      // Edit has completed.
       
   227         CompleteObserver();
       
   228         break;
       
   229     case EUnknown:
       
   230         break;
       
   231     default:
       
   232         break;
       
   233         }
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CBioOpenOp::ProgressL
       
   238 //
       
   239 // ---------------------------------------------------------
       
   240 const TDesC8& CBioOpenOp::ProgressL()
       
   241     {
       
   242     if(iOperation)
       
   243         {
       
   244         return iOperation->ProgressL();
       
   245         }
       
   246     return KNullDesC8;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // CBioOpenOp::DoCancel
       
   251 //
       
   252 // ---------------------------------------------------------
       
   253 void CBioOpenOp::DoCancel()
       
   254     {
       
   255     if(iOperation)
       
   256         {
       
   257         iOperation->Cancel();
       
   258         }
       
   259     CompleteObserver();
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------
       
   263 // CBioOpenOp::RunError
       
   264 //
       
   265 // ---------------------------------------------------------
       
   266 TInt CBioOpenOp::RunError(TInt /*aError*/)
       
   267     {
       
   268     CompleteObserver();
       
   269     return KErrNone;
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------
       
   273 // CBioOpenOp::CompleteObserver
       
   274 //
       
   275 // ---------------------------------------------------------
       
   276 void CBioOpenOp::CompleteObserver()
       
   277     {
       
   278     TRequestStatus* status = &iObserverRequestStatus;
       
   279     User::RequestComplete(status,KErrNone);
       
   280     iState=EUnknown;
       
   281     }
       
   282 
       
   283 // end of file