summaryrefslogtreecommitdiffstats
path: root/kvoctrain/kvoctrain/kvt-core/kvd_voc.cpp
blob: e99c2e3177e1b5f5723deb9ceb2e85fdeab97d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************

                   maintain a document in Vokabletrainer format

    -----------------------------------------------------------------------

    begin          : Wed Jun 15 19:32:00 PDT 2005

    copyright      : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>

    -----------------------------------------------------------------------

 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <klocale.h>
#include <kapplication.h>
#include <kmessagebox.h>
#include <kdebug.h>

#include "kvoctraindoc.h"
#include "kvoctraincore.h"


bool kvoctrainDoc::loadFromVoc(QTextStream& is)
{
  author = "http://www.vokabeln.de"; //DO NOT translate

  langs.clear();
  vocabulary.clear();
  lesson_descr.clear();

  QString title,
          lang1,
          lang2,
          expression,
          original,
          translation,
          lessonDescr,
          temp;

  int     i,
          wordCount,
          lesson;

  int lines = 10000;

  QStringList titles,
              languages,
              words;

  bool keepGoing = true;

  while (keepGoing)
  {
    temp = is.readLine();
    keepGoing = !(temp.find("\",") > 0);
    title.append(temp);
    if (keepGoing)
      title.append(" ");
  }

  titles = QStringList::split("\",", title);
  doctitle = titles[0].mid(1);
  wordCount = titles[1].section(',', 0, 0).toInt();

  is.readLine();
  is.readLine();

  lang1 = is.readLine();
  languages = QStringList::split("\",", lang1);

  langs.push_back(languages[0].mid(1));
  langs.push_back(languages[1].mid(1));

  keepGoing = true;
  while (keepGoing)
    keepGoing = !(is.readLine().find("8. Lernhilfe") > 0); //DO NOT translate

  for (i = 0; i <= 14; i++)
    is.readLine();

  for (i = 0; i < wordCount - 1; i++)
  {
    int c = 0;
    expression.setLength(0);

    while (c < 2)
    {
      temp = is.readLine();
      c+= temp.contains("\",");
      expression.append(temp);
      if (c < 2)
        expression.append(" ");
    }

    words = QStringList::split("\",", expression);
    original = words[0].mid(1);
    translation = words[1].mid(1);
    lesson = words[2].toInt();

    kvoctrainExpr kve;
    kve.setOriginal(original);
    kve.setGrade(1, 0, false);
    kve.setGrade(1, 0, true);
    kve.setLesson(lesson);
    kve.addTranslation(translation);

    vocabulary.push_back(kve);

    is.readLine();
    is.readLine();
  }

  is.readLine();
  is.readLine();
  is.readLine();

  for (int i = 0; !is.eof() && i < lines; i++)
  {
    lessonDescr = is.readLine();
    lessonDescr = lessonDescr.mid(1, lessonDescr.length() - 2);
    if (!lessonDescr.isEmpty())
      lesson_descr.push_back(lessonDescr);
    else
      break;
    is.readLine();
  }

  setModified(false);
  doc_url.setFileName(i18n("Untitled"));
  return is.device()->status() == IO_Ok;
}