author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (unidiff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/CExpander.h | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/CExpander.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CExpander.h | 193 |
1 files changed, 92 insertions, 101 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 | |||
@@ -2,4 +2,11 @@ | |||
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" |
@@ -9,19 +16,7 @@ | |||
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> |
@@ -31,9 +26,67 @@ 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; | ||
35 | }; | 42 | }; |
36 | 43 | ||
37 | class CExpander | 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; | ||
88 | }; | ||
89 | |||
90 | class CExpander : public CExpander_Interface | ||
38 | { | 91 | { |
39 | protected: | 92 | protected: |
@@ -51,13 +104,8 @@ class CExpander | |||
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; |
@@ -66,93 +114,36 @@ class CExpander | |||
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); |
114 | { | 132 | virtual void unsuspend(FILE*& fin); |
115 | bSuspended = true; | ||
116 | suspos = ftell(fin); | ||
117 | fclose(fin); | ||
118 | fin = NULL; | ||
119 | sustime = time(NULL); | ||
120 | } | ||
121 | virtual void unsuspend(FILE*& fin) | ||
122 | { | ||
123 | if (bSuspended) | ||
124 | { | ||
125 | bSuspended = false; | ||
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 | } | ||
141 | } | ||
142 | #endif | 133 | #endif |
143 | virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | 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) | ||
144 | { | 137 | { |
145 | len = srclen; | 138 | m_scrWidth = w; |
146 | data = new unsigned char[len]; | ||
147 | memcpy(data, src, len); | ||
148 | } | 139 | } |
149 | virtual void putSaveData(unsigned char*& src, unsigned short& srclen) | 140 | int getwidth() |
150 | { | 141 | { |
151 | if (srclen != 0) | 142 | return m_scrWidth; |
152 | { | ||
153 | odebug << "Don't know what to do with non-zero save data" << oendl; | ||
154 | } | ||
155 | } | 143 | } |
156 | void setwidth(int w) { m_scrWidth = w; } | 144 | // bool findstring(const QString& info); |
145 | // int getpara(CBuffer& buff); | ||
146 | virtual QImage* getPicture(const QString& href) { return NULL; } | ||
147 | virtual bool getFile(const QString& href) { return false; } | ||
157 | }; | 148 | }; |
158 | #endif | 149 | #endif |