gui
[lbook_fbreader.git] / fbreader / src / formats / txt / PlainTextFormat.h
blobd2735339dfd84ccc56baf177bff8f3a64e308873
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 #ifndef __PLAINTEXTFORMAT_H__
21 #define __PLAINTEXTFORMAT_H__
23 #include <ZLInputStream.h>
24 #include <ZLOptions.h>
25 #include <optionEntries/ZLSimpleOptionEntry.h>
26 #include <ZLResource.h>
28 #include "../FormatPlugin.h"
30 class PlainTextFormat {
32 public:
33 enum ParagraphBreakType {
34 BREAK_PARAGRAPH_AT_NEW_LINE = 1,
35 BREAK_PARAGRAPH_AT_EMPTY_LINE = 2,
36 BREAK_PARAGRAPH_AT_LINE_WITH_INDENT = 4,
39 PlainTextFormat(const std::string &fileName);
40 ~PlainTextFormat() {}
42 bool initialized() const { return InitializedOption.value(); }
43 int breakType() const { return BreakTypeOption.value(); }
44 int ignoredIndent() const { return IgnoredIndentOption.value(); }
45 int emptyLinesBeforeNewSection() const { return EmptyLinesBeforeNewSectionOption.value(); }
46 bool createContentsTable() const { return CreateContentsTableOption.value(); }
48 private:
49 ZLBooleanOption InitializedOption;
50 ZLIntegerOption BreakTypeOption;
51 ZLIntegerRangeOption IgnoredIndentOption;
52 ZLIntegerRangeOption EmptyLinesBeforeNewSectionOption;
53 ZLBooleanOption CreateContentsTableOption;
55 friend class PlainTextInfoPage;
56 friend class PlainTextFormatDetector;
59 class PlainTextInfoPage : public FormatInfoPage {
61 public:
62 PlainTextInfoPage(ZLOptionsDialog &dialog, const std::string &fileName, const ZLResourceKey &key, bool showContentsEntry);
63 ~PlainTextInfoPage();
65 private:
66 PlainTextFormat myFormat;
68 ZLSimpleSpinOptionEntry *myIgnoredIndentEntry;
69 ZLSimpleSpinOptionEntry *myEmptyLinesBeforeNewSectionEntry;
71 friend class BreakTypeOptionEntry;
72 friend class CreateContentsTableOptionEntry;
75 class PlainTextFormatDetector {
77 public:
78 PlainTextFormatDetector() {}
79 ~PlainTextFormatDetector() {}
81 void detect(ZLInputStream &stream, PlainTextFormat &format);
84 class BreakTypeOptionEntry : public ZLComboOptionEntry {
86 public:
87 BreakTypeOptionEntry(PlainTextInfoPage &page, ZLIntegerOption &breakTypeOption);
88 ~BreakTypeOptionEntry();
90 int initialIndex() const;
91 const std::string &initialValue() const;
92 const std::vector<std::string> &values() const;
93 void onAccept(const std::string &value);
94 void onValueSelected(int index);
96 private:
97 PlainTextInfoPage &myPage;
98 ZLIntegerOption &myBreakTypeOption;
101 class CreateContentsTableOptionEntry : public ZLSimpleBooleanOptionEntry {
103 public:
104 CreateContentsTableOptionEntry(PlainTextInfoPage &page, ZLBooleanOption &option);
105 ~CreateContentsTableOptionEntry();
106 void onStateChanged(bool state);
108 private:
109 PlainTextInfoPage &myPage;
112 #endif /* __PLAINTEXTFORMAT_H__ */