KDE/kdevelop
Andreas Pakulat
apaku at gmx.de
Mon Apr 30 23:43:10 UTC 2007
SVN commit 659880 by apaku:
- Use a tabwidget instead of a plain listview, now each queued command's output is displayed in its own tabwidget
- Add API to allow simple logging facility, any plugin can now open a new tab
and add lines to the listview in the tab
The main use for this is currently the SVN/CVS plugins, they shouldn't need to have
their own toolview just for logging output from executing vcs actions.
dukju and Robert would you please have a look and port the plugins to use the outputview.
CCMAIL:kdevelop-devel at kdevelop.org
M +9 -9 buildtools/builders/makebuilder/makebuilder.cpp
M +2 -2 buildtools/builders/makebuilder/makebuilder.h
M +9 -9 buildtools/builders/qmakebuilder/qmakebuilder.cpp
M +2 -2 buildtools/builders/qmakebuilder/qmakebuilder.h
M +2 -0 lib/plugins/outputviews/CMakeLists.txt
M +28 -13 lib/plugins/outputviews/interfaces/ioutputview.h
A lib/plugins/outputviews/outputviewcommand.cpp [License: GPL (v2+)]
A lib/plugins/outputviews/outputviewcommand.h [License: GPL (v2+)]
A lib/plugins/outputviews/outputwidget.cpp [License: GPL (v2+)]
A lib/plugins/outputviews/outputwidget.h [License: GPL (v2+)]
M +48 -88 lib/plugins/outputviews/simpleoutputview.cpp
M +8 -9 lib/plugins/outputviews/simpleoutputview.h
--- trunk/KDE/kdevelop/buildtools/builders/makebuilder/makebuilder.cpp #659879:659880
@@ -52,10 +52,10 @@
KDevelop::IOutputView* view = i->extension<KDevelop::IOutputView>();
if( view )
{
- connect(i, SIGNAL(commandFinished(const QStringList &)),
- this, SLOT(commandFinished(const QStringList &)));
- connect(i, SIGNAL(commandFailed(const QStringList &)),
- this, SLOT(commandFailed(const QStringList &)));
+ connect(i, SIGNAL(commandFinished(const QString &)),
+ this, SLOT(commandFinished(const QString &)));
+ connect(i, SIGNAL(commandFailed(const QString &)),
+ this, SLOT(commandFailed(const QString &)));
}
}
}
@@ -79,7 +79,7 @@
QStringList cmd = buildCommand(item);
m_queue << QPair<QStringList, KDevelop::ProjectBaseItem*>( cmd, dom );
kDebug(9038) << "Starting build: " << cmd << endl;
- view->queueCommand( item->url(), cmd, QStringList() );
+ view->queueCommand( item->url(), cmd, QMap<QString,QString>() );
return true;
}
}
@@ -93,13 +93,13 @@
return false;
}
-void MakeBuilder::commandFinished(const QStringList &command)
+void MakeBuilder::commandFinished(const QString &command)
{
if( !m_queue.isEmpty() )
{
QPair< QStringList, KDevelop::ProjectBaseItem* > pair = m_queue.front();
- if( pair.first == command )
+ if( pair.first.join(" ") == command )
{
m_queue.pop_front();
emit built( pair.second );
@@ -107,12 +107,12 @@
}
}
-void MakeBuilder::commandFailed(const QStringList &command)
+void MakeBuilder::commandFailed(const QString &command)
{
if( !m_queue.isEmpty() )
{
QPair<QStringList, KDevelop::ProjectBaseItem*> pair = m_queue.front();
- if( pair.first == command )
+ if( pair.first.join(" ") == command )
{
m_queue.pop_front();
emit failed(pair.second);
--- trunk/KDE/kdevelop/buildtools/builders/makebuilder/makebuilder.h #659879:659880
@@ -54,8 +54,8 @@
void failed( KDevelop::ProjectBaseItem* );
private Q_SLOTS:
- void commandFinished(const QStringList &command);
- void commandFailed(const QStringList &command);
+ void commandFinished(const QString &command);
+ void commandFailed(const QString &command);
private:
QStringList buildCommand(KDevelop::ProjectBaseItem *dom, const QString &target = QString::null);
--- trunk/KDE/kdevelop/buildtools/builders/qmakebuilder/qmakebuilder.cpp #659879:659880
@@ -59,10 +59,10 @@
KDevelop::IOutputView* view = i->extension<KDevelop::IOutputView>();
if( view )
{
- connect(i, SIGNAL(commandFinished(const QStringList &)),
- this, SLOT(commandFinished(const QStringList &)));
- connect(i, SIGNAL(commandFailed(const QStringList &)),
- this, SLOT(commandFailed(const QStringList &)));
+ connect(i, SIGNAL(commandFinished(const QString &)),
+ this, SLOT(commandFinished(const QString &)));
+ connect(i, SIGNAL(commandFailed(const QString &)),
+ this, SLOT(commandFailed(const QString &)));
}
}
i = core()->pluginController()->pluginForExtension("org.kdevelop.IMakeBuilder");
@@ -103,7 +103,7 @@
// kDebug(9024) << v << v.type() << v.userType() << endl;
cmd << v.path();
m_queue << QPair<QStringList, KDevelop::ProjectBaseItem*>( cmd, dom );
- view->queueCommand( item->url(), cmd, QStringList() );
+ view->queueCommand( item->url(), cmd, QMap<QString, QString>() );
return true;
}
}
@@ -116,7 +116,7 @@
return false;
}
-void QMakeBuilder::commandFinished(const QStringList &command)
+void QMakeBuilder::commandFinished(const QString &command)
{
kDebug(9024) << "command finished " << command << endl;
if( !m_queue.isEmpty() )
@@ -124,7 +124,7 @@
kDebug(9024) << "queue not empty" << endl;
QPair< QStringList, KDevelop::ProjectBaseItem* > pair = m_queue.front();
- if( pair.first == command )
+ if( pair.first.join(" ") == command )
{
kDebug(9024) << "found command" << endl;
m_queue.pop_front();
@@ -143,12 +143,12 @@
}
}
-void QMakeBuilder::commandFailed(const QStringList &command)
+void QMakeBuilder::commandFailed(const QString &command)
{
if( !m_queue.isEmpty() )
{
QPair<QStringList, KDevelop::ProjectBaseItem*> pair = m_queue.front();
- if( pair.first == command )
+ if( pair.first.join(" ") == command )
{
m_queue.pop_front();
emit failed(pair.second);
--- trunk/KDE/kdevelop/buildtools/builders/qmakebuilder/qmakebuilder.h #659879:659880
@@ -50,8 +50,8 @@
void built(KDevelop::ProjectBaseItem*);
void failed(KDevelop::ProjectBaseItem*);
private Q_SLOTS:
- void commandFinished(const QStringList &command);
- void commandFailed(const QStringList &command);
+ void commandFinished(const QString &command);
+ void commandFailed(const QString &command);
private:
QList< QPair< QStringList, KDevelop::ProjectBaseItem*> > m_queue;
--- trunk/KDE/kdevelop/lib/plugins/outputviews/CMakeLists.txt #659879:659880
@@ -9,6 +9,8 @@
set(simpleoutputview_LIB_SRCS
simpleoutputview.cpp
+ outputviewcommand.cpp
+ outputwidget.cpp
)
kde4_automoc(${simpleoutputview_LIB_SRCS})
--- trunk/KDE/kdevelop/lib/plugins/outputviews/interfaces/ioutputview.h #659879:659880
@@ -25,6 +25,7 @@
class KUrl;
class QString;
+template <typename T1, typename T2> class QMap;
/**
@author Andreas Pakulat
@@ -33,18 +34,16 @@
{
// Idea for later: Let the output view work on executable commands
-// class ExecutableCommand
+// class IExecutableCommand
// {
// public:
-// ExecutableCommand();
-// void setWorkingDir(const KUrl&);
-// void setCommandList(const QStringList&);
-// void setEnvironment(const QStringList&);
-// QStringList environment() const;
-// QStringList commandlist() const;
-// KUrl workingDirectory() const;
-// private:
-// struct ExecutableCommandPrivate* const d;
+// virtual ~IExecutableCommand(){}
+// virtual void setWorkingDir(const KUrl&) = 0;
+// virtual void setCommandList(const QStringList&) = 0;
+// virtual void setEnvironment(const QMap<QString, QString>&) = 0;
+// virtual QMap<QString, QString> environment() const = 0;
+// virtual QStringList commandlist() const = 0;
+// virtual KUrl workingDirectory() const = 0;
// };
class IOutputView
@@ -54,11 +53,27 @@
virtual ~IOutputView() {}
public:
- virtual void queueCommand( const KUrl&, const QStringList&, const QStringList& ) = 0;
+ /**
+ * Execute the Command in a K3Process and capture the output in
+ * a new tab with the command as title
+ */
+ virtual void queueCommand( const KUrl& workingdir, const QStringList&, const QMap<QString, QString>& ) = 0;
+ /**
+ * Register a new Tab for Outputting logging information, this can be used
+ * for example to log things that the VCS plugin does
+ */
+ virtual void registerLogView( const QString& title ) = 0;
+
+ /**
+ * Add the line or lines to the registered tab identified via title
+ */
+ virtual void appendLine( const QString& title, const QString& line ) = 0;
+ virtual void appendLines( const QString& title, const QStringList& lines ) = 0;
+
Q_SIGNALS:
- virtual void commandFinished( const QStringList& ) = 0;
- virtual void commandFailed( const QStringList& ) = 0;
+ virtual void commandFinished( const QString& ) = 0;
+ virtual void commandFailed( const QString& ) = 0;
};
}
KDEV_DECLARE_EXTENSION_INTERFACE_NS( KDevelop, IOutputView, "org.kdevelop.IOutputView" )
--- trunk/KDE/kdevelop/lib/plugins/outputviews/simpleoutputview.cpp #659879:659880
@@ -19,9 +19,9 @@
*/
#include "simpleoutputview.h"
+#include "outputwidget.h"
+#include "outputviewcommand.h"
-#include <config.h>
-
#include <QtCore/QStringList>
#include <QtDesigner/QExtensionFactory>
@@ -49,8 +49,7 @@
virtual QWidget* create(QWidget *parent = 0)
{
Q_UNUSED(parent)
- QListView* l = new QListView(parent);
- l->setModel( m_part->model() );
+ OutputWidget* l = new OutputWidget( parent, m_part);
return l;
}
virtual Qt::DockWidgetArea defaultPosition(const QString &/*areaName*/)
@@ -63,117 +62,78 @@
class SimpleOutputViewPrivate
{
- Q_DECLARE_PUBLIC( SimpleOutputView )
- SimpleOutputView* q_ptr;
public:
SimpleOutputViewViewFactory* m_factory;
- QStandardItemModel* m_model;
- QList<QPair<KUrl, QStringList> > m_jobs;
- K3Process* m_childProc;
- QStringList m_currentCmd;
- bool isRunning()
- {
- return (m_childProc->isRunning());
- }
- void startNextJob()
- {
- if( m_jobs.isEmpty() )
- return;
- m_model->clear();
- m_childProc->clearArguments();
-// m_childProc->setUseShell( true );
- QPair<KUrl, QStringList> job = m_jobs.takeFirst();
- m_childProc->setWorkingDirectory( job.first.path() );
- QStringList l = job.second;
- m_currentCmd = job.second;
-// QString cmd = l.takeFirst();
- QStandardItem* i = new QStandardItem( m_currentCmd.join(" ") );
- m_model->appendRow( i );
- foreach(QString s, l)
- if( !s.isEmpty() )
- *m_childProc << s;
- m_childProc->start( K3Process::OwnGroup, K3Process::AllOutput );
- if( !isRunning() )
- kDebug(9000) << "Couldn't start process" << endl;
- }
- void procReadStdout(K3Process* proc, char* buf, int len)
- {
- QString txt = QString::fromLocal8Bit( buf, len );
- QStringList l = txt.split("\n");
- foreach( QString s, l )
- {
- m_model->appendRow( new QStandardItem( s ) );
- }
- }
+ QMap<QString, QStandardItemModel* > m_models;
+ QMap<QString, OutputViewCommand* > m_jobs;
- void procReadStderr(K3Process* proc, char* buf, int len)
- {
- QString txt = QString::fromLocal8Bit( buf, len );
- QStringList l = txt.split("\n");
- foreach( QString s, l )
- {
- m_model->appendRow( new QStandardItem( s ) );
- }
- }
-
- void procFinished( K3Process* proc )
- {
- Q_Q(SimpleOutputView);
- if( !proc->exitStatus() )
- {
- QStandardItem* endItem = new QStandardItem(QString("Finished (%1)").arg(proc->exitStatus()) );
- m_model->appendRow( endItem );
- kDebug(9004) << "Finished Sucessfully" << endl;
- emit q->commandFinished( m_currentCmd );
- }
- else
- {
- QStandardItem* endItem = new QStandardItem(QString("Failed (%1)").arg(proc->exitStatus()));
- m_model->appendRow( endItem );
- kDebug(9004) << "Failed" << endl;
- emit q->commandFailed( m_currentCmd );
- }
- QTimer::singleShot(0, q, SLOT( startNextJob() ) );
- }
};
SimpleOutputView::SimpleOutputView(QObject *parent, const QStringList &)
: KDevelop::IPlugin(SimpleOutputViewFactory::componentData(), parent),
d(new SimpleOutputViewPrivate)
{
- d->q_ptr = this;
KDEV_USE_EXTENSION_INTERFACE( KDevelop::IOutputView )
- d->m_model = new QStandardItemModel( this );
- d->m_childProc = new K3Process( this );
d->m_factory = new SimpleOutputViewViewFactory( this );
core()->uiController()->addToolView( "Output View", d->m_factory );
- connect( d->m_childProc, SIGNAL(receivedStdout(K3Process* , char*, int) ), this, SLOT( procReadStdout(K3Process* , char*, int) ) );
- connect( d->m_childProc, SIGNAL(receivedStderr(K3Process* , char*, int) ), this, SLOT( procReadStderr(K3Process* , char*, int) ) );
- connect( d->m_childProc, SIGNAL(processExited( K3Process* ) ),
- this, SLOT( procFinished( K3Process* ) ) );
+
}
SimpleOutputView::~SimpleOutputView()
{
+ foreach( QStandardItemModel* m, d->m_models )
+ delete m;
+ foreach( OutputViewCommand* o, d->m_jobs )
+ delete o;
delete d;
}
-QStandardItemModel* SimpleOutputView::model()
+void SimpleOutputView::queueCommand(const KUrl& dir, const QStringList& command, const QMap<QString, QString>& env )
{
- return d->m_model;
+ if( command.isEmpty() )
+ return;
+ kDebug(9004) << "Queueing Command: " << dir << "|" << command << endl;
+ QString title = command.first();
+ if( !d->m_jobs.contains(title) )
+ {
+ QStandardItemModel* model = new QStandardItemModel();
+ OutputViewCommand* cmd = new OutputViewCommand( dir, command, env, model );
+ connect( cmd, SIGNAL( commandFinished( const QString& ) ),
+ this, SIGNAL( commandFinished( const QString& ) ) );
+ connect( cmd, SIGNAL( commandFailed( const QString& ) ),
+ this, SIGNAL( commandFailed( const QString& ) ) );
+
+ d->m_jobs[title] = cmd;
+ emit modelAdded( title, model );
+ d->m_jobs[title]->start();
+ }
}
-void SimpleOutputView::queueCommand(const KUrl& dir, const QStringList& command, const QStringList& env )
+void SimpleOutputView::registerLogView( const QString& title )
{
- Q_UNUSED(env)
- kDebug(9004) << "Queueing Command: " << dir << "|" << command << endl;
- d->m_jobs.append(QPair<KUrl,QStringList>(dir,command));
- if( !d->isRunning() )
+ if( !d->m_models.contains( title ) )
{
- d->startNextJob();
+ d->m_models[title] = new QStandardItemModel(this);
+ emit modelAdded( title, d->m_models[title] );
}
}
+void SimpleOutputView::appendLine( const QString& title, const QString& line )
+{
+ if( d->m_models.contains( title ) )
+ {
+ d->m_models[title]->appendRow( new QStandardItem( line ) );
+ }
+}
+void SimpleOutputView::appendLines( const QString& title, const QStringList& lines )
+{
+ if( d->m_models.contains( title ) )
+ {
+ foreach( QString line, lines )
+ d->m_models[title]->appendRow( new QStandardItem( line ) );
+ }
+}
+
#include "simpleoutputview.moc"
// kate: space-indent on; indent-width 4; tab-width: 4; replace-tabs on; auto-insert-doxygen on
--- trunk/KDE/kdevelop/lib/plugins/outputviews/simpleoutputview.h #659879:659880
@@ -23,7 +23,6 @@
#include "ioutputview.h"
#include "iplugin.h"
-#include <QtCore/QProcess>
class QStringList;
class QStandardItemModel;
@@ -34,6 +33,7 @@
/**
@author Andreas Pakulat
*/
+
class SimpleOutputView : public KDevelop::IPlugin, public KDevelop::IOutputView
{
Q_OBJECT
@@ -42,19 +42,18 @@
public:
SimpleOutputView(QObject *parent = 0, const QStringList &args = QStringList());
virtual ~SimpleOutputView();
- void queueCommand(const KUrl& dir, const QStringList& command, const QStringList& env );
+ void queueCommand(const KUrl& dir, const QStringList& command, const QMap<QString, QString>& env );
- QStandardItemModel* model();
+ void registerLogView( const QString& title );
+ void appendLine( const QString& title, const QString& line );
+ void appendLines( const QString& title, const QStringList& line );
Q_SIGNALS:
- void commandFinished( const QStringList& command );
- void commandFailed( const QStringList& command );
+ void commandFinished( const QString& command );
+ void commandFailed( const QString& command );
+ void modelAdded( const QString&, QStandardItemModel* );
private:
- Q_PRIVATE_SLOT( d, void procReadStdout(K3Process* proc, char*, int) )
- Q_PRIVATE_SLOT( d, void procReadStderr(K3Process* proc, char*, int) )
- Q_PRIVATE_SLOT( d, void startNextJob() )
- Q_PRIVATE_SLOT( d, void procFinished( K3Process* ) )
class SimpleOutputViewPrivate* const d;
friend class SimpleOutputViewPrivate;
};
More information about the KDevelop-devel
mailing list