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
wilder-work
Ingo Klcker 23 years ago
parent 78093d8041
commit effc8dda5e
  1. 50
      kmcomposewin.cpp
  2. 11
      kmidentity.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 );
}

@ -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;
}

Loading…
Cancel
Save