From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- vcs/cvsservice/changelog.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 vcs/cvsservice/changelog.cpp (limited to 'vcs/cvsservice/changelog.cpp') diff --git a/vcs/cvsservice/changelog.cpp b/vcs/cvsservice/changelog.cpp new file mode 100644 index 00000000..a63a2b92 --- /dev/null +++ b/vcs/cvsservice/changelog.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (C) 2003 by Mario Scalas * + * mario.scalas@libero.it * + * * + * 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 +#include +#include + +#include + +#include "changelog.h" + +ChangeLogEntry::ChangeLogEntry() +{ + KEMailSettings emailConfig; + emailConfig.setProfile( emailConfig.defaultProfileName() ); + authorEmail = emailConfig.getSetting( KEMailSettings::EmailAddress ); + authorName = emailConfig.getSetting( KEMailSettings::RealName ); + + QDate currDate = QDate::currentDate(); + date = currDate.toString( "yyyy-MM-dd" ); +} + +ChangeLogEntry::~ChangeLogEntry() +{ +} + +void ChangeLogEntry::addLine( const QString &aLine ) +{ + lines << aLine; +} + +void ChangeLogEntry::addLines( const QStringList &someLines ) +{ + lines += someLines; +} + +void streamCopy( QTextStream &is, QTextStream &os ) +{ + while (!is.eof()) + os << is.readLine() << "\n"; // readLine() eats '\n' !! +} + +void ChangeLogEntry::addToLog( const QString &logFilePath, const bool prepend, const QString &startLineString ) +{ + if (prepend) // add on head + { + QString fakeLogFilePath = logFilePath + ".fake"; + + QFile fakeFile( fakeLogFilePath ); + QFile changeLogFile( logFilePath ); + { + if (!fakeFile.open( IO_WriteOnly | IO_Append)) + return; + + if (changeLogFile.open( IO_ReadOnly )) // A Changelog already exist + { + QTextStream is( &changeLogFile ); + QTextStream os( &fakeFile ); + + // Put current entry + os << toString( startLineString ); + // Write the rest of the change log file + streamCopy( is, os ); + } + else // ChangeLog doesn't exist: just write our entry + { + QTextStream t( &fakeFile ); + t << toString( startLineString ); + } + fakeFile.close(); + changeLogFile.close(); + } + // Ok, now we have the change log we need in fakeLogFilePath: we should ask for a + // 'mv fakeLogFilePath logFilePath'-like command ... :-/ + if (!fakeFile.open( IO_ReadOnly )) + return; + + if (changeLogFile.open( IO_WriteOnly )) + { + QTextStream os( &changeLogFile ); + QTextStream is( &fakeFile ); + + // Write the rest of the change log file + streamCopy( is, os ); + } + fakeFile.close(); + fakeFile.remove(); // fake changelog is no more needed! + changeLogFile.close(); + } + else // add on tail + { + QFile f( logFilePath ); + if (!f.open( IO_WriteOnly | IO_Append)) + return; + + QTextStream t( &f ); + t << toString( startLineString ); + } +} + +QString ChangeLogEntry::toString( const QString &startLineString ) const +{ + QString header = date + " " + authorName + " <" + authorEmail + ">\n"; + + return header + startLineString + lines.join( "\n" + startLineString ) + "\n\n"; +} -- cgit v1.2.1