summaryrefslogtreecommitdiffstats
path: root/kwordquiz/src/kvtmlwriter.cpp
blob: dc123113be9185cd12a66b9d47919611052a60c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/***************************************************************************
                          kvtmlwriter.cpp  -  description
                             -------------------
   copyright            : (C) 2004 by Peter Hedlund
    email                : peter.hedlund@kdemail.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 "kvtmlwriter.h"

KVTMLWriter::KVTMLWriter(TQFile *file)
{
  outputFile = file;
  if(outputFile->open(IO_WriteOnly))
    {
      outputStream.setDevice(TQT_TQIODEVICE(outputFile));
      outputStream.setEncoding(TQTextStream::UnicodeUTF8);

      outputStream << "<?xml version=\"1.0\"?>" << endl;
      outputStream << "<!DOCTYPE kvtml SYSTEM \"kvoctrain.dtd\">" << endl;
    }
}

/*!
    \fn KVTMLWriter::addHeader(const TQString &generator, int cols, int rows, const TQString &title)
 */
void KVTMLWriter::addHeader(const TQString &generator, int cols, int rows, const TQString &title)
{
  TQString s = TQString("<kvtml\n generator=\"%1\"\n cols=\"%2\"\n lines=\"%3\"\n title=\"%4\">")
    .tqarg(generator)
    .tqarg(cols)
    .tqarg(rows)
    .tqarg(title);

  outputStream << s << endl << endl;
}

/*!
    \fn KVTMLWriter::addFirstItem(const TQString &ll, int lwidth, const TQString &left, const TQString &rl, int rwidth, const TQString &right)
 */
void KVTMLWriter::addFirstItem(const TQString &ll, int lwidth, const TQString &left, const TQString &rl, int rwidth, const TQString &right)
{
  outputStream << " <e>" << endl;
  TQString s = TQString("  <o width=\"%1\" l=\"%2\">")
    .tqarg(lwidth)
    .tqarg(ll);
  outputStream << s << escape(left) << "</o>" << endl;
  s = TQString("  <t width=\"%1\" l=\"%2\">")
    .tqarg(rwidth)
    .tqarg(rl);
  outputStream << s << escape(right) << "</t>" << endl;
  outputStream << " </e>" << endl;
}

/*!
    \fn KVTMLWriter::addItem(const TQString &left, const TQString &right)
 */
void KVTMLWriter::addItem(const TQString &left, const TQString &right)
{
  outputStream << " <e>" << endl;
  outputStream << "  <o>" << escape(left) << "</o>" << endl;
  outputStream << "  <t>" << escape(right) << "</t>" << endl;
  outputStream << " </e>" << endl;
}


KVTMLWriter::~KVTMLWriter()
{
  outputStream << "</kvtml>" << endl;
  outputFile->close();
}

TQString KVTMLWriter::escape( const TQString & s)
{
  TQString result = s;
  result.replace(TQChar('&'), "&amp;"); //must be done first 
  result.replace(TQChar('<'), "&lt;");
  result.replace(TQChar('>'), "&gt;");

  return result;  
}