Diffstat (limited to 'noncore/apps/opie-reader/ZText.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/ZText.h | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h index debfe8c..22d3733 100644 --- a/noncore/apps/opie-reader/ZText.h +++ b/noncore/apps/opie-reader/ZText.h | |||
@@ -1,39 +1,68 @@ | |||
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/zlib.h" |
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | 6 | ||
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() | ||
14 | { | ||
15 | bSuspended = true; | ||
16 | suspos = gztell(file); | ||
17 | gzclose(file); | ||
18 | file = NULL; | ||
19 | sustime = time(NULL); | ||
20 | } | ||
21 | virtual void unsuspend() | ||
22 | { | ||
23 | if (bSuspended) | ||
24 | { | ||
25 | bSuspended = false; | ||
26 | int delay = time(NULL) - sustime; | ||
27 | if (delay < 10) sleep(10-delay); | ||
28 | file = gzopen(fname, "rb"); | ||
29 | for (int i = 0; file == NULL && i < 5; i++) | ||
30 | { | ||
31 | sleep(5); | ||
32 | file = gzopen(fname, "rb"); | ||
33 | } | ||
34 | if (file == NULL) | ||
35 | { | ||
36 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); | ||
37 | exit(0); | ||
38 | } | ||
39 | suspos = gzseek(file, suspos, SEEK_SET); | ||
40 | } | ||
41 | } | ||
13 | Text() : file(NULL) {}; | 42 | Text() : file(NULL) {}; |
14 | virtual ~Text() | 43 | virtual ~Text() |
15 | { | 44 | { |
16 | if (file != NULL) gzclose(file); | 45 | if (file != NULL) gzclose(file); |
17 | } | 46 | } |
18 | virtual int openfile(const char *src) | 47 | virtual int OpenFile(const char *src) |
19 | { | 48 | { |
20 | if (file != NULL) gzclose(file); | 49 | if (file != NULL) gzclose(file); |
21 | struct stat _stat; | 50 | struct stat _stat; |
22 | stat(src,&_stat); | 51 | stat(src,&_stat); |
23 | fsize = _stat.st_size; | 52 | fsize = _stat.st_size; |
24 | return ((file = gzopen(src,"rb")) == NULL); | 53 | return ((file = gzopen(src,"rb")) == NULL); |
25 | } | 54 | } |
26 | virtual int getch() { return gzgetc(file); } | 55 | virtual int getch() { return gzgetc(file); } |
27 | virtual unsigned int locate() { return gztell(file); } | 56 | virtual unsigned int locate() { return gztell(file); } |
28 | virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } | 57 | virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } |
29 | virtual bool hasrandomaccess() { return true; } | 58 | virtual bool hasrandomaccess() { return true; } |
30 | virtual void sizes(unsigned long& _file, unsigned long& _text) | 59 | virtual void sizes(unsigned long& _file, unsigned long& _text) |
31 | { | 60 | { |
32 | _text = _file = fsize; | 61 | _text = _file = fsize; |
33 | } | 62 | } |
34 | virtual MarkupType PreferredMarkup() | 63 | virtual MarkupType PreferredMarkup() |
35 | { | 64 | { |
36 | return cTEXT; | 65 | return cTEXT; |
37 | } | 66 | } |
38 | }; | 67 | }; |
39 | #endif | 68 | #endif |