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
|
/*
Copyright (C) 2002 by Roberto Raggi <roberto@kdevelop.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
version 2, License as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "problemreporter.h"
#include "javasupportpart.h"
#include "configproblemreporter.h"
#include "backgroundparser.h"
#include <kdevpartcontroller.h>
#include <kdevmainwindow.h>
#include <kdeversion.h>
#include <kparts/part.h>
#include <ktexteditor/editinterface.h>
#include <ktexteditor/document.h>
#include <ktexteditor/markinterface.h>
#include <ktexteditor/markinterfaceextension.h>
#include <ktexteditor/view.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstatusbar.h>
#include <kurl.h>
#include <kapplication.h>
#include <kiconloader.h>
#include <kdialogbase.h>
#include <kconfig.h>
#include <qtimer.h>
#include <qregexp.h>
#include <qvbox.h>
#include <qfileinfo.h>
#include <qwhatsthis.h>
#include <qgroupbox.h>
class ProblemItem: public KListViewItem
{
public:
ProblemItem( QListView* parent, const QString& level, const QString& problem,
const QString& file, const QString& line, const QString& column )
: KListViewItem( parent, level, problem, file, line, column ) {}
ProblemItem( QListViewItem* parent, const QString& level, const QString& problem,
const QString& file, const QString& line, const QString& column )
: KListViewItem( parent, level, problem, file, line, column ) {}
int compare( QListViewItem* item, int column, bool ascending ) const {
if( column == 2 || column == 3 ){
int a = text( column ).toInt();
int b = item->text( column ).toInt();
if( a == b )
return 0;
return( a > b ? 1 : -1 );
}
return KListViewItem::compare( item, column, ascending );
}
};
ProblemReporter::ProblemReporter( JavaSupportPart* part, QWidget* parent, const char* name )
: KListView( parent, name ? name : "problemreporter" ),
m_javaSupport( part ),
m_document( 0 ),
m_markIface( 0 )
{
QWhatsThis::add(this, i18n("<b>Problem reporter</b><p>This window shows various \"problems\" in your project. "
"It displays TODO entries, FIXME's and errors reported by a language parser. "
"To add a TODO or FIXME entry, just type<br>"
"<tt>//@todo my todo</tt><br>"
"<tt>//TODO: my todo</tt><br>"
"<tt>//FIXME fix this</tt>"));
addColumn( i18n("Level") );
addColumn( i18n("File") );
addColumn( i18n("Line") );
addColumn( i18n("Column") );
addColumn( i18n("Problem") );
setAllColumnsShowFocus( TRUE );
m_timer = new QTimer( this );
connect( part->partController(), SIGNAL(activePartChanged(KParts::Part*)),
this, SLOT(slotActivePartChanged(KParts::Part*)) );
connect( part->partController(), SIGNAL(partAdded(KParts::Part*)),
this, SLOT(slotPartAdded(KParts::Part*)) );
connect( part->partController(), SIGNAL(partRemoved(KParts::Part*)),
this, SLOT(slotPartRemoved(KParts::Part*)) );
connect( m_timer, SIGNAL(timeout()), this, SLOT(reparse()) );
connect( this, SIGNAL(executed(QListViewItem*)),
this, SLOT(slotSelected(QListViewItem*)) );
configure();
}
ProblemReporter::~ProblemReporter()
{
}
void ProblemReporter::slotActivePartChanged( KParts::Part* part )
{
if( !part )
return;
m_timer->stop();
if( m_document )
disconnect( m_document, 0, this, 0 );
m_document = dynamic_cast<KTextEditor::Document*>( part );
m_markIface = 0;
if( !m_document )
return;
m_fileName = m_document->url().path();
if( !m_javaSupport->isValidSource(m_fileName) )
return;
connect( m_document, SIGNAL(textChanged()), this, SLOT(slotTextChanged()) );
m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
if( !m_javaSupport->backgroundParser() )
return;
m_javaSupport->backgroundParser()->lock();
bool needReparse = false;
if( !m_javaSupport->backgroundParser()->translationUnit(m_fileName) )
needReparse = true;
m_javaSupport->backgroundParser()->unlock();
if( needReparse )
reparse();
}
void ProblemReporter::slotTextChanged()
{
if( m_active )
m_timer->changeInterval( m_delay );
}
void ProblemReporter::removeAllProblems( const QString& filename )
{
QListViewItem* current = firstChild();
while( current ){
QListViewItem* i = current;
current = current->nextSibling();
if( i->text(1) == filename )
delete( i );
}
if( m_document && m_markIface ){
QPtrList<KTextEditor::Mark> marks = m_markIface->marks();
QPtrListIterator<KTextEditor::Mark> it( marks );
while( it.current() ){
m_markIface->removeMark( it.current()->line, KTextEditor::MarkInterface::markType07 );
++it;
}
}
}
void ProblemReporter::reparse()
{
if( !m_javaSupport->isValid() )
return;
// @todo use the project database to decide which files to parse instead of this!
// ugly hack: do not parse non .java ending files
if ( !m_fileName.endsWith(".java") )
return;
m_timer->stop();
kdDebug(9013) << "ProblemReporter::reparse()" << endl;
m_javaSupport->backgroundParser()->addFile( m_fileName );
kdDebug(9013) << "---> file added " << m_fileName << endl;
}
void ProblemReporter::slotSelected( QListViewItem* item )
{
KURL url( item->text(1) );
int line = item->text( 2 ).toInt();
// int column = item->text( 3 ).toInt();
m_javaSupport->partController()->editDocument( url, line-1 );
// m_javaSupport->mainWindow()->lowerView( this );
}
void ProblemReporter::reportProblem( const QString& fileName, const Problem& p )
{
int markType = levelToMarkType( p.level() );
if( markType != -1 && m_document && m_markIface && m_fileName == fileName ){
m_markIface->addMark( p.line(), markType );
}
QString msg = p.text();
msg = msg.replace( QRegExp("\n"), "" );
new ProblemItem( this,
levelToString( p.level() ),
fileName,
QString::number( p.line() + 1 ),
QString::number( p.column() + 1 ),
msg );
}
void ProblemReporter::configure()
{
kdDebug(9013) << "ProblemReporter::configure()" << endl;
KConfig* config = kapp->config();
config->setGroup( "General Options" );
m_active = config->readBoolEntry( "EnableJavaBgParser", TRUE );
m_delay = config->readNumEntry( "BgParserDelay", 500 );
}
void ProblemReporter::configWidget( KDialogBase* dlg )
{
QVBox *vbox = dlg->addVBoxPage(i18n("Java Parsing"));
ConfigureProblemReporter* w = new ConfigureProblemReporter( vbox );
//FIXME adymo: unused functionality
w->groupBox3->hide();
connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
connect(dlg, SIGNAL(okClicked()), this, SLOT(configure()));
}
void ProblemReporter::slotPartAdded( KParts::Part* part )
{
KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
if( !iface )
return;
iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
}
void ProblemReporter::slotPartRemoved( KParts::Part* part )
{
kdDebug(9013) << "ProblemReporter::slotPartRemoved()" << endl;
if( part == m_document ){
m_document = 0;
m_timer->stop();
}
}
QString ProblemReporter::levelToString( int level ) const
{
switch( level )
{
case Problem::Level_Error:
return QString::fromLatin1( "Error" );
case Problem::Level_Warning:
return QString::fromLatin1( "Warning" );
case Problem::Level_Todo:
return QString::fromLatin1( "Todo" );
case Problem::Level_Fixme:
return QString::fromLatin1( "Fixme" );
default:
return QString::null;
}
}
int ProblemReporter::levelToMarkType( int level ) const
{
switch( level )
{
case Problem::Level_Error:
return KTextEditor::MarkInterface::markType07;
case Problem::Level_Warning:
return -1;
case Problem::Level_Todo:
return -1;
case Problem::Level_Fixme:
return -1;
default:
return -1;
}
}
#include "problemreporter.moc"
|