From: Scott Wheeler Date: Wed, 29 May 2002 23:59:11 +0000 (+0000) Subject: Added the beginnings of a kde-edu library, libkdeedu, which at the moment X-Git-Tag: v3.1.0~7 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=d387dc2644d36880eab63f83ccf04e88d0afa52a;p=libqmvoc.git Added the beginnings of a kde-edu library, libkdeedu, which at the moment just contains a simple kvtml parser. I also made changes to FlashKard to have it make use of this lib. svn path=/trunk/kdeedu/libkdeedu/; revision=158533 --- d387dc2644d36880eab63f83ccf04e88d0afa52a diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..ac809ea --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Developers: +* Scott Wheeler + Original author and current maintainer diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..5ff42fc --- /dev/null +++ b/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES= $(all_includes) +SUBDIRS = . + +lib_LTLIBRARIES = libkdeedu.la + +libkdeedu_la_SOURCES = kedudata.cpp + +libkdeedu_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 1:0 + +include_HEADERS = kedudata.h +# noinst_HEADERS = + +libkdeedu_la_LIBADD = $(LIB_KDECORE) + +METASOURCES = AUTO + +# updatedir = +# update_DATA = + +# messages: +# $(XGETTEXT) *.cpp *.h -o $(podir)/libkdeedu.pot diff --git a/README b/README new file mode 100644 index 0000000..b60140b --- /dev/null +++ b/README @@ -0,0 +1,70 @@ +-- Email sent to kde-edu-devel@kde.org by Scott Wheeler (wheeler@kde.org) +-- on May 30, 2002. Please see the "disclaimers" part of this before +-- you make use of this lib. + +Per public and private discussion with Annma today, I've committed the first +part of libkdeedu. With all of the hype around the use of Ewald's kvtml, +Anma has been the first besides Ewald and myself to take the initiative to +begin using it. Rather than having her copy and paste my poor implementation + it seemed to be a good time to start to Do Things The Right Way (tm). + +First, I made a lib based on my bad implementation of kvtml, but then my +conscience got the better of me and I started tinkering with QDom. What you'll +find in libkdeedu is a QDom based, very basic, parser for kvtml. Right now it +just parses "e" (entry), "o" (original) and "t" (tranlation) tags, but it's done +in such a way that it should be easy to extend (unlike my previous +implementation). I've also made changes to FlashKard to do it's input using +this. + +So now, if you include "kedudata.h", you'll have access to two classes and a +typedef. They are as follows: + +KEduDataItem -- a class to store vocabulary items +KEduDataItemList -- a "typedef QValueList" +KEduData -- a class that will later be used for kvtml documents but at the +moment just has one static member "parse(const QString fileName)". + +The use is basically what I laid out in my earlier email: + +KEduDataItemList list = KEduData::parse("foo.kvtml"); +QString original = list[0].originalText(); +QString translated = list[0].translatedText(); + +Also you'll need something like: + +#include "../../libkdeedu/kedudata.h" + +and in your Makefile.am: + +flashkard_LDADD = $(LIB_KFILE) ../../libkdeedu/libkdeedu.la + +So now some disclaimers: + +This is very basic. There isn't much there, but that will change. Right now +this is to suit Annma's needs (and FlashKard while I'm at it). Many gaps need +to be filled in. + +This is all *very* subject to change. In fact I guarantee it. If you're lucky, +I'll only break your app a few times. Things will be moved, renamed, rewritten +and the API will change. + +This also means that it's open for suggestions. For the name of the lib, I +followed the libkdenetwork pattern, but that can change. I arbitrarily picked +the prefix "KEdu" for all of the classes and decided on the name "KEduData" for +the vocabulary data. Ewald had suggested some other things but mainly based on +having several KDE-Edu libs, which of course begs the question, should there be +several? Looking around at other KDE things it seems pretty common to pack a lot +of logically connected material into one lib. + +Also propper documentation will follow, but I want to get a little better idea +of what the API will be before I spend the time to document it. + +I'm really not trying to comandere this thing, I was just feeling productive, so +I started coding. + +I may start looking into writing something to write kvtml, but that will probably + happen after a brainstorming session at LinuxTag. + +Cheers and good luck! + +-Scott diff --git a/kedudata.cpp b/kedudata.cpp new file mode 100644 index 0000000..285b5d9 --- /dev/null +++ b/kedudata.cpp @@ -0,0 +1,111 @@ +/* This file is part of the KDE Edu Library + Copyright (C) 2002 Scott Wheeler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "kedudata.h" + +#include + +#include + +//////////////////////////////////////////////////////////////////////////////// +// class KEduDataItem +//////////////////////////////////////////////////////////////////////////////// + +// public methods + +KEduDataItem::KEduDataItem() +{ + +} + +KEduDataItem::KEduDataItem(QDomElement &entry) +{ + domElement = entry; +} + +KEduDataItem::~KEduDataItem() +{ + +} + +QString KEduDataItem::originalText() +{ + return getText("o"); +} + +QString KEduDataItem::translatedText() +{ + return getText("t"); +} + +// protected methods + +QString KEduDataItem::getText(const QString tagName) +{ + if(!domElement.isNull()) { + + QDomNodeList list = domElement.elementsByTagName(tagName); + + if(list.count() > 0) { + + QDomElement element = list.item(0).toElement(); + + if(!element.isNull()) { + return element.text(); + } + else + return QString::null; + } + else + return QString::null; + } + else + return QString::null; +} + +//////////////////////////////////////////////////////////////////////////////// +// class KEduData +//////////////////////////////////////////////////////////////////////////////// + +// public static methods + +KEduDataItemList KEduData::parse(const QString fileName) +{ + KEduDataItemList list; + + QDomDocument document; + QFile file(fileName); + document.setContent(&file); + + QDomNodeList entries = document.elementsByTagName("e"); + + // loop through the "e" (entry) tags looking for data + for(uint i = 0 ; i < entries.count() ; i++) { + + // get an entry to operate on + QDomElement entry = entries.item(i).toElement(); + + // if the "node" is in fact an element -- i.e. not null + if(!entry.isNull()) { + KEduDataItem item(entry); + list.append(item); + } + } + + return list; +} diff --git a/kedudata.h b/kedudata.h new file mode 100644 index 0000000..9ae59d4 --- /dev/null +++ b/kedudata.h @@ -0,0 +1,45 @@ +/* This file is part of the KDE Edu Library + Copyright (C) 2002 Scott Wheeler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include + +class KEduDataItem +{ +public: + KEduDataItem(); + KEduDataItem(QDomElement &entry); + virtual ~KEduDataItem(); + + QString originalText(); + QString translatedText(); + +protected: + QString getText(const QString tagName); + +private: + QDomElement domElement; +}; + +typedef QValueList KEduDataItemList; + +class KEduData +{ +public: + static KEduDataItemList parse(const QString fileName); +};