Commit 3cd08b15 authored by Volker Krause's avatar Volker Krause
Browse files

fix crash when another instance deletes a transport that's currently in use

svn path=/trunk/KDE/kdepim/mailtransport/; revision=620507
parent 123491f9
......@@ -15,8 +15,6 @@ Migration
TransportManager
----------------
- deletetion of Transport objects during reload is a problem
(create a copy for edit?)
- load passwords if another instance opens the wallet
Transport
......@@ -25,6 +23,7 @@ Transport
TransportJob
------------
- execute precommand
- use QByteArray for addresses instead of QString
SMTPJob
......
......@@ -105,6 +105,7 @@ int main( int argc, char** argv )
TransportMgr* t = new TransportMgr();
t->show();
app.exec();
delete t;
}
void TransportMgr::jobResult( KJob* job )
......
......@@ -203,3 +203,9 @@ void Transport::setAdHoc(bool b)
{
mIsAdHoc = b;
}
Transport* Transport::clone() const
{
QString id = currentGroup().mid( 10 );
return new Transport( id );
}
......@@ -73,6 +73,14 @@ class MAILTRANSPORT_EXPORT Transport : public TransportBase
*/
bool isAdHoc() const;
/**
Returns a deep copy of this Transport object which will no longer be
automatically updated. Use this if you need to store a Transport object
over a longer time. However it is recommended to store transport identifiers
instead if possible.
*/
Transport* clone() const;
protected:
/**
Creates a Transport object. Should only be used by TransportManager.
......
......@@ -38,7 +38,9 @@ class MAILTRANSPORT_EXPORT TransportConfigDialog : public KDialog
/**
Creates a new mail transport configuration dialog for the given
Transport object.
@param transport The Transport object to configure.
@param transport The Transport object to configure. This must be a deep copy of
a Transport object or a newly created one, which hasn't been added to the
TransportManager yet.
@param parent The parent widget.
*/
explicit TransportConfigDialog( Transport* transport, QWidget* parent = 0 );
......
......@@ -48,8 +48,7 @@ TransportJob::TransportJob( Transport* transport, QObject * parent ) :
TransportJob::~ TransportJob()
{
if ( d->transport->isAdHoc() )
delete d->transport;
delete d->transport;
delete d;
}
......
......@@ -39,13 +39,6 @@ class MAILTRANSPORT_EXPORT TransportJob : public KCompositeJob
friend class TransportManager;
public:
/**
Creates a new mail transport job.
@param transport The transport configuration.
@param parent The parent object.
*/
TransportJob( Transport* transport, QObject* parent = 0 );
/**
Deletes this transport job.
*/
......@@ -85,6 +78,15 @@ class MAILTRANSPORT_EXPORT TransportJob : public KCompositeJob
virtual void start();
protected:
/**
Creates a new mail transport job.
@param transport The transport configuration. This must be a deep copy of
a Transport object, the job takes the ownership of this object.
@param parent The parent object.
@see TransportManager::createTransportJob()
*/
TransportJob( Transport* transport, QObject* parent = 0 );
/**
Returns the Transport object containing the mail transport settings.
*/
......
......@@ -133,9 +133,14 @@ void TransportManagementWidget::editClicked()
Q_ASSERT( d->ui.transportList->currentItem() );
int currentId = d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
TransportConfigDialog t( TransportManager::self()->transportById( currentId ), this );
Transport* transport = TransportManager::self()->transportById( currentId );
if ( !transport )
return;
transport = transport->clone();
TransportConfigDialog t( transport, this );
t.setCaption( i18n("Modify Transport") );
t.exec();
delete transport;
}
void TransportManagementWidget::removeClicked()
......
......@@ -144,9 +144,9 @@ TransportJob* TransportManager::createTransportJob( int transportId )
return 0;
switch ( t->type() ) {
case Transport::EnumType::SMTP:
return new SmtpJob( t, this );
return new SmtpJob( t->clone(), this );
case Transport::EnumType::Sendmail:
return new SendmailJob( t, this );
return new SendmailJob( t->clone(), this );
}
Q_ASSERT( false );
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment