Diffstat (limited to 'noncore/apps/opie-reader/CExpander.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CExpander.h | 87 |
1 files changed, 84 insertions, 3 deletions
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h index b1147a6..c281398 100644 --- a/noncore/apps/opie-reader/CExpander.h +++ b/noncore/apps/opie-reader/CExpander.h | |||
@@ -1,43 +1,124 @@ | |||
1 | #ifndef __CExpander_h | 1 | #ifndef __CExpander_h |
2 | #define __CExpander_h | 2 | #define __CExpander_h |
3 | 3 | ||
4 | #include <unistd.h> | ||
5 | #include <stdio.h> | ||
6 | #include <time.h> | ||
7 | #include <qmessagebox.h> | ||
4 | #include "config.h" | 8 | #include "config.h" |
5 | #include "StyleConsts.h" | 9 | #include "StyleConsts.h" |
6 | #include "Markups.h" | 10 | #include "Markups.h" |
11 | #include "name.h" | ||
7 | 12 | ||
13 | class QPixmap; | ||
8 | class Bkmk; | 14 | class Bkmk; |
9 | 15 | ||
10 | template<class T> | 16 | template<class T> |
11 | class CList; | 17 | class CList; |
12 | 18 | ||
13 | class CCharacterSource | 19 | class CCharacterSource |
14 | { | 20 | { |
15 | public: | 21 | public: |
16 | virtual void getch(tchar&, CStyle&) = 0; | 22 | virtual void getch(tchar&, CStyle&) = 0; |
17 | }; | 23 | }; |
18 | 24 | ||
19 | class CExpander | 25 | class CExpander |
20 | { | 26 | { |
27 | protected: | ||
28 | size_t m_homepos; | ||
29 | bool m_continuous; | ||
30 | char* fname; | ||
31 | bool bSuspended; | ||
32 | size_t suspos; | ||
33 | time_t sustime; | ||
21 | public: | 34 | public: |
22 | CExpander() {}; | 35 | virtual void suspend() = 0; |
23 | virtual ~CExpander() {}; | 36 | virtual void unsuspend() = 0; |
24 | virtual int openfile(const char *src) = 0; | 37 | size_t getHome() { return m_homepos; } |
38 | CExpander() : m_homepos(0), fname(NULL) {}; | ||
39 | virtual ~CExpander() { if (fname != NULL) delete [] fname; }; | ||
40 | int openfile(const char *src) | ||
41 | { | ||
42 | bSuspended = false; | ||
43 | fname = strdup(src); | ||
44 | return OpenFile(src); | ||
45 | } | ||
46 | virtual int OpenFile(const char *src) = 0; | ||
25 | virtual unsigned int locate() = 0; | 47 | virtual unsigned int locate() = 0; |
26 | virtual void locate(unsigned int n) = 0; | 48 | virtual void locate(unsigned int n) = 0; |
27 | virtual bool hasrandomaccess() = 0; | 49 | virtual bool hasrandomaccess() = 0; |
28 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; | 50 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; |
29 | virtual CList<Bkmk>* getbkmklist() { return NULL; } | 51 | virtual CList<Bkmk>* getbkmklist() { return NULL; } |
30 | virtual void getch(int& ch, CStyle& sty) | 52 | virtual void getch(int& ch, CStyle& sty) |
31 | { | 53 | { |
32 | ch = getch(); | 54 | ch = getch(); |
33 | sty.unset(); | 55 | sty.unset(); |
34 | } | 56 | } |
35 | virtual int getch() = 0; | 57 | virtual int getch() = 0; |
36 | virtual bool hyperlink(unsigned int n) | 58 | virtual bool hyperlink(unsigned int n) |
37 | { | 59 | { |
38 | locate(n); | 60 | locate(n); |
39 | return true; | 61 | return true; |
40 | } | 62 | } |
41 | virtual MarkupType PreferredMarkup() = 0; | 63 | virtual MarkupType PreferredMarkup() = 0; |
64 | virtual void saveposn(size_t posn) {} | ||
65 | virtual bool forward(size_t& loc) {} | ||
66 | virtual bool back(size_t& loc) {} | ||
67 | virtual bool hasnavigation() { return false; } | ||
68 | virtual unsigned long startSection() | ||
69 | { | ||
70 | return 0; | ||
71 | } | ||
72 | virtual unsigned long endSection() | ||
73 | { | ||
74 | unsigned long file, text; | ||
75 | sizes(file, text); | ||
76 | return text; | ||
77 | } | ||
78 | virtual QPixmap* getPicture(unsigned long tgt) { return NULL; } | ||
79 | void setContinuous(bool _b) { m_continuous = _b; } | ||
80 | |||
81 | virtual void suspend(FILE*& fin) | ||
82 | { | ||
83 | bSuspended = true; | ||
84 | suspos = ftell(fin); | ||
85 | fclose(fin); | ||
86 | fin = NULL; | ||
87 | sustime = time(NULL); | ||
88 | } | ||
89 | virtual void unsuspend(FILE*& fin) | ||
90 | { | ||
91 | if (bSuspended) | ||
92 | { | ||
93 | bSuspended = false; | ||
94 | int delay = time(NULL) - sustime; | ||
95 | if (delay < 10) sleep(10-delay); | ||
96 | fin = fopen(fname, "rb"); | ||
97 | for (int i = 0; fin == NULL && i < 5; i++) | ||
98 | { | ||
99 | sleep(5); | ||
100 | fin = fopen(fname, "rb"); | ||
101 | } | ||
102 | if (fin == NULL) | ||
103 | { | ||
104 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); | ||
105 | exit(0); | ||
106 | } | ||
107 | suspos = fseek(fin, suspos, SEEK_SET); | ||
108 | } | ||
109 | } | ||
110 | virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | ||
111 | { | ||
112 | len = srclen; | ||
113 | data = new unsigned char[len]; | ||
114 | memcpy(data, src, len); | ||
115 | } | ||
116 | virtual void putSaveData(unsigned char*& src, unsigned short& srclen) | ||
117 | { | ||
118 | if (srclen != 0) | ||
119 | { | ||
120 | qDebug("Don't know what to do with non-zero save data"); | ||
121 | } | ||
122 | } | ||
42 | }; | 123 | }; |
43 | #endif | 124 | #endif |