• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

libkdeedu/keduvocdocument

  • sources
  • kde-4.12
  • kdeedu
  • libkdeedu
  • keduvocdocument
keduvockvtml2reader.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  read a KEduVocDocument from a KVTML file
3  -----------------------------------------------------------------------
4  copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
5 
6  (C) 2005 Eric Pignet <eric at erixpage.com>
7  (C) 2007 Peter Hedlund <peter.hedlund@kdemail.net>
8  Copyright 2007-2010 Frederik Gladhorn <gladhorn@kde.org>
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #include "keduvockvtml2reader.h"
21 
22 #include <QtCore/QTextStream>
23 #include <QtCore/QList>
24 #include <QtCore/QIODevice>
25 
26 #include <klocale.h>
27 
28 #include "keduvocdocument.h"
29 #include "keduvoclesson.h"
30 #include "keduvocleitnerbox.h"
31 #include "keduvocwordtype.h"
32 #include "kvtml2defs.h"
33 #include "keduvockvtmlreader.h"
34 #include "keduvoccommon_p.h"
35 
36 #include <KDebug>
37 
38 KEduVocKvtml2Reader::KEduVocKvtml2Reader( QIODevice *file )
39  : m_inputFile( file )
40 {
41  // the file must be already open
42  if ( !m_inputFile->isOpen() ) {
43  m_errorMessage = i18n( "file must be opened first" );
44  }
45 }
46 
47 
48 bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc )
49 {
50  m_doc = doc;
51 
52  QDomDocument domDoc( "KEduVocDocument" );
53 
54  if ( !domDoc.setContent( m_inputFile, &m_errorMessage ) )
55  return false;
56 
57  QDomElement domElementKvtml = domDoc.documentElement();
58  if ( domElementKvtml.tagName() != KVTML_TAG ) {
59  m_errorMessage = i18n( "This is not a KDE Vocabulary document." );
60  return false;
61  }
62 
63  if ( domElementKvtml.attribute( KVTML_VERSION ).toFloat() < 2.0 ) {
64  // read the file with the old format
65 
66  // first reset the file to the beginning
67  m_inputFile->seek( 0 );
68  KEduVocKvtmlReader oldFormat( m_inputFile );
69 
70  // get the return value
71  bool retval = oldFormat.readDoc( doc );
72 
73  // pass the errormessage up
74  m_errorMessage = oldFormat.errorMessage();
75  return retval;
76  }
77 
78  //-------------------------------------------------------------------------
79  // Information
80  //-------------------------------------------------------------------------
81 
82  QDomElement info = domElementKvtml.firstChildElement( KVTML_INFORMATION );
83  if ( !info.isNull() ) {
84  if ( !readInformation( info ) )
85  return false;
86  }
87 
88  bool result = readGroups( domElementKvtml ); // read sub-groups
89 
90  return result;
91 }
92 
93 bool KEduVocKvtml2Reader::readInformation( QDomElement &informationElement )
94 {
95  // read the generator
96  QDomElement currentElement = informationElement.firstChildElement( KVTML_GENERATOR );
97  if ( !currentElement.isNull() ) {
98  m_doc->setGenerator( currentElement.text() );
99  // add the version if it's there
100  int pos = m_doc->generator().lastIndexOf( KVD_VERS_PREFIX );
101  if ( pos >= 0 ) {
102  m_doc->setVersion( m_doc->generator().remove( 0, pos + 2 ) );
103  }
104  }
105 
106  // read the title
107  currentElement = informationElement.firstChildElement( KVTML_TITLE );
108  if ( !currentElement.isNull() ) {
109  m_doc->setTitle( currentElement.text() );
110  }
111 
112  // read the author
113  currentElement = informationElement.firstChildElement( KVTML_AUTHOR );
114  if ( !currentElement.isNull() ) {
115  m_doc->setAuthor( currentElement.text() );
116  }
117 
118  currentElement = informationElement.firstChildElement( KVTML_AUTHORCONTACT );
119  if ( !currentElement.isNull() ) {
120  m_doc->setAuthorContact( currentElement.text() );
121  }
122 
123  // read the license
124  currentElement = informationElement.firstChildElement( KVTML_LICENSE );
125  if ( !currentElement.isNull() ) {
126  m_doc->setLicense( currentElement.text() );
127  }
128 
129  // read the comment
130  currentElement = informationElement.firstChildElement( KVTML_COMMENT );
131  if ( !currentElement.isNull() ) {
132  m_doc->setDocumentComment( currentElement.text() );
133  }
134 
135  // read the category
136  currentElement = informationElement.firstChildElement( KVTML_CATEGORY );
137  if ( !currentElement.isNull() ) {
138  m_doc->setCategory( currentElement.text() );
139  }
140 
141  return true;
142 }
143 
144 bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent )
145 {
146  bool result = false;
147 
148  QDomElement groupElement = domElementParent.firstChildElement( KVTML_IDENTIFIERS );
149 
150  QDomElement currentElement;
151 
152  // ensure backwards compatibility - in kde 4.1 and earlier tenses were direct properties of the document class.
153  // now they are moved into the individual identifiers
154  QStringList tensesCompability;
155  groupElement = groupElement.firstChildElement( KVTML_TENSES );
156  if ( !groupElement.isNull() ) {
157  tensesCompability = readTenses( groupElement );
158  }
159 
160  groupElement = domElementParent.firstChildElement( KVTML_IDENTIFIERS );
161  if ( !groupElement.isNull() ) {
162  QDomNodeList entryList = groupElement.elementsByTagName( KVTML_IDENTIFIER );
163  if ( entryList.length() <= 0 ) {
164  m_errorMessage = i18n( "missing identifier elements from identifiers tag" );
165  return false;
166  }
167 
168  for ( int i = 0; i < entryList.count(); ++i ) {
169  currentElement = entryList.item( i ).toElement();
170  if ( currentElement.parentNode() == groupElement ) {
171  result = readIdentifier( currentElement );
172  if ( !result ) {
173  return false;
174  }
175  if (!tensesCompability.isEmpty()) {
176  m_doc->identifier(i).setTenseList(tensesCompability);
177  }
178  }
179  }
180  }
181 
182  groupElement = domElementParent.firstChildElement( KVTML_ENTRIES );
183  if ( !groupElement.isNull() ) {
184  QDomNodeList entryList = groupElement.elementsByTagName( KVTML_ENTRY );
185  for ( int i = 0; i < entryList.count(); ++i ) {
186  currentElement = entryList.item( i ).toElement();
187  if ( currentElement.parentNode() == groupElement ) {
188  result = readEntry( currentElement );
189  if ( !result )
190  return false;
191  }
192  }
193  }
194 
195  readSynonymsAntonymsFalseFriends( domElementParent );
196 
197  groupElement = domElementParent.firstChildElement( KVTML_WORDTYPES );
198  if ( !groupElement.isNull() ) {
199  readChildWordTypes( m_doc->wordTypeContainer(), groupElement );
200  }
201 
202  groupElement = domElementParent.firstChildElement( KVTML_LEITNERBOXES );
203  if ( !groupElement.isNull() ) {
204  readLeitner( m_doc->leitnerContainer(), groupElement );
205  }
206 
207  groupElement = domElementParent.firstChildElement( KVTML_LESSONS );
208  if ( !groupElement.isNull() ) {
209  readChildLessons(m_doc->lesson(), groupElement);
210  }
211 
212  // Additional cleanup: Put orphaned entries without a lesson into a default lesson.
213  KEduVocLesson *defaultLesson = new KEduVocLesson(i18n("Default Lesson"), m_doc->lesson());
214 
215  // now make sure we don't have any orphan entries
216  foreach (KEduVocExpression * entry, m_allEntries) {
217  if (!entry->lesson())
218  {
219  defaultLesson->appendEntry(entry);
220  }
221  }
222 
223  if (defaultLesson->entryCount() > 0)
224  {
225  m_doc->lesson()->appendChildContainer(defaultLesson);
226  } else {
227  delete defaultLesson;
228  }
229 
230  return true;
231 }
232 
233 
234 bool KEduVocKvtml2Reader::readIdentifier( QDomElement &identifierElement )
235 {
236  bool result = true;
237  int id = identifierElement.attribute( KVTML_ID ).toInt( &result );
238  if ( !result ) {
239  m_errorMessage = i18n( "identifier missing id" );
240  return false;
241  }
242 
243  // generate empty identifiers in the doc
244  for ( int i = m_doc->identifierCount(); i <= id; i++ ) {
245  m_doc->appendIdentifier( KEduVocIdentifier() );
246  }
247 
248  // the first element, create the identifier, even if empty
249  QDomElement currentElement = identifierElement.firstChildElement( KVTML_NAME );
250  m_doc->identifier(id).setName( currentElement.text() );
251 
252  currentElement = identifierElement.firstChildElement( KVTML_LOCALE );
253  m_doc->identifier(id).setLocale( currentElement.text() );
254 
255  currentElement = identifierElement.firstChildElement( KVTML_IDENTIFIERTYPE );
256  if ( !currentElement.isNull() ) {
257  // TODO: do something with the type
258  }
259 
260  // read sub-parts
261  currentElement = identifierElement.firstChildElement( KVTML_ARTICLE );
262  if ( !currentElement.isNull() ) {
263  readArticle( currentElement, id );
264  }
265 
266  currentElement = identifierElement.firstChildElement( KVTML_PERSONALPRONOUNS );
267  if ( !currentElement.isNull() ) {
268  KEduVocPersonalPronoun personalPronoun;
269  readPersonalPronoun( currentElement, personalPronoun );
270  m_doc->identifier(id).setPersonalPronouns( personalPronoun );
271  }
272 
273  QStringList tenses = readTenses(identifierElement);
274 
275  m_doc->identifier(id).setTenseList(tenses);
276 
277  return result;
278 }
279 
280 bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement )
281 {
282  QDomElement currentElement;
283  bool result = true;
284 
285  // get entry id
286  int id = entryElement.attribute( KVTML_ID ).toInt( &result );
287  if ( !result ) {
288  m_errorMessage = i18n( "entry missing id" );
289  return false;
290  }
291 
292  KEduVocExpression *expr = new KEduVocExpression;
293 
294  // read info tags: inactive, inquery, and sizehint
295  currentElement = entryElement.firstChildElement( KVTML_DEACTIVATED );
296  if ( !currentElement.isNull() ) {
297  // set the active state of the expression
298  if ( currentElement.text() == KVTML_TRUE ) {
299  expr->setActive( false );
300  } else {
301  expr->setActive( true );
302  }
303  }
304 
305  // read translation children
306  QDomNodeList translationList = entryElement.elementsByTagName( KVTML_TRANSLATION );
307 
308  for ( int i = 0; i < translationList.count(); ++i ) {
309  currentElement = translationList.item( i ).toElement();
310  if ( currentElement.parentNode() == entryElement ) {
311  result = readTranslation( currentElement, expr, i );
312  if ( !result )
313  return false;
314  }
315  }
316 
317  if ( expr->translationIndices().size() == 0 ) {
318  kDebug() << "Found entry with no words in it." << id;
319  expr->setTranslation(0, QString());
320  }
321 
322  Q_ASSERT(expr);
323 
324  // TODO: probably should insert at id position with a check to see if it exists
325  // may be useful for detecting corrupt documents
326  m_allEntries[id] = expr;
327  return result;
328 }
329 
330 bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
331  KEduVocExpression *expr, int index )
332 {
333  // read the text, grade, declension and conjugation
334  expr->translation(index)->fromKVTML2(translationElement);
335  QDomElement currentElement;
336 
337  // article grade
338  currentElement = translationElement.firstChildElement( KVTML_ARTICLE );
339  if ( !currentElement.isNull() ) {
340  KEduVocText article;
341  article.fromKVTML2(currentElement);
342  expr->translation(index)->setArticle(article);
343  }
344 
345  // comparisons
346  currentElement = translationElement.firstChildElement( KVTML_COMPARISON );
347  if ( !currentElement.isNull() ) {
348  readComparison( currentElement, expr->translation(index) );
349  }
350 
351  // multiple choice
352  currentElement = translationElement.firstChildElement( KVTML_MULTIPLECHOICE );
353  if ( !currentElement.isNull() ) {
354  readMultipleChoice( currentElement, expr->translation(index) );
355  }
356 
357  // image
358  currentElement = translationElement.firstChildElement( KVTML_IMAGE );
359  if ( !currentElement.isNull() ) {
360  expr->translation(index)->setImageUrl( KUrl( m_doc->url(), currentElement.text() ) );
361  }
362 
363  // sound
364  currentElement = translationElement.firstChildElement( KVTML_SOUND );
365  if ( !currentElement.isNull() ) {
366  expr->translation(index)->setSoundUrl( KUrl( m_doc->url(), currentElement.text() ) );
367  }
368 
369  return true;
370 }
371 
372 bool KEduVocKvtml2Reader::readChildLessons( KEduVocLesson* parentLesson, QDomElement &lessonElement )
373 {
374  QDomElement currentElement = lessonElement.firstChildElement( KVTML_CONTAINER );
375  while ( !currentElement.isNull() ) {
376  readLesson(parentLesson, currentElement);
377  currentElement = currentElement.nextSiblingElement( KVTML_CONTAINER );
378  }
379  return true;
380 }
381 
382 bool KEduVocKvtml2Reader::readLesson( KEduVocLesson* parentLesson, QDomElement &lessonElement )
383 {
384  //<name>Lesson name</name>
385  QDomElement currentElement = lessonElement.firstChildElement( KVTML_NAME );
386  KEduVocLesson * lesson = new KEduVocLesson(currentElement.text(), parentLesson);
387  parentLesson->appendChildContainer( lesson );
388 
389  readChildLessons( lesson, lessonElement );
390 
391  //<query>true</query>
392  currentElement = lessonElement.firstChildElement( KVTML_INPRACTICE );
393  lesson->setInPractice(currentElement.text() == KVTML_TRUE);
394 
395  //<entry id="123"/>
396  currentElement = lessonElement.firstChildElement( KVTML_ENTRY );
397  while ( !currentElement.isNull() ) {
398  bool result = false;
399  int entryId = currentElement.attribute( KVTML_ID ).toInt( &result );
400  if(result) {
401  if (m_allEntries[entryId]) {
402  lesson->appendEntry( m_allEntries[entryId] );
403  }
404  }
405  currentElement = currentElement.nextSiblingElement( KVTML_ENTRY );
406  }
407  return true;
408 }
409 
410 bool KEduVocKvtml2Reader::readSynonymsAntonymsFalseFriends( QDomElement &rootElement )
411 {
412  QDomElement pairElement;
413  for(int type = KEduVocTranslation::Synonym; type <= KEduVocTranslation::FalseFriend; type++) {
414  switch (type) {
415  case KEduVocTranslation::Synonym:
416  pairElement= rootElement.firstChildElement( KVTML_SYNONYM );
417  break;
418  case KEduVocTranslation::Antonym:
419  pairElement= rootElement.firstChildElement( KVTML_ANTONYM );
420  break;
421  case KEduVocTranslation::FalseFriend:
422  pairElement= rootElement.firstChildElement( KVTML_FALSEFRIEND );
423  break;
424  }
425  // pair
426  pairElement = pairElement.firstChildElement( KVTML_PAIR );
427  while ( !pairElement.isNull() ) {
428  //<entry id="123"/>
429  QDomElement entryElement = pairElement.firstChildElement( KVTML_ENTRY );
430  int firstEntryId = entryElement.attribute( KVTML_ID ).toInt();
431 
432  QDomElement translationElement = entryElement.firstChildElement( KVTML_TRANSLATION );
433  int firstTranslationId = translationElement.attribute( KVTML_ID ).toInt();
434 
435  // second entry
436  entryElement = entryElement.nextSiblingElement( KVTML_ENTRY );
437  int secondEntryId = entryElement.attribute( KVTML_ID ).toInt();
438  translationElement = entryElement.firstChildElement( KVTML_TRANSLATION );
439  int secondTranslationId = translationElement.attribute( KVTML_ID ).toInt();
440 
441  // pair them up
442  KEduVocTranslation *first = m_allEntries[firstEntryId]->translation(firstTranslationId);
443  KEduVocTranslation *second = m_allEntries[secondEntryId]->translation(secondTranslationId);
444 
445  switch (type) {
446  case KEduVocTranslation::Synonym:
447  first->addSynonym(second);
448  second->addSynonym(first);
449  break;
450  case KEduVocTranslation::Antonym:
451  first->addAntonym(second);
452  second->addAntonym(first);
453  break;
454  case KEduVocTranslation::FalseFriend:
455  first->addFalseFriend(second);
456  second->addFalseFriend(first);
457  break;
458  }
459  pairElement = pairElement.nextSiblingElement( KVTML_PAIR );
460  }
461  }
462  return true;
463 }
464 
465 bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifierNum )
466 /*
467  <article>
468  <singlular>
469  <definite>
470  <male>der</male>
471  <female>die</female>
472  <neutral>das</neutral>
473  </definite>
474  <indefinite>
475  <male>ein</male>
476  <female>eine</female>
477  <neutral>ein</neutral>
478  </indefinite>
479  </singular>
480  <dual>
481  </dual>
482  </article>
483 */
484 {
485  QMap<int, KEduVocWordFlag::Flags> numbers;
486  numbers[0] = KEduVocWordFlag::Singular;
487  numbers[1] = KEduVocWordFlag::Dual;
488  numbers[2] = KEduVocWordFlag::Plural;
489  QMap<int, KEduVocWordFlag::Flags> genders;
490  genders[0] = KEduVocWordFlag::Masculine;
491  genders[1] = KEduVocWordFlag::Feminine;
492  genders[2] = KEduVocWordFlag::Neuter;
493  QMap<int, KEduVocWordFlag::Flags> defs;
494  defs[0] = KEduVocWordFlag::Definite;
495  defs[1] = KEduVocWordFlag::Indefinite;
496 
497  for ( int num = 0; num <= 2; ++num) {
498  QDomElement numberElement = articleElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[num] );
499  if (!numberElement.isNull()) {
500  // definite
501  for ( int def = 0; def <= 1; ++def ) {
502  QDomElement defElement = numberElement.firstChildElement( KVTML_GRAMMATICAL_DEFINITENESS[def] );
503  if (!defElement.isNull()) {
504  // male
505  for ( int gen = 0; gen <= 2; ++gen ) {
506  QDomElement genderElement = defElement.firstChildElement( KVTML_GRAMMATICAL_GENDER[gen] );
507  if (!genderElement.isNull()) {
508  m_doc->identifier(identifierNum).article().setArticle( genderElement.text(), numbers[num] | defs[def] | genders[gen]);
509  }
510  }
511  }
512  }
513  }
514  }
515 
516  return true;
517 }
518 
519 
520 bool KEduVocKvtml2Reader::readChildWordTypes(KEduVocWordType* parentContainer, QDomElement &lessonElement)
521 {
522  QDomElement currentElement = lessonElement.firstChildElement( KVTML_CONTAINER );
523  while ( !currentElement.isNull() ) {
524  readWordType(parentContainer, currentElement);
525  currentElement = currentElement.nextSiblingElement( KVTML_CONTAINER );
526  }
527  return true;
528 }
529 
530 bool KEduVocKvtml2Reader::readLeitner( KEduVocLeitnerBox* parentContainer, QDomElement &leitnerParentElement )
531 {
532  QDomElement leitnerElement = leitnerParentElement.firstChildElement( KVTML_CONTAINER );
533  while ( !leitnerElement.isNull() ) {
534  QString name = leitnerElement.firstChildElement( KVTML_NAME ).text();
535 
536  KEduVocLeitnerBox * leitner = new KEduVocLeitnerBox(name, parentContainer);
537  parentContainer->appendChildContainer(leitner);
538  // for leitner we only allow a flat list, no sub boxes.
539 
540  // read entries
541  QDomElement entryElement = leitnerElement.firstChildElement( KVTML_ENTRY );
542  while ( !entryElement.isNull() ) {
543  // read <entry id="123"></entryid>
544  int entryId = entryElement.attribute( KVTML_ID ).toInt();
545  QDomElement translationElement = entryElement.firstChildElement( KVTML_TRANSLATION );
546  while( !translationElement.isNull() ) {
547  // <translation id="234"/>
548  int translationId = translationElement.attribute( KVTML_ID ).toInt();
549  m_allEntries.value(entryId)->translation(translationId)->setLeitnerBox(leitner);
550  translationElement = translationElement.nextSiblingElement( KVTML_TRANSLATION );
551  }
552  entryElement = entryElement.nextSiblingElement( KVTML_ENTRY );
553  }
554  leitnerElement = leitnerElement.nextSiblingElement( KVTML_CONTAINER );
555  }
556  return true;
557 }
558 
559 bool KEduVocKvtml2Reader::readWordType( KEduVocWordType* parentContainer, QDomElement &typeElement )
560 {
561  // set type and specialtype
562  QString typeName =
563  typeElement.firstChildElement( KVTML_NAME ).text();
564 
565  KEduVocWordType * wordTypeContainer = new KEduVocWordType(typeName, parentContainer);
566  parentContainer->appendChildContainer(wordTypeContainer);
567 
568  QString specialType = typeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text();
569  if ( !specialType.isEmpty() ) {
570  // get the localized version
571  if ( specialType == KVTML_SPECIALWORDTYPE_NOUN ) {
572  wordTypeContainer->setWordType(KEduVocWordFlag::Noun);
573  }
574  if ( specialType == KVTML_SPECIALWORDTYPE_VERB ) {
575  wordTypeContainer->setWordType(KEduVocWordFlag::Verb);
576  }
577  if ( specialType == KVTML_SPECIALWORDTYPE_ADVERB ) {
578  wordTypeContainer->setWordType(KEduVocWordFlag::Adverb);
579  }
580  if ( specialType == KVTML_SPECIALWORDTYPE_ADJECTIVE ) {
581  wordTypeContainer->setWordType(KEduVocWordFlag::Adjective);
582  }
583  if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_MALE ) {
584  wordTypeContainer->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine);
585  }
586  if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) {
587  wordTypeContainer->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine);
588  }
589  if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) {
590  wordTypeContainer->setWordType(KEduVocWordFlag::Noun| KEduVocWordFlag::Neuter);
591  }
592  if ( specialType == KVTML_SPECIALWORDTYPE_CONJUNCTION ) {
593  wordTypeContainer->setWordType(KEduVocWordFlag::Conjunction);
594  }
595  } // special type
596 
597  // read entries
598  QDomElement entryElement = typeElement.firstChildElement( KVTML_ENTRY );
599  while ( !entryElement.isNull() ) {
600  // read <entry id="123"></entryid>
601  int entryId = entryElement.attribute( KVTML_ID ).toInt();
602  QDomElement translationElement = entryElement.firstChildElement( KVTML_TRANSLATION );
603  while( !translationElement.isNull() ) {
604  // <translation id="234"/>
605  int translationId = translationElement.attribute( KVTML_ID ).toInt();
606  m_allEntries.value(entryId)->translation(translationId)->setWordType(wordTypeContainer);
607  translationElement = translationElement.nextSiblingElement( KVTML_TRANSLATION );
608  }
609  entryElement = entryElement.nextSiblingElement( KVTML_ENTRY );
610  }
611 
612  readChildWordTypes(wordTypeContainer, typeElement);
613 
614  return true;
615 }
616 
617 QStringList KEduVocKvtml2Reader::readTenses( QDomElement &tensesElement )
618 {
619  QStringList tenses;
620 
621  QDomNodeList tenseNodes = tensesElement.elementsByTagName( KVTML_TENSE );
622  for ( int i = 0; i < tenseNodes.count(); ++i ) {
623  QDomElement currentElement = tenseNodes.item( i ).toElement();
624  if ( currentElement.parentNode() == tensesElement ) {
625  tenses.append( currentElement.text() );
626  }
627  }
628 
629  return tenses;
630 }
631 
632 bool KEduVocKvtml2Reader::readComparison( QDomElement &domElementParent, KEduVocTranslation* translation )
633 /*
634  <comparison>
635  <comparative>better</comparative>
636  <superlative>best</superlative>
637  </comparison>
638 */
639 {
640  QDomElement currentElement;
641 
642  currentElement = domElementParent.firstChildElement( KVTML_COMPARATIVE );
643  if ( !currentElement.isNull() )
644  {
645  KEduVocText comparative;
646  comparative.fromKVTML2(currentElement);
647 
648  // be compatible for KDE < 4.5
649  if (comparative.text().isEmpty()) {
650  comparative.setText(currentElement.text());
651  }
652  translation->setComparativeForm(comparative);
653  }
654 
655  currentElement = domElementParent.firstChildElement( KVTML_SUPERLATIVE );
656  if ( !currentElement.isNull() )
657  {
658  KEduVocText superlative;
659  superlative.fromKVTML2(currentElement);
660 
661  // be compatible for KDE < 4.5
662  if (superlative.text().isEmpty()) {
663  superlative.setText(currentElement.text());
664  }
665  translation->setSuperlativeForm(superlative);
666  }
667  return true;
668 }
669 
670 bool KEduVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation* translation )
671 /*
672  <multiplechoice>
673  <choice>good</choice>
674  <choice>better</choice>
675  <choice>best</choice>
676  <choice>best 2</choice>
677  <choice>best 3</choice>
678  </multiplechoice>
679 */
680 {
681  QDomElement currentElement;
682  QDomNodeList choiceNodes = multipleChoiceElement.elementsByTagName( KVTML_CHOICE );
683  for ( int i = 0; i < choiceNodes.count(); ++i )
684  {
685  currentElement = choiceNodes.item( i ).toElement();
686  if ( currentElement.parentNode() == multipleChoiceElement ) {
687  translation->multipleChoice().append( currentElement.text() );
688  }
689  }
690  return true;
691 }
692 
693 
694 bool KEduVocKvtml2Reader::readPersonalPronoun(QDomElement & pronounElement, KEduVocPersonalPronoun & pronoun)
695 {
696  pronoun.setMaleFemaleDifferent(!pronounElement.firstChildElement(
697  KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT).isNull());
698  pronoun.setNeutralExists( !pronounElement.firstChildElement(
699  KVTML_THIRD_PERSON_NEUTRAL_EXISTS).isNull() );
700  pronoun.setDualExists( !pronounElement.firstChildElement(
701  KVTML_DUAL_EXISTS).isNull() );
702 
703  QDomElement personElement = pronounElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[0] );
704  if ( !personElement.isNull() ) {
705  readPersonalPronounChild( personElement, pronoun, KEduVocWordFlag::Singular );
706  }
707 
708  personElement = pronounElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[1] );
709  if ( !personElement.isNull() ) {
710  readPersonalPronounChild( personElement, pronoun, KEduVocWordFlag::Dual );
711  }
712 
713  personElement = pronounElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[2] );
714  if ( !personElement.isNull() ) {
715  readPersonalPronounChild( personElement, pronoun, KEduVocWordFlag::Plural );
716  }
717  return true;
718 }
719 
720 
721 bool KEduVocKvtml2Reader::readPersonalPronounChild(QDomElement & personElement, KEduVocPersonalPronoun & pronoun, KEduVocWordFlags number)
722 {
723  QMap<int, KEduVocWordFlag::Flags> persons;
724  persons[0] = KEduVocWordFlag::First;
725  persons[1] = KEduVocWordFlag::Second;
726  persons[2] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Masculine);
727  persons[3] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Feminine);
728  persons[4] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Neuter);
729 
730 
731 
732  for (int person = 0; person < 5; person++) {
733  QDomElement currentElement = personElement.firstChildElement( KVTML_GRAMMATICAL_PERSON[person] );
734  pronoun.setPersonalPronoun( currentElement.text(), persons[person] | number );
735  }
736 
737  return true;
738 }
739 
740 
741 #include "keduvockvtml2reader.moc"
KVTML_TITLE
#define KVTML_TITLE
Definition: kvtml2defs.h:27
KEduVocTranslation::setSuperlativeForm
void setSuperlativeForm(const KEduVocText &superlative)
Definition: keduvoctranslation.cpp:456
KEduVocLesson::appendEntry
void appendEntry(KEduVocExpression *entry)
append an entry to the lesson
Definition: keduvoclesson.cpp:67
KEduVocTranslation::addAntonym
void addAntonym(KEduVocTranslation *antonym)
Add a antonym.
Definition: keduvoctranslation.cpp:245
keduvocdocument.h
KEduVocWordFlag::Adjective
Definition: keduvocwordflags.h:41
KVTML_GRAMMATICAL_NUMBER
static const QString KVTML_GRAMMATICAL_NUMBER[]
Definition: kvtml2defs.h:60
KVTML_DEACTIVATED
#define KVTML_DEACTIVATED
Definition: kvtml2defs.h:127
KVTML_SPECIALWORDTYPE_CONJUNCTION
#define KVTML_SPECIALWORDTYPE_CONJUNCTION
Definition: kvtml2defs.h:114
KEduVocTranslation::FalseFriend
Definition: keduvoctranslation.h:42
KEduVocLesson
class to store information about a lesson
Definition: keduvoclesson.h:27
KEduVocTranslation::setSoundUrl
void setSoundUrl(const KUrl &url)
Set the sound url for this translation.
Definition: keduvoctranslation.cpp:336
KVTML_COMMENT
#define KVTML_COMMENT
Definition: kvtml2defs.h:31
KEduVocKvtmlReader
Definition: keduvockvtmlreader.h:39
KEduVocWordFlag::Verb
Definition: keduvocwordflags.h:38
KVTML_WORDTYPES
#define KVTML_WORDTYPES
Definition: kvtml2defs.h:99
keduvoccommon_p.h
KEduVocIdentifier
Class to store meta information about a language or any other category in the vocabulary.
Definition: keduvocidentifier.h:29
KVTML_ARTICLE
#define KVTML_ARTICLE
Definition: kvtml2defs.h:42
KVTML_ANTONYM
#define KVTML_ANTONYM
Definition: kvtml2defs.h:135
KEduVocPersonalPronoun::setMaleFemaleDifferent
void setMaleFemaleDifferent(bool different)
Definition: keduvocpersonalpronoun.cpp:101
KVTML_SPECIALWORDTYPE_NOUN
#define KVTML_SPECIALWORDTYPE_NOUN
Definition: kvtml2defs.h:107
KEduVocWordFlag::Singular
Definition: keduvocwordflags.h:33
KEduVocWordFlag::Third
Definition: keduvocwordflags.h:49
KEduVocTranslation::multipleChoice
QStringList & multipleChoice()
Returns multiple choice if available.
Definition: keduvoctranslation.cpp:296
KVTML_SPECIALWORDTYPE_VERB
#define KVTML_SPECIALWORDTYPE_VERB
Definition: kvtml2defs.h:111
KVTML_PERSONALPRONOUNS
#define KVTML_PERSONALPRONOUNS
Definition: kvtml2defs.h:47
KEduVocWordFlag::Masculine
Definition: keduvocwordflags.h:28
KVTML_FALSEFRIEND
#define KVTML_FALSEFRIEND
Definition: kvtml2defs.h:134
KEduVocTranslation::Antonym
Definition: keduvoctranslation.h:41
keduvocwordtype.h
KEduVocTranslation::addSynonym
void addSynonym(KEduVocTranslation *synonym)
Add a synonym.
Definition: keduvoctranslation.cpp:230
KEduVocKvtmlReader::errorMessage
QString errorMessage() const
Definition: keduvockvtmlreader.h:87
KEduVocDocument::setAuthor
void setAuthor(const QString &author)
Set the author of the file.
Definition: keduvocdocument.cpp:761
KVTML_SOUND
#define KVTML_SOUND
Definition: kvtml2defs.h:150
KVTML_NAME
#define KVTML_NAME
Definition: kvtml2defs.h:38
KEduVocDocument::setDocumentComment
void setDocumentComment(const QString &comment)
Set the comment of the file.
Definition: keduvocdocument.cpp:819
KEduVocDocument::url
KUrl url() const
Definition: keduvocdocument.cpp:731
KEduVocWordFlag::First
Definition: keduvocwordflags.h:47
KVTML_SYNONYM
#define KVTML_SYNONYM
Definition: kvtml2defs.h:136
KEduVocDocument::appendIdentifier
int appendIdentifier(const KEduVocIdentifier &identifier=KEduVocIdentifier())
Appends a new identifier (usually a language)
Definition: keduvocdocument.cpp:699
KVTML_IMAGE
#define KVTML_IMAGE
Definition: kvtml2defs.h:149
KVTML_IDENTIFIERS
#define KVTML_IDENTIFIERS
Definition: kvtml2defs.h:34
KEduVocPersonalPronoun::setNeutralExists
void setNeutralExists(bool exists)
Definition: keduvocpersonalpronoun.cpp:111
keduvoclesson.h
KEduVocWordFlag::Flags
Flags
Definition: keduvocwordflags.h:22
KEduVocDocument::leitnerContainer
KEduVocLeitnerBox * leitnerContainer()
Definition: keduvocdocument.cpp:726
KEduVocIdentifier::article
KEduVocArticle & article() const
Articles (a, the in English, el, la,...
Definition: keduvocidentifier.cpp:106
KEduVocIdentifier::setTenseList
void setTenseList(const QStringList &tenses)
Definition: keduvocidentifier.cpp:142
KVTML_VERSION
#define KVTML_VERSION
Definition: kvtml2defs.h:21
KEduVocDocument::setVersion
void setVersion(const QString &ver)
Sets version of the loaded file.
Definition: keduvocdocument.cpp:841
KEduVocLeitnerBox
Leitner Boxes are an alternative grading system.
Definition: keduvocleitnerbox.h:31
KEduVocPersonalPronoun
The conjugation of a verb.
Definition: keduvocpersonalpronoun.h:25
KEduVocDocument::setAuthorContact
void setAuthorContact(const QString &authorContact)
Set the author contact info.
Definition: keduvocdocument.cpp:772
KVTML_GRAMMATICAL_PERSON
static const QString KVTML_GRAMMATICAL_PERSON[]
Definition: kvtml2defs.h:72
KVTML_AUTHOR
#define KVTML_AUTHOR
Definition: kvtml2defs.h:28
KVTML_LESSONS
#define KVTML_LESSONS
Definition: kvtml2defs.h:100
KEduVocWordType
class to store translation word types
Definition: keduvocwordtype.h:33
KVTML_DUAL_EXISTS
#define KVTML_DUAL_EXISTS
Definition: kvtml2defs.h:91
KEduVocDocument::generator
QString generator() const
Definition: keduvocdocument.cpp:831
KEduVocExpression::setTranslation
void setTranslation(int index, KEduVocTranslation *translation)
KEduVocDocument::setCategory
void setCategory(const QString &category)
Set the category of the file.
Definition: keduvocdocument.cpp:788
KEduVocDocument::identifier
KEduVocIdentifier & identifier(int index)
Returns the identifier of translation index.
Definition: keduvocdocument.cpp:654
keduvockvtmlreader.h
KEduVocKvtml2Reader::readDoc
bool readDoc(KEduVocDocument *doc)
read the document
Definition: keduvockvtml2reader.cpp:48
KEduVocTranslation::fromKVTML2
void fromKVTML2(QDomElement &parent)
Definition: keduvoctranslation.cpp:528
KEduVocIdentifier::setName
void setName(const QString &name)
Set the name.
Definition: keduvocidentifier.cpp:86
KVTML_CATEGORY
#define KVTML_CATEGORY
Definition: kvtml2defs.h:32
KEduVocDocument::setGenerator
void setGenerator(const QString &generator)
Sets the generator of the file.
Definition: keduvocdocument.cpp:825
KVTML_SPECIALWORDTYPE_ADVERB
#define KVTML_SPECIALWORDTYPE_ADVERB
Definition: kvtml2defs.h:113
KEduVocContainer::setInPractice
void setInPractice(bool inPractice)
Definition: keduvoccontainer.cpp:166
KVTML_SPECIALWORDTYPE_NOUN_FEMALE
#define KVTML_SPECIALWORDTYPE_NOUN_FEMALE
Definition: kvtml2defs.h:109
KVTML_INPRACTICE
#define KVTML_INPRACTICE
Definition: kvtml2defs.h:103
KEduVocDocument::wordTypeContainer
KEduVocWordType * wordTypeContainer()
Definition: keduvocdocument.cpp:721
KVTML_CONTAINER
#define KVTML_CONTAINER
Definition: kvtml2defs.h:102
KEduVocExpression::setActive
void setActive(bool flag=true)
set entry active (enabled for queries)
Definition: keduvocexpression.cpp:156
KEduVocText
A text in vocabulary documents.
Definition: keduvoctext.h:59
KVTML_IDENTIFIER
#define KVTML_IDENTIFIER
Definition: kvtml2defs.h:35
KVTML_MULTIPLECHOICE
#define KVTML_MULTIPLECHOICE
Definition: kvtml2defs.h:146
KVTML_SPECIALWORDTYPE
#define KVTML_SPECIALWORDTYPE
Definition: kvtml2defs.h:106
KVTML_TRUE
#define KVTML_TRUE
Definition: kvtml2defs.h:159
KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL
#define KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL
Definition: kvtml2defs.h:110
KEduVocWordFlag::Conjunction
Definition: keduvocwordflags.h:44
KVTML_THIRD_PERSON_NEUTRAL_EXISTS
#define KVTML_THIRD_PERSON_NEUTRAL_EXISTS
Definition: kvtml2defs.h:90
KEduVocPersonalPronoun::setDualExists
void setDualExists(bool exists)
Definition: keduvocpersonalpronoun.cpp:121
KEduVocTranslation::setImageUrl
void setImageUrl(const KUrl &url)
Set the image url for this translation.
Definition: keduvoctranslation.cpp:350
KEduVocWordFlag::Plural
Definition: keduvocwordflags.h:35
KVTML_TAG
#define KVTML_TAG
Definition: kvtml2defs.h:20
KEduVocText::fromKVTML2
void fromKVTML2(QDomElement &parent)
Definition: keduvoctext.cpp:205
KEduVocTranslation::addFalseFriend
void addFalseFriend(KEduVocTranslation *falseFriend)
Add a false friend.
Definition: keduvoctranslation.cpp:214
KEduVocExpression::lesson
KEduVocLesson * lesson() const
return the lesson
Definition: keduvocexpression.cpp:144
KEduVocTranslation
Definition: keduvoctranslation.h:35
KEduVocWordFlag::Noun
Definition: keduvocwordflags.h:39
KVTML_TENSES
#define KVTML_TENSES
Definition: kvtml2defs.h:117
KVTML_TRANSLATION
#define KVTML_TRANSLATION
Definition: kvtml2defs.h:129
KEduVocWordFlag::Indefinite
Definition: keduvocwordflags.h:62
KVTML_LICENSE
#define KVTML_LICENSE
Definition: kvtml2defs.h:30
KVTML_ENTRIES
#define KVTML_ENTRIES
Definition: kvtml2defs.h:125
KEduVocExpression
This class contains one vocabulary expression as an original with one or more translations.
Definition: keduvocexpression.h:37
KEduVocKvtml2Reader::KEduVocKvtml2Reader
KEduVocKvtml2Reader(QIODevice *file)
default constructor
Definition: keduvockvtml2reader.cpp:38
KVTML_PAIR
#define KVTML_PAIR
Definition: kvtml2defs.h:133
KVTML_LEITNERBOXES
#define KVTML_LEITNERBOXES
Definition: kvtml2defs.h:101
KEduVocDocument::identifierCount
int identifierCount() const
Definition: keduvocdocument.cpp:694
KVTML_SPECIALWORDTYPE_ADJECTIVE
#define KVTML_SPECIALWORDTYPE_ADJECTIVE
Definition: kvtml2defs.h:112
KEduVocTranslation::setComparativeForm
void setComparativeForm(const KEduVocText &comparative)
Definition: keduvoctranslation.cpp:439
KEduVocKvtmlReader::readDoc
bool readDoc(KEduVocDocument *doc)
Definition: keduvockvtmlreader.cpp:45
KEduVocArticle::setArticle
void setArticle(const QString &article, const KEduVocWordFlags &)
Definition: keduvocarticle.cpp:68
KVTML_GRAMMATICAL_DEFINITENESS
static const QString KVTML_GRAMMATICAL_DEFINITENESS[]
Definition: kvtml2defs.h:80
KVTML_GRAMMATICAL_GENDER
static const QString KVTML_GRAMMATICAL_GENDER[]
Definition: kvtml2defs.h:66
KVTML_COMPARISON
#define KVTML_COMPARISON
Definition: kvtml2defs.h:141
KVTML_SPECIALWORDTYPE_NOUN_MALE
#define KVTML_SPECIALWORDTYPE_NOUN_MALE
Definition: kvtml2defs.h:108
KEduVocText::text
QString text() const
The translation as string (the word itself)
Definition: keduvoctext.cpp:55
KEduVocDocument::setLicense
void setLicense(const QString &license)
Set the license of the file.
Definition: keduvocdocument.cpp:813
KEduVocWordFlag::Adverb
Definition: keduvocwordflags.h:42
KEduVocContainer::appendChildContainer
void appendChildContainer(KEduVocContainer *child)
Definition: keduvoccontainer.cpp:77
kvtml2defs.h
KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT
#define KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT
Definition: kvtml2defs.h:88
KVD_VERS_PREFIX
#define KVD_VERS_PREFIX
Definition: keduvoccommon_p.h:14
KEduVocExpression::translation
KEduVocTranslation * translation(int index)
Get a pointer to the translation.
Definition: keduvocexpression.cpp:182
KVTML_AUTHORCONTACT
#define KVTML_AUTHORCONTACT
Definition: kvtml2defs.h:29
KEduVocTranslation::Synonym
Definition: keduvoctranslation.h:40
KEduVocLesson::entryCount
int entryCount(EnumEntriesRecursive recursive=NotRecursive)
get the number of entries in the lesson
Definition: keduvoclesson.cpp:59
KEduVocExpression::translationIndices
QList< int > translationIndices() const
Definition: keduvocexpression.cpp:199
KEduVocIdentifier::setPersonalPronouns
void setPersonalPronouns(const KEduVocPersonalPronoun &pronouns)
Sets personal pronouns.
Definition: keduvocidentifier.cpp:116
KVTML_CHOICE
#define KVTML_CHOICE
Definition: kvtml2defs.h:147
keduvocleitnerbox.h
KEduVocDocument::setTitle
void setTitle(const QString &title)
Set the title of the file.
Definition: keduvocdocument.cpp:749
KVTML_COMPARATIVE
#define KVTML_COMPARATIVE
Definition: kvtml2defs.h:143
KEduVocWordFlag::Neuter
Definition: keduvocwordflags.h:30
KEduVocDocument::lesson
KEduVocLesson * lesson()
Get the lesson root object.
Definition: keduvocdocument.cpp:716
KEduVocText::setText
void setText(const QString &expr)
Sets the translation.
Definition: keduvoctext.cpp:60
KVTML_GENERATOR
#define KVTML_GENERATOR
Definition: kvtml2defs.h:26
KVTML_INFORMATION
#define KVTML_INFORMATION
Definition: kvtml2defs.h:24
KEduVocWordType::setWordType
void setWordType(KEduVocWordFlags flags)
assignment operator
Definition: keduvocwordtype.cpp:126
KEduVocTranslation::setArticle
void setArticle(const KEduVocText &article)
Definition: keduvoctranslation.cpp:473
KEduVocDocument
This class contains the expressions of your vocabulary as well as other information about the vocabul...
Definition: keduvocdocument.h:44
KVTML_LOCALE
#define KVTML_LOCALE
Definition: kvtml2defs.h:37
KVTML_ENTRY
#define KVTML_ENTRY
Definition: kvtml2defs.h:126
KVTML_IDENTIFIERTYPE
#define KVTML_IDENTIFIERTYPE
Definition: kvtml2defs.h:36
KEduVocWordFlag::Feminine
Definition: keduvocwordflags.h:29
KVTML_SUPERLATIVE
#define KVTML_SUPERLATIVE
Definition: kvtml2defs.h:144
KEduVocWordFlag::Second
Definition: keduvocwordflags.h:48
KVTML_ID
#define KVTML_ID
Definition: kvtml2defs.h:22
KEduVocWordFlag::Definite
Definition: keduvocwordflags.h:61
KEduVocWordFlag::Dual
Definition: keduvocwordflags.h:34
keduvockvtml2reader.h
KEduVocPersonalPronoun::setPersonalPronoun
void setPersonalPronoun(const QString &conjugation, KEduVocWordFlags flags)
Definition: keduvocpersonalpronoun.cpp:90
KVTML_TENSE
#define KVTML_TENSE
Definition: kvtml2defs.h:118
KEduVocIdentifier::setLocale
void setLocale(const QString &name)
Set the locale.
Definition: keduvocidentifier.cpp:96
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:37:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdeedu/keduvocdocument

Skip menu "libkdeedu/keduvocdocument"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal