moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / libkdeedu / kdeeducore / keduvocdata.cpp
blobfd6f0473ba298f95b262e97711291890a0ad8aef
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 ////////////////////////////////////////////////////////////////////////////////
85 // public static methods
87 KEduVocDataItemList KEduVocData::parse(const QString &fileName)
89 KEduVocDataItemList list;
91 QDomDocument document;
92 QFile file(fileName);
93 document.setContent(&file);
95 QDomNodeList entries = document.elementsByTagName("e");
97 // loop through the "e" (entry) tags looking for data
98 for(uint i = 0 ; i < entries.count() ; i++) {
100 // get an entry to operate on
101 QDomElement entry = entries.item(i).toElement();
103 // if the "node" is in fact an element -- i.e. not null
104 if(!entry.isNull()) {
105 KEduVocDataItem item(entry);
106 list.append(item);
110 return list;