• 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
keduvockvtml2writer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  export a KEduVocDocument to a KVTML file
3  -----------------------------------------------------------------------
4  copyright : (C) 2007 Jeremy Whiting <jpwhiting@kde.org>
5  Copyright 2007-2010 Frederik Gladhorn <gladhorn@kde.org>
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "keduvockvtml2writer.h"
18 
19 #include <QtCore/QTextStream>
20 #include <QtCore/QFile>
21 
22 #include <KDebug>
23 
24 #include "keduvocdocument.h"
25 #include "keduvocexpression.h"
26 #include "keduvoclesson.h"
27 #include "keduvocleitnerbox.h"
28 #include "keduvocwordtype.h"
29 #include "kvtml2defs.h"
30 
31 KEduVocKvtml2Writer::KEduVocKvtml2Writer( QFile *file )
32 {
33  // the file must be already open
34  m_outputFile = file;
35 }
36 
37 bool KEduVocKvtml2Writer::writeDoc( KEduVocDocument *doc, const QString &generator )
38 {
39  if (createXmlDocument(doc, generator)) {
40  QTextStream ts( m_outputFile );
41  m_domDoc.save( ts, 2 );
42  return true;
43  }
44  return false;
45 }
46 
47 QByteArray KEduVocKvtml2Writer::toByteArray(KEduVocDocument * doc, const QString & generator)
48 {
49  if (createXmlDocument(doc, generator)) {
50  return m_domDoc.toByteArray();
51  }
52  return QByteArray();
53 }
54 
55 bool KEduVocKvtml2Writer::createXmlDocument( KEduVocDocument *doc, const QString &generator )
56 {
57  m_doc = doc;
58 
59  m_domDoc = QDomDocument( "kvtml PUBLIC \"kvtml2.dtd\" \"http://edu.kde.org/kvtml/kvtml2.dtd\"" );
60  m_domDoc.appendChild( m_domDoc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
61  QDomElement domElementKvtml = m_domDoc.createElement( "kvtml" );
62  m_domDoc.appendChild( domElementKvtml );
63 
64  domElementKvtml.setAttribute( KVTML_VERSION, ( QString ) "2.0" );
65 
66  // information group
67  QDomElement currentElement = m_domDoc.createElement( KVTML_INFORMATION );
68  writeInformation( currentElement, generator );
69  domElementKvtml.appendChild( currentElement );
70 
71  // identifiers
72  currentElement = m_domDoc.createElement( KVTML_IDENTIFIERS );
73  writeIdentifiers( currentElement );
74  domElementKvtml.appendChild( currentElement );
75 
76  // entries
77  currentElement = m_domDoc.createElement( KVTML_ENTRIES );
78  if ( !writeEntries( currentElement ) ) {
79  // at least one entry is required!
80  return false;
81  }
82  domElementKvtml.appendChild( currentElement );
83 
84  // lessons
85  currentElement = m_domDoc.createElement( KVTML_LESSONS );
86  writeLessons( m_doc->lesson(), currentElement );
87  if ( currentElement.hasChildNodes() ) {
88  domElementKvtml.appendChild( currentElement );
89  }
90 
91  // types
92  currentElement = m_domDoc.createElement( KVTML_WORDTYPES );
93  writeWordTypes( currentElement, m_doc->wordTypeContainer() );
94  if ( currentElement.hasChildNodes() ) {
95  domElementKvtml.appendChild( currentElement );
96  }
97 
98  // leitner boxes
99  currentElement = m_domDoc.createElement( KVTML_LEITNERBOXES );
100  writeLeitnerBoxes( currentElement, m_doc->leitnerContainer() );
101  if ( currentElement.hasChildNodes() ) {
102  domElementKvtml.appendChild( currentElement );
103  }
104 
105  writeSynonymAntonymFalseFriend(domElementKvtml);
106 
107  m_domDoc.appendChild( domElementKvtml );
108 
109  return true;
110 }
111 
112 bool KEduVocKvtml2Writer::writeInformation( QDomElement &informationElement, const QString &generator )
113 {
114  QDomElement currentElement;
115  QDomText textNode;
116 
117  // generator
118  informationElement.appendChild( newTextElement( KVTML_GENERATOR, generator ) );
119 
120  // title
121  if ( !m_doc->title().isEmpty() ) {
122  informationElement.appendChild( newTextElement( KVTML_TITLE, m_doc->title() ) );
123  }
124 
125  // author
126  if ( !m_doc->author().isEmpty() ) {
127  informationElement.appendChild( newTextElement( KVTML_AUTHOR, m_doc->author() ) );
128  }
129 
130  // author contact (mail/homepage)
131  if ( !m_doc->authorContact().isEmpty() ) {
132  informationElement.appendChild( newTextElement( KVTML_AUTHORCONTACT, m_doc->authorContact() ) );
133  }
134 
135  // license
136  if ( !m_doc->license().isEmpty() ) {
137  informationElement.appendChild( newTextElement( KVTML_LICENSE, m_doc->license() ) );
138  }
139 
140  // comment
141  if ( !m_doc->documentComment().isEmpty() ) {
142  informationElement.appendChild( newTextElement( KVTML_COMMENT, m_doc->documentComment() ) );
143  }
144 
145  QDate today = QDate::currentDate();
146  informationElement.appendChild( newTextElement( KVTML_DATE, today.toString(QLatin1String("yyyy-MM-dd")) ) );
147 
148  // category
149  if ( !m_doc->category().isEmpty() ) {
150  informationElement.appendChild( newTextElement( KVTML_CATEGORY, m_doc->category() ) );
151  }
152 
153  return true;
154 }
155 
156 
157 bool KEduVocKvtml2Writer::writeIdentifiers( QDomElement &identifiersElement )
158 {
159  for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
160  // create the node
161  QDomElement identifier = m_domDoc.createElement( KVTML_IDENTIFIER );
162 
163  // set the id
164  identifier.setAttribute( KVTML_ID, QString::number( i ) );
165 
166  // record the identifier as the locale for now
167  // TODO: when support for more parts of the identifier is in the document class (name, type, etc.) store those here as well
168  identifier.appendChild( newTextElement( KVTML_NAME, m_doc->identifier( i ).name() ) );
169 
170  identifier.appendChild( newTextElement( KVTML_LOCALE, m_doc->identifier( i ).locale() ) );
171 
172  // record articles
173  QDomElement article = m_domDoc.createElement( KVTML_ARTICLE );
174  writeArticle( article, i );
175  if ( article.hasChildNodes() ) {
176  identifier.appendChild( article );
177  }
178 
179  // record personalpronouns
180  QDomElement personalpronouns = m_domDoc.createElement( KVTML_PERSONALPRONOUNS );
181  writePersonalPronoun( personalpronouns, m_doc->identifier(i).personalPronouns() );
182  if ( personalpronouns.hasChildNodes() ) {
183  identifier.appendChild( personalpronouns );
184  }
185 
186  // tenses
187  foreach(const QString &tense, m_doc->identifier(i).tenseList() ) {
188  if ( !( tense.isNull() ) ) {
189  identifier.appendChild( newTextElement( KVTML_TENSE, tense ) );
190  }
191  }
192  // add this identifier to the group
193  identifiersElement.appendChild( identifier );
194  }
195  return true;
196 }
197 
198 bool KEduVocKvtml2Writer::writeLessons( KEduVocLesson *parentLesson, QDomElement &lessonsElement )
199 {
200  // iterate over child lessons.
201  // the first time this is called with the root lesson which does not have a <lesson> entry.
202  for( int i = 0; i < parentLesson->childContainerCount(); i++ ) {
203  KEduVocLesson *lesson = static_cast<KEduVocLesson*>(parentLesson->childContainer(i));
204  // make lesson element
205  QDomElement thisLessonElement = m_domDoc.createElement( KVTML_CONTAINER );
206 
207  // add a name
208  thisLessonElement.appendChild( newTextElement( KVTML_NAME, lesson->name() ) );
209 
210  // add a inquery tag
211  if ( lesson->inPractice() ) {
212  thisLessonElement.appendChild( newTextElement( KVTML_INPRACTICE, KVTML_TRUE ) );
213  }
214 
215  // child lessons
216  writeLessons(lesson, thisLessonElement);
217 
218  // child entries
219  foreach(KEduVocExpression *entry, lesson->entries()) {
220  QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
221  entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(entry)) );
222  thisLessonElement.appendChild(entryElement);
223  }
224  lessonsElement.appendChild( thisLessonElement );
225  }
226  return true;
227 }
228 
229 
230 
231 void KEduVocKvtml2Writer::writeSynonymAntonymFalseFriend(QDomElement & parentElement)
232 {
233  QList< KEduVocTranslation* > currentList;
234  QDomElement synonymElement;
235  // synonym, antonym, false friend
236  for(int type = KEduVocTranslation::Synonym; type <= KEduVocTranslation::FalseFriend; type++) {
237  switch (type) {
238  case KEduVocTranslation::Synonym:
239  synonymElement = m_domDoc.createElement( KVTML_SYNONYM );
240  currentList = m_synonyms;
241  break;
242  case KEduVocTranslation::Antonym:
243  synonymElement = m_domDoc.createElement( KVTML_ANTONYM );
244  currentList = m_antonyms;
245  break;
246  case KEduVocTranslation::FalseFriend:
247  synonymElement = m_domDoc.createElement( KVTML_FALSEFRIEND );
248  currentList = m_falseFriends;
249  break;
250  }
251 
252  while (!currentList.isEmpty()) {
253  // after writing a translation, remove it from the list
254  KEduVocTranslation* translation = currentList.takeFirst();
255 
256 
257  QDomElement relatedElement;
258  QList <KEduVocTranslation*> list;
259  switch (type) {
260  case KEduVocTranslation::Synonym:
261  list = translation->synonyms();
262  break;
263  case KEduVocTranslation::Antonym:
264  list = translation->antonyms();
265  break;
266  case KEduVocTranslation::FalseFriend:
267  list = translation->falseFriends();
268  break;
269  }
270  foreach (KEduVocTranslation* synonym, list) {
271  // if it is not in the list it has already been written and we can move on
272  if (currentList.contains(synonym)) {
273  relatedElement = m_domDoc.createElement( KVTML_PAIR );
274 
275  // fill the entry element but only add later if it is valid
276  QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
277  entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(translation->entry())) );
278  // find out which id that is... silly
279  foreach(int index, translation->entry()->translationIndices()) {
280  if (translation->entry()->translation(index) == translation) {
281  // create <translation id="123">
282  QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
283  translationElement.setAttribute( KVTML_ID, QString::number(index) );
284  entryElement.appendChild(translationElement);
285  break;
286  }
287  }
288 
289  relatedElement.appendChild(entryElement);
290 
291 
292  QDomElement partnerElement = m_domDoc.createElement( KVTML_ENTRY );
293  partnerElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(synonym->entry())) );
294  // find out which id that is
295  foreach(int index, synonym->entry()->translationIndices()) {
296  if (synonym->entry()->translation(index) == synonym) {
297  // create <translation id="123">
298  QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
299  translationElement.setAttribute( KVTML_ID, QString::number(index) );
300  partnerElement.appendChild(translationElement);
301  break;
302  }
303  }
304  relatedElement.appendChild( partnerElement );
305  synonymElement.appendChild(relatedElement);
306  }
307  }
308 
309  }
310  if (synonymElement.hasChildNodes()) {
311  parentElement.appendChild( synonymElement );
312  }
313  } // iterate over types
314 }
315 /*
316 bool KEduVocKvtml2Writer::writeRelated(QDomElement & parentElement, QList< KEduVocTranslation * > relatedList)
317 {
318  foreach (KEduVocTranslation* synonym, translation->synonyms()) {
319  QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
320  entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(translation->entry())) );
321 
322  // find out which id that is... silly
323  foreach(int index, translation->entry()->translationIndices()) {
324  if (translation->entry()->translation(index) == translation) {
325  // create <translation id="123">
326  QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
327  translationElement.setAttribute( KVTML_ID, QString::number(index) );
328  entryElement.appendChild(translationElement);
329  }
330  }
331  parentElement.appendChild( entryElement );
332  }
333 }*/
334 
335 bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int language )
336 {
338  QMap<int, KEduVocWordFlag::Flags> numbers;
339  numbers[0] = KEduVocWordFlag::Singular;
340  numbers[1] = KEduVocWordFlag::Dual;
341  numbers[2] = KEduVocWordFlag::Plural;
342  QMap<int, KEduVocWordFlag::Flags> genders;
343  genders[0] = KEduVocWordFlag::Masculine;
344  genders[1] = KEduVocWordFlag::Feminine;
345  genders[2] = KEduVocWordFlag::Neuter;
346  QMap<int, KEduVocWordFlag::Flags> defs;
347  defs[0] = KEduVocWordFlag::Definite;
348  defs[1] = KEduVocWordFlag::Indefinite;
349 
350  for (int num = 0; num <= 2; num++)
351  {
352  QDomElement numberElement = m_domDoc.createElement( KVTML_GRAMMATICAL_NUMBER[num] );
353 
354  for (int def = 0; def <= 1; def++) {
355  QDomElement defElement = m_domDoc.createElement( KVTML_GRAMMATICAL_DEFINITENESS[def] );
356 
357  for (int gen = 0; gen <= 2; gen++)
358  {
359  QString articleString = m_doc->identifier(language).article().article(numbers[num] | genders[gen] | defs[def]);
360  if ( !articleString.isEmpty() ) {
361  defElement.appendChild( newTextElement( KVTML_GRAMMATICAL_GENDER[gen], articleString ) );
362  }
363  }
364  if ( defElement.hasChildNodes() ) {
365  numberElement.appendChild( defElement );
366  }
367  }
368  if ( numberElement.hasChildNodes() ) {
369  articleElement.appendChild( numberElement );
370  }
371  }
372  return true;
373 }
374 
375 
376 bool KEduVocKvtml2Writer::writeWordTypes( QDomElement &typesElement, KEduVocWordType* parentContainer )
377 {
378  foreach( KEduVocContainer* container, parentContainer->childContainers() ) {
379  KEduVocWordType* wordType = static_cast<KEduVocWordType*>(container);
380 
381  QDomElement typeDefinitionElement = m_domDoc.createElement( KVTML_CONTAINER );
382  typeDefinitionElement.appendChild( newTextElement( KVTML_NAME, wordType->name() ) );
383 
384  if (wordType->wordType().testFlag(KEduVocWordFlag::Noun))
385  {
386  if (wordType->wordType().testFlag(KEduVocWordFlag::Masculine))
387  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_MALE ) );
388 
389  else if (wordType->wordType().testFlag(KEduVocWordFlag::Feminine))
390  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) );
391 
392  else if (wordType->wordType().testFlag(KEduVocWordFlag::Neuter))
393  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) );
394  else
395  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN ) );
396  }
397  else if (wordType->wordType().testFlag(KEduVocWordFlag::Verb))
398  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_VERB ) );
399 
400  else if (wordType->wordType().testFlag(KEduVocWordFlag::Adjective))
401  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_ADJECTIVE ) );
402 
403  else if (wordType->wordType().testFlag(KEduVocWordFlag::Adverb))
404  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_ADVERB ) );
405 
406  else if (wordType->wordType().testFlag(KEduVocWordFlag::Conjunction))
407  typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_CONJUNCTION ) );
408 
409 
410 // child entries
411 
412  // child entries
413  foreach(KEduVocExpression *entry, wordType->entries()) {
414  QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
415  entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(entry)) );
416  for(int translation = 0; translation<m_doc->identifierCount(); translation++) {
417  if (entry->translation(translation)->wordType()== wordType) {
418  QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
419  // create <translation id="123">
420  translationElement.setAttribute( KVTML_ID, QString::number(translation) );
421  // append both
422  entryElement.appendChild(translationElement);
423  }
424  }
425  typeDefinitionElement.appendChild( entryElement );
426  }
427 
428  writeWordTypes( typeDefinitionElement, wordType );
429 
430  typesElement.appendChild( typeDefinitionElement );
431  }
432  return true;
433 }
434 
435 bool KEduVocKvtml2Writer::writeLeitnerBoxes( QDomElement &leitnerParentElement, KEduVocLeitnerBox* parentContainer )
436 {
437  foreach( KEduVocContainer* container, parentContainer->childContainers() ) {
438  KEduVocLeitnerBox* leitnerBox = static_cast<KEduVocLeitnerBox*>(container);
439 
440  QDomElement containerElement = m_domDoc.createElement( KVTML_CONTAINER );
441  containerElement.appendChild( newTextElement( KVTML_NAME, leitnerBox->name() ) );
442 
443  // child entries
444  foreach(KEduVocExpression *entry, leitnerBox->entries()) {
445  QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
446  entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(entry)) );
447  for(int translation = 0; translation<m_doc->identifierCount(); translation++) {
448  if (entry->translation(translation)->leitnerBox()== leitnerBox) {
449  QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
450  // create <translation id="123">
451  translationElement.setAttribute( KVTML_ID, QString::number(translation) );
452  // append both
453  entryElement.appendChild(translationElement);
454  }
455  }
456  containerElement.appendChild( entryElement );
457  }
458 
459  leitnerParentElement.appendChild( containerElement );
460  }
461  return true;
462 }
463 
464 bool KEduVocKvtml2Writer::writeEntries( QDomElement &entriesElement )
465 {
466  m_allEntries = m_doc->lesson()->entries(KEduVocLesson::Recursive);
467 
468  // loop through entries
469  for ( int i = 0; i < m_allEntries.count(); ++i ) {
470  KEduVocExpression *thisEntry = m_allEntries.value(i);
471 
472  // write entry tag
473  QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
474 
475  // add id
476  entryElement.setAttribute( KVTML_ID, QString::number( i ) );
477 
478  // write deactivated
479  if(!thisEntry->isActive()) {
480  entryElement.appendChild( newTextElement( KVTML_DEACTIVATED, KVTML_TRUE ) );
481  }
482 
483  // loop through translations
484  foreach( int trans, thisEntry->translationIndices() ) {
485  // write translations
486  QDomElement translation = m_domDoc.createElement( KVTML_TRANSLATION );
487  translation.setAttribute( KVTML_ID, QString::number( trans ) );
488  writeTranslation( translation, thisEntry->translation( trans ) );
489  entryElement.appendChild( translation );
490  }
491  // add this entry to the entriesElement
492  entriesElement.appendChild( entryElement );
493  }
494  return true;
495 }
496 
497 
498 bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEduVocTranslation* translation )
499 {
500  // so far only for KEduVocWord - text and grades
501  translation->toKVTML2(translationElement);
502 
503  // comparison
504  if ( !(translation->comparativeForm().text().isEmpty() || translation->superlativeForm().text().isEmpty())) {
505  kDebug() << "Write comp";
506  QDomElement comparisonElement = m_domDoc.createElement( KVTML_COMPARISON );
507  translationElement.appendChild(comparisonElement);
508 
509  QDomElement comparativeElement = m_domDoc.createElement( KVTML_COMPARATIVE );
510  comparisonElement.appendChild(comparativeElement);
511  translation->comparativeForm().toKVTML2(comparativeElement);
512 
513  QDomElement superlativeElement = m_domDoc.createElement( KVTML_SUPERLATIVE );
514  comparisonElement.appendChild(superlativeElement);
515  translation->superlativeForm().toKVTML2(superlativeElement);
516  }
517 
518  if (translation->article().practiceCount() != 0) {
519  QDomElement articleElement = m_domDoc.createElement( KVTML_ARTICLE );
520  translation->article().toKVTML2(articleElement);
521  translationElement.appendChild(articleElement);
522  }
523 
524  // multiplechoice
525  if ( !translation->multipleChoice().isEmpty() ) {
526  QDomElement multipleChoiceElement = m_domDoc.createElement( KVTML_MULTIPLECHOICE );
527  writeMultipleChoice( multipleChoiceElement, translation );
528  translationElement.appendChild( multipleChoiceElement );
529  }
530 
531  // image
532  if ( !translation->imageUrl().isEmpty() ) {
533  QString urlString;
534  if ( m_doc->url().upUrl().isParentOf( translation->imageUrl()) ) {
535  // try to save as relative url
536  urlString = KUrl::relativeUrl( m_doc->url() , translation->imageUrl() );
537  } else {
538  urlString = translation->imageUrl().url();
539  }
540  translationElement.appendChild( newTextElement( KVTML_IMAGE, urlString ) );
541  }
542 
543  // sound
544  if ( !translation->soundUrl().isEmpty() ) {
545  QString urlString;
546  if ( m_doc->url().upUrl().isParentOf( translation->soundUrl()) ) {
547  // try to save as relative url
548  urlString = KUrl::relativeUrl( m_doc->url() , translation->soundUrl() );
549  } else {
550  urlString = translation->soundUrl().url();
551  }
552  translationElement.appendChild( newTextElement( KVTML_SOUND, urlString ) );
553  }
554 
555 
556  // synonym, antonym, false friend
557  // add to the list if it has any, write later since we want them separate
558  if (!translation->synonyms().isEmpty()) {
559  m_synonyms.append(translation);
560  }
561  if (!translation->antonyms().isEmpty()) {
562  m_antonyms.append(translation);
563  }
564  if (!translation->falseFriends().isEmpty()) {
565  m_falseFriends.append(translation);
566  }
567  return true;
568 }
569 
570 
571 
573  // <falsefriend fromid="0"></falsefriend>
574  // loop through the identifiers
575 // for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
576 // // see if this identifier has a falsefriend in this translation
577 // QString thisFriend = translation->falseFriend( i );
578 // if ( !thisFriend.isEmpty() ) {
579 // // if so, create it, and set the fromid to i
580 // QDomElement thisFriendElement = newTextElement( KVTML_FALSEFRIEND, thisFriend );
581 // thisFriendElement.setAttribute( KVTML_FROMID, QString::number( i ) );
582 // translationElement.appendChild( thisFriendElement );
583 // }
584 // }
585 
586 bool KEduVocKvtml2Writer::writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation* translation )
587 /*
588  <multiplechoice>
589  <choice>good</choice>
590  <choice>better</choice>
591  <choice>best</choice>
592  <choice>best 2</choice>
593  <choice>best 3</choice>
594  </multiplechoice>
595 */
596 {
597  foreach ( const QString &choice, translation->multipleChoice() ) {
598  multipleChoiceElement.appendChild( newTextElement( KVTML_CHOICE, choice ) );
599  }
600  return true;
601 }
602 
603 QDomElement KEduVocKvtml2Writer::newTextElement( const QString &elementName, const QString &text )
604 {
605  QDomElement retval = m_domDoc.createElement( elementName );
606  QDomText textNode = m_domDoc.createTextNode( text );
607  retval.appendChild( textNode );
608  return retval;
609 }
610 
611 bool KEduVocKvtml2Writer::writePersonalPronoun(QDomElement & pronounElement, const KEduVocPersonalPronoun & pronoun)
612 {
613  // general pronoun properties
614  if ( pronoun.maleFemaleDifferent() ) {
615  pronounElement.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT ) );
616  }
617  if ( pronoun.neutralExists() ) {
618  pronounElement.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_NEUTRAL_EXISTS ) );
619  }
620  if ( pronoun.dualExists() ) {
621  pronounElement.appendChild( m_domDoc.createElement( KVTML_DUAL_EXISTS ) );
622  }
623 
624 
625  QMap<int, KEduVocWordFlag::Flags> numbers;
626  numbers[0] = KEduVocWordFlag::Singular;
627  numbers[1] = KEduVocWordFlag::Dual;
628  numbers[2] = KEduVocWordFlag::Plural;
629  QMap<int, KEduVocWordFlag::Flags> persons;
630  persons[0] = KEduVocWordFlag::First;
631  persons[1] = KEduVocWordFlag::Second;
632  persons[2] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Masculine);
633  persons[3] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Feminine);
634  persons[4] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Neuter);
635 
636 
637 
638  // the actual pronouns
639  for ( int num = 0; num < 3; num++ ) {
640  QDomElement numberElement = m_domDoc.createElement( KVTML_GRAMMATICAL_NUMBER[num] );
641  for ( int person = 0; person < 5; person++ ) {
642  QString pronounString = pronoun.personalPronoun(numbers[num] | persons[person]);
643  if (!pronounString.isEmpty()) {
644  numberElement.appendChild( newTextElement( KVTML_GRAMMATICAL_PERSON[person], pronounString ));
645  }
646  }
647  if (numberElement.hasChildNodes()) {
648  pronounElement.appendChild( numberElement );
649  }
650  }
651  return true;
652 }
653 
654 void KEduVocKvtml2Writer::appendTextElement(QDomElement & parent, const QString & elementName, const QString & text)
655 {
656  // empty will never be written
657  if (text.isEmpty()) {
658  return;
659  }
660 
661  QDomDocument domDoc = parent.ownerDocument();
662  QDomElement element = domDoc.createElement( elementName );
663  parent.appendChild( element );
664  QDomText textNode = domDoc.createTextNode( text );
665  element.appendChild( textNode );
666 }
667 
668 
KVTML_TITLE
#define KVTML_TITLE
Definition: kvtml2defs.h:27
KEduVocContainer::childContainers
QList< KEduVocContainer * > childContainers()
Definition: keduvoccontainer.cpp:190
keduvocexpression.h
keduvocdocument.h
KEduVocDocument::license
QString license() const
Definition: keduvocdocument.cpp:778
KEduVocWordFlag::Adjective
Definition: keduvocwordflags.h:41
KVTML_GRAMMATICAL_NUMBER
static const QString KVTML_GRAMMATICAL_NUMBER[]
Definition: kvtml2defs.h:60
KEduVocContainer::inPractice
bool inPractice()
Definition: keduvoccontainer.cpp:161
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
KEduVocContainer
class to store information about a container - that can be a lesson or word types ...
Definition: keduvoccontainer.h:30
KVTML_COMMENT
#define KVTML_COMMENT
Definition: kvtml2defs.h:31
KEduVocWordFlag::Verb
Definition: keduvocwordflags.h:38
KVTML_DATE
#define KVTML_DATE
Definition: kvtml2defs.h:157
KEduVocIdentifier::name
QString name() const
Name of this identifier.
Definition: keduvocidentifier.cpp:81
KVTML_WORDTYPES
#define KVTML_WORDTYPES
Definition: kvtml2defs.h:99
KEduVocWordType::wordType
KEduVocWordFlags wordType() const
Return the raw WordTypeFlags.
Definition: keduvocwordtype.cpp:121
KEduVocTranslation::entry
KEduVocExpression * entry()
Definition: keduvoctranslation.cpp:391
KVTML_ARTICLE
#define KVTML_ARTICLE
Definition: kvtml2defs.h:42
KVTML_ANTONYM
#define KVTML_ANTONYM
Definition: kvtml2defs.h:135
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
KVTML_SOUND
#define KVTML_SOUND
Definition: kvtml2defs.h:150
KVTML_NAME
#define KVTML_NAME
Definition: kvtml2defs.h:38
KEduVocDocument::url
KUrl url() const
Definition: keduvocdocument.cpp:731
KEduVocWordFlag::First
Definition: keduvocwordflags.h:47
KVTML_SYNONYM
#define KVTML_SYNONYM
Definition: kvtml2defs.h:136
KEduVocExpression::isActive
bool isActive() const
returns flag if entry is activated for queries
Definition: keduvocexpression.cpp:150
KEduVocContainer::childContainer
KEduVocContainer * childContainer(int row)
Definition: keduvoccontainer.cpp:85
KVTML_IMAGE
#define KVTML_IMAGE
Definition: kvtml2defs.h:149
KVTML_IDENTIFIERS
#define KVTML_IDENTIFIERS
Definition: kvtml2defs.h:34
keduvoclesson.h
KEduVocWordFlag::Flags
Flags
Definition: keduvocwordflags.h:22
KEduVocTranslation::wordType
KEduVocWordType * wordType() const
Returns the word type of this expression, you will get a 0 pointer if wordtype is not set for the tra...
Definition: keduvoctranslation.cpp:355
KEduVocDocument::leitnerContainer
KEduVocLeitnerBox * leitnerContainer()
Definition: keduvocdocument.cpp:726
KEduVocIdentifier::article
KEduVocArticle & article() const
Articles (a, the in English, el, la,...
Definition: keduvocidentifier.cpp:106
KVTML_VERSION
#define KVTML_VERSION
Definition: kvtml2defs.h:21
KEduVocLeitnerBox
Leitner Boxes are an alternative grading system.
Definition: keduvocleitnerbox.h:31
KEduVocPersonalPronoun
The conjugation of a verb.
Definition: keduvocpersonalpronoun.h:25
KVTML_GRAMMATICAL_PERSON
static const QString KVTML_GRAMMATICAL_PERSON[]
Definition: kvtml2defs.h:72
KVTML_AUTHOR
#define KVTML_AUTHOR
Definition: kvtml2defs.h:28
KEduVocDocument::title
QString title() const
Definition: keduvocdocument.cpp:741
KEduVocTranslation::soundUrl
KUrl soundUrl()
Sets multiple choice.
Definition: keduvoctranslation.cpp:329
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::documentComment
QString documentComment() const
Definition: keduvocdocument.cpp:783
KEduVocDocument::identifier
KEduVocIdentifier & identifier(int index)
Returns the identifier of translation index.
Definition: keduvocdocument.cpp:654
KEduVocDocument::author
QString author() const
Definition: keduvocdocument.cpp:756
KEduVocWordType::entries
QList< KEduVocExpression * > entries(EnumEntriesRecursive recursive=NotRecursive)
get a list of all entries in the lesson
Definition: keduvocwordtype.cpp:46
KEduVocContainer::childContainerCount
int childContainerCount() const
Find a child container.
Definition: keduvoccontainer.cpp:122
KEduVocKvtml2Writer::KEduVocKvtml2Writer
KEduVocKvtml2Writer(QFile *file)
Definition: keduvockvtml2writer.cpp:31
KEduVocTranslation::article
KEduVocText article() const
Definition: keduvoctranslation.cpp:464
KVTML_CATEGORY
#define KVTML_CATEGORY
Definition: kvtml2defs.h:32
KVTML_SPECIALWORDTYPE_ADVERB
#define KVTML_SPECIALWORDTYPE_ADVERB
Definition: kvtml2defs.h:113
KEduVocDocument::authorContact
QString authorContact() const
Definition: keduvocdocument.cpp:767
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
KVTML_IDENTIFIER
#define KVTML_IDENTIFIER
Definition: kvtml2defs.h:35
KEduVocDocument::category
QString category() const
Definition: keduvocdocument.cpp:794
KVTML_MULTIPLECHOICE
#define KVTML_MULTIPLECHOICE
Definition: kvtml2defs.h:146
KVTML_SPECIALWORDTYPE
#define KVTML_SPECIALWORDTYPE
Definition: kvtml2defs.h:106
KEduVocIdentifier::locale
QString locale() const
The locale of the contents: en, de, es, ...
Definition: keduvocidentifier.cpp:91
KVTML_TRUE
#define KVTML_TRUE
Definition: kvtml2defs.h:159
KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL
#define KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL
Definition: kvtml2defs.h:110
keduvockvtml2writer.h
KEduVocTranslation::falseFriends
QList< KEduVocTranslation * > falseFriends() const
Returns false friends of this expression.
Definition: keduvoctranslation.cpp:224
KEduVocWordFlag::Conjunction
Definition: keduvocwordflags.h:44
KEduVocKvtml2Writer::appendTextElement
static void appendTextElement(QDomElement &parent, const QString &elementName, const QString &text)
Helper function, appends a new element AND a text child to parent Only appends if text is NOT empty...
Definition: keduvockvtml2writer.cpp:654
KVTML_THIRD_PERSON_NEUTRAL_EXISTS
#define KVTML_THIRD_PERSON_NEUTRAL_EXISTS
Definition: kvtml2defs.h:90
KEduVocWordFlag::Plural
Definition: keduvocwordflags.h:35
KEduVocPersonalPronoun::dualExists
bool dualExists() const
Definition: keduvocpersonalpronoun.cpp:116
KEduVocPersonalPronoun::personalPronoun
QString personalPronoun(KEduVocWordFlags flags) const
Definition: keduvocpersonalpronoun.cpp:78
KEduVocTranslation::imageUrl
KUrl imageUrl()
Get the image url for this translation if it exists.
Definition: keduvoctranslation.cpp:342
KEduVocLesson::entries
QList< KEduVocExpression * > entries(EnumEntriesRecursive recursive=NotRecursive)
get a list of all entries in the lesson
Definition: keduvoclesson.cpp:51
KEduVocTranslation
Definition: keduvoctranslation.h:35
KEduVocWordFlag::Noun
Definition: keduvocwordflags.h:39
KVTML_TRANSLATION
#define KVTML_TRANSLATION
Definition: kvtml2defs.h:129
KEduVocContainer::Recursive
Definition: keduvoccontainer.h:44
KEduVocTranslation::synonyms
QList< KEduVocTranslation * > synonyms() const
Returns synonyms of this expression.
Definition: keduvoctranslation.cpp:240
KEduVocLeitnerBox::entries
QList< KEduVocExpression * > entries(EnumEntriesRecursive recursive=NotRecursive)
get a list of all entries in the box
Definition: keduvocleitnerbox.cpp:44
KEduVocWordFlag::Indefinite
Definition: keduvocwordflags.h:62
KVTML_LICENSE
#define KVTML_LICENSE
Definition: kvtml2defs.h:30
KEduVocContainer::name
QString name()
get the container name
Definition: keduvoccontainer.cpp:156
KVTML_ENTRIES
#define KVTML_ENTRIES
Definition: kvtml2defs.h:125
KEduVocTranslation::antonyms
QList< KEduVocTranslation * > antonyms() const
Returns antonyms of this expression.
Definition: keduvoctranslation.cpp:250
KEduVocPersonalPronoun::neutralExists
bool neutralExists() const
Definition: keduvocpersonalpronoun.cpp:106
KEduVocExpression
This class contains one vocabulary expression as an original with one or more translations.
Definition: keduvocexpression.h:37
KEduVocTranslation::superlativeForm
KEduVocText superlativeForm() const
Definition: keduvoctranslation.cpp:447
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
KEduVocIdentifier::personalPronouns
KEduVocPersonalPronoun & personalPronouns() const
Get the personal pronouns for this identifier.
Definition: keduvocidentifier.cpp:111
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
KEduVocKvtml2Writer::writeDoc
bool writeDoc(KEduVocDocument *doc, const QString &generator)
Definition: keduvockvtml2writer.cpp:37
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
KEduVocWordFlag::Adverb
Definition: keduvocwordflags.h:42
KEduVocIdentifier::tenseList
QStringList tenseList() const
Definition: keduvocidentifier.cpp:137
kvtml2defs.h
KEduVocKvtml2Writer::toByteArray
QByteArray toByteArray(KEduVocDocument *doc, const QString &generator)
Definition: keduvockvtml2writer.cpp:47
KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT
#define KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT
Definition: kvtml2defs.h:88
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
KEduVocExpression::translationIndices
QList< int > translationIndices() const
Definition: keduvocexpression.cpp:199
KVTML_CHOICE
#define KVTML_CHOICE
Definition: kvtml2defs.h:147
keduvocleitnerbox.h
KEduVocText::practiceCount
count_t practiceCount() const
returns how often this entry has been practiced as int
Definition: keduvoctext.cpp:107
KEduVocTranslation::toKVTML2
void toKVTML2(QDomElement &parent)
Definition: keduvoctranslation.cpp:493
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
KEduVocTranslation::leitnerBox
KEduVocLeitnerBox * leitnerBox() const
Returns the leitner box of this translation.
Definition: keduvoctranslation.cpp:375
KVTML_GENERATOR
#define KVTML_GENERATOR
Definition: kvtml2defs.h:26
KVTML_INFORMATION
#define KVTML_INFORMATION
Definition: kvtml2defs.h:24
KEduVocPersonalPronoun::maleFemaleDifferent
bool maleFemaleDifferent() const
Definition: keduvocpersonalpronoun.cpp:96
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
KEduVocArticle::article
QString article(const KEduVocWordFlags &)
Definition: keduvocarticle.cpp:63
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
KEduVocTranslation::comparativeForm
KEduVocText comparativeForm() const
Definition: keduvoctranslation.cpp:430
KEduVocText::toKVTML2
void toKVTML2(QDomElement &parent)
Definition: keduvoctext.cpp:175
KVTML_TENSE
#define KVTML_TENSE
Definition: kvtml2defs.h:118
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