Commit 8a16ea00 authored by Christian Loose's avatar Christian Loose
Browse files

Separate GUI from functionality for AnnotateDialog

svn path=/trunk/kdesdk/cervisia/; revision=196696
parent a733dc54
2002-12-31 Christian Loose <christian.loose@hamburg.de>
* Separate GUI from functionality for AnnotateDialog
2002-12-29 Christian Loose <christian.loose@hamburg.de>
* Extract AddRepositoryDialog from repositorydlg.cpp
......
......@@ -14,7 +14,7 @@ libcervisiapart_la_SOURCES = updateview.cpp protocolview.cpp watchdlg.cpp \
annotatedlg.cpp annotateview.cpp progressdlg.cpp progressdlg.skel \
cvsprogressdlg.cpp tiplabel.cpp listview.cpp \
cvsdir.cpp repositories.cpp misc.cpp cervisiapart.cpp qttableview.cpp \
addrepositorydlg.cpp
addrepositorydlg.cpp annotatectl.cpp
libcervisiapart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
libcervisiapart_la_LIBADD = $(LIB_KFILE) $(LIB_KPARTS)
......
/*
* Copyright (c) 2002 Christian Loose <christian.loose@hamburg.de>
*
* This program may be distributed under the terms of the Q Public
* License as defined by Trolltech AS of Norway and appearing in the
* file LICENSE.QPL included in the packaging of this file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "annotatectl.h"
#include <qdatetime.h>
#include <qmap.h>
#include <dcopref.h>
#include <klocale.h>
#include <krfcdate.h>
#include "annotatedlg.h"
#include "progressdlg.h"
struct AnnotateController::Private
{
typedef QMap<QString, QString> RevisionCommentMap;
RevisionCommentMap comments; // maps comment to a revision
DCOPRef* cvsService;
AnnotateDialog* dialog;
ProgressDialog* progress;
bool execute(const QString& fileName, const QString& revision);
void parseCvsLogOutput();
void parseCvsAnnotateOutput();
};
AnnotateController::AnnotateController(AnnotateDialog* dialog, DCOPRef* cvsService)
: d(new Private)
{
// initialize private data
d->cvsService = cvsService;
d->dialog = dialog;
d->progress = 0;
}
AnnotateController::~AnnotateController()
{
delete d;
}
void AnnotateController::showDialog(const QString& fileName, const QString& revision)
{
if( !d->execute(fileName, revision) )
{
delete d->dialog;
return;
}
d->parseCvsLogOutput();
d->parseCvsAnnotateOutput();
// hide progress dialog
delete d->progress; d->progress = 0;
d->dialog->setCaption(i18n("CVS Annotate: %1").arg(fileName));
d->dialog->show();
}
bool AnnotateController::Private::execute(const QString& fileName, const QString& revision)
{
DCOPReply job = cvsService->call("annotate(QString, QString)", fileName, revision);
if( !job.isValid() )
return false;
progress = new ProgressDialog(dialog, "Annotate", job, "annotate", i18n("CVS Annotate"));
return progress->execute();
}
void AnnotateController::Private::parseCvsLogOutput()
{
QString line, comment, rev;
enum { Begin, Tags, Admin, Revision,
Author, Branches, Comment, Finished } state;
state = Begin;
while( progress->getLine(line) )
{
switch( state )
{
case Begin:
if( line == "symbolic names:" )
state = Tags;
break;
case Tags:
if( line[0] != '\t' )
state = Admin;
break;
case Admin:
if( line == "----------------------------" )
state = Revision;
break;
case Revision:
rev = line.section(' ', 1, 1);
state = Author;
break;
case Author:
state = Branches;
break;
case Branches:
if( !line.startsWith("branches:") )
{
state = Comment;
comment = line;
}
break;
case Comment:
if( line == "----------------------------" )
state = Revision;
else if( line == "=============================================================================" )
state = Finished;
if( state == Comment )
comment += QString("\n") + line;
else
comments[rev] = comment;
break;
case Finished:
;
}
if (state == Finished)
break;
}
// skip 2 lines
for( int i = 0; i < 2; ++i )
progress->getLine(line);
}
void AnnotateController::Private::parseCvsAnnotateOutput()
{
QDate date;
QString rev, author, content, comment, line;
QString oldRevision = "";
bool odd = false;
while( progress->getLine(line) )
{
QDateTime dt;
dt.setTime_t(KRFCDate::parseDate(line.mid(23, 9)), Qt::UTC);
date = dt.date();
rev = line.left(13).stripWhiteSpace();
author = line.mid(14, 8).stripWhiteSpace();
content = line.mid(35, line.length()-35);
comment = comments[rev];
if( comment.isNull() )
comment = "";
if( rev == oldRevision )
{
author = QString::null;
rev = QString::null;
}
else
{
oldRevision = rev;
odd = !odd;
}
dialog->addLine(rev, author, date, content, comment, odd);
}
}
/*
* Copyright (c) 2002 Christian Loose <christian.loose@hamburg.de>
*
* This program may be distributed under the terms of the Q Public
* License as defined by Trolltech AS of Norway and appearing in the
* file LICENSE.QPL included in the packaging of this file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef ANNOTATECTL_H
#define ANNOTATECTL_H
#include <qstring.h>
class AnnotateDialog;
class DCOPRef;
class QWidget;
class AnnotateController
{
public:
AnnotateController(AnnotateDialog* dialog, DCOPRef* cvsService);
~AnnotateController();
void showDialog(const QString& fileName, const QString& revision = "");
private:
struct Private;
Private* d;
};
#endif
......@@ -14,16 +14,9 @@
#include "annotatedlg.h"
#include <dcopref.h>
#include <kconfig.h>
#include <klocale.h>
#include <kprocess.h>
#include <krfcdate.h>
#include "annotateview.h"
#include "cvsprogressdlg.h"
#include "misc.h"
#include "progressdlg.h"
AnnotateDialog::Options *AnnotateDialog::options = 0;
......@@ -73,239 +66,10 @@ void AnnotateDialog::saveOptions(KConfig *config)
}
bool AnnotateDialog::parseCvsAnnotate(const QString &sandbox, const QString &repository,
const QString &filename, const QString &annorev)
void AnnotateDialog::addLine(const QString &rev, const QString &author, const QDate &date,
const QString &content, const QString &comment, bool odd)
{
QStringList strlist;
QString rev, author, comment, content;
QDate date;
QMap<QString, QString> logmap;
enum { Begin, Tags, Admin, Revision,
Author, Branches, Comment, Finished } state;
setCaption(i18n("CVS Annotate: %1").arg(filename));
QString cmdline = "( ";
cmdline += cvsClient(repository);
cmdline += " log ";
cmdline += KShellProcess::quote(filename);
cmdline += " && ";
cmdline += cvsClient(repository);
cmdline += " annotate ";
if (!annorev.isEmpty())
{
cmdline += " -r ";
cmdline += annorev;
}
cmdline += " ";
cmdline += KShellProcess::quote(filename);
// Hack because the string Annotations for blabla is
// printed to stderr even with option -Q. Arg!
cmdline += " ) 2>&1";
CvsProgressDialog l("Annotate", this);
l.setCaption(i18n("CVS Annotate"));
if (!l.execCommand(sandbox, repository, cmdline, "annotate"))
return false;
//
// First the log output...
//
state = Begin;
QString line;
while (l.getOneLine(&line))
{
switch (state)
{
case Begin:
if (line == "symbolic names:")
state = Tags;
break;
case Tags:
if (line[0] != '\t')
state = Admin;
break;
case Admin:
if (line == "----------------------------")
state = Revision;
break;
case Revision:
strlist = splitLine(line);
rev = strlist[1];
state = Author;
break;
case Author:
state = Branches;
break;
case Branches:
if (line.left(9) != "branches:")
{
state = Comment;
comment = line;
}
break;
case Comment:
if (line == "----------------------------")
state = Revision;
else if (line == "=============================================================================")
state = Finished;
if (state == Comment)
comment += QString("\n") + QString(line);
else
logmap[rev] = comment;
break;
case Finished:
;
}
if (state == Finished)
break;
}
//
// ... then the annotate output.
//
for (int i = 0; i < 2; ++i)
l.getOneLine(&line);
bool odd = false;
QString oldRevision = "";
while ( l.getOneLine(&line) )
{
rev = line.left(13).stripWhiteSpace();
comment = logmap[rev];
author = line.mid(14, 8).stripWhiteSpace();
QDateTime d;
d.setTime_t(KRFCDate::parseDate(line.mid(23, 9)), Qt::UTC);
date = d.date();
content = line.mid(35, line.length()-35);
if (comment.isNull())
comment = "";
if (rev == oldRevision)
{
author = QString::null;
rev = QString::null;
}
else
{
oldRevision = rev;
odd = !odd;
}
annotate->addLine(rev, author, date, content, comment, odd);
}
return true; // successful
}
bool AnnotateDialog::parseCvsAnnotate(DCOPRef& cvsService, const QString& fileName,
const QString& revision)
{
QMap<QString, QString> logmap; // maps comment to a revision
enum { Begin, Tags, Admin, Revision,
Author, Branches, Comment, Finished } state;
setCaption(i18n("CVS Annotate: %1").arg(fileName));
DCOPReply job = cvsService.call("annotate(QString, QString)", fileName,
revision);
if( !job.isValid() )
return false;
ProgressDialog dlg(this, "Annotate", job, "annotate", i18n("CVS Annotate"));
if( !dlg.execute() )
return false;
// process cvs log output
state = Begin;
QString line, comment, rev;
while( dlg.getLine(line) )
{
switch( state )
{
case Begin:
if( line == "symbolic names:" )
state = Tags;
break;
case Tags:
if( line[0] != '\t' )
state = Admin;
break;
case Admin:
if( line == "----------------------------" )
state = Revision;
break;
case Revision:
rev = line.section(' ', 1, 1);
state = Author;
break;
case Author:
state = Branches;
break;
case Branches:
if( !line.startsWith("branches:") )
{
state = Comment;
comment = line;
}
break;
case Comment:
if( line == "----------------------------" )
state = Revision;
else if( line == "=============================================================================" )
state = Finished;
if( state == Comment )
comment += QString("\n") + line;
else
logmap[rev] = comment;
break;
case Finished:
;
}
if (state == Finished)
break;
}
// skip 2 lines
for( int i = 0; i < 2; ++i )
dlg.getLine(line);
// process cvs annotate output
QString author, content;
QDate date;
bool odd = false;
QString oldRevision = "";
while( dlg. getLine(line) )
{
rev = line.left(13).stripWhiteSpace();
comment = logmap[rev];
author = line.mid(14, 8).stripWhiteSpace();
QDateTime d;
d.setTime_t(KRFCDate::parseDate(line.mid(23, 9)), Qt::UTC);
date = d.date();
content = line.mid(35, line.length()-35);
if( comment.isNull() )
comment = "";
if( rev == oldRevision )
{
author = QString::null;
rev = QString::null;
}
else
{
oldRevision = rev;
odd = !odd;
}
annotate->addLine(rev, author, date, content, comment, odd);
}
return true;
annotate->addLine(rev, author, date, content, comment, odd);
}
......
......@@ -21,7 +21,7 @@
class KConfig;
class AnnotateView;
class DCOPRef;
class QDate;
class AnnotateDialog : public KDialogBase
......@@ -32,11 +32,8 @@ public:
virtual ~AnnotateDialog();
bool parseCvsAnnotate(const QString &sandbox, const QString &repository,
const QString &filename, const QString &rev);
bool parseCvsAnnotate(DCOPRef& cvsService, const QString& fileName,
const QString& revision = "");
void addLine(const QString &rev, const QString &author, const QDate &date,
const QString &content, const QString &comment, bool odd);
static void loadOptions(KConfig *config);
static void saveOptions(KConfig *config);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment