koSpellConfig.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <koSpellConfig.h>
00021 #include <kdebug.h>
00022 #include "koSpellConfig.moc"
00023 #include "klocale.h"
00024 #include <kdialog.h>
00025 #include <klineedit.h>
00026 #include <keditlistbox.h>
00027 #include <kio/netaccess.h>
00028 #include "koSconfig.h"
00029
00030 #include <qcheckbox.h>
00031 #include <qlabel.h>
00032 #include <qvbox.h>
00033 #include <qcombobox.h>
00034 #include <qwhatsthis.h>
00035 #include <qvgroupbox.h>
00036 #include <qlistbox.h>
00037 #include <qpushbutton.h>
00038 #include <qtabwidget.h>
00039 #include <qgrid.h>
00040 #include <qgroupbox.h>
00041 #include <qlayout.h>
00042 #include <qfile.h>
00043 #include <qtextstream.h>
00044 #include <qdir.h>
00045
00046 KoSpellConfigWidget::KoSpellConfigWidget( QWidget *_parent, KOSpellConfig *_config, bool backgroundSpellCheck )
00047 : QWidget( _parent)
00048 {
00049 QTabWidget *tab = new QTabWidget(_parent);
00050 QGroupBox* tmpQGroupBox = new QGroupBox( tab, "GroupBox" );
00051 tmpQGroupBox->setTitle(i18n("Spelling"));
00052 QGridLayout *grid1 = new QGridLayout(tmpQGroupBox, 6, 1, KDialog::marginHint(), KDialog::spacingHint());
00053 grid1->addRowSpacing( 0, KDialog::marginHint() + 5 );
00054 grid1->setRowStretch( 5, 10 );
00055 m_spellConfig = new KOSpellConfig(tmpQGroupBox, 0L, _config, false );
00056 grid1->addWidget(m_spellConfig,1,0);
00057
00058 m_cbBackgroundSpellCheck=new QCheckBox(i18n("Show misspelled words in document"),tmpQGroupBox);
00059 grid1->addWidget(m_cbBackgroundSpellCheck,4,0);
00060
00061 if ( !backgroundSpellCheck )
00062 m_cbBackgroundSpellCheck->hide();
00063
00064 tab->addTab(tmpQGroupBox, i18n("General"));
00065
00066 QVBox* tmpQGroupBox2 = new QVBox( tab, "GroupBox2" );
00067 m_listignoreall = new KEditListBox( i18n("Word"),
00068 tmpQGroupBox2, "list_ignoreall" , false,
00069 KEditListBox::Add|KEditListBox::Remove );
00070
00071 m_clearIgnoreAllHistory= new QPushButton( i18n("Clear Ignore All Word History"),tmpQGroupBox2);
00072 connect( m_clearIgnoreAllHistory, SIGNAL(clicked()),this, SLOT(slotClearIgnoreAllHistory()));
00073
00074 tab->addTab(tmpQGroupBox2, i18n( "Ignore All List" ) );
00075
00076
00077 QVBox* tmpQGroupBox3 = new QVBox( tab, "GroupBox3" );
00078 m_dictionary = new KEditListBox( i18n("Word"),
00079 tmpQGroupBox3, "dictionary" , false,
00080 KEditListBox::Add|KEditListBox::Remove );
00081
00082 m_clearDictionary = new QPushButton( i18n("Clear Dictionary"),tmpQGroupBox3);
00083 connect( m_clearDictionary, SIGNAL(clicked()),this, SLOT(slotClearDictionary()));
00084
00085 tab->addTab(tmpQGroupBox3, i18n("Dictionary"));
00086 initDictionaryListWord();
00087 }
00088
00089
00090 void KoSpellConfigWidget::initDictionaryListWord()
00091 {
00092 if ( m_spellConfig->client() == KOS_CLIENT_ISPELL )
00093 {
00094
00095 QString directoryName = QDir::homeDirPath() + "/.ispell_"+m_spellConfig->dictionary();
00096 kdDebug()<<" directoryName :"<<directoryName<<endl;
00097 QFile f( directoryName );
00098 if ( f.exists() && f.open(IO_ReadOnly))
00099 {
00100 QTextStream t( &f );
00101 QString result = t.read();
00102 f.close();
00103 QStringList lst = QStringList::split("\n", result);
00104 m_dictionary->insertStringList( lst );
00105 }
00106 }
00107 else
00108 {
00109 m_dictionary->setEnabled( false );
00110 m_clearDictionary->setEnabled( false );
00111 }
00112 }
00113
00114 bool KoSpellConfigWidget::backgroundSpellCheck()
00115 {
00116 return m_cbBackgroundSpellCheck->isChecked();
00117 }
00118
00119 void KoSpellConfigWidget::setBackgroundSpellCheck( bool _b )
00120 {
00121 m_cbBackgroundSpellCheck->setChecked(_b);
00122 }
00123
00124 void KoSpellConfigWidget::slotClearIgnoreAllHistory()
00125 {
00126 m_listignoreall->listBox()->clear();
00127 m_listignoreall->lineEdit()->clear();
00128
00129 }
00130
00131 void KoSpellConfigWidget::addIgnoreList( const QStringList & lst)
00132 {
00133 m_listignoreall->listBox()->insertStringList( lst );
00134
00135 }
00136
00137 QStringList KoSpellConfigWidget::ignoreList()
00138 {
00139 QStringList lst;
00140 for (int i = 0; i< (int)m_listignoreall->listBox()->count() ; i++)
00141 lst << m_listignoreall->listBox()->text( i );
00142 return lst;
00143 }
00144
00145 void KoSpellConfigWidget::setDefault()
00146 {
00147 m_spellConfig->setNoRootAffix( 0);
00148 m_spellConfig->setRunTogether(0);
00149 m_spellConfig->setDictionary( "");
00150 m_spellConfig->setDictFromList( FALSE);
00151 m_spellConfig->setEncoding (KOS_E_ASCII);
00152 m_spellConfig->setClient (KOS_CLIENT_ISPELL);
00153
00154
00155 m_spellConfig->setIgnoreCase(false);
00156 m_spellConfig->setIgnoreAccent(false);
00157 m_spellConfig->setSpellWordWithNumber(false);
00158 m_spellConfig->setDontCheckUpperWord(false);
00159 m_spellConfig->setDontCheckTitleCase(false);
00160 m_cbBackgroundSpellCheck->setChecked(false);
00161 m_listignoreall->listBox()->clear();
00162 }
00163
00164 void KoSpellConfigWidget::slotClearDictionary()
00165 {
00166 m_dictionary->listBox()->clear();
00167 m_dictionary->lineEdit()->clear();
00168 }
00169
00170 void KoSpellConfigWidget::saveDictionary()
00171 {
00172 QString lst;
00173 for (int i = 0; i< (int)m_dictionary->listBox()->count() ; i++)
00174 lst+= m_dictionary->listBox()->text( i ) +"\n";
00175
00176 if ( m_spellConfig->client() == KOS_CLIENT_ISPELL )
00177 {
00178 QString directoryName = QDir::homeDirPath() + "/.ispell_"+m_spellConfig->dictionary();
00179 QFile f( directoryName );
00180 (void )KIO::NetAccess::del( KURL( f.name() ) );
00181 if ( f.open(IO_ReadWrite))
00182 {
00183 QTextStream t( &f );
00184 t <<lst;
00185 f.close();
00186 }
00187 }
00188
00189 }
This file is part of the documentation for lib Library Version 1.3.5.