1
/* ****************************************************************************
2
This file is part of KBabel
4
Copyright (C) 2002-2003 by Stanislav Visnovsky
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
In addition, as a special exception, the copyright holders give
22
permission to link the code of this program with any edition of
23
the Qt library by Trolltech AS, Norway (or with modified versions
24
of Qt that use the same license as Qt), and distribute linked
25
combinations including the two. You must obey the GNU General
26
Public License in all respects for all of the code used other than
27
Qt. If you modify this file, you may extend this exception to
28
your version of the file, but you are not obligated to do so. If
29
you do not wish to do so, delete this exception statement from
32
**************************************************************************** */
33
#include "validateprogress.h"
34
#include "validateprogresswidget.h"
35
#include "catmanlistitem.h"
36
#include "catmanresource.h"
39
#include <kdatatool.h>
41
#include <kmessagebox.h>
42
#include <kpopupmenu.h>
43
#include <kprogress.h>
44
#include <ksqueezedtextlabel.h>
49
#define ID_ERROR_OPEN 1
50
#define ID_ERROR_IGNORE 2
52
// version identification for validation ignores
53
#define IGNOREFILE_VERSION 0x00
55
ValidateProgressDialog::ValidateProgressDialog(const QString& ignoreURL, QWidget *parent,const char *name)
56
: KDialogBase(parent,name,true,i18n("Caption of dialog","Validation")
58
, _ignoreURL(ignoreURL), _tool(0), _stopped(false)
59
, _ignoreFuzzy(false), _setAsFuzzy(false)
62
_mainWidget = new ValidateProgressWidget(this);
63
setMainWidget(_mainWidget);
64
setInitialSize( QSize(400, 300) );
71
_errorMenu = new KPopupMenu(this);
72
_errorMenu->insertItem(i18n("&Open"),ID_ERROR_OPEN);
73
_errorMenu->insertItem(i18n("&Ignore"),ID_ERROR_IGNORE);
75
connect( this, SIGNAL(closeClicked()), this, SLOT(stop()));
76
connect( _mainWidget->_errorList, SIGNAL( doubleClicked(QListBoxItem *)),
77
this, SLOT( errorItemDoubleClicked(QListBoxItem *)));
79
connect( _mainWidget->_errorList, SIGNAL( contextMenuRequested(QListBoxItem *, const QPoint &)),
80
this, SLOT( showContextMenu(QListBoxItem *, const QPoint &)));
83
ValidateProgressDialog::~ValidateProgressDialog()
88
void ValidateProgressDialog::validate( const KDataToolInfo &tool, const QPtrList<CatManListItem> files )
90
if( files.isEmpty() ) return;
94
KDataTool* t = tool.createTool();
98
KMessageBox::error( this, i18n("Cannot instantiate a validation tool.\n"
99
"Please check your installation."), i18n("Validation Tool Error") );
104
_toolID = tool.service()->library();
107
_mainWidget->_errorList->clear();
108
_mainWidget->_currentTool->setText(*(tool.userCommands().at(0)));
109
_mainWidget->_overallProgress->setTotalSteps(files.count());
110
_mainWidget->_overallProgress->setValue(0);
114
QTimer::singleShot( 0, this, SLOT(validate_internal()) );
121
void ValidateProgressDialog::validate_internal()
125
uint ignorederrors=0;
127
for( CatManListItem* it=_files.first() ; it && !_stopped ; it = _files.next() )
129
_mainWidget->_currentFile->setText( it->poFile() );
133
_mainWidget->_currentFileProgress->setTotalSteps(100);
134
_mainWidget->_currentFileProgress->setValue(0);
136
it->checkErrors(_tool,_mainWidget, _ignoreFuzzy, _setAsFuzzy);
138
bool noHeader = true;
140
if( it->hasErrors() )
142
QValueList<IgnoreItem> err = it->errors();
144
for( QValueList<IgnoreItem>::Iterator errit = err.begin(); errit!=err.end() ; ++errit )
146
IgnoreItem item = (*errit);
148
QValueList<IgnoreItem>::Iterator ig;
149
for( ig = _ignores.begin() ; ig != _ignores.end() ; ++ig )
151
if( (*ig).validationTool == _toolID &&
152
(*ig).msgid == item.msgid &&
153
(*ig).msgstr == item.msgstr &&
154
(*ig).fileURL == item.fileURL ) break;
157
if( ig != _ignores.end() )
165
_mainWidget->_errorList->insertItem( ICON_ERROR, it->package() );
166
_errors.insert( it->package(), err.first() );
170
QString errortext=QString::number(item.index+1)+": " + item.msgid.first().left(50);
171
errortext.replace("\n"," ");
172
if( item.msgid.first().length() > 50 ) errortext+="...";
173
_mainWidget->_errorList->insertItem( errortext);
175
_errors.insert( errortext, item );
179
_mainWidget->_currentFileProgress->setValue(100);
181
_mainWidget->_overallProgress->advance(1);
186
KMessageBox::information(this, i18n("Validation done.\n"
188
"Checked files: %1\n"
189
"Number of errors: %2\n"
190
"Number of ignored errors: %3").arg(checked).arg(errors).arg(ignorederrors),i18n("Validation Done"));
198
void ValidateProgressDialog::stop()
203
void ValidateProgressDialog::errorItemDoubleClicked(QListBoxItem * item)
205
QString it = item->text();
208
int offset = it.find(":");
211
if( offset < -1 ) num = 0;
214
num = it.left(offset).toInt(&ok);
218
QListBoxItem* package=item;
220
while( package && !package->text().startsWith("/") ) package=package->prev();
224
kdWarning() << "Unable to find the package for the error" << endl;
228
emit errorDoubleClicked(package->text(), num-1 );
231
void ValidateProgressDialog::showContextMenu(QListBoxItem * item, const QPoint & pos)
233
// disable ignore for whole package
234
_errorMenu->setItemEnabled(ID_ERROR_IGNORE, item->pixmap()==0 );
235
int result = _errorMenu->exec(pos);
239
errorItemDoubleClicked( item );
241
case ID_ERROR_IGNORE:
242
IgnoreItem it = _errors.find(item->text()).data();
244
// if there is no pixmap, it's the whole file
245
if( !item->pixmap() )
247
it.validationTool = _toolID;
248
_ignores.append( it );
254
void ValidateProgressDialog::readIgnores()
258
QFile ignoreFile( _ignoreURL );
259
if( ignoreFile.open( IO_ReadOnly ) ) {
260
QDataStream s( &ignoreFile );
265
if( version == IGNOREFILE_VERSION ) // Only read if correct versi
269
while( !s.atEnd() ) {
271
_ignores.append(item);
278
void ValidateProgressDialog::writeIgnores()
280
QFile ignoreFile( _ignoreURL );
281
if( ignoreFile.open( IO_WriteOnly ) ) {
282
QDataStream s( &ignoreFile );
284
int version = IGNOREFILE_VERSION;
288
for( QValueList<IgnoreItem>::Iterator it = _ignores.begin(); it!=_ignores.end(); ++it)
296
QDataStream & operator<<( QDataStream & stream, const IgnoreItem & i )
298
return stream << i.fileURL
305
QDataStream & operator>>( QDataStream & stream, IgnoreItem & i ) {
306
return stream >> i.fileURL
313
#include "validateprogress.moc"