00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <kdebug.h>
00019 #include "filterlist.h"
00020
00021 FilterList::FilterList()
00022 {
00023 setAutoDelete (true);
00024 }
00025
00026 FilterList::~FilterList()
00027 {
00028 }
00029
00030 void FilterList::setCombo (TQComboBox* combo, int nIndex)
00031 {
00032 combo->clear ();
00033 for (FilterElem* pElem = first(); pElem; pElem = next())
00034 {
00035 combo->insertItem (pElem->toString());
00036 }
00037 if (nIndex >= 0)
00038 {
00039 at (nIndex);
00040 combo->setCurrentItem (nIndex);
00041 }
00042 }
00043
00044 FilterList& FilterList::operator = (FilterList& list)
00045 {
00046 clear ();
00047 int nIndex = list.at ();
00048 for (FilterElem* item = list.first (); item; item = list.next ())
00049 {
00050 inSort (new FilterElem (*item));
00051 }
00052 at (nIndex);
00053 return *this;
00054 }
00055
00056 TQPtrCollection::Item FilterList::newItem (TQPtrCollection::Item d)
00057 {
00058 return new FilterElem (*(FilterElem*)d);
00059 }
00060
00061 int FilterList::compareItems (TQPtrCollection::Item item1, TQPtrCollection::Item item2 )
00062 {
00063 FilterElem* entry1 = (FilterElem*) item1;
00064 FilterElem* entry2 = (FilterElem*) item2;
00065
00066
00067 if (entry1->getCounter() < entry2->getCounter())
00068 return 1;
00069 else if (entry1->getCounter() == entry2->getCounter())
00070 {
00071
00072 if (entry1->toString() > entry2->toString())
00073 return 1;
00074 else if (entry1->toString() == entry2->toString())
00075 return 0;
00076 else
00077 return -1;
00078 }
00079 else return -1;
00080 }
00081
00082 void FilterList::readOptions (TDEConfig* config)
00083 {
00084 bool goon = true;
00085 int i = 0;
00086 while (goon)
00087 {
00088 config->setGroup (TQString("filter%1").arg(i));
00089 TQString name (config->readEntry ("name"));
00090 if (!name.isEmpty ())
00091 {
00092 unsigned int counter = config->readNumEntry ("counter");
00093 FilterRecord::filterType type = (FilterRecord::filterType)config->readNumEntry ("type1");
00094 FilterRecord::expressionType expr = (FilterRecord::expressionType)config->readNumEntry ("expression1");
00095 TQString match = config->readEntry ("match1");
00096 bool caseSensitive = (bool)config->readNumEntry ("casesensitive1", 0);
00097 bool regExp = (bool)config->readNumEntry ("regexp1", 0);
00098
00099 FilterElem* filter = new FilterElem (FilterRecord(type, expr, match, caseSensitive, regExp));
00100 filter->setCounter( counter );
00101
00102 FilterElem::secondCondition secondCondition = (FilterElem::secondCondition)config->readNumEntry ("secondcondition");
00103 type = (FilterRecord::filterType)config->readNumEntry ("type2");
00104 expr = (FilterRecord::expressionType)config->readNumEntry ("expression2");
00105 match = config->readEntry ("match2");
00106 caseSensitive = (bool)config->readNumEntry ("casesensitive2", 0);
00107 regExp = (bool)config->readNumEntry ("regexp2", 0);
00108
00109 filter->setSecondCondition(secondCondition, FilterRecord (type, expr, match, caseSensitive, regExp));
00110
00111 inSort (filter);
00112 i++;
00113 }
00114 else
00115 goon = false;
00116 }
00117 if (i > 0)
00118 at (0);
00119 sort ();
00120 }
00121
00122 void FilterList::saveOptions (TDEConfig* config)
00123 {
00124
00125 int filterNumber = 0;
00126 bool ready = false;
00127
00128 while( !ready )
00129 {
00130
00131 if( config->hasGroup( TQString( CONFIG_GROUP_FILTER ) + TQString( "%1" ).arg( filterNumber ) ) )
00132 {
00133
00134 config->deleteGroup( TQString( CONFIG_GROUP_FILTER ) + TQString( "%1" ).arg( filterNumber ) );
00135
00136
00137 filterNumber++;
00138 }
00139 else
00140 ready = true;
00141 }
00142
00143
00144 kdDebug () << "FilterList::saveOptions" << endl;
00145 for (unsigned int i = 0; i < count (); i++)
00146 {
00147 config->setGroup (TQString ("filter%1").arg(i));
00148 config->writeEntry ("name", at(i)->toString());
00149 config->writeEntry ("counter", at(i)->getCounter() );
00150
00151 config->writeEntry ("type1", at(i)->_filter1._type);
00152 config->writeEntry ("expression1", at(i)->_filter1._expression);
00153 config->writeEntry ("match1", at(i)->_filter1._match);
00154 config->writeEntry ("casesensitive1", at(i)->_filter1._CaseSensitive);
00155 config->writeEntry ("regexp1", at(i)->_filter1._RegExp);
00156
00157 config->writeEntry ("secondcondition", at(i)->_secondCondition);
00158
00159 config->writeEntry ("type2", at(i)->_filter2._type);
00160 config->writeEntry ("expression2", at(i)->_filter2._expression);
00161 config->writeEntry ("match2", at(i)->_filter2._match);
00162 config->writeEntry ("casesensitive2", at(i)->_filter2._CaseSensitive);
00163 config->writeEntry ("regexp2", at(i)->_filter2._RegExp);
00164 }
00165 }