summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabel/kbabelview.h
blob: 205f34a845d69b619e2e7b767c14a571ae12152d (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
/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 1999-2000 by Matthias Kiefer
                            <matthias.kiefer@gmx.de>
		2002-2005  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.

**************************************************************************** */
#ifndef KBABELVIEW_H
#define KBABELVIEW_H

class HidingMsgEdit;
class MsgMultiLineEdit;
class GotoDialog;
class TQPopupMenu;
class KLed;
class FindDialog;
class ReplaceDialog;

namespace KBabel
{
    class EditCommand;
    class RegExpExtractor;
    class FindOptions;
    class ReplaceOptions;
}

class TQListBoxItem;
class TQTextView;
class TQTabWidget;
class KListBox;
class KSpell;
class KSpellConfig;
class KBabelDictBox;
class KDataToolInfo;
struct ReplaceOptions;
struct ModuleInfo;

#include <kdockwidget.h>
#include <kurl.h>
#include <tdeconfig.h>
#include <tqwidget.h>
#include <tqstrlist.h>
#include <resources.h>

#include <catalogview.h>
#include "kbcatalog.h"
#include "kbproject.h"
#include "projectsettings.h"

class KBabelMW;
class CommentView;
class ContextView;
class KBCatalogListView;
class CharacterSelectorView;
class SourceView;
class TagListView;

/**
 * This is the main view class for KBabel.  Most of the non-menu,
 * non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
 * here.
 * @short Main view
 * @author Matthias Kiefer <matthias.kiefer@gmx.de>
 * @version 0.1
 */
class KBabelView : public TQWidget, public KBabel::CatalogView
{
    Q_OBJECT
  
public:
    /**
    * Default constructor
    * @param buildLeds flag, if status leds should be created in editor
    */
    KBabelView(KBCatalog* catalog,KBabelMW *parent, KBabel::Project::Ptr project);

    /**
    * Destructor
    */
    virtual ~KBabelView();

    /**
     * @return the view, that has opened file url or 0 if this
     * file is not opened
     */
    static KBabelView *viewForURL(const KURL& url, const TQString project);

    /**
     * @return the view, that has no opened file url or 0 if there
     * is no such view
     */
    static KBabelView *emptyView(const TQString project);

    KURL currentURL() const;
    TQString project() const { return _project->filename(); }
    void useProject (KBabel::Project::Ptr project);
    
    bool isLastView() const;
    bool isModified() const;
    /** the edit mode of the entry-editors*/
    bool isOverwriteMode() const;
    bool isReadOnly() const;
    /** the edit mode of the entry-editors*/
    void setOverwriteMode(bool ovr);
    bool isSearching() const;

    void saveView(TDEConfig *config);
    void restoreView(TDEConfig *config);
    void saveSession(TDEConfig*);
    void restoreSession(TDEConfig*);

    void readSettings(TDEConfig* config);
    void saveSettings();

    void readProject(KBabel::Project::Ptr project);
    void saveProject(TDEConfig* config);

    void openTemplate(const KURL& openURL, const KURL& saveURL);
    bool saveFile(bool checkSyntax=true);
    bool saveFileAs(KURL url = KURL(), bool checkSyntax=true);
    bool saveFileSpecial();

    /**
    * Checks, if the file has been modified. If true, it askes the user if he wants
    * to save, discard or cancel. If the users chose save, it saves the file.
    * @return true, if it is allowed to open a new file. false, if the user wants
    * to edit the file again.
    */
    bool checkModified();


    /**
    * Checks syntax of the current catalog. If the catalog is modified it
    * saves it under a temporary filename ( using @ref Catalog::saveTempFile ).
    *
    * @param msgOnlyAtError flag, if a message should be shown, only if
    * a error occured.
    * @param question flag, if only a information about the result should
    * be shown or a question, whether the user wants to continue or cancel
    *
    * @return true, if no error occured or if an error occured but the user
    * wants to continue anyway.
    */
    bool checkSyntax(bool msgOnlyAtError, bool question);

    /**
    * this is called from the catalog when updating his views.
    * reimplemented from @ref CatalogView
    * @param cmd the edit command that has been applied
    */
    virtual void update(KBabel::EditCommand* cmd, bool undo=false);

    KBCatalog* catalog() const{return _catalog;}

    void processUriDrop(KURL::List& uriList, const TQPoint & pos);

   /**
   * checks the status of the displayed entry: last, first, fuzzy,...
   * and emits the appropriate signals
   */
   void emitEntryState();

   void setRMBEditMenu(TQPopupMenu*);
   void setRMBSearchMenu(TQPopupMenu*);
   void setTagsMenu(TQPopupMenu*);
   void setArgsMenu(TQPopupMenu*);

   TQPtrList<ModuleInfo> dictionaries();
   KBabelDictBox* searchView() { return dictBox; }

   bool autoDiffEnabled() const {return _diffEnabled;}

public slots:
   
   void gotoEntry(const KBabel::DocPosition& pos, bool updateHistory=true);

    /** opens a filedialog and asks for an url */
    void open();
    void open(const KURL& url, const TQString & package=TQString(), bool checkModified=true, bool newView=false);
    void setFilePackage();
    void revertToSaved();

    void updateSettings();
    void updateProjectSettings();

    void undo();
    void redo();
    void textCut();
    void textCopy();
    void textPaste();
    bool findNext();
    bool findPrev();
    void find();
    void findInFile(TQCString fileSource, KBabel::FindOptions options);
    void replaceInFile(TQCString fileSource, KBabel::ReplaceOptions options);
    void replace();
    void selectAll();
    void deselectAll();
    void clear();
    void msgid2msgstr();
    void search2msgstr();
    void plural2msgstr();
    void gotoFirst();
    void gotoLast();
    void gotoNext();
    void gotoPrev();
    void gotoEntry();
    void gotoNextFuzzyOrUntrans();
    void gotoPrevFuzzyOrUntrans();
    void gotoNextFuzzy();
    void gotoPrevFuzzy();
    void gotoNextUntranslated();
    void gotoPrevUntranslated();
    void gotoNextError();
    void gotoPrevError();

    void forwardHistory();
    void backHistory();

    void spellcheckAll();
    void spellcheckAllMulti();
    void spellcheckFromCursor();
    void spellcheckCurrent();
    void spellcheckFromCurrent();
    void spellcheckMarked();
    void spellcheckCommon();

    void roughTranslation();
    void diff();
    void toggleAutoDiff(bool on);
    void diffShowOrig();
    bool openDiffFile();
    void insertNextTag();
    void insertNextTagMsgid();
    void insertNextArg();
    void insertTagFromTool( const TQString& tag );
    void showTagsMenu();
    void showArgsMenu();
    void skipToNextTag();
    void skipToPreviousTag();
    void skipToTagFromTool(int index);
    void wordCount();

    void removeFuzzyStatus();
    /** opens the header editor for the po-file */
    void editHeader();

    /** checks the syntax of the file by using msgftm */
    bool checkSyntax();

    /**
     * perform all checks listed above
     */
    bool checkAll();

    void stopSearch();
    void startSearch();
    void startSelectionSearch();
    void startSearch(const TQString id);
    void startSelectionSearch(const TQString id);

    void configureDictionary(const TQString id);
    void editDictionary(const TQString id);
    void aboutDictionary(const TQString id);

    /** 
     * this was originally protected, but we need this to expose for
     * KBabelMW forwarding
     */
    virtual void wheelEvent(TQWheelEvent*);
    
protected:
    virtual void dragEnterEvent(TQDragEnterEvent *event);
    virtual void dropEvent(TQDropEvent *event);
    virtual bool eventFilter(TQObject*, TQEvent* event);

signals:
    /** emited when a fuzzy catalogentry is shown */
    void signalFuzzyDisplayed(bool);
    /** emited when a untranslated catalogentry is shown */
    void signalUntranslatedDisplayed(bool);
    void signalFaultyDisplayed(bool);
    /** emited when the first catalogentry is shown */
    void signalFirstDisplayed(bool firstEntry, bool firstForm);
    /** emited when the last catalog entry is shown */
    void signalLastDisplayed(bool lastEntry, bool lastForm);
    
    void signalNextTag( int index );
    
    /**
    * emited when a new entry is shown
    * pos: position (index and plural form) of the currently shown entry
    */
    void signalDisplayed(const KBabel::DocPosition& pos);

    /**
    * emited when new entry is displayed and there is no
    * fuzzy entry afterwards in the catalog
    */
    void signalFuzzyAfterwards(bool);
    /**
    * emited when new entry is displayed and there is no
    * fuzzy entry in front of it in the catalog
    */
    void signalFuzzyInFront(bool);
    /**
    * emited when new entry is displayed and there is no
    * untranslated entry afterwards in the catalog
    */
    void signalUntranslatedAfterwards(bool);
    /**
    * emited when new entry is displayed and there is no
    * fuzzy entry in fornt of it in the catalog
    */
    void signalUntranslatedInFront(bool);

    void signalErrorAfterwards(bool);
    void signalErrorInFront(bool);

    /**
     * Use this signal to change the content of the statusbar
     */
    void signalChangeStatusbar(const TQString& text);
    /**
     * Use this signal to change the content of the caption
     */
    void signalChangeCaption(const TQString& text);

    void signalNewFileOpened(KURL url);

    void signalResetProgressBar(TQString,int);
    void signalProgress(int);
    void signalClearProgressBar();

    void signalSearchActive(bool);

    void signalDiffEnabled(bool);

    void signalForwardHistory(bool have);
    void signalBackHistory(bool have);

    void ledColorChanged(const TQColor& color);

    void signalDictionariesChanged();

    void signalMsgstrChanged();

    void signalNextTagAvailable(bool);
    void signalTagsAvailable(bool);

    void signalNextArgAvailable(bool);
    void signalArgsAvailable(bool);

    void signalCursorPosChanged(int line, int col);

    void signalSpellcheckDone(int result);

    void signalCopy();
    void signalCut();
    void signalPaste();
    void signalSelectAll();

private:
   /**
   * inserts the content of the current catalog entry into
   * the fields in the view
   * @param delay flag, if the auto search should be started delayed
   * this is useful when a new file is opened
   * @param formID number of the plural form to be displayed. Use 0 for
   * no plural form
   */
   void updateEditor(int formID=0, bool delay=false);

   void initDockWidgets();
   
   void startSearch(bool delay);

   /**
    * makes some checks like checkings arguments and accels etc
    * @param onlyWhenChanged flag, if message should only be shown
    * when status changed
    */
   void autoCheck(bool onlyWhenChanged);

   /**
    * Create instances of tools currently setup for autochecks
    */
   void setupAutoCheckTools();

   /**
    * internal function to find next string given with @ref FindDialog
    * starting at position pos
    * @return true, if search was successful
    */
   bool findNext_internal(KBabel::DocPosition& pos, bool forReplace=false, bool mark=true);
   /**
    * internal function to find previous string given with @ref FindDialog
    * starting at position pos
    * @return true, if search was successful
    */
   bool findPrev_internal(KBabel::DocPosition& pos, bool forReplace=false, bool mark=true);

   /**
    * makes the real work
    * @param autoDiff flag, if called from @ref autoDiff()
    */
   void diffInternal(bool autoDiff);

   /**
    * @param autoDiff flag, if called from @ref autoDiff()
    */
   bool openDiffFile(bool autoDiff);

   /**
    * Inserts a text into the msgstr (into the current form) using undoable commands.
    * if @param clearFirst is set to true, it will clear the contents of msgstr before inserting
    */
   void modifyMsgstrText(const uint offset, const TQString& text, bool clearFirst=false);

protected slots:
   bool validateUsingTool( const KDataToolInfo & info, const TQString & command );
   void modifyUsingTool( const KDataToolInfo & info, const TQString & command );
   void modifyCatalogUsingTool( const KDataToolInfo & info, const TQString & command );

private slots:
   void msgstrPluralFormChanged (uint index);
   void autoRemoveFuzzyStatus();

   /** connected to the catalog. it is called when a new file is opened*/
   void newFileOpened(bool readOnly);

   void showError(const TQString& message);

   void toggleFuzzyLed(bool on);
   void toggleUntransLed(bool on);
   void toggleErrorLed(bool on);

   void forwardMsgstrEditCmd(KBabel::EditCommand*);

   /**
   * called from a signal from ReplaceDialog to replace the
   * current found string. After that it searches the next string
   */
   void replaceNext();
   /**
   * called from a signal from ReplaceDialog to replace
   * all without asking anymore.
   */
   void replaceAll();
   /**
   * called from a signal from ReplaceDialog to go to next
   * string to replace
   */
   void findNextReplace();

   /**
   * makes some checks like checkings arguments and accels etc
   */
   void autoCheck();

   void autoDiff();

   /**
    * called, when text in msgstrEdit changes to inform
    * the dictionary about the changes
    */
   void informDictionary();
   void setNewLanguage();

   void forwardProgressStart(const TQString& msg);
   void forwardSearchStart();
   void forwardSearchStop();

   /**
    * checks if there is are fuzzy entries in front or behind
    * the current entry and emits the appropriate signals
    */
   void checkFuzzies();
   /**
    * checks if there is are untranslated entries in front or behind
    * the current entry and emits the appropriate signals
    */
   void checkUntranslated();

   /** inserts the nth tag from the available tags into msgstr*/
   void insertTag(int n);

   /** visually display the tag to be inserted next */
   void selectTag();

   void updateTags();

   /** inserts the nth argument from the available arguments into msgstr*/
   void insertArg(int n);

   void updateArgs();
   void insertChar(TQChar ch);

   void showTryLaterMessageBox();

   void dummy(KSpell*) {}

private:
   static TQPtrList<KBabelView> *viewList;

   HidingMsgEdit* msgstrEdit;
   HidingMsgEdit* msgidLabel;
   KBabelDictBox* dictBox;
   GotoDialog* _gotoDialog;
   FindDialog* _findDialog;
   FindDialog* _replaceDialog;
   ReplaceDialog* _replaceAskDialog;

   TQPopupMenu* _dropMenu;

   KLed* _fuzzyLed;
   KLed* _untransLed;
   KLed* _errorLed;

   KBCatalog* _catalog;
   uint _currentIndex;
   KBabel::DocPosition _currentPos;

   KBabel::SpellcheckSettings _spellcheckSettings;

   bool _autoSearchTempDisabled;

   TQValueList<uint> _backHistory;
   TQValueList<uint> _forwardHistory;

   // flag to not beep, when switching to the next entry, because
   // go -> next or prev entry was used.
   bool _dontBeep;

   /**
   * position in document were find or replace function
   * started to search
   */
   KBabel::DocPosition _findStartPos;
   /**
   * the string that was marked during the last search
   */
   TQString _lastFoundString;

   /*
   * flag, if internal find functions should break at end or ask for
   * beginning at the other end of the document
   */
   bool _findBreakAtEnd;

   /*
   * flag, if we search backwards and the direction was already
   * changed (see findNext and findPrev)
   */   
   bool _redirectedBackSearch;

   bool _showTryLaterBox;

   KBabel::DocPosition _replacePos;
   int _replaceLen;
   int _replacesTotal;
   bool _replaceWasAtEnd;
   /** contains the diff to the offset, where we started to search */
   int _replaceExtraOffset;

   /** appId for a source of the next files to be searched */
   TQCString _fileSource;

   TQStringList _tags;
   TQPopupMenu *_tagsMenu;

   TQStringList _args;
   TQPopupMenu *_argsMenu;

   bool _diffEnabled;
   bool _loadingDiffFile;
   bool _diffing;

   /*
    * flag, set if editing KDE documentation PO-file
    */
   bool _editingDocumentation;
   TQPtrList<KDataTool> _autocheckTools;

//spellcheck things
private:
   struct Position
   {
      uint index;
      uint form;
      uint pos;
      uint end;
   };

   enum SpellWhat{All,AllMulti,Current,Marked,Begin,End,BeginCurrent};

   struct
   {
      KSpell *tdespell;
      KSpellConfig* config;
      TQStringList wordList;
      bool active;
      int misspelled;
      int replaced;
      int posCorrection;
      uint lastIndex;
      TQPtrList<Position> posDict;
      SpellWhat what2Check;

      // the last word, that was misspelled
      uint lastPos;
      // the position correction in the last word.
      // needed if words with '-' are treated as seperate words
      int inWordCorrection;

      TQStringList origWords;
      TQStringList newWords;

      TQStringList ignoreList;
      TQStringList newIgnoreList;
   } spell;

    struct {
        KSpell *tdespell;
        KSpellConfig* config;
    } spell2;                   // on-the-fly spellchecking

    //DictSpellChecker * flyspell;


   /**
    * Marks a misspelled word in the editor.
    * After that, the cursor is at the beginning of the
    * marked text
    * @param orig the original word as given from KSpell
    * @param pos the position of the word in the StringList
    * spell.wordList
    *
    * @returns false, if the there is a synchronization error,
    * means the word has not been found in the editor.
    */
   bool markMisspelled(const TQString &orig, unsigned int pos);

private slots:
   void spellcheck();
   void cancelSpellcheck();
   void spellStart(KSpell*);
   void spellMisspelled(const TQString &orig, const TQStringList &sug, unsigned int pos);
   void spellCorrected(const TQString &orig, const TQString &newWord, unsigned int pos);
   void spellResult(bool);
   void spellCleanDone();
   void spellAddIgnore(const TQString &);
   // initialize spellchecking struct
   void cleanUpSpellStruct();
   void slotAutoSaveTimeout( );

private:
   void addSpellcheckWords(uint pos, TQString text, uint index, uint form);

private:
   // configuration file
   KSharedConfig::Ptr _config;
   // project file
   KBabel::Project::Ptr _project;
   
   KBabel::RegExpExtractor* _tagExtractor;
   KBabel::RegExpExtractor* _argExtractor;

   TQTimer * autoSaveTimer;
   int _autoSaveDelay;

   int _currentTag;
   
   KBabelMW* m_mainwindow;
   CommentView* m_commentview;
   ContextView* m_contextview;
   KBCatalogListView* m_cataloglistview;
   
   CharacterSelectorView* m_charselectorview;
   TagListView* m_taglistview;
   SourceView* m_sourceview;
   
   bool m_overwrite;
};

#endif // KBABELVIEW_H