kmail

dictionarycombobox.cpp
1 /*
2  dictionarycombobox.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
6 
7  KMail is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License, version 2, as
9  published by the Free Software Foundation.
10 
11  KMail is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the TQt library by Trolltech AS, Norway (or with modified versions
23  of TQt that use the same license as TQt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  TQt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 */
31 
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35 
36 #include "dictionarycombobox.h"
37 
38 #include <ksconfig.h>
39 #include <kdebug.h>
40 
41 #include <tqstringlist.h>
42 
43 namespace KMail {
44 
45  DictionaryComboBox::DictionaryComboBox( TQWidget * parent, const char * name )
46  : TQComboBox( false, parent, name ),
47  mSpellConfig( 0 ),
48  mDefaultDictionary( 0 )
49  {
50  reloadCombo();
51  connect( this, TQ_SIGNAL( activated( int ) ),
52  this, TQ_SLOT( slotDictionaryChanged( int ) ) );
53  connect( this, TQ_SIGNAL( dictionaryChanged( int ) ),
54  mSpellConfig, TQ_SLOT( sSetDictionary( int ) ) );
55  }
56 
57  DictionaryComboBox::~DictionaryComboBox()
58  {
59  delete mSpellConfig;
60  mSpellConfig = 0;
61  }
62 
63  TQString DictionaryComboBox::currentDictionaryName() const
64  {
65  return currentText();
66  }
67 
68  TQString DictionaryComboBox::currentDictionary() const
69  {
70  TQString dict = mDictionaries[ currentItem() ];
71  if ( dict.isEmpty() )
72  return "<default>";
73  else
74  return dict;
75  }
76 
77  void DictionaryComboBox::setCurrentByDictionaryName( const TQString & name )
78  {
79  if ( name.isEmpty() )
80  return;
81 
82  for ( int i = 0; i < count(); ++i ) {
83  if ( text( i ) == name ) {
84  if ( i != currentItem() ) {
85  setCurrentItem( i );
86  slotDictionaryChanged( i );
87  }
88  return;
89  }
90  }
91  }
92 
93  void DictionaryComboBox::setCurrentByDictionary( const TQString & dictionary )
94  {
95  if ( !dictionary.isEmpty() ) {
96  // first handle the special case of the default dictionary
97  if ( dictionary == "<default>" ) {
98  if ( 0 != currentItem() ) {
99  setCurrentItem( 0 );
100  slotDictionaryChanged( 0 );
101  }
102  return;
103  }
104 
105  int i = 0;
106  for ( TQStringList::ConstIterator it = mDictionaries.begin();
107  it != mDictionaries.end();
108  ++it, ++i ) {
109  if ( *it == dictionary ) {
110  if ( i != currentItem() ) {
111  setCurrentItem( i );
112  slotDictionaryChanged( i );
113  }
114  return;
115  }
116  }
117  }
118 
119  // If dictionary is empty or doesn't exist fall back to the global default
120  if ( mDefaultDictionary != currentItem() ) {
121  setCurrentItem( mDefaultDictionary );
122  slotDictionaryChanged( mDefaultDictionary );
123  }
124  }
125 
126  KSpellConfig* DictionaryComboBox::spellConfig() const
127  {
128  return mSpellConfig;
129  }
130 
131  void DictionaryComboBox::reloadCombo()
132  {
133  delete mSpellConfig;
134  mSpellConfig = new KSpellConfig( 0, 0, 0, false );
135  mSpellConfig->fillDicts( this, &mDictionaries );
136  mDefaultDictionary = currentItem();
137  mSpellConfig->setDictionary( currentDictionary() );
138  }
139 
140  void DictionaryComboBox::slotDictionaryChanged( int idx )
141  {
142  kdDebug( 5006 ) << "DictionaryComboBox::slotDictionaryChanged( " << idx
143  << " )" << endl;
144  emit dictionaryChanged( mDictionaries[idx] );
145  emit dictionaryChanged( idx );
146  }
147 
148 } // namespace KMail
149 
150 #include "dictionarycombobox.moc"
folderdiaquotatab.h
Definition: aboutdata.cpp:40