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

« back to all changes in this revision

Viewing changes to parts/outputviews/appoutputwidget.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) 1999-2001 by Bernd Gehrmann                             *
3
 
 *   bernd@kdevelop.org                                                    *
4
 
 *                                                                         *
5
 
 *   Copyright (C) 2003 by Hamish Rodda                                    *
6
 
 *   meddie@yoyo.its.monash.edu.au                                         *
7
 
 *                                                                         *
8
 
 *   This program is free software; you can redistribute it and/or modify  *
9
 
 *   it under the terms of the GNU General Public License as published by  *
10
 
 *   the Free Software Foundation; either version 2 of the License, or     *
11
 
 *   (at your option) any later version.                                   *
12
 
 *                                                                         *
13
 
 ***************************************************************************/
14
 
 
15
 
#include "appoutputwidget.h"
16
 
 
17
 
#include <qregexp.h>
18
 
#include <qbuttongroup.h>
19
 
#include <qcheckbox.h>
20
 
#include <qradiobutton.h>
21
 
#include <qfile.h>
22
 
#include <qtextstream.h>
23
 
#include <qclipboard.h>
24
 
 
25
 
#include <klocale.h>
26
 
#include <kdebug.h>
27
 
#include <kstatusbar.h>
28
 
#include <kapplication.h>
29
 
#include <kconfig.h>
30
 
#include <kpopupmenu.h>
31
 
#include <klineedit.h>
32
 
#include <kfiledialog.h>
33
 
 
34
 
#include "appoutputviewpart.h"
35
 
#include "filterdlg.h"
36
 
#include "kdevpartcontroller.h"
37
 
#include "kdevmainwindow.h"
38
 
#include "kdevproject.h"
39
 
 
40
 
AppOutputWidget::AppOutputWidget(AppOutputViewPart* part)
41
 
    : ProcessWidget(0, "app output widget"), m_part(part)
42
 
{
43
 
        connect(this, SIGNAL(executed(QListBoxItem*)), SLOT(slotRowSelected(QListBoxItem*)));
44
 
        connect(this, SIGNAL(rightButtonClicked( QListBoxItem *, const QPoint & )), 
45
 
                SLOT(slotContextMenu( QListBoxItem *, const QPoint & )));
46
 
        KConfig *config = kapp->config();
47
 
        config->setGroup("General Options");
48
 
        setFont(config->readFontEntry("OutputViewFont"));
49
 
  setSelectionMode(QListBox::Extended);
50
 
}
51
 
 
52
 
void AppOutputWidget::clearViewAndContents()
53
 
{
54
 
        m_contentList.clear();
55
 
        clear();
56
 
}
57
 
 
58
 
AppOutputWidget::~AppOutputWidget()
59
 
{}
60
 
 
61
 
 
62
 
void AppOutputWidget::childFinished(bool normal, int status)
63
 
{
64
 
    if( !stdoutbuf.isEmpty() )
65
 
        insertStdoutLine("");
66
 
    if( !stderrbuf.isEmpty() )
67
 
        insertStderrLine("");
68
 
 
69
 
    ProcessWidget::childFinished(normal, status);
70
 
}
71
 
 
72
 
 
73
 
void AppOutputWidget::slotRowSelected(QListBoxItem* row)
74
 
{
75
 
        static QRegExp assertMatch("ASSERT: \\\"([^\\\"]+)\\\" in ([^\\( ]+) \\(([\\d]+)\\)");
76
 
        static QRegExp lineInfoMatch("\\[([^:]+):([\\d]+)\\]");
77
 
        static QRegExp rubyErrorMatch("([^:\\s]+\\.rb):([\\d]+):?.*$");
78
 
 
79
 
        if (row) {
80
 
                if (assertMatch.exactMatch(row->text())) {
81
 
                        m_part->partController()->editDocument(KURL( assertMatch.cap(2) ), assertMatch.cap(3).toInt() - 1);
82
 
                        m_part->mainWindow()->statusBar()->message(i18n("Assertion failed: %1").arg(assertMatch.cap(1)), 10000);
83
 
                        m_part->mainWindow()->lowerView(this);
84
 
 
85
 
                } else if (lineInfoMatch.search(row->text()) != -1) {
86
 
                        m_part->partController()->editDocument(KURL( lineInfoMatch.cap(1) ), lineInfoMatch.cap(2).toInt() - 1);
87
 
                        m_part->mainWindow()->statusBar()->message(row->text(), 10000);
88
 
                        m_part->mainWindow()->lowerView(this);
89
 
                } else if (rubyErrorMatch.search(row->text()) != -1) {
90
 
                        QString file;
91
 
                        if (rubyErrorMatch.cap(1).startsWith("/")) {
92
 
                                file = rubyErrorMatch.cap(1);
93
 
                        } else {
94
 
                                file = m_part->project()->projectDirectory() + "/" + rubyErrorMatch.cap(1);
95
 
                        }
96
 
                        m_part->partController()->editDocument(KURL(rubyErrorMatch.cap(1)), rubyErrorMatch.cap(2).toInt() - 1);
97
 
                        m_part->mainWindow()->statusBar()->message(row->text(), 10000);
98
 
                        m_part->mainWindow()->lowerView(this);
99
 
                }
100
 
        }
101
 
}
102
 
 
103
 
 
104
 
void AppOutputWidget::insertStdoutLine(const QCString &line)
105
 
{
106
 
//      kdDebug(9004) << k_funcinfo << line << endl;
107
 
 
108
 
        if ( !m_part->isViewVisible() )
109
 
        {
110
 
                m_part->showView();
111
 
        }
112
 
 
113
 
        QString sline;
114
 
        if( !stdoutbuf.isEmpty() )
115
 
        {
116
 
            sline = QString::fromLocal8Bit( stdoutbuf+line );
117
 
            stdoutbuf.truncate( 0 );
118
 
        }else
119
 
        {
120
 
            sline = QString::fromLocal8Bit( line );
121
 
        }
122
 
 
123
 
        m_contentList.append(QString("o-")+sline);
124
 
        if ( filterSingleLine( sline ) )
125
 
        {
126
 
            ProcessWidget::insertStdoutLine( sline.local8Bit() );
127
 
        }
128
 
}
129
 
 
130
 
 
131
 
void AppOutputWidget::insertStderrLine(const QCString &line)
132
 
{
133
 
//      kdDebug(9004) << k_funcinfo << line << endl;
134
 
 
135
 
        if ( !m_part->isViewVisible() )
136
 
        {
137
 
                m_part->showView();
138
 
        }
139
 
 
140
 
 
141
 
        QString sline;
142
 
        if( !stderrbuf.isEmpty() )
143
 
        {
144
 
            sline = QString::fromLocal8Bit( stderrbuf+line );
145
 
            stderrbuf.truncate( 0 );
146
 
        }else
147
 
        {
148
 
            sline = QString::fromLocal8Bit( line );
149
 
        }
150
 
 
151
 
        m_contentList.append(QString("e-")+sline);
152
 
        if ( filterSingleLine( sline ) )
153
 
        {
154
 
            ProcessWidget::insertStderrLine( sline.local8Bit() );
155
 
        }
156
 
}
157
 
 
158
 
void AppOutputWidget::editFilter()
159
 
{
160
 
        FilterDlg dlg( this );
161
 
        dlg.caseSensitive->setChecked( m_filter.m_caseSensitive );
162
 
        dlg.regularExpression->setChecked( m_filter.m_isRegExp );
163
 
        dlg.filterString->setText( m_filter.m_filterString );
164
 
 
165
 
        if ( dlg.exec() == QDialog::Accepted )
166
 
        {
167
 
                m_filter.m_caseSensitive = dlg.caseSensitive->isChecked();
168
 
                m_filter.m_isRegExp = dlg.regularExpression->isChecked();
169
 
                m_filter.m_filterString = dlg.filterString->text();
170
 
 
171
 
                m_filter.m_isActive = !m_filter.m_filterString.isEmpty();
172
 
 
173
 
                reinsertAndFilter();
174
 
        }
175
 
 
176
 
}
177
 
bool AppOutputWidget::filterSingleLine(const QString & line)
178
 
{
179
 
        if ( !m_filter.m_isActive ) return true;
180
 
 
181
 
        if ( m_filter.m_isRegExp )
182
 
        {
183
 
                return ( line.find( QRegExp( m_filter.m_filterString, m_filter.m_caseSensitive, false ) ) != -1 );
184
 
        }
185
 
        else
186
 
        {
187
 
                return ( line.find( m_filter.m_filterString, 0, m_filter.m_caseSensitive ) != -1 );
188
 
        }       
189
 
}
190
 
 
191
 
void AppOutputWidget::reinsertAndFilter()
192
 
{
193
 
        //copy the first item from the listbox
194
 
        //if a programm was started, this contains the issued command
195
 
        QString issuedCommand;
196
 
        if ( count() > 0 ) 
197
 
        {
198
 
                setTopItem(0);
199
 
                issuedCommand = item(topItem())->text();
200
 
        }
201
 
 
202
 
        clear();
203
 
 
204
 
        //write back the issued command
205
 
        if ( !issuedCommand.isEmpty() )
206
 
        {
207
 
                insertItem( new ProcessListBoxItem( issuedCommand, ProcessListBoxItem::Diagnostic ) );
208
 
        }
209
 
 
210
 
        //grep through the list for items matching the filter...
211
 
        QStringList strListFound;
212
 
        if ( m_filter.m_isActive )
213
 
        {       
214
 
                if ( m_filter.m_isRegExp )
215
 
                {
216
 
                        strListFound = m_contentList.grep( QRegExp(m_filter.m_filterString, m_filter.m_caseSensitive, false ) );
217
 
                }
218
 
                else
219
 
                {
220
 
                        strListFound = m_contentList.grep( m_filter.m_filterString, m_filter.m_caseSensitive );
221
 
                }
222
 
        }
223
 
        else
224
 
        {
225
 
                strListFound = m_contentList;
226
 
        }
227
 
 
228
 
        //... and reinsert the found items into the listbox
229
 
        for ( QStringList::Iterator it = strListFound.begin(); it != strListFound.end(); ++it )
230
 
        {
231
 
                if ((*it).startsWith("o-"))
232
 
                 {
233
 
                        (*it).remove(0,2);
234
 
                        insertItem(new ProcessListBoxItem(*it, ProcessListBoxItem::Normal));
235
 
                }
236
 
                else if ((*it).startsWith("e-"))
237
 
                {
238
 
                        (*it).remove(0,2);
239
 
                        insertItem(new ProcessListBoxItem(*it, ProcessListBoxItem::Error));
240
 
                }
241
 
        }
242
 
}
243
 
 
244
 
void AppOutputWidget::clearFilter()
245
 
{
246
 
        m_filter.m_isActive = false;
247
 
        reinsertAndFilter();
248
 
}
249
 
 
250
 
void AppOutputWidget::slotContextMenu( QListBoxItem *, const QPoint &p )
251
 
{
252
 
        KPopupMenu popup(this, "filter output");
253
 
 
254
 
        int id = popup.insertItem( i18n("Clear output"), this, SLOT(clearViewAndContents()) );
255
 
        popup.setItemEnabled( id, m_contentList.size() > 0 );
256
 
 
257
 
  popup.insertItem( i18n("Copy selected lines"), this, SLOT(copySelected()) );
258
 
  popup.insertSeparator();
259
 
 
260
 
        popup.insertItem( i18n("Save unfiltered"), this, SLOT(saveAll()) );
261
 
        id = popup.insertItem( i18n("Save filtered output"), this, SLOT(saveFiltered()) );
262
 
        popup.setItemEnabled( id, m_filter.m_isActive );
263
 
        popup.insertSeparator();
264
 
 
265
 
        id = popup.insertItem( i18n("Clear filter"), this, SLOT(clearFilter()) );
266
 
        popup.setItemEnabled( id, m_filter.m_isActive );
267
 
 
268
 
        popup.insertItem( i18n("Edit filter"), this, SLOT(editFilter() ) );
269
 
 
270
 
        popup.insertSeparator();
271
 
        popup.insertItem( i18n("Hide view"), this, SLOT(hideView()) );
272
 
 
273
 
        popup.exec(p);
274
 
}
275
 
 
276
 
void AppOutputWidget::hideView()
277
 
{
278
 
        m_part->hideView();
279
 
}
280
 
 
281
 
void AppOutputWidget::saveAll()
282
 
{
283
 
        saveOutputToFile( false );
284
 
}
285
 
 
286
 
void AppOutputWidget::saveFiltered()
287
 
{
288
 
        saveOutputToFile( true );
289
 
}
290
 
 
291
 
void AppOutputWidget::saveOutputToFile(bool useFilter)
292
 
{
293
 
        QString filename = KFileDialog::getSaveFileName();
294
 
 
295
 
        if ( filename.isEmpty() ) return;
296
 
 
297
 
        QStringList contents;
298
 
        if ( useFilter && m_filter.m_isActive )
299
 
        {       
300
 
                if ( m_filter.m_isRegExp )
301
 
                {
302
 
                        contents = m_contentList.grep( QRegExp(m_filter.m_filterString, m_filter.m_caseSensitive, false ) );
303
 
                }
304
 
                else
305
 
                {
306
 
                        contents = m_contentList.grep( m_filter.m_filterString, m_filter.m_caseSensitive );
307
 
                }
308
 
        }
309
 
        else
310
 
        {
311
 
                contents = m_contentList;
312
 
        }
313
 
 
314
 
        QFile file( filename );
315
 
        if ( file.open( IO_WriteOnly ) )
316
 
        {
317
 
                QTextStream ostream( &file );
318
 
                QStringList::ConstIterator it = contents.begin();
319
 
                while( it != contents.end() )
320
 
                {
321
 
                        QString line = *it;
322
 
                        if ( line.startsWith("o-") || line.startsWith("e-") )
323
 
                        {
324
 
                                line.remove( 0, 2 );
325
 
                        }
326
 
                        ostream << line << endl;
327
 
                        ++it;
328
 
                }
329
 
                file.close();
330
 
        }
331
 
}
332
 
 
333
 
void AppOutputWidget::copySelected()
334
 
{
335
 
  uint n = count();
336
 
  QString buffer;
337
 
  for (uint i = 0; i < n; i++)
338
 
  {
339
 
    if (isSelected(i))
340
 
      buffer += item(i)->text() + "\n";
341
 
  }
342
 
  kapp->clipboard()->setText(buffer, QClipboard::Clipboard);
343
 
}
344
 
 
345
 
void AppOutputWidget::addPartialStderrLine(const QCString & line)
346
 
{
347
 
    stderrbuf += line;
348
 
}
349
 
 
350
 
void AppOutputWidget::addPartialStdoutLine(const QCString & line)
351
 
{
352
 
    stdoutbuf += line;
353
 
}
354
 
 
355
 
#include "appoutputwidget.moc"