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

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
  • glossary
tbxparser_obsolete.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #include "tbxparser.h"
25 
26 #include "glossary.h"
27 #include "project.h"
28 #include <kdebug.h>
29 
30 using namespace GlossaryNS;
31 
32 bool TbxParser::startDocument()
33 {
34  m_state=null;
35  m_lang=langNull;
36  return true;
37 }
38 
39 
40 
41 bool TbxParser::startElement( const QString&, const QString&,
42  const QString& qName,
43  const QXmlAttributes& attr)
44 {
45  if (qName=="langSet")
46  {
47  if (attr.value("xml:lang").startsWith("en"))
48  m_lang=langEn;
49  else if (attr.value("xml:lang")==Project::instance()->langCode())
50  m_lang=langTarget;
51  else
52  m_lang=langNull;
53  }
54  else if (qName=="term")
55  {
56  m_state=term;
57  }
58  else if (qName=="termEntry")
59  {
60  m_termEn.clear();
61  m_termOther.clear();
62  m_entry.clear();
63  m_entry.id=attr.value("id");
64  }
65  else if (qName=="descrip")
66  {
67  if (attr.value("type")=="definition")
68  m_state=descripDefinition;
69  else if (attr.value("type")=="subjectField")
70  m_state=descripSubjectField;
71  }
72  return true;
73 }
74 
75 bool TbxParser::endElement(const QString&,const QString&,const QString& qName)
76 {
77  if (qName=="term")
78  {
79  if (m_lang==langEn)
80  {
81  m_entry.english << m_termEn;
82  m_termEn.clear();
83  m_entry.english.last().squeeze();
84  }
85  else if (m_lang==langTarget)
86  {
87  m_entry.target << m_termOther;
88  m_termOther.clear();
89  m_entry.target.last().squeeze();
90  }
91 
92  }
93  else if (qName=="descrip")
94  {
95  if (m_state==descripSubjectField && !m_subjectField.isEmpty())
96  {
97  m_entry.subjectField=Project::instance()->glossary()->subjectFields.indexOf(m_subjectField);
98  if (m_entry.subjectField==-1)//got this field value for the first time
99  {
100  m_entry.subjectField=Project::instance()->glossary()->subjectFields.size();
101  Project::instance()->glossary()->subjectFields << m_subjectField;
102  }
103  m_subjectField.clear();
104  }
105 
106  }
107  else if (qName=="termEntry")
108  {
109  //sanity check --maybe this entry is only for another language?
110  if (m_entry.target.isEmpty()||m_entry.english.isEmpty())
111  return true;
112 
113  int index=m_glossary->termList.count();
114  m_glossary->termList.append(m_entry);
115  m_glossary->hashTermEntry(index);
116 
117  m_entry.clear();
118  }
119  m_state=null;
120  return true;
121 }
122 
123 
124 
125 bool TbxParser::characters ( const QString & ch )
126 {
127  if(m_state==term)
128  {
129  if (m_lang==langEn)
130  m_termEn+=ch.toLower();//this is important
131  else if (m_lang==langTarget)
132  m_termOther+=ch;
133  }
134  else if (m_state==descripDefinition)
135  m_entry.definition+=ch;
136  else if (m_state==descripSubjectField)
137  m_subjectField+=ch;
138 
139 
140  return true;
141 }
142 
project.h
GlossaryNS::TermEntry::target
QStringList target
Definition: glossary.h:53
GlossaryNS::TermEntry::definition
QString definition
Definition: glossary.h:54
Project::instance
static Project * instance()
Definition: project.cpp:67
ProjectBase::langCode
QString langCode() const
Get LangCode.
Definition: projectbase.h:65
QList::size
int size() const
QString::clear
void clear()
GlossaryNS::TbxParser::startDocument
bool startDocument()
Definition: tbxparser_obsolete.cpp:32
GlossaryNS::Glossary::hashTermEntry
void hashTermEntry(const QDomElement &)
Definition: glossary.cpp:591
Project::glossary
GlossaryNS::Glossary * glossary() const
Definition: project.h:73
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
glossary.h
GlossaryNS::TermEntry::id
QString id
Definition: glossary.h:56
QString::toLower
QString toLower() const
GlossaryNS::TermEntry::english
QStringList english
Definition: glossary.h:52
GlossaryNS::TermEntry::subjectField
int subjectField
Definition: glossary.h:55
QXmlAttributes
QList::last
T & last()
GlossaryNS::TermEntry::clear
void clear()
Definition: glossary.h:76
GlossaryNS::Glossary::subjectFields
QStringList subjectFields() const
Definition: glossary.cpp:322
GlossaryNS::TbxParser::characters
bool characters(const QString &)
Definition: tbxparser_obsolete.cpp:125
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
GlossaryNS::TbxParser::startElement
bool startElement(const QString &, const QString &, const QString &, const QXmlAttributes &)
Definition: tbxparser_obsolete.cpp:41
GlossaryNS::Glossary::append
void append(const QString &_english, const QString &_target)
Definition: glossary.cpp:704
QXmlAttributes::value
QString value(int index) const
GlossaryNS::TbxParser::endElement
bool endElement(const QString &, const QString &, const QString &)
Definition: tbxparser_obsolete.cpp:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

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