summaryrefslogtreecommitdiffstats
path: root/vcs/cvsservice/cvslogpage.cpp
blob: cf8645e9b1ba4ec9b1220227c94bc873b004de8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/***************************************************************************
 *   Copyright (C) 200?-2003 by KDevelop Authors                           *
 *   www.kdevelop.org                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qtextbrowser.h>
#include <qlayout.h>
#include <qregexp.h>
#include <qdir.h>
#include <qstringlist.h>

#include <kmessagebox.h>
#include <kcursor.h>
#include <klocale.h>
#include <kdebug.h>
#include <dcopref.h>

#include <cvsjob_stub.h>
#include <cvsservice_stub.h>

#include "cvsoptions.h"
#include "cvslogpage.h"
#include "cvsdiffpage.h"

///////////////////////////////////////////////////////////////////////////////
// class CVSLogPage
///////////////////////////////////////////////////////////////////////////////

CVSLogPage::CVSLogPage( CvsService_stub *cvsService, QWidget *parent, const char *name, int )
    : DCOPObject( "CvsLogPageDCOPIface" ),
	QWidget( parent, name? name : "logformpage" ),
    m_cvsService( cvsService ), m_cvsLogJob( 0 )
{
    QLayout *thisLayout = new QVBoxLayout( this );

    m_textBrowser = new QTextBrowser( this, "logbrowser" );
    thisLayout->add( m_textBrowser );

    /// \FIXME a better way?
    m_textBrowser->setMinimumWidth(fontMetrics().width('X')*50);
    m_textBrowser->setMinimumHeight(fontMetrics().width('X')*43);

    connect( m_textBrowser, SIGNAL(linkClicked( const QString& )), this, SLOT(slotLinkClicked( const QString& )) );
}

///////////////////////////////////////////////////////////////////////////////

CVSLogPage::~CVSLogPage()
{
    kdDebug(9006) << "CVSLogPage::~CVSLogPage()" << endl;
    cancel();
    delete m_cvsLogJob;
}

///////////////////////////////////////////////////////////////////////////////

void CVSLogPage::startLog( const QString &workDir, const QString &pathName )
{
    kdDebug(9006) << "CVSLogPage::start() here! workDir = " << workDir <<
        ", pathName = " << pathName << endl;

//    CvsOptions *options = CvsOptions::instance();
    // "cvs log" needs to be done on relative-path basis
    m_pathName = pathName;
	m_diffStrings.clear();

    DCOPRef job = m_cvsService->log( pathName );
    m_cvsLogJob = new CvsJob_stub( job.app(), job.obj() );

    // establish connections to the signals of the cvs m_job
    connectDCOPSignal( job.app(), job.obj(), "jobExited(bool, int)", "slotJobExited(bool, int)", true );
    // We'll read the ouput directly from the job ...
    connectDCOPSignal( job.app(), job.obj(), "receivedStdout(QString)", "slotReceivedOutput(QString)", true );
//    connectDCOPSignal( job.app(), job.obj(), "receivedStderr(QString)", "slotReceivedErrors(QString)", true );

    kdDebug(9006) << "Running: " << m_cvsLogJob->cvsCommand() << endl;
    m_cvsLogJob->execute();
}

///////////////////////////////////////////////////////////////////////////////
/*
void CVSLogPage::parseLogContent( const QString& text )
{
    kdDebug(9006) << "CVSLogPage::parseLogContent()" << endl;

    m_base->contents->clear();

    QStringList l = QStringList::split( "----------------------------", text );
    QString header = l.front();
    l.pop_front();

    for( QStringList::Iterator it=l.begin(); it!=l.end(); ++it )
    {
        const QString &s = *it;
        if (s)
        {
            m_base->contents->append( s );
            m_base->contents->append( "<hr>" );
        }
    }
}
*/
///////////////////////////////////////////////////////////////////////////////

void CVSLogPage::slotJobExited( bool normalExit, int exitStatus )
{
//    m_part->core()->running( m_part, false );
    if (!normalExit)
    {
        KMessageBox::sorry( this, i18n("Log failed with exitStatus == %1").arg( exitStatus), i18n("Log Failed") );
        return;
    }

    static QRegExp rx_sep( "\\-+" );
    static QRegExp rx_sep2( "=+" );
    static QRegExp rx_date( "date: .* author: .* state: .* lines: .*" );
    // "revision" followed by one or more decimals followed by a optional dot
    static QRegExp rx_rev( "revision ((\\d+\\.?)+)" );
    m_textBrowser->setTextFormat( QTextBrowser::PlainText );

    for (size_t i=0; i<m_diffStrings.count(); ++i) {
        QString s = m_diffStrings[i];
        kdDebug(9006) << "Examining line: " << s << endl;
        if ( rx_rev.exactMatch(s) )
        {
            QString ver = rx_rev.cap( 1 );
            QString dstr = "<b>" + s + "</b> ";
            int lastVer = ver.section( '.', -1 ).toInt() - 1;
            if ( lastVer > 0 ) {
                QString lv = ver.left( ver.findRev( "." ) + 1 ) + QString::number( lastVer );
                dstr += " [<a href=\"diff:/" + m_pathName + "/" + lv + "_" + ver + "\">diff to " + lv + "</a>]";
            }
            m_textBrowser->setTextFormat( QTextBrowser::RichText );
            m_textBrowser->append( dstr );
            m_textBrowser->setTextFormat( QTextBrowser::PlainText );
        }
        else if ( rx_date.exactMatch(s) )
        {
            m_textBrowser->setTextFormat( QTextBrowser::RichText );
            m_textBrowser->append( "<i>" + s + "</i>" );
            m_textBrowser->setTextFormat( QTextBrowser::PlainText );
        }
        else if ( rx_sep.exactMatch(s) || rx_sep2.exactMatch(s) )
        {
            m_textBrowser->append( "\n" );
            m_textBrowser->setTextFormat( QTextBrowser::RichText );
            m_textBrowser->append( "<hr>" );
            m_textBrowser->setTextFormat( QTextBrowser::PlainText );
        } else
        {
            m_textBrowser->append( s );
        }
    }
    m_logTextBackup = m_textBrowser->source();

//    emit jobFinished( normalExit, exitStatus );
}

///////////////////////////////////////////////////////////////////////////////

void CVSLogPage::slotLinkClicked( const QString &link )
{
    kdDebug(9006) << "CVSLogPage::slotLinkClicked()" << endl;

    // The text browser clears the page so we go back to our old one
    /// \FIXME in this way I lose the source
    m_textBrowser->setSource( m_logTextBackup );

    QString ver = link.mid( link.findRev( "/" ) + 1 );
    QString v1 = ver.section( '_', 0, 0 );
    QString v2 = ver.section( '_', 1, 1 );
    if ( v1.isEmpty() || v2.isEmpty() )
    {
        m_textBrowser->append( i18n( "invalid link clicked" ) );
        return;
    }

    emit diffRequested( m_pathName, v1, v2 );
}

///////////////////////////////////////////////////////////////////////////////

void CVSLogPage::slotReceivedOutput( QString someOutput )
{
    kdDebug(9006) << "CVSLogPage::slotReceivedOutput(QString)" << endl;

    kdDebug(9006) << "OUTPUT: " << someOutput << endl;
	m_diffStrings += m_outputBuffer.process(someOutput);
}

///////////////////////////////////////////////////////////////////////////////

void CVSLogPage::slotReceivedErrors( QString someErrors )
{
    kdDebug(9006) << "ERRORS: " << someErrors << endl;
}

///////////////////////////////////////////////////////////////////////////////

void CVSLogPage::cancel()
{
    if (m_cvsLogJob && m_cvsLogJob->isRunning())
        m_cvsLogJob->cancel();
}

#include "cvslogpage.moc"