Diffstat (limited to 'noncore/apps/opie-reader/CExpander.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CExpander.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/CExpander.cpp b/noncore/apps/opie-reader/CExpander.cpp new file mode 100644 index 0000000..e398d86 --- a/dev/null +++ b/noncore/apps/opie-reader/CExpander.cpp | |||
@@ -0,0 +1,103 @@ | |||
1 | #include "CExpander.h" | ||
2 | |||
3 | size_t CExpander::getHome() { return m_homepos; } | ||
4 | |||
5 | CExpander::CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {}; | ||
6 | |||
7 | CExpander::~CExpander() { if (fname != NULL) delete [] fname; }; | ||
8 | |||
9 | int CExpander::openfile(const char *src) | ||
10 | { | ||
11 | bSuspended = false; | ||
12 | fname = strdup(src); | ||
13 | return OpenFile(src); | ||
14 | } | ||
15 | |||
16 | void CExpander::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
17 | { | ||
18 | pos = locate(); | ||
19 | int ich = getch(); | ||
20 | ch = (ich == EOF) ? UEOF : ich; | ||
21 | // sty.unset(); | ||
22 | } | ||
23 | |||
24 | linkType CExpander::hyperlink(unsigned int n, unsigned int, QString& wrd, QString& nm) | ||
25 | { | ||
26 | locate(n); | ||
27 | return eLink; | ||
28 | } | ||
29 | |||
30 | unsigned long CExpander::startSection() | ||
31 | { | ||
32 | unsigned long current = locate(); | ||
33 | if (m_currentstart > current || current > m_currentend) | ||
34 | { | ||
35 | start2endSection(); | ||
36 | } | ||
37 | return m_currentstart; | ||
38 | } | ||
39 | |||
40 | unsigned long CExpander::endSection() | ||
41 | { | ||
42 | unsigned long current = locate(); | ||
43 | if (m_currentstart > current || current > m_currentend) | ||
44 | { | ||
45 | start2endSection(); | ||
46 | } | ||
47 | return m_currentend; | ||
48 | } | ||
49 | |||
50 | void CExpander::start2endSection() | ||
51 | { | ||
52 | m_currentstart = 0; | ||
53 | unsigned long file; | ||
54 | sizes(file, m_currentend); | ||
55 | } | ||
56 | |||
57 | #ifdef USEQPE | ||
58 | void CExpander::suspend(FILE*& fin) | ||
59 | { | ||
60 | bSuspended = true; | ||
61 | suspos = ftell(fin); | ||
62 | fclose(fin); | ||
63 | fin = NULL; | ||
64 | sustime = time(NULL); | ||
65 | } | ||
66 | |||
67 | void CExpander::unsuspend(FILE*& fin) | ||
68 | { | ||
69 | if (bSuspended) | ||
70 | { | ||
71 | bSuspended = false; | ||
72 | int delay = time(NULL) - sustime; | ||
73 | if (delay < 10) sleep(10-delay); | ||
74 | fin = fopen(fname, "rb"); | ||
75 | for (int i = 0; fin == NULL && i < 5; i++) | ||
76 | { | ||
77 | sleep(5); | ||
78 | fin = fopen(fname, "rb"); | ||
79 | } | ||
80 | if (fin == NULL) | ||
81 | { | ||
82 | QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); | ||
83 | exit(0); | ||
84 | } | ||
85 | suspos = fseek(fin, suspos, SEEK_SET); | ||
86 | } | ||
87 | } | ||
88 | #endif | ||
89 | |||
90 | void CExpander::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | ||
91 | { | ||
92 | len = srclen; | ||
93 | data = new unsigned char[len]; | ||
94 | memcpy(data, src, len); | ||
95 | } | ||
96 | |||
97 | void CExpander::putSaveData(unsigned char*& src, unsigned short& srclen) | ||
98 | { | ||
99 | if (srclen != 0) | ||
100 | { | ||
101 | qDebug("Don't know what to do with non-zero save data"); | ||
102 | } | ||
103 | } | ||