KDevelop API Documentation

languages/pascal/problemreporter.cpp

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