1
//---------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2012 LenMus project
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//---------------------------------------------------------------------------------------
21
#ifndef __LENMUS_BOOK_READER_H__
22
#define __LENMUS_BOOK_READER_H__
25
#include "lenmus_standard_header.h"
26
#include "lenmus_xml_parser.h"
30
#include <wx/object.h>
31
#include <wx/string.h>
32
#include <wx/filesys.h>
33
#include <wx/dynarray.h>
35
#include <wx/filename.h>
45
//forward declarations
49
//---------------------------------------------------------------------------------------
50
// BookRecord: a record per book, to contain the info from the lmb file
57
wxString m_sCoverPage;
58
int m_ContentsStart; //index to content table for the first entry of this book
59
int m_ContentsEnd; //index to content table for the last entry of this book
62
BookRecord(const wxString& bookfile, const wxString& basepath,
63
const wxString& title, const wxString& start);
66
inline wxString GetBookFile() const { return m_sBookFile; }
68
inline wxString GetTitle() const { return m_sTitle; }
69
inline void SetTitle(const wxString& title) { m_sTitle = title; }
71
inline wxString GetCoverPage() const { return m_sCoverPage; }
73
wxString GetBasePath() const { return m_sBasePath; }
74
inline void SetBasePath(const wxString& path) { m_sBasePath = path; }
75
wxString GetFullPath(const wxString &page) const;
77
// Contents related methods
78
inline void SetContentsRange(int start, int end) {
79
m_ContentsStart = start;
82
inline int GetContentsStart() const { return m_ContentsStart; }
83
inline int GetContentsEnd() const { return m_ContentsEnd; }
87
//---------------------------------------------------------------------------------------
88
// BookIndexItem: an entry of the index and contents tables
89
// The only difference between content entries and index entries is that the index
90
// entries don't have an image.
93
BookIndexItem() : level(0), parent(NULL), id(wxEmptyString),
94
titlenum(wxEmptyString), pBookRecord(NULL) {}
96
int level; // level of this entry. 0: book, 1-n: pages
97
BookIndexItem* parent; // parent entry if this is a sub-entry (level > 0)
98
wxString id; // page id (to search pages by id)
99
wxString titlenum; // prefix for title (number/letter)
100
wxString title; // text for this entry
101
wxString page; // html page to display
102
wxString image; // image to display
103
BookRecord* pBookRecord; // ptr to book record
105
// returns full filename of page, i.e. with book's basePath prepended
106
inline wxString GetFullPath() const { return pBookRecord->GetFullPath(page); }
108
// returns item indented with spaces if it has level > 1
109
wxString GetIndentedName() const;
112
//---------------------------------------------------------------------------------------
113
// lmPageIndexItem: an entry of the page index table
114
// The page index is a global table with all the html pages available. It is used to
115
// search for a page. This table is needed as all other tables only contains
116
// information about the pages that are in a book's TOC
117
struct lmPageIndexItem
119
lmPageIndexItem() : page(wxEmptyString), book(wxEmptyString) {}
121
wxString page; // html page to display
122
wxString book; // book path
124
// returns full filename of page, i.e. with book's basePath prepended
125
inline wxString GetFullPath() const { return book + _T("#zip:") + page; }
130
#include <wx/dynarray.h>
131
WX_DEFINE_ARRAY(BookRecord*, BookRecArray);
132
WX_DEFINE_ARRAY(BookIndexItem*, BookIndexArray);
133
WX_DEFINE_ARRAY(lmPageIndexItem*, lmPageIndexArray);
136
////---------------------------------------------------------------------------------------
137
//// BookSearchEngine
138
//// This class takes input streams and scans them for occurrence
140
//////---------------------------------------------------------------------------------------
142
//class BookSearchEngine
145
// BookSearchEngine() {}
146
// virtual ~BookSearchEngine() {}
148
// // Sets the keyword we will be searching for
149
// virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
151
// // Scans the stream for the keyword.
152
// // Returns true if the stream contains keyword, fALSE otherwise
153
// virtual bool Scan(const wxFSFile& file);
156
// wxString m_Keyword;
157
// bool m_CaseSensitive;
158
// bool m_WholeWords;
160
// DECLARE_NO_COPY_CLASS(BookSearchEngine)
164
//// State information of a search action. I'd have preferred to make this a
165
//// nested class inside BookReader, but that's against coding standards :-(
166
//// Never construct this class yourself, obtain a copy from
167
//// BookReader::PrepareKeywordSearch(const wxString& key)
168
//class lmSearchStatus
171
// // constructor; supply BookReader ptr, the keyword and (optionally) the
172
// // title of the book to search. By default, all books are searched.
173
// lmSearchStatus(BookReader* base, const wxString& keyword,
174
// bool case_sensitive, bool whole_words_only,
175
// const wxString& book = wxEmptyString);
176
// bool Search(); // do the next iteration
177
// bool IsActive() { return m_Active; }
178
// int GetCurIndex() { return m_CurIndex; }
179
// int GetMaxIndex() { return m_MaxIndex; }
180
// const wxString& GetName() { return m_Name; }
182
// const BookIndexItem *GetCurItem() const { return m_CurItem; }
185
// BookReader* m_Data;
186
// BookSearchEngine m_Engine;
187
// wxString m_Keyword, m_Name;
188
// wxString m_LastPage;
189
// BookIndexItem* m_CurItem;
190
// bool m_Active; // search is not finished
191
// int m_CurIndex; // where we are now
192
// int m_MaxIndex; // number of files we search
193
// // For progress bar: 100*curindex/maxindex = % complete
195
// DECLARE_NO_COPY_CLASS(lmSearchStatus)
199
//---------------------------------------------------------------------------------------
200
// Class BookReader contains the information about all loaded books
203
// friend class lmSearchStatus;
205
bool AddBookPagesToList(const wxFileName& oFilename);
206
bool ProcessIndexFile(const wxFileName& oFilename, BookRecord* pBookr);
207
void ProcessIndexEntries(wxXmlNode* pNode, BookRecord *pBookr);
208
bool ProcessTOCEntry(wxXmlNode* pNode, BookRecord *pBookr, int nLevel);
211
XmlParser* m_pParser;
212
BookRecArray m_bookRecords; // each book has one record in this array
213
BookIndexArray m_contents; // list of all available books and their TOCs
214
BookIndexArray m_index; // list of all index items
215
lmPageIndexArray m_pagelist; // list of all html pages (whether in TOC or not in TOC)
217
DECLARE_NO_COPY_CLASS(BookReader)
223
void SetTempDir(const wxString& path);
226
bool AddBook(const wxFileName& book);
228
// Page search methods
229
wxString FindPageByName(const wxString& page);
230
wxString FindPageById(int id);
232
// accessors to the tables
233
inline const BookRecArray& GetBookRecArray() const { return m_bookRecords; }
234
inline const BookIndexArray& GetContentsArray() const { return m_contents; }
235
inline const BookIndexArray& GetIndexArray() const { return m_index; }
237
BookRecord* ProcessTOCFile(const wxFileName& oFilename);
245
#endif // __LENMUS_BOOK_READER_H__