From c2fd9712a1dea99f166efcc73ddfe352fcdaa365 Mon Sep 17 00:00:00 2001 From: Waldo Bastian Date: Fri, 5 Oct 2001 23:15:13 +0000 Subject: [PATCH] Warn if us-ascii or local8Bit encoding can't encode all characters. (This was already done for encodings handled by a particular codec) svn path=/trunk/kdenetwork/kmail/; revision=116653 --- kmcomposewin.cpp | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index e5fe03250..17ae61367 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -1307,30 +1307,39 @@ QCString KMComposeWin::pgpProcessedMsg(void) text = mEditor->brokenText(); text.truncate(text.length()); // to ensure text.size()==text.length()+1 - QTextCodec *codec = KMMsgBase::codecForName(mCharset); - - if (mCharset == "us-ascii") - cText = KMMsgBase::toUsAscii(text); - else if (codec == NULL) { - kdDebug(5006) << "Something is wrong and I can not get a codec." << endl; - cText = text.local8Bit(); - } else - cText = codec->fromUnicode(text); - if (!text.isEmpty() && codec && codec->toUnicode(cText) != text) { - QString oldText = mEditor->text(); - mEditor->setText(codec->toUnicode(cText)); - kernel->kbp()->idle(); - bool anyway = (KMessageBox::warningYesNo(0L, - i18n("Not all characters fit into the chosen" - " encoding.\nSend the message anyway?"), - i18n("Some characters will be lost"), - i18n("Yes"), i18n("No, let me change the encoding") ) == KMessageBox::Yes); - if (!anyway) + // Provide a local scope for newText. + QString newText; + QTextCodec *codec = KMMsgBase::codecForName(mCharset); + + if (mCharset == "us-ascii") { + cText = KMMsgBase::toUsAscii(text); + newText = QString::fromLatin1(cText); + } else if (codec == NULL) { + kdDebug(5006) << "Something is wrong and I can not get a codec." << endl; + cText = text.local8Bit(); + newText = QString::fromLocal8Bit(cText); + } else { + cText = codec->fromUnicode(text); + newText = codec->toUnicode(cText); + } + + if (!text.isEmpty() && (newText != text)) { - mEditor->setText(oldText); - return QCString(); + QString oldText = mEditor->text(); + mEditor->setText(newText); + kernel->kbp()->idle(); + bool anyway = (KMessageBox::warningYesNo(0L, + i18n("Not all characters fit into the chosen" + " encoding.\nSend the message anyway?"), + i18n("Some characters will be lost"), + i18n("Yes"), i18n("No, let me change the encoding") ) == KMessageBox::Yes); + if (!anyway) + { + mEditor->setText(oldText); + return QCString(); + } } }