summaryrefslogtreecommitdiffstats
path: root/kwordquiz/src/wqlreader.cpp
blob: 5d87e56f5074ad0e6f17f1ff1b6c7390f28df0d9 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************************************
                                 wqlreader.cpp
                             -------------------
   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 <textstream.h>
#include <tqfile.h>

#include <kmessagebox.h>
#include <klocale.h>

#include "wqlreader.h"

KWqlDataItem::KWqlDataItem()
{

}

KWqlDataItem::KWqlDataItem(const TQString &front, const TQString &back, int height)
{
  m_front = front;
  m_back = back;
  m_height = height;
}

KWqlDataItem::~KWqlDataItem()
{

}

/*!
    \fn WqlReader::WqlReader
 */
WqlReader::WqlReader()
{

}

KWqlDataItemList WqlReader::parse(const TQString &fileName)
{
    KWqlDataItemList list;
    TQFile file(fileName);
    file.open(IO_ReadOnly);
    TQTextStream ts(&file);
    ts.setEncoding(TQTextStream::Latin1);

    TQString s = "";
    s=ts.readLine();
    if (s != "WordQuiz")
    {
      KMessageBox::error(0, i18n("This does not appear to be a (K)WordQuiz file") + s);
      file.close();
      return list;
    }
    s = ts.readLine();
    s = s.left(1);
    int iFV = s.toInt(0);
    if (iFV != 5)
    {
      KMessageBox::error(0, i18n("KWordQuiz can only open files created by WordQuiz 5.x"));
      file.close();
      return list;
    }

    while (ts.readLine() != "[Font Info]");
    s = ts.readLine();
    int p = s.find("=", 0);
    TQString fam = s.right(s.length() - (p + 1));
    fam = fam.mid(1, fam.length() - 2);
    //g->font().setFamily(s);

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    int ps = s.toInt(0);

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    int b = 0;
    if (s == "1")
    {
      b = TQFont::Bold;
    }

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    bool it = (s == "1");

    TQFont m_font(fam, ps, b, it);

    while (ts.readLine() != "[Character Info]");  
    s = ts.readLine();    
    p = s.find("=", 0);
    m_specialCharacters = s.right(s.length() - (p + 1));

    while (ts.readLine() != "[Grid Info]");
    ts.readLine(); //skip value for width of row headers

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_colWidth1 = s.toInt(0, 10);

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_colWidth2 = s.toInt(0, 10);

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_numRows = (s.toInt(0, 10) - 1); //We need to reduce by one since the header is not included

    // Selection
    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_topLeft =s.toInt(0, 10) - 1;

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_topRight =s.toInt(0, 10) - 1;

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_bottomLeft =s.toInt(0, 10) - 1;

    s = ts.readLine();
    p = s.find("=", 0);
    s = s.right(s.length() - (p + 1));
    m_bottomRight =s.toInt(0, 10) - 1 ;

    while (ts.readLine() != "[Vocabulary]");

    s = ts.readLine();
    p = s.find("   [", 0);
    s = s.left(p);
    s = s.stripWhiteSpace();
    m_language1 = s;
    m_language2 = ts.readLine();

    while (!s.isNull())
    {
      s = ts.readLine();
      p = s.find("[", 0);
      TQString r = s.mid(p + 1, 10);
      int h = r.toInt(0, 10);
      s = s.left(p);
      s = s.stripWhiteSpace();
      
      TQString b;
      b = ts.readLine();
      
      KWqlDataItem item(s, b, h /15);
      list.append(item);
    }
    file.close();
    return list;
}


/*!
    \fn WqlReader::colWidth(int col)
 */
int WqlReader::colWidth(int col)
{
  if (col == 0)
    return m_colWidth1;
  else
    return m_colWidth2;
}


/*!
    \fn WqlReader::language(int col)
 */
TQString WqlReader::language(int col)
{
  if (col == 0)
    return m_language1;
  else
    return m_language2;
}