The list of available charsets in the composer is now configurable.

svn path=/trunk/kdenetwork/kmail/; revision=71916
wilder-work
Michael Haeckel 26 years ago
parent 0698301e1d
commit 34d98ed174
  1. 163
      configuredialog.cpp
  2. 10
      configuredialog.h
  3. 29
      kmcomposewin.cpp
  4. 8
      kmkernel.cpp

@ -977,7 +977,7 @@ void ConfigureDialog::makeComposerPage( void )
mComposer.LanguageList = NULL;
QHBoxLayout *languageHlay = new QHBoxLayout( group, 0, spacingHint() );
glay->addLayout( languageHlay, 3, 1 );
QPushButton *newButton = new QPushButton( i18n("New..."), group );
QPushButton *newButton = new QPushButton( i18n("Add..."), group );
mComposer.removeButton = new QPushButton( i18n("Remove"), group );
newButton->setAutoDefault( false );
mComposer.removeButton->setAutoDefault( false );
@ -1113,24 +1113,53 @@ void ConfigureDialog::makeComposerPage( void )
QWidget *charsetPage = new QWidget( tabWidget );
tabWidget->addTab( charsetPage, i18n("Charset") );
QVBoxLayout *topLevel3 = new QVBoxLayout( charsetPage, spacingHint() );
//list of charsets
QHBoxLayout *charsetHLay = new QHBoxLayout( topLevel3 );
label = new QLabel( i18n("Default charset:"), charsetPage );
charsetHLay->addWidget( label );
mComposer.defaultCharsetCombo = new QComboBox( charsetPage );
QStringList charsetList = KGlobal::charsets()->availableCharsetNames();
charsetList.remove(QString("*-*")); //this doesn't make sense
charsetList.prepend( "us-ascii" );
charsetList.prepend( i18n("Use language encoding") );
mComposer.defaultCharsetCombo->insertStringList(charsetList);
charsetHLay->addWidget( mComposer.defaultCharsetCombo );
charsetHLay->addStretch(10);
topLevel3->addSpacing( spacingHint() );
QGroupBox *charsetsGroup = new QGroupBox( i18n("Available charsets"),
charsetPage );
QGridLayout *charsetsGridLay = new QGridLayout( charsetsGroup, 6, 2,
spacingHint() );
charsetsGridLay->addRowSpacing( 0, fontMetrics().lineSpacing() );
charsetsGridLay->setRowStretch( 1, 10 );
mComposer.charsetListBox = new QListBox( charsetsGroup );
charsetsGridLay->addMultiCellWidget( mComposer.charsetListBox, 1, 5, 0, 0 );
mComposer.addCharsetButton = new QPushButton( i18n("Add..."), charsetsGroup );
charsetsGridLay->addWidget( mComposer.addCharsetButton, 2, 1 );
mComposer.removeCharsetButton = new QPushButton( i18n("Remove"),
charsetsGroup );
charsetsGridLay->addWidget( mComposer.removeCharsetButton, 3, 1 );
mComposer.charsetUpButton = new QPushButton( i18n("Up"), charsetsGroup );
mComposer.charsetUpButton->setAutoRepeat( TRUE );
charsetsGridLay->addWidget( mComposer.charsetUpButton, 4, 1 );
mComposer.charsetDownButton = new QPushButton( i18n("Down"), charsetsGroup );
mComposer.charsetDownButton->setAutoRepeat( TRUE );
charsetsGridLay->addWidget( mComposer.charsetDownButton, 5, 1 );
topLevel3->addWidget( charsetsGroup );
connect( mComposer.addCharsetButton, SIGNAL(clicked()),
this, SLOT(slotAddCharset()) );
connect( mComposer.removeCharsetButton, SIGNAL(clicked()),
this, SLOT(slotRemoveSelCharset()) );
connect( mComposer.charsetUpButton, SIGNAL(clicked()),
this, SLOT(slotCharsetUp()) );
connect( mComposer.charsetDownButton, SIGNAL(clicked()),
this, SLOT(slotCharsetDown()) );
connect( mComposer.charsetListBox, SIGNAL(selectionChanged()),
this, SLOT(slotCharsetSelectionChanged()) );
//default charset
QGroupBox *defaultCharsetGroup = new QGroupBox( i18n("Default charset"),
charsetPage );
QVBoxLayout *charsetVLay = new QVBoxLayout( defaultCharsetGroup,
spacingHint() );
charsetVLay->addSpacing( fontMetrics().lineSpacing() );
mComposer.defaultCharsetCombo = new QComboBox( defaultCharsetGroup );
charsetVLay->addWidget( mComposer.defaultCharsetCombo );
mComposer.forceReplyCharsetCheck =
new QCheckBox( i18n("Use own default charset when replying"), charsetPage );
topLevel3->addWidget( mComposer.forceReplyCharsetCheck );
topLevel3->addStretch(10);
new QCheckBox( i18n("Use own default charset when replying"),
defaultCharsetGroup );
charsetVLay->addWidget( mComposer.forceReplyCharsetCheck );
topLevel3->addWidget( defaultCharsetGroup );
topLevel3->addSpacing( spacingHint() );
}
@ -1354,7 +1383,7 @@ void ConfigureDialog::setupNetworkPage( void )
mNetwork.smtpServerEdit->setText( kernel->msgSender()->smtpHost() );
mNetwork.smtpPortEdit->setText(
QString().setNum(kernel->msgSender()->smtpPort()) );
mNetwork.precommandEdit->setText( kernel->msgSender()->precommand() );
mNetwork.precommandEdit->setText( kernel->msgSender()->precommand() );
KConfig &config = *kapp->config();
config.setGroup("Composer");
@ -1552,21 +1581,22 @@ void ConfigureDialog::setupComposerPage( void )
slotWordWrapSelectionChanged();
//charsets
QStringList charsets = config.readListEntry("charsets");
mComposer.charsetListBox->clear();
mComposer.charsetListBox->insertStringList( charsets );
mComposer.charsetListBox->setCurrentItem( 0 );
charsets.prepend( i18n("Use language encoding") );
mComposer.defaultCharsetCombo->clear();
mComposer.defaultCharsetCombo->insertStringList(charsets);
QString str = config.readEntry( "charset", "" );
if (str.isNull() || str.isEmpty() || str == "default")
mComposer.defaultCharsetCombo->setCurrentItem( 0 );
else
{
bool found = false;
if (str == "us-ascii")
{
mComposer.defaultCharsetCombo->setCurrentItem( 1 );
found = true;
}
//we start from 2, because 0 stands for "Use language def", 1 stands for "us-ascii"
for (int j = 2; !found && (j < mComposer.defaultCharsetCombo->count()); j++ )
if (mComposer.defaultCharsetCombo->text( j ) == KGlobal::charsets()->xCharsetName(
KGlobal::charsets()->nameToID(str)))
for (int j = 1; !found && (j < mComposer.defaultCharsetCombo->count()); j++ )
if (mComposer.defaultCharsetCombo->text( j ) == str)
{
mComposer.defaultCharsetCombo->setCurrentItem( j );
found = true;
@ -1964,6 +1994,12 @@ void ConfigureDialog::slotDoApply( bool everything )
config.writeEntry("replace-forward-prefix",
mComposer.replaceForwardPrefixCheck->isChecked() );
QStringList charsetList;
int charsetCount = mComposer.charsetListBox->count();
for (j = 0; j < charsetCount; j++)
charsetList.append( mComposer.charsetListBox->item( j )->text() );
config.writeEntry("charsets", charsetList);
bool autoSignature = mComposer.autoAppSignFileCheck->isChecked();
config.writeEntry("signature", autoSignature ? "auto" : "manual" );
config.writeEntry("smart-quote", mComposer.smartQuoteCheck->isChecked() );
@ -1974,9 +2010,9 @@ void ConfigureDialog::slotDoApply( bool everything )
// charset settings
if ( mComposer.defaultCharsetCombo->currentItem() == 0 )
config.writeEntry("charset", "default");
else //charset should be e.g. iso-8889-1, on the list we have iso8859-1
config.writeEntry("charset", KGlobal::charsets()->name(
KGlobal::charsets()->nameToID( mComposer.defaultCharsetCombo->currentText())));
else
config.writeEntry("charset", mComposer.defaultCharsetCombo->
currentText());
config.writeEntry("force-reply-charset",
mComposer.forceReplyCharsetCheck->isChecked() );
}
@ -2825,6 +2861,73 @@ void ConfigureDialog::slotForwardPrefixSelected( void )
mComposer.removeForwardPrefixButton->setEnabled( true );
}
void ConfigureDialog::slotAddCharset( void )
{
KLineEditDlg * linedlg = new KLineEditDlg(i18n("Enter charset to add"), "",
this);
if ( linedlg->exec() == QDialog::Accepted )
{
if (linedlg->text().lower() == "us-ascii" ||
QTextCodec::codecForName( linedlg->text() ))
{
mComposer.charsetListBox->insertItem( linedlg->text(),
mComposer.charsetListBox->currentItem() + 1 );
mComposer.charsetListBox->setSelected( mComposer.charsetListBox->
currentItem() + 1, TRUE );
mComposer.defaultCharsetCombo->insertItem( linedlg->text() );
} else {
KMessageBox::sorry( this, i18n("This charset is not supported.") );
}
}
}
void ConfigureDialog::slotRemoveSelCharset( void )
{
int crItem = mComposer.charsetListBox->currentItem();
if( crItem != -1 )
{
for (int i = 0; i < mComposer.defaultCharsetCombo->count(); i++)
{
if (mComposer.defaultCharsetCombo->text( i ) ==
mComposer.charsetListBox->currentText())
{
mComposer.defaultCharsetCombo->removeItem( i );
break;
}
}
mComposer.charsetListBox->removeItem( crItem );
if (crItem - mComposer.charsetListBox->count() <= 0) crItem--;
mComposer.charsetListBox->setSelected( crItem, TRUE );
}
}
void ConfigureDialog::slotCharsetUp( void )
{
int crItem = mComposer.charsetListBox->currentItem();
QString text = mComposer.charsetListBox->text( crItem );
mComposer.charsetListBox->removeItem( crItem );
mComposer.charsetListBox->insertItem( text, crItem - 1 );
mComposer.charsetListBox->setSelected( crItem - 1, TRUE );
}
void ConfigureDialog::slotCharsetDown( void )
{
int crItem = mComposer.charsetListBox->currentItem();
QString text = mComposer.charsetListBox->text( crItem );
mComposer.charsetListBox->removeItem( crItem );
mComposer.charsetListBox->insertItem( text, crItem + 1 );
mComposer.charsetListBox->setSelected( crItem + 1, TRUE );
}
void ConfigureDialog::slotCharsetSelectionChanged( void )
{
mComposer.charsetUpButton->setEnabled( mComposer.charsetListBox->
currentItem() > 0 );
mComposer.charsetDownButton->setEnabled( mComposer.charsetListBox->
count() - mComposer.charsetListBox->currentItem() > 1 );
mComposer.removeCharsetButton->setEnabled( mComposer.charsetListBox->
count() != 0 );
}
void ConfigureDialog::slotMimeHeaderSelectionChanged( void )
{

@ -328,6 +328,11 @@ class ConfigureDialog : public KDialogBase
QPushButton *addForwardPrefixButton;
QPushButton *removeForwardPrefixButton;
QCheckBox *replaceForwardPrefixCheck;
QListBox *charsetListBox;
QPushButton *addCharsetButton;
QPushButton *removeCharsetButton;
QPushButton *charsetUpButton;
QPushButton *charsetDownButton;
QComboBox *defaultCharsetCombo;
QCheckBox* forceReplyCharsetCheck;
};
@ -453,6 +458,11 @@ class ConfigureDialog : public KDialogBase
void slotAddForwardPrefix( void );
void slotRemoveSelForwardPrefix( void );
void slotForwardPrefixSelected( void );
void slotAddCharset( void );
void slotRemoveSelCharset( void );
void slotCharsetUp( void );
void slotCharsetDown( void );
void slotCharsetSelectionChanged( void );
void slotMimeHeaderSelectionChanged( void );
void slotMimeHeaderNameChanged( const QString &text );
void slotMimeHeaderValueChanged( const QString &text );

@ -720,25 +720,11 @@ void KMComposeWin::setupActions(void)
wordWrapAction->setChecked(mWordWrap);
connect(wordWrapAction, SIGNAL(toggled(bool)), SLOT(slotWordWrapToggled(bool)));
// availableCharsetNames seems more reasonable than availableEncodingNames
QStringList encodings = KGlobal::charsets()->availableCharsetNames();
encodings.remove(QString("*-*")); //this doesn't make sense
encodings.prepend( "utf-8" );
encodings.prepend( "us-ascii" );
KConfig *config = kapp->config();
config->setGroup("Composer");
QStringList encodings = config->readListEntry("charsets");
encodingAction->setItems( encodings );
//default is given by mDefCharset
int i = 0;
bool found = false;
QFont::CharSet defCharset = KGlobal::charsets()->nameToID(mDefCharset);
for ( QStringList::Iterator it = encodings.begin(); it != encodings.end(); ++it, i++ )
if ((*it) == KGlobal::charsets()->xCharsetName(defCharset))
{
encodingAction->setCurrentItem(i);
found = true;
break;
}
if (!found)
encodingAction->setCurrentItem(0);
encodingAction->setCurrentItem( -1 );
//these are checkable!!!
allFieldsAction = new KToggleAction (i18n("&All Fields"), 0, this,
@ -999,6 +985,7 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign)
if (KGlobal::charsets()->nameToID(*it) == KGlobal::charsets()->nameToID(mCharset))
{
encodingAction->setCurrentItem( i );
slotSetCharset();
break;
}
@ -1510,14 +1497,8 @@ void KMComposeWin::slotInsertFile()
void KMComposeWin::slotSetCharset()
{
mCharset = encodingAction->currentText();
if (encodingAction->currentItem() != 0) //i.e. <none>
{
QFont::CharSet c = KGlobal::charsets()->nameToID(mCharset);
if (mCharset != "utf-8") mCharset = KGlobal::charsets()->name(c);
}
if (mAtmList.count() <= 0)
mMsg->setCharset(mCharset);
writeConfig();
setEditCharset();
}

@ -463,6 +463,14 @@ void KMKernel::init()
the_server_is_ready = true;
cfg->setGroup("Composer");
if (cfg->readListEntry("charsets").isEmpty())
{
cfg->writeEntry("charsets", "us-ascii,utf-8,iso-8859-1,iso-8859-2,"
"iso-8859-3,iso-8859-4,iso-8859-5,iso-8859-6,iso-8859-7,iso-8859-8,"
"iso-8859-9,iso-8859-10,iso-8859-13,iso-8859-14,iso-8859-15,koi8-r,koi8-u,"
"iso-2022-jp,iso-2022-jp-2,iso-2022-kr,euc-jp,euc-kr,Big5,gb2312");
}
// filterMgr->dump();
kdDebug() << "exiting KMKernel::init()" << endl;
}

Loading…
Cancel
Save