From a82036f17a7a830997e58595c8093741e29c6f59 Mon Sep 17 00:00:00 2001 From: Ingo Klcker Date: Tue, 17 Oct 2006 19:17:09 +0000 Subject: [PATCH] Fix bug 132560 (When changing identity, the transport is then reset to the wrong one) I've got this patch on my harddisk for a long time. The patch should also fix a few other transport related bugs. BUG:132560 svn path=/branches/KDE/3.5/kdepim/; revision=596514 --- kmcomposewin.cpp | 68 ++++++++++++++++++++++++++---------------------- kmcomposewin.h | 8 ++++++ 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index b7ecfeafa..80e4cd0a1 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -620,16 +620,9 @@ void KMComposeWin::readConfig(void) while ( transportHistory.count() > (uint)GlobalSettings::self()->maxTransportEntries() ) transportHistory.remove( transportHistory.last() ); mTransport->insertStringList( transportHistory ); - if (mBtnTransport->isChecked() && !currentTransport.isEmpty()) - { - for (int i = 0; i < mTransport->count(); i++) - if (mTransport->text(i) == currentTransport) - mTransport->setCurrentItem(i); - mTransport->setEditText( currentTransport ); - } - - if ( !mBtnTransport->isChecked() ) { - mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() ); + mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() ); + if ( mBtnTransport->isChecked() ) { + setTransport( currentTransport ); } QString fccName = ""; @@ -1658,6 +1651,37 @@ void KMComposeWin::decryptOrStripOffCleartextSignature( QCString& body ) } } +//----------------------------------------------------------------------------- +void KMComposeWin::setTransport( const QString & transport ) +{ + kdDebug(5006) << "KMComposeWin::setTransport( \"" << transport << "\" )" << endl; + // Don't change the transport combobox if transport is empty + if ( transport.isEmpty() ) + return; + + bool transportFound = false; + for ( int i = 0; i < mTransport->count(); ++i ) { + if ( mTransport->text(i) == transport ) { + transportFound = true; + mTransport->setCurrentItem(i); + kdDebug(5006) << "transport found, it's no. " << i << " in the list" << endl; + break; + } + } + if ( !transportFound ) { // unknown transport + kdDebug(5006) << "unknown transport \"" << transport << "\"" << endl; + if ( transport.startsWith("smtp://") || transport.startsWith("smtps://") || + transport.startsWith("file://") ) { + // set custom transport + mTransport->setEditText( transport ); + } + else { + // neither known nor custom transport -> use default transport + mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() ); + } + } +} + //----------------------------------------------------------------------------- void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign, bool allowDecryption, bool isModified) @@ -1778,12 +1802,7 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign, QString transport = newMsg->headerField("X-KMail-Transport"); if (!mBtnTransport->isChecked() && !transport.isEmpty()) - { - for (int i = 0; i < mTransport->count(); i++) - if (mTransport->text(i) == transport) - mTransport->setCurrentItem(i); - mTransport->setEditText( transport ); - } + setTransport( transport ); if (!mBtnFcc->isChecked()) { @@ -4293,24 +4312,11 @@ void KMComposeWin::slotIdentityChanged( uint uoid ) if ( transp.isEmpty() ) { mMsg->removeHeaderField("X-KMail-Transport"); - transp = mTransport->text(0); + transp = GlobalSettings::self()->defaultTransport(); } else mMsg->setHeaderField("X-KMail-Transport", transp); - bool found = false; - int i; - for (i = 0; i < mTransport->count(); i++) { - if (mTransport->text(i) == transp) { - found = true; - mTransport->setCurrentItem(i); - break; - } - } - if (found == false) { - if (i == mTransport->maxCount()) mTransport->setMaxCount(i + 1); - mTransport->insertItem(transp,i); - mTransport->setCurrentItem(i); - } + setTransport( transp ); } mDictionaryCombo->setCurrentByDictionary( ident.dictionary() ); diff --git a/kmcomposewin.h b/kmcomposewin.h index f67f2d1e7..ec54dc285 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -649,6 +649,14 @@ private: */ static bool validateAddresses( QWidget * parent, const QString & addresses ); + /** + * Sets the transport combobox to @p transport. If @p transport is empty + * then the combobox remains unchanged. If @p transport is neither a known transport + * nor a custom transport then the combobox is set to the default transport. + * @param transport the transport the combobox should be set to + */ + void setTransport( const QString & transport ); + private slots: /** * Compress an attachemnt with the given index