gui
[lbook_fbreader.git] / fbreader / src / formats / txt / TxtPlugin.cpp
blobaeb4ed2ad9020c517ba47715dc8df28864013346
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 <ZLFile.h>
21 #include <ZLInputStream.h>
23 #include "TxtPlugin.h"
24 #include "TxtBookReader.h"
25 #include "PlainTextFormat.h"
26 #include "../../description/BookDescription.h"
28 TxtPlugin::~TxtPlugin() {
31 bool TxtPlugin::providesMetaInfo() const {
32 return false;
35 bool TxtPlugin::acceptsFile(const ZLFile &file) const {
36 return (file.extension() == "txt") || (file.extension() == "TXT");
39 bool TxtPlugin::readDescription(const std::string &path, BookDescription &description) const {
40 ZLFile file(path);
42 shared_ptr<ZLInputStream> stream = file.inputStream();
43 if (stream.isNull()) {
44 return false;
46 detectEncodingAndLanguage(description, *stream);
47 if (description.encoding().empty()) {
48 return false;
51 return true;
54 bool TxtPlugin::readModel(const BookDescription &description, BookModel &model) const {
55 shared_ptr<ZLInputStream> stream = ZLFile(description.fileName()).inputStream();
56 if (stream.isNull()) {
57 return false;
60 PlainTextFormat format(description.fileName());
61 if (!format.initialized()) {
62 PlainTextFormatDetector detector;
63 detector.detect(*stream, format);
66 TxtBookReader(model, format, description.encoding()).readDocument(*stream);
67 return true;
70 const std::string &TxtPlugin::iconName() const {
71 static const std::string ICON_NAME = "unknown";
72 return ICON_NAME;
75 FormatInfoPage *TxtPlugin::createInfoPage(ZLOptionsDialog &dialog, const std::string &fileName) {
76 return new PlainTextInfoPage(dialog, fileName, ZLResourceKey("Text"), true);