00001 #include "CExpander.h"
00002 #ifdef USEQPE
00003 #include <qpe/global.h>
00004 #endif
00005
00006 size_t CExpander::getHome() { return m_homepos; }
00007
00008 CExpander::CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {};
00009
00010 CExpander::~CExpander() { if (fname != NULL) delete [] fname; };
00011
00012 int CExpander::openfile(const char *src)
00013 {
00014 bSuspended = false;
00015 fname = strdup(src);
00016 return OpenFile(src);
00017 }
00018
00019 void CExpander::getch(tchar& ch, CStyle& sty, unsigned long& pos)
00020 {
00021 pos = locate();
00022 int ich = getch();
00023 ch = (ich == EOF) ? UEOF : ich;
00024
00025 }
00026
00027 linkType CExpander::hyperlink(unsigned int n, unsigned int, QString& wrd, QString& nm)
00028 {
00029 locate(n);
00030 return eLink;
00031 }
00032
00033 unsigned long CExpander::startSection()
00034 {
00035 unsigned long current = locate();
00036 if (m_currentstart > current || current > m_currentend)
00037 {
00038 start2endSection();
00039 }
00040 return m_currentstart;
00041 }
00042
00043 unsigned long CExpander::endSection()
00044 {
00045 unsigned long current = locate();
00046 if (m_currentstart > current || current > m_currentend)
00047 {
00048 start2endSection();
00049 }
00050 return m_currentend;
00051 }
00052
00053 void CExpander::start2endSection()
00054 {
00055 m_currentstart = 0;
00056 unsigned long file;
00057 sizes(file, m_currentend);
00058 }
00059
00060 #ifdef USEQPE
00061 void CExpander::suspend(FILE*& fin)
00062 {
00063 bSuspended = true;
00064 suspos = ftell(fin);
00065 fclose(fin);
00066 fin = NULL;
00067 sustime = time(NULL);
00068 }
00069
00070 void CExpander::unsuspend(FILE*& fin)
00071 {
00072 if (bSuspended)
00073 {
00074 bSuspended = false;
00075 int delay = time(NULL) - sustime;
00076 if (delay < 10)
00077 {
00078 Global::statusMessage("Stalling");
00079 sleep(10-delay);
00080 }
00081 fin = fopen(fname, "rb");
00082 for (int i = 0; fin == NULL && i < 5; i++)
00083 {
00084 Global::statusMessage("Stalling");
00085 sleep(5);
00086 fin = fopen(fname, "rb");
00087 }
00088 if (fin == NULL)
00089 {
00090 QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
00091 exit(0);
00092 }
00093 suspos = fseek(fin, suspos, SEEK_SET);
00094 }
00095 }
00096 #endif
00097
00098 void CExpander::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
00099 {
00100 len = srclen;
00101 data = new unsigned char[len];
00102 memcpy(data, src, len);
00103 }
00104
00105 void CExpander::putSaveData(unsigned char*& src, unsigned short& srclen)
00106 {
00107 if (srclen != 0)
00108 {
00109 qDebug("Don't know what to do with non-zero save data");
00110 }
00111 }