messagingapp/msgui/appengine/src/conversationmsgstorehandler.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
    13 *
    13 *
    14 * Description:  
    14 * Description:  
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <textresolver.h> // from CommonEngine
       
    19 #include <mtclreg.h>
       
    20 #include <mmsnotificationclient.h>
       
    21 #include <mmssettings.h>
       
    22 #include <xqconversions.h> // from xqutils
       
    23 #include <mmsconst.h>
       
    24 #include <QDateTime>
       
    25 
    18 #include "conversationmsgstorehandler.h"
    26 #include "conversationmsgstorehandler.h"
    19 #include "draftsmodel.h"
    27 #include "draftsmodel.h"
       
    28 #include "MuiuOperationWait.h"
       
    29 #include "MsgBioUids.h"
       
    30 #include "UniEditorGenUtils.h"
       
    31 
    20 // SYSTEM INCLUDES
    32 // SYSTEM INCLUDES
    21 #include <StringLoader.h>
    33 #include <StringLoader.h>
    22 #include <ccsdefs.h> 
    34 #include <ccsdefs.h> 
    23 #include <mmsconst.h>
    35 #include <msvids.h>
       
    36 #include <mmserrors.h>
       
    37 #include <msvuids.h>
       
    38 #include <smut.h>
    24 #include <SendUiConsts.h>
    39 #include <SendUiConsts.h>
       
    40 #include <featmgr.h>
       
    41 #include <gsmerror.h> 
    25 
    42 
    26 // CONSTANTS
    43 // CONSTANTS
       
    44 const TUid KSmsMtmUid ={KSenduiMtmSmsUidValue};
       
    45 const TUid KMmsMtmUid ={KSenduiMtmMmsUidValue};
       
    46 _LIT(KUnixEpoch, "19700000:000000.000000");
       
    47 #define BYTES_TO_KBYTES_FACTOR 1024
       
    48 
       
    49 // TODO: read global setting of formats on the phone
       
    50 const QString DATE_FORMAT("dd/MM");
       
    51 const QString TIME_FORMAT("hh:mm");
    27 
    52 
    28 // ================= MEMBER FUNCTIONS =======================
    53 // ================= MEMBER FUNCTIONS =======================
    29 
    54 
    30 // ---------------------------------------------------------
    55 // ---------------------------------------------------------
    31 // Default constructor.
    56 // Default constructor.
    32 // ---------------------------------------------------------
    57 // ---------------------------------------------------------
    33 //
    58 //
    34 ConversationMsgStoreHandler::ConversationMsgStoreHandler():
    59 ConversationMsgStoreHandler::ConversationMsgStoreHandler():
    35     iMsvSession(NULL),iDraftEntry(NULL),iDraftMessages(NULL),mDraftsModel(NULL)
    60     iMsvSession(NULL),iDraftEntry(NULL),iDraftMessages(NULL),mDraftsModel(NULL),
       
    61     iMtmReg(NULL),iMmsClient(NULL),iNotificationClient(NULL)
    36     {
    62     {
    37     TRAP_IGNORE(InitL());
    63     TRAP_IGNORE(InitL());
    38     }
    64     }
    39 
    65 
    40 // ---------------------------------------------------------
    66 // ---------------------------------------------------------
    45     {
    71     {
    46     if ( iDraftEntry )
    72     if ( iDraftEntry )
    47         {
    73         {
    48         delete iDraftEntry;
    74         delete iDraftEntry;
    49         iDraftEntry = NULL;
    75         iDraftEntry = NULL;
    50         }
       
    51 
       
    52     if( iMsvSession )
       
    53         {
       
    54         delete iMsvSession;
       
    55         iMsvSession = NULL;
       
    56         }
    76         }
    57 
    77 
    58     if ( iDraftMessages )
    78     if ( iDraftMessages )
    59         {
    79         {
    60         iDraftMessages->Reset();
    80         iDraftMessages->Reset();
    61         delete iDraftMessages;
    81         delete iDraftMessages;
    62         iDraftMessages = NULL;
    82         iDraftMessages = NULL;
       
    83     }
       
    84 
       
    85     if (iMmsClient)
       
    86     {
       
    87         delete iMmsClient;
       
    88         iMmsClient = NULL;
       
    89     }
       
    90     if (iNotificationClient)
       
    91     {
       
    92         delete iNotificationClient;
       
    93         iNotificationClient = NULL;
       
    94     }
       
    95     if (iMtmReg)
       
    96     {
       
    97         delete iMtmReg;
       
    98         iMtmReg = NULL;
       
    99     }
       
   100     if (iMsvSession)
       
   101     {
       
   102         delete iMsvSession;
       
   103         iMsvSession = NULL;
    63         }
   104         }
    64     }
   105     }
    65 
   106 
    66 // ---------------------------------------------------------
   107 // ---------------------------------------------------------
    67 // 
   108 // 
    68 // ---------------------------------------------------------
   109 // ---------------------------------------------------------
    69 //
   110 //
    70 void ConversationMsgStoreHandler::InitL( )
   111 void ConversationMsgStoreHandler::InitL( )
    71     {
   112     {
    72     iMsvSession = CMsvSession::OpenSyncL(*this);
   113     TInt err = KErrNone;
       
   114     TRAP(err,iMsvSession = CMsvSession::OpenSyncL(*this));
       
   115     if(err != KErrNone)
       
   116         {
       
   117         iMsvSession = NULL;
       
   118         return;
       
   119         }
       
   120     
       
   121     TRAP(err,iMtmReg = CClientMtmRegistry::NewL(*iMsvSession));
       
   122     if(err != KErrNone)
       
   123         {
       
   124         iMtmReg = NULL;
       
   125         return;
       
   126         }
       
   127 	
       
   128 	 // Get if offline is supported
       
   129     FeatureManager::InitializeLibL();
       
   130     if (FeatureManager::FeatureSupported(KFeatureIdOfflineMode))
       
   131     {
       
   132         iOfflineSupported = ETrue;
       
   133     }
       
   134     else
       
   135     {
       
   136         iOfflineSupported = EFalse;
       
   137     }
       
   138     FeatureManager::UnInitializeLib();
       
   139 		
    73     }
   140     }
    74 
   141 
    75 // ---------------------------------------------------------
   142 // ---------------------------------------------------------
    76 // ConversationMsgStoreHandler::HandleSessionEventL()
   143 // ConversationMsgStoreHandler::HandleSessionEventL()
    77 // ---------------------------------------------------------
   144 // ---------------------------------------------------------
   170     TMsvEntry entry;
   237     TMsvEntry entry;
   171     iMsvSession->GetEntry(aMsvId, dummy, entry);
   238     iMsvSession->GetEntry(aMsvId, dummy, entry);
   172     
   239     
   173     TCsMmsNotificationMsgState status = EMsgStatusNull;
   240     TCsMmsNotificationMsgState status = EMsgStatusNull;
   174 
   241 
       
   242     TTime currentTime;
       
   243     currentTime.HomeTime( );
       
   244     TTime expiryTime = iNotificationClient->ExpiryDate( );
       
   245     TLocale locale;
       
   246     expiryTime += locale.UniversalTimeOffset();
       
   247     if (locale.QueryHomeHasDaylightSavingOn())          
       
   248     {
       
   249         TTimeIntervalHours daylightSaving(1);          
       
   250         expiryTime += daylightSaving;
       
   251     }
       
   252 
   175     // operationMask includes operation type. It is not bitmap but ordinal number. 
   253     // operationMask includes operation type. It is not bitmap but ordinal number. 
   176     // It does not include operation status and result
   254     // It does not include operation status and result
   177     TInt operationMask = (entry.iMtmData2 & KMmsOperationIdentifier) ;
   255     TInt operationMask = (entry.iMtmData2 & KMmsOperationIdentifier) ;
   178 
   256 
   179     // Note! Ongoing operation resets every bit of operation type, operation status
   257     // Note! Ongoing operation resets every bit of operation type, operation status
   213                 &&  OperationFinished( entry )
   291                 &&  OperationFinished( entry )
   214                 &&  !( entry.iMtmData2 & KMmsOperationResult ) )
   292                 &&  !( entry.iMtmData2 & KMmsOperationResult ) )
   215             { 
   293             { 
   216             // It's been deleted succesfully
   294             // It's been deleted succesfully
   217             status = EMsgStatusDeleted;
   295             status = EMsgStatusDeleted;
       
   296             }
       
   297         else if( currentTime > expiryTime )
       
   298             {
       
   299             status = EMsgStatusExpired;
   218             }
   300             }
   219         else 
   301         else 
   220             {   // Normal waiting state
   302             {   // Normal waiting state
   221             status = EMsgStatusReadyForFetching;
   303             status = EMsgStatusReadyForFetching;
   222             }
   304             }
   282         iMsvSession->RemoveEntry(id);
   364         iMsvSession->RemoveEntry(id);
   283     }   
   365     }   
   284 }
   366 }
   285 
   367 
   286 // ---------------------------------------------------------
   368 // ---------------------------------------------------------
       
   369 // ConversationMsgStoreHandler::DeleteAllDraftMessages
       
   370 // ---------------------------------------------------------
       
   371 //
       
   372 void ConversationMsgStoreHandler::DeleteAllDraftMessagesL()
       
   373 {
       
   374     // Cancel the processing of draft messages.
       
   375     iIdle->Cancel();
       
   376 
       
   377     CMsvEntry *draftsEntry = iMsvSession->GetEntryL(KMsvDraftEntryIdValue);
       
   378     CleanupStack::PushL(draftsEntry);
       
   379     CMsvEntrySelection *draftsSelection = draftsEntry->ChildrenL();
       
   380     CleanupStack::PushL(draftsSelection);
       
   381     if ( draftsSelection->Count() > 0 )
       
   382         {
       
   383         CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   384         CMsvOperation *operation = draftsEntry->DeleteL(*draftsSelection, wait->iStatus);
       
   385         wait->Start();
       
   386         CleanupStack::PopAndDestroy(wait);
       
   387         delete operation;
       
   388         }
       
   389     CleanupStack::PopAndDestroy(2, draftsEntry);
       
   390 }
       
   391 
       
   392 // ---------------------------------------------------------
   287 // ConversationMsgStoreHandler::DeleteMessagesL
   393 // ConversationMsgStoreHandler::DeleteMessagesL
   288 // ---------------------------------------------------------
   394 // ---------------------------------------------------------
   289 //
   395 //
   290 CMsvSession& ConversationMsgStoreHandler::GetMsvSession()
   396 CMsvSession& ConversationMsgStoreHandler::GetMsvSession()
   291 {
   397 {
   328         {
   434         {
   329         case EReadDrafts:
   435         case EReadDrafts:
   330             {
   436             {
   331             iDraftEntry = iMsvSession->GetEntryL(KMsvDraftEntryIdValue);
   437             iDraftEntry = iMsvSession->GetEntryL(KMsvDraftEntryIdValue);
   332            
   438            
   333             iDraftMessages = iDraftEntry->ChildrenL();    
   439             iDraftMessages = iDraftEntry->ChildrenL();
   334             iDraftMessageCount = iDraftEntry->Count();
   440             iDraftMessageCount = iDraftEntry->Count();
   335 
   441 
   336             if ( iDraftMessageCount ) 
   442             if ( iDraftMessageCount ) 
   337                 {
   443                 {
   338                 iState = EProcessDrafts;
   444                 iState = EProcessDrafts;
   411         {
   517         {
   412         return ETrue;
   518         return ETrue;
   413         }	
   519         }	
   414     return EFalse;
   520     return EFalse;
   415     }
   521     }
       
   522 	
       
   523 //-----------------------------------------------------------------------------
       
   524 // ConversationMsgStoreHandler::ResendMessage(TMsvId aId)
       
   525 // 
       
   526 // -----------------------------------------------------------------------------
       
   527 //	
       
   528 	
       
   529 bool ConversationMsgStoreHandler::ResendMessageL(TMsvId aId)
       
   530 {
       
   531     bool retval = true;
       
   532 	TMsvId serviceId;
       
   533 	TMsvEntry msgEntry;
       
   534 	  
       
   535 	if(iMsvSession == NULL)
       
   536 	    {
       
   537         return false;
       
   538    		}
       
   539   TInt err = iMsvSession->GetEntry(aId, serviceId, msgEntry);
       
   540     
       
   541   if (KErrNone == err)
       
   542   {
       
   543        TUid mtmUid = msgEntry.iMtm;
       
   544 
       
   545        CMsvEntry* entry = iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   546        CleanupStack::PushL(entry);
       
   547 
       
   548        CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   549 
       
   550        if (mtmUid == KSmsMtmUid)
       
   551        {
       
   552            UniEditorGenUtils* genUtils = new UniEditorGenUtils();
       
   553            CleanupStack::PushL(genUtils);
       
   554 
       
   555            // if phone is in offline mode set sending state to suspended
       
   556            // so that mtm does not try to send it.
       
   557            if (iOfflineSupported && genUtils->IsPhoneOfflineL())
       
   558            {
       
   559                msgEntry.SetSendingState(KMsvSendStateSuspended);
       
   560                msgEntry.iError = KErrGsmOfflineOpNotAllowed;
       
   561            }
       
   562            else
       
   563            {
       
   564                msgEntry.SetSendingState(KMsvSendStateWaiting);
       
   565            }
       
   566            CleanupStack::PopAndDestroy(genUtils);
       
   567 
       
   568            // Update message entry with sending state.
       
   569            entry->SetEntryL(msgEntry.Id());
       
   570            entry->ChangeL(msgEntry);
       
   571 
       
   572            TMsvId firstId;
       
   573            TSmsUtilities::ServiceIdL(*iMsvSession, firstId);
       
   574 
       
   575            entry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   576            //send the message
       
   577            entry->CopyL(aId, firstId, wait->iStatus);
       
   578            wait->Start();
       
   579        }
       
   580        else if (mtmUid == KMmsMtmUid)
       
   581        {
       
   582            //send the message
       
   583            entry->CopyL(aId, msgEntry.iServiceId, wait->iStatus);
       
   584            wait->Start();
       
   585        }
       
   586        CleanupStack::PopAndDestroy(2, entry);
       
   587    }
       
   588    else
       
   589    {
       
   590        User::LeaveIfError(err);
       
   591    }
       
   592    return retval;
       
   593 }
       
   594 
       
   595 //-----------------------------------------------------------------------------
       
   596 // ConversationMsgStoreHandler::DownloadOperationSupported
       
   597 // -----------------------------------------------------------------------------
       
   598 bool ConversationMsgStoreHandler::DownloadOperationSupported(
       
   599         const TMsvId& aId)
       
   600 {
       
   601     TMsvId serviceId;
       
   602     TMsvEntry msgEntry;
       
   603     TInt err = iMsvSession->GetEntry(aId,serviceId,msgEntry);
       
   604     
       
   605     TCsMmsNotificationMsgState msgstatus = 
       
   606             MmsNotificationStatus( aId );
       
   607 
       
   608     if ( msgEntry.iType == KUidMsvMessageEntry  )
       
   609         {
       
   610 
       
   611         if( msgEntry.iMtmData2 & KMmsNewOperationForbidden ) // New Forbidden
       
   612             {
       
   613             return false;
       
   614             }
       
   615         // If notification is succesfully routed to app 
       
   616         // aContext.iMtmData2 & KMmsMessageRoutedToApplication is ETrue and
       
   617         // if notification is NOT succesfully routed to app 
       
   618         // aContext.iError is KMmsErrorUnregisteredApplication.
       
   619         if(    ( msgEntry.iError == KMmsErrorUnregisteredApplication ) // To unregistered application
       
   620             || ( msgEntry.iMtmData2 & KMmsMessageRoutedToApplication ) )
       
   621             {
       
   622             return false;
       
   623             }
       
   624 
       
   625         if( msgstatus == EMsgStatusDeleted )
       
   626             { // Msg already been deleted from server
       
   627             return false;
       
   628             }
       
   629 
       
   630         if( msgstatus == EMsgStatusReadyForFetching 
       
   631             || msgstatus == EMsgStatusFailed )
       
   632             {   // Fetch is supported if the msg is waiting or something has been failed
       
   633             return true;
       
   634             }
       
   635 
       
   636         if (    msgstatus == EMsgStatusForwarded 
       
   637             &&  msgEntry.iMtmData2 & KMmsStoredInMMBox )
       
   638             { // Fetch is supported if it's forwarded and multiple forward is supported
       
   639             return true;
       
   640             }
       
   641         
       
   642         if( msgstatus == EMsgStatusExpired )
       
   643             {
       
   644             return false;
       
   645             }
       
   646         }
       
   647     return false;
       
   648 }
       
   649 
       
   650 //---------------------------------------------------------------
       
   651 // ConversationMsgStoreHandler::setNotificationMessageId
       
   652 // @see header
       
   653 //---------------------------------------------------------------
       
   654 void ConversationMsgStoreHandler::setNotificationMessageId(int messageId)
       
   655 {
       
   656     // get MMS Notification client mtm & set the content to current entry
       
   657     if(iNotificationClient)
       
   658     {
       
   659         delete iNotificationClient;
       
   660         iNotificationClient = NULL;
       
   661     }
       
   662     CClientMtmRegistry* mtmRegistry = 
       
   663             CClientMtmRegistry::NewL( *iMsvSession );
       
   664     iNotificationClient = static_cast<CMmsNotificationClientMtm*>( 
       
   665                     mtmRegistry->NewMtmL( KUidMsgMMSNotification ));
       
   666     iNotificationClient->SwitchCurrentEntryL(messageId);
       
   667     iNotificationClient->LoadMessageL();
       
   668 }
       
   669 
       
   670 //---------------------------------------------------------------
       
   671 // ConversationMsgStoreHandler::NotificationMsgSize
       
   672 // @see header
       
   673 //---------------------------------------------------------------
       
   674 QString ConversationMsgStoreHandler::NotificationMsgSize()
       
   675 {
       
   676     // Size of message.
       
   677     TInt size = iNotificationClient->MessageTransferSize( );
       
   678     
       
   679     // read max receive size limit from settings
       
   680     CMmsSettings* settings = CMmsSettings::NewL();
       
   681     CleanupStack::PushL( settings );
       
   682     iNotificationClient->RestoreSettingsL();
       
   683     settings->CopyL( iNotificationClient->MmsSettings() );
       
   684     TInt maxSize = static_cast<TInt>(settings->MaximumReceiveSize() );
       
   685     CleanupStack::PopAndDestroy( settings );
       
   686 
       
   687     // apply max size limit rule
       
   688     if( maxSize > 0 )
       
   689     {
       
   690         if( size > maxSize )
       
   691         {
       
   692             size = maxSize;
       
   693         }
       
   694     }
       
   695 
       
   696     // Finally make the UI string
       
   697     int fileSize = size / BYTES_TO_KBYTES_FACTOR;
       
   698     if ( size % BYTES_TO_KBYTES_FACTOR )
       
   699     {
       
   700         fileSize++;
       
   701     }
       
   702     // TODO: use localized string constants here
       
   703     QString sizeString = QString("%1").arg(fileSize);
       
   704     sizeString.append(" Kb");
       
   705     return sizeString;
       
   706 }
       
   707 
       
   708 //---------------------------------------------------------------
       
   709 // ConversationMsgStoreHandler::NotificationClass
       
   710 // @see header
       
   711 //---------------------------------------------------------------
       
   712 QString ConversationMsgStoreHandler::NotificationClass()
       
   713 {
       
   714     //TODO: use localized string
       
   715     QString notificationClass;
       
   716     TInt msgClass = iNotificationClient->MessageClass( );
       
   717     switch( msgClass )
       
   718     {
       
   719         case EMmsClassPersonal:
       
   720         {
       
   721             notificationClass = "Personal";
       
   722             break;
       
   723         }
       
   724         case EMmsClassAdvertisement:
       
   725         {
       
   726             notificationClass = "Advertisement";
       
   727             break;
       
   728         }
       
   729         case EMmsClassInformational:
       
   730         {
       
   731             notificationClass = "Informative";
       
   732             break;
       
   733         }
       
   734         default:
       
   735         {   // In case no class is returned (0), don't add the field
       
   736             break;
       
   737         }
       
   738     }
       
   739     return notificationClass;
       
   740 }
       
   741 
       
   742 //---------------------------------------------------------------
       
   743 // ConversationMsgStoreHandler::NotificationStatus
       
   744 // @see header
       
   745 //---------------------------------------------------------------
       
   746 void ConversationMsgStoreHandler::NotificationStatus(
       
   747         int& status,
       
   748         QString& statusStr)
       
   749 {
       
   750     // TODO : use standard strings provided by Arul
       
   751     // fetch mms notification status from store handler
       
   752     // and map as per our UI requirements
       
   753     TMsvEntry entry = iNotificationClient->Entry().Entry();
       
   754     status = MmsNotificationStatus(entry.Id());
       
   755     switch(status)
       
   756     {
       
   757         case ConvergedMessage::NotifFailed:
       
   758         {
       
   759             statusStr = "Message retrieval failed !";
       
   760             break;
       
   761         }
       
   762         case ConvergedMessage::NotifExpired:
       
   763         {
       
   764             statusStr = "Message Expired !";
       
   765             break;
       
   766         }
       
   767         case ConvergedMessage::NotifReadyForFetching:
       
   768         {
       
   769             statusStr = "Multimedia Message waiting...";
       
   770             break;
       
   771         }
       
   772         case ConvergedMessage::NotifWaiting:
       
   773         case ConvergedMessage::NotifRetrieving:
       
   774         {
       
   775             statusStr = "Retrieving message...";
       
   776             break;
       
   777         }
       
   778         default:
       
   779         {
       
   780             // not handled, do nothing
       
   781             break;
       
   782         }
       
   783     }
       
   784 }
       
   785 
       
   786 //---------------------------------------------------------------
       
   787 // ConversationMsgStoreHandler::NotificationExpiryDate
       
   788 // @see header
       
   789 //---------------------------------------------------------------
       
   790 void ConversationMsgStoreHandler::NotificationExpiryDate(
       
   791         TTime& expiryTime,
       
   792         QString& expiryTimeStr)
       
   793 {
       
   794     // get expiry time from entry
       
   795     expiryTime = iNotificationClient->ExpiryDate( );
       
   796     TLocale locale;
       
   797     expiryTime += locale.UniversalTimeOffset();
       
   798     if (locale.QueryHomeHasDaylightSavingOn())          
       
   799     {
       
   800         TTimeIntervalHours daylightSaving(1);          
       
   801         expiryTime += daylightSaving;
       
   802     }
       
   803     
       
   804     // create formatted string for the expiry time
       
   805     TTime unixEpoch(KUnixEpoch);
       
   806     TTimeIntervalSeconds seconds;
       
   807     expiryTime.SecondsFrom(unixEpoch, seconds);
       
   808     QDateTime dateTime;
       
   809     dateTime.setTime_t(seconds.Int());
       
   810     if (dateTime.date() == QDateTime::currentDateTime().date()) {
       
   811         expiryTimeStr = dateTime.toString(TIME_FORMAT);
       
   812     }
       
   813     else {
       
   814         expiryTimeStr = dateTime.toString(DATE_FORMAT);
       
   815     }
       
   816 }
       
   817 
       
   818 //-----------------------------------------------------------------------------
       
   819 // ConversationMsgStoreHandler::DownloadMessageL
       
   820 // 
       
   821 // -----------------------------------------------------------------------------
       
   822 //  
       
   823     
       
   824 TInt ConversationMsgStoreHandler::DownloadMessageL(TMsvId aId)
       
   825 {
       
   826     TMsvId serviceId;
       
   827     TMsvEntry msgEntry;
       
   828 
       
   829     TInt err = iMsvSession->GetEntry(aId,serviceId,msgEntry);
       
   830 
       
   831     if(err!= KErrNone || msgEntry.iMtm!= KUidMsgMMSNotification)
       
   832     {
       
   833         return KErrGeneral;
       
   834     }
       
   835 
       
   836     /*if(!iNotificationClient)
       
   837     {
       
   838         iNotificationClient = static_cast<CMmsNotificationClientMtm*> 
       
   839         (iMtmReg->NewMtmL(KUidMsgMMSNotification));
       
   840     }
       
   841     iNotificationClient->SwitchCurrentEntryL(aId);    */ 
       
   842     
       
   843     // set context to current entry
       
   844     setNotificationMessageId(aId);
       
   845 
       
   846     TTime currentTime;
       
   847     currentTime.HomeTime( );
       
   848     TTime expiryTime = iNotificationClient->ExpiryDate( );
       
   849     TLocale locale;
       
   850     expiryTime += locale.UniversalTimeOffset();
       
   851     if (locale.QueryHomeHasDaylightSavingOn())          
       
   852     {
       
   853         TTimeIntervalHours daylightSaving(1);          
       
   854         expiryTime += daylightSaving;
       
   855     }
       
   856 
       
   857     if( currentTime > expiryTime )
       
   858     {   // Message is expired
       
   859         return KErrGeneral;
       
   860     }
       
   861 
       
   862     //Check if the mms client mtm object is already created or not
       
   863     if( iMmsClient )
       
   864     {
       
   865         // If mms client mtm object is already created restore the settings
       
   866         iMmsClient->RestoreSettingsL();
       
   867     }
       
   868     else
       
   869     {
       
   870         iMmsClient = static_cast<CMmsClientMtm*> (iMtmReg->NewMtmL(KMmsMtmUid));
       
   871     }        
       
   872 
       
   873     //TODO chk if only AP check is sufficient
       
   874     TMsvId service = iMmsClient->DefaultServiceL();
       
   875     TBool valid( iMmsClient->ValidateService( service ) == KErrNone );
       
   876     if(!valid)
       
   877     {
       
   878         return KErrNotFound;
       
   879     }
       
   880 
       
   881     CMuiuOperationWait* wait =CMuiuOperationWait::NewLC();;
       
   882 
       
   883     CMsvEntrySelection* sel = new ( ELeave ) CMsvEntrySelection;
       
   884     CleanupStack::PushL( sel );
       
   885     sel->AppendL( aId );    
       
   886 
       
   887     CMsvOperation* op = 
       
   888             iNotificationClient->FetchMessagesL( *sel, wait->iStatus );
       
   889 
       
   890     if( !op )
       
   891     {  
       
   892         CleanupStack::PopAndDestroy( sel ); // selection
       
   893         CleanupStack::PopAndDestroy( wait ); // wait
       
   894         return KErrGeneral; 
       
   895     }
       
   896 
       
   897     CleanupStack::PushL( op );
       
   898     wait->Start();
       
   899     // Lets ignore the return value of wait
       
   900 
       
   901     CleanupStack::PopAndDestroy( op ); // op 
       
   902     CleanupStack::PopAndDestroy( sel ); // selection
       
   903     CleanupStack::PopAndDestroy( wait ); // wait
       
   904 
       
   905     return KErrNone;
       
   906 }
       
   907 
       
   908 //----------------------------------------------------------------------------
       
   909 // ConversationMsgStoreHandler::markAsReadAndGetType
       
   910 // @see header
       
   911 //----------------------------------------------------------------------------
       
   912 void ConversationMsgStoreHandler::markAsReadAndGetType(int msgId,
       
   913                                                       int& msgType,
       
   914                                                       int& msgSubType)
       
   915     {
       
   916     msgType = ConvergedMessage::None;
       
   917     msgSubType = ConvergedMessage::None;
       
   918     
       
   919     CMsvEntry* cEntry = NULL;
       
   920     TRAPD(err, cEntry = iMsvSession->GetEntryL(msgId));
       
   921     if ( err == KErrNone)
       
   922         {
       
   923         TMsvEntry entry = cEntry->Entry();
       
   924         if ( entry.Unread() ) 
       
   925             {
       
   926             // Mark the entry as read
       
   927             entry.SetUnread( EFalse );
       
   928             cEntry->ChangeL( entry );
       
   929             }
       
   930         // extract message type
       
   931         extractMsgType(entry,msgType,msgSubType);
       
   932         }
       
   933     
       
   934     delete cEntry;
       
   935     }
       
   936 
       
   937 //----------------------------------------------------------------------------
       
   938 // ConversationMsgStoreHandler::extractMsgType
       
   939 // @see header
       
   940 //----------------------------------------------------------------------------
       
   941 void ConversationMsgStoreHandler::extractMsgType(const TMsvEntry& entry,
       
   942                                     int& msgType,
       
   943                                     int& msgSubType)
       
   944     {
       
   945     msgType = ConvergedMessage::None;
       
   946     msgSubType = ConvergedMessage::None;
       
   947 
       
   948     switch(entry.iMtm.iUid)   
       
   949         {
       
   950         case KSenduiMtmSmsUidValue:            
       
   951             msgType = ConvergedMessage::Sms;
       
   952             break;
       
   953         case KSenduiMtmBtUidValue:
       
   954             msgType = ConvergedMessage::BT;
       
   955             break;
       
   956         case KSenduiMtmMmsUidValue:        
       
   957             msgType = ConvergedMessage::Mms;
       
   958             break;
       
   959         case KSenduiMMSNotificationUidValue:            
       
   960             msgType = ConvergedMessage::MmsNotification;
       
   961             break;
       
   962         case KSenduiMtmBioUidValue:
       
   963             { 
       
   964             msgType = ConvergedMessage::BioMsg; 
       
   965 
       
   966             // based on the biotype uid set message type
       
   967             if(entry.iBioType == KMsgBioUidRingingTone.iUid)
       
   968                 {
       
   969                 msgSubType = ConvergedMessage::RingingTone;
       
   970                 }
       
   971             else if(entry.iBioType == KMsgBioProvisioningMessage.iUid)
       
   972                 {
       
   973                 msgSubType = ConvergedMessage::Provisioning;
       
   974                 }     
       
   975             else if (entry.iBioType == KMsgBioUidVCard.iUid)
       
   976                 {
       
   977                 msgSubType = ConvergedMessage::VCard;
       
   978                 }
       
   979             else if (entry.iBioType == KMsgBioUidVCalendar.iUid)
       
   980                 {
       
   981                 msgSubType = ConvergedMessage::VCal;
       
   982                 }        
       
   983             }
       
   984             break;
       
   985         default:
       
   986             msgType = ConvergedMessage::None;       
       
   987             break;
       
   988         }
       
   989     }
   416 // End of file
   990 // End of file