Commit 63a62425 authored by André Wöbbeking's avatar André Wöbbeking

factored out the data for a log info entry into the struct LogInfo.

svn path=/trunk/kdesdk/cervisia/; revision=240735
parent 418dc8ae
......@@ -15,7 +15,7 @@ libcervisiapart_la_SOURCES = updateview.cpp protocolview.cpp protocolview.skel \
cvsprogressdlg.cpp tiplabel.cpp listview.cpp globalconfig.cpp \
cvsdir.cpp repositories.cpp misc.cpp cervisiapart.cpp qttableview.cpp \
addrepositorydlg.cpp annotatectl.cpp addremovedlg.cpp watchersdlg.cpp \
logplainview.cpp
logplainview.cpp loginfo.cpp
libcervisiapart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
libcervisiapart_la_LIBADD = $(LIB_KFILE) $(LIB_KPARTS) -lkutils \
cvsservice/libcvsservice.la
......
......@@ -34,9 +34,10 @@
#include "annotatedlg.h"
#include "annotatectl.h"
#include "diffdlg.h"
#include "loginfo.h"
#include "loglist.h"
#include "logtree.h"
#include "logplainview.h"
#include "logtree.h"
#include "misc.h"
#include "progressdlg.h"
......@@ -199,8 +200,10 @@ LogDialog::~LogDialog()
bool LogDialog::parseCvsLog(CvsService_stub* service, const QString& fileName)
{
QString tag, rev, author, comment;
QDateTime date;
QString rev;
Cervisia::LogInfo logInfo;
enum { Begin, Tags, Admin, Revision,
Author, Branches, Comment, Finished } state;
......@@ -232,10 +235,10 @@ bool LogDialog::parseCvsLog(CvsService_stub* service, const QString& fileName)
case Tags:
if( line[0] == '\t' )
{
QStringList strlist = splitLine(line, ':');
QString rev = strlist[1].simplifyWhiteSpace();
QString tag = strlist[0].simplifyWhiteSpace();
QString branchpoint = "";
const QStringList strlist(splitLine(line, ':'));
rev = strlist[1].simplifyWhiteSpace();
const QString tag(strlist[0].simplifyWhiteSpace());
QString branchpoint;
int pos1, pos2;
if( (pos2 = rev.findRev('.')) > 0 &&
(pos1 = rev.findRev('.', pos2-1)) > 0 &&
......@@ -268,7 +271,7 @@ bool LogDialog::parseCvsLog(CvsService_stub* service, const QString& fileName)
}
break;
case Revision:
rev = line.section(' ', 1, 1);
logInfo.m_revision = rev = line.section(' ', 1, 1);
state = Author;
break;
case Author:
......@@ -277,17 +280,16 @@ bool LogDialog::parseCvsLog(CvsService_stub* service, const QString& fileName)
// convert date in ISO format (YYYY-MM-DDTHH:MM:SS)
strlist[1].replace('/', '-');
strlist[2].truncate(8); // Time foramt is HH:MM:SS
date.setTime_t(KRFCDate::parseDateISO8601(strlist[1] + 'T' + strlist[2]));
author = strlist[4];
author = author.left(author.length()-1);
comment = "";
logInfo.m_dateTime.setTime_t(KRFCDate::parseDateISO8601(strlist[1] + 'T' + strlist[2]));
logInfo.m_author = strlist[4];
logInfo.m_author.truncate(logInfo.m_author.length() - 1); // remove trailing ';'
state = Branches;
}
break;
case Branches:
if( !line.startsWith("branches:") )
{
comment = line;
logInfo.m_comment = line;
state = Comment;
}
break;
......@@ -301,61 +303,48 @@ bool LogDialog::parseCvsLog(CvsService_stub* service, const QString& fileName)
state = Finished;
}
if( state == Comment ) // still in message
comment += QString("\n") + line;
logInfo.m_comment += '\n' + line;
else
{
// Create tagcomment
QString tagcomment, taglist, branchrev;
QString branchrev;
int pos1, pos2;
// 1.60.x.y => revision belongs to branch 1.60.0.x
if( (pos2 = rev.findRev('.')) > 0 &&
(pos1 = rev.findRev('.', pos2-1)) > 0 )
branchrev = rev.left(pos2);
// Build tagcomment and taglist:
// tagcomment contains Tags, Branchpoints and 'On Branch's
// taglist contains tags (without prefix) and Branchpoints
// Build Cervisia::TagInfo for logInfo
QPtrListIterator<TagInfo> it(tags);
for( ; it.current(); ++it )
{
if( rev == it.current()->rev )
{
// This never matches branch tags...
tagcomment += i18n("\nTag: ");
tagcomment += it.current()->tag;
taglist += "\n";
taglist += it.current()->tag;
logInfo.m_tags.push_back(Cervisia::TagInfo(it.current()->tag,
Cervisia::TagInfo::Tag));
}
if( rev == it.current()->branchpoint )
{
tagcomment += i18n("\nBranchpoint: ");
tagcomment += it.current()->tag;
taglist += i18n("\nBranchpoint: ");
taglist += it.current()->tag;
logInfo.m_tags.push_back(Cervisia::TagInfo(it.current()->tag,
Cervisia::TagInfo::Branch));
}
if( branchrev == it.current()->rev )
{
// ... and this never matches ordinary tags :-)
tagcomment += i18n("\nOn branch: ");
tagcomment += it.current()->tag;
logInfo.m_tags.push_back(Cervisia::TagInfo(it.current()->tag,
Cervisia::TagInfo::OnBranch));
}
}
// remove leading '\n'
if( !tagcomment.isEmpty() )
tagcomment.remove(0, 1);
if( !taglist.isEmpty() )
taglist.remove(0, 1);
plain->addRevision(rev, author, date, comment, tagcomment);
tree->addRevision(rev, author, date, comment, taglist, tagcomment);
list->addRevision(rev, author, date, comment, tagcomment);
RevisionInfo *item = new RevisionInfo;
item->rev = rev;
item->author = author;
item->date = date;
item->comment = comment;
item->tagcomment = tagcomment;
items.append(item);
plain->addRevision(logInfo);
tree->addRevision(logInfo);
list->addRevision(logInfo);
items.append(new Cervisia::LogInfo(logInfo));
// reset for next entry
logInfo = Cervisia::LogInfo();
}
break;
case Finished:
......@@ -363,8 +352,8 @@ bool LogDialog::parseCvsLog(CvsService_stub* service, const QString& fileName)
}
}
tagcombo[0]->insertItem("");
tagcombo[1]->insertItem("");
tagcombo[0]->insertItem(QString::null);
tagcombo[1]->insertItem(QString::null);
QPtrListIterator<TagInfo> it(tags);
for( ; it.current(); ++it )
{
......@@ -421,9 +410,9 @@ void LogDialog::annotateClicked()
void LogDialog::revisionSelected(QString rev, bool rmb)
{
QPtrListIterator<RevisionInfo> it(items);
QPtrListIterator<Cervisia::LogInfo> it(items);
for (; it.current(); ++it)
if (it.current()->rev == rev)
if (it.current()->m_revision == rev)
{
if (rmb)
selectionB = rev;
......@@ -431,10 +420,10 @@ void LogDialog::revisionSelected(QString rev, bool rmb)
selectionA = rev;
revbox[rmb?1:0]->setText(rev);
authorbox[rmb?1:0]->setText(it.current()->author);
datebox[rmb?1:0]->setText(KGlobal::locale()->formatDateTime(it.current()->date));
commentbox[rmb?1:0]->setText(it.current()->comment);
tagsbox[rmb?1:0]->setText(it.current()->tagcomment);
authorbox[rmb?1:0]->setText(it.current()->m_author);
datebox[rmb?1:0]->setText(it.current()->dateTimeToString());
commentbox[rmb?1:0]->setText(it.current()->m_comment);
tagsbox[rmb?1:0]->setText(it.current()->tagsToString());
tree->setSelectedPair(selectionA, selectionB);
list->setSelectedPair(selectionA, selectionB);
......
......@@ -17,7 +17,8 @@
#include <kdialogbase.h>
#include <qdatetime.h>
#include "loginfo.h"
#include <qptrlist.h>
......@@ -33,17 +34,6 @@ class QTabWidget;
class QTextEdit;
class CvsService_stub;
class RevisionInfo
{
public:
QString rev;
QString author;
QDateTime date;
QString comment;
QString tagcomment;
};
class TagInfo
{
public:
......@@ -77,7 +67,7 @@ private:
void tagSelected(TagInfo* tag, bool rmb);
QString filename;
QPtrList<RevisionInfo> items;
QPtrList<Cervisia::LogInfo> items;
QPtrList<TagInfo> tags;
QString selectionA;
QString selectionB;
......
/*
* Copyright (c) 2003 Andr Wbbeking <Woebbeking@web.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 "loginfo.h"
#include <qstylesheet.h>
#include <kglobal.h>
#include <klocale.h>
namespace Cervisia
{
TagInfo::TagInfo(const QString& name, Type type)
: m_name(name),
m_type(type)
{
}
QString TagInfo::toString(bool prefixWithType) const
{
QString text;
if (prefixWithType)
{
text += typeToString() + QString::fromLatin1(": ");
}
text += m_name;
return text;
}
QString TagInfo::typeToString() const
{
QString text;
switch (m_type)
{
case Branch:
text = i18n("Branchpoint");
break;
case OnBranch:
text = i18n("On Branch");
break;
case Tag:
text = i18n("Tag");
break;
}
return text;
}
QString LogInfo::createToolTipText() const
{
QString text(QString::fromLatin1("<b>"));
text += QStyleSheet::escape(m_revision);
text += QString::fromLatin1("</b>&nbsp;&nbsp;");
text += QStyleSheet::escape(m_author);
text += QString::fromLatin1("&nbsp;&nbsp;<b>");
text += QStyleSheet::escape(dateTimeToString());
text += QString::fromLatin1("</b>");
if (!m_comment.isEmpty())
{
text += QString::fromLatin1("<pre>");
text += m_comment;
text += QString::fromLatin1("</pre>");
}
if (!m_tags.isEmpty())
{
text += QString::fromLatin1("<i>");
for (TTagInfoSeq::const_iterator it = m_tags.begin();
it != m_tags.end(); ++it)
{
if (it != m_tags.begin() || m_comment.isEmpty())
text += QString::fromLatin1("<br>");
text += QStyleSheet::escape((*it).toString());
}
text += QString::fromLatin1("</i>");
}
return text;
}
QString LogInfo::dateTimeToString(bool shortFormat) const
{
return KGlobal::locale()->formatDateTime(m_dateTime, shortFormat);
}
QString LogInfo::tagsToString(unsigned int types,
unsigned int prefixWithType,
const QString& separator) const
{
QString text;
for (TTagInfoSeq::const_iterator it = m_tags.begin();
it != m_tags.end(); ++it)
{
const TagInfo& tagInfo(*it);
if (tagInfo.m_type & types)
{
if (!text.isEmpty())
{
text += separator;
}
text += tagInfo.toString(tagInfo.m_type & prefixWithType);
}
}
return text;
}
} // namespace Cervisia
/*
* Copyright (c) 2003 André Wöbbeking <Woebbeking@web.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 CERVISIA_MISC_H
#define CERVISIA_MISC_H
#include <qdatetime.h>
#include <qstring.h>
#include <qvaluelist.h>
namespace Cervisia
{
/**
* Dumb data struct to store informations of a tag plus some
* convenience methods. The struct is used by the LogInfo struct.
*/
struct TagInfo
{
/**
* The types of a tag.
*/
enum Type
{
/**
* Branchpoint.
*/
Branch = 1 << 0,
/**
* This type is for internal use. If the revision is in a branch
* this tag represents the branch.
*/
OnBranch = 1 << 1,
/**
* Normal tag.
*/
Tag = 1 << 2
};
explicit TagInfo(const QString& name = QString::null, Type type = Tag);
/**
* @param prefixWithType prefix the string with the type of the tag
* (e.g. Tag: KDE_3_1_3_RELEASE).
*
* @return tag as string.
*/
QString toString(bool prefixWithType = true) const;
/**
* @return type of tag as string.
*/
QString typeToString() const;
/**
* The name of the tag.
*/
QString m_name;
/**
* The type of the tag.
*/
Type m_type;
};
/**
* Dumb data struct to store the results of the log command plus some
* convenience methods.
*/
struct LogInfo
{
typedef QValueList<TagInfo> TTagInfoSeq;
/**
* @return rich text formatted tooltip text.
*/
QString createToolTipText() const;
/**
* Calls KLocale::formatDateTime() to create a formatted string.
*
* @param shortFormat using the short date format.
*
* @return The date/time formatted to the user's locale's conventions.
*/
QString dateTimeToString(bool shortFormat = true) const;
enum
{
NoTagType = 0,
AllTagTypes = TagInfo::Branch | TagInfo::OnBranch | TagInfo::Tag
};
/**
* Creates a single string from alls tags.
*
* @param types tags that should be taken into account.
* @param prefixWithType tags that should be prefixed with their type
* (see TagInfo::toString()).
* @param separator string to separate the tags.
*
* @return string of joined tags.
*/
QString tagsToString(unsigned int types = AllTagTypes,
unsigned int prefixWithType = AllTagTypes,
const QString& separator = QString(QChar('\n'))) const;
/**
* The revision of this entry.
*/
QString m_revision;
/**
* The author who committed.
*/
QString m_author;
/**
* The commit message.
*/
QString m_comment;
/**
* The date/time of the commit.
*/
QDateTime m_dateTime;
/**
* Sequence of tags of this entry.
*/
TTagInfoSeq m_tags;
};
} // namespace Cervisia
#endif // CERVISIA_MISC_H
......@@ -15,14 +15,12 @@
#include "loglist.h"
#include <qapplication.h>
#include <qdatetime.h>
#include <qkeycode.h>
#include <qstylesheet.h>
#include <kglobal.h>
#include <klocale.h>
#include "tiplabel.h"
#include "loginfo.h"
#include "misc.h"
#include "tiplabel.h"
class LogListViewItem : public KListViewItem
......@@ -31,31 +29,41 @@ public:
enum { Revision, Author, Date, Branch, Comment, Tags };
LogListViewItem(QListView *list,
const QString &rev, const QString &author, const QDateTime &date,
const QString &comment, const QString &tagcomment);
LogListViewItem(QListView* list, const Cervisia::LogInfo& logInfo);
virtual int compare(QListViewItem* i, int col, bool) const;
private:
static QString truncateLine(const QString &s);
static QString extractOrdinaryTags(const QString &s);
static QString extractBranchName(const QString &s);
QString mrev, mauthor;
QDateTime mdate;
QString mcomment, mtagcomment;
Cervisia::LogInfo m_logInfo;
friend class LogListView;
};
LogListViewItem::LogListViewItem( QListView *list,
const QString &rev, const QString &author, const QDateTime &date,
const QString &comment, const QString &tagcomment )
: KListViewItem(list, rev, author, KGlobal::locale()->formatDateTime(date),
extractBranchName(tagcomment), truncateLine(comment), extractOrdinaryTags(tagcomment)),
mrev(rev), mauthor(author), mdate(date), mcomment(comment), mtagcomment(tagcomment)
LogListViewItem::LogListViewItem(QListView* list, const Cervisia::LogInfo& logInfo)
: KListViewItem(list),
m_logInfo(logInfo)
{
setText(Revision, logInfo.m_revision);
setText(Author, logInfo.m_author);
setText(Date, logInfo.dateTimeToString());
setText(Comment, truncateLine(logInfo.m_comment));
for (Cervisia::LogInfo::TTagInfoSeq::const_iterator it = logInfo.m_tags.begin();
it != logInfo.m_tags.end(); ++it)
{
const Cervisia::TagInfo& tagInfo(*it);
if (tagInfo.m_type == Cervisia::TagInfo::OnBranch)
{
setText(Branch, tagInfo.m_name);
}
}
setText(Tags, logInfo.tagsToString(Cervisia::TagInfo::Tag,
Cervisia::LogInfo::NoTagType,
QString::fromLatin1(", ")));
}
......@@ -71,80 +79,18 @@ QString LogListViewItem::truncateLine(const QString &s)
}
static void takeLine(QString *s, QString *line)
{
int pos = s->find('\n');
if (pos == -1)
{
*line = *s;
s->remove(0, s->length());
}
else
{
*line = s->left(pos);
s->remove(0, pos+1);
}
}
QString LogListViewItem::extractOrdinaryTags(const QString &s)
{
QString res;
// Note: same translation as in logdlg.cpp
// This is a hack...
QString prefix = i18n("\nTag: ");
prefix.remove(0, 1);
QString rest = s;
while ( !rest.isEmpty() )
{
QString line;
takeLine(&rest, &line);
if (line.left(prefix.length()) == prefix)
{
res += ", ";
res += line.right(line.length()-prefix.length());
}
}
if (!res.isEmpty())
res.remove(0, 2);
return res;
}
QString LogListViewItem::extractBranchName(const QString &s)
{
// Note: same translation as in logdlg.cpp
// This is a hack...
QString prefix = i18n("\nOn branch: ");
prefix.remove(0, 1);
QString rest = s;
while ( !rest.isEmpty() )
{
QString line;
takeLine(&rest, &line);
if (line.left(prefix.length()) == prefix)
return line.right(line.length()-prefix.length());
}
return "";
}