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

okular

  • kde-4.x
  • kdegraphics
  • okular
  • generators
  • chm
  • lib
helperxmlhandler_epubtoc.cpp
Go to the documentation of this file.
1 /*
2  * Kchmviewer - a CHM and EPUB file viewer with broad language support
3  * Copyright (C) 2004-2014 George Yunaev, [email protected]
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <QtDebug>
20 #include "helperxmlhandler_epubtoc.h"
21 
22 HelperXmlHandler_EpubTOC::HelperXmlHandler_EpubTOC(EBook_EPUB *epub)
23 {
24  m_epub = epub;
25  m_inNavMap = false;
26  m_inText = false;
27  m_indent = 0;
28 }
29 
30 bool HelperXmlHandler_EpubTOC::startElement(const QString &, const QString &localName, const QString &, const QXmlAttributes &atts)
31 {
32 // qDebug() << "startElement " << " " << localName;
33 
34 // for ( int i = 0; i < atts.count(); i++ )
35 // qDebug() << " " << atts.localName(i) << " " << atts.value(i);
36 
37  if ( localName == "navMap" )
38  {
39  m_inNavMap = true;
40  return true;
41  }
42 
43  if ( !m_inNavMap )
44  return true;
45 
46  if ( localName == "navPoint" )
47  m_indent++;
48 
49  if ( localName == "text" )
50  m_inText = true;
51 
52  if ( localName == "content" )
53  {
54  int idx = atts.index( "src" );
55 
56  if ( idx == -1 )
57  return false;
58 
59  m_lastId = atts.value( idx );
60  checkNewTocEntry();
61  }
62 
63  return true;
64 }
65 
66 bool HelperXmlHandler_EpubTOC::characters(const QString &ch)
67 {
68  // qDebug() << "characters" << " " << ch;
69  if ( m_inText )
70  m_lastTitle = ch;
71 
72  checkNewTocEntry();
73  return true;
74 }
75 
76 bool HelperXmlHandler_EpubTOC::endElement(const QString& , const QString &localName, const QString &)
77 {
78 // qDebug() << "endElement" << " " << qName;
79 
80  if ( localName == "navMap" )
81  {
82  m_inNavMap = false;
83  return true;
84  }
85 
86  if ( localName == "navPoint" )
87  m_indent--;
88 
89  if ( localName == "text" )
90  m_inText = false;
91 
92  return true;
93 }
94 
95 void HelperXmlHandler_EpubTOC::checkNewTocEntry()
96 {
97  if ( !m_lastId.isEmpty() && !m_lastTitle.isEmpty() )
98  {
99  EBookTocEntry entry;
100  entry.name = m_lastTitle;
101  entry.url = m_epub->pathToUrl( m_lastId );
102  entry.iconid = EBookTocEntry::IMAGE_AUTO;
103  entry.indent = m_indent - 1;
104 
105  entries.push_back( entry );
106 
107  //qDebug() << "TOC entry: " << m_lastId << " :" << m_lastTitle << " :" << m_indent - 1;
108 
109  m_lastId.clear();
110  m_lastTitle.clear();
111  }
112 }
HelperXmlHandler_EpubTOC::entries
QList< EBookTocEntry > entries
Definition: helperxmlhandler_epubtoc.h:30
QList::push_back
void push_back(const T &value)
EBook_EPUB::pathToUrl
QUrl pathToUrl(const QString &link) const
Definition: ebook_epub.cpp:277
QXmlAttributes::index
int index(const QString &qName) const
helperxmlhandler_epubtoc.h
QString::clear
void clear()
EBookTocEntry::IMAGE_AUTO
Definition: ebook.h:34
HelperXmlHandler_EpubTOC::HelperXmlHandler_EpubTOC
HelperXmlHandler_EpubTOC(EBook_EPUB *epub)
Definition: helperxmlhandler_epubtoc.cpp:22
QString::isEmpty
bool isEmpty() const
EBookTocEntry::url
QUrl url
Entry URL.
Definition: ebook.h:43
QString
EBookTocEntry::iconid
Icon iconid
Associated image number.
Definition: ebook.h:47
QXmlAttributes
EBookTocEntry
Stores a single table of content entry.
Definition: ebook.h:27
QXmlAttributes::value
QString value(int index) const
EBookTocEntry::name
QString name
Entry name.
Definition: ebook.h:40
EBookTocEntry::indent
int indent
Indentation level for this entry.
Definition: ebook.h:50
EBook_EPUB
Definition: ebook_epub.h:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sat Dec 14 2019 01:25:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okular

Skip menu "okular"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkipiplugins
  •     src
  •     src
  •     src
  •     src
  •     src
  • okular

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