messagingapp/msgutils/unieditorutils/unieditorplugins/unieditorsmsplugin/src/unieditorsmsplugin_p.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 41 25fe1fe642e3
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    55 #include "msgbiouids.h"
    55 #include "msgbiouids.h"
    56 #include "unieditorsmsplugin_p.h"
    56 #include "unieditorsmsplugin_p.h"
    57 #include "convergedmessage.h"
    57 #include "convergedmessage.h"
    58 #include "convergedmessageid.h"
    58 #include "convergedmessageid.h"
    59 #include "convergedmessageattachment.h"
    59 #include "convergedmessageattachment.h"
    60 #include "s60qconversions.h"
    60 
    61 #include "MuiuOperationWait.h"
    61 #include "MuiuOperationWait.h"
    62 #include "UniEditorGenUtils.h"
    62 #include "UniEditorGenUtils.h"
    63 #include "unidatamodelloader.h"
    63 #include "unidatamodelloader.h"
    64 #include "unidatamodelplugininterface.h"
    64 #include "unidatamodelplugininterface.h"
    65 #include <hbglobal.h> // for translation support
    65 #include <hbglobal.h> // for translation support
    66 
    66 #include <xqconversions.h>
    67 // resources
    67 // resources
    68 
    68 
    69 // CONSTANTS
    69 // CONSTANTS
    70 
    70 
    71 // Used to set msg in unparsed state
    71 // Used to set msg in unparsed state
   434 
   434 
   435     ConvergedMessageAddressList addrList = message->toAddressList();
   435     ConvergedMessageAddressList addrList = message->toAddressList();
   436     int addrCount = addrList.count();
   436     int addrCount = addrList.count();
   437     for(int i=0; i<addrCount; i++)
   437     for(int i=0; i<addrCount; i++)
   438     {
   438     {
   439         HBufC* addr = S60QConversions::qStringToS60Desc( addrList.at(i)->address() );
   439         HBufC* addr = XQConversions::qStringToS60Desc( addrList.at(i)->address() );
   440         HBufC* alt_alias = S60QConversions::qStringToS60Desc( addrList.at(i)->alias() );
   440         HBufC* alt_alias = XQConversions::qStringToS60Desc( addrList.at(i)->alias() );
   441         if(addr)
   441         if(addr->Length() > 0)
   442         {
   442         {
   443             CleanupStack::PushL(addr);
   443             CleanupStack::PushL(addr);
   444             if(alt_alias)
   444             if(alt_alias->Length() > 0)
   445                 CleanupStack::PushL(alt_alias);
   445                 CleanupStack::PushL(alt_alias);
   446             HBufC* pureAddr = TMmsGenUtils::PureAddress( *addr ).AllocLC();
   446             HBufC* pureAddr = TMmsGenUtils::PureAddress( *addr ).AllocLC();
   447             HBufC* aliasAddr = TMmsGenUtils::Alias( *addr ).AllocLC();
   447             HBufC* aliasAddr = TMmsGenUtils::Alias( *addr ).AllocLC();
   448             TInt appendLen = KMaxDetailsLength-idetailsBuf.Length();
   448             TInt appendLen = KMaxDetailsLength-idetailsBuf.Length();
   449             TPtrC appendbuf;
   449             TPtrC appendbuf;
   459                     SmsMtmL()->AddAddresseeL( *pureAddr, *aliasAddr );
   459                     SmsMtmL()->AddAddresseeL( *pureAddr, *aliasAddr );
   460                     appendbuf.Set(aliasAddr->Des().Left(appendLen));
   460                     appendbuf.Set(aliasAddr->Des().Left(appendLen));
   461                 }
   461                 }
   462                 else
   462                 else
   463                 {
   463                 {
   464                     if(alt_alias)
   464                     if(alt_alias->Length() > 0)
   465                     {
   465                     {
   466                         SmsMtmL()->AddAddresseeL( *pureAddr, *alt_alias );
   466                         SmsMtmL()->AddAddresseeL( *pureAddr, *alt_alias );
   467                         appendbuf.Set(alt_alias->Des().Left(appendLen));
   467                         appendbuf.Set(alt_alias->Des().Left(appendLen));
   468                     }
   468                     }
   469                     else
   469                     else
   480             }
   480             }
   481             iRecipients->AppendL( *addr );
   481             iRecipients->AppendL( *addr );
   482 
   482 
   483             // cleanup
   483             // cleanup
   484             CleanupStack::PopAndDestroy(2, pureAddr );            
   484             CleanupStack::PopAndDestroy(2, pureAddr );            
   485             if(alt_alias)
   485             if(alt_alias->Length() > 0)
   486             {
   486             {
   487                 CleanupStack::PopAndDestroy( alt_alias );
   487                 CleanupStack::PopAndDestroy( alt_alias );
   488             }
   488             }
   489             CleanupStack::PopAndDestroy( addr );
   489             CleanupStack::PopAndDestroy( addr );
   490             
   490             
   503     {
   503     {
   504         // set iDetails
   504         // set iDetails
   505         CMsvEntry& entry = SmsMtmL()->Entry();
   505         CMsvEntry& entry = SmsMtmL()->Entry();
   506         TMsvEntry msvEntry( entry.Entry() );
   506         TMsvEntry msvEntry( entry.Entry() );
   507         msvEntry.iDetails.Set( idetailsBuf );
   507         msvEntry.iDetails.Set( idetailsBuf );
       
   508         entry.ChangeL( msvEntry );
   508         SmsMtmL()->SaveMessageL();
   509         SmsMtmL()->SaveMessageL();
   509         entry.ChangeL( msvEntry );
       
   510     }
   510     }
   511 
   511 
   512     // set subject
   512     // set subject
   513     if ( !message->subject().isEmpty() )
   513     if ( !message->subject().isEmpty() )
   514     {
   514     {
   515         HBufC* subj = S60QConversions::qStringToS60Desc( message->subject() );
   515         HBufC* subj = XQConversions::qStringToS60Desc( message->subject() );
   516         if( subj )
   516         if( subj )
   517         {
   517         {
   518             CleanupStack::PushL( subj );
   518             CleanupStack::PushL( subj );
   519             emailFields->SetSubjectL( *subj );
   519             emailFields->SetSubjectL( *subj );
   520             CleanupStack::PopAndDestroy( subj );
   520             CleanupStack::PopAndDestroy( subj );
   529 // SetSmsBodyL
   529 // SetSmsBodyL
   530 // @see header
   530 // @see header
   531 // -----------------------------------------------------------------------------
   531 // -----------------------------------------------------------------------------
   532 void UniEditorSmsPluginPrivate::SetSmsBodyL(ConvergedMessage* message)
   532 void UniEditorSmsPluginPrivate::SetSmsBodyL(ConvergedMessage* message)
   533 {
   533 {
   534     HBufC8* bodytext = S60QConversions::qStringToS60Desc8( message->bodyText() );
   534     HBufC8* bodytext = XQConversions::qStringToS60Desc8( message->bodyText() );
   535     if( bodytext->Length() > 0)
   535     if( bodytext->Length() > 0)
   536     {
   536     {
   537         CleanupStack::PushL( bodytext );
   537         CleanupStack::PushL( bodytext );
   538         RDesReadStream stream(*bodytext);
   538         RDesReadStream stream(*bodytext);
   539         CleanupClosePushL( stream );
   539         CleanupClosePushL( stream );
   583     QString descr;
   583     QString descr;
   584     if ( attachment )
   584     if ( attachment )
   585         {
   585         {
   586          // create msv attachment in store
   586          // create msv attachment in store
   587         CreateAttachmentL(store,
   587         CreateAttachmentL(store,
   588                 *S60QConversions::qStringToS60Desc(attachment->filePath()));
   588                 *XQConversions::qStringToS60Desc(attachment->filePath()));
   589         
   589         
   590         // check for mimetype of the attachment
   590         // check for mimetype of the attachment
   591         TPtrC8 mimetype;
   591         TPtrC8 mimetype;
   592         int attSize;
   592         int attSize;
   593         QString attMimeType;
   593         QString attMimeType;
   594         TMsgMediaType attMediaType = EMsgMediaUnknown;
   594         TMsgMediaType attMediaType = EMsgMediaUnknown;
   595         iGenUtils->getFileInfoL(attachment->filePath(),
   595         iGenUtils->getFileInfoL(attachment->filePath(),
   596                 attSize, attMimeType, attMediaType);
   596                 attSize, attMimeType, attMediaType);
   597         mimetype.Set( *S60QConversions::qStringToS60Desc8(attMimeType) );
   597         mimetype.Set( *XQConversions::qStringToS60Desc8(attMimeType) );
   598         
   598         
   599         if ( mimetype.CompareF( KMsgMimeTextPlain ) == 0 )
   599         if ( mimetype.CompareF( KMsgMimeTextPlain ) == 0 )
   600             {
   600             {
   601             iBioMsg=EFalse;
   601             iBioMsg=EFalse;
   602             }
   602             }
   632                 buf,
   632                 buf,
   633                 KSmsMessageEntryDescriptionAmountOfChars );    
   633                 KSmsMessageEntryDescriptionAmountOfChars );    
   634     }
   634     }
   635     else if(!descr.isNull())
   635     else if(!descr.isNull())
   636     {
   636     {
   637         buf.Copy( *S60QConversions::qStringToS60Desc(descr) );
   637         buf.Copy( *XQConversions::qStringToS60Desc(descr) );
   638     }
   638     }
   639     tEntry.iDescription.Set( buf );
   639     tEntry.iDescription.Set( buf );
   640 
   640 
   641     // save/commit all changes
   641     // save/commit all changes
   642     SmsMtmL()->SaveMessageL( *store, tEntry );
   642     SmsMtmL()->SaveMessageL( *store, tEntry );
   656     CleanupStack::PushL( attachment );
   656     CleanupStack::PushL( attachment );
   657 
   657 
   658     int attSize;
   658     int attSize;
   659     QString mimeType;
   659     QString mimeType;
   660     TMsgMediaType mediaType = EMsgMediaUnknown;
   660     TMsgMediaType mediaType = EMsgMediaUnknown;
   661     QString filepath = S60QConversions::s60DescToQString( aFilePath );
   661     QString filepath = XQConversions::s60DescToQString( aFilePath );
   662     iGenUtils->getFileInfoL(filepath, attSize, mimeType, mediaType);
   662     iGenUtils->getFileInfoL(filepath, attSize, mimeType, mediaType);
   663     
   663     
   664     attachment->SetSize( attSize );
   664     attachment->SetSize( attSize );
   665     attachment->SetMimeTypeL( *S60QConversions::qStringToS60Desc8(mimeType) );
   665     attachment->SetMimeTypeL( *XQConversions::qStringToS60Desc8(mimeType) );
   666     
   666     
   667     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
   667     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
   668     attachmentManager->AddAttachmentL( aFilePath, attachment, wait->iStatus );
   668     attachmentManager->AddAttachmentL( aFilePath, attachment, wait->iStatus );
   669     wait->Start();
   669     wait->Start();
   670     CleanupStack::PopAndDestroy( wait );
   670     CleanupStack::PopAndDestroy( wait );
   738     CleanupStack::PopAndDestroy(defaultSettings);
   738     CleanupStack::PopAndDestroy(defaultSettings);
   739     CleanupStack::PopAndDestroy( sendOptions );
   739     CleanupStack::PopAndDestroy( sendOptions );
   740     
   740     
   741 
   741 
   742     //Initialize the settings
   742     //Initialize the settings
   743     SetEncodingSettings( iUnicodeMode, ESmsEncodingNone, 
   743     SetEncodingSettingsL( iUnicodeMode, ESmsEncodingNone, 
   744             iCharSupportType);
   744             iCharSupportType);
   745     
   745     
   746     //get bodytext
   746     //get bodytext
   747     TInt smslength = SmsMtmL()->Body().LdDocumentLength();
   747     TInt smslength = SmsMtmL()->Body().LdDocumentLength();
   748     HBufC* body = HBufC::NewLC(smslength);
   748     HBufC* body = HBufC::NewLC(smslength);
   888             }
   888             }
   889         else if (mimetype.CompareF(KMsgMimeVCard) == 0)
   889         else if (mimetype.CompareF(KMsgMimeVCard) == 0)
   890             {
   890             {
   891             CreateVCardSMSL(filehandle);
   891             CreateVCardSMSL(filehandle);
   892             CleanupStack::Pop(&filehandle);
   892             CleanupStack::Pop(&filehandle);
   893             filehandle.Close();
   893             filehandle.Close();         
   894             managerSync.RemoveAttachmentL(0);
       
   895             }
   894             }
   896         else if (mimetype.CompareF(KMsgMimeVCal) == 0 || 
   895         else if (mimetype.CompareF(KMsgMimeVCal) == 0 || 
   897                  mimetype.CompareF(KMsgMimeICal) == 0)
   896                  mimetype.CompareF(KMsgMimeICal) == 0)
   898             {
   897             {
   899             CreateVCalSMSL(filehandle);
   898             CreateVCalSMSL(filehandle);
  1621 // IMPORTANT NOTE:
  1620 // IMPORTANT NOTE:
  1622 // This function is usually called from CV and UE to reset/set alternative
  1621 // This function is usually called from CV and UE to reset/set alternative
  1623 // encoding or char support
  1622 // encoding or char support
  1624 // when corresponding feilds change. Hence aUnicodeMode is always set to false
  1623 // when corresponding feilds change. Hence aUnicodeMode is always set to false
  1625 //------------------------------------------------------------------------------
  1624 //------------------------------------------------------------------------------
  1626 void UniEditorSmsPluginPrivate::SetEncodingSettings( TBool aUnicodeMode,
  1625 void UniEditorSmsPluginPrivate::SetEncodingSettingsL( TBool aUnicodeMode,
  1627     TSmsEncoding aAlternativeEncodingType, 
  1626     TSmsEncoding aAlternativeEncodingType, 
  1628     TInt aCharSupportType)
  1627     TInt aCharSupportType)
  1629     {
  1628     {
  1630     
  1629     
  1631     if ( !iSmsHeader )
  1630     if ( !iSmsHeader )
  1706             }
  1705             }
  1707         else if( numOfUnconvChars || iCharSupportType == TUniSendingSettings::EUniCharSupportFull)
  1706         else if( numOfUnconvChars || iCharSupportType == TUniSendingSettings::EUniCharSupportFull)
  1708             {
  1707             {
  1709             //switch to Unicode
  1708             //switch to Unicode
  1710             //iUnicodeMode = ETrue;
  1709             //iUnicodeMode = ETrue;
  1711             SetEncodingSettings( ETrue, iAlternativeEncodingType, TUniSendingSettings::EUniCharSupportFull);
  1710             SetEncodingSettingsL( ETrue, iAlternativeEncodingType, TUniSendingSettings::EUniCharSupportFull);
  1712             }
  1711             }
  1713         else
  1712         else
  1714             {
  1713             {
  1715             //Get out of while loop and return the results
  1714             //Get out of while loop and return the results
  1716             break;
  1715             break;
  1764         for( TInt id = 0; id < emailRecipients.MdcaCount( ); id++ )
  1763         for( TInt id = 0; id < emailRecipients.MdcaCount( ); id++ )
  1765             {
  1764             {
  1766             HBufC* pureAddr = TMmsGenUtils::PureAddress( emailRecipients.MdcaPoint( id ) ).AllocLC();
  1765             HBufC* pureAddr = TMmsGenUtils::PureAddress( emailRecipients.MdcaPoint( id ) ).AllocLC();
  1767             HBufC* aliasAddr = TMmsGenUtils::Alias( emailRecipients.MdcaPoint( id ) ).AllocLC();
  1766             HBufC* aliasAddr = TMmsGenUtils::Alias( emailRecipients.MdcaPoint( id ) ).AllocLC();
  1768             ConvergedMessageAddress messageAddress(
  1767             ConvergedMessageAddress messageAddress(
  1769                     S60QConversions::s60DescToQString(*pureAddr), 
  1768                     XQConversions::s60DescToQString(*pureAddr), 
  1770                     S60QConversions::s60DescToQString(*aliasAddr));
  1769                     XQConversions::s60DescToQString(*aliasAddr));
  1771             CleanupStack::PopAndDestroy(2, pureAddr );
  1770             CleanupStack::PopAndDestroy(2, pureAddr );
  1772             aMessage->addToRecipient(messageAddress);
  1771             aMessage->addToRecipient(messageAddress);
  1773             }
  1772             }
  1774         }
  1773         }
  1775 
  1774 
  1783             HBufC* pureAddr =
  1782             HBufC* pureAddr =
  1784                     TMmsGenUtils::PureAddress(smsRecipients[i]).AllocLC();
  1783                     TMmsGenUtils::PureAddress(smsRecipients[i]).AllocLC();
  1785             HBufC* aliasAddr =
  1784             HBufC* aliasAddr =
  1786                     TMmsGenUtils::Alias(smsRecipients[i]).AllocLC();
  1785                     TMmsGenUtils::Alias(smsRecipients[i]).AllocLC();
  1787             ConvergedMessageAddress messageAddress(
  1786             ConvergedMessageAddress messageAddress(
  1788                     S60QConversions::s60DescToQString(*pureAddr), 
  1787                     XQConversions::s60DescToQString(*pureAddr), 
  1789                     S60QConversions::s60DescToQString(*aliasAddr));
  1788                     XQConversions::s60DescToQString(*aliasAddr));
  1790             CleanupStack::PopAndDestroy(2, pureAddr );
  1789             CleanupStack::PopAndDestroy(2, pureAddr );
  1791             aMessage->addToRecipient(messageAddress);
  1790             aMessage->addToRecipient(messageAddress);
  1792             }
  1791             }
  1793         }
  1792         }
  1794 
  1793 
  1795     if( emailFields.Subject( ).Length( ) )
  1794     if( emailFields.Subject( ).Length( ) )
  1796         { // If email subject exists -> copy it
  1795         { // If email subject exists -> copy it
  1797         aMessage->setSubject(S60QConversions::s60DescToQString(
  1796         aMessage->setSubject(XQConversions::s60DescToQString(
  1798                 emailFields.Subject()));
  1797                 emailFields.Subject()));
  1799         }
  1798         }
  1800 
  1799 
  1801 }
  1800 }
  1802 
  1801 
  1819             //so we can directly extract it
  1818             //so we can directly extract it
  1820             CMsvStore* store = SmsMtmL()->Entry().EditStoreL();
  1819             CMsvStore* store = SmsMtmL()->Entry().EditStoreL();
  1821             CleanupStack::PushL( store );
  1820             CleanupStack::PushL( store );
  1822             MMsvAttachmentManager& manager = store->AttachmentManagerL();
  1821             MMsvAttachmentManager& manager = store->AttachmentManagerL();
  1823             CMsvAttachment *attachment = manager.GetAttachmentInfoL(0);
  1822             CMsvAttachment *attachment = manager.GetAttachmentInfoL(0);
  1824             QString filepath = S60QConversions::s60DescToQString(attachment->FilePath());
  1823             QString filepath = XQConversions::s60DescToQString(attachment->FilePath());
  1825             ConvergedMessageAttachment* conv_attachment = 
  1824             ConvergedMessageAttachment* conv_attachment = 
  1826                 new ConvergedMessageAttachment(filepath, ConvergedMessageAttachment::EAttachment);
  1825                 new ConvergedMessageAttachment(filepath, ConvergedMessageAttachment::EAttachment);
  1827             ConvergedMessageAttachmentList conv_attList;
  1826             ConvergedMessageAttachmentList conv_attList;
  1828             conv_attList << conv_attachment;
  1827             conv_attList << conv_attachment;
  1829             aMessage->addAttachments(conv_attList);
  1828             aMessage->addAttachments(conv_attList);
  1860         if ( totalLength > 0 )
  1859         if ( totalLength > 0 )
  1861         {
  1860         {
  1862             HBufC* bodyText = HBufC::NewLC ( totalLength ); 
  1861             HBufC* bodyText = HBufC::NewLC ( totalLength ); 
  1863             TPtr bodyTextPtr ( bodyText->Des() ); 
  1862             TPtr bodyTextPtr ( bodyText->Des() ); 
  1864             SmsMtmL()->Body().Extract( bodyTextPtr, 0, totalLength );
  1863             SmsMtmL()->Body().Extract( bodyTextPtr, 0, totalLength );
  1865             aMessage->setBodyText(S60QConversions::s60DescToQString(
  1864             aMessage->setBodyText(XQConversions::s60DescToQString(
  1866                 bodyTextPtr));
  1865                 bodyTextPtr));
  1867             CleanupStack::PopAndDestroy( bodyText );            
  1866             CleanupStack::PopAndDestroy( bodyText );            
  1868         }
  1867         }
  1869     }
  1868     }
  1870 }
  1869 }