summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabel/kbabelview2.cpp
blob: 5089f5635569e9c588271a5b4c2f85c27374e7e0 (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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 1999-2000 by Matthias Kiefer
                            <matthias.kiefer@gmx.de>
		2002-2004 by Stanislav Visnovsky
			    <visnovsky@kde.org>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

  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 <kdatatool.h>
#include <kdebug.h>
#include <tdefiledialog.h>
#include <kinputdialog.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <knotifyclient.h>
#include <kurl.h>
#include <tdeio/netaccess.h>

#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqmessagebox.h>
#include <tqpopupmenu.h>
#include <tqvbox.h>

#include "catalogsettings.h"
#include "editcmd.h"
#include "tagextractor.h"
#include "kbabelview.h"
#include "kbabeldictbox.h"
#include "mymultilineedit.h"
#include "hidingmsgedit.h"
#include "roughtransdlg.h"
#include "kbabelsettings.h"
#include "kbprojectsettings.h"

#include "resources.h"

using namespace KBabel;

TQPtrList<ModuleInfo> KBabelView::dictionaries()
{
   TQPtrList<ModuleInfo> list = dictBox->moduleInfos();

   return list;
}

void KBabelView::configureDictionary(const TQString id)
{
   dictBox->configure(id);
}

void KBabelView::editDictionary(const TQString id)
{
   dictBox->edit(id);
}


void KBabelView::aboutDictionary(const TQString id)
{
   dictBox->aboutModule(id);
}

void KBabelView::informDictionary()
{
    if( isSearching () )
	stopSearch ();

    if( msgstrEdit->isModified() )
	dictBox->setTextChanged(_catalog->msgid(_currentIndex,true)
	    ,*(_catalog->msgstr(_currentIndex).at(msgstrEdit->currentForm()))
	    ,msgstrEdit->currentForm()
	    ,_catalog->comment(_currentIndex));
}

void KBabelView::setNewLanguage()
{
    IdentitySettings s = _catalog->identitySettings();

    dictBox->setLanguage(s.languageCode, s.languageName);

    // setup new plural form number
    int form = msgstrEdit->currentForm();
    if( form >= s.numberOfPluralForms )
	form = s.numberOfPluralForms-1;

    msgstrEdit->setNumberOfPlurals (s.numberOfPluralForms);
    updateSettings();

    if (! _catalog->currentURL().isEmpty())
    {
	updateEditor( form );
    }
}


void KBabelView::wheelEvent(TQWheelEvent *e)
{
    if( _catalog->numberOfEntries() == 0 ) return;

    if( (e->state() & ControlButton) && (e->state() & AltButton))
    {
        if(e->delta() > 0)
        {
            gotoPrevFuzzyOrUntrans();
        }
        else
        {
            gotoNextFuzzyOrUntrans();
        }
    }
    else if(e->state() & ControlButton)
    {
        if(e->delta() > 0)
        {
            gotoPrevFuzzy();
        }
        else
        {
            gotoNextFuzzy();
        }
    }
    else if(e->state() & AltButton)
    {
        if(e->delta() > 0)
        {
            gotoPrevUntranslated();
        }
        else
        {
            gotoNextUntranslated();
        }
    }
    else
    {
        if(e->delta() > 0)
        {
            gotoPrev();
        }
        else
        {
            gotoNext();
        }
    }

    e->accept();
}



void KBabelView::roughTranslation()
{
    RoughTransDlg *dlg = new RoughTransDlg(dictBox, _catalog, this
            , "roughtransDlg");

    dlg->exec();

    delete dlg;
}


void KBabelView::updateTags()
{
    bool hadTags = _tags.count() > 0;

    _tags = _catalog->tagList(_currentIndex);

    if(_tagsMenu)
    {
        _tagsMenu->clear();

        TQStringList tList;
        TQStringList::Iterator it;
        int counter=0;
        for(it=_tags.begin(); it!=_tags.end(); ++it)
        {
	    TQString s = *it;
	    if( s.startsWith("&") ) s = "&"+s;
            if(!tList.contains(s))
            {
                _tagsMenu->insertItem(s,counter);
                tList.append(s);
            }
            counter++;
        }
    }

    bool haveTags = (_tags.count() > 0);

    if(isReadOnly())
        haveTags=false;

    if(haveTags != hadTags)
    {
        emit signalNextTagAvailable(haveTags);
        emit signalTagsAvailable(haveTags);
    }

    _currentTag = 0;

    if(haveTags)
    {
	_tagExtractor->setString(_catalog->msgid(_currentIndex).first());
    }
    // if there is no tag, it will set invalid tag
    selectTag();
}

void KBabelView::skipToNextTag()
{
    if( (uint)_currentTag >= _tags.count()-1 ) return;
    ++_currentTag;
    selectTag();
}

void KBabelView::skipToPreviousTag()
{
    if( _currentTag == 0 ) return;
    --_currentTag;
    selectTag();
}

void KBabelView::selectTag()
{
    if( _tagExtractor->countMatches() == 0 ) {
	// no tags, select none
	kdDebug() << "No tags" << endl;
	msgidLabel->selectTag(0,0);
	return;
    }

    // count number of eofs in tag
    uint diff=0;
    // FIXME: what about plural forms
    TQString msgid = _catalog->msgid(_currentIndex).first();

    for( uint i = _tagExtractor->matchIndex(_currentTag); i < _tagExtractor->matchIndex(_currentTag)+_tags[_currentTag].length()+1; i++ )
    {
	if( msgid[i] == '\n' ) diff++;
    }
    msgidLabel->selectTag(_tagExtractor->matchIndex(_currentTag),_tags[_currentTag].length()+diff);
    emit signalNextTag (_currentTag);
}

void KBabelView::setTagsMenu(TQPopupMenu *menu)
{
    _tagsMenu=menu;

    connect(_tagsMenu,TQT_SIGNAL(activated(int)),this,TQT_SLOT(insertTag(int)));
}

void KBabelView::modifyMsgstrText(const uint offset, const TQString& text, bool clearFirst)
{
    _catalog->applyBeginCommand( _currentIndex, Msgstr ,this);

    if( clearFirst ) msgstrEdit->clear();

    InsTextCmd* insCmd = new InsTextCmd(offset,text,msgstrEdit->currentForm());
    insCmd->setPart(Msgstr);
    insCmd->setIndex(_currentIndex);

    msgstrEdit->processCommand(insCmd,false);
    forwardMsgstrEditCmd(insCmd);

    _catalog->applyEndCommand(_currentIndex, Msgstr,this);

    autoCheck( true ); // check it NOW - it should not be needed, but it is, I don't know why :-(
}

void KBabelView::insertTag(int n)
{
    TQString tag = _tagsMenu->text(n);
    if( tag.startsWith( "&&" ) ) tag = tag.remove(0,1); // replace && -> &. && is used for correct menu display

    modifyMsgstrText( msgstrEdit->currentIndex(), tag );
}

void KBabelView::insertNextTag()
{
    if(_currentTag >= (int)_tags.count())
    {
	KNotifyClient::beep();
	return;
    }

    int offset = msgstrEdit->currentIndex();

    _currentTag++;
    selectTag();

    modifyMsgstrText( offset, _tags[_currentTag-1] );
}

void KBabelView::insertNextTagMsgid()
{
    TagExtractor extractor;

    int offset = msgstrEdit->beginOfLastMarkedText(); //msgstrEdit->currentIndex();

    TQString s = (*_catalog->msgstr(_currentIndex).at(msgstrEdit->currentForm())).left(offset);

    TQString t;

    if( _catalog->pluralForm( _currentIndex ) == KDESpecific )
    {
	    int pos = msgstrEdit->currentIndex();
            int currentFormBegin=s.findRev("\\n",pos);
	    if( currentFormBegin == -1 ) currentFormBegin=0;
	    else currentFormBegin+=3; // skip the newline
	    int currentFormEnd=s.find("\\n",pos);
	    if( currentFormEnd == -1 ) currentFormEnd=s.length();

	    s=s.mid(currentFormBegin,currentFormEnd-currentFormBegin);
    }

    extractor.setString(s);
    uint num= extractor.countMatches();
    if(num >= _tags.count())
    {
	KNotifyClient::beep();
	return;
    }

    t=_tags[num];

    modifyMsgstrText( offset, t );
}

void KBabelView::showTagsMenu()
{
    if(_tagsMenu && _tags.count() > 0)
    {
        int y=msgstrEdit->height()/2;
        int x=msgstrEdit->width()/2;
        _tagsMenu->exec(msgstrEdit->mapToGlobal( TQPoint(x,y) ) );

        return;
    }
}


void KBabelView::updateArgs()
{
    bool hadArgs = _args.count() > 0;

    _args = _catalog->argList(_currentIndex);

    if(_argsMenu)
    {
        _argsMenu->clear();

        TQStringList tList;
        TQStringList::Iterator it;
        int counter=0;
        for(it=_args.begin(); it!=_args.end(); ++it)
        {
	    TQString s = *it;
            if(!tList.contains(s))
            {
                _argsMenu->insertItem(s,counter);
                tList.append(s);
            }
            counter++;
        }
    }

    bool haveArgs = (_args.count() > 0);

    if(isReadOnly())
        haveArgs=false;

    if(haveArgs != hadArgs)
    {
        emit signalNextArgAvailable(haveArgs);
        emit signalArgsAvailable(haveArgs);
    }
}

void KBabelView::setArgsMenu(TQPopupMenu *menu)
{
    _argsMenu=menu;

    connect(_argsMenu,TQT_SIGNAL(activated(int)),this,TQT_SLOT(insertArg(int)));
}


void KBabelView::insertArg(int n)
{
    TQString arg = _argsMenu->text(n);

    modifyMsgstrText( msgstrEdit->currentIndex(), arg );
}

void KBabelView::insertNextArg()
{
    int offset = msgstrEdit->currentIndex();

    TQString s = (*_catalog->msgstr(_currentIndex).at(msgstrEdit->currentForm())).left(offset);

    if( _catalog->pluralForm( _currentIndex ) == KDESpecific )
    {
	int pos = msgstrEdit->currentIndex();
    	int currentFormBegin=s.findRev("\\n",pos);
	if( currentFormBegin == -1 ) currentFormBegin=0;
	else currentFormBegin+=3; // skip the newline
	int currentFormEnd=s.find("\\n",pos);
	if( currentFormEnd == -1 ) currentFormEnd=s.length();

	s=s.mid(currentFormBegin,currentFormEnd-currentFormBegin);
    }

    _argExtractor->setString(s);
    uint num=_argExtractor->countMatches();
    if(num >= _args.count())
    {
    	KNotifyClient::beep();
        return;
    }

    TQString t=_args[num];

    modifyMsgstrText( offset,t );
}

void KBabelView::showArgsMenu()
{
    if(_argsMenu && _args.count() > 0)
    {
        int y=msgstrEdit->height()/2;
        int x=msgstrEdit->width()/2;
        _argsMenu->exec(msgstrEdit->mapToGlobal( TQPoint(x,y) ) );

        return;
    }
}


void KBabelView::diff()
{
    diffInternal(false);
    msgstrEdit->setFocus();
}

void KBabelView::diffShowOrig()
{
    msgidLabel->setText(_catalog->msgid(_currentIndex));
    msgidLabel->forceUpdate();
    msgstrEdit->setFocus();
}

void KBabelView::toggleAutoDiff(bool on)
{
    if(on != _diffEnabled)
    {
        _diffEnabled = on;

        if(on)
        {
            diff();
        }
        else
        {
            diffShowOrig();
        }
    }
}

void KBabelView::autoDiff()
{
    diffInternal(true);
}

void KBabelView::diffInternal(bool autoDf)
{
    if(_diffing || _loadingDiffFile)
    {
        return;
    }

    _diffing = true;
    uint diffIndex = _currentIndex;

    TQString diffString;

    Catalog::DiffResult r = _catalog->diff(_currentIndex, &diffString);

    if(r == Catalog::DiffNeedList)
    {
	switch( _project->settings()->useDBForDiff() )
	{
	    case 1:
    	    {
        	_loadingDiffFile=true;
    		bool wasEnabled=_diffEnabled;
    	        _diffEnabled=false;

        	TQValueList<DiffEntry> diffList;
                TQString error;
	        TQString package = _catalog->packageName()+".po";
    	        kdDebug(KBABEL) << "getting list for " << package << endl;

        	if(dictBox->messagesForPackage(package,diffList,error))
        	{
                    kdDebug(KBABEL) << "got " << diffList.count()
	                << " messages" << endl;
    	            _catalog->setDiffList(diffList);
        	}
                else
	        {
    	            KMessageBox::sorry(this
        	        ,i18n("An error occurred while trying to get the list "
                        "of messages for this file from the database:\n"
                        "%1").arg(error));

            	    _diffing=false;
                    _diffEnabled=false;
	            _loadingDiffFile=false;
    	            emit signalDiffEnabled(false);

        	    return;
        	}

                _diffEnabled=wasEnabled;
	        _loadingDiffFile=false;
		break;
    	    }
	    case 0:
    	    {
        	_diffing=false;
                if(!openDiffFile(true))
	        {
    		    _diffEnabled=false;
    	             emit signalDiffEnabled(false);

            	    _diffing=false;
                    return;
	        }

    	        _diffing = true;
		break;
            }
	    case 2:
	    {
		// get the list of all entries
        	TQValueList<DiffEntry> diffList = _catalog->asDiffList();

		TQValueList<DiffEntry> resultList;

		// swap msgstr and msgid
		TQValueList<DiffEntry>::iterator it;
		DiffEntry entry;

		 for ( it = diffList.begin(); it != diffList.end(); ++it )
		 {
		    entry.msgstr = (*it).msgid;
		    // if there is no translation, do not show difference
		    if( !(*it).msgstr.isEmpty() )
		    {
			entry.msgid = (*it).msgstr;
		    }
		    else
		    {
			entry.msgid = (*it).msgid;
		    }
		    resultList.append(entry);
		 }

		// set as a source for diff
    	        _catalog->setDiffList(resultList);

            	_diffing=false;
                _diffEnabled=true;
	        _loadingDiffFile=false;
    	        emit signalDiffEnabled(true);
	    }
	}

        diffIndex = _currentIndex;
        r = _catalog->diff(_currentIndex, &diffString);
    }

    // if the index changed in the meanwhile
    while(diffIndex != _currentIndex)
    {
        diffIndex=_currentIndex;
        r = _catalog->diff(_currentIndex,&diffString);
    }

    if(r == Catalog::DiffOk)
    {
	msgidLabel->setText(diffString);
	msgidLabel->forceUpdate();

	// FIXME: should care about plural forms
        if(diffString == _catalog->msgid(_currentIndex).first() )
        {
            emit signalChangeStatusbar(i18n("No difference found"));
        }
        else
        {
            emit signalChangeStatusbar(i18n("Difference found"));
        }
    }
    else
    {
        if(!autoDf)
        {
            KMessageBox::information(this
                ,i18n("No corresponding message found."));
        }
        else
        {
            emit signalChangeStatusbar(
                    i18n("No corresponding message found"));
        }
    }

    _diffing = false;
}

bool KBabelView::openDiffFile()
{
    return openDiffFile(false);
}

bool KBabelView::openDiffFile(bool autoDiff)
{
    if(_diffing || _loadingDiffFile)
        return false;

    KURL url;

    if( autoDiff && ! _project->settings()->diffBaseDir().isEmpty() )
    {
        KURL fileURL = _catalog->currentURL();
	
	KURL poBaseURL( _project->catManSettings().poBaseDir );
	
        TQString poBase = poBaseURL.path();
        int len = poBase.length();
        if(fileURL.path().left(len) == poBase)
        {
           TQString fileRelPath = fileURL.path().mid(len);
           if(fileRelPath[0] == '/')
               fileRelPath=fileRelPath.mid(1);

           if(_project->settings()->diffBaseDir().right(1) != "/")
               _project->settings()->diffBaseDir() += '/';

           TQString diffFilePath = _project->settings()->diffBaseDir() + fileRelPath;


           KURL diffFileURL(diffFilePath);

           if(diffFileURL.isValid() && TDEIO::NetAccess::exists(diffFileURL,true,NULL))
           {
               url = diffFileURL;

               kdDebug(KBABEL) << "using file " << diffFileURL.prettyURL()
                         << " as diff file" << endl;
           }
        }
    }


    if(url.isEmpty())
    {
        url = KFileDialog::getOpenURL(_project->settings()->diffBaseDir(), 
"application/x-gettext", this, i18n("Select File to Diff With"));
    }

    if(url.isEmpty())
        return false;

    _loadingDiffFile=true;
    bool wasEnabled=_diffEnabled;
    _diffEnabled=false;


    Catalog cat;

    connect(&cat,TQT_SIGNAL(signalProgress(int)),this,TQT_SIGNAL(signalProgress(int)));
    emit signalResetProgressBar(i18n("loading file for diff"),100);

    ConversionStatus stat = cat.openURL(url);

    emit signalClearProgressBar();


    if(stat != OK && stat != RECOVERED_PARSE_ERROR)
    {
        switch(stat)
        {
            case PARSE_ERROR:
            {
                KMessageBox::sorry(this
                    ,i18n("Error while trying to read file:\n %1\n"
                   "Maybe it is not a valid PO file.").arg(url.prettyURL()));
                break;
            }
            case NO_PERMISSIONS:
            {
                KMessageBox::sorry(this,i18n(
                "You do not have permissions to read file:\n %1")
                        .arg(url.prettyURL()));
                break;
            }
            case NO_FILE:
            {
                 KMessageBox::sorry(this,i18n(
                 "You have not specified a valid file:\n %1")
                         .arg(url.prettyURL()));
                break;
            }
	    case NO_PLUGIN:
	    {
	         KMessageBox::error(this,i18n(
	              "KBabel cannot find a corresponding plugin for the MIME type of the file:\n %1").arg(url.prettyURL()));
	         break;
	    }
	    case UNSUPPORTED_TYPE:
	    {
	          KMessageBox::error(this,i18n(
	               "The import plugin cannot handle this type of the file:\n %1").arg(url.prettyURL()));
                  break;
	    }
            default:
            {
                 KMessageBox::sorry(this,i18n(
                  "Error while trying to open file:\n %1")
                         .arg(url.prettyURL()));
                 break;
            }

        }

        _diffEnabled=wasEnabled;
        _loadingDiffFile=false;

        return false;
    }

    _catalog->setDiffList( cat.asDiffList() );

    _diffEnabled=wasEnabled;
    _loadingDiffFile=false;

    return true;
}

void KBabelView::showTryLaterMessageBox()
{
    if( !_showTryLaterBox ) return;

    KDialogBase *dialog= new KDialogBase(
		i18n("Information"),
		KDialogBase::Yes,
		KDialogBase::Yes, KDialogBase::Yes,
		this, "information", true, true,
		KStdGuiItem::ok() );

    TQVBox *topcontents = new TQVBox (dialog);
    topcontents->setSpacing(KDialog::spacingHint()*2);
    topcontents->setMargin(KDialog::marginHint()*2);

    TQWidget *contents = new TQWidget(topcontents);
    TQHBoxLayout * lay = new TQHBoxLayout(contents);
    lay->setSpacing(KDialog::spacingHint()*2);

    lay->addStretch(1);
    TQLabel *label1 = new TQLabel( contents);
    label1->setPixmap(TQMessageBox::standardIcon(TQMessageBox::Information));
    lay->add( label1 );
    TQLabel *label2 = new TQLabel( i18n("The search string has not been found yet.\n"
	         "However, the string might be found "
		 "in the files being searched at the moment.\n"
		 "Please try later."), contents);
    label2->setAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::ExpandTabs | TQt::WordBreak );
    label2->setMinimumSize(label2->sizeHint());
    lay->add( label2 );
    lay->addStretch(1);

    TQCheckBox *checkbox = new TQCheckBox(i18n("Do not show in this find/replace session again"), topcontents);

    dialog->setMainWidget(topcontents);
    dialog->enableButtonSeparator(false);
    dialog->incInitialSize( TQSize(50,0) );

    dialog->exec();

    _showTryLaterBox = !checkbox->isChecked();
    delete dialog;
}

void KBabelView::setFilePackage()
{
    bool result=false;
    TQString p = KInputDialog::getText(TQString(), i18n("Enter new package for the current file:"),_catalog->package(),&result,this);
    if( result )
    {
	_catalog->setPackage(p);
	emit signalChangeCaption(p);
    }
}

void KBabelView::insertTagFromTool( const TQString& tag )
{
    modifyMsgstrText(msgstrEdit->currentIndex(),tag);

    msgstrEdit->setFocus();
}

void KBabelView::skipToTagFromTool( int index )
{
    _currentTag = index;
    selectTag();
}

void KBabelView::plural2msgstr()
{
    int currentFormBegin, currentFormEnd, pos;
    uint i;

    TQStringList msgs = _catalog->msgstr(_currentIndex);
    TQString text= *msgs.at(msgstrEdit->currentForm());
    uint numForms = _catalog->numberOfPluralForms(_currentIndex);

    if( text.isEmpty() || _catalog->pluralForm(_currentIndex) == NoPluralForm) return;


    TQString result;

    switch( _catalog->pluralForm(_currentIndex) )
    {
	case Gettext:

	    _catalog->applyBeginCommand( _currentIndex, Msgstr ,this);

	    i=0;
	    for( TQStringList::Iterator it=msgs.begin() ; it!=msgs.end() ; ++it )
	    {
		if( i!= msgstrEdit->currentForm() )
		{
		    // clear first
		    DelTextCmd* insCmd = new DelTextCmd(0,(*it),i);
		    insCmd->setPart(Msgstr);
		    insCmd->setIndex(_currentIndex);
		    msgstrEdit->processCommand(insCmd,false);
		    forwardMsgstrEditCmd(insCmd);

		    // insert text
		    insCmd = new InsTextCmd(0,text,i);
		    insCmd->setPart(Msgstr);
		    insCmd->setIndex(_currentIndex);
		    msgstrEdit->processCommand(insCmd,false);
		    forwardMsgstrEditCmd(insCmd);
		}
		i++;
	    }
	    
	    // fill the non-initialized ones
	    while (i != numForms)
	    {
		// insert text
		DelTextCmd* insCmd = new InsTextCmd(0,text,i);
		insCmd->setPart(Msgstr);
		insCmd->setIndex(_currentIndex);
		msgstrEdit->processCommand(insCmd,false);
		forwardMsgstrEditCmd(insCmd);
		i++;
	    }

	    _catalog->applyEndCommand( _currentIndex, Msgstr ,this);

	    break;

	case KDESpecific:
	    {
		pos = msgstrEdit->currentIndex();
    		currentFormBegin=text.findRev("\\n",pos);
		if( currentFormBegin == -1 ) currentFormBegin=0;
		else currentFormBegin+=3; // skip the newline
		currentFormEnd=text.find("\\n",pos);
		if( currentFormEnd == -1 ) currentFormEnd=text.length();

	        text=text.mid(currentFormBegin,currentFormEnd-currentFormBegin);

		TQString result=text;
		for( i=1; i<numForms ; i++ )
		    result+="\\n\n"+text;

		modifyMsgstrText( 0, result, true );
	    }
	    break;

	case NoPluralForm: break;
    }

}

bool KBabelView::validateUsingTool( const KDataToolInfo & info, const TQString &command )
{
    if(currentURL().isEmpty())
        return false;

    KDataTool* tool = info.createTool();
    if( !tool )
    {
	kdWarning() << "Cannot create tool" << endl;
	return false;
    }

    bool result=_catalog->checkUsingTool(tool);
    emitEntryState();

    TQString checkName = *(info.userCommands().at( info.commands().findIndex(command) ));

    if(result)
    {
	KMessageBox::information(this
	    ,i18n("No mismatch has been found.")
	    ,checkName);
    }
    else
    {
	int index=0;
	DocPosition pos;

	if(!_catalog->hasError(0,pos))
	    index = _catalog->nextError(0,pos);
	if(index>=0)
	{
	    kdDebug(KBABEL) << "Going to " << pos.item << ", " << pos.form << endl;
	    gotoEntry(pos);
	}

	KMessageBox::error(this
	    ,i18n("Some mismatches have been found.\n"
	    "Please check the questionable entries by using "
	    "Go->Next error")
	    ,checkName);
    }
    delete tool;

    return result;
}

void KBabelView::modifyUsingTool( const KDataToolInfo & info, const TQString &command )
{
    KDataTool* tool = info.createTool();
    if( !tool )
    {
	kdWarning() << "Cannot create tool" << endl;
	return;
    }

    // do some stuff on all entries
    _catalog->modifyUsingTool(tool, command);

    delete tool;
}

void KBabelView::modifyCatalogUsingTool( const KDataToolInfo & info, const TQString &command )
{
    KDataTool* tool = info.createTool();
    if( !tool )
    {
	kdWarning() << "Cannot create tool" << endl;
	return;
    }

    // do some stuff on the catalog
    tool->run(command, _catalog, "Catalog", "application/x-kbabel-catalog");

    delete tool;
}

void KBabelView::insertChar( TQChar ch )
{
    if( isReadOnly() || _catalog->package().isEmpty() )
	return;

    modifyMsgstrText(msgstrEdit->currentIndex(),ch);
    msgstrEdit->setFocus();
}

void KBabelView::wordCount()
{
    uint total, untranslated, fuzzy;
    
    _catalog->wordCount( total, fuzzy, untranslated );
    
    KMessageBox::information( this
	, i18n("Total words: %1\n\n"
"Words in untranslated messages: %2\n\n"
"Words in fuzzy messages: %3").arg(total).arg(untranslated).arg(fuzzy)
	, i18n("Word Count") );
}