/*************************************************************************** htmlwriter.cpp - description ------------------- begin : Son Jul 28 2002 copyright : (C) 2002 by Alexander Theel email : alex.theel@gmx.net ***************************************************************************/ /*************************************************************************** * * * 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 "htmlwriter.h" #include "../version.h" #include #include #include #include #include "dot.xpm" #include "space15.xpm" const QString HTMLWriter::TUX_HTMLEXPORT_SUBDIR = "Notes"; const QString HTMLWriter::TUX_SPACER = "space15.png"; const QString HTMLWriter::TUX_DOT = "dot.png"; QStringList HTMLWriter::static_List = QStringList(); /** * Exports a aollection to HTML. * Returns 'TRUE' if successful, otherwise 'FALSE'. */ // ------------------------------------------------------------------------------- bool HTMLWriter::writeCollectionToHTMLFile( CInformationCollection& collection, const QString& dirPath ) // ------------------------------------------------------------------------------- { QDir dir = QDir( dirPath ); bool bSuccess = createSubDir( dir ); if ( !bSuccess ) return FALSE; bSuccess = createImages( dir ); if ( !bSuccess ) return FALSE; static_List.clear(); // TODO: Check if files could be opened, also. If not -> return 'FALSE'. createTopFrame( dir ); CInformationElement* pRootElem = collection.getRootElement(); if ( NULLPTR != pRootElem ) { createIndexFile( dir, pRootElem->getDescription() ); createTreeFrame( collection, dir ); } static_List.clear(); return TRUE; } // ------------------------------------------------------------------------------- bool HTMLWriter::createSubDir( const QDir& dir ) // ------------------------------------------------------------------------------- { bool bSuccess = dir.mkdir( TUX_HTMLEXPORT_SUBDIR ); if ( FALSE == bSuccess ) return FALSE; return TRUE; } // ------------------------------------------------------------------------------- bool HTMLWriter::createImages( const QDir& dir ) // ------------------------------------------------------------------------------- { // create dot and space and write them to disk QPixmap dot( dot_xpm ); bool bRetVal = dot.save( dir.absPath() + "/" + TUX_DOT, "PNG" ); QPixmap space( space15_xpm ); bRetVal = bRetVal | space.save( dir.absPath() + "/" + TUX_SPACER, "PNG" ); return bRetVal; } // ------------------------------------------------------------------------------- void HTMLWriter::createIndexFile( const QDir& dir, const QString& sRootDescription ) // ------------------------------------------------------------------------------- { // "index.html" erstellen; // we could not do this in advance -> because we did not know the 'name' of the "root-page" QString index=" TuxCards-HTMLExport\n\n"; index+="\n"; index+="\n"; index+="\n"; index+=" \n"; index+=" \n"; index+=" \n"; index+=" \n"; index+="\n"; index+=" <body bgcolor=\"#F0F0E1\">\n"; index+=" Sie benötigen einen Framefähigen Browser.<br>\n"; index+=" You do need a browser that supports frames.\n"; index+=" </body>\n"; index+="\n"; index+="\n"; index+=""; QFile f2( dir.absPath() + "/index.html" ); if ( f2.open(IO_WriteOnly) ) { // file opened successfully QTextStream t( &f2 ); // use a text stream t<"); QFile f( dir.absPath()+"/"+"treeHTML.html" ); if ( f.open(IO_WriteOnly) ) // file opened successfully { QTextStream t( &f ); // use a text stream // t.setEncoding(QTextStream::UnicodeUTF8); t<\n "+element.getDescription()+" \n"; QString text = element.getInformation(); t<< text.replace(QRegExp("\n"),"
\n"); t<<"\n"; } else { t<"); iTabCount++; sTreeHTML.append(QString("") + "" + element.getDescription()+"
\n"); QPtrListIterator it(*element.getChildren()); CInformationElement* x; while( (x = it.current()) != 0 ) { ++it; convertInformationElementToHTML( *x, dir, sTreeHTML, iTabCount ); } } // ------------------------------------------------------------------------------- void HTMLWriter::createTopFrame( const QDir& dir ) // ------------------------------------------------------------------------------- { // "top.html" erstellen QString top = " TuxCards-HTMLExport\n\n"; top += "
\n

TuxCards-HTMLExport

\n"; top += ""; top += TUX_VERSION; top += " - written by Alexander Theel\n"; top +=""; QFile f( dir.absPath()+"/top.html" ); if ( f.open(IO_WriteOnly) ) // file opened successfully { QTextStream t( &f ); // use a text stream t<