messagingapp/msgutils/unidatautils/unidatamodelplugins/unibiomessagedataplugin/src/unibiomessagedataplugin_p.cpp
changeset 25 84d9eb65b26f
child 34 84197e66a4bd
child 37 518b245aa84c
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     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 //SYSTEM INCLUDES
       
    19 #include <e32cmn.h>
       
    20 #include <mtclreg.h>
       
    21 #include <mtclbase.h>
       
    22 #include <msvids.h>
       
    23 #include <txtetext.h>
       
    24 #include <txtrich.h>
       
    25 #include <txtfmlyr.h>
       
    26 #include <smsclnt.h>
       
    27 
       
    28 #include <bioscmds.h>
       
    29 #include <biocmtm.h>
       
    30 #include "debugtraces.h"
       
    31 
       
    32 #include <QDateTime>
       
    33 #include <s60qconversions.h>
       
    34 #include <mmsvattachmentmanager.h>
       
    35 
       
    36 #include "convergedmessage.h"
       
    37 #include "convergedmessageaddress.h"
       
    38 #include "unibiomessagedataplugin_p.h"
       
    39 
       
    40 #define KBioUidValue  0x10001262
       
    41 const TUid KBioUidValueUid =
       
    42 {KBioUidValue};
       
    43 _LIT(KUnixEpoch, "19700000:000000.000000");
       
    44 
       
    45 //---------------------------------------------------------------
       
    46 // UniBioMessageDataPluginPrivate::~UniBioMessageDataPluginPrivate
       
    47 // @see header
       
    48 //---------------------------------------------------------------
       
    49 UniBioMessageDataPluginPrivate::~UniBioMessageDataPluginPrivate()
       
    50 {
       
    51     q_ptr = NULL;
       
    52     if (iMsvEntry)
       
    53     {
       
    54         delete iMsvEntry;
       
    55     }
       
    56 
       
    57     delete iBioClientMtm;
       
    58     delete iMtmReg;
       
    59     delete iMSession;
       
    60 
       
    61 }
       
    62 
       
    63 //---------------------------------------------------------------
       
    64 // UniBioMessageDataPluginPrivate::UniBioMessageDataPluginPrivate
       
    65 // @see header
       
    66 //---------------------------------------------------------------
       
    67 UniBioMessageDataPluginPrivate::UniBioMessageDataPluginPrivate(UniBioMessageDataPlugin* plugin) :
       
    68     q_ptr(plugin), iMSession(NULL), iMtmReg(NULL), iBioClientMtm(NULL),
       
    69             iMsvEntry(NULL)
       
    70 {
       
    71     iMSession = CMsvSession::OpenSyncL(*this);
       
    72     done = EFalse;
       
    73 }
       
    74 
       
    75 
       
    76 
       
    77 
       
    78 void UniBioMessageDataPluginPrivate::initL()
       
    79 {
       
    80     iMtmReg = CClientMtmRegistry::NewL(*iMSession);
       
    81     iBioClientMtm = (CBIOClientMtm*) iMtmReg->NewMtmL(KBioUidValueUid);
       
    82 
       
    83     attachmentProcessed = EFalse;
       
    84     done = ETrue;
       
    85 
       
    86 }
       
    87 
       
    88 //---------------------------------------------------------------
       
    89 // UniBioMessageDataPluginPrivate::reset
       
    90 // @see header
       
    91 //---------------------------------------------------------------
       
    92 void UniBioMessageDataPluginPrivate::reset()
       
    93 {
       
    94 }
       
    95 
       
    96 //---------------------------------------------------------------
       
    97 // UniBioMessageDataPluginPrivate::setMessageId
       
    98 // @see header
       
    99 //---------------------------------------------------------------
       
   100 int UniBioMessageDataPluginPrivate::setMessageId(int mId)
       
   101 {
       
   102     TInt error = KErrNone;
       
   103     TRAP(error, setMessageIdL(mId));
       
   104     return error;
       
   105 }
       
   106 
       
   107 //---------------------------------------------------------------
       
   108 // UniBioMessageDataPluginPrivate::setMessageIdL
       
   109 // @see header
       
   110 //---------------------------------------------------------------
       
   111 void UniBioMessageDataPluginPrivate::setMessageIdL(int mId)
       
   112 {
       
   113     if (done == EFalse)
       
   114     {
       
   115         initL();
       
   116     }
       
   117     if (iMessageId != mId)
       
   118     {
       
   119         attachmentProcessed = EFalse;
       
   120     }
       
   121 
       
   122     iMessageId = (TMsvId) mId;
       
   123     iBioClientMtm->SwitchCurrentEntryL(iMessageId);
       
   124 
       
   125     iMsvEntry = CMsvEntry::NewL(iBioClientMtm->Session(),
       
   126                                 iMessageId,
       
   127                                 TMsvSelectionOrdering());
       
   128 
       
   129     iBioClientMtm->LoadMessageL();
       
   130 }
       
   131 
       
   132 //---------------------------------------------------------------
       
   133 // UniBioMessageDataPluginPrivate::body
       
   134 // @see header
       
   135 //---------------------------------------------------------------
       
   136 void UniBioMessageDataPluginPrivate::body(QString& aBodyText)
       
   137 {
       
   138 
       
   139     CRichText& textBody = iBioClientMtm->Body();
       
   140     TInt len = textBody.DocumentLength();
       
   141     HBufC* buf = HBufC::NewL(len);
       
   142     TPtr bufPtr = buf->Des();
       
   143     textBody.ExtractSelectively(bufPtr, 0, len, CPlainText::EExtractAll);
       
   144     aBodyText = S60QConversions::s60DescToQString(*buf);
       
   145     delete buf;
       
   146 }
       
   147 
       
   148 //---------------------------------------------------------------
       
   149 // UniBioMessageDataPluginPrivate::messageSize
       
   150 // @see header
       
   151 //---------------------------------------------------------------
       
   152 qint32 UniBioMessageDataPluginPrivate::messageSize()
       
   153 {
       
   154     return iBioClientMtm->Entry().Entry().iSize;
       
   155 }
       
   156 
       
   157 //---------------------------------------------------------------
       
   158 // UniBioMessageDataPluginPrivate::toRecipientList
       
   159 // @see header
       
   160 //---------------------------------------------------------------
       
   161 void UniBioMessageDataPluginPrivate::toRecipientList(
       
   162                                                ConvergedMessageAddressList& mAddressList)
       
   163 {
       
   164     TPtrC name;
       
   165     TPtrC address;
       
   166 
       
   167     CPlainText* pText = CPlainText::NewL();
       
   168     CleanupStack::PushL(pText);
       
   169 
       
   170     CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *pText);
       
   171     CleanupStack::PushL(smsHeader);
       
   172 
       
   173     CMsvStore* store = iMsvEntry->ReadStoreL();
       
   174     CleanupStack::PushL(store);
       
   175 
       
   176     smsHeader->RestoreL(*store);
       
   177 
       
   178     for (TInt id = 0; id < smsHeader->Recipients().Count(); ++id)
       
   179     {
       
   180         CSmsNumber* rcpt = smsHeader->Recipients()[id];
       
   181         name.Set(rcpt->Name());
       
   182         address.Set(rcpt->Address());
       
   183 
       
   184         ConvergedMessageAddress
       
   185                 * messageAddress =
       
   186                         new ConvergedMessageAddress(S60QConversions::s60DescToQString(address),
       
   187                                                     S60QConversions::s60DescToQString(name));
       
   188         mAddressList.append(messageAddress);
       
   189     }
       
   190     CleanupStack::PopAndDestroy(3, pText);
       
   191 
       
   192 }
       
   193 
       
   194 //---------------------------------------------------------------
       
   195 // UniBioMessageDataPluginPrivate::fromAddress
       
   196 // @see header
       
   197 //---------------------------------------------------------------
       
   198 void UniBioMessageDataPluginPrivate::fromAddress(QString& messageAddress)
       
   199 {
       
   200     CPlainText* pText = CPlainText::NewL();
       
   201     CleanupStack::PushL(pText);
       
   202 
       
   203     CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *pText);
       
   204     CleanupStack::PushL(smsHeader);
       
   205 
       
   206     CMsvStore* store = iMsvEntry->ReadStoreL();
       
   207     CleanupStack::PushL(store);
       
   208 
       
   209     smsHeader->RestoreL(*store);
       
   210 
       
   211     messageAddress
       
   212             = S60QConversions::s60DescToQString(smsHeader->FromAddress());
       
   213     CleanupStack::PopAndDestroy(3, pText);
       
   214 }
       
   215 
       
   216 //---------------------------------------------------------------
       
   217 // UniBioMessageDataPluginPrivate::timeStamp
       
   218 // @see header
       
   219 //---------------------------------------------------------------
       
   220 int UniBioMessageDataPluginPrivate::timeStamp()
       
   221 {
       
   222     QDateTime retTimeStamp;
       
   223     TTime timeStamp = iBioClientMtm->Entry().Entry().iDate;
       
   224     TTime unixEpoch(KUnixEpoch);
       
   225     TTimeIntervalSeconds seconds;
       
   226     timeStamp.SecondsFrom(unixEpoch, seconds);
       
   227     return seconds.Int();
       
   228 }
       
   229 
       
   230 //---------------------------------------------------------------
       
   231 // UniBioMessageDataPluginPrivate::attachmentList
       
   232 // @see header
       
   233 //---------------------------------------------------------------
       
   234 RFile UniBioMessageDataPluginPrivate::attachmentL()
       
   235 {
       
   236     if (attachmentProcessed)
       
   237     {
       
   238 
       
   239         CMsvStore* store1 = iMsvEntry->ReadStoreL();
       
   240         CleanupStack::PushL(store1);
       
   241         MMsvAttachmentManager& attachMan = store1->AttachmentManagerL();
       
   242         RFile file = attachMan.GetAttachmentFileL(0);
       
   243         CleanupStack::PopAndDestroy(store1);
       
   244         return file;
       
   245     }
       
   246 
       
   247     CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   248     CleanupStack::PushL(selection);
       
   249 
       
   250     selection->AppendL(iMessageId);
       
   251 
       
   252     TBuf8<1> aParameter;
       
   253     CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC();
       
   254     
       
   255     CMsvOperation* operation =
       
   256             iBioClientMtm->InvokeAsyncFunctionL(KBiosMtmParse,
       
   257                                                 *selection,
       
   258                                                 aParameter,
       
   259                                                 wait->iStatus);
       
   260 
       
   261     wait->Start();
       
   262 
       
   263     CMsvStore* store = iMsvEntry->ReadStoreL();
       
   264     CleanupStack::PushL(store);
       
   265     MMsvAttachmentManager& attachMan = store->AttachmentManagerL();
       
   266 
       
   267     iAttachmentCount = attachMan.AttachmentCount();
       
   268 
       
   269     RFile file = attachMan.GetAttachmentFileL(0);
       
   270 
       
   271     delete operation;
       
   272     CleanupStack::PopAndDestroy(3,selection);
       
   273     attachmentProcessed = ETrue;
       
   274     return file;
       
   275 
       
   276 }
       
   277 
       
   278 //---------------------------------------------------------------
       
   279 // UniBioMessageDataPluginPrivate::attachmentCount
       
   280 // @see header
       
   281 //---------------------------------------------------------------
       
   282 
       
   283 int UniBioMessageDataPluginPrivate::attachmentCount()
       
   284 {
       
   285     if (!attachmentProcessed)
       
   286     {
       
   287         RFile file = attachmentL();
       
   288         file.Close();
       
   289     }
       
   290 
       
   291     return (int) iAttachmentCount;
       
   292 }
       
   293 
       
   294 //---------------------------------------------------------------
       
   295 // UniBioMessageDataPluginPrivate::messagePriority
       
   296 // @see header
       
   297 //---------------------------------------------------------------
       
   298 
       
   299 MsgPriority UniBioMessageDataPluginPrivate::messagePriority()
       
   300 {
       
   301 
       
   302     MsgPriority priority = (MsgPriority) iMsvEntry->Entry().Priority();
       
   303     return priority;
       
   304 }
       
   305 
       
   306 //---------------------------------------------------------------
       
   307 // UniBioMessageDataPluginPrivate::session
       
   308 // @see header
       
   309 //---------------------------------------------------------------
       
   310 CMsvSession* UniBioMessageDataPluginPrivate::session()
       
   311 {
       
   312     return iMSession;
       
   313 }
       
   314 
       
   315 //---------------------------------------------------------------
       
   316 // UniBioMessageDataPluginPrivate::HandleSessionEventL
       
   317 // @see header
       
   318 //---------------------------------------------------------------
       
   319 void UniBioMessageDataPluginPrivate::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
   320                                                   TAny* /*aArg1*/,
       
   321                                                   TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   322 {
       
   323 // do nothing
       
   324 }
       
   325 
       
   326