KDevelop API Documentation

problemreporter.cpp

Go to the documentation of this file.
00001 /* $Id: problemreporter.cpp,v 1.5 2004/07/19 16:08:22 dhaumann Exp $
00002    Copyright (C) 2002 by Roberto Raggi <roberto@kdevelop.org>
00003    Copyright (C) 2003 Oliver Kellogg <okellogg@users.sourceforge.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    version 2, License as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "problemreporter.h"
00021 #include "adasupportpart.h"
00022 #include "kdevpartcontroller.h"
00023 #include "kdevmainwindow.h"
00024 #include "configproblemreporter.h"
00025 #include "backgroundparser.h"
00026 
00027 #include <kdeversion.h>
00028 #include <kparts/part.h>
00029 #include <ktexteditor/editinterface.h>
00030 #include <ktexteditor/document.h>
00031 #include <ktexteditor/markinterface.h>
00032 
00033 #if (KDE_VERSION > 305)
00034 # include <ktexteditor/markinterfaceextension.h>
00035 #else
00036 # include "kde30x_markinterfaceextension.h"
00037 #endif
00038 
00039 #include <kdebug.h>
00040 #include <klocale.h>
00041 #include <kstatusbar.h>
00042 #include <kurl.h>
00043 #include <kapplication.h>
00044 #include <kiconloader.h>
00045 
00046 #include <kconfig.h>
00047 
00048 #include <qtimer.h>
00049 #include <qregexp.h>
00050 #include <qvbox.h>
00051 #include <qwhatsthis.h>
00052 #include <kdialogbase.h>
00053 
00054 
00055 class ProblemItem: public QListViewItem{
00056 public:
00057     ProblemItem( QListView* parent, const QString& level, const QString& problem,
00058                  const QString& file, const QString& line, const QString& column  )
00059         : QListViewItem( parent, level, problem, file, line, column ) {}
00060 
00061     ProblemItem( QListViewItem* parent, const QString& level, const QString& problem,
00062                  const QString& file, const QString& line, const QString& column  )
00063         : QListViewItem( parent, level, problem, file, line, column ) {}
00064 
00065     int compare( QListViewItem* item, int column, bool ascending ) const {
00066         if( column == 3 || column == 4 ){
00067             int a = text( column ).toInt();
00068             int b = item->text( column ).toInt();
00069             if( a == b )
00070                 return 0;
00071             return( a > b ? -1 : 1 );
00072         }
00073         return QListViewItem::compare( item, column, ascending );
00074     }
00075 
00076 };
00077 
00078 ProblemReporter::ProblemReporter( AdaSupportPart* part, QWidget* parent, const char* name )
00079     : QListView( parent, name ),
00080       m_adaSupport( part ),
00081       m_editor( 0 ),
00082       m_document( 0 ),
00083       m_markIface( 0 ),
00084       m_bgParser( 0 )
00085 {
00086     QWhatsThis::add(this, i18n("<b>Problem reporter</b><p>This window shows errors reported by a language parser."));
00087 
00088     addColumn( i18n("Level") );
00089     addColumn( i18n("Problem") );
00090     addColumn( i18n("File") );
00091     addColumn( i18n("Line") );
00092     //addColumn( i18n("Column") );
00093     setAllColumnsShowFocus( TRUE );
00094 
00095     m_timer = new QTimer( this );
00096 
00097     connect( part->partController(), SIGNAL(activePartChanged(KParts::Part*)),
00098              this, SLOT(slotActivePartChanged(KParts::Part*)) );
00099     connect( part->partController(), SIGNAL(partAdded(KParts::Part*)),
00100              this, SLOT(slotPartAdded(KParts::Part*)) );
00101     connect( part->partController(), SIGNAL(partRemoved(KParts::Part*)),
00102              this, SLOT(slotPartRemoved(KParts::Part*)) );
00103 
00104     connect( m_timer, SIGNAL(timeout()), this, SLOT(reparse()) );
00105 
00106     connect( this, SIGNAL(doubleClicked(QListViewItem*)),
00107              this, SLOT(slotSelected(QListViewItem*)) );
00108     connect( this, SIGNAL(returnPressed(QListViewItem*)),
00109              this, SLOT(slotSelected(QListViewItem*)) );
00110 
00111     configure();
00112 }
00113 
00114 ProblemReporter::~ProblemReporter()
00115 {
00116     if( m_bgParser ) {
00117         m_bgParser->wait();
00118     }
00119 
00120     delete( m_bgParser );
00121     m_bgParser = 0;
00122 }
00123 
00124 void ProblemReporter::slotActivePartChanged( KParts::Part* part )
00125 {
00126     if( !part )
00127         return;
00128     
00129     if( m_editor )
00130     reparse();
00131 
00132     m_document = dynamic_cast<KTextEditor::Document*>( part );
00133     if( m_document ){
00134         m_filename = m_document->url().path();
00135     }
00136 
00137     m_editor = dynamic_cast<KTextEditor::EditInterface*>( part );
00138     if( m_editor )
00139         connect( m_document, SIGNAL(textChanged()), this, SLOT(slotTextChanged()) );
00140 
00141     m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
00142 
00143     m_timer->changeInterval( m_delay );
00144 }
00145 
00146 void ProblemReporter::slotTextChanged()
00147 {
00148     if( m_active )
00149         m_timer->changeInterval( m_delay );
00150 }
00151 
00152 void ProblemReporter::reparse()
00153 {
00154     kdDebug() << "ProblemReporter::reparse()" << endl;
00155 
00156     if( !m_editor )
00157         return;
00158 
00159     m_timer->stop();
00160 
00161     if( m_bgParser ) {
00162         if( m_bgParser->running() ) {
00163             m_timer->changeInterval( m_delay );
00164             return;
00165         }
00166 
00167         delete( m_bgParser );
00168         m_bgParser = 0;
00169     }
00170 
00171     QListViewItem* current = firstChild();
00172     while( current ){
00173         QListViewItem* i = current;
00174         current = current->nextSibling();
00175 
00176         if( i->text(2) == m_filename )
00177             delete( i );
00178     }
00179 
00180     if( m_markIface ){
00181         QPtrList<KTextEditor::Mark> marks = m_markIface->marks();
00182         QPtrListIterator<KTextEditor::Mark> it( marks );
00183         while( it.current() ){
00184             m_markIface->removeMark( it.current()->line, KTextEditor::MarkInterface::markType07 );
00185             ++it;
00186         }
00187     }
00188 
00189 /* Temporarily deactivated (crashes)*/
00190     m_bgParser = new BackgroundParser( this, m_editor->text(), m_filename );
00191     m_bgParser->start();
00192  
00193 }
00194 
00195 void ProblemReporter::slotSelected( QListViewItem* item )
00196 {
00197     KURL url( item->text(2) );
00198     int line = item->text( 3 ).toInt();
00199     // int column = item->text( 4 ).toInt();
00200     m_adaSupport->partController()->editDocument( url, line-1 );
00201 }
00202 
00203 void ProblemReporter::reportError( QString message,
00204                                    QString filename,
00205                                    int line, int column )
00206 {
00207     if( m_markIface ){
00208         m_markIface->addMark( line-1, KTextEditor::MarkInterface::markType07 );
00209     }
00210 
00211     new ProblemItem( this,
00212                        "error",
00213                        message.replace( QRegExp("\n"), "" ),
00214                        filename,
00215                        QString::number( line ),
00216                        QString::number( column ) );
00217 }
00218 
00219 void ProblemReporter::reportWarning( QString message,
00220                                      QString filename,
00221                                      int line, int column )
00222 {
00223     new ProblemItem( this,
00224                        "warning",
00225                        message.replace( QRegExp("\n"), "" ),
00226                        filename,
00227                        QString::number( line ),
00228                        QString::number( column ) );
00229 }
00230 
00231 void ProblemReporter::reportMessage( QString message,
00232                                      QString filename,
00233                                      int line, int column )
00234 {
00235     new QListViewItem( this,
00236                        "message",
00237                        message.replace( QRegExp("\n"), "" ),
00238                        filename,
00239                        QString::number( line ),
00240                        QString::number( column ) );
00241 }
00242 
00243 void ProblemReporter::configure()
00244 {
00245     kdDebug() << "ProblemReporter::configure()" << endl;
00246     KConfig* config = kapp->config();
00247     config->setGroup( "General Options" );
00248     m_active = config->readBoolEntry( "EnableCppBgParser", TRUE );
00249     m_delay = config->readNumEntry( "BgParserDelay", 250 );
00250 }
00251 
00252 void ProblemReporter::configWidget( KDialogBase* dlg )
00253 {
00254     kdDebug() << "ProblemReporter::configWidget()" << endl;
00255     QVBox *vbox = dlg->addVBoxPage(i18n("Ada Parsing"));
00256     ConfigureProblemReporter* w = new ConfigureProblemReporter( vbox );
00257     connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
00258     connect(dlg, SIGNAL(okClicked()), this, SLOT(configure()));
00259 }
00260 
00261 void ProblemReporter::slotPartAdded( KParts::Part* part )
00262 {
00263     KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
00264     
00265     if( !iface )
00266         return;
00267         
00268     iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
00269 }
00270 
00271 void ProblemReporter::slotPartRemoved( KParts::Part* part )
00272 {
00273     kdDebug() << "ProblemReporter::slotPartRemoved()" << endl;
00274     if( part == m_document ){
00275         m_document = 0;
00276         m_editor = 0;
00277         m_timer->stop();
00278     }
00279 }
00280 
00281 #include "problemreporter.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:28 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003