00001
00002
00003
00004
00005
00006
00007
00008
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
00034
00035 CVSLogPage::CVSLogPage( CvsService_stub *cvsService,
QWidget *parent,
const char *name,
int )
00036 :
QWidget( parent, name? name : "logformpage" ),
00037
DCOPObject( "CvsLogPageDCOPIface" ),
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
00069
00070
m_pathName = pathName;
00071
00072
DCOPRef job =
m_cvsService->log( pathName );
00073
m_cvsLogJob =
new CvsJob_stub( job.
app(), job.
obj() );
00074
00075
00076 connectDCOPSignal( job.
app(), job.
obj(),
"jobExited(bool, int)",
"slotJobExited(bool, int)",
true );
00077
00078
00079
00080
00081
kdDebug(9006) <<
"Running: " <<
m_cvsLogJob->cvsCommand() <<
endl;
00082
m_cvsLogJob->execute();
00083 }
00084
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00109
00110 void CVSLogPage::slotJobExited(
bool normalExit,
int exitStatus )
00111 {
00112
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
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
00163 }
00164
00166
00167 void CVSLogPage::slotLinkClicked(
const QString &link )
00168 {
00169
kdDebug(9006) <<
"CVSLogPage::slotLinkClicked()" <<
endl;
00170
00171
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"