1
/* ****************************************************************************
2
This file is part of KBabel
4
Copyright (C) 1999-2000 by Matthias Kiefer
5
<matthias.kiefer@gmx.de>
6
2002-2005 by Stanislav Visnovsky
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
In addition, as a special exception, the copyright holders give
24
permission to link the code of this program with any edition of
25
the Qt library by Trolltech AS, Norway (or with modified versions
26
of Qt that use the same license as Qt), and distribute linked
27
combinations including the two. You must obey the GNU General
28
Public License in all respects for all of the code used other than
29
Qt. If you modify this file, you may extend this exception to
30
your version of the file, but you are not obligated to do so. If
31
you do not wish to do so, delete this exception statement from
34
**************************************************************************** */
39
class MsgMultiLineEdit;
49
class RegExpExtractor;
62
struct ReplaceOptions;
65
#include <kdockwidget.h>
70
#include <resources.h>
72
#include <catalogview.h>
73
#include "kbcatalog.h"
74
#include "kbproject.h"
75
#include "projectsettings.h"
80
class KBCatalogListView;
81
class CharacterSelectorView;
86
* This is the main view class for KBabel. Most of the non-menu,
87
* non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
90
* @author Matthias Kiefer <matthias.kiefer@gmx.de>
93
class KBabelView : public QWidget, public KBabel::CatalogView
99
* @param buildLeds flag, if status leds should be created in editor
101
KBabelView(KBCatalog* catalog,KBabelMW *parent, KBabel::Project::Ptr project);
106
virtual ~KBabelView();
109
* @return the view, that has opened file url or 0 if this
112
static KBabelView *viewForURL(const KURL& url, const QString project);
115
* @return the view, that has no opened file url or 0 if there
118
static KBabelView *emptyView(const QString project);
120
KURL currentURL() const;
121
QString project() const { return _project->filename(); }
122
void useProject (KBabel::Project::Ptr project);
124
bool isLastView() const;
125
bool isModified() const;
126
/** the edit mode of the entry-editors*/
127
bool isOverwriteMode() const;
128
bool isReadOnly() const;
129
/** the edit mode of the entry-editors*/
130
void setOverwriteMode(bool ovr);
131
bool isSearching() const;
133
void saveView(KConfig *config);
134
void restoreView(KConfig *config);
135
void saveSession(KConfig*);
136
void restoreSession(KConfig*);
138
void readSettings(KConfig* config);
141
void readProject(KBabel::Project::Ptr project);
142
void saveProject(KConfig* config);
144
void openTemplate(const KURL& openURL, const KURL& saveURL);
145
bool saveFile(bool checkSyntax=true);
146
bool saveFileAs(KURL url = KURL(), bool checkSyntax=true);
147
bool saveFileSpecial();
150
* Checks, if the file has been modified. If true, it askes the user if he wants
151
* to save, discard or cancel. If the users chose save, it saves the file.
152
* @return true, if it is allowed to open a new file. false, if the user wants
153
* to edit the file again.
155
bool checkModified();
159
* Checks syntax of the current catalog. If the catalog is modified it
160
* saves it under a temporary filename ( using @ref Catalog::saveTempFile ).
162
* @param msgOnlyAtError flag, if a message should be shown, only if
164
* @param question flag, if only a information about the result should
165
* be shown or a question, whether the user wants to continue or cancel
167
* @return true, if no error occured or if an error occured but the user
168
* wants to continue anyway.
170
bool checkSyntax(bool msgOnlyAtError, bool question);
173
* this is called from the catalog when updating his views.
174
* reimplemented from @ref CatalogView
175
* @param cmd the edit command that has been applied
177
virtual void update(KBabel::EditCommand* cmd, bool undo=false);
179
KBCatalog* catalog() const{return _catalog;}
181
void processUriDrop(KURL::List& uriList, const QPoint & pos);
184
* checks the status of the displayed entry: last, first, fuzzy,...
185
* and emits the appropriate signals
187
void emitEntryState();
189
void setRMBEditMenu(QPopupMenu*);
190
void setRMBSearchMenu(QPopupMenu*);
191
void setTagsMenu(QPopupMenu*);
192
void setArgsMenu(QPopupMenu*);
194
QPtrList<ModuleInfo> dictionaries();
195
KBabelDictBox* searchView() { return dictBox; }
197
bool autoDiffEnabled() const {return _diffEnabled;}
201
void gotoEntry(const KBabel::DocPosition& pos, bool updateHistory=true);
203
/** opens a filedialog and asks for an url */
205
void open(const KURL& url, const QString & package=QString::null, bool checkModified=true, bool newView=false);
206
void setFilePackage();
207
void revertToSaved();
209
void updateSettings();
210
void updateProjectSettings();
220
void findInFile(QCString fileSource, KBabel::FindOptions options);
221
void replaceInFile(QCString fileSource, KBabel::ReplaceOptions options);
227
void search2msgstr();
228
void plural2msgstr();
234
void gotoNextFuzzyOrUntrans();
235
void gotoPrevFuzzyOrUntrans();
236
void gotoNextFuzzy();
237
void gotoPrevFuzzy();
238
void gotoNextUntranslated();
239
void gotoPrevUntranslated();
240
void gotoNextError();
241
void gotoPrevError();
243
void forwardHistory();
246
void spellcheckAll();
247
void spellcheckAllMulti();
248
void spellcheckFromCursor();
249
void spellcheckCurrent();
250
void spellcheckFromCurrent();
251
void spellcheckMarked();
252
void spellcheckCommon();
254
void roughTranslation();
256
void toggleAutoDiff(bool on);
259
void insertNextTag();
260
void insertNextTagMsgid();
261
void insertNextArg();
262
void insertTagFromTool( const QString& tag );
265
void skipToNextTag();
266
void skipToPreviousTag();
267
void skipToTagFromTool(int index);
270
void removeFuzzyStatus();
271
/** opens the header editor for the po-file */
274
/** checks the syntax of the file by using msgftm */
278
* perform all checks listed above
284
void startSelectionSearch();
285
void startSearch(const QString id);
286
void startSelectionSearch(const QString id);
288
void configureDictionary(const QString id);
289
void editDictionary(const QString id);
290
void aboutDictionary(const QString id);
293
* this was originally protected, but we need this to expose for
294
* KBabelMW forwarding
296
virtual void wheelEvent(QWheelEvent*);
299
virtual void dragEnterEvent(QDragEnterEvent *event);
300
virtual void dropEvent(QDropEvent *event);
301
virtual bool eventFilter(QObject*, QEvent* event);
304
/** emited when a fuzzy catalogentry is shown */
305
void signalFuzzyDisplayed(bool);
306
/** emited when a untranslated catalogentry is shown */
307
void signalUntranslatedDisplayed(bool);
308
void signalFaultyDisplayed(bool);
309
/** emited when the first catalogentry is shown */
310
void signalFirstDisplayed(bool firstEntry, bool firstForm);
311
/** emited when the last catalog entry is shown */
312
void signalLastDisplayed(bool lastEntry, bool lastForm);
314
void signalNextTag( int index );
317
* emited when a new entry is shown
318
* pos: position (index and plural form) of the currently shown entry
320
void signalDisplayed(const KBabel::DocPosition& pos);
323
* emited when new entry is displayed and there is no
324
* fuzzy entry afterwards in the catalog
326
void signalFuzzyAfterwards(bool);
328
* emited when new entry is displayed and there is no
329
* fuzzy entry in front of it in the catalog
331
void signalFuzzyInFront(bool);
333
* emited when new entry is displayed and there is no
334
* untranslated entry afterwards in the catalog
336
void signalUntranslatedAfterwards(bool);
338
* emited when new entry is displayed and there is no
339
* fuzzy entry in fornt of it in the catalog
341
void signalUntranslatedInFront(bool);
343
void signalErrorAfterwards(bool);
344
void signalErrorInFront(bool);
347
* Use this signal to change the content of the statusbar
349
void signalChangeStatusbar(const QString& text);
351
* Use this signal to change the content of the caption
353
void signalChangeCaption(const QString& text);
355
void signalNewFileOpened(KURL url);
357
void signalResetProgressBar(QString,int);
358
void signalProgress(int);
359
void signalClearProgressBar();
361
void signalSearchActive(bool);
363
void signalDiffEnabled(bool);
365
void signalForwardHistory(bool have);
366
void signalBackHistory(bool have);
368
void ledColorChanged(const QColor& color);
370
void signalDictionariesChanged();
372
void signalMsgstrChanged();
374
void signalNextTagAvailable(bool);
375
void signalTagsAvailable(bool);
377
void signalNextArgAvailable(bool);
378
void signalArgsAvailable(bool);
380
void signalCursorPosChanged(int line, int col);
382
void signalSpellcheckDone(int result);
387
void signalSelectAll();
391
* inserts the content of the current catalog entry into
392
* the fields in the view
393
* @param delay flag, if the auto search should be started delayed
394
* this is useful when a new file is opened
395
* @param formID number of the plural form to be displayed. Use 0 for
398
void updateEditor(int formID=0, bool delay=false);
400
void initDockWidgets();
402
void startSearch(bool delay);
405
* makes some checks like checkings arguments and accels etc
406
* @param onlyWhenChanged flag, if message should only be shown
407
* when status changed
409
void autoCheck(bool onlyWhenChanged);
412
* Create instances of tools currently setup for autochecks
414
void setupAutoCheckTools();
417
* internal function to find next string given with @ref FindDialog
418
* starting at position pos
419
* @return true, if search was successful
421
bool findNext_internal(KBabel::DocPosition& pos, bool forReplace=false, bool mark=true);
423
* internal function to find previous string given with @ref FindDialog
424
* starting at position pos
425
* @return true, if search was successful
427
bool findPrev_internal(KBabel::DocPosition& pos, bool forReplace=false, bool mark=true);
430
* makes the real work
431
* @param autoDiff flag, if called from @ref autoDiff()
433
void diffInternal(bool autoDiff);
436
* @param autoDiff flag, if called from @ref autoDiff()
438
bool openDiffFile(bool autoDiff);
441
* Inserts a text into the msgstr (into the current form) using undoable commands.
442
* if @param clearFirst is set to true, it will clear the contents of msgstr before inserting
444
void modifyMsgstrText(const uint offset, const QString& text, bool clearFirst=false);
447
bool validateUsingTool( const KDataToolInfo & info, const QString & command );
448
void modifyUsingTool( const KDataToolInfo & info, const QString & command );
449
void modifyCatalogUsingTool( const KDataToolInfo & info, const QString & command );
452
void msgstrPluralFormChanged (uint index);
453
void autoRemoveFuzzyStatus();
455
/** connected to the catalog. it is called when a new file is opened*/
456
void newFileOpened(bool readOnly);
458
void showError(const QString& message);
460
void toggleFuzzyLed(bool on);
461
void toggleUntransLed(bool on);
462
void toggleErrorLed(bool on);
464
void forwardMsgstrEditCmd(KBabel::EditCommand*);
467
* called from a signal from ReplaceDialog to replace the
468
* current found string. After that it searches the next string
472
* called from a signal from ReplaceDialog to replace
473
* all without asking anymore.
477
* called from a signal from ReplaceDialog to go to next
480
void findNextReplace();
483
* makes some checks like checkings arguments and accels etc
490
* called, when text in msgstrEdit changes to inform
491
* the dictionary about the changes
493
void informDictionary();
494
void setNewLanguage();
496
void forwardProgressStart(const QString& msg);
497
void forwardSearchStart();
498
void forwardSearchStop();
501
* checks if there is are fuzzy entries in front or behind
502
* the current entry and emits the appropriate signals
506
* checks if there is are untranslated entries in front or behind
507
* the current entry and emits the appropriate signals
509
void checkUntranslated();
511
/** inserts the nth tag from the available tags into msgstr*/
512
void insertTag(int n);
514
/** visually display the tag to be inserted next */
519
/** inserts the nth argument from the available arguments into msgstr*/
520
void insertArg(int n);
523
void insertChar(QChar ch);
525
void showTryLaterMessageBox();
527
void dummy(KSpell*) {}
530
static QPtrList<KBabelView> *viewList;
532
HidingMsgEdit* msgstrEdit;
533
HidingMsgEdit* msgidLabel;
534
KBabelDictBox* dictBox;
535
GotoDialog* _gotoDialog;
536
FindDialog* _findDialog;
537
FindDialog* _replaceDialog;
538
ReplaceDialog* _replaceAskDialog;
540
QPopupMenu* _dropMenu;
548
KBabel::DocPosition _currentPos;
550
KBabel::SpellcheckSettings _spellcheckSettings;
552
bool _autoSearchTempDisabled;
554
QValueList<uint> _backHistory;
555
QValueList<uint> _forwardHistory;
557
// flag to not beep, when switching to the next entry, because
558
// go -> next or prev entry was used.
562
* position in document were find or replace function
565
KBabel::DocPosition _findStartPos;
567
* the string that was marked during the last search
569
QString _lastFoundString;
572
* flag, if internal find functions should break at end or ask for
573
* beginning at the other end of the document
575
bool _findBreakAtEnd;
578
* flag, if we search backwards and the direction was already
579
* changed (see findNext and findPrev)
581
bool _redirectedBackSearch;
583
bool _showTryLaterBox;
585
KBabel::DocPosition _replacePos;
588
bool _replaceWasAtEnd;
589
/** contains the diff to the offset, where we started to search */
590
int _replaceExtraOffset;
592
/** appId for a source of the next files to be searched */
593
QCString _fileSource;
596
QPopupMenu *_tagsMenu;
599
QPopupMenu *_argsMenu;
602
bool _loadingDiffFile;
606
* flag, set if editing KDE documentation PO-file
608
bool _editingDocumentation;
609
QPtrList<KDataTool> _autocheckTools;
621
enum SpellWhat{All,AllMulti,Current,Marked,Begin,End,BeginCurrent};
626
KSpellConfig* config;
627
QStringList wordList;
633
QPtrList<Position> posDict;
634
SpellWhat what2Check;
636
// the last word, that was misspelled
638
// the position correction in the last word.
639
// needed if words with '-' are treated as seperate words
640
int inWordCorrection;
642
QStringList origWords;
643
QStringList newWords;
645
QStringList ignoreList;
646
QStringList newIgnoreList;
651
KSpellConfig* config;
652
} spell2; // on-the-fly spellchecking
654
//DictSpellChecker * flyspell;
658
* Marks a misspelled word in the editor.
659
* After that, the cursor is at the beginning of the
661
* @param orig the original word as given from KSpell
662
* @param pos the position of the word in the StringList
665
* @returns false, if the there is a synchronization error,
666
* means the word has not been found in the editor.
668
bool markMisspelled(const QString &orig, unsigned int pos);
672
void cancelSpellcheck();
673
void spellStart(KSpell*);
674
void spellMisspelled(const QString &orig, const QStringList &sug, unsigned int pos);
675
void spellCorrected(const QString &orig, const QString &newWord, unsigned int pos);
676
void spellResult(bool);
677
void spellCleanDone();
678
void spellAddIgnore(const QString &);
679
// initialize spellchecking struct
680
void cleanUpSpellStruct();
681
void slotAutoSaveTimeout( );
684
void addSpellcheckWords(uint pos, QString text, uint index, uint form);
687
// configuration file
688
KSharedConfig::Ptr _config;
690
KBabel::Project::Ptr _project;
692
KBabel::RegExpExtractor* _tagExtractor;
693
KBabel::RegExpExtractor* _argExtractor;
695
QTimer * autoSaveTimer;
700
KBabelMW* m_mainwindow;
701
CommentView* m_commentview;
702
ContextView* m_contextview;
703
KBCatalogListView* m_cataloglistview;
705
CharacterSelectorView* m_charselectorview;
706
TagListView* m_taglistview;
707
SourceView* m_sourceview;
712
#endif // KBABELVIEW_H