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