kdevlicense.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qfile.h>
00021 #include <qdatetime.h>
00022 #include <qregexp.h>
00023
00024 #include "kdevlicense.h"
00025
00026 KDevLicense::KDevLicense( const QString& name, const QString& fileName )
00027 : m_name( name )
00028 {
00029 readFile( fileName );
00030 }
00031
00032 void KDevLicense::readFile( const QString& fileName )
00033 {
00034 QFile f(fileName);
00035 if (!f.open(IO_ReadOnly))
00036 return;
00037 QTextStream stream(&f);
00038 QString str;
00039 enum { readingText, readingFiles } mode = readingText;
00040 for(;;)
00041 {
00042 str = stream.readLine();
00043 if( str.isNull() )
00044 break;
00045 if( str == "[FILES]" )
00046 mode = readingFiles;
00047 else if( str == "[PREFIX]" )
00048 mode = readingText;
00049 else if( mode == readingFiles )
00050 {
00051 if( !str.isEmpty() )
00052 {
00053 m_copyFiles.append( str );
00054 }
00055 } else
00056 m_rawLines.append( str );
00057 }
00058
00059 }
00060
00061 QString KDevLicense::assemble( KDevFile::CommentingStyle commentingStyle, const QString& author, const QString& email, int leadingSpaces )
00062 {
00063
00064
00065 QString strFill;
00066 strFill.fill( ' ', leadingSpaces );
00067
00068 QString str =
00069 strFill + "/***************************************************************************\n" +
00070 strFill + " * Copyright (C) %1 by %2 *\n" +
00071 strFill + " * %3 *\n" +
00072 strFill + " * *\n";
00073
00074 str = str.arg(QDate::currentDate().year()).arg(author.left(45),-45).arg(email.left(67),-67);
00075
00076 QStringList::Iterator it;
00077 for( it = m_rawLines.begin(); it != m_rawLines.end(); ++it )
00078 {
00079 str += QString( "%1 * %2 *\n").arg( strFill ).arg( *it, -69 );
00080 }
00081
00082 str += strFill + " ***************************************************************************/\n";
00083
00084 switch( commentingStyle )
00085 {
00086 case KDevFile::CPPStyle:
00087 return str;
00088
00089 case KDevFile::PascalStyle:
00090 str.replace(QRegExp("/\\**\n \\*"), "{\n ");
00091 str.replace(QRegExp("\\*\n \\*"), " \n ");
00092 str.replace(QRegExp(" *\\**/\n"), "}\n");
00093 return str;
00094
00095 case KDevFile::AdaStyle:
00096 str.replace(QRegExp("/\\*"), "--");
00097 str.replace(QRegExp(" \\*"), "--");
00098 str.replace(QRegExp("\\*/"), "*");
00099 return str;
00100
00101 case KDevFile::BashStyle:
00102 str.replace(QRegExp("\\*|/"), "#");
00103 str.replace(QRegExp("\n ##"), "\n##");
00104 str.replace(QRegExp("\n #"), "\n# ");
00105 return str;
00106 }
00107
00108 return "currently unknown/unsupported commenting style";
00109 }
This file is part of the documentation for KDevelop Version 3.1.2.