does now compile with -DCHARSETS too

svn path=/trunk/kdenetwork/kmail/; revision=23374
wilder-work
Lars Knoll 27 years ago
parent 8e4198aaf6
commit 83fb58a9fb
  1. 14
      charsetsDlg.cpp
  2. 117
      kmcomposewin.cpp
  3. 9
      kmcomposewin.h

@ -8,7 +8,7 @@
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <kapp.h>
#include <kglobal.h>
#include <klocale.h>
#include <kconfig.h>
#include <kcharsets.h>
@ -33,7 +33,7 @@ int i;
QBoxLayout *mainl=new QVBoxLayout(this);
QBoxLayout *buttonsl=new QHBoxLayout();
QBoxLayout *optl=new QHBoxLayout();
KCharsets *charsets=kapp->getCharsets();
KCharsets *charsets=KGlobal::charsets();
QLabel *l=new QLabel(i18n("Message charset"),this,"l1");
@ -43,10 +43,9 @@ int i;
messageCharset=new QComboBox(this,"c1");
mainl->addWidget(messageCharset);
QStrList lst=charsets->registered();
QStringList lst=charsets->availableCharsetNames();
messageCharset->insertItem( "default" );
for(const char *chset=lst.first();chset;chset=lst.next())
messageCharset->insertItem( chset );
messageCharset->insertStringList( lst );
int n=messageCharset->count();
for(i=0;i<n;i++)
if (!stricmp(messageCharset->text(i),message)){
@ -61,10 +60,9 @@ int i;
composerCharset=new QComboBox(this,"c2");
mainl->addWidget(composerCharset);
QStrList lst1=charsets->displayable();
QStringList lst1=charsets->availableCharsetNames();
composerCharset->insertItem( "default" );
for(const char *chset=lst1.first();chset;chset=lst1.next())
composerCharset->insertItem( chset );
composerCharset->insertStringList( lst );
n=composerCharset->count();
for(i=0;i<n;i++)
if (!stricmp(composerCharset->text(i),composer)){

@ -224,7 +224,7 @@ void KMComposeWin::readConfig(void)
mQuoteUnknownCharacters = config->readNumEntry("quote-unknown",0);
str = config->readEntry("default-charset", "");
if (str.isNull() || str=="default" || !KCharset(str).ok())
if (str.isNull() || str=="default" || !KGlobal::charsets()->isAvailable(str))
mDefaultCharset="default";
else
mDefaultCharset=str;
@ -232,7 +232,7 @@ void KMComposeWin::readConfig(void)
debug("Default charset: %s", (const char*)mDefaultCharset);
str = config->readEntry("composer-charset", "");
if (str.isNull() || str=="default" || !KCharset(str).isDisplayable())
if (str.isNull() || str=="default" || !KGlobal::charsets()->isAvailable(str))
mDefComposeCharset="default";
else
mDefComposeCharset=str;
@ -746,16 +746,17 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign)
if (mCharset==""){
mComposeCharset=mDefComposeCharset;
if (mComposeCharset=="default"
&& KCharset(mDefaultCharset).isDisplayable())
&& KGlobal::charsets()->isAvailable(mDefaultCharset))
mComposeCharset=mDefaultCharset;
}
else if (KCharset(mCharset).isDisplayable()) mComposeCharset=mCharset;
else if (KGlobal::charsets()->isAvailable(mCharset))
mComposeCharset=mCharset;
else mComposeCharset=mDefComposeCharset;
cout<<"Compose charset: "<<mComposeCharset<<"\n";
mEditor->setText(convertToLocal(bodyPart.bodyDecoded()));
#else
mEditor->setText(QString(bodyPart.bodyDecoded()));
// FIXME: We might need a QTextCodec here
#endif
mEditor->setText(QString(bodyPart.bodyDecoded()));
mEditor->insertLine("\n", -1);
for(i=1; i<num; i++)
@ -772,13 +773,15 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign)
if (mCharset==""){
mComposeCharset=mDefComposeCharset;
if (mComposeCharset=="default"
&& KCharset(mDefaultCharset).isDisplayable())
&& KGlobal::charsets()->isAvailable(mDefaultCharset))
mComposeCharset=mDefaultCharset;
}
else if (KCharset(mCharset).isDisplayable()) mComposeCharset=mCharset;
else if (KGlobal::charsets()->isAvailable(mCharset))
mComposeCharset=mCharset;
else mComposeCharset=mDefComposeCharset;
cout<<"Compose charset: "<<mComposeCharset<<"\n";
mEditor->setText(convertToLocal(mMsg->bodyDecoded()));
// FIXME: QTextCodec needed?
mEditor->setText(QString(mMsg->bodyDecoded()));
}
#else
else mEditor->setText(QString(mMsg->bodyDecoded()));
@ -844,34 +847,28 @@ bool KMComposeWin::applyChanges(void)
mMsg->setTypeStr("text");
mMsg->setSubtypeStr("plain");
mMsg->setCteStr("quoted-printable");
#if defined CHARSETS
str=convertToSend(pgpProcessedMsg());
str = pgpProcessedMsg();
if (str.isNull()) return FALSE;
#if defined CHARSETS
convertToSend(str);
cout<<"Setting charset to: "<<mCharset<<"\n";
mMsg->setCharset(mCharset);
#endif
mMsg->setBodyEncoded(str);
#else
str = pgpProcessedMsg();
if (str.isNull()) return FALSE;
mMsg->setBodyEncoded(str);
#endif
}
else
{
mMsg->setTypeStr("text");
mMsg->setSubtypeStr("plain");
mMsg->setCteStr("8bit");
#if defined CHARSETS
str=convertToSend(pgpProcessedMsg());
str = pgpProcessedMsg();
if (str.isNull()) return FALSE;
#if defined CHARSETS
convertToSend(str);
cout<<"Setting charset to: "<<mCharset<<"\n";
mMsg->setCharset(mCharset);
#endif
mMsg->setBody(str);
#else
str = pgpProcessedMsg();
if (str.isNull()) return FALSE;
mMsg->setBody(str);
#endif
}
}
else
@ -892,7 +889,7 @@ bool KMComposeWin::applyChanges(void)
str = pgpProcessedMsg();
if (str.isNull()) return FALSE;
#if defined CHARSETS
str=convertToSend(str);
convertToSend(str);
cout<<"Setting charset to: "<<mCharset<<"\n";
mMsg->setCharset(mCharset);
#endif
@ -1710,8 +1707,6 @@ void KMComposeWin::slotSetCharsets(const char *message,const char *composer,
#if defined CHARSETS
mCharset=message;
m7BitAscii=ascii;
if (composer!=mComposeCharset && quote)
transcodeMessageTo(composer);
mComposeCharset=composer;
mQuoteUnknownCharacters=quote;
if (def)
@ -1742,85 +1737,33 @@ bool KMComposeWin::is8Bit(const QString str)
return FALSE;
}
//-----------------------------------------------------------------------------
QString KMComposeWin::convertToLocal(const QString str)
{
if (m7BitAscii && !is8Bit(str)) return str.copy();
KCharset destCharset;
KCharset srcCharset;
if (mCharset=="")
{
if (mDefaultCharset=="default") mCharset=klocale->charset();
else mCharset=mDefaultCharset;
}
srcCharset=mCharset;
if (mComposeCharset=="default") destCharset=klocale->charset();
else destCharset=mComposeCharset;
if (srcCharset==destCharset) return str.copy();
int flags=mQuoteUnknownCharacters?KCharsetConverter::OUTPUT_AMP_SEQUENCES:0;
KCharsetConverter conv(srcCharset,destCharset,flags);
KCharsetConversionResult result=conv.convert(str);
return result.copy();
}
//-----------------------------------------------------------------------------
QString KMComposeWin::convertToSend(const QString str)
void KMComposeWin::convertToSend(const QString str)
{
cout<<"Converting to send...\n";
if (m7BitAscii && !is8Bit(str))
{
mCharset="us-ascii";
return str.copy();
return;
}
if (mCharset=="")
{
if (mDefaultCharset=="default")
mCharset=klocale->charset();
mCharset=KGlobal::charsets()->charsetForLocale();
else mCharset=mDefaultCharset;
}
cout<<"mCharset: "<<mCharset<<"\n";
KCharset srcCharset;
KCharset destCharset(mCharset);
if (mComposeCharset=="default") srcCharset=klocale->charset();
else srcCharset=mComposeCharset;
cout<<"srcCharset: "<<srcCharset<<"\n";
if (srcCharset==destCharset) return str.copy();
int flags=mQuoteUnknownCharacters?KCharsetConverter::INPUT_AMP_SEQUENCES:0;
KCharsetConverter conv(srcCharset,destCharset,flags);
KCharsetConversionResult result=conv.convert(str);
return result.copy();
}
//-----------------------------------------------------------------------------
void KMComposeWin::transcodeMessageTo(const QString charset)
{
cout<<"Transcoding message...\n";
QString inputStr=mEditor->text();
KCharset srcCharset;
KCharset destCharset(charset);
if (mComposeCharset=="default") srcCharset=klocale->charset();
else srcCharset=mComposeCharset;
cout<<"srcCharset: "<<srcCharset<<"\n";
if (srcCharset==destCharset) return;
int flags=mQuoteUnknownCharacters?KCharsetConverter::AMP_SEQUENCES:0;
KCharsetConverter conv(srcCharset,destCharset,flags);
KCharsetConversionResult result=conv.convert(inputStr);
mComposeCharset=charset;
mEditor->setText(result.copy());
}
//-----------------------------------------------------------------------------
void KMComposeWin::setEditCharset()
{
QFont fnt=mSavedEditorFont;
KCharset kcharset;
if (mComposeCharset=="default") kcharset=klocale->charset();
else if (mComposeCharset!="") kcharset=mComposeCharset;
cout<<"Setting font to: "<<kcharset.name()<<"\n";
mEditor->setFont(kcharset.setQFont(fnt));
if (mComposeCharset=="default")
mComposeCharset=KGlobal::charsets()->charsetForLocale();
cout<<"Setting font to: "<<mComposeCharset<<"\n";
KGlobal::charsets()->setQFont(fnt, mComposeCharset);
mEditor->setFont(fnt);
}
#endif //CHARSETS

@ -287,15 +287,8 @@ private:
virtual const QString pgpProcessedMsg(void);
#if defined CHARSETS
/** Convert message text for editing.
Converts message to mComposeCharset charset (if neccessary).*/
QString convertToLocal(const QString str);
/** Converts message text for sending. */
QString convertToSend(const QString str);
/** Converts message text for sending. */
void transcodeMessageTo(const QString newCharset);
void convertToSend(const QString str);
/** Test if string has any 8-bit characters */
bool is8Bit(const QString str);

Loading…
Cancel
Save