summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CExpander.cpp
blob: 1158a7a2c24fbda425785a44461110efeabe54c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "CExpander.h"
#ifdef USEQPE
#include <qpe/global.h>
#endif

size_t CExpander::getHome() { return m_homepos; }

CExpander::CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {};

CExpander::~CExpander() { if (fname != NULL) delete [] fname; };

int CExpander::openfile(const char *src)
{
  bSuspended = false;
  fname = strdup(src);
  return OpenFile(src);
}

void CExpander::getch(tchar& ch, CStyle& sty, unsigned long& pos)
{
  pos = locate();
  int ich = getch();
  ch = (ich == EOF) ? UEOF : ich;
  //	    sty.unset();
}

linkType CExpander::hyperlink(unsigned int n, unsigned int, QString& wrd, QString& nm)
{
  locate(n);
  return eLink;
}

unsigned long CExpander::startSection()
{
  unsigned long current = locate();
  if (m_currentstart > current || current > m_currentend)
    {
      start2endSection();
    }
  return m_currentstart;
}

unsigned long CExpander::endSection()
{
  unsigned long current = locate();
  if (m_currentstart > current || current > m_currentend)
    {
      start2endSection();
    }
  return m_currentend;
}

void CExpander::start2endSection()
{
  m_currentstart = 0;
  unsigned long file;
  sizes(file, m_currentend);
}

#ifdef USEQPE
void CExpander::suspend(FILE*& fin)
{
  bSuspended = true;
  suspos = ftell(fin);
  fclose(fin);
  fin = NULL;
  sustime = time(NULL);
}

void CExpander::unsuspend(FILE*& fin)
{
  if (bSuspended)
    {
      bSuspended = false;
      int delay = time(NULL) - sustime;
      if (delay < 10)
	{
	  Global::statusMessage("Stalling");
	  sleep(10-delay);
	}
      fin = fopen(fname, "rb");
      for (int i = 0; fin == NULL && i < 5; i++)
	{
	  Global::statusMessage("Stalling");
	  sleep(5);
	  fin = fopen(fname, "rb");
	}
      if (fin == NULL)
	{
	  QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
	  exit(0);
	}
      suspos = fseek(fin, suspos, SEEK_SET);
    }
}
#endif

void CExpander::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
{
  len = srclen;
  data = new unsigned char[len];
  memcpy(data, src, len);
}

void CExpander::putSaveData(unsigned char*& src, unsigned short& srclen)
{
  if (srclen != 0)
    {
      qDebug("Don't know what to do with non-zero save data");
    }
}