moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kwordquiz / src / paukerreader.cpp
blobbc6f78bfac7dcfff1640a5ed0d1e8f71ecb84b7a
1 /* This file is part of KWordQuiz
2 Copyright (C) 2004 Peter Hedlund <peter@peterandlinda.com>
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 "paukerreader.h"
21 #include <qiodevice.h>
22 #include <qfile.h>
24 #include <kdebug.h>
25 #include <kfilterdev.h>
27 PaukerDataItem::PaukerDataItem()
31 PaukerDataItem::PaukerDataItem(QDomElement &entry)
33 domElement = entry;
36 PaukerDataItem::~PaukerDataItem()
40 QString PaukerDataItem::frontSide() const
42 return getText("FrontSide");
45 QString PaukerDataItem::backSide() const
47 return getText("BackSide");
50 QString PaukerDataItem::getText(const QString &tagName) const
52 if(!domElement.isNull()) {
54 QDomNodeList list = domElement.elementsByTagName(tagName);
56 if(list.count() > 0) {
58 QDomElement element = list.item(0).toElement();
60 if(!element.isNull()) {
61 return element.text();
63 else
64 return QString::null;
66 else
67 return QString::null;
69 else
70 return QString::null;
73 /*!
74 \fn PaukerData::PaukerData
76 PaukerData::PaukerData()
78 document = new QDomDocument();
81 PaukerDataItemList PaukerData::parse(const QString &fileName)
83 PaukerDataItemList list;
85 QIODevice * file = KFilterDev::deviceForFile(fileName);
86 document->setContent(file);
88 QDomNodeList entries = document->elementsByTagName("Card");
90 // loop through the "Card" tags looking for data
91 for(uint i = 0 ; i < entries.count() ; i++) {
93 // get an entry to operate on
94 QDomElement entry = entries.item(i).toElement();
96 // if the "node" is in fact an element -- i.e. not null
97 if(!entry.isNull()) {
98 PaukerDataItem item(entry);
99 list.append(item);
102 delete file;
103 return list;