KDevelop API Documentation

vcs/cvsservice/cvsprocesswidget.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by KDevelop Authors * 00003 * www.kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include <qpainter.h> 00013 #include <qregexp.h> 00014 00015 #include <dcopref.h> 00016 #include <kstatusbar.h> 00017 #include <kdebug.h> 00018 #include <klocale.h> 00019 #include <kmessagebox.h> 00020 00021 #include "kdevpartcontroller.h" 00022 #include "kdevmainwindow.h" 00023 #include "kdevcore.h" 00024 00025 #include "cvspart.h" 00026 #include "cvsprocesswidget.h" 00027 #include "processwidget.h" 00028 00029 #include <cvsjob_stub.h> 00030 #include <cvsservice_stub.h> 00031 00032 // Undef 00033 //#define MYDCOPDEBUG 00034 00036 // class CvsProcessWidget 00038 00039 #ifdef MYDCOPDEBUG 00040 int g_dcopExitCounter = 0; 00041 int g_dcopOutCounter = 0; 00042 int g_dcopErrCounter = 0; 00043 #endif 00044 00045 00046 CvsProcessWidget::CvsProcessWidget( CvsService_stub *service, CvsServicePart *part, QWidget *parent, const char *name ) 00047 : QTextEdit( parent, name ), 00048 DCOPObject( "CvsProcessWidgetDCOPIface" ), 00049 m_part( part ), m_service( service ), m_job( 0 ) 00050 { 00051 setReadOnly( true ); 00052 setTextFormat( Qt::LogText ); 00053 00054 QStyleSheetItem *style = 0; 00055 style = new QStyleSheetItem( styleSheet(), "goodtag" ); 00056 style->setColor( "black" ); 00057 00058 style = new QStyleSheetItem( styleSheet(), "errortag" ); 00059 style->setColor( "red" ); 00060 style->setFontWeight( QFont::Bold ); 00061 00062 style = new QStyleSheetItem( styleSheet(), "infotag" ); 00063 style->setColor( "blue" ); 00064 00065 style = new QStyleSheetItem( styleSheet(), "cvs_conflict" ); 00066 style->setColor( "red" ); 00067 00068 style = new QStyleSheetItem( styleSheet(), "cvs_added" ); 00069 style->setColor( "green" ); 00070 00071 style = new QStyleSheetItem( styleSheet(), "cvs_removed" ); 00072 style->setColor( "yellow" ); 00073 00074 style = new QStyleSheetItem( styleSheet(), "cvs_updated" ); 00075 style->setColor( "lightblue" ); 00076 00077 style = new QStyleSheetItem( styleSheet(), "cvs_modified" ); 00078 style->setColor( "darkgreen" ); 00079 00080 style = new QStyleSheetItem( styleSheet(), "cvs_unknown" ); 00081 style->setColor( "gray" ); 00082 } 00083 00085 00086 CvsProcessWidget::~CvsProcessWidget() 00087 { 00088 if (m_job) 00089 { 00090 delete m_job; 00091 } 00092 } 00093 00095 00096 bool CvsProcessWidget::isAlreadyWorking() const 00097 { 00098 if (m_job) 00099 return m_job->isRunning(); 00100 else 00101 return false; 00102 } 00103 00105 00106 void CvsProcessWidget::clear() 00107 { 00108 QTextEdit::clear(); 00109 this->m_errors = QString::null; 00110 this->m_output = QString::null; 00111 } 00112 00114 00115 bool CvsProcessWidget::startJob( const DCOPRef &aJob ) 00116 { 00117 kdDebug(9006) << "CvsProcessWidget::startJob(const DCOPRef &) here!" << endl; 00118 00119 clear(); 00120 m_part->mainWindow()->raiseView( this ); 00121 m_part->core()->running( m_part, true ); 00122 00123 // create a DCOP stub for the non-concurrent cvs job 00124 if (m_job) 00125 { 00126 delete m_job; 00127 m_job = 0; 00128 } 00129 m_job = new CvsJob_stub( aJob.app(), aJob.obj() ); 00130 00131 // establish connections to the signals of the cvs m_job 00132 connectDCOPSignal( m_job->app(), m_job->obj(), "jobExited(bool, int)", "slotJobExited(bool, int)", true ); 00133 connectDCOPSignal( m_job->app(), m_job->obj(), "receivedStdout(QString)", "slotReceivedOutput(QString)", true ); 00134 connectDCOPSignal( m_job->app(), m_job->obj(), "receivedStderr(QString)", "slotReceivedErrors(QString)", true ); 00135 00136 // get command line and add it to output buffer 00137 QString cmdLine = m_job->cvsCommand(); 00138 m_part->mainWindow()->statusBar()->message( cmdLine ); 00139 00140 kdDebug(9006) << "Running: " << cmdLine << endl; 00141 00142 // disconnect 3rd party slots from our signals 00143 disconnect( SIGNAL(jobFinished(bool, int)) ); 00144 00145 showInfo( i18n("Started job: ") + cmdLine ); 00146 00147 #ifdef MYDCOPDEBUG 00148 g_dcopExitCounter = 0; 00149 g_dcopOutCounter = 0; 00150 g_dcopErrCounter = 0; 00151 #endif 00152 00153 return m_job->execute(); 00154 } 00155 00157 00158 void CvsProcessWidget::cancelJob() 00159 { 00160 kdDebug(9006) << "CvsProcessWidget::cancelJob() here!" << endl; 00161 00162 if (!m_job || !m_job->isRunning()) 00163 return; 00164 m_job->cancel(); 00165 delete m_job; m_job = 0; 00166 00167 showInfo( i18n("*** Job canceled by user request ***") ); 00168 00169 m_part->core()->running( m_part, false ); 00170 } 00171 00173 00174 void CvsProcessWidget::slotJobExited( bool normalExit, int exitStatus ) 00175 { 00176 kdDebug(9006) << "CvsProcessWidget::slotJobExited(bool, int) here!" << endl; 00177 #ifdef MYDCOPDEBUG 00178 g_dcopExitCounter++; 00179 kdDebug(9006) << "MYDCOPDEBUG: dcopExitCounter == " << g_dcopExitCounter << endl; 00180 #endif 00181 if (m_job) 00182 { 00183 disconnectDCOPSignal( m_job->app(), m_job->obj(), "jobExited(bool, int)", "slotJobExited(bool, int)" ); 00184 disconnectDCOPSignal( m_job->app(), m_job->obj(), "receivedStdout(QString)", "slotReceivedOutput(QString)" ); 00185 disconnectDCOPSignal( m_job->app(), m_job->obj(), "receivedStderr(QString)", "slotReceivedErrors(QString)" ); 00186 delete m_job; 00187 m_job = 0; 00188 } 00189 QString exitMsg = i18n("Job finished with exitCode == %1"); 00190 showInfo( exitMsg.arg( exitStatus) ); 00191 00192 m_part->core()->running( m_part, false ); 00193 m_part->mainWindow()->statusBar()->message( i18n("Done CVS command ..."), 2000 ); 00194 00195 emit jobFinished( normalExit, exitStatus ); 00196 } 00197 00199 00200 void CvsProcessWidget::slotReceivedOutput( QString someOutput ) 00201 { 00202 kdDebug(9006) << "CvsProcessWidget::slotReceivedOutput(QString) here!" << endl; 00203 #ifdef MYDCOPDEBUG 00204 g_dcopOutCounter++; 00205 kdDebug(9006) << "MYDCOPDEBUG: dcopOutCounter == " << g_dcopOutCounter << endl; 00206 #endif 00207 00208 QStringList strings = m_outputBuffer.process( someOutput ); 00209 if (strings.count() > 0) 00210 { 00211 m_output += strings; 00212 showOutput( strings ); 00213 scrollToBottom(); 00214 } 00215 } 00216 00218 00219 void CvsProcessWidget::slotReceivedErrors( QString someErrors ) 00220 { 00221 kdDebug(9006) << "CvsProcessWidget::slotReceivedErrors(QString) here!" << endl; 00222 #ifdef MYDCOPDEBUG 00223 g_dcopErrCounter++; 00224 kdDebug(9006) << "MYDCOPDEBUG: dcopErrCounter == " << g_dcopErrCounter << endl; 00225 #endif 00226 00227 QStringList strings = m_errorBuffer.process( someErrors ); 00228 if (strings.count() > 0) 00229 { 00230 m_errors += strings; 00231 showError( strings ); 00232 scrollToBottom(); 00233 } 00234 } 00235 00237 00238 void CvsProcessWidget::showInfo( const QStringList &msg ) 00239 { 00240 for (QStringList::const_iterator it = msg.begin(); it != msg.end(); ++it) 00241 append( "<infotag>" + (*it) + "</infotag>" ); 00242 } 00243 00245 00246 void CvsProcessWidget::showError( const QStringList &msg ) 00247 { 00248 for (QStringList::const_iterator it = msg.begin(); it != msg.end(); ++it) 00249 append( "<errortag>" + (*it) + "</errortag>" ); 00250 } 00251 00253 00254 void CvsProcessWidget::showOutput( const QStringList &msg ) 00255 { 00256 for (QStringList::const_iterator it = msg.begin(); it != msg.end(); ++it) 00257 { 00258 // @todo here we can interpret lines as [C], [M], ... 00259 const QString &line = (*it); 00260 00261 if (line.startsWith( "C " )) 00262 append( "<cvs_conflict>" + line + "</cvs_conflict>" ); 00263 else if (line.startsWith( "M " )) 00264 append( "<cvs_modified>" + line + "</cvs_modified>" ); 00265 else if (line.startsWith( "A " )) 00266 append( "<cvs_added>" + line + "</cvs_added>" ); 00267 else if (line.startsWith( "R " )) 00268 append( "<cvs_removed>" + line + "</cvs_removed>" ); 00269 else if (line.startsWith( "U " )) 00270 append( "<cvs_updated>" + line + "</cvs_updated>" ); 00271 else if (line.startsWith( "? " )) 00272 append( "<cvs_unknown>" + line + "</cvs_unknown>" ); 00273 else // default 00274 append( "<goodtag>" + (*it) + "</goodtag>" ); 00275 } 00276 } 00277 00278 #include "cvsprocesswidget.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 Tue Oct 19 08:01:53 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003