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
21 #include <ZLInputStream.h>
23 #include "TcrPlugin.h"
24 #include "TcrStream.h"
25 #include "PPLBookReader.h"
26 #include "../util/TextFormatDetector.h"
27 #include "../../description/BookDescription.h"
28 #include "../txt/TxtBookReader.h"
29 #include "../html/HtmlBookReader.h"
30 #include "../txt/PlainTextFormat.h"
32 bool TcrPlugin::acceptsFile(const ZLFile
&file
) const {
33 return (file
.extension() == "tcr") || (file
.extension() == "TCR");
36 bool TcrPlugin::readDescription(const std::string
&path
, BookDescription
&description
) const {
39 shared_ptr
<ZLInputStream
> stream
= new TcrStream(file
);
40 detectEncodingAndLanguage(description
, *stream
);
41 if (description
.encoding().empty()) {
48 bool TcrPlugin::readModel(const BookDescription
&description
, BookModel
&model
) const {
49 ZLFile
file(description
.fileName());
50 shared_ptr
<ZLInputStream
> stream
= new TcrStream(file
);
52 PlainTextFormat
format(description
.fileName());
53 if (!format
.initialized()) {
54 PlainTextFormatDetector detector
;
55 detector
.detect(*stream
, format
);
58 if (TextFormatDetector().isPPL(*stream
)) {
59 PPLBookReader(model
, description
.encoding()).readDocument(*stream
);
60 } else if (TextFormatDetector().isHtml(*stream
)) {
61 HtmlBookReader("", model
, format
, description
.encoding()).readDocument(*stream
);
63 TxtBookReader(model
, format
, description
.encoding()).readDocument(*stream
);
68 const std::string
&TcrPlugin::iconName() const {
69 static const std::string ICON_NAME
= "tcr";
73 FormatInfoPage
*TcrPlugin::createInfoPage(ZLOptionsDialog
&dialog
, const std::string
&fileName
) {
74 ZLFile
file(fileName
);
75 shared_ptr
<ZLInputStream
> stream
= new TcrStream(file
);
76 if (TextFormatDetector().isPPL(*stream
)) {
79 return new PlainTextInfoPage(dialog
, fileName
, ZLResourceKey("Text"), !TextFormatDetector().isHtml(*stream
));