Get rid of the ugly delete-inside-if statements by using boost::shared_ptr goodness.

svn path=/trunk/KDE/kdepim/; revision=915815
wilder-work
Thomas McGuire 17 years ago
parent 5088282641
commit ab46f0b6d2
  1. 70
      messagecomposer.cpp
  2. 12
      messagecomposer.h

@ -88,6 +88,8 @@
#include <algorithm>
#include <memory>
using namespace boost;
#undef MessageBox // Windows: avoid clash between MessageBox define and Kleo::MessageBox
// ## keep default values in sync with configuredialog.cpp, Security::CryptoTab::setup()
@ -1518,36 +1520,32 @@ void MessageComposer::composeMessage( KMMessage &theMessage,
//
// Now, create the core body part by calling all helper functions.
//
DwBodyPart * theInnerBodyPart = innerBodypart( theMessage, doSign, oldContentType );
DwBodyPart * theImageBodyPart = imageBodyPart( theMessage, theInnerBodyPart );
DwBodyPart * theMixedBodyPart = mixedBodyPart( theMessage, theImageBodyPart,
doSignBody, doEncryptBody );
{
shared_ptr<DwBodyPart> theInnerBodyPart = innerBodypart( theMessage, doSign, oldContentType );
shared_ptr<DwBodyPart> theImageBodyPart = imageBodyPart( theMessage, theInnerBodyPart );
shared_ptr<DwBodyPart> theMixedBodyPart = mixedBodyPart( theMessage, theImageBodyPart,
doSignBody, doEncryptBody );
// Set the saved boundary, so that the header will have the same boundary information in the
// content-type header like in the body.
if ( mSaveBoundary.length() > 0 ) {
theMixedBodyPart->Headers().ContentType().SetBoundary( mSaveBoundary );
theMixedBodyPart->Assemble();
}
// Set the saved boundary, so that the header will have the same boundary information in the
// content-type header like in the body.
if ( mSaveBoundary.length() > 0 ) {
theMixedBodyPart->Headers().ContentType().SetBoundary( mSaveBoundary );
theMixedBodyPart->Assemble();
//
// Ok, we finished creating our main body part here, now actually set it as the body text
// of mOldBodyPart.
// Everything after here deals with signing/encrypting and late attachments.
//
mOldBodyPart.setTypeStr( theMixedBodyPart->Headers().ContentType().TypeStr().c_str() );
mOldBodyPart.setSubtypeStr( theMixedBodyPart->Headers().ContentType().SubtypeStr().c_str() );
mOldBodyPart.setOriginalContentTypeStr( theMixedBodyPart->Headers().ContentType().AsString().c_str() );
mOldBodyPart.setContentTransferEncodingStr( theMixedBodyPart->Headers().ContentTransferEncoding().AsString().c_str() );
mOldBodyPart.setContentDescription( theMixedBodyPart->Headers().ContentDescription().AsString().c_str() );
mOldBodyPart.setBody( theMixedBodyPart->Body().AsString().c_str() );
}
//
// Ok, we finished creating our main body part here, now actually set it as the body text
// of mOldBodyPart.
// Everything after here deals with signing/encrypting and late attachments.
//
mOldBodyPart.setTypeStr( theMixedBodyPart->Headers().ContentType().TypeStr().c_str() );
mOldBodyPart.setSubtypeStr( theMixedBodyPart->Headers().ContentType().SubtypeStr().c_str() );
mOldBodyPart.setOriginalContentTypeStr( theMixedBodyPart->Headers().ContentType().AsString().c_str() );
mOldBodyPart.setContentTransferEncodingStr( theMixedBodyPart->Headers().ContentTransferEncoding().AsString().c_str() );
mOldBodyPart.setContentDescription( theMixedBodyPart->Headers().ContentDescription().AsString().c_str() );
mOldBodyPart.setBody( theMixedBodyPart->Body().AsString().c_str() );
delete theInnerBodyPart;
if ( theInnerBodyPart != theImageBodyPart )
delete theImageBodyPart;
if ( theMixedBodyPart != theImageBodyPart && theMixedBodyPart != theInnerBodyPart )
delete theMixedBodyPart;
// This will be our *final* body part, which contains the main body part (mOldBodyPart) plus
// signing, encryption and late attachments.
mNewBodyPart = new KMMessagePart;
@ -1705,8 +1703,8 @@ QByteArray MessageComposer::innerBodypartBody( KMMessage &theMessage, bool doSig
return body;
}
DwBodyPart* MessageComposer::innerBodypart( KMMessage &theMessage, bool doSign,
QString oldContentType )
boost::shared_ptr<DwBodyPart> MessageComposer::innerBodypart( KMMessage &theMessage, bool doSign,
QString oldContentType )
{
KMMessagePart innerBodyPart;
if ( mIsRichText ) {
@ -1727,7 +1725,7 @@ DwBodyPart* MessageComposer::innerBodypart( KMMessage &theMessage, bool doSign,
}
// Now, create a DwBodyPart of the KMMessagePart and return its string representation.
DwBodyPart* innerDwPart = theMessage.createDWBodyPart( &innerBodyPart );
shared_ptr<DwBodyPart> innerDwPart( theMessage.createDWBodyPart( &innerBodyPart ) );
DwHeaders &headers = innerDwPart->Headers();
DwMediaType &ct = headers.ContentType();
@ -1746,7 +1744,8 @@ DwBodyPart* MessageComposer::innerBodypart( KMMessage &theMessage, bool doSign,
return innerDwPart;
}
DwBodyPart* MessageComposer::imageBodyPart( KMMessage &theMessage, DwBodyPart *innerBodyPart )
shared_ptr<DwBodyPart> MessageComposer::imageBodyPart( KMMessage &theMessage,
shared_ptr<DwBodyPart> innerBodyPart )
{
if ( mEmbeddedImages.size() == 0 )
return innerBodyPart;
@ -1801,7 +1800,7 @@ DwBodyPart* MessageComposer::imageBodyPart( KMMessage &theMessage, DwBodyPart *i
imageBodyPart.setBodyEncoded( imageBodyPartBody );
// Now, create a DwBodyPart of the KMMessagePart and return its string representation.
DwBodyPart* imageDwPart = theMessage.createDWBodyPart( &imageBodyPart );
shared_ptr<DwBodyPart> imageDwPart( theMessage.createDWBodyPart( &imageBodyPart ) );
DwHeaders &headers = imageDwPart->Headers();
DwMediaType &ct = headers.ContentType();
ct.SetBoundary( tmpCT.Boundary() );
@ -1811,8 +1810,9 @@ DwBodyPart* MessageComposer::imageBodyPart( KMMessage &theMessage, DwBodyPart *i
return imageDwPart;
}
DwBodyPart* MessageComposer::mixedBodyPart( KMMessage &theMessage, DwBodyPart *imageBodyPart,
bool doSignBody, bool doEncryptBody )
shared_ptr<DwBodyPart> MessageComposer::mixedBodyPart( KMMessage &theMessage,
shared_ptr<DwBodyPart> imageBodyPart,
bool doSignBody, bool doEncryptBody )
{
if ( !mEarlyAddAttachments )
return imageBodyPart;
@ -1856,7 +1856,7 @@ DwBodyPart* MessageComposer::mixedBodyPart( KMMessage &theMessage, DwBodyPart *i
mixedBodyPart.setBodyEncoded( mixedBodyPartBody );
// Now, create a DwBodyPart of the KMMessagePart and return its string representation.
DwBodyPart* mixedDwPart = theMessage.createDWBodyPart( &mixedBodyPart );
shared_ptr<DwBodyPart> mixedDwPart( theMessage.createDWBodyPart( &mixedBodyPart ) );
DwHeaders &headers = mixedDwPart->Headers();
DwMediaType &ct = headers.ContentType();
ct.SetBoundary( tmpCT.Boundary() );

@ -42,6 +42,7 @@
#include <mimelib/mediatyp.h>
#include "kleo/cryptobackend.h"
#include <boost/shared_ptr.hpp>
#include <vector>
class KMMessage;
@ -283,7 +284,8 @@ class MessageComposer : public QObject {
* be of this content type, and not text/plain
* @return the complete inner body part
*/
DwBodyPart* innerBodypart( KMMessage &theMessage, bool doSign, QString oldContentType = QString() );
boost::shared_ptr<DwBodyPart> innerBodypart( KMMessage &theMessage,
bool doSign, QString oldContentType = QString() );
/**
* Helper function for innerBodypart(). This creates and returns the body of the inner body
@ -306,7 +308,8 @@ class MessageComposer : public QObject {
* @param innerBodyPart the inner body part created so far
* @return the complete image body part
*/
DwBodyPart* imageBodyPart( KMMessage &theMessage, DwBodyPart *innerBodyPart );
boost::shared_ptr<DwBodyPart> imageBodyPart( KMMessage &theMessage,
boost::shared_ptr<DwBodyPart> innerBodyPart );
/**
* Returns the mixed body part
@ -320,8 +323,9 @@ class MessageComposer : public QObject {
* @param imageBodyPart the image body part created so far
* @return the complete mixed body part
*/
DwBodyPart* mixedBodyPart( KMMessage &theMessage, DwBodyPart *iamgeBodyPart,
bool doSignBody, bool doEncryptBody );
boost::shared_ptr<DwBodyPart> mixedBodyPart( KMMessage &theMessage,
boost::shared_ptr<DwBodyPart> imageBodyPart,
bool doSignBody, bool doEncryptBody );
// The composer window. Mainly used in readFromComposeWin() to read the information from it.
KMComposeWin *mComposeWin;

Loading…
Cancel
Save