00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
#ifdef HAVE_CONFIG_H
00033
#include <config.h>
00034
#endif
00035
00036
#include "dictionarycombobox.h"
00037
00038
#include <ksconfig.h>
00039
#include <kdebug.h>
00040
00041
#include <qstringlist.h>
00042
00043
namespace KMail {
00044
00045 DictionaryComboBox::DictionaryComboBox(
QWidget * parent,
const char * name )
00046 :
QComboBox( false, parent, name ),
00047 mSpellConfig( 0 ),
00048 mDefaultDictionary( 0 )
00049 {
00050 reloadCombo();
00051 connect(
this, SIGNAL( activated(
int ) ),
00052
this, SLOT( slotDictionaryChanged(
int ) ) );
00053 connect(
this, SIGNAL( dictionaryChanged(
int ) ),
00054 mSpellConfig, SLOT( sSetDictionary(
int ) ) );
00055 }
00056
00057 DictionaryComboBox::~DictionaryComboBox()
00058 {
00059
delete mSpellConfig;
00060 mSpellConfig = 0;
00061 }
00062
00063
QString DictionaryComboBox::currentDictionaryName()
const
00064
{
00065
return currentText();
00066 }
00067
00068
QString DictionaryComboBox::currentDictionary()
const
00069
{
00070
QString dict = mDictionaries[ currentItem() ];
00071
if ( dict.isEmpty() )
00072
return "<default>";
00073
else
00074
return dict;
00075 }
00076
00077
void DictionaryComboBox::setCurrentByDictionaryName(
const QString & name )
00078 {
00079
if ( name.isEmpty() )
00080
return;
00081
00082
for (
int i = 0; i < count(); ++i ) {
00083
if ( text( i ) == name ) {
00084
if ( i != currentItem() ) {
00085 setCurrentItem( i );
00086 slotDictionaryChanged( i );
00087 }
00088
return;
00089 }
00090 }
00091 }
00092
00093
void DictionaryComboBox::setCurrentByDictionary(
const QString & dictionary )
00094 {
00095
if ( !dictionary.isEmpty() ) {
00096
00097
if ( dictionary ==
"<default>" ) {
00098
if ( 0 != currentItem() ) {
00099 setCurrentItem( 0 );
00100 slotDictionaryChanged( 0 );
00101 }
00102
return;
00103 }
00104
00105
int i = 0;
00106
for ( QStringList::ConstIterator it = mDictionaries.begin();
00107 it != mDictionaries.end();
00108 ++it, ++i ) {
00109
if ( *it == dictionary ) {
00110
if ( i != currentItem() ) {
00111 setCurrentItem( i );
00112 slotDictionaryChanged( i );
00113 }
00114
return;
00115 }
00116 }
00117 }
00118
00119
00120
if ( mDefaultDictionary != currentItem() ) {
00121 setCurrentItem( mDefaultDictionary );
00122 slotDictionaryChanged( mDefaultDictionary );
00123 }
00124 }
00125
00126 KSpellConfig* DictionaryComboBox::spellConfig()
const
00127
{
00128
return mSpellConfig;
00129 }
00130
00131
void DictionaryComboBox::reloadCombo()
00132 {
00133
delete mSpellConfig;
00134 mSpellConfig =
new KSpellConfig( 0, 0, 0,
false );
00135 mSpellConfig->fillDicts(
this, &mDictionaries );
00136 mDefaultDictionary = currentItem();
00137 }
00138
00139
void DictionaryComboBox::slotDictionaryChanged(
int idx )
00140 {
00141 kdDebug( 5006 ) <<
"DictionaryComboBox::slotDictionaryChanged( " << idx
00142 <<
" )" << endl;
00143 emit dictionaryChanged( mDictionaries[idx] );
00144 emit dictionaryChanged( idx );
00145 }
00146
00147 }
00148
00149
#include "dictionarycombobox.moc"