2
Copyright (C) 2002 by Roberto Raggi <roberto@kdevelop.org>
3
Copyright (C) 2005 by Nicolas Escuder <n.escuder@intra-links.com>
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., 51 Franklin Steet, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "phperrorview.h"
21
#include "phpsupportpart.h"
23
#include <kdevpartcontroller.h>
24
#include <kdevmainwindow.h>
25
#include <kdevproject.h>
27
#include <kdeversion.h>
28
#include <kparts/part.h>
29
#include <ktexteditor/editinterface.h>
30
#include <ktexteditor/document.h>
31
#include <ktexteditor/markinterface.h>
33
#include <ktexteditor/markinterfaceextension.h>
34
#include <ktexteditor/view.h>
38
#include <kstatusbar.h>
40
#include <kapplication.h>
41
#include <kiconloader.h>
42
#include <kdialogbase.h>
49
#include <qfileinfo.h>
50
#include <qwhatsthis.h>
52
#include <qwidgetstack.h>
54
#include <qlineedit.h>
56
class ProblemItem: public KListViewItem
59
ProblemItem( QListView* parent, const QString& problem,
60
const QString& file, const QString& line, const QString& column )
61
: KListViewItem( parent, problem, file, line, column ) {}
63
ProblemItem( QListViewItem* parent, const QString& problem,
64
const QString& file, const QString& line, const QString& column )
65
: KListViewItem( parent, problem, file, line, column ) {}
67
int compare( QListViewItem* item, int column, bool ascending ) const {
68
if( column == 2 || column == 3 ){
69
int a = text( column ).toInt();
70
int b = item->text( column ).toInt();
73
return( a > b ? 1 : -1 );
75
return KListViewItem::compare( item, column, ascending );
80
PHPErrorView::PHPErrorView( PHPSupportPart* part, QWidget* parent, const char* name )
81
: QWidget( parent, name ? name : "problemreporter" ),
86
QWhatsThis::add(this, i18n("<b>Problem reporter</b><p>This window shows various \"problems\" in your project. "
87
"It displays TODO entries, FIXME's and errors reported by a language parser. "
88
"To add a TODO or FIXME entry, just type<br>"
89
"<tt>//@todo my todo</tt><br>"
90
"<tt>//TODO: my todo</tt><br>"
91
"<tt>//FIXME fix this</tt>"));
93
m_gridLayout = new QGridLayout(this,2,3);
95
m_errorList = new KListView(this);
96
m_fixmeList = new KListView(this);
97
m_todoList = new KListView(this);
98
m_filteredList = new KListView(this);
99
m_currentList = new KListView(this);
101
m_filteredList->addColumn( i18n("Level") );
102
m_currentList->addColumn( i18n("Level") );
104
//addColumn( i18n("Level") );
105
InitListView(m_errorList);
106
InitListView(m_fixmeList);
107
InitListView(m_todoList);
108
InitListView(m_filteredList);
109
InitListView(m_currentList);
110
m_currentList->removeColumn(1);
112
m_widgetStack = new QWidgetStack(this);
113
m_widgetStack->addWidget(m_currentList,0);
114
m_widgetStack->addWidget(m_errorList,1);
115
m_widgetStack->addWidget(m_fixmeList,2);
116
m_widgetStack->addWidget(m_todoList,3);
117
m_widgetStack->addWidget(m_filteredList,4);
119
m_tabBar = new QTabBar(this);
120
m_tabBar->insertTab(new QTab(i18n("Current")),0);
121
m_tabBar->insertTab(new QTab(i18n("Errors")),1);
122
m_tabBar->insertTab(new QTab(i18n("Fixme")),2);
123
m_tabBar->insertTab(new QTab(i18n("Todo")),3);
124
m_tabBar->insertTab(new QTab(i18n("Filtered")),4);
125
m_tabBar->setTabEnabled(0,false);
126
m_tabBar->setTabEnabled(4,false);
128
m_tabBar->setCurrentTab(0);
130
m_filterEdit = new KLineEdit(this);
132
QLabel* m_filterLabel = new QLabel(i18n("Lookup:"),this);
134
m_gridLayout->addWidget(m_tabBar,0,0);
135
m_gridLayout->addMultiCellWidget(m_widgetStack,1,1,0,2);
136
m_gridLayout->addWidget(m_filterLabel,0,1,Qt::AlignRight);
137
m_gridLayout->addWidget(m_filterEdit,0,2,Qt::AlignLeft);
139
connect( m_filterEdit, SIGNAL(returnPressed()), this, SLOT(slotFilter()) );
140
connect( m_filterEdit, SIGNAL(textChanged( const QString & )), this, SLOT(slotFilter()) );
141
connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabSelected(int)) );
142
connect( part->partController(), SIGNAL(activePartChanged(KParts::Part*)), this, SLOT(slotActivePartChanged(KParts::Part*)) );
143
connect( part->partController(), SIGNAL(partAdded(KParts::Part*)), this, SLOT(slotPartAdded(KParts::Part*)) );
144
connect( part->partController(), SIGNAL(partRemoved(KParts::Part*)), this, SLOT(slotPartRemoved(KParts::Part*)) );
146
slotActivePartChanged( part->partController()->activePart() );
149
void PHPErrorView::slotFilter()
151
if(!m_tabBar->isTabEnabled(4))
152
m_tabBar->setTabEnabled(4,true);
154
m_tabBar->tab(4)->setText(i18n("Filtered: %1").arg( m_filterEdit->text() ));
155
m_tabBar->setCurrentTab(4);
157
m_filteredList->clear();
159
filterList(m_errorList,i18n("Error"));
160
filterList(m_fixmeList,i18n("Fixme"));
161
filterList(m_todoList,i18n("Todo"));
165
void PHPErrorView::filterList(KListView* listview, const QString& level)
167
QListViewItemIterator it( listview );
168
while ( it.current() ) {
169
if ( it.current()->text(3).contains(m_filterEdit->text(),false))
170
new KListViewItem(m_filteredList,level,
171
it.current()->text(0),it.current()->text(1),it.current()->text(2),it.current()->text(3));
176
void PHPErrorView::slotTabSelected( int tabindex )
178
m_widgetStack->raiseWidget(tabindex);
181
void PHPErrorView::InitListView(KListView* listview)
183
listview->addColumn( i18n("File") );
184
listview->addColumn( i18n("Line") );
185
listview->addColumn( i18n("Column") );
186
listview->addColumn( i18n("Problem") );
187
listview->setAllColumnsShowFocus( TRUE );
189
connect( listview, SIGNAL(executed(QListViewItem*)),
190
this, SLOT(slotSelected(QListViewItem*)) );
192
connect( listview, SIGNAL(returnPressed(QListViewItem*)),
193
this, SLOT(slotSelected(QListViewItem* )) );
197
PHPErrorView::~PHPErrorView()
201
void PHPErrorView::slotActivePartChanged( KParts::Part* part )
204
m_tabBar->setTabEnabled(0,false);
209
disconnect( m_document, 0, this, 0 );
211
m_document = dynamic_cast<KTextEditor::Document*>( part );
215
m_tabBar->setTabEnabled(0,false);
219
m_fileName = m_document->url().path();
223
m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
226
void PHPErrorView::removeAllItems( QListView* listview, const QString& filename )
228
QListViewItem* current = listview->firstChild();
230
QListViewItem* i = current;
231
current = current->nextSibling();
233
if( i->text(0) == filename )
238
void PHPErrorView::removeAllProblems( const QString& filename )
240
QString relFileName = filename;
241
relFileName.remove(m_phpSupport->project()->projectDirectory());
243
kdDebug(9008) << "PHPErrorView::removeAllProblems()" << relFileName << endl;
245
if (filename == m_fileName)
246
m_currentList->clear();
248
removeAllItems(m_errorList,relFileName);
249
removeAllItems(m_fixmeList,relFileName);
250
removeAllItems(m_todoList,relFileName);
252
if ( m_document && m_markIface ) {
253
QPtrList<KTextEditor::Mark> marks = m_markIface->marks();
254
QPtrListIterator<KTextEditor::Mark> it( marks );
255
while( it.current() ) {
256
m_markIface->removeMark( it.current()->line, KTextEditor::MarkInterface::markType07 );
262
void PHPErrorView::initCurrentList()
264
m_tabBar->setTabEnabled(0,true);
266
QString relFileName = m_fileName;
268
if (m_phpSupport->project())
269
relFileName.remove(m_phpSupport->project()->projectDirectory());
271
m_currentList->clear();
273
updateCurrentWith(m_errorList, i18n("Error"),relFileName);
274
updateCurrentWith(m_fixmeList,i18n("Fixme"),relFileName);
275
updateCurrentWith(m_todoList,i18n("Todo"),relFileName);
278
void PHPErrorView::updateCurrentWith(QListView* listview, const QString& level, const QString& filename)
280
QListViewItemIterator it(listview);
281
while ( it.current() ) {
282
if ( it.current()->text(0) == filename)
283
new QListViewItem(m_currentList,level,it.current()->text(1),it.current()->text(2),it.current()->text(3));
288
void PHPErrorView::slotSelected( QListViewItem* item )
290
bool is_filtered = false;
291
bool is_current = false;
293
if (item->listView() == m_filteredList)
295
else if(item->listView() == m_currentList)
298
KURL url( is_current ? m_fileName : item->text(0 + is_filtered) );
299
int line = item->text( 1 + is_filtered).toInt();
300
m_phpSupport->partController()->editDocument( url, line-1 );
303
void PHPErrorView::reportProblem( int level, const QString& fileName, int line, const QString& text)
305
int markType = levelToMarkType( level );
306
if ( markType != -1 && m_document && m_markIface && m_fileName == fileName ) {
307
m_markIface->addMark( line, markType );
311
msg = msg.replace( QRegExp("\n"), "" );
313
QString relFileName = fileName;
314
relFileName.remove(m_phpSupport->project()->projectDirectory());
320
case ErrorNoSuchFunction:
323
m_tabBar->setCurrentTab(m_tabBar->tab(1));
344
kdDebug(9018) << "PB " << msg << endl;
345
new ProblemItem( list, relFileName, QString::number( line + 1 ), 0, msg );
348
if (fileName == m_fileName)
349
new QListViewItem(m_currentList, levelToString( level ), QString::number( line + 1 ), 0, msg);
352
void PHPErrorView::slotPartAdded( KParts::Part* part )
354
KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
359
iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
362
void PHPErrorView::slotPartRemoved( KParts::Part* part )
364
kdDebug(9007) << "PHPErrorView::slotPartRemoved()" << endl;
365
if ( part == m_document ){
370
QString PHPErrorView::levelToString( int level ) const
374
case ErrorNoSuchFunction:
375
return QString( i18n("Undefined function") );
378
return QString( i18n("Parse Error") );
381
return QString( i18n("Error") );
384
return QString( i18n("Warning") );
387
return QString( i18n("Todo") );
390
return QString( i18n("Fixme") );
393
return QString::null;
398
int PHPErrorView::levelToMarkType( int level ) const
402
case ErrorNoSuchFunction:
405
return KTextEditor::MarkInterface::markType07;
422
#include "phperrorview.moc"