~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/php/phperrorview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
   Copyright (C) 2002 by Roberto Raggi <roberto@kdevelop.org>
3
 
   Copyright (C) 2005 by Nicolas Escuder <n.escuder@intra-links.com>
4
 
 
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.
8
 
 
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.
13
 
 
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.
18
 
*/
19
 
 
20
 
#include "phperrorview.h"
21
 
#include "phpsupportpart.h"
22
 
 
23
 
#include <kdevpartcontroller.h>
24
 
#include <kdevmainwindow.h>
25
 
#include <kdevproject.h>
26
 
 
27
 
#include <kdeversion.h>
28
 
#include <kparts/part.h>
29
 
#include <ktexteditor/editinterface.h>
30
 
#include <ktexteditor/document.h>
31
 
#include <ktexteditor/markinterface.h>
32
 
 
33
 
#include <ktexteditor/markinterfaceextension.h>
34
 
#include <ktexteditor/view.h>
35
 
 
36
 
#include <kdebug.h>
37
 
#include <klocale.h>
38
 
#include <kstatusbar.h>
39
 
#include <kurl.h>
40
 
#include <kapplication.h>
41
 
#include <kiconloader.h>
42
 
#include <kdialogbase.h>
43
 
 
44
 
#include <kconfig.h>
45
 
 
46
 
#include <qtimer.h>
47
 
#include <qregexp.h>
48
 
#include <qvbox.h>
49
 
#include <qfileinfo.h>
50
 
#include <qwhatsthis.h>
51
 
#include <qtabbar.h>
52
 
#include <qwidgetstack.h>
53
 
#include <qlayout.h>
54
 
#include <qlineedit.h>
55
 
 
56
 
class ProblemItem: public KListViewItem
57
 
{
58
 
public:
59
 
    ProblemItem( QListView* parent, const QString& problem,
60
 
       const QString& file, const QString& line, const QString& column  )
61
 
   : KListViewItem( parent, problem, file, line, column ) {}
62
 
 
63
 
    ProblemItem( QListViewItem* parent, const QString& problem,
64
 
       const QString& file, const QString& line, const QString& column  )
65
 
   : KListViewItem( parent,  problem, file, line, column ) {}
66
 
 
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();
71
 
       if( a == b )
72
 
      return 0;
73
 
       return( a > b ? 1 : -1 );
74
 
   }
75
 
   return KListViewItem::compare( item, column, ascending );
76
 
    }
77
 
 
78
 
};
79
 
 
80
 
PHPErrorView::PHPErrorView( PHPSupportPart* part, QWidget* parent, const char* name )
81
 
    : QWidget( parent, name ? name : "problemreporter" ),
82
 
      m_phpSupport( part ),
83
 
      m_document( 0 ),
84
 
      m_markIface( 0 )
85
 
{
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>"));
92
 
 
93
 
    m_gridLayout = new QGridLayout(this,2,3);
94
 
 
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);
100
 
 
101
 
    m_filteredList->addColumn( i18n("Level") );
102
 
    m_currentList->addColumn( i18n("Level") );
103
 
 
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);
111
 
 
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);
118
 
 
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);
127
 
 
128
 
    m_tabBar->setCurrentTab(0);
129
 
 
130
 
    m_filterEdit = new KLineEdit(this);
131
 
 
132
 
    QLabel* m_filterLabel = new QLabel(i18n("Lookup:"),this);
133
 
 
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);
138
 
 
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*)) );
145
 
 
146
 
    slotActivePartChanged( part->partController()->activePart() );
147
 
}
148
 
 
149
 
void PHPErrorView::slotFilter()
150
 
{
151
 
    if(!m_tabBar->isTabEnabled(4))
152
 
      m_tabBar->setTabEnabled(4,true);
153
 
 
154
 
    m_tabBar->tab(4)->setText(i18n("Filtered: %1").arg( m_filterEdit->text() ));
155
 
    m_tabBar->setCurrentTab(4);
156
 
 
157
 
    m_filteredList->clear();
158
 
 
159
 
    filterList(m_errorList,i18n("Error"));
160
 
    filterList(m_fixmeList,i18n("Fixme"));
161
 
    filterList(m_todoList,i18n("Todo"));
162
 
 
163
 
}
164
 
 
165
 
void PHPErrorView::filterList(KListView* listview, const QString& level)
166
 
{
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));
172
 
        ++it;
173
 
    }
174
 
}
175
 
 
176
 
void PHPErrorView::slotTabSelected( int tabindex )
177
 
{
178
 
    m_widgetStack->raiseWidget(tabindex);
179
 
}
180
 
 
181
 
void PHPErrorView::InitListView(KListView* listview)
182
 
{
183
 
    listview->addColumn( i18n("File") );
184
 
    listview->addColumn( i18n("Line") );
185
 
    listview->addColumn( i18n("Column") );
186
 
    listview->addColumn( i18n("Problem") );
187
 
    listview->setAllColumnsShowFocus( TRUE );
188
 
 
189
 
    connect( listview, SIGNAL(executed(QListViewItem*)),
190
 
             this, SLOT(slotSelected(QListViewItem*)) );
191
 
 
192
 
    connect( listview, SIGNAL(returnPressed(QListViewItem*)),
193
 
             this, SLOT(slotSelected(QListViewItem* )) );
194
 
 
195
 
}
196
 
 
197
 
PHPErrorView::~PHPErrorView()
198
 
{
199
 
}
200
 
 
201
 
void PHPErrorView::slotActivePartChanged( KParts::Part* part )
202
 
{
203
 
   if ( !part ) {
204
 
      m_tabBar->setTabEnabled(0,false);
205
 
      return;
206
 
   }
207
 
 
208
 
   if ( m_document )
209
 
      disconnect( m_document, 0, this, 0 );
210
 
 
211
 
   m_document = dynamic_cast<KTextEditor::Document*>( part );
212
 
   m_markIface = 0;
213
 
 
214
 
   if ( !m_document ) {
215
 
      m_tabBar->setTabEnabled(0,false);
216
 
      return;
217
 
   }
218
 
 
219
 
   m_fileName = m_document->url().path();
220
 
 
221
 
   initCurrentList();
222
 
 
223
 
   m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
224
 
}
225
 
 
226
 
void PHPErrorView::removeAllItems( QListView* listview, const QString& filename )
227
 
{
228
 
   QListViewItem* current = listview->firstChild();
229
 
   while( current ){
230
 
      QListViewItem* i = current;
231
 
      current = current->nextSibling();
232
 
 
233
 
      if( i->text(0) == filename )
234
 
         delete( i );
235
 
   }
236
 
}
237
 
 
238
 
void PHPErrorView::removeAllProblems( const QString& filename )
239
 
{
240
 
   QString relFileName = filename;
241
 
   relFileName.remove(m_phpSupport->project()->projectDirectory());
242
 
 
243
 
   kdDebug(9008) << "PHPErrorView::removeAllProblems()" << relFileName << endl;
244
 
 
245
 
   if (filename == m_fileName)
246
 
      m_currentList->clear();
247
 
 
248
 
   removeAllItems(m_errorList,relFileName);
249
 
   removeAllItems(m_fixmeList,relFileName);
250
 
   removeAllItems(m_todoList,relFileName);
251
 
 
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 );
257
 
         ++it;
258
 
      }
259
 
   }
260
 
}
261
 
 
262
 
void PHPErrorView::initCurrentList()
263
 
{
264
 
   m_tabBar->setTabEnabled(0,true);
265
 
 
266
 
   QString relFileName = m_fileName;
267
 
 
268
 
   if (m_phpSupport->project())
269
 
      relFileName.remove(m_phpSupport->project()->projectDirectory());
270
 
 
271
 
   m_currentList->clear();
272
 
 
273
 
   updateCurrentWith(m_errorList, i18n("Error"),relFileName);
274
 
   updateCurrentWith(m_fixmeList,i18n("Fixme"),relFileName);
275
 
   updateCurrentWith(m_todoList,i18n("Todo"),relFileName);
276
 
}
277
 
 
278
 
void PHPErrorView::updateCurrentWith(QListView* listview, const QString& level, const QString& filename)
279
 
{
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));
284
 
      ++it;
285
 
   }
286
 
}
287
 
 
288
 
void PHPErrorView::slotSelected( QListViewItem* item )
289
 
{
290
 
   bool is_filtered = false;
291
 
   bool is_current = false;
292
 
 
293
 
   if (item->listView() == m_filteredList)
294
 
      is_filtered = true;
295
 
   else if(item->listView() == m_currentList)
296
 
      is_current = true;
297
 
 
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 );
301
 
}
302
 
 
303
 
void PHPErrorView::reportProblem( int level, const QString& fileName, int line, const QString& text)
304
 
{
305
 
   int markType = levelToMarkType( level );
306
 
   if ( markType != -1 && m_document && m_markIface && m_fileName == fileName ) {
307
 
      m_markIface->addMark( line, markType );
308
 
   }
309
 
 
310
 
   QString msg = text;
311
 
   msg = msg.replace( QRegExp("\n"), "" );
312
 
 
313
 
   QString relFileName = fileName;
314
 
   relFileName.remove(m_phpSupport->project()->projectDirectory());
315
 
 
316
 
   KListView* list;
317
 
   switch( level )
318
 
   {
319
 
      case Error:
320
 
      case ErrorNoSuchFunction:
321
 
      case ErrorParse:
322
 
      list = m_errorList;
323
 
      m_tabBar->setCurrentTab(m_tabBar->tab(1));
324
 
      break;
325
 
 
326
 
      case Warning:
327
 
      list = m_errorList;
328
 
      break;
329
 
 
330
 
      case Todo:
331
 
      list = m_todoList;
332
 
      break;
333
 
 
334
 
      case Fixme:
335
 
      list = m_fixmeList;
336
 
      break;
337
 
 
338
 
      default:
339
 
      list = NULL;
340
 
      break;
341
 
   }
342
 
 
343
 
   if (list) {
344
 
      kdDebug(9018) << "PB " << msg << endl;
345
 
      new ProblemItem( list, relFileName, QString::number( line + 1 ), 0, msg );
346
 
   }
347
 
 
348
 
   if (fileName == m_fileName)
349
 
      new QListViewItem(m_currentList, levelToString( level ), QString::number( line + 1 ), 0, msg);
350
 
}
351
 
 
352
 
void PHPErrorView::slotPartAdded( KParts::Part* part )
353
 
{
354
 
   KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
355
 
 
356
 
   if ( !iface )
357
 
      return;
358
 
 
359
 
   iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
360
 
}
361
 
 
362
 
void PHPErrorView::slotPartRemoved( KParts::Part* part )
363
 
{
364
 
   kdDebug(9007) << "PHPErrorView::slotPartRemoved()" << endl;
365
 
   if ( part == m_document ){
366
 
      m_document = 0;
367
 
   }
368
 
}
369
 
 
370
 
QString PHPErrorView::levelToString( int level ) const
371
 
{
372
 
   switch( level )
373
 
   {
374
 
      case ErrorNoSuchFunction:
375
 
      return QString( i18n("Undefined function") );
376
 
 
377
 
      case ErrorParse:
378
 
      return QString( i18n("Parse Error") );
379
 
 
380
 
      case Error:
381
 
      return QString( i18n("Error") );
382
 
 
383
 
      case Warning:
384
 
      return QString( i18n("Warning") );
385
 
 
386
 
      case Todo:
387
 
      return QString( i18n("Todo") );
388
 
 
389
 
      case Fixme:
390
 
      return QString( i18n("Fixme") );
391
 
 
392
 
      default:
393
 
      return QString::null;
394
 
    }
395
 
 
396
 
}
397
 
 
398
 
int PHPErrorView::levelToMarkType( int level ) const
399
 
{
400
 
   switch( level )
401
 
   {
402
 
      case ErrorNoSuchFunction:
403
 
      case ErrorParse:
404
 
      case Error:
405
 
      return KTextEditor::MarkInterface::markType07;
406
 
 
407
 
      case Warning:
408
 
      return -1;
409
 
 
410
 
      case Todo:
411
 
      return -1;
412
 
 
413
 
      case Fixme:
414
 
      return -1;
415
 
 
416
 
      default:
417
 
      return -1;
418
 
    }
419
 
 
420
 
}
421
 
 
422
 
#include "phperrorview.moc"