moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kwordquiz / src / keduvocdata.cpp
blob2e4999bc6f91b69c227d4db6b96b890567e8e80a
1 /* This file is part of the KDE Edu Library
2 Copyright (C) 2002 Scott Wheeler <wheeler@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
19 #include "keduvocdata.h"
21 #include <qfile.h>
23 #include <kdebug.h>
25 ////////////////////////////////////////////////////////////////////////////////
26 // class KEduVocDataItem
27 ////////////////////////////////////////////////////////////////////////////////
29 // public methods
31 KEduVocDataItem::KEduVocDataItem()
36 KEduVocDataItem::KEduVocDataItem(QDomElement &entry)
38 domElement = entry;
41 KEduVocDataItem::~KEduVocDataItem()
46 QString KEduVocDataItem::originalText() const
48 return getText("o");
51 QString KEduVocDataItem::translatedText() const
53 return getText("t");
56 // protected methods
58 QString KEduVocDataItem::getText(const QString &tagName) const
60 if(!domElement.isNull()) {
62 QDomNodeList list = domElement.elementsByTagName(tagName);
64 if(list.count() > 0) {
66 QDomElement element = list.item(0).toElement();
68 if(!element.isNull()) {
69 return element.text();
71 else
72 return QString::null;
74 else
75 return QString::null;
77 else
78 return QString::null;
81 ////////////////////////////////////////////////////////////////////////////////
82 // class KEduVocData
83 ////////////////////////////////////////////////////////////////////////////////
86 /*!
87 \fn KEduVocData::KEduVocData
89 KEduVocData::KEduVocData()
91 document = new QDomDocument();
94 KEduVocDataItemList KEduVocData::parse(const QString &fileName)
96 KEduVocDataItemList list;
98 //QDomDocument document;
99 QFile file(fileName);
100 document->setContent(&file);
102 QDomNodeList entries = document->elementsByTagName("e");
104 // loop through the "e" (entry) tags looking for data
105 for(uint i = 0 ; i < entries.count() ; i++) {
107 // get an entry to operate on
108 QDomElement entry = entries.item(i).toElement();
110 // if the "node" is in fact an element -- i.e. not null
111 if(!entry.isNull()) {
112 KEduVocDataItem item(entry);
113 list.append(item);
117 return list;
122 \fn KEduVocData::colWidth(int col)
124 int KEduVocData::colWidth(int col)
126 if (!document->isNull())
127 if (col == 0)
128 return document -> documentElement().namedItem("e").namedItem("o").toElement().attribute("width", "250").toInt();
129 else
130 return document -> documentElement().namedItem("e").namedItem("t").toElement().attribute("width", "250").toInt();
131 else
132 return 250;
137 \fn KEduVocData::numRows()
139 int KEduVocData::numRows()
141 if (!document->isNull())
142 return document->documentElement().attribute("lines", "0").toInt();
143 else
144 return 0;
149 \fn KEduVocData::language(int col)
151 QString KEduVocData::language(int col)
153 if (!document->isNull())
154 if (col == 0)
155 return document -> documentElement().namedItem("e").namedItem("o").toElement().attribute("l");
156 else
157 return document -> documentElement().namedItem("e").namedItem("t").toElement().attribute("l");
158 else
159 return QString::null;