Diffstat (limited to 'noncore/apps/opie-reader/CExpander.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CExpander.h | 197 |
1 files changed, 94 insertions, 103 deletions
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h index 553069c..e9aaf79 100644 --- a/noncore/apps/opie-reader/CExpander.h +++ b/noncore/apps/opie-reader/CExpander.h | |||
@@ -1,158 +1,149 @@ | |||
1 | #ifndef __CExpander_h | 1 | #ifndef __CExpander_h |
2 | #define __CExpander_h | 2 | #define __CExpander_h |
3 | 3 | ||
4 | #ifndef _WINDOWS | ||
5 | #include <unistd.h> | ||
6 | #endif | ||
7 | #include <stdio.h> | ||
8 | #include <time.h> | ||
9 | #include <sys/stat.h> | ||
10 | #include <qmessagebox.h> | ||
4 | #include "useqpe.h" | 11 | #include "useqpe.h" |
5 | #include "config.h" | 12 | #include "config.h" |
6 | #include "StyleConsts.h" | 13 | #include "StyleConsts.h" |
7 | #include "Markups.h" | 14 | #include "Markups.h" |
8 | #include "names.h" | 15 | #include "names.h" |
9 | #include "linktype.h" | 16 | #include "linktype.h" |
10 | 17 | ||
11 | /* OPIE */ | ||
12 | #include <opie2/odebug.h> | ||
13 | |||
14 | /* QT */ | ||
15 | #include <qmessagebox.h> | ||
16 | |||
17 | /* STD */ | ||
18 | #ifndef _WINDOWS | ||
19 | #include <unistd.h> | ||
20 | #endif | ||
21 | #include <stdio.h> | ||
22 | #include <time.h> | ||
23 | |||
24 | class QImage; | 18 | class QImage; |
25 | class Bkmk; | 19 | class Bkmk; |
20 | class QString; | ||
26 | 21 | ||
27 | template<class T> | 22 | template<class T> |
28 | class CList; | 23 | class CList; |
29 | 24 | ||
30 | class CCharacterSource | 25 | class CCharacterSource |
31 | { | 26 | { |
32 | public: | 27 | public: |
33 | virtual void getch(tchar&, CStyle&) = 0; | 28 | virtual void getch(tchar&, CStyle&, unsigned long&) = 0; |
34 | virtual linkType hyperlink(unsigned int n, QString&) = 0; | 29 | virtual linkType hyperlink(unsigned int n, unsigned int noff, QString&, QString& nm) = 0; |
30 | virtual void locate(unsigned int n) = 0; | ||
31 | virtual bool findanchor(const QString& nm) = 0; | ||
32 | virtual void saveposn(const QString& f, size_t posn) = 0; | ||
33 | virtual void writeposn(const QString& f, size_t posn) = 0; | ||
34 | virtual linkType forward(QString& f, size_t& loc) = 0; | ||
35 | virtual linkType back(QString& f, size_t& loc) = 0; | ||
36 | virtual bool hasnavigation() = 0; | ||
37 | virtual int getwidth() = 0; | ||
38 | virtual QImage* getPicture(unsigned long) = 0; | ||
39 | virtual QImage* getPicture(const QString& href) = 0; | ||
40 | virtual bool getFile(const QString& href) = 0; | ||
41 | virtual QString about() = 0; | ||
42 | }; | ||
43 | |||
44 | class CExpander_Interface | ||
45 | { | ||
46 | public: | ||
47 | #ifdef USEQPE | ||
48 | virtual void suspend() = 0; | ||
49 | virtual void unsuspend() = 0; | ||
50 | #endif | ||
51 | virtual QString about() = 0; | ||
52 | virtual size_t getHome() = 0; | ||
53 | //CExpander_Interface(); | ||
54 | //virtual ~CExpander_Interface(); | ||
55 | virtual int openfile(const char *src) = 0; | ||
56 | //virtual int OpenFile(const char *src) = 0; | ||
57 | virtual unsigned int locate() = 0; | ||
58 | virtual void locate(unsigned int n) = 0; | ||
59 | virtual bool hasrandomaccess() = 0; | ||
60 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; | ||
61 | virtual CList<Bkmk>* getbkmklist() { return NULL; } | ||
62 | virtual void getch(tchar& ch, CStyle& sty, unsigned long& pos) = 0; | ||
63 | virtual int getch() = 0; | ||
64 | virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) = 0; | ||
65 | virtual MarkupType PreferredMarkup() = 0; | ||
66 | virtual void saveposn(size_t posn) {} | ||
67 | virtual void writeposn(size_t posn) {} | ||
68 | virtual linkType forward(size_t& loc) { return eNone; } | ||
69 | virtual linkType back(size_t& loc) { return eNone; } | ||
70 | virtual bool hasnavigation() { return false; } | ||
71 | virtual unsigned long startSection() = 0; | ||
72 | virtual unsigned long endSection() = 0; | ||
73 | virtual void start2endSection() = 0; | ||
74 | virtual QImage* getPicture(unsigned long tgt) { return NULL; } | ||
75 | virtual void setContinuous(bool _b) = 0; | ||
76 | #ifdef USEQPE | ||
77 | virtual void suspend(FILE*& fin) = 0; | ||
78 | virtual void unsuspend(FILE*& fin) = 0; | ||
79 | #endif | ||
80 | virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) = 0; | ||
81 | virtual void putSaveData(unsigned char*& src, unsigned short& srclen) = 0; | ||
82 | virtual void setwidth(int w) = 0; | ||
83 | // bool findstring(const QString& info); | ||
84 | // int getpara(CBuffer& buff); | ||
85 | virtual int getwidth() = 0; | ||
86 | virtual QImage* getPicture(const QString& href) = 0; | ||
87 | virtual bool getFile(const QString& href) = 0; | ||
35 | }; | 88 | }; |
36 | 89 | ||
37 | class CExpander | 90 | class CExpander : public CExpander_Interface |
38 | { | 91 | { |
39 | protected: | 92 | protected: |
40 | size_t m_homepos; | 93 | size_t m_homepos; |
41 | bool m_continuous; | 94 | bool m_continuous; |
42 | char* fname; | 95 | char* fname; |
43 | bool bSuspended; | 96 | bool bSuspended; |
44 | size_t suspos; | 97 | size_t suspos; |
45 | time_t sustime; | 98 | time_t sustime; |
46 | int m_scrWidth; | 99 | int m_scrWidth; |
47 | unsigned long m_currentstart, m_currentend; | 100 | unsigned long m_currentstart, m_currentend; |
48 | public: | 101 | public: |
49 | #ifdef USEQPE | 102 | #ifdef USEQPE |
50 | virtual void suspend() = 0; | 103 | virtual void suspend() = 0; |
51 | virtual void unsuspend() = 0; | 104 | virtual void unsuspend() = 0; |
52 | #endif | 105 | #endif |
53 | size_t getHome() { return m_homepos; } | 106 | size_t getHome(); |
54 | CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {}; | 107 | CExpander(); |
55 | virtual ~CExpander() { if (fname != NULL) delete [] fname; }; | 108 | virtual ~CExpander(); |
56 | int openfile(const char *src) | 109 | int openfile(const char *src); |
57 | { | ||
58 | bSuspended = false; | ||
59 | fname = strdup(src); | ||
60 | return OpenFile(src); | ||
61 | } | ||
62 | virtual int OpenFile(const char *src) = 0; | 110 | virtual int OpenFile(const char *src) = 0; |
63 | virtual unsigned int locate() = 0; | 111 | virtual unsigned int locate() = 0; |
64 | virtual void locate(unsigned int n) = 0; | 112 | virtual void locate(unsigned int n) = 0; |
65 | virtual bool hasrandomaccess() = 0; | 113 | virtual bool hasrandomaccess() = 0; |
66 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; | 114 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; |
67 | virtual CList<Bkmk>* getbkmklist() { return NULL; } | 115 | virtual CList<Bkmk>* getbkmklist() { return NULL; } |
68 | virtual void getch(tchar& ch, CStyle& sty) | 116 | virtual void getch(tchar& ch, CStyle& sty, unsigned long& pos); |
69 | { | ||
70 | int ich = getch(); | ||
71 | ch = (ich == EOF) ? UEOF : ich; | ||
72 | sty.unset(); | ||
73 | } | ||
74 | virtual int getch() = 0; | 117 | virtual int getch() = 0; |
75 | virtual linkType hyperlink(unsigned int n, QString& wrd) | 118 | virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm); |
76 | { | ||
77 | locate(n); | ||
78 | return eLink; | ||
79 | } | ||
80 | virtual MarkupType PreferredMarkup() = 0; | 119 | virtual MarkupType PreferredMarkup() = 0; |
81 | virtual void saveposn(size_t posn) {} | 120 | virtual void saveposn(size_t posn) {} |
82 | virtual void writeposn(size_t posn) {} | 121 | virtual void writeposn(size_t posn) {} |
83 | virtual bool forward(size_t& loc) { return false; } | 122 | virtual linkType forward(size_t& loc) { return eNone; } |
84 | virtual bool back(size_t& loc) { return false; } | 123 | virtual linkType back(size_t& loc) { return eNone; } |
85 | virtual bool hasnavigation() { return false; } | 124 | virtual bool hasnavigation() { return false; } |
86 | unsigned long startSection() | 125 | unsigned long startSection(); |
87 | { | 126 | unsigned long endSection(); |
88 | unsigned long current = locate(); | 127 | virtual void start2endSection(); |
89 | if (m_currentstart > current || current > m_currentend) | ||
90 | { | ||
91 | start2endSection(); | ||
92 | } | ||
93 | return m_currentstart; | ||
94 | } | ||
95 | unsigned long endSection() | ||
96 | { | ||
97 | unsigned long current = locate(); | ||
98 | if (m_currentstart > current || current > m_currentend) | ||
99 | { | ||
100 | start2endSection(); | ||
101 | } | ||
102 | return m_currentend; | ||
103 | } | ||
104 | virtual void start2endSection() | ||
105 | { | ||
106 | m_currentstart = 0; | ||
107 | unsigned long file; | ||
108 | sizes(file, m_currentend); | ||
109 | } | ||
110 | virtual QImage* getPicture(unsigned long tgt) { return NULL; } | 128 | virtual QImage* getPicture(unsigned long tgt) { return NULL; } |
111 | void setContinuous(bool _b) { m_continuous = _b; } | 129 | void setContinuous(bool _b) { m_continuous = _b; } |
112 | #ifdef USEQPE | 130 | #ifdef USEQPE |
113 | virtual void suspend(FILE*& fin) | 131 | virtual void suspend(FILE*& fin); |
132 | virtual void unsuspend(FILE*& fin); | ||
133 | #endif | ||
134 | virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen); | ||
135 | virtual void putSaveData(unsigned char*& src, unsigned short& srclen); | ||
136 | void setwidth(int w) | ||
114 | { | 137 | { |
115 | bSuspended = true; | 138 | m_scrWidth = w; |
116 | suspos = ftell(fin); | ||
117 | fclose(fin); | ||
118 | fin = NULL; | ||
119 | sustime = time(NULL); | ||
120 | } | 139 | } |
121 | virtual void unsuspend(FILE*& fin) | 140 | int getwidth() |
122 | { | ||
123 | if (bSuspended) | ||
124 | { | 141 | { |
125 | bSuspended = false; | 142 | return m_scrWidth; |
126 | int delay = time(NULL) - sustime; | ||
127 | if (delay < 10) sleep(10-delay); | ||
128 | fin = fopen(fname, "rb"); | ||
129 | for (int i = 0; fin == NULL && i < 5; i++) | ||
130 | { | ||
131 | sleep(5); | ||
132 | fin = fopen(fname, "rb"); | ||
133 | } | ||
134 | if (fin == NULL) | ||
135 | { | ||
136 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); | ||
137 | exit(0); | ||
138 | } | ||
139 | suspos = fseek(fin, suspos, SEEK_SET); | ||
140 | } | 143 | } |
141 | } | 144 | // bool findstring(const QString& info); |
142 | #endif | 145 | // int getpara(CBuffer& buff); |
143 | virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | 146 | virtual QImage* getPicture(const QString& href) { return NULL; } |
144 | { | 147 | virtual bool getFile(const QString& href) { return false; } |
145 | len = srclen; | ||
146 | data = new unsigned char[len]; | ||
147 | memcpy(data, src, len); | ||
148 | } | ||
149 | virtual void putSaveData(unsigned char*& src, unsigned short& srclen) | ||
150 | { | ||
151 | if (srclen != 0) | ||
152 | { | ||
153 | odebug << "Don't know what to do with non-zero save data" << oendl; | ||
154 | } | ||
155 | } | ||
156 | void setwidth(int w) { m_scrWidth = w; } | ||
157 | }; | 148 | }; |
158 | #endif | 149 | #endif |