summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/modules/dbsearchengine2/KDBSearchEngine2.cpp
blob: a3309a26b01f71721cb18cd8a0687de83d8fc0a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/***************************************************************************
			  KDBSearchEngine2.cpp  -  description
			     -------------------
    begin                : Fri Sep 8 2000
    copyright            : (C) 2000-2003 by Andrea Rizzi
    email                : rizzi@kde.org
***************************************************************************/

/*
  Translation search engine. Version II
  
  
  Copyright  2000-2003
  Andrea Rizzi rizzi@kde.org
  
  License GPL v 2.0

 *                                                                         *
 *   In addition, as a special exception, the copyright holders give       *
 *   permission to link the code of this program with any edition of       *
 *   the TQt library by Trolltech AS, Norway (or with modified versions     *
 *   of TQt that use the same license as TQt), and distribute linked         *
 *   combinations including the two.  You must obey the GNU General        *
 *   Public License in all respects for all of the code used other than    *
 *   TQt. If you modify this file, you may extend this exception to         *
 *   your version of the file, but you are not obligated to do so.  If     *
 *   you do not wish to do so, delete this exception statement from        *
 *   your version.                                                         *
  
*/
#include "algorithms.h"
#include "chunk.h"
#include "database.h"
#include "KDBSearchEngine2.h"
#include "dbscan.h"
#include <klineedit.h>
#include <tdeapplication.h>
#include <tqpushbutton.h>
#include <kurlrequester.h>
#include <tqcheckbox.h>
#include <knuminput.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>

#include <tqmap.h>

#include <kdebug.h>
#define i18n (const char *)

KDBSearchEngine2::KDBSearchEngine2(TQObject *parent,const char*name)
    : SearchEngine(parent,name)
    {
    pw=0;
    dbDirectory=".";
    
    di=0;   //Database Interface is not yet initialized
    
    connect(this,TQT_SIGNAL(hasError(TQString)),TQT_SLOT(setLastError(TQString)));
    
    searching=false;  // i'm not searching
    iAmReady=true;  //there are no reason to say I'm not ready.
    
}


KDBSearchEngine2::~KDBSearchEngine2()
{
    if(di)
	delete di;  //delete database interface
}

bool KDBSearchEngine2::startSearch(TQString str)
{
    kdDebug(0) << "Start a new search. Looking for: " << str << endl;
    
    static TQString queryString;
    
    queryString=str;  //set the latest query string (note: it is static)
    
    if(autoupdate)
    {
	updateSettings();
    }
    
    
    if(!init()) return false;    //-check initialization
    di->stop(true); //stop all new emits from database interface
    emit started(); //say everybody we are starting
    
    if(searching) return true; //We already have a search loop, as soon as we come back
    //on the search loop we will start the new search (queryString).
    
    searching=true;  //really start searching
    
    TQString searchingString;
    
    do //Search loop, it stops only when finished and latest searched string is the actual query string.
    {
	searchingString=queryString; //-set new search string
	di->stop(false);  	   //-unlock searching
	
	if(numberOfResult<1) numberOfResult=1;

//	di->singleWordMatch(searchingString,0,true);

	GenericSearchAlgorithm strategy(di,&settings);

	//Let's create a search sequence:
	ExactSearchAlgorithm exact(di,&settings);
	AlphaSearchAlgorithm alpha(di,&settings);
	SentenceArchiveSearchAlgorithm sent(di,&settings);
	ChunkByChunkSearchAlgorithm sbys(di,&settings);
	ChunkByChunkSearchAlgorithm wbyw(di,&settings);
	CorrelationSearchAlgorithm corr(di,&settings);
	FuzzyChunkSearchAlgorithm fs(di,&settings);
	FuzzyChunkSearchAlgorithm fw(di,&settings);

	SentenceChunkFactory sf(di);
	sbys.setChunkFactory(&sf);
	fs.setChunkFactory(&sf);


	WordChunkFactory wf(di);
	wbyw.setChunkFactory(&wf);
	fw.setChunkFactory(&wf);

	strategy.addAlgorithm(&exact);
	strategy.addAlgorithm(&alpha);
	strategy.addAlgorithm(&sent);
	strategy.addAlgorithm(&sbys);
	//strategy.addAlgorithm(&fs);
	strategy.addAlgorithm(&fw);
	strategy.addAlgorithm(&corr);
	strategy.addAlgorithm(&wbyw);


	connect(&strategy,TQT_SIGNAL(newResult(QueryResult)),this,TQT_SLOT(receiveResult(QueryResult)));
	strategy.exec(searchingString);	disconnect(&strategy,TQT_SIGNAL(newResult(QueryResult)),this,TQT_SLOT(receiveResult(QueryResult)));


	kdDebug(0) << "End of search for " << searchingString  << endl;
    }
    while(searchingString!=queryString);
    kdDebug(0) << "Exiting the search loop" << endl;
    //if != someone asked a different string when we was searching
    //so we restart our search (maybe a cleanresult is needed?).
    
    
    di->stop(false);  //-clean searching locks
    searching=false;  //-clean searching locks
    emit finished();  //Finished
    
    return true;
    
}





bool KDBSearchEngine2::startSearchInTranslation(TQString str)
{
    if(autoupdate)
    { 
	updateSettings();
    }

    //TODO!!!!
    return true; 
    
}



bool KDBSearchEngine2::messagesForPackage(const TQString& package
					  , TQValueList<Message>& resultList, TQString& error)
{
    //FIXME implement this (needs filters)
    return true;
}


void  KDBSearchEngine2::setLastError(TQString er)
{
    lasterror=er;
}

TQString KDBSearchEngine2::translate(const TQString text)
{
	ExactSearchAlgorithm exact(di,&settings);

	return exact.exec(text)[0].result();

}


void KDBSearchEngine2::receiveResult(QueryResult r)
{

    SearchResult se; // Create a new SearchResult for our QueryResult

    se.translation=r.richResult();
    se.found=r.richOriginal();
    
    se.plainTranslation=r.result();
    se.plainFound=r.original();
    se.score=r.score();

    emit resultFound(&se); // dispatch the new SearchResult
    
}


/*  A SEARCH RESULT CONTAINS (see searchengine.h)
    TQString requested;
    TQString found;
    TQString translation;
    TQString plainTranslation;
    TQString plainFound;
    TQString plainRequested;
    int score;
    TQPtrList<TranslationInfo> descriptions;
*/



bool KDBSearchEngine2::init()
{
    if(di!=0) return true; //if there already is a DBinterface we are ok
    else
    {
	di = new DataBaseInterface(dbDirectory,&settings);
	connect(di,TQT_SIGNAL(newResult(QueryResult)),this,TQT_SLOT(receiveResult(QueryResult)));
	//FIXME: what wbout ready()
	if(!di->mainOk()) return false;  //check if the main DB is OK.

	return true;
    }

}
const TDEAboutData *KDBSearchEngine2::about() const
{
    return DbSe2Factory::instance()->aboutData();
}

void KDBSearchEngine2::stringChanged( TQString orig, TQString translated
				      , TQString description)
{

    if(!init()) return;
    //if(translated.isEmpty()) return;
    InputInfo ii;
    if(description.find("fuzzy",false)==-1)
	di->addEntry(orig,translated,&ii);
    
}

PrefWidget * KDBSearchEngine2::preferencesWidget(TQWidget *parent)
{
    
    pw =  new KDB2PreferencesWidget(parent);
    kdDebug(0) << "new KDB2 preferences widget" << endl;
    setSettings();
    connect(pw,TQT_SIGNAL(restoreNow()),this,TQT_SLOT(setSettings()));
    connect(pw,TQT_SIGNAL(applyNow()),this,TQT_SLOT(updateSettings()));
    connect(pw,TQT_SIGNAL(destroyed()),this,TQT_SLOT(prefDestr()));

    
    connect(pw->dbpw->scanAll,TQT_SIGNAL(clicked()),this,TQT_SLOT(scanAllPressed()));
    connect(pw->dbpw->scanSource,TQT_SIGNAL(clicked()),this,TQT_SLOT(scanNowPressed()));
    connect(pw->dbpw->addSource,TQT_SIGNAL(clicked()),this,TQT_SLOT(addSource()));
    connect(pw->dbpw->editSource,TQT_SIGNAL(clicked()),this,TQT_SLOT(editSource()));
    connect(pw->dbpw->removeSource,TQT_SIGNAL(clicked()),this,TQT_SLOT(removeSource()));
    
    
    return pw;
}

void KDBSearchEngine2::saveSettings(TDEConfigBase *config)
{
 TDEConfigGroupSaver cgs(config,"KDBSearchEngine2");
    
 
 
 config->writeEntry("DBDirectory",dbDirectory);
 config->writeEntry("AutoAdd",autoAdd);
 config->writeEntry("UseSentence",useSentence);
 config->writeEntry("UseGlossary",useGlossary);
 config->writeEntry("UseExact",useExact);
 config->writeEntry("UseDivide",useDivide);
 config->writeEntry("UseAlpha",useAlpha);
 config->writeEntry("UseWordByWord",useWordByWord);
 config->writeEntry("UseDynamic",useDynamic);
 config->writeEntry("NumberOfResults",numberOfResult);
 
 config->writeEntry("ScoreDivide",settings.scoreDivide);
 config->writeEntry("ScoreExact",settings.scoreExact);
 config->writeEntry("ScoreSentence",settings.scoreSentence);
 config->writeEntry("ScoreWordByWord",settings.scoreWordByWord);
 config->writeEntry("ScoreGlossary",settings.scoreGlossary);
 config->writeEntry("ScoreAlpha",settings.scoreAlpha);
 config->writeEntry("ScoreDynamic",settings.scoreDynamic);
 config->writeEntry("MinimumScore",settings.minScore);
 config->writeEntry("FirstCapital",settings.firstCapital);
 config->writeEntry("AllCapital",settings.allCapital);
 config->writeEntry("Accelerator",settings.accelerator);
 config->writeEntry("SameLetter",settings.sameLetter);

 uint sourceNumber=0;
 config->writeEntry("NumberOfDBImportSources",sources.count());
 
   for(TQMap<TQString,MessagesSource>::iterator sourceIt=sources.begin() ; sourceIt!=sources.end(); ++sourceIt)
    {
     sourceNumber++;
     config->setGroup("DBImportSource-"+TQString::number(sourceNumber));
     config->writeEntry("Name",sourceIt.key());
     sourceIt.data().writeConfig(config);
    }
}

void KDBSearchEngine2::readSettings(TDEConfigBase *config)
{
    
    /*TQString defaultDir;
 TDEStandardDirs * dirs = TDEGlobal::dirs();
 if(dirs)
 {
     defaultDir = dirs->saveLocation("data");
     if(defaultDir.right(1)!="/")
	 defaultDir+="/";
     defaultDir += "kbabeldict/dbsearchengine2";
 }
*/
    TDEConfigGroupSaver cgs(config,"KDBSearchEngine2");
    
    // dbDirectory=config->readEntry("DBDirectory",defaultDir);
    autoAdd=config->readBoolEntry("AutoAdd",true);
    useSentence=config->readBoolEntry("UseSentence",true);
    useGlossary=config->readBoolEntry("UseGlossary",true);
    useExact=config->readBoolEntry("UseExact",true);
    useDivide=config->readBoolEntry("UseDivide",true);
    useAlpha=config->readBoolEntry("UseAlpha",true);
    useWordByWord=config->readBoolEntry("UseWordByWord",true);
    useDynamic=config->readBoolEntry("UseDynamic",true);
    numberOfResult=config->readNumEntry("NumberOfResults",5);

    settings.scoreDivide=config->readNumEntry("ScoreDivide",90);
    settings.scoreExact=config->readNumEntry("ScoreExact",100);
    settings.scoreSentence=config->readNumEntry("ScoreSentence",90);
    settings.scoreWordByWord=config->readNumEntry("ScoreWordByWord",70);
    settings.scoreGlossary=config->readNumEntry("ScoreGlossary",98);
    settings.scoreAlpha=config->readNumEntry("ScoreAlpha",98);
    settings.scoreDynamic=config->readNumEntry("ScoreDynamic",80);
    settings.minScore=config->readNumEntry("MinimumScore",60);
    settings.firstCapital=config->readBoolEntry("FirstCapital",true);
    settings.allCapital=config->readBoolEntry("AllCapital",false);
    settings.accelerator=config->readBoolEntry("Accelerator",true);
    settings.sameLetter=config->readBoolEntry("SameLetter",true);
 
    uint numberOfSources=config->readNumEntry("NumberOfDBImportSources",0);
    kdDebug(0) << "Found "<< numberOfSources << " sources" << endl;
    for(uint sourceNumber=1;sourceNumber<=numberOfSources;sourceNumber++)
    {
     config->setGroup("DBImportSource-"+TQString::number(sourceNumber));
     TQString name=config->readEntry("Name");
     sources[name].readConfig(config);
    }
    if(pw)
	setSettings();
    
}

void KDBSearchEngine2::setSettings()
{
    if(pw) {
	pw->dbpw->dbDirectory->setURL(dbDirectory);
	pw->dbpw->autoUpdate->setChecked(autoAdd);

	pw->dbpw->useSentence->setChecked(useSentence);
	pw->dbpw->useGlossary->setChecked(useGlossary);
	pw->dbpw->useExact->setChecked(useExact);
	pw->dbpw->useDivide->setChecked(useDivide);
	pw->dbpw->useAlpha->setChecked(useAlpha);
	pw->dbpw->useWordByWord->setChecked(useWordByWord);
	pw->dbpw->useDynamic->setChecked(useDynamic);
	pw->dbpw->numberOfResult->setValue(numberOfResult);
	pw->dbpw->scoreDivide->setValue(settings.scoreDivide);
	pw->dbpw->scoreExact->setValue(settings.scoreExact);
	pw->dbpw->scoreSentence->setValue(settings.scoreSentence);
	pw->dbpw->scoreWordByWord->setValue(settings.scoreWordByWord);
	pw->dbpw->scoreGlossary->setValue(settings.scoreGlossary);
	pw->dbpw->scoreAlpha->setValue(settings.scoreAlpha);
	pw->dbpw->scoreDynamic->setValue(settings.scoreDynamic);
	pw->dbpw->minScore->setValue(settings.minScore);
	pw->dbpw->firstCapital->setChecked(settings.firstCapital);
	pw->dbpw->allCapital->setChecked(settings.allCapital);
	pw->dbpw->accelerator->setChecked(settings.accelerator);
	pw->dbpw->sameLetter->setChecked(settings.sameLetter);
	
	//pw->dbpw->checkLang->setChecked(true);
	//pw->dbpw->useFilters->setChecked(false);
	//pw->dbpw->dateToday->setChecked(false);
	pw->dbpw->sourceList->clear();	
	for(TQMap<TQString,MessagesSource>::iterator sourceIt=sources.begin() ; sourceIt!=sources.end(); ++sourceIt)
	{
	    pw->dbpw->sourceList->insertItem(sourceIt.key());
	}
    }

}

void KDBSearchEngine2::updateSettings()
{
    if(!pw) return;
    
    TQString newdb = pw->dbpw->dbDirectory->url();
    if(newdb !=dbDirectory)
    {
	kdDebug(0) << "Recreate DB-Interface cause dbdir is changed" << endl;
	dbDirectory=newdb;
	if (di!=0) delete di;
	di= new DataBaseInterface(dbDirectory,&settings);
    }
    
    autoAdd=pw->dbpw->autoUpdate->isChecked();
    
    useSentence=pw->dbpw->useSentence->isChecked();
    useGlossary=pw->dbpw->useGlossary->isChecked();
    useExact=pw->dbpw->useExact->isChecked();
    useDivide=pw->dbpw->useDivide->isChecked();
    useAlpha=pw->dbpw->useAlpha->isChecked();
    useWordByWord=pw->dbpw->useWordByWord->isChecked();
    useDynamic=pw->dbpw->useDynamic->isChecked();
    
    numberOfResult=pw->dbpw->numberOfResult->value();
    
    settings.scoreWordByWord=pw->dbpw->scoreWordByWord->value();
    settings.scoreGlossary=pw->dbpw->scoreGlossary->value();
    settings.scoreDivide=pw->dbpw->scoreDivide->value();
    settings.scoreExact=pw->dbpw->scoreExact->value();
    settings.scoreSentence=pw->dbpw->scoreSentence->value();
    settings.scoreAlpha=pw->dbpw->scoreAlpha->value();
    settings.scoreDynamic=pw->dbpw->scoreDynamic->value();
    
    settings.minScore=pw->dbpw->minScore->value();
    
    settings.firstCapital=pw->dbpw->firstCapital->isChecked();
    settings.allCapital=pw->dbpw->allCapital->isChecked();
    settings.accelerator=pw->dbpw->accelerator->isChecked();
    settings.sameLetter=pw->dbpw->sameLetter->isChecked();
    
    //pw->dbpw->editRule->
    //pw->dbpw->deleteRule->
    //pw->dbpw->customRules->

    /*
pw->dbpw->checkLang->
pw->dbpw->useFilters->
pw->dbpw->dateToday->

pw->dbpw->removeSource->
pw->dbpw->scanSource->
pw->dbpw->addSource->
pw->dbpw->sourceDir->
pw->dbpw->scanAll->
pw->dbpw->sourceList->
*/

}


/*void  KDBSearchEngine2::scanSource(TQString sourceName)
{
    //FIXME: an error here would be nice
    if(!init()) return;
    
    
    for(TQValueList<MessagesSource>::iterator sourceIt=sources.begin() ; sourceIt!=sources.end(); sourceIt++)
    {
	if((*sourceIt).getName()==sourceName)
	{
	    TQValueList<KURL> urls=(*sourceIt).urls();
	    PoScanner ps(di);
	    for(TQValueList<KURL>::iterator urlIt=urls.begin();urlIt!=urls.end();urlIt++)
		ps.scanFile(*urlIt);

	    //We suppose name are unique so no need for further scrolling
	    return ;
	}	
    }
}*/
void  KDBSearchEngine2::scanNowPressed()
{
    if(!pw)
    {
	kdDebug(0) << "We should not be here, scanNow called without a pw!" << endl;
	return; 
    }
    TQString sourceName;	
    sourceName=pw->dbpw->sourceList->currentText();
    if(!init()) return;
    if(sources.contains(sourceName))
    {
	TQValueList<KURL> urls=sources[sourceName].urls();
	PoScanner ps(di);
	for(TQValueList<KURL>::iterator urlIt=urls.begin();urlIt!=urls.end();++urlIt)
	    ps.scanURL(*urlIt);	
	
    }
    else
    {	
	kdDebug(0) << "source name not found in our MAP. This is a bug." << endl;	
    }	
}

void  KDBSearchEngine2::scanAllPressed()
{
    //FIXME: an error here would be nice too
    if(!init()) return;
    PoScanner ps(di);
    
    
    for(TQMap<TQString,MessagesSource>::iterator sourceIt=sources.begin() ; sourceIt!=sources.end(); ++sourceIt)
    {
	TQValueList<KURL> urls=(*sourceIt).urls();
	for(TQValueList<KURL>::iterator urlIt=urls.begin();urlIt!=urls.end();++urlIt)
	    ps.scanURL(*urlIt);	
    }	
}

void  KDBSearchEngine2::editSource()
{
    if(!pw)
    {
	kdDebug(0) << "We should not be here, editSource called without a pw!" << endl;
	return; 
    }
    TQString sourceName;	
    sourceName=pw->dbpw->sourceList->currentText();
 
    if(sources.contains(sourceName))
    {
	bool nameIsNew;
	TQString newName;
	SourceDialog sd;
	do{
	    sources[sourceName].setDialogValues(&sd);
	    sd.sourceName->setText(sourceName);
	    if(sd.exec()==TQDialog::Accepted)
	    {
		sources[sourceName].getDialogValues(&sd);
		newName= sd.sourceName->text();
	    } else
	    {
		return;
	    }
	    nameIsNew=sources.contains(newName);
	    if(newName!=sourceName && !nameIsNew)
	    {

		KMessageBox::error(0,
		i18n("The name you chose is already used.\nPlease change the source name."),
		i18n("Name is Not Unique"));
		kdDebug(0) << "Name is not uniqe" << endl;
	    }
	}while(newName!=sourceName && !nameIsNew);

	if(newName!=sourceName){
	  sources[newName]=sources[sourceName];
	  sources.remove(sourceName);
	}
	pw->dbpw->sourceList->changeItem(newName,pw->dbpw->sourceList->currentItem());

    }
    else
    {
	kdDebug(0) << "source name not found in our MAP. This is a bug." << endl;
    }

}
void  KDBSearchEngine2::removeSource()
{

    if(!pw)
    {
	kdDebug(0) << "We should not be here, delteSource called without a pw!" << endl;
	return; 
    }
    TQString sourceName;	
    sourceName=pw->dbpw->sourceList->currentText();
    sources.remove(sourceName);
    pw->dbpw->sourceList->removeItem(pw->dbpw->sourceList->currentItem());

}

void  KDBSearchEngine2::addSource()
{
    TQString newName;
    SourceDialog sd;
    bool nameIsNew;
    do{
	if(sd.exec()==TQDialog::Accepted)
	{
	    newName= sd.sourceName->text();
	    nameIsNew=!sources.contains(newName);
	}
	else
	{
	    return;
	}
	// nameIsNew=sources.contains(newName);
	if(!nameIsNew)
	{
		KMessageBox::error(0,i18n("The name you chose is already used.\nPlease change the source name."),
		i18n("Name is Not Unique"));
	    kdDebug(0) << "Name is not uniqe" << endl;
	}
	else
	{
	    	    sources[newName].getDialogValues(&sd);
	}
    }while(!nameIsNew);

    pw->dbpw->sourceList->insertItem(newName);


}
TQString KDBSearchEngine2::searchTranslation( const TQString text, int & score )
{
	GenericSearchAlgorithm strategy(di,&settings);
	strategy.setMaxResultNumber(1);

	ExactSearchAlgorithm exact(di,&settings);
	AlphaSearchAlgorithm alpha(di,&settings);
	SentenceArchiveSearchAlgorithm sent(di,&settings);

	strategy.addAlgorithm(&exact);
	strategy.addAlgorithm(&alpha);
	strategy.addAlgorithm(&sent);

	QueryResult firstRes=strategy.exec(text)[0];
	score=firstRes.score();
	return firstRes.result();

}

TQString KDBSearchEngine2::fuzzyTranslation( const TQString text, int & score )
{
	GenericSearchAlgorithm strategy(di,&settings);
	strategy.setMaxResultNumber(1);
	ExactSearchAlgorithm exact(di,&settings);
	AlphaSearchAlgorithm alpha(di,&settings);
	SentenceArchiveSearchAlgorithm sent(di,&settings);
	ChunkByChunkSearchAlgorithm sbys(di,&settings);
	ChunkByChunkSearchAlgorithm wbyw(di,&settings);
	FuzzyChunkSearchAlgorithm fs(di,&settings);
	FuzzyChunkSearchAlgorithm fw(di,&settings);

	SentenceChunkFactory sf(di);
	sbys.setChunkFactory(&sf);
	fs.setChunkFactory(&sf);


	WordChunkFactory wf(di);
	wbyw.setChunkFactory(&wf);
	fw.setChunkFactory(&wf);

	strategy.addAlgorithm(&exact);
	strategy.addAlgorithm(&alpha);
	strategy.addAlgorithm(&sent);
	strategy.addAlgorithm(&sbys);
	//strategy.addAlgorithm(&fs);
	strategy.addAlgorithm(&fw);
	strategy.addAlgorithm(&wbyw);


	QueryResult firstRes=strategy.exec(text)[0];
	score=firstRes.score();
	return firstRes.result();


}

//FIXME: ProgressBasr, progressbar,progressbasr
#include "KDBSearchEngine2.moc"