Initial commit. FBReader 0.8.12
[lbook_fbreader.git] / fbreader / src / bookmodel / BookModel.cpp
bloba8292b394a602687fe8148cee69db96fcf592db1
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include <ZLImage.h>
21 #include <ZLFile.h>
23 #include "BookModel.h"
24 #include "BookReader.h"
26 #include "../formats/FormatPlugin.h"
28 BookModel::BookModel(const BookDescriptionPtr description) : myDescription(description) {
29 myBookTextModel = new ZLTextPlainModel(102400);
30 myContentsModel = new ContentsModel();
31 ZLFile file(description->fileName());
32 FormatPlugin *plugin = PluginCollection::instance().plugin(file, false);
33 if (plugin != 0) {
34 plugin->readModel(*description, *this);
38 BookModel::~BookModel() {
41 const std::string &BookModel::fileName() const {
42 return myDescription->fileName();
45 BookModel::Label BookModel::label(const std::string &id) const {
46 std::map<std::string,Label>::const_iterator it = myInternalHyperlinks.find(id);
47 return (it != myInternalHyperlinks.end()) ? it->second : Label(0, -1);
50 void ContentsModel::setReference(const ZLTextTreeParagraph *paragraph, int reference) {
51 myReferenceByParagraph[paragraph] = reference;
54 int ContentsModel::reference(const ZLTextTreeParagraph *paragraph) const {
55 std::map<const ZLTextTreeParagraph*,int>::const_iterator it = myReferenceByParagraph.find(paragraph);
56 return (it != myReferenceByParagraph.end()) ? it->second : -1;