From ab46f0b6d26d23acebbc608413b39343020a7b28 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 23 Jan 2009 21:05:33 +0000 Subject: [PATCH] Get rid of the ugly delete-inside-if statements by using boost::shared_ptr goodness. svn path=/trunk/KDE/kdepim/; revision=915815 --- messagecomposer.cpp | 70 ++++++++++++++++++++++----------------------- messagecomposer.h | 12 +++++--- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/messagecomposer.cpp b/messagecomposer.cpp index 05c1b6eac..b760b7a3a 100644 --- a/messagecomposer.cpp +++ b/messagecomposer.cpp @@ -88,6 +88,8 @@ #include #include +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 theInnerBodyPart = innerBodypart( theMessage, doSign, oldContentType ); + shared_ptr theImageBodyPart = imageBodyPart( theMessage, theInnerBodyPart ); + shared_ptr 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 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 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 MessageComposer::imageBodyPart( KMMessage &theMessage, + shared_ptr 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 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 MessageComposer::mixedBodyPart( KMMessage &theMessage, + shared_ptr 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 mixedDwPart( theMessage.createDWBodyPart( &mixedBodyPart ) ); DwHeaders &headers = mixedDwPart->Headers(); DwMediaType &ct = headers.ContentType(); ct.SetBoundary( tmpCT.Boundary() ); diff --git a/messagecomposer.h b/messagecomposer.h index 706ae30b3..612ebaae5 100644 --- a/messagecomposer.h +++ b/messagecomposer.h @@ -42,6 +42,7 @@ #include #include "kleo/cryptobackend.h" +#include #include 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 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 imageBodyPart( KMMessage &theMessage, + boost::shared_ptr 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 mixedBodyPart( KMMessage &theMessage, + boost::shared_ptr imageBodyPart, + bool doSignBody, bool doEncryptBody ); // The composer window. Mainly used in readFromComposeWin() to read the information from it. KMComposeWin *mComposeWin;