Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/BuffDoc.h | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h new file mode 100644 index 0000000..7c5ef9a --- a/dev/null +++ b/noncore/apps/opie-reader/BuffDoc.h | |||
@@ -0,0 +1,138 @@ | |||
1 | #ifndef __BuffDoc_h | ||
2 | #define __BuffDoc_h | ||
3 | |||
4 | #include "CBuffer.h" | ||
5 | #include "ZText.h" | ||
6 | #include "Aportis.h" | ||
7 | #include "ztxt.h" | ||
8 | #include "ppm_expander.h" | ||
9 | #include "CFilter.h" | ||
10 | #include <qfontmetrics.h> | ||
11 | #include <qmessagebox.h> | ||
12 | |||
13 | class BuffDoc | ||
14 | { | ||
15 | CBuffer lastword; | ||
16 | CSizeBuffer lastsizes, allsizes; | ||
17 | size_t laststartline; | ||
18 | bool lastispara; | ||
19 | CExpander* exp; | ||
20 | CFilterChain* filt; | ||
21 | QFontMetrics* m_fm; | ||
22 | public: | ||
23 | ~BuffDoc() | ||
24 | { | ||
25 | delete filt; | ||
26 | delete exp; | ||
27 | } | ||
28 | BuffDoc() : m_fm(NULL) | ||
29 | { | ||
30 | exp = NULL; | ||
31 | filt = NULL; | ||
32 | // qDebug("Buffdoc created"); | ||
33 | } | ||
34 | bool empty() { return (exp == NULL); } | ||
35 | void setfm(QFontMetrics* fm) | ||
36 | { | ||
37 | m_fm = fm; | ||
38 | // qDebug("Buffdoc:setfm"); | ||
39 | } | ||
40 | void setfilter(CFilterChain* _f) | ||
41 | { | ||
42 | if (filt != NULL) delete filt; | ||
43 | filt = _f; | ||
44 | filt->setsource(exp); | ||
45 | } | ||
46 | CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } | ||
47 | bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } | ||
48 | bool iseol() { return (lastword[0] == '\0'); } | ||
49 | int openfile(QWidget* _parent, const char *src) | ||
50 | { | ||
51 | // qDebug("BuffDoc:Openfile:%s", src); | ||
52 | // qDebug("Trying aportis %x",exp); | ||
53 | if (exp != NULL) delete exp; | ||
54 | lastword[0] = '\0'; | ||
55 | lastsizes[0] = laststartline = 0; | ||
56 | lastispara = false; | ||
57 | /* | ||
58 | exp = new Text; | ||
59 | int ret = exp->openfile(src); | ||
60 | */ | ||
61 | |||
62 | exp = new Aportis; | ||
63 | // qDebug("Calling openfile"); | ||
64 | int ret = exp->openfile(src); | ||
65 | // qDebug("Called openfile"); | ||
66 | if (ret == -1) | ||
67 | { | ||
68 | // qDebug("problem opening source file:%s",src); | ||
69 | delete exp; | ||
70 | exp = NULL; | ||
71 | return ret; | ||
72 | } | ||
73 | if (ret == -2) | ||
74 | { | ||
75 | |||
76 | delete exp; | ||
77 | // qDebug("Trying ztxt"); | ||
78 | exp = new ztxt; | ||
79 | ret = exp->openfile(src); | ||
80 | } | ||
81 | #ifndef SMALL | ||
82 | if (ret != 0) | ||
83 | { | ||
84 | delete exp; | ||
85 | // qDebug("Trying ppms"); | ||
86 | exp = new ppm_expander; | ||
87 | ret = exp->openfile(src); | ||
88 | } | ||
89 | |||
90 | if (ret != 0) | ||
91 | { | ||
92 | delete exp; | ||
93 | exp = new Text; | ||
94 | // qDebug("Trying text"); | ||
95 | ret = exp->openfile(src); | ||
96 | } | ||
97 | #else | ||
98 | if (ret != 0) | ||
99 | { | ||
100 | delete exp; | ||
101 | exp = new Text; | ||
102 | ret = exp->openfile(src); | ||
103 | } | ||
104 | #endif | ||
105 | if (ret != 0) | ||
106 | { | ||
107 | delete exp; | ||
108 | QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file"); | ||
109 | return ret; | ||
110 | } | ||
111 | // qDebug("Doing final open:%x:%x",exp,filt); | ||
112 | |||
113 | lastword[0] = '\0'; | ||
114 | lastsizes[0] = laststartline = 0; | ||
115 | lastispara = false; | ||
116 | exp->locate(0); | ||
117 | filt->setsource(exp); | ||
118 | // qDebug("BuffDoc:file opened"); | ||
119 | return 0; | ||
120 | } | ||
121 | int getch() { return (exp == NULL) ? UEOF : filt->getch(); } | ||
122 | unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } | ||
123 | void locate(unsigned int n); | ||
124 | bool getline(CBuffer* buff, int w); | ||
125 | bool getline(CBuffer* buff, int w, int cw); | ||
126 | void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } | ||
127 | int getpara(CBuffer& buff) | ||
128 | { | ||
129 | int ch, i = 0; | ||
130 | while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; | ||
131 | buff[i] = '\0'; | ||
132 | if (i == 0 && ch == UEOF) i = -1; | ||
133 | laststartline = exp->locate(); | ||
134 | return i; | ||
135 | } | ||
136 | }; | ||
137 | |||
138 | #endif | ||