From effc8dda5ead30a78ea657ba149c8b1fa7c35d5b Mon Sep 17 00:00:00 2001 From: Ingo Klcker Date: Sun, 6 Apr 2003 13:25:02 +0000 Subject: [PATCH] Don't add an empty line before a signature which already contains the signature separator. This makes abusing signatures as templates more useful because one doesn't have to manually remove the empty line before the start of the template. svn path=/trunk/kdepim/; revision=218648 --- kmcomposewin.cpp | 50 ++++++------------------------------------------ kmidentity.cpp | 11 +++++++---- 2 files changed, 13 insertions(+), 48 deletions(-) diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index d5c7950a6..f6d19cb1b 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -4780,49 +4780,11 @@ void KMComposeWin::slotAppendSignature() const KMIdentity & ident = kernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() ); - QString sigText = ident.signatureText(); -#if 0 // will be moved to identitymanager - if( sigText.isNull() && ident.useSignatureFile() ) - { - // open a file dialog and let the user choose manually - KFileDialog dlg( QDir::homeDirPath(), QString::null, this, 0, TRUE ); - if (ident.signatureIsPlainFile()) - dlg.setCaption(i18n("Choose Signature File")); - else - dlg.setCaption(i18n("Choose Signature Command")); - if( !dlg.exec() ) - { - return; - } - KURL url = dlg.selectedURL(); - if( url.isEmpty() ) - { - return; - } - if( !url.isLocalFile() ) - { - KMessageBox::sorry( 0, i18n( "Only local files are supported." ) ); - return; - } - QString sigFileName = url.path(); - QFileInfo qfi( sigFileName ); - if ( ident.signatureIsCommand() && !qfi.isExecutable() ) - { - // ### Commented out due to msg freeze (remove comment and underscores): - //KMessageBox::sorry( 0, _i_1_8_n_( "%1 is not executable." ).arg( url.path() ) ); - return; - } - ident.setSignatureFile(sigFileName); - ident.writeConfig(true); - sigText = ident.signature(false); // try again, but don't prompt - } -#endif - mOldSigText = sigText; - if( !sigText.isEmpty() ) + mOldSigText = ident.signatureText(); + if( !mOldSigText.isEmpty() ) { mEditor->sync(); - mEditor->append("\n"); - mEditor->append(sigText); + mEditor->append(mOldSigText); mEditor->update(); mEditor->setModified(mod); mEditor->setContentsPos( 0, 0 ); @@ -4967,8 +4929,8 @@ void KMComposeWin::slotIdentityChanged(uint uoid) // try to truncate the old sig if( !mOldSigText.isEmpty() ) { - if( edtText.endsWith( "\n" + mOldSigText ) ) - edtText.truncate( edtText.length() - mOldSigText.length() - 1 ); + if( edtText.endsWith( mOldSigText ) ) + edtText.truncate( edtText.length() - mOldSigText.length() ); else appendNewSig = false; } @@ -4977,7 +4939,7 @@ void KMComposeWin::slotIdentityChanged(uint uoid) if( appendNewSig ) { if( !mOldSigText.isEmpty() && mAutoSign ) - edtText.append( "\n" + mOldSigText ); + edtText.append( mOldSigText ); mEditor->setText( edtText ); } diff --git a/kmidentity.cpp b/kmidentity.cpp index 339a66824..321c9840d 100644 --- a/kmidentity.cpp +++ b/kmidentity.cpp @@ -145,13 +145,16 @@ QString Signature::withSeparator( bool * ok ) const } if ( ok ) *ok = true; if ( signature.isEmpty() ) return signature; // don't add a separator in this case - if ( signature.startsWith( QString::fromLatin1("-- \n") ) || - signature.find( QString::fromLatin1("\n-- \n") ) != -1 ) - // already have signature separator: + if ( signature.startsWith( QString::fromLatin1("-- \n") ) ) + // already have signature separator at start of sig: + return QString::fromLatin1("\n") += signature; + else if ( signature.find( QString::fromLatin1("\n-- \n") ) != -1 ) + // already have signature separator inside sig; don't prepend '\n' + // to improve abusing signatures as templates: return signature; else // need to prepend one: - return QString::fromLatin1("-- \n") + signature; + return QString::fromLatin1("\n-- \n") + signature; }