Diffstat (limited to 'noncore/apps/opie-reader/plucker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/plucker.cpp | 100 |
1 files changed, 90 insertions, 10 deletions
diff --git a/noncore/apps/opie-reader/plucker.cpp b/noncore/apps/opie-reader/plucker.cpp index a8e688f..d1ccd6f 100644 --- a/noncore/apps/opie-reader/plucker.cpp +++ b/noncore/apps/opie-reader/plucker.cpp | |||
@@ -1,151 +1,231 @@ | |||
1 | #include "useqpe.h" | ||
1 | #include <stdio.h> | 2 | #include <stdio.h> |
2 | #include <string.h> | 3 | #include <string.h> |
4 | #include <qmessagebox.h> | ||
5 | #include <qpixmap.h> | ||
3 | #ifdef USEQPE | 6 | #ifdef USEQPE |
4 | #include <qpe/qcopenvelope_qws.h> | 7 | #include <qpe/qcopenvelope_qws.h> |
5 | #endif | 8 | #endif |
6 | #ifdef LOCALPICTURES | 9 | #ifdef LOCALPICTURES |
7 | #include <qscrollview.h> | 10 | #include <qscrollview.h> |
8 | #endif | 11 | #endif |
9 | #ifdef USEQPE | 12 | #ifdef USEQPE |
10 | #include <qpe/global.h> | 13 | #include <qpe/global.h> |
11 | #include <qpe/qpeapplication.h> | 14 | #include <qpe/qpeapplication.h> |
12 | #else | 15 | #else |
13 | #include <qapplication.h> | 16 | #include <qapplication.h> |
14 | #endif | 17 | #endif |
18 | #include <qclipboard.h> | ||
15 | 19 | ||
16 | #include "plucker.h" | 20 | #include "plucker.h" |
21 | #include "Aportis.h" | ||
17 | #include "Palm2QImage.h" | 22 | #include "Palm2QImage.h" |
23 | #include "static.h" | ||
18 | 24 | ||
19 | 25 | ||
20 | struct CPlucker_dataRecord | 26 | struct CPlucker_dataRecord |
21 | { | 27 | { |
22 | UInt16 uid; | 28 | UInt16 uid; |
23 | UInt16 nParagraphs; | 29 | UInt16 nParagraphs; |
24 | UInt16 size; | 30 | UInt16 size; |
25 | UInt8 type; | 31 | UInt8 type; |
26 | UInt8 reserved; | 32 | UInt8 reserved; |
27 | }; | 33 | }; |
28 | 34 | ||
29 | int CPlucker::HeaderSize() | 35 | int CPlucker::HeaderSize() |
30 | { | 36 | { |
31 | return sizeof(CPlucker_dataRecord); | 37 | return sizeof(CPlucker_dataRecord); |
32 | } | 38 | } |
33 | 39 | ||
34 | void CPlucker::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved) | 40 | void CPlucker::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved) |
35 | { | 41 | { |
36 | CPlucker_dataRecord thishdr; | 42 | CPlucker_dataRecord thishdr; |
37 | fread(&thishdr, 1, HeaderSize(), fin); | 43 | fread(&thishdr, 1, HeaderSize(), fin); |
38 | uid = ntohs(thishdr.uid); | 44 | uid = ntohs(thishdr.uid); |
39 | nParagraphs = ntohs(thishdr.nParagraphs); | 45 | nParagraphs = ntohs(thishdr.nParagraphs); |
40 | size = ntohs(thishdr.size); | 46 | size = ntohs(thishdr.size); |
41 | type = thishdr.type; | 47 | type = thishdr.type; |
42 | reserved = thishdr.reserved; | 48 | reserved = thishdr.reserved; |
43 | } | 49 | } |
44 | 50 | ||
45 | CPlucker::CPlucker() | 51 | CPlucker::CPlucker() |
46 | { /*printf("constructing:%x\n",fin);*/ } | 52 | { /*printf("constructing:%x\n",fin);*/ |
53 | EOPPhase = 0; | ||
54 | } | ||
47 | 55 | ||
48 | bool CPlucker::CorrectDecoder() | 56 | bool CPlucker::CorrectDecoder() |
49 | { | 57 | { |
50 | return (memcmp(&head.type, "DataPlkr", 8) == 0); | 58 | return (memcmp(&head.type, "DataPlkr", 8) == 0); |
51 | } | 59 | } |
52 | 60 | ||
53 | int CPlucker::bgetch() | 61 | int CPlucker::bgetch() |
54 | { | 62 | { |
55 | int ch = EOF; | 63 | int ch = EOF; |
56 | if (bufferpos >= buffercontent) | 64 | if (bufferpos >= buffercontent) |
57 | { | 65 | { |
58 | if (!m_continuous) return EOF; | 66 | if (isEndOfSection(bufferrec)) |
59 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF; | 67 | { |
60 | ////odebug << "Passing through " << currentpos << "" << oendl; | 68 | if (!m_continuous) return EOF; |
61 | if (!expand(bufferrec+1)) return EOF; | 69 | } |
70 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) | ||
71 | { | ||
72 | return EOF; | ||
73 | } | ||
74 | if (!expand(bufferrec+1)) | ||
75 | { | ||
76 | return EOF; | ||
77 | } | ||
62 | mystyle.unset(); | 78 | mystyle.unset(); |
63 | if (m_ParaOffsets[m_nextParaIndex] == 0) | 79 | if (m_ParaOffsets[m_nextParaIndex] == 0) |
64 | { | 80 | { |
65 | while (m_ParaOffsets[m_nextParaIndex+1] == 0) | 81 | while (m_ParaOffsets[m_nextParaIndex+1] == 0) |
66 | { | 82 | { |
67 | // odebug << "Skipping extraspace:" << m_ParaAttrs[m_nextParaIndex]&7 << "" << oendl; | 83 | // qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); |
68 | m_nextParaIndex++; | 84 | m_nextParaIndex++; |
69 | } | 85 | } |
70 | } | 86 | } |
71 | mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); | 87 | mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); |
72 | //odebug << "Using extraspace:" << m_ParaAttrs[m_nextParaIndex]&7 << "" << oendl; | 88 | //qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); |
73 | ch = 10; | 89 | ch = 10; |
74 | EOPPhase = 4; | 90 | if (m_continuous) EOPPhase = 4; |
75 | } | 91 | } |
76 | else if (bufferpos == m_nextPara) | 92 | else if (bufferpos == m_nextPara) |
77 | { | 93 | { |
78 | while (bufferpos == m_nextPara) | 94 | while (bufferpos == m_nextPara) |
79 | { | 95 | { |
80 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 96 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
81 | m_nextParaIndex++; | 97 | m_nextParaIndex++; |
82 | // odebug << "Skipping extraspace:" << m_ParaAttrs[m_nextParaIndex]&7 << "" << oendl; | 98 | // qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); |
83 | if (m_nextParaIndex == m_nParas) | 99 | if (m_nextParaIndex == m_nParas) |
84 | { | 100 | { |
85 | m_nextPara = -1; | 101 | m_nextPara = -1; |
86 | } | 102 | } |
87 | else | 103 | else |
88 | { | 104 | { |
89 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 105 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
90 | } | 106 | } |
91 | } | 107 | } |
92 | mystyle.unset(); | 108 | mystyle.unset(); |
93 | mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); | 109 | mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); |
94 | //odebug << "Using extraspace:" << m_ParaAttrs[m_nextParaIndex]&7 << "" << oendl; | 110 | //qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); |
95 | if (m_lastBreak == locate()) | 111 | if (m_lastBreak == locate()) |
96 | { | 112 | { |
97 | currentpos++; | 113 | currentpos++; |
98 | ch = expandedtextbuffer[bufferpos++]; | 114 | ch = expandedtextbuffer[bufferpos++]; |
99 | } | 115 | } |
100 | else | 116 | else |
101 | { | 117 | { |
102 | ch = 10; | 118 | ch = 10; |
103 | } | 119 | } |
104 | } | 120 | } |
105 | else | 121 | else |
106 | { | 122 | { |
107 | currentpos++; | 123 | currentpos++; |
108 | ch = expandedtextbuffer[bufferpos++]; | 124 | ch = expandedtextbuffer[bufferpos++]; |
109 | } | 125 | } |
110 | return ch; | 126 | return ch; |
111 | } | 127 | } |
112 | 128 | ||
113 | tchar CPlucker::getch(bool fast) | 129 | tchar CPlucker::getch(bool fast) |
114 | { | 130 | { |
115 | mystyle.clearPicture(); | 131 | mystyle.clearPicture(); |
116 | 132 | ||
117 | if (EOPPhase > 0) | 133 | if (EOPPhase > 0) |
118 | { | 134 | { |
119 | int ch = 10; | 135 | int ch = 10; |
120 | switch (EOPPhase) | 136 | switch (EOPPhase) |
121 | { | 137 | { |
122 | case 4: | 138 | case 4: |
123 | if (!fast) mystyle.setPicture(false, hRule(100,5)); | 139 | if (!fast) mystyle.setPicture(false, hRule(100,5)); |
124 | mystyle.setCentreJustify(); | 140 | mystyle.setCentreJustify(); |
125 | ch = '#'; | 141 | ch = '#'; |
126 | break; | 142 | break; |
127 | case 3: | 143 | case 3: |
128 | mystyle.setFontSize(3); | 144 | mystyle.setFontSize(3); |
129 | ch = 10; | 145 | ch = 10; |
130 | break; | 146 | break; |
131 | case 2: | 147 | case 2: |
132 | ch = 10; | 148 | ch = 10; |
133 | break; | 149 | break; |
134 | case 1: | 150 | case 1: |
135 | mystyle.unset(); | 151 | mystyle.unset(); |
136 | default: | 152 | default: |
137 | ch = 10; | 153 | ch = 10; |
138 | } | 154 | } |
139 | EOPPhase--; | 155 | EOPPhase--; |
140 | return ch; | 156 | return ch; |
141 | } | 157 | } |
142 | 158 | ||
143 | return getch_base(fast); | 159 | return getch_base(fast); |
144 | } | 160 | } |
145 | 161 | ||
146 | QImage* CPlucker::imagefromdata(UInt8* imgbuffer, UInt32 imgsize) | 162 | QImage* CPlucker::imagefromdata(UInt8* imgbuffer, UInt32 imgsize) |
147 | { | 163 | { |
148 | QImage* qimage = Palm2QImage(imgbuffer, imgsize); | 164 | QImage* qimage = Palm2QImage(imgbuffer, imgsize); |
149 | delete [] imgbuffer; | 165 | delete [] imgbuffer; |
150 | return qimage; | 166 | return qimage; |
151 | } | 167 | } |
168 | |||
169 | void CPlucker::start2endSection() // to plucker base | ||
170 | { | ||
171 | m_currentstart = NEFstartSection(); | ||
172 | m_currentend = NEFendSection(); | ||
173 | } | ||
174 | |||
175 | unsigned long CPlucker::NEFstartSection() // virtual in plucker base - differs only in obsoleted nef so move implementation | ||
176 | { | ||
177 | //inefficient - Should calc start/end of section on entry to section? | ||
178 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
179 | UInt32 thishdr_size; | ||
180 | UInt8 thishdr_type, thishdr_reserved; | ||
181 | unsigned long textlength = currentpos-bufferpos; | ||
182 | for (UInt16 recptr = bufferrec-1; recptr >= 1; recptr--) | ||
183 | { | ||
184 | gotorecordnumber(recptr); | ||
185 | //qDebug("recptr:%u", recptr); | ||
186 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
187 | if (thishdr_type < 2) | ||
188 | { | ||
189 | if ((thishdr_reserved && continuation_bit) == 0) break; | ||
190 | textlength -= thishdr_size; | ||
191 | //qDebug("Textlength:%u, reserved:%u, recptr:%u", textlength, thishdr_reserved, recptr); | ||
192 | } | ||
193 | } | ||
194 | return textlength; | ||
195 | } | ||
196 | |||
197 | unsigned long CPlucker::NEFendSection() // virtual in plucker base - differs only in obsoleted nef so move implementation | ||
198 | { | ||
199 | //inefficient - Should calc start/end of section on entry to section? | ||
200 | unsigned long textlength = currentpos-bufferpos+buffercontent; | ||
201 | gotorecordnumber(bufferrec); | ||
202 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
203 | UInt32 thishdr_size; | ||
204 | UInt8 thishdr_type, thishdr_reserved; | ||
205 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
206 | if ((thishdr_reserved && continuation_bit) != 0) | ||
207 | { | ||
208 | for (UInt16 recptr = bufferrec+1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
209 | { | ||
210 | gotorecordnumber(recptr); | ||
211 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
212 | UInt32 thishdr_size; | ||
213 | UInt8 thishdr_type, thishdr_reserved; | ||
214 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
215 | //qDebug("recptr %u bufferrec %u type %u m_reserved %u", recptr, bufferrec, typ | ||
216 | if (thishdr_type < 2) | ||
217 | { | ||
218 | textlength += thishdr_size; | ||
219 | if ((thishdr_reserved && continuation_bit) == 0) break; | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | return textlength; | ||
224 | } | ||
225 | |||
226 | #ifndef __STATIC | ||
227 | extern "C" | ||
228 | { | ||
229 | CExpander* newcodec() { return new CPlucker; } | ||
230 | } | ||
231 | #endif | ||