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

« back to all changes in this revision

Viewing changes to languages/ada/problemreporter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

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) 2003 Oliver Kellogg <okellogg@users.sourceforge.net>
 
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., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include "problemreporter.h"
 
21
#include "adasupportpart.h"
 
22
#include "kdevpartcontroller.h"
 
23
#include "kdevmainwindow.h"
 
24
#include "configproblemreporter.h"
 
25
#include "backgroundparser.h"
 
26
 
 
27
#include <qfileinfo.h>
 
28
 
 
29
#include <kdeversion.h>
 
30
#include <kparts/part.h>
 
31
#include <ktexteditor/editinterface.h>
 
32
#include <ktexteditor/document.h>
 
33
#include <ktexteditor/markinterface.h>
 
34
 
 
35
#if (KDE_VERSION > 305)
 
36
# include <ktexteditor/markinterfaceextension.h>
 
37
#else
 
38
# include "kde30x_markinterfaceextension.h"
 
39
#endif
 
40
 
 
41
#include <kdebug.h>
 
42
#include <klocale.h>
 
43
#include <kstatusbar.h>
 
44
#include <kurl.h>
 
45
#include <kapplication.h>
 
46
#include <kiconloader.h>
 
47
 
 
48
#include <kconfig.h>
 
49
 
 
50
#include <qtimer.h>
 
51
#include <qregexp.h>
 
52
#include <qvbox.h>
 
53
#include <qwhatsthis.h>
 
54
#include <kdialogbase.h>
 
55
 
 
56
 
 
57
class ProblemItem: public QListViewItem{
 
58
public:
 
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 ) {}
 
62
 
 
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 ) {}
 
66
 
 
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();
 
71
                        if( a == b )
 
72
                                return 0;
 
73
                        return( a > b ? -1 : 1 );
 
74
                }
 
75
                return QListViewItem::compare( item, column, ascending );
 
76
        }
 
77
 
 
78
};
 
79
 
 
80
ProblemReporter::ProblemReporter( AdaSupportPart* part, QWidget* parent, const char* name )
 
81
    : QListView( parent, name ),
 
82
      m_adaSupport( part ),
 
83
      m_editor( 0 ),
 
84
      m_document( 0 ),
 
85
          m_markIface( 0 ),
 
86
      m_bgParser( 0 )
 
87
{
 
88
    QWhatsThis::add(this, i18n("<b>Problem reporter</b><p>This window shows errors reported by a language parser."));
 
89
 
 
90
    addColumn( i18n("Level") );
 
91
    addColumn( i18n("Problem") );
 
92
    addColumn( i18n("File") );
 
93
    addColumn( i18n("Line") );
 
94
    //addColumn( i18n("Column") );
 
95
    setAllColumnsShowFocus( TRUE );
 
96
 
 
97
    m_timer = new QTimer( this );
 
98
 
 
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*)) );
 
105
 
 
106
    connect( m_timer, SIGNAL(timeout()), this, SLOT(reparse()) );
 
107
 
 
108
    connect( this, SIGNAL(doubleClicked(QListViewItem*)),
 
109
             this, SLOT(slotSelected(QListViewItem*)) );
 
110
    connect( this, SIGNAL(returnPressed(QListViewItem*)),
 
111
             this, SLOT(slotSelected(QListViewItem*)) );
 
112
 
 
113
    configure();
 
114
}
 
115
 
 
116
ProblemReporter::~ProblemReporter()
 
117
{
 
118
    if( m_bgParser ) {
 
119
        m_bgParser->wait();
 
120
    }
 
121
 
 
122
    delete( m_bgParser );
 
123
    m_bgParser = 0;
 
124
}
 
125
 
 
126
void ProblemReporter::slotActivePartChanged( KParts::Part* part )
 
127
{
 
128
    if( !part )
 
129
        return;
 
130
    
 
131
    if( m_editor )
 
132
        reparse();
 
133
 
 
134
    m_document = dynamic_cast<KTextEditor::Document*>( part );
 
135
    if( m_document ){
 
136
        m_filename = m_document->url().path();
 
137
    }
 
138
 
 
139
    m_editor = dynamic_cast<KTextEditor::EditInterface*>( part );
 
140
    if( m_editor )
 
141
        connect( m_document, SIGNAL(textChanged()), this, SLOT(slotTextChanged()) );
 
142
 
 
143
        m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
 
144
 
 
145
        m_timer->changeInterval( m_delay );
 
146
}
 
147
 
 
148
void ProblemReporter::slotTextChanged()
 
149
{
 
150
    if( m_active )
 
151
        m_timer->changeInterval( m_delay );
 
152
}
 
153
 
 
154
void ProblemReporter::reparse()
 
155
{
 
156
    kdDebug() << "ProblemReporter::reparse()" << endl;
 
157
 
 
158
    if( !m_editor )
 
159
        return;
 
160
 
 
161
    m_timer->stop();
 
162
 
 
163
    if( m_bgParser ) {
 
164
        if( m_bgParser->running() ) {
 
165
            m_timer->changeInterval( m_delay );
 
166
            return;
 
167
        }
 
168
 
 
169
        delete( m_bgParser );
 
170
        m_bgParser = 0;
 
171
    }
 
172
 
 
173
    QListViewItem* current = firstChild();
 
174
    while( current ){
 
175
        QListViewItem* i = current;
 
176
        current = current->nextSibling();
 
177
 
 
178
        if( i->text(2) == m_filename )
 
179
            delete( i );
 
180
    }
 
181
 
 
182
        if( m_markIface ){
 
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 );
 
187
                        ++it;
 
188
                }
 
189
        }
 
190
 
 
191
/* Temporarily deactivated (crashes)*/
 
192
    if (!m_adaSupport->fileExtensions ().contains (QFileInfo (m_filename).extension ()))
 
193
    {
 
194
        m_bgParser = new BackgroundParser( this, m_editor->text(), m_filename );
 
195
        m_bgParser->start();
 
196
    }
 
197
 /**/
 
198
}
 
199
 
 
200
void ProblemReporter::slotSelected( QListViewItem* item )
 
201
{
 
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 );
 
206
}
 
207
 
 
208
void ProblemReporter::reportError( QString message,
 
209
                                   QString filename,
 
210
                                   int line, int column )
 
211
{
 
212
        if( m_markIface ){
 
213
                m_markIface->addMark( line-1, KTextEditor::MarkInterface::markType07 );
 
214
        }
 
215
 
 
216
    new ProblemItem( this,
 
217
                       "error",
 
218
                       message.replace( QRegExp("\n"), "" ),
 
219
                       filename,
 
220
                       QString::number( line ),
 
221
                       QString::number( column ) );
 
222
}
 
223
 
 
224
void ProblemReporter::reportWarning( QString message,
 
225
                                     QString filename,
 
226
                                     int line, int column )
 
227
{
 
228
    new ProblemItem( this,
 
229
                       "warning",
 
230
                       message.replace( QRegExp("\n"), "" ),
 
231
                       filename,
 
232
                       QString::number( line ),
 
233
                       QString::number( column ) );
 
234
}
 
235
 
 
236
void ProblemReporter::reportMessage( QString message,
 
237
                                     QString filename,
 
238
                                     int line, int column )
 
239
{
 
240
    new QListViewItem( this,
 
241
                       "message",
 
242
                       message.replace( QRegExp("\n"), "" ),
 
243
                       filename,
 
244
                       QString::number( line ),
 
245
                       QString::number( column ) );
 
246
}
 
247
 
 
248
void ProblemReporter::configure()
 
249
{
 
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 );
 
255
}
 
256
 
 
257
void ProblemReporter::configWidget( KDialogBase* dlg )
 
258
{
 
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()));
 
264
}
 
265
 
 
266
void ProblemReporter::slotPartAdded( KParts::Part* part )
 
267
{
 
268
        KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
 
269
        
 
270
        if( !iface )
 
271
                return;
 
272
                
 
273
        iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
 
274
}
 
275
 
 
276
void ProblemReporter::slotPartRemoved( KParts::Part* part )
 
277
{
 
278
    kdDebug() << "ProblemReporter::slotPartRemoved()" << endl;
 
279
    if( part == m_document ){
 
280
        m_document = 0;
 
281
        m_editor = 0;
 
282
        m_timer->stop();
 
283
    }
 
284
}
 
285
 
 
286
#include "problemreporter.moc"