KDevelop API Documentation

cvslogpage.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 200?-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 <qtextbrowser.h>
00013 #include <qlayout.h>
00014 #include <qregexp.h>
00015 #include <qdir.h>
00016 #include <qstringlist.h>
00017 
00018 #include <kmessagebox.h>
00019 #include <kcursor.h>
00020 #include <klocale.h>
00021 #include <kdebug.h>
00022 #include <dcopref.h>
00023 
00024 #include <cvsjob_stub.h>
00025 #include <cvsservice_stub.h>
00026 
00027 #include "cvsoptions.h"
00028 #include "cvslogpage.h"
00029 #include "cvsdiffpage.h"
00030 
00032 // class CVSLogPage
00034 
00035 CVSLogPage::CVSLogPage( CvsService_stub *cvsService, QWidget *parent, const char *name, int )
00036     : DCOPObject( "CvsLogPageDCOPIface" ),
00037     QWidget( parent, name? name : "logformpage" ),
00038     m_cvsService( cvsService ), m_cvsLogJob( 0 )
00039 {
00040     QLayout *thisLayout = new QVBoxLayout( this );
00041 
00042     m_textBrowser = new QTextBrowser( this, "logbrowser" );
00043     thisLayout->add( m_textBrowser );
00044 
00046     m_textBrowser->setMinimumWidth(fontMetrics().maxWidth()*40);
00047     m_textBrowser->setMinimumHeight(fontMetrics().maxWidth()*43);
00048 
00049     connect( m_textBrowser, SIGNAL(linkClicked( const QString& )), this, SLOT(slotLinkClicked( const QString& )) );
00050 }
00051 
00053 
00054 CVSLogPage::~CVSLogPage()
00055 {
00056     kdDebug(9006) << "CVSLogPage::~CVSLogPage()" << endl;
00057     cancel();
00058     delete m_cvsLogJob;
00059 }
00060 
00062 
00063 void CVSLogPage::startLog( const QString &workDir, const QString &pathName )
00064 {
00065     kdDebug(9006) << "CVSLogPage::start() here! workDir = " << workDir <<
00066         ", pathName = " << pathName << endl;
00067 
00068 //    CvsOptions *options = CvsOptions::instance();
00069     // "cvs log" needs to be done on relative-path basis
00070     m_pathName = pathName;
00071 
00072     DCOPRef job = m_cvsService->log( pathName );
00073     m_cvsLogJob = new CvsJob_stub( job.app(), job.obj() );
00074 
00075     // establish connections to the signals of the cvs m_job
00076     connectDCOPSignal( job.app(), job.obj(), "jobExited(bool, int)", "slotJobExited(bool, int)", true );
00077     // We'll read the ouput directly from the job ...
00078 //    connectDCOPSignal( job.app(), job.obj(), "receivedStdout(QString)", "slotReceivedOutput(QString)", true );
00079 //    connectDCOPSignal( job.app(), job.obj(), "receivedStderr(QString)", "slotReceivedErrors(QString)", true );
00080 
00081     kdDebug(9006) << "Running: " << m_cvsLogJob->cvsCommand() << endl;
00082     m_cvsLogJob->execute();
00083 }
00084 
00086 /*
00087 void CVSLogPage::parseLogContent( const QString& text )
00088 {
00089     kdDebug(9006) << "CVSLogPage::parseLogContent()" << endl;
00090 
00091     m_base->contents->clear();
00092 
00093     QStringList l = QStringList::split( "----------------------------", text );
00094     QString header = l.front();
00095     l.pop_front();
00096 
00097     for( QStringList::Iterator it=l.begin(); it!=l.end(); ++it )
00098     {
00099         const QString &s = *it;
00100         if (s)
00101         {
00102             m_base->contents->append( s );
00103             m_base->contents->append( "<hr>" );
00104         }
00105     }
00106 }
00107 */
00109 
00110 void CVSLogPage::slotJobExited( bool normalExit, int exitStatus )
00111 {
00112 //    m_part->core()->running( m_part, false );
00113     if (!normalExit)
00114     {
00115         KMessageBox::sorry( this, i18n("Log failed with exitStatus == %1").arg( exitStatus), i18n("Log Failed") );
00116         return;
00117     }
00118 
00119     static QRegExp rx_sep( "\\-+" );
00120     static QRegExp rx_sep2( "=+" );
00121     static QRegExp rx_date( "date: .* author: .* state: .* lines: .*" );
00122     // "revision" followed by one or more decimals followed by a optional dot
00123     static QRegExp rx_rev( "revision ((\\d+\\.?)+)" );
00124     m_textBrowser->setTextFormat( QTextBrowser::PlainText );
00125 
00126     QStringList lines = m_cvsLogJob->output();
00127     for (size_t i=0; i<lines.count(); ++i) {
00128         QString s = lines[i];
00129         kdDebug(9006) << "Examining line: " << s << endl;
00130         if ( rx_rev.exactMatch(s) )
00131         {
00132             QString ver = rx_rev.cap( 1 );
00133             QString dstr = "<b>" + s + "</b> ";
00134             int lastVer = ver.section( '.', -1 ).toInt() - 1;
00135             if ( lastVer > 0 ) {
00136                 QString lv = ver.left( ver.findRev( "." ) + 1 ) + QString::number( lastVer );
00137                 dstr += " [<a href=\"diff:/" + m_pathName + "/" + lv + "_" + ver + "\">diff to " + lv + "</a>]";
00138             }
00139             m_textBrowser->setTextFormat( QTextBrowser::RichText );
00140             m_textBrowser->append( dstr );
00141             m_textBrowser->setTextFormat( QTextBrowser::PlainText );
00142         }
00143         else if ( rx_date.exactMatch(s) )
00144         {
00145             m_textBrowser->setTextFormat( QTextBrowser::RichText );
00146             m_textBrowser->append( "<i>" + s + "</i>" );
00147             m_textBrowser->setTextFormat( QTextBrowser::PlainText );
00148         }
00149         else if ( rx_sep.exactMatch(s) || rx_sep2.exactMatch(s) )
00150         {
00151             m_textBrowser->append( "\n" );
00152             m_textBrowser->setTextFormat( QTextBrowser::RichText );
00153             m_textBrowser->append( "<hr>" );
00154             m_textBrowser->setTextFormat( QTextBrowser::PlainText );
00155         } else
00156         {
00157             m_textBrowser->append( s );
00158         }
00159     }
00160     m_logTextBackup = m_textBrowser->source();
00161 
00162 //    emit jobFinished( normalExit, exitStatus );
00163 }
00164 
00166 
00167 void CVSLogPage::slotLinkClicked( const QString &link )
00168 {
00169     kdDebug(9006) << "CVSLogPage::slotLinkClicked()" << endl;
00170 
00171     // The text browser clears the page so we go back to our old one
00173     m_textBrowser->setSource( m_logTextBackup );
00174 
00175     QString ver = link.mid( link.findRev( "/" ) + 1 );
00176     QString v1 = ver.section( '_', 0, 0 );
00177     QString v2 = ver.section( '_', 1, 1 );
00178     if ( v1.isEmpty() || v2.isEmpty() )
00179     {
00180         m_textBrowser->append( "invalid link clicked" );
00181         return;
00182     }
00183 
00184     emit diffRequested( m_pathName, v1, v2 );
00185 }
00186 
00188 
00189 void CVSLogPage::slotReceivedOutput( QString someOutput )
00190 {
00191     kdDebug(9006) << "CVSLogPage::slotReceivedOutput(QString)" << endl;
00192 
00193     kdDebug(9006) << "OUTPUT: " << someOutput << endl;
00194 }
00195 
00197 
00198 void CVSLogPage::slotReceivedErrors( QString someErrors )
00199 {
00200     kdDebug(9006) << "ERRORS: " << someErrors << endl;
00201 }
00202 
00204 
00205 void CVSLogPage::cancel()
00206 {
00207     if (m_cvsLogJob && m_cvsLogJob->isRunning())
00208         m_cvsLogJob->cancel();
00209 }
00210 
00211 #include "cvslogpage.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 Tue Feb 22 09:22:43 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003