summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/BuffDoc.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h104
1 files changed, 25 insertions, 79 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 7c5ef9a..1aac817 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -1,135 +1,81 @@
1#ifndef __BuffDoc_h 1#ifndef __BuffDoc_h
2#define __BuffDoc_h 2#define __BuffDoc_h
3 3
4#include "CBuffer.h"
5#include "ZText.h" 4#include "ZText.h"
6#include "Aportis.h" 5#include "Aportis.h"
7#include "ztxt.h" 6#include "ztxt.h"
8#include "ppm_expander.h" 7#include "ppm_expander.h"
8#include "CDrawBuffer.h"
9#include "CFilter.h" 9#include "CFilter.h"
10#include <qfontmetrics.h> 10#include <qfontmetrics.h>
11#include <qmessagebox.h> 11#include <qmessagebox.h>
12 12
13class BuffDoc 13class BuffDoc
14{ 14{
15 CBuffer lastword; 15 CDrawBuffer lastword;
16 CSizeBuffer lastsizes, allsizes; 16 CSizeBuffer lastsizes, allsizes;
17 size_t laststartline; 17 size_t laststartline;
18 bool lastispara; 18 bool lastispara;
19 CExpander* exp; 19 CExpander* exp;
20 CFilterChain* filt; 20 CFilterChain* filt;
21 QFontMetrics* m_fm;
22 public: 21 public:
23 ~BuffDoc() 22 ~BuffDoc()
24 { 23 {
25 delete filt; 24 delete filt;
26 delete exp; 25 delete exp;
27 } 26 }
28 BuffDoc() : m_fm(NULL) 27 BuffDoc()
29 { 28 {
30 exp = NULL; 29 exp = NULL;
31 filt = NULL; 30 filt = NULL;
31 lastword.empty();
32 // qDebug("Buffdoc created"); 32 // qDebug("Buffdoc created");
33 } 33 }
34 bool empty() { return (exp == NULL); } 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) 35 void setfilter(CFilterChain* _f)
41 { 36 {
42 if (filt != NULL) delete filt; 37 if (filt != NULL) delete filt;
43 filt = _f; 38 filt = _f;
44 filt->setsource(exp); 39 filt->setsource(exp);
45 } 40 }
46 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } 41 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
47 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } 42 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
48 bool iseol() { return (lastword[0] == '\0'); } 43 bool iseol() { return (lastword[0] == '\0'); }
49 int openfile(QWidget* _parent, const char *src) 44 int openfile(QWidget* _parent, const char *src);
45 tchar getch()
50 { 46 {
51 // qDebug("BuffDoc:Openfile:%s", src); 47 tchar ch = UEOF;
52 // qDebug("Trying aportis %x",exp); 48 CStyle sty;
53 if (exp != NULL) delete exp; 49 if (exp != NULL)
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 { 50 {
68 // qDebug("problem opening source file:%s",src); 51 filt->getch(ch, sty);
69 delete exp;
70 exp = NULL;
71 return ret;
72 } 52 }
73 if (ret == -2) 53 return ch;
74 { 54 }
75 55 void getch(tchar& ch, CStyle& sty)
76 delete exp; 56 {
77 // qDebug("Trying ztxt"); 57 if (exp != NULL)
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 { 58 {
107 delete exp; 59 filt->getch(ch, sty);
108 QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
109 return ret;
110 } 60 }
111 // qDebug("Doing final open:%x:%x",exp,filt); 61 else
112 62 ch = UEOF;
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 } 63 }
121 int getch() { return (exp == NULL) ? UEOF : filt->getch(); }
122 unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } 64 unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
65 unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
66 MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
67 bool hyperlink(unsigned int n);
123 void locate(unsigned int n); 68 void locate(unsigned int n);
124 bool getline(CBuffer* buff, int w); 69 bool getline(CDrawBuffer* buff, int w);
125 bool getline(CBuffer* buff, int w, int cw); 70 bool getline(CDrawBuffer* buff, int w, int cw);
126 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } 71 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
127 int getpara(CBuffer& buff) 72 int getpara(CBuffer& buff)
128 { 73 {
129 int ch, i = 0; 74 tchar ch;
75 int i = 0;
130 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; 76 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
131 buff[i] = '\0'; 77 buff[i] = '\0';
132 if (i == 0 && ch == UEOF) i = -1; 78 if (i == 0 && ch == UEOF) i = -1;
133 laststartline = exp->locate(); 79 laststartline = exp->locate();
134 return i; 80 return i;
135 } 81 }