summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CExpander.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/CExpander.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/CExpander.h87
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
@@ -3,2 +3,6 @@
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"
@@ -6,3 +10,5 @@
6#include "Markups.h" 10#include "Markups.h"
11#include "name.h"
7 12
13class QPixmap;
8class Bkmk; 14class Bkmk;
@@ -20,6 +26,22 @@ 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;
@@ -41,2 +63,61 @@ class CExpander
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};