• 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
keduvocdocument.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Vocabulary Document for KDE Edu
3  -----------------------------------------------------------------------
4  copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
5 
6  (C) 2005-2007 Peter Hedlund <peter.hedlund@kdemail.net>
7  (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "keduvocdocument.h"
20 
21 #include <QtCore/QFileInfo>
22 #include <QtCore/QTextStream>
23 #include <QtCore/QtAlgorithms>
24 #include <QtCore/QIODevice>
25 
26 #include <klocale.h>
27 #include <kdebug.h>
28 #include <kio/netaccess.h>
29 #include <krandomsequence.h>
30 #include <kfilterdev.h>
31 
32 #include "keduvocexpression.h"
33 #include "keduvoclesson.h"
34 #include "keduvocleitnerbox.h"
35 #include "keduvocwordtype.h"
36 #include "keduvockvtmlwriter.h"
37 #include "keduvockvtml2writer.h"
38 #include "keduvoccsvreader.h"
39 #include "keduvoccsvwriter.h"
40 #include "keduvockvtml2reader.h"
41 #include "keduvocwqlreader.h"
42 #include "keduvocpaukerreader.h"
43 #include "keduvocvokabelnreader.h"
44 #include "keduvocxdxfreader.h"
45 
46 #define WQL_IDENT "WordQuiz"
47 
48 #define KVTML_EXT "kvtml"
49 #define CSV_EXT "csv"
50 #define TXT_EXT "txt"
51 #define WQL_EXT "wql"
52 
53 class KEduVocDocument::KEduVocDocumentPrivate
54 {
55 public:
56  KEduVocDocumentPrivate( KEduVocDocument* qq )
57  : q( qq )
58  {
59  m_lessonContainer = 0;
60  m_wordTypeContainer = 0;
61  m_leitnerContainer = 0;
62  init();
63  }
64 
65  ~KEduVocDocumentPrivate();
66 
67  void init();
68 
69  KEduVocDocument* q;
70 
71  bool m_dirty;
72  KUrl m_url;
73 
74  // save these to document
75  QList<KEduVocIdentifier> m_identifiers;
76 
77  QList<int> m_extraSizeHints;
78  QList<int> m_sizeHints;
79 
80  QString m_generator;
81  QString m_queryorg;
82  QString m_querytrans;
83 
84  QStringList m_tenseDescriptions;
85  QSet<QString> m_usages;
86 
87  QString m_title;
88  QString m_author;
89  QString m_authorContact;
90  QString m_license;
91  QString m_comment;
92  QString m_version;
93  QString m_csvDelimiter;
94 
98  QString m_category;
99 
100  KEduVocLesson * m_lessonContainer;
101  KEduVocWordType * m_wordTypeContainer;
102  KEduVocLeitnerBox * m_leitnerContainer;
103 };
104 
105 KEduVocDocument::KEduVocDocumentPrivate::~KEduVocDocumentPrivate()
106 {
107  delete m_lessonContainer;
108  delete m_wordTypeContainer;
109  delete m_leitnerContainer;
110 }
111 
112 void KEduVocDocument::KEduVocDocumentPrivate::init()
113 {
114  delete m_lessonContainer;
115  m_lessonContainer = new KEduVocLesson(i18nc("The top level lesson which contains all other lessons of the document.", "Document Lesson"));
116  m_lessonContainer->setContainerType(KEduVocLesson::Lesson);
117  delete m_wordTypeContainer;
118  m_wordTypeContainer = new KEduVocWordType(i18n( "Word types" ));
119 
120  delete m_leitnerContainer;
121  m_leitnerContainer = new KEduVocLeitnerBox(i18n( "Leitner Box" ));
122 
123  m_tenseDescriptions.clear();
124  m_identifiers.clear();
125  m_extraSizeHints.clear();
126  m_sizeHints.clear();
127  m_dirty = false;
128  m_queryorg = "";
129  m_querytrans = "";
130  m_url.setFileName( i18n( "Untitled" ) );
131  m_author = "";
132  m_title = "";
133  m_comment = "";
134  m_version = "";
135  m_generator = "";
136  m_csvDelimiter = QString( '\t' );
137  m_usages.clear();
138  m_license.clear();
139  m_category.clear();
140 }
141 
142 
143 KEduVocDocument::KEduVocDocument( QObject *parent )
144  : QObject( parent ), d( new KEduVocDocumentPrivate( this ) )
145 {
146  kDebug() << "constructor done";
147 }
148 
149 
150 KEduVocDocument::~KEduVocDocument()
151 {
152  delete d;
153 }
154 
155 
156 void KEduVocDocument::setModified( bool dirty )
157 {
158  d->m_dirty = dirty;
159  emit docModified( d->m_dirty );
160 }
161 
162 
163 KEduVocDocument::FileType KEduVocDocument::detectFileType( const QString &fileName )
164 {
165  QIODevice * f = KFilterDev::deviceForFile( fileName );
166  if ( !f->open( QIODevice::ReadOnly ) ) {
167  kDebug(1100) << "Warning, could not open QIODevice for file: " << fileName;
168  delete f;
169  return Csv;
170  }
171 
172  QTextStream ts( f );
173  QString line1;
174  QString line2;
175 
176  line1 = ts.readLine();
177  if ( !ts.atEnd() ) {
178  line2 = ts.readLine();
179  }
180 
181  /*
182  * Vokabeln.de files:
183  The header seems to be something like this:
184 
185  "Name
186  Lang1 - Lang2",123,234,456
187  0
188 
189  or something longer:
190 
191  "Name
192  Lang1 - Lang2
193  [..]
194  Blah, blah, blah...",123,234,456
195  0
196  */
197 
198  QString tmp;
199 
200  if ( line1.startsWith(QChar::fromLatin1('"'))) {
201  ts.seek(0);
202  tmp = ts.readLine();
203  // There shouldn't be headers longer than 10 lines.
204  for ( int x=0; x < 10; x++) {
205  if (tmp.contains( "\"," )) {
206  tmp = ts.readLine();
207  if (tmp.endsWith('0')) {
208  f->close();
209  delete f;
210  return Vokabeln;
211  }
212  }
213  tmp = ts.readLine();
214  }
215  }
216  f->close();
217  delete f;
218 
219 
220  if ( line1.startsWith(QString::fromLatin1("<?xml")) ) {
221  if ( line2.indexOf( "pauker", 0 ) > 0 ) {
222  return Pauker;
223  }
224  if ( line2.indexOf( "xdxf", 0 ) > 0 ) {
225  return Xdxf;
226  } else {
227  return Kvtml;
228  }
229  }
230 
231  if ( line1 == WQL_IDENT ) {
232  return Wql;
233  }
234 
235  return Csv;
236 }
237 
238 
239 int KEduVocDocument::open( const KUrl& url )
240 {
241  // save csv delimiter to preserve it in case this is a csv document
242  QString csv = d->m_csvDelimiter;
243  // clear all other properties
244  d->init();
245  if ( !url.isEmpty() ) {
246  d->m_url = url;
247  }
248  d->m_csvDelimiter = csv;
249 
250  bool read = false;
251  QString errorMessage = i18n( "<qt>Cannot open file<br /><b>%1</b></qt>", url.path() );
252  QString temporaryFile;
253  if ( KIO::NetAccess::download( url, temporaryFile, 0 ) ) {
254  QIODevice * f = KFilterDev::deviceForFile( temporaryFile );
255 
256  if ( !f->open( QIODevice::ReadOnly ) ) {
257  kError() << errorMessage;
258  delete f;
259  return FileCannotRead;
260  }
261 
262  FileType ft = detectFileType( temporaryFile );
263 
264  switch ( ft ) {
265  case Kvtml: {
266  kDebug(1100) << "Reading KVTML document...";
267  KEduVocKvtml2Reader kvtmlReader( f );
268  read = kvtmlReader.readDoc( this );
269  if ( !read ) {
270  errorMessage = kvtmlReader.errorMessage();
271  }
272  }
273  break;
274 
275  case Wql: {
276  kDebug(1100) << "Reading WordQuiz (WQL) document...";
277  KEduVocWqlReader wqlReader( f );
278  d->m_url.setFileName( i18n( "Untitled" ) );
279  read = wqlReader.readDoc( this );
280  if ( !read ) {
281  errorMessage = wqlReader.errorMessage();
282  }
283  }
284  break;
285 
286  case Pauker: {
287  kDebug(1100) << "Reading Pauker document...";
288  KEduVocPaukerReader paukerReader( this );
289  d->m_url.setFileName( i18n( "Untitled" ) );
290  read = paukerReader.read( f );
291  if ( !read ) {
292  errorMessage = i18n( "Parse error at line %1, column %2:\n%3", paukerReader.lineNumber(), paukerReader.columnNumber(), paukerReader.errorString() );
293  }
294  }
295  break;
296 
297  case Vokabeln: {
298  kDebug(1100) << "Reading Vokabeln document...";
299  KEduVocVokabelnReader vokabelnReader( f );
300  d->m_url.setFileName( i18n( "Untitled" ) );
301  read = vokabelnReader.readDoc( this );
302  if ( !read ) {
303  errorMessage = vokabelnReader.errorMessage();
304  }
305  }
306  break;
307 
308  case Csv: {
309  kDebug(1100) << "Reading CVS document...";
310  KEduVocCsvReader csvReader( f );
311  read = csvReader.readDoc( this );
312  if ( !read ) {
313  errorMessage = csvReader.errorMessage();
314  }
315  }
316  break;
317 
318  case Xdxf: {
319  kDebug(1100) << "Reading XDXF document...";
320  KEduVocXdxfReader xdxfReader( this );
321  d->m_url.setFileName( i18n( "Untitled" ) );
322  read = xdxfReader.read( f );
323  if ( !read ) {
324  errorMessage = i18n( "Parse error at line %1, column %2:\n%3", xdxfReader.lineNumber(), xdxfReader.columnNumber(), xdxfReader.errorString() );
325  }
326  }
327  break;
328 
329  default: {
330  kDebug(1100) << "Reading KVTML document (fallback)...";
331  KEduVocKvtml2Reader kvtmlReader( f );
332  read = kvtmlReader.readDoc( this );
333  if ( !read ) {
334  errorMessage = kvtmlReader.errorMessage();
335  }
336  }
337  }
338 
339  if ( !read ) {
340  QString msg = i18n( "Could not open or properly read \"%1\"\n(Error reported: %2)", url.path(), errorMessage );
341  kError() << msg << i18n( "Error Opening File" );
343  delete f;
344  return FileReaderFailed;
345  }
346 
347  f->close();
348  delete f;
349  KIO::NetAccess::removeTempFile( temporaryFile );
350  }
351 
352  if ( !read ) {
353  return FileReaderFailed;
354  }
355 
356  setModified(false);
357  return 0;
358 }
359 
360 
361 int KEduVocDocument::saveAs( const KUrl & url, FileType ft, const QString & generator )
362 {
363  KUrl tmp( url );
364 
365  if ( ft == Automatic ) {
366  if ( tmp.path().right( strlen( "." KVTML_EXT ) ) == "." KVTML_EXT )
367  ft = Kvtml;
368  else if ( tmp.path().right( strlen( "." CSV_EXT ) ) == "." CSV_EXT )
369  ft = Csv;
370  else {
371  return FileTypeUnknown;
372  }
373  }
374 
375  QFile f( tmp.path() );
376 
377  if ( !f.open( QIODevice::WriteOnly ) ) {
378  kError() << i18n( "Cannot write to file %1", tmp.path() );
379  return FileCannotWrite;
380  }
381 
382  KUrl oldUrl = d->m_url;
383  bool saved = false;
384  d->m_url = tmp;
385 
386  switch ( ft ) {
387  case Kvtml: {
388  // write version 2 file
389  KEduVocKvtml2Writer kvtmlWriter( &f );
390  saved = kvtmlWriter.writeDoc( this, generator );
391  }
392  break;
394 // case Kvtml1: {
395 // // write old version 1 file
396 // KEduVocKvtmlWriter kvtmlWriter( &f );
397 // saved = kvtmlWriter.writeDoc( this, generator );
398 // }
399 // break;
400  case Csv: {
401  KEduVocCsvWriter csvWriter( &f );
402  saved = csvWriter.writeDoc( this, generator );
403  }
404  break;
405  default: {
406  kError() << "kvcotrainDoc::saveAs(): unknown filetype" << endl;
407  }
408  break;
409  } // switch
410 
411  f.close();
412 
413  if ( !saved ) {
414  kError() << "Error Saving File" << tmp.path();
415  d->m_url = oldUrl;
416  return FileWriterFailed;
417  }
418 
419  setModified( false );
420  return 0;
421 }
422 
423 QByteArray KEduVocDocument::toByteArray(const QString &generator)
424 {
425  // no file needed
426  KEduVocKvtml2Writer kvtmlWriter(0);
427  return kvtmlWriter.toByteArray( this, generator );
428 }
429 
430 void KEduVocDocument::merge( KEduVocDocument *docToMerge, bool matchIdentifiers )
431 {
432  Q_UNUSED(docToMerge)
433  Q_UNUSED(matchIdentifiers)
434  kDebug(1100) << "Merging of docs is not implemented";
435  // This code was really horribly broken.
436  // Now with the new classes we could attempt to reactivate it.
437  // A rewrite might be easier.
438 
439  /*
440  if (docToMerge) {
441 
442  QStringList new_names = docToMerge->lessonDescriptions();
443 
444  QStringList new_types = docToMerge->typeDescriptions();
445 
446  QStringList new_tenses = docToMerge->tenseDescriptions();
447 
448  QList<int> old_in_query = lessonsInPractice();
449  QList<int> new_in_query = docToMerge->lessonsInPractice();
450 
451  QStringList new_usages = docToMerge->usageDescriptions();
452 
453  int lesson_offset = d->m_lessonDescriptions.count();
454  for (int i = 0; i < new_names.count(); i++) {
455  d->m_lessonDescriptions.append(new_names[i]);
456  }
457 
458  for (int i = 0; i < new_in_query.count(); i++)
459  old_in_query.append(new_in_query[i] + lesson_offset);
460  setLessonsInPractice(old_in_query);
461 
462  int types_offset = d->m_typeDescriptions.count();
463  for (int i = 0; i < new_types.count(); i++) {
464  d->m_typeDescriptions.append(new_types[i]);
465  }
466 
467  int tenses_offset = d->m_tenseDescriptions.count();
468  for (int i = 0; i < new_tenses.count(); i++) {
469  d->m_tenseDescriptions.append(new_tenses[i]);
470  }
471 
472  int usages_offset = d->m_usageDescriptions.count();
473  for (int i = 0; i < new_usages.count(); i++) {
474  d->m_usageDescriptions.append(new_usages[i]);
475  }
476 
477  bool equal = true;
478  if (originalIdentifier() != docToMerge->originalIdentifier())
479  equal = false;
480  for (int i = 1; i < identifierCount(); i++)
481  if (identifier(i) != docToMerge->identifier(i))
482  equal = false;
483 
484  if (!matchIdentifiers)
485  equal = true; ///@todo massive cheating, problem if docToMerge has more identifiers than this
486 
487  if (equal) { // easy way: same language codes, just append
488 
489  for (int i = 0; i < docToMerge->entryCount(); i++) {
490  KEduVocExpression *expr = docToMerge->entry(i);
491 
492  expr->setLesson(expr->lesson() + lesson_offset);
493 
494  for (int lang = 0; lang <= expr->translationCount(); lang++) {
495  QString t = expr->translation(lang).type();
496  // adjust type offset
497  if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) {
498  QString t2;
499  t.remove(0, 1);
500  t2.setNum(t.toInt() + types_offset);
501  t2.prepend(QM_USER_TYPE);
502  expr->translation(lang).setType (t2);
503  }
504 
505  t = expr->translation(lang).usageLabel();
506  // adjust usage offset
507  QString tg;
508  if (!t.isEmpty()) {
509  QString t2;
510  while (t.left(strlen(":")) == UL_USER_USAGE) {
511  QString n;
512  t.remove(0, 1);
513  int next;
514  if ((next = t.indexOf(":")) >= 0) {
515  n = t.left(next);
516  t.remove(0, next + 1);
517  }
518  else {
519  n = t;
520  t = "";
521  }
522 
523  t2.setNum(n.toInt() + usages_offset);
524  t2.prepend(UL_USER_USAGE);
525  if (tg.length() == 0)
526  tg = t2;
527  else
528  tg += ':' + t2;
529  }
530 
531  if (tg.length() == 0)
532  tg = t;
533  else if (t.length() != 0)
534  tg += ':' + t;
535 
536  expr->translation(lang).setUsageLabel (tg);
537  }
538 
539  KEduVocConjugation conj = expr->translation(lang).conjugation();
540  bool condirty = false;
541  for (int ci = 0; ci < conj.entryCount(); ci++) {
542  t = conj.getType(ci);
543  if (!t.isEmpty() && t.left(1) == UL_USER_TENSE) {
544  t.remove(0, strlen(UL_USER_TENSE));
545  QString t2;
546  t2.setNum(t.toInt() + tenses_offset);
547  t2.prepend(UL_USER_TENSE);
548  conj.setType(ci, t2);
549  condirty = true;
550  }
551  if (condirty)
552  expr->translation(lang).setConjugation(conj);
553  }
554  }
555 
556  appendEntry(expr);
557  }
558  setModified();
559  }
560  else { // hard way: move entries around, most attributes get lost
561  QList<int> move_matrix;
562  QList<bool> cs_equal;
563  QString s;
564 
565  for (int i = 0; i < qMax (identifierCount(), docToMerge->identifierCount()); i++)
566  cs_equal.append(false);
567 
568  move_matrix.append(docToMerge->indexOfIdentifier(originalIdentifier()));
569  for (int i = 1; i < identifierCount(); i++)
570  move_matrix.append(docToMerge->indexOfIdentifier(identifier(i)));
571 
572  for (int j = 0; j < docToMerge->entryCount(); j++) {
573  KEduVocExpression new_expr;
574  KEduVocExpression *expr = docToMerge->entry(j);
575  new_expr.setLesson(expr->lesson()+lesson_offset);
576 
577  for (int i = 0; i < move_matrix.count(); i++) {
578  int lpos = move_matrix[i];
579  if (lpos >= 0) {
580 
581  if (lpos == 0)
582  s = expr->original();
583  else
584  s = expr->translation(lpos);
585 
586  if (!cs_equal[lpos]) {
587  cs_equal[lpos] = true;
588  QString id = lpos == 0 ? originalIdentifier() : identifier(lpos);
589  }
590 
591  if (i == 0)
592  new_expr.setOriginal(s);
593  else
594  new_expr.setTranslation(i, s);
595  QString r = expr->remark(lpos);
596  new_expr.setRemark (i, r);
597 
598  QString t = expr->type(lpos);
599  if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) {
600  QString t2;
601  t.remove(0, 1);
602  t2.setNum(t.toInt() + types_offset);
603  t2.prepend(QM_USER_TYPE);
604  new_expr.setType(i, t2);
605  }
606 
607  t = expr->usageLabel(lpos);
608  if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) {
609  QString t2;
610  t.remove(0, 1);
611  t2.setNum(t.toInt() + usages_offset);
612  t2.prepend(QM_USER_TYPE);
613  new_expr.setUsageLabel(i, t2);
614  }
615 
616  KEduVocConjugation conj = expr->conjugation(lpos);
617  for (int ci = 0; ci < conj.entryCount(); ci++) {
618  t = conj.getType(ci);
619  if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) {
620  t.remove (0, strlen(QM_USER_TYPE));
621  QString t2;
622  t2.setNum(t.toInt() + tenses_offset);
623  t2.prepend(QM_USER_TYPE);
624  conj.setType(ci, t2);
625  }
626  }
627 
628  }
629  }
630  // only append if entries are used
631  bool used = !new_expr.original().isEmpty();
632  for (int i = 1; i < identifierCount(); i++)
633  if (!new_expr.translation(i).isEmpty())
634  used = true;
635 
636  if (used) {
637  appendEntry(&new_expr);
638  setModified();
639  }
640  }
641  }
642  }
643  */
644 }
645 
646 const KEduVocIdentifier& KEduVocDocument::identifier( int index ) const
647 {
648  if ( index < 0 || index >= d->m_identifiers.size() ) {
649  kError() << " Error: Invalid identifier index: " << index;
650  }
651  return d->m_identifiers[index];
652 }
653 
654 KEduVocIdentifier& KEduVocDocument::identifier( int index )
655 {
656  if ( index < 0 || index >= d->m_identifiers.size() ) {
657  kError() << " Error: Invalid identifier index: " << index;
658  }
659  return d->m_identifiers[index];
660 }
661 
662 void KEduVocDocument::setIdentifier( int idx, const KEduVocIdentifier &id )
663 {
664  if ( idx >= 0 && idx < d->m_identifiers.size() ) {
665  d->m_identifiers[idx] = id;
666  }
667  setModified(true);
668 }
669 
670 // works if const is removed
671 int KEduVocDocument::indexOfIdentifier( const QString &name ) const
672 {
673  for (int i = 0; i < identifierCount(); i++)
674  if (identifier(i).locale() == name)
675  return i;
676  return -1;
677 }
678 
679 void KEduVocDocument::removeIdentifier( int index )
680 {
681  if ( index < d->m_identifiers.size() && index >= 0 ) {
682  d->m_identifiers.removeAt( index );
683  d->m_lessonContainer->removeTranslation( index );
684  }
685 }
686 
687 
688 bool KEduVocDocument::isModified() const
689 {
690  return d->m_dirty;
691 }
692 
693 
694 int KEduVocDocument::identifierCount() const
695 {
696  return d->m_identifiers.count(); // number of translations
697 }
698 
699 int KEduVocDocument::appendIdentifier( const KEduVocIdentifier& id )
700 {
701  int i = d->m_identifiers.size();
702 //kDebug(1100) << "appendIdentifier: " << i << id.name() << id.locale();
703  d->m_identifiers.append( id );
704  if ( id.name().isEmpty() ) {
705  if ( i == 0 ) {
706  identifier(i).setName(i18nc("The name of the first language/column of vocabulary, if we have to guess it.", "Original"));
707  } else {
708  identifier(i).setName(i18nc( "The name of the second, third ... language/column of vocabulary, if we have to guess it.", "Translation %1", i ) );
709  }
710  }
711 
712 
713  return i;
714 }
715 
716 KEduVocLesson * KEduVocDocument::lesson()
717 {
718  return d->m_lessonContainer;
719 }
720 
721 KEduVocWordType * KEduVocDocument::wordTypeContainer()
722 {
723  return d->m_wordTypeContainer;
724 }
725 
726 KEduVocLeitnerBox * KEduVocDocument::leitnerContainer()
727 {
728  return d->m_leitnerContainer;
729 }
730 
731 KUrl KEduVocDocument::url() const
732 {
733  return d->m_url;
734 }
735 
736 void KEduVocDocument::setUrl( const KUrl& url )
737 {
738  d->m_url = url;
739 }
740 
741 QString KEduVocDocument::title() const
742 {
743  if ( d->m_title.isEmpty() )
744  return d->m_url.fileName();
745  else
746  return d->m_title;
747 }
748 
749 void KEduVocDocument::setTitle( const QString & title )
750 {
751  d->m_title = title;
752  d->m_lessonContainer->setName(title);
753  setModified(true);
754 }
755 
756 QString KEduVocDocument::author() const
757 {
758  return d->m_author;
759 }
760 
761 void KEduVocDocument::setAuthor( const QString & s )
762 {
763  d->m_author = s.simplified();
764  setModified(true);
765 }
766 
767 QString KEduVocDocument::authorContact() const
768 {
769  return d->m_authorContact;
770 }
771 
772 void KEduVocDocument::setAuthorContact( const QString & s )
773 {
774  d->m_authorContact = s.simplified();
775  setModified(true);
776 }
777 
778 QString KEduVocDocument::license() const
779 {
780  return d->m_license;
781 }
782 
783 QString KEduVocDocument::documentComment() const
784 {
785  return d->m_comment;
786 }
787 
788 void KEduVocDocument::setCategory( const QString & category )
789 {
790  d->m_category = category;
791  setModified(true);
792 }
793 
794 QString KEduVocDocument::category() const
795 {
796  return d->m_category;
798 }
799 
800 void KEduVocDocument::queryIdentifier( QString &org, QString &trans ) const
801 {
802  org = d->m_queryorg;
803  trans = d->m_querytrans;
804 }
805 
806 void KEduVocDocument::setQueryIdentifier( const QString &org, const QString &trans )
807 {
808  d->m_queryorg = org;
809  d->m_querytrans = trans;
810  setModified(true);
811 }
812 
813 void KEduVocDocument::setLicense( const QString & s )
814 {
815  d->m_license = s.simplified();
816  setModified(true);
817 }
818 
819 void KEduVocDocument::setDocumentComment( const QString & s )
820 {
821  d->m_comment = s.trimmed();
822  setModified(true);
823 }
824 
825 void KEduVocDocument::setGenerator( const QString & generator )
826 {
827  d->m_generator = generator;
828  setModified(true);
829 }
830 
831 QString KEduVocDocument::generator() const
832 {
833  return d->m_generator;
834 }
835 
836 QString KEduVocDocument::version() const
837 {
838  return d->m_version;
839 }
840 
841 void KEduVocDocument::setVersion( const QString & vers )
842 {
843  d->m_version = vers;
844  setModified(true);
845 }
846 
847 QString KEduVocDocument::csvDelimiter() const
848 {
849  return d->m_csvDelimiter;
850 }
851 
852 void KEduVocDocument::setCsvDelimiter( const QString &delimiter )
853 {
854  d->m_csvDelimiter = delimiter;
855  setModified(true);
856 }
857 
858 
859 QString KEduVocDocument::pattern( FileDialogMode mode )
860 {
861  static const struct SupportedFilter {
862  bool reading;
863  bool writing;
864  const char* extensions;
865  const char* description;
866  }
867  filters[] = {
868  { true, true, "*.kvtml", I18N_NOOP( "KDE Vocabulary Document" ) },
869  { true, false, "*.wql", I18N_NOOP( "KWordQuiz Document" ) },
870  { true, false, "*.xml.qz *.pau.gz", I18N_NOOP( "Pauker Lesson" ) },
871  { true, false, "*.voc", I18N_NOOP( "Vokabeltrainer" ) },
872  { true, false, "*.xdxf", I18N_NOOP( "XML Dictionary Exchange Format" ) },
873  { true, true, "*.csv", I18N_NOOP( "Comma Separated Values (CSV)" ) },
874  // last is marker for the end, do not remove it
875  { false, false, 0, 0 }
876  };
877  QStringList newfilters;
878  QStringList allext;
879  for ( int i = 0; filters[i].extensions; ++i ) {
880  if (( mode == Reading && filters[i].reading ) ||
881  ( mode == Writing && filters[i].writing ) ) {
882  newfilters.append( QLatin1String( filters[i].extensions ) + '|' + i18n( filters[i].description ) );
883  allext.append( QLatin1String( filters[i].extensions ) );
884  }
885  }
886  if ( mode == Reading ) {
887  newfilters.prepend( allext.join( " " ) + '|' + i18n( "All supported documents" ) );
888  }
889  return newfilters.join( "\n" );
890 }
891 
892 QString KEduVocDocument::errorDescription( int errorCode )
893 {
894  switch (errorCode) {
895  case NoError:
896  return i18n("No error found.");
897 
898  case InvalidXml:
899  return i18n("Invalid XML in document.");
900  case FileTypeUnknown:
901  return i18n("Unknown file type.");
902  case FileCannotWrite:
903  return i18n("File is not writeable.");
904  case FileWriterFailed:
905  return i18n("File writer failed.");
906  case FileCannotRead:
907  return i18n("File is not readable.");
908  case FileReaderFailed:
909  return i18n("The file reader failed.");
910  case FileDoesNotExist:
911  return i18n("The file does not exist.");
912  case Unknown:
913  default:
914  return i18n("Unknown error.");
915  }
916 }
917 
918 #include "keduvocdocument.moc"
919 
KEduVocDocument::Pauker
Definition: keduvocdocument.h:55
KEduVocDocument::detectFileType
static FileType detectFileType(const QString &fileName)
Definition: keduvocdocument.cpp:163
KEduVocDocument::removeIdentifier
void removeIdentifier(int index)
Removes identifier and the according translation in all entries.
Definition: keduvocdocument.cpp:679
CSV_EXT
#define CSV_EXT
Definition: keduvocdocument.cpp:49
KEduVocDocument::FileDialogMode
FileDialogMode
used as parameter for pattern
Definition: keduvocdocument.h:76
KEduVocCsvReader
Definition: keduvoccsvreader.h:26
keduvocexpression.h
keduvocdocument.h
KEduVocDocument::license
QString license() const
Definition: keduvocdocument.cpp:778
keduvoccsvreader.h
KEduVocLesson
class to store information about a lesson
Definition: keduvoclesson.h:27
KEduVocContainer::Lesson
Definition: keduvoccontainer.h:37
keduvocvokabelnreader.h
KEduVocIdentifier
Class to store meta information about a language or any other category in the vocabulary.
Definition: keduvocidentifier.h:29
KEduVocDocument::Automatic
Definition: keduvocdocument.h:52
KEduVocCsvWriter::writeDoc
bool writeDoc(KEduVocDocument *doc, const QString &generator)
Definition: keduvoccsvwriter.cpp:36
KEduVocCsvReader::errorMessage
QString errorMessage() const
Definition: keduvoccsvreader.h:33
KEduVocDocument::saveAs
int saveAs(const KUrl &url, FileType ft, const QString &generator)
Saves the data under the given name.
Definition: keduvocdocument.cpp:361
keduvocwordtype.h
KEduVocDocument::FileTypeUnknown
Definition: keduvocdocument.h:67
KEduVocDocument::~KEduVocDocument
~KEduVocDocument()
Destructor.
Definition: keduvocdocument.cpp:150
KEduVocDocument::setAuthor
void setAuthor(const QString &author)
Set the author of the file.
Definition: keduvocdocument.cpp:761
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
KEduVocDocument::appendIdentifier
int appendIdentifier(const KEduVocIdentifier &identifier=KEduVocIdentifier())
Appends a new identifier (usually a language)
Definition: keduvocdocument.cpp:699
KEduVocVokabelnReader::readDoc
bool readDoc(KEduVocDocument *doc)
Definition: keduvocvokabelnreader.cpp:43
KEduVocXdxfReader::read
bool read(QIODevice *device)
Definition: keduvocxdxfreader.cpp:32
KEduVocDocument::Reading
Definition: keduvocdocument.h:78
keduvoclesson.h
KEduVocDocument::indexOfIdentifier
int indexOfIdentifier(const QString &name) const
Determines the index of a given identifier.
Definition: keduvocdocument.cpp:671
QObject
KEduVocDocument::leitnerContainer
KEduVocLeitnerBox * leitnerContainer()
Definition: keduvocdocument.cpp:726
KEduVocDocument::setCsvDelimiter
void setCsvDelimiter(const QString &delimiter)
Sets the delimiter (separator) used for csv import and export.
Definition: keduvocdocument.cpp:852
KEduVocDocument::Xdxf
Definition: keduvocdocument.h:57
keduvoccsvwriter.h
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
KEduVocDocument::FileType
FileType
known vocabulary file types
Definition: keduvocdocument.h:50
KEduVocCsvWriter
Definition: keduvoccsvwriter.h:25
KEduVocDocument::setAuthorContact
void setAuthorContact(const QString &authorContact)
Set the author contact info.
Definition: keduvocdocument.cpp:772
KEduVocDocument::open
int open(const KUrl &url)
Open a document file.
Definition: keduvocdocument.cpp:239
KEduVocWqlReader::readDoc
bool readDoc(KEduVocDocument *doc)
Definition: keduvocwqlreader.cpp:38
KEduVocDocument::title
QString title() const
Definition: keduvocdocument.cpp:741
KEduVocDocument::FileWriterFailed
Definition: keduvocdocument.h:69
KEduVocWordType
class to store translation word types
Definition: keduvocwordtype.h:33
KEduVocDocument::isModified
bool isModified() const
Definition: keduvocdocument.cpp:688
KEduVocDocument::errorDescription
static QString errorDescription(int errorCode)
Definition: keduvocdocument.cpp:892
KEduVocDocument::generator
QString generator() const
Definition: keduvocdocument.cpp:831
KEduVocDocument::documentComment
QString documentComment() const
Definition: keduvocdocument.cpp:783
KEduVocVokabelnReader::errorMessage
QString errorMessage() const
Definition: keduvocvokabelnreader.h:33
KEduVocDocument::setCategory
void setCategory(const QString &category)
Set the category of the file.
Definition: keduvocdocument.cpp:788
WQL_IDENT
#define WQL_IDENT
Definition: keduvocdocument.cpp:46
KEduVocKvtml2Writer
Class to write kvtml2 data files from KEduVocDocument.
Definition: keduvockvtml2writer.h:38
KEduVocPaukerReader
Definition: keduvocpaukerreader.h:25
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
KEduVocDocument::FileDoesNotExist
Definition: keduvocdocument.h:72
KEduVocKvtml2Reader::readDoc
bool readDoc(KEduVocDocument *doc)
read the document
Definition: keduvockvtml2reader.cpp:48
KEduVocIdentifier::setName
void setName(const QString &name)
Set the name.
Definition: keduvocidentifier.cpp:86
KEduVocDocument::setQueryIdentifier
KDE_DEPRECATED void setQueryIdentifier(const QString &org, const QString &trans)
Sets the identifiers for the current query not written in the new version!
Definition: keduvocdocument.cpp:806
KEduVocDocument::docModified
void docModified(bool mod)
Emitted when the document becomes modified or saved.
KEduVocDocument::InvalidXml
Definition: keduvocdocument.h:66
KEduVocDocument::setGenerator
void setGenerator(const QString &generator)
Sets the generator of the file.
Definition: keduvocdocument.cpp:825
KEduVocDocument::toByteArray
QByteArray toByteArray(const QString &generator)
Definition: keduvocdocument.cpp:423
KEduVocDocument::authorContact
QString authorContact() const
Definition: keduvocdocument.cpp:767
KEduVocDocument::KEduVocDocument
KEduVocDocument(QObject *parent=0)
Constructor for a KDEEdu vocabulary document.
Definition: keduvocdocument.cpp:143
KEduVocDocument::wordTypeContainer
KEduVocWordType * wordTypeContainer()
Definition: keduvocdocument.cpp:721
KEduVocDocument::category
QString category() const
Definition: keduvocdocument.cpp:794
KEduVocIdentifier::locale
QString locale() const
The locale of the contents: en, de, es, ...
Definition: keduvocidentifier.cpp:91
KEduVocDocument::queryIdentifier
KDE_DEPRECATED void queryIdentifier(QString &org, QString &trans) const
Retrieves the identifiers for the current query not written in the new version!
Definition: keduvocdocument.cpp:800
keduvockvtml2writer.h
KEduVocDocument::NoError
Definition: keduvocdocument.h:64
KEduVocDocument::Unknown
Definition: keduvocdocument.h:65
keduvockvtmlwriter.h
KEduVocDocument::FileCannotWrite
Definition: keduvocdocument.h:68
KEduVocDocument::Vokabeln
Definition: keduvocdocument.h:56
KEduVocDocument::FileCannotRead
Definition: keduvocdocument.h:70
KEduVocDocument::merge
void merge(KEduVocDocument *docToMerge, bool matchIdentifiers)
Merges data from another document.
Definition: keduvocdocument.cpp:430
KEduVocDocument::setIdentifier
void setIdentifier(int index, const KEduVocIdentifier &lang)
Sets the identifier of translation.
Definition: keduvocdocument.cpp:662
KEduVocDocument::identifierCount
int identifierCount() const
Definition: keduvocdocument.cpp:694
KEduVocDocument::FileReaderFailed
Definition: keduvocdocument.h:71
keduvocwqlreader.h
KEduVocDocument::pattern
static QString pattern(FileDialogMode mode)
Create a string with the supported document types, that can be used as filter in KFileDialog.
Definition: keduvocdocument.cpp:859
KEduVocKvtml2Writer::writeDoc
bool writeDoc(KEduVocDocument *doc, const QString &generator)
Definition: keduvockvtml2writer.cpp:37
KEduVocDocument::Kvtml
Definition: keduvocdocument.h:53
KEduVocDocument::setLicense
void setLicense(const QString &license)
Set the license of the file.
Definition: keduvocdocument.cpp:813
KEduVocXdxfReader
Definition: keduvocxdxfreader.h:25
KEduVocKvtml2Writer::toByteArray
QByteArray toByteArray(KEduVocDocument *doc, const QString &generator)
Definition: keduvockvtml2writer.cpp:47
KEduVocDocument::csvDelimiter
QString csvDelimiter() const
Returns the delimiter (separator) used for csv import and export.
Definition: keduvocdocument.cpp:847
KEduVocDocument::Wql
Definition: keduvocdocument.h:54
KEduVocPaukerReader::read
bool read(QIODevice *device)
Definition: keduvocpaukerreader.cpp:33
keduvocleitnerbox.h
KEduVocDocument::setTitle
void setTitle(const QString &title)
Set the title of the file.
Definition: keduvocdocument.cpp:749
KEduVocWqlReader
Definition: keduvocwqlreader.h:26
KEduVocWqlReader::errorMessage
QString errorMessage() const
Definition: keduvocwqlreader.h:33
KEduVocDocument::setModified
void setModified(bool dirty=true)
Indicates if the document is modified.
Definition: keduvocdocument.cpp:156
KEduVocDocument::lesson
KEduVocLesson * lesson()
Get the lesson root object.
Definition: keduvocdocument.cpp:716
KVTML_EXT
#define KVTML_EXT
Definition: keduvocdocument.cpp:48
KEduVocDocument
This class contains the expressions of your vocabulary as well as other information about the vocabul...
Definition: keduvocdocument.h:44
KEduVocDocument::version
QString version() const
Definition: keduvocdocument.cpp:836
KEduVocVokabelnReader
Definition: keduvocvokabelnreader.h:26
KEduVocKvtml2Reader
class to read kvtml2 data files into keduvocdocument
Definition: keduvockvtml2reader.h:36
keduvocpaukerreader.h
KEduVocCsvReader::readDoc
bool readDoc(KEduVocDocument *doc)
Definition: keduvoccsvreader.cpp:45
KEduVocDocument::Writing
Definition: keduvocdocument.h:79
keduvocxdxfreader.h
KEduVocKvtml2Reader::errorMessage
QString errorMessage() const
get the errormessage string
Definition: keduvockvtml2reader.h:53
KEduVocDocument::setUrl
void setUrl(const KUrl &url)
Sets the URL of the XML file.
Definition: keduvocdocument.cpp:736
keduvockvtml2reader.h
KEduVocDocument::Csv
Definition: keduvocdocument.h:58
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