~ubuntu-branches/ubuntu/oneiric/libkdeedu/oneiric-proposed

« back to all changes in this revision

Viewing changes to keduvocdocument/keduvocpaukerreader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 10:41:49 UTC
  • Revision ID: james.westby@ubuntu.com-20110708104149-89wcmexl435kzroa
Tags: upstream-4.6.90+repack1
Import upstream version 4.6.90+repack1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                     create a KEduVocDocument from a Pauker file
 
3
    -----------------------------------------------------------------------
 
4
    copyright     : (C) 2004, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
 
5
 
 
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 "keduvocpaukerreader.h"
 
18
 
 
19
#include <QIODevice>
 
20
 
 
21
#include <KLocale>
 
22
 
 
23
#include "keduvocexpression.h"
 
24
#include "keduvoclesson.h"
 
25
#include "keduvocdocument.h"
 
26
 
 
27
KEduVocPaukerReader::KEduVocPaukerReader( KEduVocDocument * doc )
 
28
{
 
29
    m_doc = doc;
 
30
}
 
31
 
 
32
 
 
33
bool KEduVocPaukerReader::read( QIODevice * device )
 
34
{
 
35
    setDevice( device );
 
36
 
 
37
    while ( !atEnd() ) {
 
38
        readNext();
 
39
 
 
40
        if ( isStartElement() ) {
 
41
            if ( name() == "Lesson" )
 
42
                readPauker();
 
43
            else
 
44
                raiseError( i18n( "This is not a Pauker document" ) );
 
45
        }
 
46
    }
 
47
 
 
48
    return !error();
 
49
}
 
50
 
 
51
 
 
52
void KEduVocPaukerReader::readUnknownElement()
 
53
{
 
54
    while ( !atEnd() ) {
 
55
        readNext();
 
56
 
 
57
        if ( isEndElement() )
 
58
            break;
 
59
 
 
60
        if ( isStartElement() )
 
61
            readUnknownElement();
 
62
    }
 
63
}
 
64
 
 
65
 
 
66
void KEduVocPaukerReader::readPauker()
 
67
{
 
68
    m_doc->setAuthor( "http://pauker.sf.net" );
 
69
    ///Pauker does not provide any column titles
 
70
    m_doc->appendIdentifier();
 
71
    m_doc->appendIdentifier();
 
72
 
 
73
    while ( !atEnd() ) {
 
74
        readNext();
 
75
 
 
76
        if ( isEndElement() )
 
77
            break;
 
78
 
 
79
        if ( isStartElement() ) {
 
80
            if ( name() == "Description" )
 
81
                m_doc->setDocumentComment( readElementText() );
 
82
            else if ( name() == "Batch" )
 
83
                readBatch();
 
84
            else
 
85
                readUnknownElement();
 
86
        }
 
87
    }
 
88
}
 
89
 
 
90
 
 
91
void KEduVocPaukerReader::readBatch()
 
92
{
 
93
    while ( !atEnd() ) {
 
94
        readNext();
 
95
 
 
96
        if ( isEndElement() )
 
97
            break;
 
98
 
 
99
        if ( isStartElement() ) {
 
100
            if ( name() == "Card" )
 
101
                readCard();
 
102
            else
 
103
                readUnknownElement();
 
104
        }
 
105
    }
 
106
}
 
107
 
 
108
 
 
109
void KEduVocPaukerReader::readCard()
 
110
{
 
111
    QString front;
 
112
    QString back;
 
113
 
 
114
    while ( !atEnd() ) {
 
115
        readNext();
 
116
 
 
117
        if ( isEndElement() )
 
118
            break;
 
119
 
 
120
        if ( isStartElement() ) {
 
121
            if ( name() == "FrontSide" )
 
122
                front = readText();
 
123
            else if ( name() == "ReverseSide" )
 
124
                back = readText();
 
125
            else
 
126
                readUnknownElement();
 
127
        }
 
128
    }
 
129
 
 
130
    KEduVocLesson* lesson = new KEduVocLesson(i18n("Vocabulary"), m_doc->lesson());
 
131
    m_doc->lesson()->appendChildContainer(lesson);
 
132
 
 
133
    KEduVocExpression* expr = new KEduVocExpression( QStringList() << front << back);
 
134
    lesson->appendEntry( expr );
 
135
}
 
136
 
 
137
 
 
138
QString KEduVocPaukerReader::readText()
 
139
{
 
140
    QString result;
 
141
 
 
142
    while ( !atEnd() ) {
 
143
        readNext();
 
144
 
 
145
        if ( isEndElement() )
 
146
            break;
 
147
 
 
148
        if ( isStartElement() ) {
 
149
            if ( name() == "Text" )
 
150
                result = readElementText();
 
151
            else
 
152
                readUnknownElement();
 
153
        }
 
154
    }
 
155
    return result;
 
156
}