btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewerutils.cpp
changeset 47 9e2a905b887f
parent 42 b72428996822
child 57 5ebadcda06cb
equal deleted inserted replaced
45:b0aebde9b1fb 47:9e2a905b887f
    14  * Description:  
    14  * Description:  
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <mmsvattachmentmanager.h>
    18 #include <mmsvattachmentmanager.h>
       
    19 #include <apgcli.h>
    19 #include "btmsgviewerutils.h"
    20 #include "btmsgviewerutils.h"
    20 
    21 
       
    22 const TInt32 KUidMsgTypeBtTInt32 = 0x10009ED5;
    21 
    23 
       
    24     
    22 CBtMsgViewerUtils* CBtMsgViewerUtils::NewL()
    25 CBtMsgViewerUtils* CBtMsgViewerUtils::NewL()
    23     {
    26     {
    24     CBtMsgViewerUtils* me = new (ELeave) CBtMsgViewerUtils();
    27     CBtMsgViewerUtils* me = new (ELeave) CBtMsgViewerUtils();
    25     CleanupStack::PushL(me);
    28     CleanupStack::PushL(me);
    26     me->ConstructL();
    29     me->ConstructL();
    40 
    43 
    41 CBtMsgViewerUtils::~CBtMsgViewerUtils()
    44 CBtMsgViewerUtils::~CBtMsgViewerUtils()
    42     {
    45     {
    43     if ( iMsvSession )
    46     if ( iMsvSession )
    44         {
    47         {
    45 		 delete iMsvSession;
    48         delete iMsvSession;
    46         }
    49         }
       
    50     delete iMimeType;
    47     }
    51     }
    48 
    52 
    49 HBufC* CBtMsgViewerUtils::GetMessagePath(TInt aMessageId, TInt aError)
    53 HBufC* CBtMsgViewerUtils::GetMessagePath(TInt aMessageId, TInt aError)
    50     {
    54     {
    51     HBufC* fileName = NULL;
    55     HBufC* fileName = NULL;
    60     }
    64     }
    61 
    65 
    62 void CBtMsgViewerUtils::GetMessagePathL(TPtr aMsgPath, const TInt aMessageId)
    66 void CBtMsgViewerUtils::GetMessagePathL(TPtr aMsgPath, const TInt aMessageId)
    63     {
    67     {
    64     CMsvEntry* messageEntry = iMsvSession->GetEntryL(aMessageId);
    68     CMsvEntry* messageEntry = iMsvSession->GetEntryL(aMessageId);
    65     CleanupStack::PushL(messageEntry);
    69     CleanupStack::PushL(messageEntry); //1st push
    66     
    70     
    67     CMsvEntry* attachmentEntry = iMsvSession->GetEntryL((*messageEntry)[0].Id());
    71     TMsvEntry entry = messageEntry->Entry();
    68     CleanupStack::PushL(attachmentEntry);
    72     if(entry.MtmData1() == KUidMsgTypeBtTInt32)
    69     
    73         {
    70     CMsvStore* store = attachmentEntry->EditStoreL();
    74         CMsvStore* store = messageEntry->ReadStoreL();
    71     CleanupStack::PushL(store); 
    75         CleanupStack::PushL(store); //2nd push
    72     
    76 
    73     //get file handle for the attachment & the complete path of the file
    77         //get file handle for the attachment & the complete path of the file
    74     RFile attachmentFile;
    78         RFile attachmentFile;
    75     attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
    79         attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
    76     attachmentFile.FullName(aMsgPath);
    80         CleanupClosePushL(attachmentFile); //3rd push
    77     attachmentFile.Close();
    81         User::LeaveIfError(attachmentFile.FullName(aMsgPath));
    78     
    82         CleanupStack::PopAndDestroy(&attachmentFile);
    79     //mark attachment as Read
    83         StoreMessageMimeTypeL(aMsgPath);
    80     TMsvEntry attachEntry = attachmentEntry->Entry();
    84         
    81     attachEntry.SetUnread(EFalse);
    85         //mark attachment as Read
    82     attachmentEntry->ChangeL(attachEntry);
    86         TMsvEntry attachEntry = messageEntry->Entry();
    83     
    87         attachEntry.SetUnread(EFalse);
    84     CleanupStack::PopAndDestroy(store);
    88         messageEntry->ChangeL(attachEntry);
    85     CleanupStack::PopAndDestroy(attachmentEntry);
    89         
    86     CleanupStack::PopAndDestroy(messageEntry);
    90         CleanupStack::PopAndDestroy(store);
       
    91         CleanupStack::PopAndDestroy(messageEntry);
       
    92         }
       
    93     else
       
    94         {
       
    95         CMsvEntry* attachmentEntry = iMsvSession->GetEntryL((*messageEntry)[0].Id());
       
    96         CleanupStack::PushL(attachmentEntry); //2nd push
       
    97             
       
    98         CMsvStore* store = attachmentEntry->ReadStoreL();
       
    99         CleanupStack::PushL(store);  //3rd push
       
   100         
       
   101         //get file handle for the attachment & the complete path of the file
       
   102         RFile attachmentFile;
       
   103         attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
       
   104         CleanupClosePushL(attachmentFile);
       
   105         User::LeaveIfError(attachmentFile.FullName(aMsgPath));
       
   106         CleanupStack::PopAndDestroy(&attachmentFile);
       
   107         StoreMessageMimeTypeL(aMsgPath);
       
   108         
       
   109         //mark attachment as Read
       
   110         TMsvEntry attachEntry = attachmentEntry->Entry();
       
   111         attachEntry.SetUnread(EFalse);
       
   112         attachmentEntry->ChangeL(attachEntry);
       
   113         
       
   114         CleanupStack::PopAndDestroy(store);
       
   115         CleanupStack::PopAndDestroy(attachmentEntry);
       
   116         CleanupStack::PopAndDestroy(messageEntry);
       
   117         }
    87     }
   118     }
    88 
   119 
    89 void CBtMsgViewerUtils::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, 
   120 void CBtMsgViewerUtils::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, 
    90                                                     TAny* aArg2, TAny* aArg3)
   121                                                     TAny* aArg2, TAny* aArg3)
    91     {
   122     {
    93     (void) aArg1;
   124     (void) aArg1;
    94     (void) aArg2;
   125     (void) aArg2;
    95     (void) aArg3;
   126     (void) aArg3;
    96     }
   127     }
    97 
   128 
       
   129 void CBtMsgViewerUtils::StoreMessageMimeTypeL(TPtr aMsgPath)
       
   130     {
       
   131     RFs rfs;
       
   132     RFile file;
       
   133     
       
   134     User::LeaveIfError(rfs.Connect());
       
   135     
       
   136     User::LeaveIfError(rfs.ShareProtected());
       
   137     
       
   138     User::LeaveIfError(file.Open(rfs, aMsgPath, EFileShareReadersOrWriters | EFileRead));
       
   139     
       
   140     TDataRecognitionResult dataType;
       
   141     RApaLsSession apaSession;
       
   142     
       
   143     if(apaSession.Connect() == KErrNone)
       
   144         {
       
   145         if (apaSession.RecognizeData(file, dataType) == KErrNone)
       
   146             {
       
   147             if(iMimeType)
       
   148                 {
       
   149                 delete iMimeType;
       
   150                 iMimeType = NULL;
       
   151                 }
       
   152         
       
   153             iMimeType = dataType.iDataType.Des8().AllocL();
       
   154             
       
   155             rfs.Close();
       
   156             apaSession.Close();
       
   157             }
       
   158         }
    98 
   159 
       
   160     rfs.Close();
       
   161     }
    99 
   162 
       
   163 HBufC8* CBtMsgViewerUtils::GetMimeType()
       
   164     {
       
   165     return iMimeType;
       
   166     }