00001 /*************************************************************************** 00002 filterentrydialog.cpp - description 00003 ------------------- 00004 begin : Mit Sep 24 2003 00005 copyright : (C) 2003 by Eggert Ehmke 00006 email : eggert.ehmke@berlin.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include <tqvalidator.h> 00019 #include <tqlineedit.h> 00020 #include <tqcombobox.h> 00021 #include <tqcheckbox.h> 00022 #include <tqgroupbox.h> 00023 #include <tqspinbox.h> 00024 #include <tqpushbutton.h> 00025 00026 #include <kdebug.h> 00027 #include <tdelocale.h> 00028 #include <tdemessagebox.h> 00029 #include <kregexpeditorinterface.h> 00030 #include <tdeparts/part.h> 00031 #include <tdeparts/componentfactory.h> 00032 00033 #include "filterelem.h" 00034 #include "filterentrydialog.h" 00035 00036 FilterEntryDialog::FilterEntryDialog(TQWidget *parent, const char *name, FilterElem* elem ) : 00037 FilterEntryDlg(parent,name), _elem (elem) 00038 { 00039 _editName->setText (elem->toString()); 00040 00041 _comboItem1->setCurrentItem (elem->_filter1._type); 00042 _comboExpression1->setCurrentItem (elem->_filter1._expression); 00043 _editMatch1->setText (elem->_filter1._match); 00044 _checkCaseSensitive1->setChecked (elem->_filter1._CaseSensitive); 00045 _checkRegExp1->setChecked (elem->_filter1._RegExp); 00046 00047 _comboSecondCondition->setCurrentItem (elem->_secondCondition); 00048 00049 _comboItem2->setCurrentItem (elem->_filter2._type); 00050 _comboExpression2->setCurrentItem (elem->_filter2._expression); 00051 _editMatch2->setText (elem->_filter2._match); 00052 _checkCaseSensitive2->setChecked (elem->_filter2._CaseSensitive); 00053 _checkRegExp2->setChecked (elem->_filter2._RegExp); 00054 _spinCounter->setValue (elem->getCounter() ); 00055 00056 slotItem1Selected (elem->_filter1._type); 00057 slotItem2Selected (elem->_filter2._type); 00058 slotSecondCondition (_elem->_secondCondition); 00059 00060 if (TDETrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty()) 00061 { 00062 _buttonEditRegExp1->hide(); 00063 _buttonEditRegExp2->hide(); 00064 } 00065 else 00066 { 00067 _buttonEditRegExp1->setEnabled (elem->_filter1._RegExp); 00068 _buttonEditRegExp2->setEnabled (elem->_filter2._RegExp); 00069 } 00070 } 00071 00072 FilterEntryDialog::~FilterEntryDialog() 00073 { 00074 } 00075 00076 void FilterEntryDialog::slotOk () 00077 { 00078 if (_editMatch1->text().isEmpty() || 00079 (((FilterElem::secondCondition)_comboSecondCondition->currentItem() != FilterElem::noSecondCondition) && 00080 _editMatch2->text().isEmpty())) 00081 { 00082 KMessageBox::sorry (this, i18n("Your conditions contain empty match strings.\n" 00083 "This will not work.")); 00084 return; 00085 } 00086 00087 if (_elem->_filter1._RegExp) 00088 { 00089 TQRegExp exp (_elem->_filter1._match); 00090 if (!exp.isValid()) 00091 { 00092 KMessageBox::sorry (this, i18n ("Condition") + ":\n" + exp.errorString()); 00093 return; 00094 } 00095 } 00096 if (_elem->_secondCondition && _elem->_filter2._RegExp) 00097 { 00098 TQRegExp exp (_elem->_filter2._match); 00099 if (!exp.isValid()) 00100 { 00101 KMessageBox::sorry (this, i18n ("second Condition") + ":\n" + exp.errorString()); 00102 return; 00103 } 00104 } 00105 00106 _elem->_filter1._CaseSensitive = _checkCaseSensitive1->isChecked(); 00107 _elem->_filter2._CaseSensitive = _checkCaseSensitive2->isChecked(); 00108 _elem->_filter1._RegExp = _checkRegExp1->isChecked(); 00109 _elem->_filter2._RegExp = _checkRegExp2->isChecked(); 00110 00111 accept (); 00112 } 00113 00114 void FilterEntryDialog::slotItem1Selected (int type) 00115 { 00116 if (type == FilterRecord::size) 00117 { 00118 int dummy; 00119 TQString match (_editMatch1->text()); 00120 TQIntValidator* validator = new TQIntValidator (_editMatch1); 00121 if (validator->validate (match, dummy) == TQValidator::Invalid) 00122 _editMatch1->clear(); 00123 _editMatch1->setValidator (validator); 00124 _checkCaseSensitive1->setEnabled (false); 00125 } 00126 else 00127 { 00128 _editMatch1->setValidator (NULL); 00129 _checkCaseSensitive1->setEnabled (true); 00130 } 00131 00132 _elem->_filter1._type = (FilterRecord::filterType)type; 00133 _editName->setText (_elem->toString()); 00134 } 00135 00136 void FilterEntryDialog::slotItem2Selected (int type) 00137 { 00138 if (type == FilterRecord::size) 00139 { 00140 int dummy; 00141 TQString match (_editMatch2->text()); 00142 TQIntValidator* validator = new TQIntValidator (_editMatch2); 00143 if (validator->validate (match, dummy) == TQValidator::Invalid) 00144 _editMatch2->clear(); 00145 _editMatch2->setValidator (validator); 00146 _checkCaseSensitive2->setEnabled (false); 00147 } 00148 else 00149 { 00150 _editMatch2->setValidator (NULL); 00151 _checkCaseSensitive2->setEnabled (true); 00152 } 00153 00154 _elem->_filter2._type = (FilterRecord::filterType)type; 00155 _editName->setText (_elem->toString()); 00156 } 00157 00158 void FilterEntryDialog::slotSecondCondition (int condition) 00159 { 00160 if (condition == FilterElem::noSecondCondition) 00161 _groupBox2->setEnabled(false); 00162 else 00163 _groupBox2->setEnabled(true); 00164 00165 _elem->_secondCondition = (FilterElem::secondCondition)condition; 00166 _editName->setText (_elem->toString()); 00167 } 00168 00169 void FilterEntryDialog::slotCondition1Selected(int cond) 00170 { 00171 _elem->_filter1._expression = (FilterRecord::expressionType)cond; 00172 _editName->setText (_elem->toString()); 00173 } 00174 00175 void FilterEntryDialog::slotCondition2Selected(int cond) 00176 { 00177 _elem->_filter2._expression = (FilterRecord::expressionType)cond; 00178 _editName->setText (_elem->toString()); 00179 } 00180 00181 void FilterEntryDialog::slotMatch1Changed(const TQString& match) 00182 { 00183 _elem->_filter1._match = match; 00184 _editName->setText (_elem->toString()); 00185 } 00186 00187 void FilterEntryDialog::slotMatch2Changed(const TQString& match) 00188 { 00189 _elem->_filter2._match = match; 00190 _editName->setText (_elem->toString()); 00191 } 00192 00193 void FilterEntryDialog::slotResetCounter() 00194 { 00195 _spinCounter->setValue(0); 00196 } 00197 00198 void FilterEntryDialog::slotCounterChanged (int val) 00199 { 00200 _elem->setCounter( val ); 00201 _editName->setText (_elem->toString()); 00202 } 00203 00204 void FilterEntryDialog::slotEditRegExp1() 00205 { 00206 TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>( "KRegExpEditor/KRegExpEditor" ); 00207 if ( editorDialog ) 00208 { 00209 // tdeutils was installed, so the dialog was found fetch the editor interface 00210 KRegExpEditorInterface *editor = static_cast<KRegExpEditorInterface *>( editorDialog->qt_cast( "KRegExpEditorInterface" ) ); 00211 Q_ASSERT( editor ); // This should not fail! 00212 00213 // now use the editor. 00214 editor->setRegExp(_editMatch1->text()); 00215 00216 // Finally exec the dialog 00217 if (editorDialog->exec() == TQDialog::Accepted) 00218 _editMatch1->setText (editor->regExp()); 00219 } 00220 } 00221 00222 void FilterEntryDialog::slotEditRegExp2() 00223 { 00224 TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>( "KRegExpEditor/KRegExpEditor" ); 00225 if ( editorDialog ) 00226 { 00227 // tdeutils was installed, so the dialog was found fetch the editor interface 00228 KRegExpEditorInterface *editor = static_cast<KRegExpEditorInterface *>( editorDialog->qt_cast( "KRegExpEditorInterface" ) ); 00229 Q_ASSERT( editor ); // This should not fail! 00230 00231 // now use the editor. 00232 editor->setRegExp(_editMatch2->text()); 00233 00234 // Finally exec the dialog 00235 if (editorDialog->exec() == TQDialog::Accepted) 00236 _editMatch2->setText (editor->regExp()); 00237 } 00238 } 00239 00240 void FilterEntryDialog::slotToggleRegExp1 (bool on) 00241 { 00242 _buttonEditRegExp1->setEnabled (on); 00243 } 00244 00245 void FilterEntryDialog::slotToggleRegExp2 (bool on) 00246 { 00247 _buttonEditRegExp2->setEnabled (on); 00248 } 00249 00250