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