2
Copyright (C) 2002 by Roberto Raggi <roberto@kdevelop.org>
3
Copyright (C) 2003 Oliver Kellogg <okellogg@users.sourceforge.net>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
version 2, License as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#include "problemreporter.h"
21
#include "adasupportpart.h"
22
#include "kdevpartcontroller.h"
23
#include "kdevmainwindow.h"
24
#include "configproblemreporter.h"
25
#include "backgroundparser.h"
27
#include <qfileinfo.h>
29
#include <kdeversion.h>
30
#include <kparts/part.h>
31
#include <ktexteditor/editinterface.h>
32
#include <ktexteditor/document.h>
33
#include <ktexteditor/markinterface.h>
35
#if (KDE_VERSION > 305)
36
# include <ktexteditor/markinterfaceextension.h>
38
# include "kde30x_markinterfaceextension.h"
43
#include <kstatusbar.h>
45
#include <kapplication.h>
46
#include <kiconloader.h>
53
#include <qwhatsthis.h>
54
#include <kdialogbase.h>
57
class ProblemItem: public QListViewItem{
59
ProblemItem( QListView* parent, const QString& level, const QString& problem,
60
const QString& file, const QString& line, const QString& column )
61
: QListViewItem( parent, level, problem, file, line, column ) {}
63
ProblemItem( QListViewItem* parent, const QString& level, const QString& problem,
64
const QString& file, const QString& line, const QString& column )
65
: QListViewItem( parent, level, problem, file, line, column ) {}
67
int compare( QListViewItem* item, int column, bool ascending ) const {
68
if( column == 3 || column == 4 ){
69
int a = text( column ).toInt();
70
int b = item->text( column ).toInt();
73
return( a > b ? -1 : 1 );
75
return QListViewItem::compare( item, column, ascending );
80
ProblemReporter::ProblemReporter( AdaSupportPart* part, QWidget* parent, const char* name )
81
: QListView( parent, name ),
88
QWhatsThis::add(this, i18n("<b>Problem reporter</b><p>This window shows errors reported by a language parser."));
90
addColumn( i18n("Level") );
91
addColumn( i18n("Problem") );
92
addColumn( i18n("File") );
93
addColumn( i18n("Line") );
94
//addColumn( i18n("Column") );
95
setAllColumnsShowFocus( TRUE );
97
m_timer = new QTimer( this );
99
connect( part->partController(), SIGNAL(activePartChanged(KParts::Part*)),
100
this, SLOT(slotActivePartChanged(KParts::Part*)) );
101
connect( part->partController(), SIGNAL(partAdded(KParts::Part*)),
102
this, SLOT(slotPartAdded(KParts::Part*)) );
103
connect( part->partController(), SIGNAL(partRemoved(KParts::Part*)),
104
this, SLOT(slotPartRemoved(KParts::Part*)) );
106
connect( m_timer, SIGNAL(timeout()), this, SLOT(reparse()) );
108
connect( this, SIGNAL(doubleClicked(QListViewItem*)),
109
this, SLOT(slotSelected(QListViewItem*)) );
110
connect( this, SIGNAL(returnPressed(QListViewItem*)),
111
this, SLOT(slotSelected(QListViewItem*)) );
116
ProblemReporter::~ProblemReporter()
122
delete( m_bgParser );
126
void ProblemReporter::slotActivePartChanged( KParts::Part* part )
134
m_document = dynamic_cast<KTextEditor::Document*>( part );
136
m_filename = m_document->url().path();
139
m_editor = dynamic_cast<KTextEditor::EditInterface*>( part );
141
connect( m_document, SIGNAL(textChanged()), this, SLOT(slotTextChanged()) );
143
m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
145
m_timer->changeInterval( m_delay );
148
void ProblemReporter::slotTextChanged()
151
m_timer->changeInterval( m_delay );
154
void ProblemReporter::reparse()
156
kdDebug() << "ProblemReporter::reparse()" << endl;
164
if( m_bgParser->running() ) {
165
m_timer->changeInterval( m_delay );
169
delete( m_bgParser );
173
QListViewItem* current = firstChild();
175
QListViewItem* i = current;
176
current = current->nextSibling();
178
if( i->text(2) == m_filename )
183
QPtrList<KTextEditor::Mark> marks = m_markIface->marks();
184
QPtrListIterator<KTextEditor::Mark> it( marks );
185
while( it.current() ){
186
m_markIface->removeMark( it.current()->line, KTextEditor::MarkInterface::markType07 );
191
/* Temporarily deactivated (crashes)*/
192
if (!m_adaSupport->fileExtensions ().contains (QFileInfo (m_filename).extension ()))
194
m_bgParser = new BackgroundParser( this, m_editor->text(), m_filename );
200
void ProblemReporter::slotSelected( QListViewItem* item )
202
KURL url( item->text(2) );
203
int line = item->text( 3 ).toInt();
204
// int column = item->text( 4 ).toInt();
205
m_adaSupport->partController()->editDocument( url, line-1 );
208
void ProblemReporter::reportError( QString message,
210
int line, int column )
213
m_markIface->addMark( line-1, KTextEditor::MarkInterface::markType07 );
216
new ProblemItem( this,
218
message.replace( QRegExp("\n"), "" ),
220
QString::number( line ),
221
QString::number( column ) );
224
void ProblemReporter::reportWarning( QString message,
226
int line, int column )
228
new ProblemItem( this,
230
message.replace( QRegExp("\n"), "" ),
232
QString::number( line ),
233
QString::number( column ) );
236
void ProblemReporter::reportMessage( QString message,
238
int line, int column )
240
new QListViewItem( this,
242
message.replace( QRegExp("\n"), "" ),
244
QString::number( line ),
245
QString::number( column ) );
248
void ProblemReporter::configure()
250
kdDebug() << "ProblemReporter::configure()" << endl;
251
KConfig* config = kapp->config();
252
config->setGroup( "General Options" );
253
m_active = config->readBoolEntry( "EnableCppBgParser", TRUE );
254
m_delay = config->readNumEntry( "BgParserDelay", 250 );
257
void ProblemReporter::configWidget( KDialogBase* dlg )
259
kdDebug() << "ProblemReporter::configWidget()" << endl;
260
QVBox *vbox = dlg->addVBoxPage(i18n("Ada Parsing"), i18n("Ada Parsing"), BarIcon( "source", KIcon::SizeMedium ));
261
ConfigureProblemReporter* w = new ConfigureProblemReporter( vbox );
262
connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
263
connect(dlg, SIGNAL(okClicked()), this, SLOT(configure()));
266
void ProblemReporter::slotPartAdded( KParts::Part* part )
268
KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
273
iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
276
void ProblemReporter::slotPartRemoved( KParts::Part* part )
278
kdDebug() << "ProblemReporter::slotPartRemoved()" << endl;
279
if( part == m_document ){
286
#include "problemreporter.moc"