PlainTextInfoPage::PlainTextInfoPage(ZLOptionsDialog &dialog, const std::string &fileName, const ZLResourceKey &key, bool showContentsEntry) : myFormat(fileName) {
	if (!myFormat.initialized()) {
		PlainTextFormatDetector detector;
		shared_ptr<ZLInputStream> stream = ZLFile(fileName).inputStream();
		if (stream) {
			detector.detect(*stream, myFormat);
		}
	}

	ZLDialogContent &tab = dialog.createTab(key);

	BreakTypeOptionEntry *breakEntry = new BreakTypeOptionEntry(*this, myFormat.BreakTypeOption);
	myIgnoredIndentEntry = new ZLSimpleSpinOptionEntry(myFormat.IgnoredIndentOption, 1);
	tab.addOption(ZLResourceKey("breakType"), breakEntry);
	tab.addOption(ZLResourceKey("ignoreIndent"), myIgnoredIndentEntry);
	breakEntry->onValueSelected(breakEntry->initialIndex());

	if (showContentsEntry) {
		CreateContentsTableOptionEntry *contentsTableEntry = new CreateContentsTableOptionEntry(*this, myFormat.CreateContentsTableOption);
		myEmptyLinesBeforeNewSectionEntry = new ZLSimpleSpinOptionEntry(myFormat.EmptyLinesBeforeNewSectionOption, 1);
		tab.addOption(ZLResourceKey("buildTOC"), contentsTableEntry);
		tab.addOption(ZLResourceKey("emptyLines"), myEmptyLinesBeforeNewSectionEntry);
		contentsTableEntry->onStateChanged(contentsTableEntry->initialState());
	}
}
Esempio n. 2
0
bool TxtPlugin::readModel(BookModel &model) const {
	Book &book = *model.book();
	const ZLFile &file = book.file();
	shared_ptr<ZLInputStream> stream = file.inputStream();
	if (stream.isNull()) {
		return false;
	}

	PlainTextFormat format(file);
	if (!format.initialized()) {
		PlainTextFormatDetector detector;
		detector.detect(*stream, format);
	}

	readLanguageAndEncoding(book);
	TxtBookReader(model, format, book.encoding()).readDocument(*stream);
	return true;
}
Esempio n. 3
0
bool HtmlPlugin::readModel(const BookDescription &description, BookModel &model) const {
	std::string fileName = description.fileName();
	shared_ptr<ZLInputStream> stream = ZLFile(fileName).inputStream();
	if (stream.isNull()) {
		return false;
	}

	PlainTextFormat format(fileName);
	if (!format.initialized()) {
		PlainTextFormatDetector detector;
		detector.detect(*stream, format);
	}

	int index0 = fileName.rfind('/');
	int index1 = fileName.rfind(':');
	HtmlBookReader(fileName.substr(0, std::max(index0, index1) + 1), model, format, description.encoding()).readDocument(*stream);

	return true;
}
Esempio n. 4
0
bool HtmlPlugin::readModel(BookModel &model) const {
	const Book& book = *model.book();
	const ZLFile &file = book.file();
	shared_ptr<ZLInputStream> stream = file.inputStream();
	if (stream.isNull()) {
		return false;
	}

	PlainTextFormat format(file);
	if (!format.initialized()) {
		PlainTextFormatDetector detector;
		detector.detect(*stream, format);
	}

	std::string directoryPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
	HtmlBookReader reader(directoryPrefix, model, format, book.encoding());
	reader.setFileName(MiscUtil::htmlFileName(file.path()));
	reader.readDocument(*stream);

	return true;
}