summaryrefslogtreecommitdiffstats
path: root/kbabel/catalogmanager/catalogmanagerview.h
blob: 1743ce739d440e5d8e5729387f3e7c1b9f32752f (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
/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 1999-2000 by Matthias Kiefer
                            <[email protected]>
                2001-2004 by Stanislav Visnovsky <[email protected]>
  Copyright (C) 2005, 2006 by Nicolas GOUTTE <[email protected]>

  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 CATALOGMANAGERVIEW_H
#define CATALOGMANAGERVIEW_H

#include <tqdict.h>
#include <tqlistview.h>
#include <tqdatetime.h>
#include <tqtimer.h>
#include <tqfileinfo.h>
#include <tqguardedptr.h>

#include <kdialogbase.h>
#include <kdirwatch.h>
#include <kprocess.h>
#include <tqptrlist.h>

#include "kbproject.h"
#include "projectsettings.h"
#include "findoptions.h"
#include "cvsresources.h"
#include "svnresources.h"

class CatManListItem;
class TQPixmap;
class TQPopupMenu;
class KBabelDictBox;
class CatManPreferences;
class TQTextEdit;
class KProgress;
class TDEConfig;
class KDataToolInfo;
class ValidateProgressDialog;
class CVSHandler;
class SVNHandler;
class MarkPatternDialog;
class ValidationOptions;

namespace KBabel
{
    class KBabelMailer;
    class PoInfo;
}

class CatalogManagerView : public TQListView
{
   Q_OBJECT
  
public:
   CatalogManagerView(KBabel::Project::Ptr project, TQWidget* parent=0, const char* name=0);
   virtual ~CatalogManagerView();

   KBabel::CatManSettings settings() const;
   /** clears the tree */
   virtual void clear();

   /** pauses the update timer */
   void pause(bool);

   /** if file fileWithPath exists in the treeview, this is updated */
   void updateFile(TQString fileWithPath, bool force = false);

   void updateAfterSave(TQString fileWithPath, KBabel::PoInfo &info);

   bool isActive() const {return _active;}
   bool isStopped() const {return _stop;}

   void restoreView(TDEConfig *config);
   void saveView(TDEConfig *config) const;

   void setRMBMenuFile( TQPopupMenu *m);
   void setRMBMenuDir( TQPopupMenu *m);
   void setDirCommandsMenu( TQPopupMenu *m);
   void setFileCommandsMenu( TQPopupMenu *m);

   CVSHandler * cvsHandler();
   SVNHandler * svnHandler();

public slots:
   void setSettings(KBabel::CatManSettings newSettings);
   void toggleMark();
   /**
   * removes all marks in directory of current item (must be a directory)
   */
   void slotClearMarksInDir();
   void clearAllMarks();
   void toggleAllMarks();
   void markModifiedFiles();
   void loadMarks();
   void saveMarks();
   void slotMarkPattern( );
   void slotUnmarkPattern( );
   /**
   * traverses all childs in the directory of the current item
   * (including all subdirectories) and displays some statistics
   * about the translations. If the item is a file, its
   * parent directory is used instead.
   */
   void statistics();
   /**
   * traverses all marked childs in the directory of the current item
   * (including all subdirectories) and displays some statistics
   * about the translations. If the item is a file, its
   * parent directory is used instead.
   */
   void markedStatistics();
   /**
	* calls @ref Msgfmt::checkSyntax, to check the po-file of
	* the selected item
	*/
   void checkSyntax();

   void roughTranslation();
   void markedRoughTranslation();

   /** Send the selected item as a compressed mail attachment. If the
    *  selected item is a directory send the items contained in the
    *  directory.
    */
   void mailFiles();
   /** Send the marked items as a compressed mail attachment.
    */
   void mailMarkedFiles();

   void packageFiles();
   void packageMarkedFiles();

   void cvsUpdate( );
   void cvsUpdateMarked( );
   void cvsCommit( );
   void cvsCommitMarked( );
   void cvsStatus( );
   void cvsStatusMarked( );
   void cvsUpdateTemplate( );
   void cvsUpdateMarkedTemplate( );
   void cvsCommitTemplate( );
   void cvsCommitMarkedTemplate( );
   void cvsDiff( );

   void svnUpdate( );
   void svnUpdateMarked( );
   void svnCommit( );
   void svnCommitMarked( );
   void svnStatusRemote();
   void svnStatusRemoteMarked();
   void svnStatusLocal();
   void svnStatusLocalMarked();
   void svnUpdateTemplate( );
   void svnUpdateMarkedTemplate( );
   void svnCommitTemplate( );
   void svnCommitMarkedTemplate( );
   void svnDiff( );
   void svnInfo();
   void svnInfoMarked();

   TQString find(KBabel::FindOptions &options, TQStringList &rest);

   void showLog();

   void stop(bool s = true);

   /**
   * Stop searching, do not try to proceed to the next file
   * @ref @find will return clear list of rest to be searched
   * and @ref TQString(), if search string was not is the last searched file
   */
   void stopSearch();

   /**
   * Information for this file has been read. If the file is in
   * @ref @_readInfoFileList, it will update progress bar by emitting @ref @progress
   */
   void fileInfoRead( TQString file );

   void gotoNextUntranslated();
   void gotoPreviousUntranslated();
   void gotoNextFuzzy();
   void gotoPreviousFuzzy();
   void gotoNextFuzzyOrUntranslated();
   void gotoPreviousFuzzyOrUntranslated();
   void gotoNextError();
   void gotoPreviousError();
   void gotoNextTemplate();
   void gotoPreviousTemplate();
   void gotoNextPo();
   void gotoPreviousPo();
   void gotoNextMarked();
   void gotoPreviousMarked();

   void validateUsingTool( const KDataToolInfo &, const TQString& );
   void validateMarkedUsingTool( const KDataToolInfo &, const TQString& );

   void showError( const TQString package, const int num);

   void updateCurrent();

   /**
    * An update for more than one file has become necessary. For instance
    * after 'cvs commit' or 'svn commit' the file contents have not changed
    * but the CVS/SVN file status could have changed.
    */
   void updateFiles( const TQStringList& files );

   /**
   * Returns the list of all currently selected files. If current selection is dir,
   * it returns list of all its children.
   */
   TQStringList current();
   /**
   * Returns the list of all currently marked files.
   */
   TQStringList marked();

signals:
   void openFile(TQString filename,TQString package);
   void openFileInNewWindow(TQString filename,TQString package);
   void openTemplate(TQString openFilename,TQString saveFileName,TQString package);
   void openTemplateInNewWindow(TQString openFilename,TQString saveFileName,TQString package);
   void gotoFileEntry(TQString filename,TQString package,int msgid);
   void prepareProgressBar(TQString msg,int max);
   void progress(int);
   void clearProgressBar();
   void prepareFindProgressBar(int max);
   void signalBuildTree(bool done);
   void signalSearchedFile(int count);

   void newValidationFile(TQString);
   void newValidationTool(TQString);
   void setValidationProgressBar(int);
   void advanceValidationFileProgressBar(int);
   void setMaxValidationProgressBar(int);
   void setMaxValidationFileProgressBar(int);

   /**
    * The selected item in the tree view has changed.
    * This signal emits the corresponding action value for this item.
    * @param actionValue Action value for the selected item.
    */
   void selectedChanged(uint actionValue);

signals:
   void updateFinished();

protected:
   /**
   * builds the tree under dir relDir, but does not update any files
   * this functions always traverses all subdirs
   *
   * @param relDir the relative dir under the po- and pot- base directories
   * @param fast if true, no files will be updated
   *
   * @return true, if the directory contains any po or pot-files
   * @see CatalogManagerView::buildDir
   * @see CatalogManagerView::updateDir
   */
   bool buildDir(TQString relDir,bool fast=true);

   /**
   * This function is traversing the real directory on the
   * disc using baseDir as the
   * base directory and starts at baseDir+relDir
   * @param extension the extension of the files in this directory
   * @param fast if true, no file will be updated
   *
   * @return true, if the directory contains any po or pot-files
   * @see CatalogManagerView::buildDir
   * @see CatalogManagerView::updateDir
   */
   bool buildDir(const TQString& baseDir,const TQString& relDir, const TQString extension,bool fast=true);

   /**
   * updates dir relDir and if any new subdir is added
   * builds this with @ref buildDir
   *
   * This function doesn't enters subdirs except when a new subdir is added.
   * @see CatalogManagerView::buildDir
   */
   void updateDir(TQString relDir);

   /**
   * stops the update timer and the dirwatch
   * @see KDirWatch::stop
   * @see TQTimer::stop
   */
   virtual void hideEvent(TQHideEvent*);
   /**
   * restarts the update timer and the dirwatch
   * @see KDirWatch::start
   * @see TQTimer::start
   */
   virtual void showEvent(TQShowEvent*);

   /** used for dragging */
   virtual void contentsMousePressEvent(TQMouseEvent* e);
   /** used for dragging */
   virtual void contentsMouseMoveEvent(TQMouseEvent* e);

   void showStatistics( CatManListItem *i, TQStringList &packages);

protected slots:
   /** rebuilds the tree*/
   void buildTree();
   /**
   * recurse all visible files and updates them if necessary
   * @see CatManListItem::checkUpdate
   */
   void checkUpdate();

   /** this is called from KDirWatch when a directory has changed */
   void directoryChanged(const TQString& dir);
   /** this is called from KDirWatch when a directory has been deleted */
   void directoryDeleted(const TQString& dir);

   void showContentsMenu(TQListViewItem *, const TQPoint &, int col);
   /** does the default action on the currently selected item*/
   void activateItem(TQListViewItem *);
   /** emits the state of the selected item using selectedChanged*/
   void checkSelected();
   /** calls @ref activateItem with the selected item as argument*/
   void slotOpenFile();
   void slotOpenFileInNewWindow();
   /** emits signal @ref openTemplate */
   void slotOpenTemplate();
   /** deletes the po-file on the disc, that belongs to the selected item */
   void slotDeleteFile();
   /** toggles the mark of the selected item */
   void slotToggleMark();
   /**
   * toggles all marks in directory of current item (must be a directory)
   */
   void slotToggleMarksInDir();
   void slotDirCommand(int);
   void slotFileCommand(int);

private slots:
   void showOutput(TDEProcess *proc, char *buffer, int buflen);
   void processEnded(TDEProcess *proc);
   void columnClicked(TQListViewItem * item, const TQPoint & pnt, int c);

   void slotToggleCVSOrSVNColumn( bool );

   void slotValidPOCVSRepository( bool );
   void slotValidPOSVNRepository( bool );
   void slotValidPOTCVSRepository( bool );
   void slotValidPOTSVNRepository( bool );

private:
   void toggleColumn( uint id, bool show);

   void readMarker(TDEConfig *config);
   void saveMarker(TDEConfig *config) const;
   /**
   * remove marked entries, which are not in the current file list
   */
   void updateMarkerList();

   /**
    * Mark or unmark entries.
    *
    * @param mark If true the items are marked, if false the marks are removed.
    */
   void setPatternMarks(bool mark);

   /**
	* deletes item with package name (relative directory) relDir
	* and makes sure, that all subitems are removed from the lists
	*/
   void deleteDirItem(TQString relDir);

   bool hasMatchingWords( TQStringList &itemWords, TQStringList &searchWords);

   CatManListItem *itemBelow( CatManListItem *item );
   CatManListItem *itemAbove( CatManListItem *item );

   void validate_internal( const TQStringList&, const KDataToolInfo &, const TQString& );

   void doCVSCommand( CVS::Command cmd, bool marked = false, bool templates = false );
   void doSVNCommand( SVN::Command cmd, bool marked = false, bool templates = false );

private:
   TQDict<CatManListItem> _dirList;
   TQDict<CatManListItem> _fileList;

   KDirWatch *_dirWatch;
   TQTimer *_updateTimer;

   // list of files for which was calculated the progress bar for reading file info
   TQStringList _readInfoFileList;
   // current count of already read files in @ref @_readInfoFileList.
   int _readInfoCount;

   KBabel::CatManSettings _settings;

   TQStringList _markerList;

   bool _active;
   // stopping, application quit
   bool _stop;
   // stop searching, do not proceed to the next file
   bool _stopSearch;
   int _updateNesting;

   TQPtrList<TDEProcess> _pendingProcesses;

   TQTextEdit* _logView;
   KDialogBase* _logWindow;
   TQPopupMenu* _fileContentsMenu;
   TQPopupMenu* _dirContentsMenu;
   TQPopupMenu* _dirCommandsMenu;
   TQPopupMenu* _fileCommandsMenu;

   /** used for starting a drag */
   TQPoint _pressPos;

   KBabelDictBox* _dictBox;

   KBabel::KBabelMailer* mailer;

   CVSHandler* cvshandler;
   SVNHandler* svnhandler;

   /// Is the PO path a valid CVS repository?
   bool m_validPOCVSRepository;
   /// Is the POT path a valid CVS repository?
   bool m_validPOTCVSRepository;
   /// Is the PO path a valid SVN repository?
   bool m_validPOSVNRepository;
   /// Is the POT path a valid SVN repository?
   bool m_validPOTSVNRepository;

   MarkPatternDialog * markPatternDialog;

   //validation
   ValidateProgressDialog* _validateDialog;
   ValidationOptions* _validateOptions;
   KDialogBase* _validateOptionsDlg;
   bool _markAsFuzzy;
   bool _ignoreFuzzy;

   KBabel::Project::Ptr _project;
};

#endif // CATALOGMANAGERVIEW_H