author | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
commit | 118d03d815a7615b9c53363218a7ac45b3f4c514 (patch) (unidiff) | |
tree | 356953e2413cddcec0f35bd47bb6439767da7051 /noncore/apps/opie-reader/ZText.h | |
parent | 00894537decf01c5a5cdc565b2740b5e67a2e90f (diff) | |
download | opie-118d03d815a7615b9c53363218a7ac45b3f4c514.zip opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.gz opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.bz2 |
Incorporated TimWs current source tree and make it compile
Diffstat (limited to 'noncore/apps/opie-reader/ZText.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/ZText.h | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h index 22d3733..ab81a5e 100644 --- a/noncore/apps/opie-reader/ZText.h +++ b/noncore/apps/opie-reader/ZText.h | |||
@@ -1,68 +1,85 @@ | |||
1 | #ifndef __Text_h | 1 | #ifndef __Text_h |
2 | #define __Text_h | 2 | #define __Text_h |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include "zlib/zlib.h" | 4 | #include <zlib.h> |
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | 6 | #include "useqpe.h" | |
7 | #include "CExpander.h" | 7 | #include "CExpander.h" |
8 | 8 | ||
9 | class Text: public CExpander { | 9 | class Text: public CExpander { |
10 | gzFile file; | 10 | gzFile file; |
11 | unsigned long fsize; | 11 | unsigned long fsize; |
12 | public: | 12 | public: |
13 | virtual void suspend() | 13 | void suspend() |
14 | { | 14 | { |
15 | #ifdef USEQPE | ||
15 | bSuspended = true; | 16 | bSuspended = true; |
16 | suspos = gztell(file); | 17 | suspos = gztell(file); |
17 | gzclose(file); | 18 | gzclose(file); |
18 | file = NULL; | 19 | file = NULL; |
19 | sustime = time(NULL); | 20 | sustime = time(NULL); |
21 | #endif | ||
20 | } | 22 | } |
21 | virtual void unsuspend() | 23 | void unsuspend() |
22 | { | 24 | { |
25 | #ifdef USEQPE | ||
23 | if (bSuspended) | 26 | if (bSuspended) |
24 | { | 27 | { |
25 | bSuspended = false; | 28 | bSuspended = false; |
26 | int delay = time(NULL) - sustime; | 29 | int delay = time(NULL) - sustime; |
27 | if (delay < 10) sleep(10-delay); | 30 | if (delay < 10) sleep(10-delay); |
28 | file = gzopen(fname, "rb"); | 31 | file = gzopen(fname, "rb"); |
29 | for (int i = 0; file == NULL && i < 5; i++) | 32 | for (int i = 0; file == NULL && i < 5; i++) |
30 | { | 33 | { |
31 | sleep(5); | 34 | sleep(5); |
32 | file = gzopen(fname, "rb"); | 35 | file = gzopen(fname, "rb"); |
33 | } | 36 | } |
34 | if (file == NULL) | 37 | if (file == NULL) |
35 | { | 38 | { |
36 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); | 39 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); |
37 | exit(0); | 40 | exit(0); |
38 | } | 41 | } |
39 | suspos = gzseek(file, suspos, SEEK_SET); | 42 | suspos = gzseek(file, suspos, SEEK_SET); |
40 | } | 43 | } |
44 | #endif | ||
41 | } | 45 | } |
42 | Text() : file(NULL) {}; | 46 | Text() : file(NULL) {}; |
43 | virtual ~Text() | 47 | virtual ~Text() |
44 | { | 48 | { |
45 | if (file != NULL) gzclose(file); | 49 | if (file != NULL) gzclose(file); |
46 | } | 50 | } |
47 | virtual int OpenFile(const char *src) | 51 | int OpenFile(const char *src) |
48 | { | 52 | { |
49 | if (file != NULL) gzclose(file); | 53 | if (file != NULL) gzclose(file); |
50 | struct stat _stat; | 54 | struct stat _stat; |
51 | stat(src,&_stat); | 55 | stat(src,&_stat); |
52 | fsize = _stat.st_size; | 56 | fsize = _stat.st_size; |
53 | return ((file = gzopen(src,"rb")) == NULL); | 57 | return ((file = gzopen(src,"rb")) == NULL); |
54 | } | 58 | } |
55 | virtual int getch() { return gzgetc(file); } | 59 | int getch() { return gzgetc(file); } |
56 | virtual unsigned int locate() { return gztell(file); } | 60 | unsigned int locate() { return gztell(file); } |
57 | virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } | 61 | void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } |
58 | virtual bool hasrandomaccess() { return true; } | 62 | bool hasrandomaccess() { return true; } |
59 | virtual void sizes(unsigned long& _file, unsigned long& _text) | 63 | void sizes(unsigned long& _file, unsigned long& _text) |
60 | { | 64 | { |
61 | _text = _file = fsize; | 65 | _text = _file = fsize; |
66 | FILE* f = fopen(fname, "rb"); | ||
67 | if (f != NULL) | ||
68 | { | ||
69 | unsigned char mn[2]; | ||
70 | fread(mn, 1, 2, f); | ||
71 | if ((mn[0] == 31) && (mn[1] == 139)) | ||
72 | { | ||
73 | int tmp = sizeof(_text); | ||
74 | fseek(f,-tmp,SEEK_END); | ||
75 | fread(&_text, sizeof(_text), 1, f); | ||
76 | } | ||
77 | fclose(f); | ||
78 | } | ||
62 | } | 79 | } |
63 | virtual MarkupType PreferredMarkup() | 80 | MarkupType PreferredMarkup() |
64 | { | 81 | { |
65 | return cTEXT; | 82 | return cTEXT; |
66 | } | 83 | } |
67 | }; | 84 | }; |
68 | #endif | 85 | #endif |