KDevelop API Documentation

appoutputwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 1999-2001 by Bernd Gehrmann                             *
00003  *   bernd@kdevelop.org                                                    *
00004  *                                                                         *
00005  *   Copyright (C) 2003 by Hamish Rodda                                    *
00006  *   meddie@yoyo.its.monash.edu.au                                         *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  ***************************************************************************/
00014 
00015 #include "appoutputwidget.h"
00016 
00017 #include <qregexp.h>
00018 
00019 #include <klocale.h>
00020 #include <kdebug.h>
00021 #include <kstatusbar.h>
00022 #include <kapplication.h>
00023 #include <kconfig.h>
00024 #include <kpopupmenu.h>
00025 #include <qbuttongroup.h>
00026 #include <klineedit.h>
00027 #include <qcheckbox.h>
00028 #include <qradiobutton.h>
00029 
00030 #include "appoutputviewpart.h"
00031 #include "filterdlg.h"
00032 #include "kdevpartcontroller.h"
00033 #include "kdevmainwindow.h"
00034 
00035 AppOutputWidget::AppOutputWidget(AppOutputViewPart* part)
00036     : ProcessWidget(0, "app output widget")
00037     , m_part(part)
00038 {
00039     connect(this, SIGNAL(executed(QListBoxItem*)), SLOT(slotRowSelected(QListBoxItem*)));
00040     connect(this, SIGNAL(rightButtonClicked( QListBoxItem *, const QPoint & )), 
00041         SLOT(slotContextMenu( QListBoxItem *, const QPoint & )));
00042     KConfig *config = kapp->config();
00043     config->setGroup("General Options");
00044     setFont(config->readFontEntry("Application Font"));
00045 }
00046 
00047 
00048 AppOutputWidget::~AppOutputWidget()
00049 {}
00050 
00051 
00052 void AppOutputWidget::childFinished(bool normal, int status)
00053 {
00054     ProcessWidget::childFinished(normal, status);
00055 }
00056 
00057 
00058 void AppOutputWidget::slotRowSelected(QListBoxItem* row)
00059 {
00060     static QRegExp assertMatch("ASSERT: \\\"([^\\\"]+)\\\" in ([^\\( ]+) \\(([\\d]+)\\)");
00061     static QRegExp lineInfoMatch("\\[([^:]+):([\\d]+)\\]");
00062     if (row) {
00063         if (assertMatch.exactMatch(row->text())) {
00064             m_part->partController()->editDocument(KURL( assertMatch.cap(2) ), assertMatch.cap(3).toInt() - 1);
00065             m_part->mainWindow()->statusBar()->message(i18n("Assertion failed: %1").arg(assertMatch.cap(1)), 10000);
00066             m_part->mainWindow()->lowerView(this);
00067 
00068         } else if (lineInfoMatch.search(row->text()) != -1) {
00069             m_part->partController()->editDocument(KURL( lineInfoMatch.cap(1) ), lineInfoMatch.cap(2).toInt() - 1);
00070             m_part->mainWindow()->statusBar()->message(row->text(), 10000);
00071             m_part->mainWindow()->lowerView(this);
00072         }
00073     }
00074 }
00075 
00076 
00077 void AppOutputWidget::insertStdoutLine(const QString &line)
00078 {
00079     fprintf(stderr, "RGR: insertStdoutLine(%s)", line.latin1());
00080     strList.append(QString("o-")+line);
00081     ProcessWidget::insertStdoutLine(line);
00082 }
00083 
00084 
00085 void AppOutputWidget::insertStderrLine(const QString &line)
00086 {
00087     fprintf(stderr, "RGR: insertStderrLine(%s)", line.latin1());
00088     strList.append(QString("e-")+line);
00089     ProcessWidget::insertStderrLine(line);
00090 }
00091 
00092 
00093 void AppOutputWidget::slotContextMenu( QListBoxItem *, const QPoint &p )
00094 {
00095     //generate the popupmenu first
00096     KPopupMenu popup(this, "filter output");
00097 
00098     int idNoFilter = popup.insertItem( i18n("Do Not Filter Output") );
00099     popup.setItemChecked(idNoFilter, iFilterType == eNoFilter);
00100 
00101     int idFilter = popup.insertItem( i18n("Filter Output") );
00102     popup.setItemChecked(idFilter, iFilterType == eFilterStr || iFilterType == eFilterRegExp);
00103 
00104     //pop it up
00105     int res = popup.exec(p);
00106 
00107     //init the query dialog with current data
00108     FilterDlg dlg(this, "filter output settings");
00109     dlg.filtergroup->setButton((int)iFilterType);
00110     dlg.cbCase->setChecked(bCS);
00111     dlg.leFilterStr->setText(strFilterStr);
00112 
00113     //did user select the filter item from the popup
00114     //and did he accept the filter-dialog
00115     if (res == idFilter || res == idNoFilter) {
00116         if (res == idFilter) {
00117             if ( dlg.exec() != QDialog::Accepted ) 
00118                 return;
00119             //get back data from the dialog
00120             if (dlg.rNoFilter->isChecked())
00121                 iFilterType = eNoFilter;
00122             else if (dlg.rFilterStr->isChecked())
00123                 iFilterType = eFilterStr;
00124             else if (dlg.rFilterRegExp->isChecked())
00125                 iFilterType = eFilterRegExp;
00126             strFilterStr = dlg.leFilterStr->text();
00127             bCS = dlg.cbCase->isChecked();
00128         } else {
00129             iFilterType = eNoFilter;
00130         }
00131         
00132         //copy the first item from the listbox
00133         //if a programm was started, this contains the issued command
00134         QString strFirst=QString::null;
00135         if (count()) {
00136             setTopItem(0);
00137             strFirst = item(topItem())->text();
00138         }
00139         //clear the listbox and write back the issued command
00140         clear();
00141         if (strFirst != QString::null)
00142             insertItem(new ProcessListBoxItem(strFirst, ProcessListBoxItem::Diagnostic));
00143 
00144         //grep through the QList for items matching the filter...
00145         QStringList strListFound;
00146         if (iFilterType == eFilterStr)
00147             strListFound = strList.grep(strFilterStr, bCS);
00148         else if (iFilterType == eFilterRegExp)
00149             strListFound = strList.grep(QRegExp(strFilterStr, bCS, false));
00150         else if (iFilterType == eNoFilter)
00151             strListFound = strList;
00152 
00153         //... and reinsert the found items into the listbox
00154         for ( QStringList::Iterator it = strListFound.begin(); it != strListFound.end(); ++it ) {
00155             if ((*it).startsWith("o-")) {
00156                 (*it).remove(0,2);
00157                 insertItem(new ProcessListBoxItem(*it, ProcessListBoxItem::Normal));
00158             } else if ((*it).startsWith("e")) {
00159                 (*it).remove(0,2);
00160                 insertItem(new ProcessListBoxItem(*it, ProcessListBoxItem::Error));
00161             }
00162         }
00163     } else if (res == idNoFilter) {
00164         iFilterType = eNoFilter;
00165     }
00166 }
00167 
00168 
00169 #include "appoutputwidget.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 Wed Mar 23 00:03:57 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003