44 files changed, 21 insertions, 61 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 7528e78..353996c 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp @@ -1,390 +1,389 @@ #include <stdio.h> #include <string.h> #include "Aportis.h" #include "my_list.h" #include "Bkmks.h" -#include "static.h" Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } void Aportis::dePeanut(int& ch) { if (peanutfile && ch != EOF) { unsigned char c = ch; if (peanutfile) c ^= 0xa5; ch = c; } } CList<Bkmk>* Aportis::getbkmklist() { /* if (peanutfile) { if (nRecs2 > nRecs) { CList<Bkmk>* t = new CList<Bkmk>; for (int i = nRecs; i < nRecs2; i++) { char name[17]; name[16] = '\0'; // qDebug("Record:%d, Length:%u",i,recordlength(i)); gotorecordnumber(i); fread(name,1,16,fin); unsigned long lcn; fread(&lcn,sizeof(lcn),1,fin); lcn ^= 0xa5a5a5a5; lcn = SwapLong(lcn); // qDebug("Bookmark:%s:%u", name,lcn); tchar tname[17]; memset(tname, 0, sizeof(tname)); for (int i = 0; name[i] != 0; i++) { tname[i] = name[i] ^ 0xa5; } t->push_back(Bkmk(tname, NULL, lcn)); } return t; } else { return NULL; } } */ if (bCompressed != 4) return NULL; CList<Bkmk>* t = new CList<Bkmk>; size_t cur = ftell(fin); for (int i = 0; i < nRecs2; i++) { DWORD dwPos; fseek(fin, 0x56 + 8*i, SEEK_SET); fread(&dwPos, 4, 1, fin); dwPos = SwapLong(dwPos); fseek(fin,dwPos,SEEK_SET); unsigned char ch; fread(&ch,1,1,fin); if (ch != 241) { char name[17]; name[16] = '\0'; fseek(fin,dwPos,SEEK_SET); fread(name,1,16,fin); unsigned long lcn; fread(&lcn,sizeof(lcn),1,fin); lcn = SwapLong(lcn); #ifdef _UNICODE tchar tname[17]; memset(tname, 0, sizeof(tname)); for (int i = 0; name[i] != 0; i++) { tname[i] = name[i]; } t->push_back(Bkmk(tname, NULL, lcn)); #else t->push_back(Bkmk(name,lcn)); #endif } } fseek(fin, cur, SEEK_SET); return t; } int Aportis::OpenFile(const char *src) { // printf("In openfile\n"); int ret = 0; html = false; mobiimagerec = 0; if (!Cpdb::openpdbfile(src)) return -1; if (head.creator == 0x64414552 // 'dAER' || head.type == 0x74584554) // 'tXET') { } else if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) { peanutfile = true; } else if (memcmp(&head.creator, "MOBI", 4) == 0 && memcmp(&head.type, "BOOK", 4) == 0) { html = true; unsigned char vsn; fseek(fin, recordpos(0)+39, SEEK_SET); fread(&vsn, 1, sizeof(vsn), fin); qDebug("Mobi version:%x", vsn); if (vsn > 2) { fseek(fin, recordpos(0)+110, SEEK_SET); fread(&mobiimagerec, 1, sizeof(mobiimagerec), fin); mobiimagerec = ntohs(mobiimagerec)-1; } } else { return -2; } nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; struct stat _stat; stat(src,&_stat); dwLen = _stat.st_size; //fseek(fin,0,SEEK_END); //dwLen = ftell(fin); if (peanutfile) { PeanutHeader hdr0; gotorecordnumber(0); fread(&hdr0, sizeof(hdr0), 1, fin); // qDebug("Version:%x", ntohs(hdr0.Version)); if (hdr0.Version && 0x0200) { bCompressed = 2; } else { bCompressed = 1; } BlockSize = 4096; nRecs = SwapWord(hdr0.Records)-1; dwTLen = nRecs*BlockSize; } else { gotorecordnumber(0); tDocRecord0 hdr0; fread(&hdr0, sizeof(hdr0), 1, fin); bCompressed = SwapWord(hdr0.wVersion); if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { qDebug("ERROR:Unrecognised compression type in Aportis:%u", bCompressed); ret = bCompressed; bCompressed = 2; } switch (bCompressed) { case 4: { dwTLen = 0; int i; for (i = 0; i < nRecs; i++) { unsigned int bs = GetBS(i); if (bs == 0) break; else dwTLen += bs; } nRecs = i; BlockSize = 0; } break; case 1: case 2: default: nRecs = SwapWord(hdr0.wNumRecs); if (mobiimagerec == 0 || mobiimagerec > nRecs2) mobiimagerec = nRecs; dwTLen = SwapLong(hdr0.dwStoryLen); BlockSize = SwapWord(hdr0.wRecSize); if (BlockSize == 0) { BlockSize = 4096; printf("WARNING: Blocksize not set in source file\n"); } } } qDebug("Mobi image rec:%u", mobiimagerec); // this is the main record buffer // it knows how to stretch to accomodate the decompress currentrec = 0; cbptr = 0; outptr = 0; refreshbuffer(); if (!html) { int c; char htmltag[] = "<HTML>"; char *p = htmltag; while (1) { c = getch(); char ch = *p++; if (ch == 0) { html = true; break; } if (c != ch) { html = false; break; } } currentrec = 0; cbptr = 0; outptr = 0; refreshbuffer(); } /* for (int i = 0; i < nRecs2; i++) { qDebug("Record:%u - %u bytes at position %x", i, recordlength(i), recordpos(i)); } */ qDebug("Number of records:[%u,%u]", nRecs, nRecs2); return ret; } int Aportis::getch() { if (bCompressed == 1) { if ((dwRecLen == 0) && !refreshbuffer()) return EOF; else { int c = getc(fin); dePeanut(c); dwRecLen--; currentpos++; return c; } } if (outptr != cbptr) { currentpos++; return (circbuf[outptr = (outptr + 1) % 2048]); } if ((dwRecLen == 0) && !refreshbuffer()) return EOF; currentpos++; int c; // take a char from the input buffer c = getc(fin); dePeanut(c); dwRecLen--; // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF // codes 1...8 mean copy that many chars; for accented chars & binary if (c == 0) { circbuf[outptr = cbptr = (cbptr+1)%2048] = c; return c; } else if (c >= 0x09 && c <= 0x7F) { circbuf[outptr = cbptr = (cbptr+1)%2048] = c; return c; } else if (c >= 0x01 && c <= 0x08) { dwRecLen -= c; while(c--) { int c = getc(fin); dePeanut(c); circbuf[cbptr = (cbptr+1)%2048] = c; } return circbuf[outptr = (outptr+1)%2048]; } else if (c >= 0x80 && c <= 0xBF) { int m,n; c <<= 8; int c1 = getc(fin); dePeanut(c1); c += c1; dwRecLen--; m = (c & 0x3FFF) >> COUNT_BITS; n = c & ((1<<COUNT_BITS) - 1); n += 3; while (n--) { cbptr = (cbptr+1)%2048; circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048]; } return circbuf[outptr = (outptr+1)%2048]; } else if (c >= 0xC0 && c <= 0xFF) { circbuf[cbptr = (cbptr+1)%2048] = ' '; circbuf[cbptr = (cbptr+1)%2048] = c^0x80; return circbuf[outptr = (outptr+1)%2048]; } } unsigned int Aportis::GetBS(unsigned int bn) { DWORD dwPos; WORD fs; fseek(fin, 0x56 + 8*bn, SEEK_SET); fread(&dwPos, 4, 1, fin); dwPos = SwapLong(dwPos); fseek(fin,dwPos,SEEK_SET); // gotorecordnumber(bn+1); unsigned char ch; fread(&ch,1,1,fin); if (ch == 241) { fread(&fs,sizeof(fs),1,fin); fs = SwapWord(fs); } else fs = 0; return fs; } unsigned int Aportis::locate() { if (bCompressed == 4) { size_t cur = ftell(fin); unsigned int clen = 0; for (unsigned int i = 0; i < currentrec-1; i++) { unsigned int bs = GetBS(i); if (bs == 0) break; clen += bs; } fseek(fin,cur,SEEK_SET); return clen+currentpos; } else return (currentrec-1)*BlockSize+currentpos; } void Aportis::locate(unsigned int n) { unsigned int offset; // currentrec = (n >> OFFBITS); switch (bCompressed) { case 4: { DWORD clen = 0; offset = n; unsigned int i; for (i = 0; i < nRecs; i++) { unsigned int bs = GetBS(i); if (bs == 0) break; clen += bs; if (clen > n) break; offset = n - clen; } currentrec = i; } break; case 1: case 2: default: currentrec = n / BlockSize; offset = n % BlockSize; } diff --git a/noncore/apps/opie-reader/AportisCodec/AportisCodec.pro b/noncore/apps/opie-reader/AportisCodec/AportisCodec.pro index 4b61a7a..fcab192 100644 --- a/noncore/apps/opie-reader/AportisCodec/AportisCodec.pro +++ b/noncore/apps/opie-reader/AportisCodec/AportisCodec.pro @@ -1,30 +1,29 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = Aportis.h \ CExpander.h \ - ../OREADERINC/useqpe.h \ config.h \ ustring.h \ StyleConsts.h \ Markups.h \ names.h \ linktype.h \ pdb.h \ my_list.h \ Bkmks.h \ Filedata.h SOURCES = Aportis.cpp INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/codecs TARGET = Aportis LIBS += -lreader_pdb -lreader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include -include ( $(OPIEDIR)/include.pro )
\ No newline at end of file +include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp index 22934f9..1f0a524 100644 --- a/noncore/apps/opie-reader/BuffDoc.cpp +++ b/noncore/apps/opie-reader/BuffDoc.cpp @@ -1,391 +1,389 @@ -#include "static.h" #include "names.h" #define NEWLINEBREAK #define INCREMENTALWIDTH -#include "useqpe.h" #include "usenef.h" #include "BuffDoc.h" #include "config.h" #include "CDrawBuffer.h" #include "ZText.h" #include "ebookcodec.h" #ifdef __STATIC #include "Aportis.h" #include "CHM.h" #include "ppm_expander.h" #include "ztxt.h" #include "plucker.h" #ifdef USENEF #include "nef.h" #include "arrierego.h" #endif #include "iSilo.h" #endif linkType BuffDoc::hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) { linkType bRet = eNone; if (exp != NULL) { bRet = filt->hyperlink(n, noff, wrd, nm); if ((bRet & eLink) != 0) { lastword.empty(); lastsizes[0] = laststartline = n; #ifdef NEWLINEBREAK lastispara = false; #else lastispara = false; #endif lastsizes[0] = laststartline = exp->locate(); } } return bRet; } void BuffDoc::locate(unsigned int n) { // //qDebug("BuffDoc:locating:%u",n); lastword.empty(); lastsizes[0] = laststartline = n; #ifdef NEWLINEBREAK lastispara = false; #else lastispara = false; #endif // tchar linebuf[1024]; if (exp != NULL) filt->locate(n); // //qDebug("BuffDoc:Located"); } static bool isletter(unsigned short c) { if ('a' <= c && c <= 'z') return true; if ('A' <= c && c <= 'Z') return true; // Cyrillic letters if (0x400 <= c && c <= 0x52F) return true; return false; } static bool isvowel(unsigned short c) // Only want lower case vowels { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': // Cyrillic vowels case 0x430: case 0x435: case 0x438: case 0x43E: case 0x443: case 0x44B: case 0x44D: case 0x44E: case 0x44F: case 0x451: case 0x450: case 0x454: case 0x456: case 0x457: case 0x45D: case 0x463: case 0x4AF: case 0x4B1: case 0x4D1: case 0x4D3: case 0x4D5: case 0x4D7: case 0x4E3: case 0x4E5: case 0x4E7: case 0x4E9: case 0x4EB: case 0x4ED: case 0x4EF: case 0x4F1: case 0x4F3: case 0x4F9: return true; default: return ((0xe0 <= c) && (c <= 0xfc) && (c != 0xf1) && (c != 0xf7) && (c != 0xe7)); } } inline bool isconsonant(unsigned short c) { switch( c ) { // Some cyrillic letters are neither vowels, nor consonants, or otherwise // the letters no word can start from. case 0x439: case 0x44A: case 0x44C: case 0x45E: return false; default: return (isletter(c) && !isvowel(c)); } return (isletter(c) && !isvowel(c)); } #ifdef NEWLINEBREAK bool BuffDoc::getline(CDrawBuffer* buff, int wth, unsigned short _lborder, unsigned short _rborder, bool hyphenate, int availht) { bool moreleft = true; bool margindone = false; int isCentred = -1; int w = wth-(_lborder+_rborder); tchar ch = 32; CStyle cs; buff->empty(); if (exp == NULL) { buff->empty(); buff->setEof(); return false; } int len = 0; if (lastword.length() > 0) { if (isCentred < 0) { isCentred = (lastword.firststyle().getJustify() == m_AlignCentre) ? 1 : 0; } *buff = lastword; cs = lastword.laststyle(); w -= buff->leftMargin() + buff->rightMargin(); margindone = true; len = lastword.length(); } else buff->empty(); lastword.empty(); unsigned int slen = buff->width(availht, len); if (lastispara) buff->setstartpara(); int nospaces = 0; while (1) { getch(ch, cs, lastsizes[len]); if (isCentred < 0) { isCentred = (cs.getJustify() == m_AlignCentre) ? 1 : 0; } if (ch == 10 && len == 0 && !lastispara) { getch(ch, cs, lastsizes[len]); buff->setstartpara(); } if (ch == UEOF) { buff->setendpara(cs); if (len == 0) { buff->setEof(); moreleft = false; } laststartline = exp->locate(); break; } if (ch == 10) { buff->setendpara(cs); lastispara = true; laststartline = exp->locate(); break; } if (ch == 6) { buff->setendpara(cs); buff->setBop(); lastispara = true; laststartline = exp->locate(); break; } lastispara = false; buff->addch(ch, cs); if (ch == ' ') { nospaces++; } len++; if (!margindone) { w -= buff->leftMargin() + buff->rightMargin(); margindone = true; } #ifdef INCREMENTALWIDTH if ((slen += buff->charwidth(len-1, cs)) > w) #else if ((slen = buff->width(availht, len)) > w) #endif { if (ch == ' ' || len == 1) { if (ch == ' ') buff->truncate(len-1); laststartline = exp->locate(); break; } else // should do a backward search for spaces, first. { int lastk = len-4; for (int i = len-2; i > 0; i--) { if ( (((*buff)[i] == 0x2014) && isletter((*buff)[i+1])) || ((*buff)[i] == '-') // ((*buff)[i] == '-' && !(((*buff)[i-1] == '-') || ((*buff)[i+1] == '-'))) ) { (*buff)[len] = 0; lastword.setright(*buff, i+1); buff->truncate(i+1); (*buff)[i+1] = '\0'; laststartline = lastsizes[i+1]; // buff->resize(); for (int j = 0; j < lastword.length(); j++) { lastsizes[j] = lastsizes[j+i+1]; } return true; } //if (hyphenate && (m_hyphenthreshold+1)*i < m_hyphenthreshold*len) // We end up with i+1 characters instead of len-1 // Thus we are removing len - 1 - (i + 1) = len-i-2 // The space characters will be stretched to cover // nospaces to nospaces + len - i - 2 // The stretch factor is hence // (nospaces+len-i-2)/nospaces if (hyphenate && !isCentred && ( 100*(nospaces+len-i-2) > (100+m_hyphenthreshold)*nospaces )) { /* if (m_customhyphen) { for (int k = lastk; k >= i && k >= 2; k--) { if ( isletter((*buff)[k+3]) && isletter((*buff)[k+2]) && isvowel((*buff)[k+1]) && isconsonant((*buff)[k]) && isletter((*buff)[k-1]) && isletter((*buff)[k-2]) ) { (*buff)[len] = 0; lastword.setright(*buff, k+1); buff->truncate(k+2); (*buff)[k+1] = '-'; (*buff)[k+2] = '\0'; laststartline = lastsizes[k+1]; buff->resize(); for (int j = 0; j < lastword.length(); j++) { lastsizes[j] = lastsizes[j+k+1]; } return true; } } } else */ { for (int k = lastk; k >= i && k >= 1; k--) { if ( /* ( k < len-3 && k >= 1 && isletter((*buff)[k+3]) && isletter((*buff)[k+2]) && isconsonant((*buff)[k+1]) && ((*buff)[k+1] != 'y') && ((*buff)[k+1] != 'h') && isconsonant((*buff)[k]) && ((*buff)[k] != 'h') && isletter((*buff)[k-1]) ) || */ ( isletter((*buff)[k+3]) && isletter((*buff)[k+2]) && isconsonant((*buff)[k+1]) && ((*buff)[k+1] != 'y') && isletter((*buff)[k]) && ((*buff)[k] != 'h') && isletter((*buff)[k-1]) && // Do not hyphenate when the first part ends with a vowel, // and the second starts with the two consonants. // Examples: "co-nsona-nts" -> "con-sonants", // "hy-phenation" -> "hyp-henation" etc. !( isvowel( (*buff)[k] ) && isconsonant( (*buff)[k+2] ) ) ) ) { (*buff)[len] = 0; lastword.setright(*buff, k+1); buff->truncate(k+2); (*buff)[k+1] = '-'; (*buff)[k+2] = '\0'; laststartline = lastsizes[k+1]; // buff->resize(); for (int j = 0; j < lastword.length(); j++) { lastsizes[j] = lastsizes[j+k+1]; } return true; } } } lastk = i; } if ((*buff)[i] == ' ') { (*buff)[len] = 0; lastword.setright(*buff, i+1); buff->truncate(i); (*buff)[i] = '\0'; laststartline = lastsizes[i+1]; // buff->resize(); for (int j = 0; j < lastword.length(); j++) { lastsizes[j] = lastsizes[j+i+1]; } return true; diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h index a7dd7bf..2b4fb57 100644 --- a/noncore/apps/opie-reader/BuffDoc.h +++ b/noncore/apps/opie-reader/BuffDoc.h @@ -1,144 +1,143 @@ #ifndef __BuffDoc_h #define __BuffDoc_h -#include "useqpe.h" #include "CDrawBuffer.h" #include "CFilter.h" #include "CExpander.h" #include <qfontmetrics.h> #include <qmessagebox.h> class BuffDoc { CDrawBuffer lastword; CSizeBuffer lastsizes, allsizes; size_t laststartline; bool lastispara; CExpander_Interface* exp; CFilterChain* filt; int m_hyphenthreshold; // bool m_customhyphen; public: QString about(); bool findanchor(const QString& nm) { return filt->findanchor(nm); } // void setCustomHyphen(bool _v) { m_customhyphen = _v; } // bool getCustomHyphen() { return m_customhyphen; } void setHyphenThreshold(int _v) { m_hyphenthreshold = _v; } void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { if (exp == NULL) { data = NULL; len = 0; } else { exp->setSaveData(data, len, src, srclen); } } void putSaveData(unsigned char*& src, unsigned short& srclen) { if (exp != NULL) { exp->putSaveData(src, srclen); } } #ifdef USEQPE void suspend() { if (exp != NULL) exp->suspend(); } void unsuspend() { if (exp != NULL) exp->unsuspend(); } #else void suspend() {} void unsuspend() {} #endif ~BuffDoc() { delete filt; delete exp; } BuffDoc() { exp = NULL; filt = NULL; lastword.empty(); // // qDebug("Buffdoc created"); } bool empty() { return (exp == NULL); } void setfilter(CFilterChain* _f) { if (filt != NULL) delete filt; filt = _f; filt->setsource(exp); } CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } bool iseol() { return (lastword[0] == '\0'); } int openfile(QWidget* _parent, const char *src); tchar getch() { tchar ch = UEOF; CStyle sty; if (exp != NULL) { unsigned long dummy; filt->getch(ch, sty, dummy); } return ch; } void getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (exp != NULL) { filt->getch(ch, sty, pos); } else ch = UEOF; } void setwidth(int w) { if (exp != NULL) exp->setwidth(w); } QImage* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); } unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); } unsigned int endSection() { return (exp == NULL) ? 0 : exp->endSection(); } unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); } void setContinuous(bool _b) { if (exp != NULL) exp->setContinuous(_b); } MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); } linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm); size_t getHome() { return ((exp != NULL) ? exp->getHome() : 0); } void locate(unsigned int n); bool getline(CDrawBuffer* buff, int w, unsigned short _lborder, unsigned short _rborder, bool hyphenate, int availht); bool getline(CDrawBuffer* buff, int w, int cw, unsigned short _lborder, unsigned short _rborder, int availht); void sizes(unsigned long& fs, unsigned long& ts) { if (exp != NULL) { exp->sizes(fs,ts); } else { fs = ts = 0; } } int getpara(CBuffer& buff) { tchar ch; int i = 0; while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; buff[i] = '\0'; if (i == 0 && ch == UEOF) i = -1; laststartline = exp->locate(); return i; } void saveposn(const QString& f, size_t posn) { filt->saveposn(f, posn); } void writeposn(const QString& f, size_t posn) { filt->writeposn(f, posn); } linkType forward(QString& f, size_t& loc) { return filt->forward(f, loc); } linkType back(QString& f, size_t& loc) { return filt->back(f, loc); } bool hasnavigation() { return filt->hasnavigation(); } bool getFile(QString href) { return (exp == NULL) ? false : exp->getFile(href); } }; #endif diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp index caccf1b..bfb3027 100644 --- a/noncore/apps/opie-reader/CDrawBuffer.cpp +++ b/noncore/apps/opie-reader/CDrawBuffer.cpp @@ -1,391 +1,390 @@ #include "CDrawBuffer.h" #include "FontControl.h" #include <qfontmetrics.h> #include <qpainter.h> #include <qpixmap.h> #include <qimage.h> -#include "useqpe.h" CDrawBuffer::~CDrawBuffer() { while (!segs.isEmpty()) segs.erase(0); } void CDrawBuffer::setright(CDrawBuffer& rhs, int f) { int i; len = rhs.len; fc = rhs.fc; m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; while (!segs.isEmpty()) { segs.erase(0); } for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); ) { CList<textsegment>::iterator next = iter; iter++; if (iter == rhs.segs.end() || iter->start > f) { int st = next->start-f; if (st < 0) st = 0; CStyle _style = next->style; segs.push_back(textsegment(st,next->style)); } } for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i]; (*this)[i-f] = '\0'; len = i; } CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) { int i; // //qDebug("Trying 2"); len = rhs.len; m_ascent = rhs.m_ascent; m_descent = rhs.m_descent; m_lineSpacing = rhs.m_lineSpacing; m_lineExtraSpacing = rhs.m_lineExtraSpacing; m_showPartial = rhs.m_showPartial; while (!segs.isEmpty()) { segs.erase(0); } for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++) { segs.push_back(*iter); } for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i]; (*this)[i] = '\0'; len = i; // //qDebug("Tried 2"); return *this; } CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) { int i; while (!segs.isEmpty()) { segs.erase(0); } segs.push_back(textsegment(0, CStyle())); for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; (*this)[i] = '\0'; len = i; return *this; } void CDrawBuffer::empty() { m_bSop = false; m_bEop = false; m_bBop = false; len = 0; (*this)[0] = 0; while (!segs.isEmpty()) { segs.erase(0); } segs.push_back(textsegment(0,CStyle())); m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; m_bEof = false; } void CDrawBuffer::setendpara(const CStyle& _style/* = ucFontBase*/) { m_bEop = true; if (len == 0) { segs.first().start = 0; segs.first().style = _style; } } void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) { if (len == 0) { segs.first().start = 0; segs.first().style = _style; } else if (_style != segs.last().style) { segs.push_back(textsegment(len, _style)); } (*this)[len++] = ch; } void CDrawBuffer::truncate(int n) { len = n; (*this)[n] = 0; } int CDrawBuffer::width(int availht, int numchars, bool onscreen, int scwidth, unsigned short _lborder, unsigned short _rborder) { int gzoom = fc->gzoom(); int currentx = 0, end = 0; QString text = (numchars < 0) ? toQString(data()) : toQString(data(), numchars); CList<textsegment>::iterator textstart = segs.begin(); int extraspace = 0; bool just = (onscreen && !m_bEop && textstart->style.getJustify() == m_AlignJustify); int spaces = 0; int spacesofar = 0; int spacenumber = 0; int nonspace = 0; if (just) { for (int i = 0; i < len; i++) { if ((*this)[i] != ' ') { nonspace = i; break; } } #ifdef _WINDOWS for (i = nonspace; i < len; i++) #else for (int i = nonspace; i < len; i++) #endif { if ((*this)[i] == ' ') { spaces++; } } if (spaces == 0) { just = false; } else { extraspace = (scwidth - (_lborder+_rborder) - rightMargin() - leftMargin() - width(availht)); if (extraspace == 0) just = false; } } CList<textsegment>::iterator textend = textstart; do { textend++; end = (textend != segs.end()) ? textend->start : len; if (numchars >= 0 && end > numchars) { end = numchars; } CStyle currentstyle = textstart->style; if (currentstyle.isPicture()) { if (currentstyle.canScale()) { int ht = (gzoom*currentstyle.getPicture()->height())/100; int wt = (gzoom*currentstyle.getPicture()->width())/100; if (ht > availht) { wt = (wt*availht)/ht; } currentx += wt; } else { currentx += currentstyle.getPicture()->width(); } } else { if (currentstyle.isMono() && !fc->hasCourier()) { int cw = (7*fc->getsize(currentstyle))/10; currentx += cw*(end-textstart->start); } else { QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); // f.setUnderline(currentstyle.isUnderline()); QString str = text.mid(textstart->start, end-textstart->start); QFontMetrics fm(f); if (just) { int lastspace = -1; int nsp = 0; int cx = currentx; while ((nsp = str.find(" ", lastspace+1)) >= 0) { if (nsp > nonspace) { spacenumber++; int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar; QString nstr = str.mid(lastspace+1, nsp-lastspace); int lw = fm.width(nstr); cx += lw+nexttoadd; spacesofar += nexttoadd; lastspace = nsp; } else { QString nstr = str.mid(lastspace+1, nsp-lastspace); // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); int lw = fm.width(nstr); cx += lw; lastspace = nsp; } } QString nstr = str.right(str.length()-1-lastspace); cx += fm.width(nstr); currentx = cx; } else { currentx += fm.width(str); } } } textstart = textend; } while (textend != segs.end() && end != numchars && textstart->start < len); return currentx; } int CDrawBuffer::charwidth(int numchars, CStyle& currentstyle) { if (currentstyle.isPicture()) { int gzoom = fc->gzoom(); if (currentstyle.canScale()) { return (gzoom*currentstyle.getPicture()->width())/100; } else { return currentstyle.getPicture()->width(); } } else { if (currentstyle.isMono() && !fc->hasCourier()) { return (7*fc->getsize(currentstyle))/10; } else { QString text = QChar((data())[numchars]); QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); // f.setUnderline(currentstyle.isUnderline()); QFontMetrics fm(f); return fm.width(text); } } return 0; } int CDrawBuffer::charwidth(int numchars) { int gzoom = fc->gzoom(); int end = 0; QString text = QChar((data())[numchars]); CList<textsegment>::iterator textstart = segs.begin(); CList<textsegment>::iterator textend = textstart; do { textend++; end = (textend != segs.end()) ? textend->start : len; if (end <= numchars) { textstart = textend; continue; } if (numchars >= 0 && end > numchars) { end = numchars; } CStyle currentstyle = textstart->style; if (currentstyle.isPicture()) { if (currentstyle.canScale()) { return (gzoom*currentstyle.getPicture()->width())/100; } else { return currentstyle.getPicture()->width(); } } else { if (currentstyle.isMono() && !fc->hasCourier()) { return (7*fc->getsize(currentstyle))/10; } else { QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); // f.setUnderline(currentstyle.isUnderline()); QFontMetrics fm(f); return fm.width(text); } } textstart = textend; } while (textend != segs.end() /* && end != numchars*/ && textstart->start < len); return 0; } int CDrawBuffer::leftMargin() { return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style)+3)/6; } int CDrawBuffer::rightMargin() { return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style)+3)/6; } int CDrawBuffer::offset(int scwidth, unsigned short _lborder, unsigned short _rborder, int availht) { int currentx = _lborder; switch(segs.begin()->style.getJustify()) { case m_AlignRight: { currentx = scwidth - _rborder - rightMargin() - width(availht); } break; case m_AlignCentre: { currentx = ( scwidth - _lborder -_rborder + leftMargin() - rightMargin() - width(availht))/2 + _lborder; } break; case m_AlignJustify: case m_AlignLeft: currentx = _lborder + leftMargin(); break; } return currentx; } void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned short _lborder, unsigned short _rborder, const QColor& _bg, int availht) { CList<textsegment>::iterator textstart = segs.begin(); QColor paperColour = QColor(qRgb(textstart->style.pRed(), textstart->style.pGreen(), textstart->style.pBlue())); Highlight(_p, !(paperColour == _bg), _lborder, _y, scwidth-(_lborder+_rborder), paperColour); // Highlight(_p, true, _lborder, _y, scwidth-(_lborder+_rborder), paperColour); int gzoom = fc->gzoom(); int currentx = offset(scwidth, _lborder, _rborder, availht); if (!m_hastext) { for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++) { CStyle currentstyle = iter->style; if (currentstyle.isPicture()) { diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h index e9aaf79..7fa84f9 100644 --- a/noncore/apps/opie-reader/CExpander.h +++ b/noncore/apps/opie-reader/CExpander.h @@ -1,149 +1,148 @@ #ifndef __CExpander_h #define __CExpander_h #ifndef _WINDOWS #include <unistd.h> #endif #include <stdio.h> #include <time.h> #include <sys/stat.h> #include <qmessagebox.h> -#include "useqpe.h" #include "config.h" #include "StyleConsts.h" #include "Markups.h" #include "names.h" #include "linktype.h" class QImage; class Bkmk; class QString; template<class T> class CList; class CCharacterSource { public: virtual void getch(tchar&, CStyle&, unsigned long&) = 0; virtual linkType hyperlink(unsigned int n, unsigned int noff, QString&, QString& nm) = 0; virtual void locate(unsigned int n) = 0; virtual bool findanchor(const QString& nm) = 0; virtual void saveposn(const QString& f, size_t posn) = 0; virtual void writeposn(const QString& f, size_t posn) = 0; virtual linkType forward(QString& f, size_t& loc) = 0; virtual linkType back(QString& f, size_t& loc) = 0; virtual bool hasnavigation() = 0; virtual int getwidth() = 0; virtual QImage* getPicture(unsigned long) = 0; virtual QImage* getPicture(const QString& href) = 0; virtual bool getFile(const QString& href) = 0; virtual QString about() = 0; }; class CExpander_Interface { public: #ifdef USEQPE virtual void suspend() = 0; virtual void unsuspend() = 0; #endif virtual QString about() = 0; virtual size_t getHome() = 0; //CExpander_Interface(); //virtual ~CExpander_Interface(); virtual int openfile(const char *src) = 0; //virtual int OpenFile(const char *src) = 0; virtual unsigned int locate() = 0; virtual void locate(unsigned int n) = 0; virtual bool hasrandomaccess() = 0; virtual void sizes(unsigned long& file, unsigned long& text) = 0; virtual CList<Bkmk>* getbkmklist() { return NULL; } virtual void getch(tchar& ch, CStyle& sty, unsigned long& pos) = 0; virtual int getch() = 0; virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) = 0; virtual MarkupType PreferredMarkup() = 0; virtual void saveposn(size_t posn) {} virtual void writeposn(size_t posn) {} virtual linkType forward(size_t& loc) { return eNone; } virtual linkType back(size_t& loc) { return eNone; } virtual bool hasnavigation() { return false; } virtual unsigned long startSection() = 0; virtual unsigned long endSection() = 0; virtual void start2endSection() = 0; virtual QImage* getPicture(unsigned long tgt) { return NULL; } virtual void setContinuous(bool _b) = 0; #ifdef USEQPE virtual void suspend(FILE*& fin) = 0; virtual void unsuspend(FILE*& fin) = 0; #endif virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) = 0; virtual void putSaveData(unsigned char*& src, unsigned short& srclen) = 0; virtual void setwidth(int w) = 0; // bool findstring(const QString& info); // int getpara(CBuffer& buff); virtual int getwidth() = 0; virtual QImage* getPicture(const QString& href) = 0; virtual bool getFile(const QString& href) = 0; }; class CExpander : public CExpander_Interface { protected: size_t m_homepos; bool m_continuous; char* fname; bool bSuspended; size_t suspos; time_t sustime; int m_scrWidth; unsigned long m_currentstart, m_currentend; public: #ifdef USEQPE virtual void suspend() = 0; virtual void unsuspend() = 0; #endif size_t getHome(); CExpander(); virtual ~CExpander(); int openfile(const char *src); virtual int OpenFile(const char *src) = 0; virtual unsigned int locate() = 0; virtual void locate(unsigned int n) = 0; virtual bool hasrandomaccess() = 0; virtual void sizes(unsigned long& file, unsigned long& text) = 0; virtual CList<Bkmk>* getbkmklist() { return NULL; } virtual void getch(tchar& ch, CStyle& sty, unsigned long& pos); virtual int getch() = 0; virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm); virtual MarkupType PreferredMarkup() = 0; virtual void saveposn(size_t posn) {} virtual void writeposn(size_t posn) {} virtual linkType forward(size_t& loc) { return eNone; } virtual linkType back(size_t& loc) { return eNone; } virtual bool hasnavigation() { return false; } unsigned long startSection(); unsigned long endSection(); virtual void start2endSection(); virtual QImage* getPicture(unsigned long tgt) { return NULL; } void setContinuous(bool _b) { m_continuous = _b; } #ifdef USEQPE virtual void suspend(FILE*& fin); virtual void unsuspend(FILE*& fin); #endif virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen); virtual void putSaveData(unsigned char*& src, unsigned short& srclen); void setwidth(int w) { m_scrWidth = w; } int getwidth() { return m_scrWidth; } // bool findstring(const QString& info); // int getpara(CBuffer& buff); virtual QImage* getPicture(const QString& href) { return NULL; } virtual bool getFile(const QString& href) { return false; } }; #endif diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp index 6f76e9a..6d94d70 100644 --- a/noncore/apps/opie-reader/CFilter.cpp +++ b/noncore/apps/opie-reader/CFilter.cpp @@ -1,389 +1,388 @@ #include <qmap.h> #include <qfileinfo.h> #include <qtextstream.h> #include <qdir.h> -#include "useqpe.h" #ifdef USEQPE #include <qpe/global.h> #endif #include "CDrawBuffer.h" #include "CFilter.h" #include "hrule.h" #include "util.h" #include <qregexp.h> #include <qimage.h> #include <qpixmap.h> //#include <qprogressdialog.h> //#include <qapplication.h> void textfmt::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) { if (uselast) { ch = lastchar; uselast = false; } else { parent->getch(ch, sty, pos); } } void textfmt::getch(tchar& ch, CStyle& sty, unsigned long& pos) { mygetch(ch, sty, pos); do { sty = currentstyle; switch (ch) { case 10: currentstyle.unset(); sty = currentstyle; break; // Use this if you want to replace -- by em-dash case '-': // parent->getch(ch, sty); mygetch(ch, sty, pos); if (ch == '-') { ch = 0x2014; } else { lastchar = ch; uselast = true; ch = '-'; } break; case '*': if (currentstyle.isBold()) { // Already bold - time to turn it off? // The next two lines ensure that * follows a character but it works better without // QChar c(lastchar); // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber())) if (lastchar != '*') { currentstyle.unsetBold(); CStyle dummy; // parent->getch(ch, dummy); mygetch(ch, dummy, pos); } } else { // not bold - time to turn it on? CStyle dummy; // parent->getch(ch, dummy); mygetch(ch, dummy, pos); QChar c(ch); if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber())) { currentstyle.setBold(); } else { lastchar = ch; uselast = true; ch = '*'; } } break; case '_': if (currentstyle.isItalic()) { // Already bold - time to turn it off? // The next two lines ensure that * follows a character but it works better without // QChar c(lastchar); // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber())) if (lastchar != '_') { currentstyle.unsetItalic(); CStyle dummy; // parent->getch(ch, dummy); mygetch(ch, dummy, pos); } } else { // not bold - time to turn it on? CStyle dummy; // parent->getch(ch, dummy); mygetch(ch, dummy, pos); QChar c(ch); if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber())) { currentstyle.setItalic(); } else { lastchar = ch; uselast = true; ch = '_'; } } break; } } while (sty != currentstyle); if (!uselast) lastchar = ch; return; } void remap::getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (q[offset] != 0) { q[offset++]; sty = currentstyle; return; } parent->getch(ch, sty, pos); switch (ch) { case 0x201a: ch = '\''; break; case 0x0192: ch = 'f'; break; case 0x201e: ch = '"'; break; case 0x2026: offset = 0; q[0] = '.'; q[1] = '.'; q[2] = 0; ch = '.'; // should be ... break; case 0x0160: ch = 'S'; break; case 0x2039: ch = '<'; break; case 0x0152: offset = 0; q[0] = 'E'; q[1] = 0; ch = 'O'; break; case 0x017d: ch = 'Z'; break; case 0x2018: ch = '\''; break; case 0x2019: ch = '\''; break; case 0x201c: ch = '"'; break; case 0x201d: ch = '"'; break; case 0x2022: ch = '>'; break; case 0x2013: ch = '-'; break; case 0x2014: offset = 0; q[0] = '-'; q[1] = 0; ch = '-'; // should be -- break; case 0x02dc: ch = '~'; break; case 0x0161: ch = 's'; break; case 0x203a: ch = '>'; break; case 0x0153: offset = 0; q[0] = 'e'; q[1] = 0; ch = 'o';// should be oe break; /* case 0x0009: // tab offset = 0; q[0] = ' '; q[1] = 0; ch = ' '; break; */ case 0x017e: ch = 'z'; break; case 0x0178: ch = 'Y'; break; } currentstyle = sty; } void PeanutFormatter::getch(tchar& ch, CStyle& sty, unsigned long& pos) { CStyle dummy; currentstyle.setColour(0,0,0); parent->getch(ch, dummy, pos); while (ch == '\\') { parent->getch(ch, dummy, pos); if (ch == '\\') break; switch(ch) { case 'a': { int code = 0; for (int i = 0; i < 3; i++) { parent->getch(ch, dummy, pos); code = 10*code + ch - '0'; } ch = code; } break; case 'v': { while (1) { parent->getch(ch, dummy, pos); if (ch == '\\') { parent->getch(ch, dummy, pos); if (ch == 'v') { parent->getch(ch, dummy, pos); break; } } } } break; case 's': case 'n': currentstyle.setFontSize(0); parent->getch(ch,dummy, pos); break; case 'p': currentstyle.unset(); // parent->getch(ch,dummy); ch = 10; break; case 'l': if (currentstyle.getFontSize() == 1) { currentstyle.setFontSize(0); } else { currentstyle.setFontSize(1); } parent->getch(ch, dummy, pos); break; case 'x': if (currentstyle.getFontSize() == 0) { // currentstyle.unset(); // currentstyle.setBold(); currentstyle.setFontSize(1); } else { currentstyle.unset(); } // parent->getch(ch, dummy); ch = 10; break; case 'i': if (currentstyle.isItalic()) { currentstyle.unsetItalic(); } else { currentstyle.setItalic(); } parent->getch(ch, dummy, pos); break; case 'b': case 'B': if (currentstyle.isBold()) { currentstyle.unsetBold(); } else { currentstyle.setBold(); } parent->getch(ch, dummy, pos); break; case 'c': if (currentstyle.getJustify() == m_AlignCentre) { currentstyle.setLeftJustify(); } else { currentstyle.setCentreJustify(); } parent->getch(ch, dummy, pos); break; case 'r': if (currentstyle.getJustify() == m_AlignRight) { currentstyle.setLeftJustify(); } else { currentstyle.setRightJustify(); } parent->getch(ch, dummy, pos); break; default: currentstyle.setColour(255,0,0); } } sty = currentstyle; } void OnePara::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); if (m_lastchar == 10) { while (ch == 10) parent->getch(ch, sty, pos); } m_lastchar = ch; } void repalm::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); switch (ch) { case 0x80: ch = 0x20ac; break; case 0x82: ch = 0x201a; break; case 0x83: ch = 0x0192; break; case 0x84: ch = 0x201e; break; case 0x85: diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h index cec9618..174e6b4 100644 --- a/noncore/apps/opie-reader/CFilter.h +++ b/noncore/apps/opie-reader/CFilter.h @@ -10,466 +10,465 @@ class CFilter_IFace : public CCharacterSource virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm) = 0; virtual void setparent(CCharacterSource* p) = 0; virtual ~CFilter_IFace() {}; virtual void locate(unsigned int n) = 0; virtual bool findanchor(const QString& nm) = 0; virtual void saveposn(const QString& f, size_t posn) = 0; virtual void writeposn(const QString& f, size_t posn) = 0; virtual linkType forward(QString& f, size_t& loc) = 0; virtual linkType back(QString& f, size_t& loc) = 0; virtual bool hasnavigation() = 0; virtual int getwidth() = 0; virtual CCharacterSource* getparent() = 0; }; class CFilter : public CFilter_IFace { protected: CCharacterSource* parent; public: virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm) { return parent->hyperlink(n,noff,w,nm); } CFilter() : parent(NULL) {} void setparent(CCharacterSource* p) { parent = p; } CCharacterSource* getparent() { return parent; } virtual ~CFilter() {}; virtual void locate(unsigned int n) { parent->locate(n); } virtual bool findanchor(const QString& nm) { return parent->findanchor(nm); } virtual void saveposn(const QString& f, size_t posn) { parent->saveposn(f, posn); } virtual void writeposn(const QString& f, size_t posn) { parent->writeposn(f, posn); } virtual linkType forward(QString& f, size_t& loc) { return parent->forward(f, loc); } virtual linkType back(QString& f, size_t& loc) { return parent->back(f, loc); } virtual bool hasnavigation() { return parent->hasnavigation(); } virtual int getwidth() { return parent->getwidth(); } QImage* getPicture(unsigned long tgt) { return parent->getPicture(tgt); } QImage* getPicture(const QString& href) { return parent->getPicture(href); } bool getFile(const QString& href) { return parent->getFile(href); } }; class CFilterChain { CExpander_Interface* expander; CEncoding* encoder; CFilter_IFace* first; CCharacterSource* front; public: CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {}; ~CFilterChain() { CCharacterSource* p = front; while (p != encoder) { CFilter_IFace* pnext = (CFilter_IFace*)p; p = ((CFilter_IFace*)p)->getparent(); delete pnext; } delete encoder; } linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) { return front->hyperlink(n, noff, wrd, nm); } void locate(unsigned int n) { front->locate(n); } void getch(tchar& ch, CStyle& sty, unsigned long& pos) { front->getch(ch, sty, pos); } void addfilter(CFilter_IFace* p) { if (first == NULL) { front = first = p; p->setparent(encoder); } else { p->setparent(front); front = p; } } void setsource(CExpander_Interface* p) { expander = p; encoder->setparent(p); } void setencoder(CEncoding* p) { delete encoder; encoder = p; first->setparent(p); encoder->setparent(expander); } bool findanchor(const QString& nm) { return front->findanchor(nm); } void saveposn(const QString& f, size_t posn) { front->saveposn(f, posn); } void writeposn(const QString& f, size_t posn) { front->writeposn(f, posn); } linkType forward(QString& f, size_t& loc) { return front->forward(f, loc); } linkType back(QString& f, size_t& loc) { return front->back(f, loc); } bool hasnavigation() { return front->hasnavigation(); } QString about() { return QString("Filter chain (c) Tim Wentford\n")+front->about(); } }; class stripcr : public CFilter { public: stripcr() {} ~stripcr() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { do { parent->getch(ch, sty, pos); } while (ch == 13); } QString about() { return QString("StripCR filter (c) Tim Wentford\n")+parent->about(); } }; class dehyphen : public CFilter { bool m_bCharWaiting; tchar m_nextChar; CStyle m_nextSty; public: dehyphen() : m_bCharWaiting(false) {} ~dehyphen() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (m_bCharWaiting) { m_bCharWaiting = false; ch = m_nextChar; sty = m_nextSty; return; } parent->getch(ch, sty, pos); if (ch != '-') return; parent->getch(m_nextChar, m_nextSty, pos); if (m_nextChar != 10) { m_bCharWaiting = true; ch = '-'; return; } parent->getch(ch, sty, pos); } QString about() { return QString("Hyphenation filter (c) Tim Wentford\n")+parent->about(); } }; template<class A, class B>class QMap; const int m_cmaxdepth = 8; class htmlmark { QString file; size_t pos; public: htmlmark() : file(), pos(0) {} htmlmark(const QString& _f, size_t _p) : file(_f), pos(_p) {} QString filename() { return file; } size_t posn() { return pos; } }; class unindent : public CFilter { tchar lc; public: unindent() : lc(0) {} ~unindent() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (lc == 10) { do { parent->getch(ch, sty, pos); } while (ch == ' '); } else parent->getch(ch, sty, pos); lc = ch; return; } QString about() { return QString("Unindent filter (c) Tim Wentford\n")+parent->about(); } }; class CRegExpFilt; class repara : public CFilter { tchar tch; CRegExpFilt* flt; public: repara(const QString&); ~repara(); void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Reparagraph filter (c) Tim Wentford\n")+parent->about(); } }; class indenter : public CFilter { int amnt; int indent; CStyle lsty; public: indenter(int _a=5) : amnt(_a), indent(0) {} ~indenter() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (indent > 0) { indent--; ch = ' '; sty = lsty; return; } parent->getch(ch, sty, pos); if (ch == 10) { indent = amnt; lsty = sty; } return; } QString about() { return QString("Indentation filter (c) Tim Wentford\n")+parent->about(); } }; class dblspce : public CFilter { bool lastlf; CStyle lsty; public: dblspce() : lastlf(false) {} ~dblspce() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (lastlf) { lastlf = false; ch = 10; sty = lsty; return; } parent->getch(ch, sty, pos); if (lastlf = (ch == 10)) { lsty = sty; } return; } QString about() { return QString("Double space (c) Tim Wentford\n")+parent->about(); } }; class textfmt : public CFilter { CStyle currentstyle; tchar lastchar; bool uselast; void mygetch(tchar&, CStyle&, unsigned long& pos); public: textfmt() : lastchar(0), uselast(false) {} ~textfmt() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Text formatting filter (c) Tim Wentford\n")+parent->about(); } }; class embolden : public CFilter { public: embolden() {} ~embolden() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); sty.setBold(); } QString about() { return QString("Emboldening filter (c) Tim Wentford\n")+parent->about(); } }; class remap : public CFilter { tchar q[3]; int offset; CStyle currentstyle; public: remap() : offset(0) { q[0] = 0; } ~remap() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Character remapping filter (c) Tim Wentford\n")+parent->about(); } }; class PeanutFormatter : public CFilter { CStyle currentstyle; public: ~PeanutFormatter() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("PML filter (c) Tim Wentford\n")+parent->about(); } }; class OnePara : public CFilter { tchar m_lastchar; public: OnePara() : m_lastchar(0) {} ~OnePara() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Single space filter (c) Tim Wentford\n")+parent->about(); } }; class DePluck : public CFilter { tchar* nextpart; tchar m_buffer; int m_buffed; int m_current; bool m_debuff; CStyle m_laststyle; public: DePluck(tchar* t) : nextpart(t), m_buffer(0), m_buffed(0), m_current(0), m_debuff(false) {} ~DePluck() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Depluck filter (c) Tim Wentford\n")+parent->about(); } }; class repalm : public CFilter { public: ~repalm() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Repalm filter (c) Tim Wentford\n")+parent->about(); } }; class FullJust : public CFilter { public: void getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); if (sty.getJustify() == m_AlignLeft) sty.setFullJustify(); } QString about() { return QString("Full justification filter (c) Tim Wentford\n")+parent->about(); } }; /* class AddSpace : public CFilter { unsigned char m_espc; public: AddSpace(unsigned char s) : m_espc(s) {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); sty.setExtraSpace(m_espc); } }; */ class QTReader; class HighlightFilter : public CFilter { QTReader* pReader; unsigned long lastpos, nextpos; unsigned char red, green, blue; CList<Bkmk>* bkmks; public: HighlightFilter(QTReader*); void getch(tchar& ch, CStyle& sty, unsigned long& pos); void refresh(unsigned long); QString about() { return QString("High-lighting filter (c) Tim Wentford\n")+parent->about(); } }; -#include "static.h" #ifndef __STATIC #include <dlfcn.h> class ExternFilter : public CFilter_IFace { CFilter* filt; void *handle; public: linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm) { return filt->hyperlink(n, noff, w, nm); } void setparent(CCharacterSource* p) { filt->setparent(p); } ExternFilter(const QString& nm, const QString& optional); ~ExternFilter() { if (filt != NULL) delete filt; if (handle != NULL) dlclose(handle); } void locate(unsigned int n) { filt->locate(n); } bool findanchor(const QString& nm) { return filt->findanchor(nm); } void saveposn(const QString& f, size_t posn) { filt->saveposn(f, posn); } void writeposn(const QString& f, size_t posn) { filt->writeposn(f, posn); } linkType forward(QString& f, size_t& loc) { return filt->forward(f, loc); } linkType back(QString& f, size_t& loc) { return filt->back(f, loc); } bool hasnavigation() { return filt->hasnavigation(); } int getwidth() { return filt->getwidth(); } CCharacterSource* getparent() { return filt->getparent(); } void getch(tchar& c, CStyle& s, unsigned long& l) { filt->getch(c, s, l); } QImage* getPicture(unsigned long tgt) { return filt->getPicture(tgt); } CFilter* filter() { return filt; } QImage* getPicture(const QString& href) { return filt->getPicture(href); } bool getFile(const QString& href) { return filt->getFile(href); } QString about() { return QString("Filter plug-in (c) Tim Wentford\n")+filt->about(); } }; #endif class kern : public CFilter { tchar lastchar; bool uselast; CStyle laststy; public: kern() : lastchar(0), uselast(false) {} ~kern() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Kerning filter (c) Tim Wentford\n")+parent->about(); } }; class makeInverse : public CFilter { public: void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Colourmap inversion filter (c) Tim Wentford\n")+parent->about(); } }; /* class makeNegative : public CFilter { public: void getch(tchar& ch, CStyle& sty, unsigned long& pos); }; */ class setbg : public CFilter { int m_r, m_g, m_b; public: setbg(int _r, int _g, int _b) : m_r(_r), m_g(_g), m_b(_b) {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Background colour filter (c) Tim Wentford\n")+parent->about(); } }; class setfg : public CFilter { int m_r, m_g, m_b; public: setfg(int _r, int _g, int _b) : m_r(_r), m_g(_g), m_b(_b) {} void getch(tchar& ch, CStyle& sty, unsigned long& pos); QString about() { return QString("Foreground colour filter (c) Tim Wentford\n")+parent->about(); } }; #endif diff --git a/noncore/apps/opie-reader/CHM.cpp b/noncore/apps/opie-reader/CHM.cpp index 9d1eb87..88d53bf 100644 --- a/noncore/apps/opie-reader/CHM.cpp +++ b/noncore/apps/opie-reader/CHM.cpp @@ -1,380 +1,379 @@ #include "CHM.h" #include "chm_lib.h" -#include "static.h" #include <qstring.h> #include <qstringlist.h> #include <stdio.h> #include <qimage.h> #include <qpixmap.h> #ifndef __STATIC extern "C" { CExpander* newcodec() { return new CHM; } } #endif static int _print_ui_index(struct chmFile *h, struct chmUnitInfo *ui, void *context) { CHM *chm = (CHM *)context; QString temp = "<tr>"; char buff[1024]; sprintf( buff,"<td align=right>%8d\n</td><td><a href=\"%s\">%s</a></td></tr>",(int)ui->length, ui->path, ui->path); temp += buff; chm->addContent(temp); return CHM_ENUMERATOR_CONTINUE; } static int _get_hhc (struct chmFile *h, struct chmUnitInfo *ui, void *context) { CHM *chm = (CHM *)context; QString PathName = ui->path; if (PathName.find(".hhc") > -1) { chm->setPath(PathName); } return CHM_ENUMERATOR_CONTINUE; } CHM::CHM() { chmFile = NULL; chmPath = ""; chmHHCPath = ""; chmBuffer = ""; bufpos = 0; } CHM::~CHM() { if (chmFile != NULL) chm_close(chmFile); } void CHM::suspend() {
#ifdef USEQPE bSuspended = true; //suspos = gztell(file); chm_close(chmFile); chmFile = NULL; sustime = time(NULL);
#endif } void CHM::unsuspend() {
#ifdef USEQPE if (bSuspended) { bSuspended = false; int delay = time(NULL) - sustime; if (delay < 10)
sleep(10-delay);
chmFile = chm_open(fname); for (int i = 0; chmFile == NULL && i < 5; i++) { sleep(5); chmFile = chm_open(fname); } if (chmFile == NULL) { QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); exit(0); } //suspos = gzseek(file, suspos, SEEK_SET); }
#endif } void CHM::addContent(QString content) { chmBuffer += content; } void CHM::FillHomeContent() { if (chmHHCPath != "") { const char *ext; char buffer[65536]; unsigned int swath, offset; QString tmp=""; QString HTML=""; /* try to find the file */ const char *filename = (const char *)chmHHCPath; if (chm_resolve_object(chmFile, filename, &m_ui) != CHM_RESOLVE_SUCCESS) { chmBuffer = "HELP"; fsize = chmBuffer.length(); return; } m_homestart = m_ui.start; m_homeend = m_homestart + m_ui.length; swath = 65536; offset = 0; fsize = m_ui.length; while (offset < m_ui.length) { if ((m_ui.length - offset) < 65536) swath = m_ui.length - offset; else swath = 65536; swath = (int)chm_retrieve_object(chmFile, &m_ui, (unsigned char *) buffer, offset, swath); tmp += buffer; offset += swath; } HTML +="<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN>\r\n"; HTML +="<HTML>\r\n"; HTML +="<BODY>\r\n"; HTML +="<h2>Home Page</h2>\r\n"; HTML +="<h3>\r\n"; QStringList qsl = QStringList::split("\r\n",tmp); QString NameFind ="<param name=\"Name\" value=\""; QString LocalFind = "<param name=\"Local\" value=\""; QString ULOpenFind = "<UL>"; QString LIOpenFind = "<LI>"; QString ULCloseFind = "</UL>"; QString Name = ""; QString Local = ""; for ( QStringList::Iterator it = qsl.begin(); it != qsl.end(); ++it ) { QString Line = (*it); int NamePos = Line.find( NameFind); int LocalPos = Line.find( LocalFind); if (NamePos > -1) { Name = Line.mid(NamePos+NameFind.length(),Line.length()); Name = Name.left(Name.length() - 2); } if (LocalPos > -1) { Local = Line.mid(LocalPos+LocalFind.length(),Line.length()); Local = Local.left(Local.length() - 2); if (Name != "") { HTML += "<br>\r\n<a href="; HTML += Local; HTML += ">"; HTML += Name; HTML += "</a>\r\n"; Name = ""; } } } HTML +="</h3>"; HTML +="</BODY>\r\n"; HTML +="</HTML>\r\n"; chmHomeBuffer = HTML; chmBuffer = HTML; fsize = chmBuffer.length(); m_currentstart = m_ui.start; m_currentend = m_currentstart+chmBuffer.length(); } } bool CHM::FillBuffer() { bool bRetVal = false; char buffer[65536]; int swath, offset; chmBuffer = ""; swath = 65536; offset = 0; fsize = m_ui.length; while (offset < m_ui.length) { if ((m_ui.length - offset) < 65536) swath = m_ui.length - offset; else swath = 65536; swath = (int)chm_retrieve_object(chmFile, &m_ui, (unsigned char *) buffer, offset, swath); chmBuffer += buffer; offset += swath; } //There seems to be a ton of gobbledygook at the end that is reminiscent of the hhc file - remove it QString temp = chmBuffer.lower(); int lpos = temp.find("</html"); if (lpos > -1) { chmBuffer.truncate(lpos); chmBuffer = chmBuffer+"</HTML>"; } fsize = chmBuffer.length(); bufpos = 0; bRetVal = true; m_currentstart = m_ui.start; m_currentend = m_currentstart+chmBuffer.length(); return bRetVal; } bool CHM::FillContent() { bool bRetVal = false; if (chmPath != "") { /* try to find the file */ const char *filename = (const char *)chmPath; if (chm_resolve_object(chmFile, filename, &m_ui) != CHM_RESOLVE_SUCCESS) { fsize = chmBuffer.length(); return bRetVal; } char buffer[65536]; int swath, offset; chmBuffer = ""; swath = 65536; offset = 0; fsize = m_ui.length; while (offset < m_ui.length) { if ((m_ui.length - offset) < 65536) swath = m_ui.length - offset; else swath = 65536; swath = (int)chm_retrieve_object(chmFile, &m_ui, (unsigned char *) buffer, offset, swath); chmBuffer += buffer; offset += swath; } //There seems to be a ton of gobbledygook at the end that is reminiscent of the hhc file - remove it QString temp = chmBuffer.lower(); int lpos = temp.find("</html"); if (lpos > -1) { chmBuffer.truncate(lpos); chmBuffer = chmBuffer+"</HTML>"; } fsize = chmBuffer.length(); bufpos = 0; m_currentstart = m_ui.start; m_currentend = m_currentstart+chmBuffer.length(); bRetVal = true; } return bRetVal; } bool CHM::getFile(const QString& href) { qDebug("Got:%s", (const char*)href); bool bRetVal = false; QString temp = chmPath; chmPath = href; if (FillContent()) { qDebug("Got it"); bRetVal = true; } else { qDebug("Missed"); chmPath = temp; FillContent(); } return bRetVal; } QImage *CHM::getPicture(const QString& href) { QImage *img = NULL; QString PicRef = "/"+href; struct chmUnitInfo ui; const char *ext; /* try to find the file */ const char *filename = (const char *)PicRef; if (chm_resolve_object(chmFile, filename, &ui) != CHM_RESOLVE_SUCCESS) { qDebug ("Could not resolve image"); return img; } if (ui.length > 0) { char *temp = new char[ui.length]; char buffer[65536]; int swath, offset; swath = 65536; offset = 0; while (offset < ui.length) { if ((ui.length - offset) < 65536) swath = ui.length - offset; else swath = 65536; swath = (int)chm_retrieve_object(chmFile, &ui, (unsigned char *) buffer, offset, swath); memcpy( (void *) (temp + offset), (void *)&buffer, swath ); offset += swath; } QByteArray qba; qba.setRawData( (const char *)temp, ui.length); QPixmap qpm(qba); img = new QImage(qpm.convertToImage()); qba.resetRawData((const char *)temp, ui.length); delete[] temp; } return img; } int CHM::OpenFile(const char *src) { if (chmFile != NULL) chm_close(chmFile); struct stat _stat; stat(src,&_stat); fsize = _stat.st_size; chmFile = chm_open(src); if (chmFile != NULL) { chm_enumerate(chmFile, CHM_ENUMERATE_ALL, _get_hhc, (void *)this); if ( chmPath != "") { setHomePath(chmPath); FillHomeContent(); } } m_homepos = locate(); qDebug("Home:%u", m_homepos); return (chmFile==NULL); } int CHM::getch() { if ( (bufpos+1) >= chmBuffer.length() ) return EOF; #ifdef _WINDOWS
QChar letter = chmBuffer.at(bufpos++);
#else
QChar letter = chmBuffer[bufpos++];
#endif
return (int)(char)letter; } void CHM::getch(tchar& ch, CStyle& sty) { int ich = getch(); ch = (ich == EOF) ? UEOF : ich; } void CHM::start2endSection() { m_currentstart = m_ui.start; m_currentend = m_currentstart+chmBuffer.length(); } unsigned int CHM::locate() { return m_currentstart+bufpos; } void CHM::locate(unsigned int n) { if (n == 0) n = m_homepos; if (n >= m_homestart && n < m_homeend) { FillHomeContent(); bufpos = n - m_homestart; start2endSection(); qDebug("Home:%u:<%u, %u, %u>", m_ui.start, m_currentstart, n, m_currentend); } else if (n >= m_currentstart && n < m_currentend) { bufpos = n - m_currentstart; } else if (CHM_RESOLVE_FAILURE == chm_resolve_location(chmFile, n/4, &m_ui)) { qDebug("Resolve failure"); FillHomeContent(); bufpos = 0; start2endSection(); qDebug("Home:%u:<%u, %u, %u>", m_ui.start, m_currentstart, n, m_currentend); } else { qDebug("Resolve success"); FillBuffer(); start2endSection(); bufpos=n-m_currentstart; qDebug("Not Home:%u:<%u, %u, %u>", m_ui.start, m_currentstart, n, m_currentend); } } void CHM::sizes(unsigned long& _file, unsigned long& _text) { _text = _file = fsize; } diff --git a/noncore/apps/opie-reader/CHM.h b/noncore/apps/opie-reader/CHM.h index 7dac46f..001f7fc 100644 --- a/noncore/apps/opie-reader/CHM.h +++ b/noncore/apps/opie-reader/CHM.h @@ -1,68 +1,67 @@ #ifndef __CHM_h #define __CHM_h #include <stdio.h> #include <sys/stat.h> -#include "useqpe.h" #include "CExpander.h" #include "chm_lib.h" #include "my_list.h" #include "CExpander.h" struct Ref { QString RefName; QString RefLoc; int beginpos; int endpos; }; struct Pic { QString RefName; QString RefLoc; int beginpos; int endpos; }; class CHM : public CExpander { void start2endSection(); struct chmUnitInfo m_ui; struct chmFile *chmFile; chmUnitInfo chmui; //alloc a meg to buffer QString chmHomeBuffer; QString chmBuffer; QString chmPath; QString chmHHCPath; unsigned int bufpos; unsigned long fsize; unsigned long m_homestart, m_homeend; public: void suspend(); void unsuspend(); bool hasnavigation() { return true; } CHM(); virtual ~CHM(); int OpenFile(const char *src); int getch(); unsigned int locate(); void locate(unsigned int n); bool hasrandomaccess() { return true; } void sizes(unsigned long& _file, unsigned long& _text); void addContent(QString content); void getch(tchar& ch, CStyle& sty); void setPath(QString PathName) {chmPath = PathName;}; void setHomePath(QString PathName) {chmHHCPath = PathName;}; MarkupType PreferredMarkup() { return cCHM; } bool getFile(const QString& href); QImage *getPicture(const QString& href); QString about() { return QString("CHM codec (c) Bob Griffin\nchm_lib (c) Jed Wing\nLZX code (c) Stuart Cale"); } private : bool FillBuffer(); bool FillContent(); void FillHomeContent(); }; #endif diff --git a/noncore/apps/opie-reader/CHM/CHM.pro b/noncore/apps/opie-reader/CHM/CHM.pro index 6ed86f6..d3a2a28 100644 --- a/noncore/apps/opie-reader/CHM/CHM.pro +++ b/noncore/apps/opie-reader/CHM/CHM.pro @@ -1,18 +1,18 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = CHM.h chm_lib.h lzx.h SOURCES = CHM.cpp chm_lib.c lzx.c INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/codecs TARGET = CHM LIBS += -lreader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro )
\ No newline at end of file diff --git a/noncore/apps/opie-reader/CloseDialog.h b/noncore/apps/opie-reader/CloseDialog.h index 62e6423..54aaf1c 100644 --- a/noncore/apps/opie-reader/CloseDialog.h +++ b/noncore/apps/opie-reader/CloseDialog.h @@ -1,62 +1,61 @@ /**************************************************************************** ** Form interface generated from reading ui file 'Prefs.ui' ** ** Created: Tue Feb 11 23:53:32 2003 ** by: The User Interface Compiler (uic) ** ** WARNING! All changes made in this file will be lost! ****************************************************************************/ #ifndef __CLOSEDIALOG_H #define __CLOSEDIALOG_H -#include "useqpe.h" #include <qvariant.h> #include <qwidget.h> #include <qtabdialog.h> #include <qtabwidget.h> #include <qspinbox.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlineedit.h> //#include <qpe/menubutton.h> #include <qvbuttongroup.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; //class QCheckBox; class QLabel; //class QSpinBox; class CCloseDialog : public QDialog { Q_OBJECT QCheckBox *file, *marks, *config; #ifndef USEQPE void keyPressEvent(QKeyEvent* e) { switch (e->key()) { case Key_Escape: e->accept(); reject(); break; case Key_Space: case Key_Return: e->accept(); accept(); break; default: QWidget::keyPressEvent(e); } } #endif public: CCloseDialog(const QString&, bool fs = true, QWidget* parent = 0, const char* name = 0); ~CCloseDialog() {} bool delFile() { return file->isChecked(); } bool delMarks() { return marks->isChecked(); } bool delConfig() { return config->isChecked(); } }; #endif // CPREFS_H diff --git a/noncore/apps/opie-reader/FontControl.cpp b/noncore/apps/opie-reader/FontControl.cpp index bbd9fe0..9bb3bc0 100644 --- a/noncore/apps/opie-reader/FontControl.cpp +++ b/noncore/apps/opie-reader/FontControl.cpp @@ -1,67 +1,66 @@ #include <qfontdatabase.h> -#include "useqpe.h" #include "FontControl.h" int FontControl::gzoom() { if (m_fixgraphics) { return 100; } else { int ret; if (m_size == g_size) { ret = m_fontsizes[m_size]*m_basesize; } else if (g_size < 0) { int f = -g_size; ret = (m_fontsizes[0]*m_basesize) >> (f/2); if (f%2) ret = (2*ret/3); } else { int f = g_size - m_maxsize + 1; ret = (m_fontsizes[m_maxsize-1]*m_basesize) << (f/2); if (f%2) ret = (3*ret/2); } return ret; } } bool FontControl::ChangeFont(QString& n, int tgt) { QValueList<int>::Iterator it; QFontDatabase fdb; QValueList<int> sizes = fdb.pointSizes(n); if (sizes.count() == 0) { return false; } else { m_fontname = n; m_maxsize = sizes.count(); if (m_fontsizes != NULL) delete [] m_fontsizes; m_fontsizes = new int[m_maxsize]; uint i = 0; uint best = 0; for (it = sizes.begin(); it != sizes.end(); it++) { #if defined(OPIE) || !defined(USEQPE) m_fontsizes[i] = (*it); #else m_fontsizes[i] = (*it)/10; #endif if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best])) { best = i; } i++; } g_size = m_size = best; } return true; } diff --git a/noncore/apps/opie-reader/HTMLFilter/HTMLFilter.pro b/noncore/apps/opie-reader/HTMLFilter/HTMLFilter.pro index cc049a9..8eb6f17 100644 --- a/noncore/apps/opie-reader/HTMLFilter/HTMLFilter.pro +++ b/noncore/apps/opie-reader/HTMLFilter/HTMLFilter.pro @@ -1,20 +1,20 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = CFilter.h \ util.h SOURCES = striphtml.cpp # copy data file to install directory QMAKE_PRE_LINK = mkdir -p $(OPIEDIR)/plugins/reader/data && cp ../HTMLentities $(OPIEDIR)/plugins/reader/data/HTMLentities INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/filters TARGET = HTMLfilter -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp index c1b7b7a..c6907eb 100644 --- a/noncore/apps/opie-reader/Palm2QImage.cpp +++ b/noncore/apps/opie-reader/Palm2QImage.cpp @@ -1,299 +1,298 @@ /* -*- mode: c; indent-tabs-mode: nil; -*- */ -#include "useqpe.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef _WINDOWS #include <unistd.h> /* for link */ #endif #include <sys/types.h> #include <sys/stat.h> #include <stdarg.h> #include <qimage.h> /***********************************************************************/ /***********************************************************************/ /***** *****/ /***** Code to decode the Palm image format to JPEG *****/ /***** *****/ /***********************************************************************/ /***********************************************************************/ #define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1])) #define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3])) #define PALM_IS_COMPRESSED_FLAG 0x8000 #define PALM_HAS_COLORMAP_FLAG 0x4000 #define PALM_HAS_TRANSPARENCY_FLAG 0x2000 #define PALM_DIRECT_COLOR_FLAG 0x0400 #define PALM_4_BYTE_FIELD_FLAG 0x0200 #define PALM_COMPRESSION_SCANLINE 0x00 #define PALM_COMPRESSION_RLE 0x01 #define PALM_COMPRESSION_PACKBITS 0x02 #define PALM_COMPRESSION_NONE 0xFF #define PALM_COLORMAP_SIZE 232 typedef struct { unsigned char red; unsigned char green; unsigned char blue; } ColorMapEntry; static ColorMapEntry Palm8BitColormap[] = { { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 }, { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 }, { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 }, { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 }, { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 }, { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 }, { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 }, { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 }, { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 }, { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 }, { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 }, { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 }, { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 }, { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 }, { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 }, { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 }, { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 }, { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 }, { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 }, { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 }, { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 }, { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 }, { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 }, { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 }, { 255, 51, 102 }, { 255, 0, 102 }, { 255, 255, 51 }, { 255, 204, 51 }, { 255, 153, 51 }, { 255, 102, 51 }, { 255, 51, 51 }, { 255, 0, 51 }, { 255, 255, 0 }, { 255, 204, 0 }, { 255, 153, 0 }, { 255, 102, 0 }, { 255, 51, 0 }, { 255, 0, 0 }, { 204, 255, 102 }, { 204, 204, 102 }, { 204, 153, 102 }, { 204, 102, 102 }, { 204, 51, 102 }, { 204, 0, 102 }, { 204, 255, 51 }, { 204, 204, 51 }, { 204, 153, 51 }, { 204, 102, 51 }, { 204, 51, 51 }, { 204, 0, 51 }, { 204, 255, 0 }, { 204, 204, 0 }, { 204, 153, 0 }, { 204, 102, 0 }, { 204, 51, 0 }, { 204, 0, 0 }, { 153, 255, 102 }, { 153, 204, 102 }, { 153, 153, 102 }, { 153, 102, 102 }, { 153, 51, 102 }, { 153, 0, 102 }, { 153, 255, 51 }, { 153, 204, 51 }, { 153, 153, 51 }, { 153, 102, 51 }, { 153, 51, 51 }, { 153, 0, 51 }, { 153, 255, 0 }, { 153, 204, 0 }, { 153, 153, 0 }, { 153, 102, 0 }, { 153, 51, 0 }, { 153, 0, 0 }, { 102, 255, 102 }, { 102, 204, 102 }, { 102, 153, 102 }, { 102, 102, 102 }, { 102, 51, 102 }, { 102, 0, 102 }, { 102, 255, 51 }, { 102, 204, 51 }, { 102, 153, 51 }, { 102, 102, 51 }, { 102, 51, 51 }, { 102, 0, 51 }, { 102, 255, 0 }, { 102, 204, 0 }, { 102, 153, 0 }, { 102, 102, 0 }, { 102, 51, 0 }, { 102, 0, 0 }, { 51, 255, 102 }, { 51, 204, 102 }, { 51, 153, 102 }, { 51, 102, 102 }, { 51, 51, 102 }, { 51, 0, 102 }, { 51, 255, 51 }, { 51, 204, 51 }, { 51, 153, 51 }, { 51, 102, 51 }, { 51, 51, 51 }, { 51, 0, 51 }, { 51, 255, 0 }, { 51, 204, 0 }, { 51, 153, 0 }, { 51, 102, 0 }, { 51, 51, 0 }, { 51, 0, 0 }, { 0, 255, 102 }, { 0, 204, 102 }, { 0, 153, 102 }, { 0, 102, 102 }, { 0, 51, 102 }, { 0, 0, 102 }, { 0, 255, 51 }, { 0, 204, 51 }, { 0, 153, 51 }, { 0, 102, 51 }, { 0, 51, 51 }, { 0, 0, 51 }, { 0, 255, 0 }, { 0, 204, 0 }, { 0, 153, 0 }, { 0, 102, 0 }, { 0, 51, 0 }, { 17, 17, 17 }, { 34, 34, 34 }, { 68, 68, 68 }, { 85, 85, 85 }, { 119, 119, 119 }, { 136, 136, 136 }, { 170, 170, 170 }, { 187, 187, 187 }, { 221, 221, 221 }, { 238, 238, 238 }, { 192, 192, 192 }, { 128, 0, 0 }, { 128, 0, 128 }, { 0, 128, 0 }, { 0, 128, 128 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }}; static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }}; static ColorMapEntry Palm2BitColormap[] = { { 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }}; static ColorMapEntry Palm4BitColormap[] = { { 255, 255, 255 }, { 238, 238, 238 }, { 221, 221, 221 }, { 204, 204, 204 }, { 187, 187, 187 }, { 170, 170, 170 }, { 153, 153, 153 }, { 136, 136, 136 }, { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 }, { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }}; QImage* Palm2QImage (unsigned char *image_bytes_in, int byte_count_in) { unsigned int width, height, bytes_per_row, flags, next_depth_offset; unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount; unsigned int palm_red_bits, palm_green_bits, palm_blue_bits; unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow, *imagedatastart, *palmimage; ColorMapEntry *colormap; palmimage = image_bytes_in; width = READ_BIGENDIAN_SHORT(palmimage + 0); height = READ_BIGENDIAN_SHORT(palmimage + 2); bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4); flags = READ_BIGENDIAN_SHORT(palmimage + 6); bits_per_pixel = palmimage[8]; version = palmimage[9]; next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10); transparent_index = palmimage[12]; compression_type = palmimage[13]; /* bytes 14 and 15 are reserved by Palm and always 0 */ #if 0 // qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type); #endif if (compression_type == PALM_COMPRESSION_PACKBITS) { // qDebug ("Image uses packbits compression; not yet supported"); return NULL; } else if ((compression_type != PALM_COMPRESSION_NONE) && (compression_type != PALM_COMPRESSION_RLE) && (compression_type != PALM_COMPRESSION_SCANLINE)) { // qDebug ("Image uses unknown compression, code 0x%x", compression_type); return NULL; } /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: 1, 2, or 4 bit grayscale 8-bit StaticColor using the Palm standard colormap 8-bit PseudoColor using a user-specified colormap 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue Each of these can be compressed with one of four compression schemes, "RLE", "Scanline", "PackBits", or none. We begin by constructing the colormap. */ if (flags & PALM_HAS_COLORMAP_FLAG) { // qDebug("Palm images with custom colormaps are not currently supported.\n"); return NULL; } else if (bits_per_pixel == 1) { colormap = Palm1BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 2) { colormap = Palm2BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 4) { colormap = Palm4BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 8) { colormap = Palm8BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { colormap = NULL; palm_red_bits = palmimage[16]; palm_green_bits = palmimage[17]; palm_blue_bits = palmimage[18]; // qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { // qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n", palm_red_bits, palm_green_bits, palm_blue_bits); return NULL; } if (bits_per_pixel > (8 * sizeof(unsigned long))) { // qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); return NULL; } imagedatastart = palmimage + 24; } else { // qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); return NULL; } #ifndef USEQPE QImage* qimage = new QImage(width, height, 32); #else QImage* qimage = new QImage(width, height, 16); #endif /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ rowbuf = new unsigned char[bytes_per_row * width]; lastrow = new unsigned char[bytes_per_row * width]; for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { // qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row); /* first, uncompress the Palm image */ if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { for (j = 0; j < bytes_per_row; ) { incount = *palm_ptr++; inval = *palm_ptr++; memset(rowbuf + j, inval, incount); j += incount; } } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { for (j = 0; j < bytes_per_row; j += 8) { incount = *palm_ptr++; inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; for (inbit = 0; inbit < inval; inbit += 1) { if (incount & (1 << (7 - inbit))) rowbuf[j + inbit] = *palm_ptr++; else rowbuf[j + inbit] = lastrow[j + inbit]; } } memcpy (lastrow, rowbuf, bytes_per_row); } else if (((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_NONE)) || ((flags & PALM_IS_COMPRESSED_FLAG) == 0)) { memcpy (rowbuf, palm_ptr, bytes_per_row); palm_ptr += bytes_per_row; } else { qDebug("Case 4"); qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true"); qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true"); qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true"); qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true"); qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true"); memcpy (rowbuf, palm_ptr, bytes_per_row); palm_ptr += bytes_per_row; } /* next, write it to the GDK bitmap */ if (colormap) { mask = (1 << bits_per_pixel) - 1; for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) { inval = ((*inbyte) & (mask << inbit)) >> inbit; /* correct for oddity of the 8-bit color Palm pixmap... */ if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; /* now lookup the correct color and set the pixel in the GTK bitmap */ QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); qimage->setPixel(j, i, colour); if (!inbit) { ++inbyte; inbit = 8 - bits_per_pixel; } else { inbit -= bits_per_pixel; } } } else if (!colormap && bits_per_pixel == 16) { for (inbyte = rowbuf, j = 0; j < width; ++j) { inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; /* qDebug ("pixel is %d,%d (%d:%d:%d)", j, i, ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); */ QRgb colour = qRgb( ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); qimage->setPixel(j, i, colour); inbyte += 2; } } } delete [] rowbuf; delete [] lastrow; return qimage; } diff --git a/noncore/apps/opie-reader/PluckerCodec/PluckerCodec.pro b/noncore/apps/opie-reader/PluckerCodec/PluckerCodec.pro index 6ed4032..7042542 100644 --- a/noncore/apps/opie-reader/PluckerCodec/PluckerCodec.pro +++ b/noncore/apps/opie-reader/PluckerCodec/PluckerCodec.pro @@ -1,18 +1,18 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = plucker.h SOURCES = plucker.cpp \ Palm2QImage.cpp INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/codecs TARGET = Plucker LIBS += -lreader_pdb -lreader_pluckerbase -lreader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp index dfdba28..33884a0 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp @@ -1,397 +1,396 @@ /**************************************************************************** ** $Id$ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ const int _SBARHEIGHT = 3; -#include "useqpe.h" #include <qpainter.h> //#include <qdirectpainter_qws.h> #include <qimage.h> #include <qtimer.h> #include "config.h" #include "QTReader.h" //#include "QTReaderApp.h" #include "CDrawBuffer.h" #ifdef USEQPE #include <qpe/qpeapplication.h> #endif #include <math.h> #include <ctype.h> #include <stdio.h> //for sprintf #ifdef USEQPE #include <qpe/config.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/qcopenvelope_qws.h> #endif #include <qfileinfo.h> #include <qdir.h> #ifdef _UNICODE const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; #else const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; #endif //const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; //const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; //const int QTReader::fontsizes[] = {10,16,17,22,0}; //const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; //const int QTReader::fontsizes[] = {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,0}; tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; //tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f), m_default_fg(0,0,0), m_default_bg(255,255,255), m_bg(255,255,255), m_delay(100), m_scrolldy1(0), m_scrolldy2(0), m_totalscroll(0), m_autoScroll(false), //textarray(NULL), //locnarray(NULL), numlines(0), m_fontname("unifont"), m_fm(NULL), mouseUpOn(true), m_twotouch(true), m_touchone(true), bDoUpdates(false), #ifdef _SCROLLPIPE m_pipeout(NULL), #endif m_left_border(2), m_right_border(2), m_rotated(true), pBkmklist(NULL), m_scrollpos(0), // bNegative(false), bInverse(false), m_highlightfilter(NULL), m_bgIsScaled(false), m_scrollstep(2), m_topmargin(5), m_bottommargin(5), m_reparastring("{\\n[\\n ]}"), m_currentlinkstyle(NULL), m_currentlinkoffset(-1), m_currentlink(-1) { m_overlap = 1; setKeyCompression ( true ); #ifdef DOUBLEBUFFER dbuff = new QPixmap(); dbp = new QPainter(); // if (painter->isActive()) painter->end(); // painter->begin(frame); #endif // init(); } /* QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : QWidget(parent, name, f), m_textfont(0), m_textsize(1), textarray(NULL), numlines(0), bstripcr(true), bunindent(false), brepara(false), bdblspce(false), btight(false), bindenter(0), m_fm(NULL) { init(); // // qDebug("Load_file(1)"); load_file((const tchar*)filename); } */ /* void QTReader::mouseMoveEvent(QMouseEvent* _e) { mouseUpOn = !(_e->pos().x() == -1); qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y()); } */ long QTReader::real_delay() { return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); } void QTReader::mousePressEvent( QMouseEvent* _e ) { buffdoc.unsuspend(); int x, y, ht, wh; if (m_rotated) { x = _e->y(); y = width()-_e->x(); ht = width(); wh = height(); } else { x = _e->x(); y = _e->y(); ht = height(); wh = width(); } if (_e->button() == RightButton) { // qDebug("MousePress"); mouseUpOn = false; if (m_swapmouse) { int lineno = 0; /* int hgt = textarray[0]->lineSpacing(); while ((hgt < y) && (lineno < numlines)) { hgt += textarray[++lineno]->lineSpacing(); } */ size_t startpos, startoffset, tgt, tgtoffset, pictgt; QImage* img; getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); processmousewordevent(startpos, startoffset, _e, lineno); } else processmousepositionevent(_e); } } void QTReader::processmousepositionevent( QMouseEvent* _e ) { int x, y, ht, wh; if (m_rotated) { x = _e->y(); y = width()-_e->x(); ht = width(); wh = height(); } else { x = _e->x(); y = _e->y(); ht = height(); wh = width(); } if (buffdoc.hasnavigation()) { if (y > (2*ht)/3) { goDown(); } else if (y < ht/3) { goUp(); } else { if (x < wh/3) { goBack(); } else if (x > (2*wh)/3) { goForward(); } else { goHome(); } } } else { if (y > ht/2) { goDown(); } else { goUp(); } } } void QTReader::goHome() { if (buffdoc.hasnavigation()) { size_t current=pagelocate(); size_t home=buffdoc.getHome(); if (current!=home) { buffdoc.saveposn(m_lastfile, current); locate(home); } } else locate(0); } void QTReader::goBack() { if (buffdoc.hasnavigation()) { size_t target = pagelocate(); QString nxt = m_lastfile; buffdoc.writeposn(m_lastfile, target); linkType lt = buffdoc.back(nxt, target); if ((lt & eFile) != 0) { if (nxt != m_lastfile) { emit NewFileRequest(nxt); } locate(target); } else if ((lt & eLink) != 0) { locate(target); } } } void QTReader::goForward() { if (buffdoc.hasnavigation()) { size_t target = pagelocate(); QString nxt = m_lastfile; linkType lt = buffdoc.forward(nxt, target); if ((lt & eFile) != 0) { if (nxt != m_lastfile) { emit NewFileRequest(nxt); } locate(target); } else if ((lt & eLink) != 0) { locate(target); } } } linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*& img) { int ht; if (m_scrolldy == m_topmargin) { lineno = 0; ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin; } else { if (y >= m_scrolldy) { lineno = 0; ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin; } else { lineno = 0; ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin; while ((ht < h) && (lineno < numlines-1)) { ht += textarray[++lineno]->lineSpacing(); } ht = textarray[lineno]->lineSpacing(); } } while ((ht < y) && (lineno < numlines-1)) { ht += textarray[++lineno]->lineSpacing(); } if (ht < y && textarray[numlines]->showPartial()) lineno = numlines; start = locnarray[lineno]; int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; if (m_bMonoSpaced) { offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth; } else { int i; CDrawBuffer* t = textarray[lineno]; x = x - t->offset(width(), m_left_border, m_right_border, availht); for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--); offset = i; } return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img); } void QTReader::suspend() { buffdoc.suspend(); /*#ifdef OPIE if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); #else if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); #endif */ } void QTReader::setTwoTouch(bool _b) { setBackgroundColor( m_bg ); m_twotouch = m_touchone = _b; } void QTReader::setContinuous(bool _b) { buffdoc.unsuspend(); buffdoc.setContinuous(m_continuousDocument = _b); } void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) { unsigned long wrdstart, wrdend; QString wrd; int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; if (m_twotouch) { if (m_touchone) { m_touchone = false; m_startpos = startpos; m_startoffset = startoffset; setBackgroundColor( lightGray ); } else { m_touchone = true; setBackgroundColor( m_bg ); size_t endpos, endoffset; endpos = startpos; endoffset = startoffset; size_t currentpos = locate(); if (endpos >= m_startpos) { jumpto(m_startpos); for (int i = 0; i < m_startoffset; i++) { getch(); diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h index 7b0ebc8..3bcdde4 100644 --- a/noncore/apps/opie-reader/QTReader.h +++ b/noncore/apps/opie-reader/QTReader.h @@ -1,389 +1,388 @@ #ifndef __QTREADER_H #define __QTREADER_H //#define _SCROLLPIPE -#include "static.h" #include <qwidget.h> //#include <qpainter.h> #include "my_list.h" #include "BuffDoc.h" #include "FontControl.h" //#include <qtimer.h> class CDrawBuffer; //class CBuffer; #include <qpixmap.h> class QPainter; class QTimer; class QImage; #include "BGType.h" #include "striphtml.h" #define ROTATION_ENABLED #define SPECIALSCROLL #define DOUBLEBUFFER #ifdef DOUBLEBUFFER class QPainter; #endif class CStyle; class QTReader : public QWidget { Q_OBJECT friend class QTReaderApp; #ifdef DOUBLEBUFFER QPixmap *dbuff; QPainter* dbp; #endif void drawSingleLine(int lineno); void gotoLink(); void emitRedraw(); CStyle* m_currentlinkstyle; int m_currentlink; int m_currentlinkoffset; QPixmap m_bgpm; bool m_bgIsScaled; bground m_bgtype; int m_scrollpos; unsigned short m_scrollstep; void blitRot(int dx, int sx, int sw, int sh, CDrawBuffer* txt); void setBackgroundBitmap(const QPixmap& _pm, bground bg) { m_bgpm = _pm; m_bgtype = bg; m_bgIsScaled = false; } QColor m_bg, m_default_bg, m_default_fg, m_negative_fg; static tchar pluckernextpart[]; static tchar jplucknextpart[]; CList<Bkmk>* pBkmklist; void setHyphenThreshold(int _v) { buffdoc.setHyphenThreshold(_v); } void ResetScroll(); void increaseScroll(); void reduceScroll(); void drawText(QPainter& p, int x, int y, tchar* text); void DrawScroll( QPainter *p, int w, int h ); void dorollingscroll(bool); void doinplacescroll(); void dostaticscroll(); void suspend(); void redrawScroll(QPainter* p); int m_delay, m_scrolltype; unsigned int m_overlap; bool m_autoScroll, m_swapmouse; void drawBackground(); #ifdef ROTATION_ENABLED bool m_rotated; void setrotated(bool); #endif void autoscroll(); QTimer* timer; int m_scrolldy1, m_scrolldy2, m_encd, m_scrollpart, m_totalscroll; void focusInEvent(QFocusEvent*); void focusOutEvent(QFocusEvent*); void processmousepositionevent( QMouseEvent* _e ); void processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno); bool ChangeFont(int); bool getline(CDrawBuffer*); int m_charWidth; int m_charpc; unsigned short m_absleft_border, m_absright_border; unsigned short m_left_border, m_right_border; FontControl m_fontControl; void setBaseSize(unsigned char _s) { m_fontControl.setBaseSize(_s); } unsigned char getBaseSize() { return m_fontControl.getBaseSize(); } #ifdef _SCROLLPIPE FILE* m_pipeout; QString m_pipetarget; bool m_isPaused; bool m_pauseAfterEachPara; #endif public: QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0); // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); ~QTReader(); QString about(); CList<Bkmk>* Bkmklist() { return pBkmklist; } void setBackground(const QColor& _c) { m_default_bg = _c; reset_bg(); } void setForeground(const QColor& _c) { m_default_fg = _c; int r,g,b; m_default_fg.rgb(&r, &g, &b); r = 255-r; g = 255-g; b = 255-b; m_negative_fg.setRgb(r,g,b); } void zoomin(); void zoomout(); void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { buffdoc.setSaveData(data, len, src, srclen); } void putSaveData(unsigned char*& src, unsigned short& srclen) { buffdoc.putSaveData(src, srclen); } bool empty(); void setContinuous(bool _b); void toggle_autoscroll(); void setautoscroll(bool); void disableAutoscroll() { m_autoScroll = false; } void copy() { /* size_t nd = locate(); jumpto(m_mark); QString text; while (m_mark < nd) { text += buffdoc.getch(); m_mark++; } QApplication::clipboard()->setText(text); jumpto(nd); */ }; void clear() {}; void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); }; /* void setText(bool oldfile) { if (oldfile) { m_string = m_lastfile; load_file((const tchar*)m_string); } else { m_string = QString::null; } }; */ void setlead(int _lead) { m_fontControl.setlead(_lead); } int getlead() { return m_fontControl.getlead(); } void setextraspace(int _lead) { m_fontControl.setextraspace(_lead); } int getextraspace() { return m_fontControl.getextraspace(); } void setpagemode(bool _b) { m_bpagemode = _b; } void setmono(bool _b) { m_bMonoSpaced = _b; ChangeFont(m_fontControl.currentsize()); locate(pagelocate()); } void setencoding(int _f) { m_encd = _f; setfilter(getfilter()); } MarkupType PreferredMarkup(); CEncoding* getencoding() { // qDebug("m_encd:%d", m_encd); switch (m_encd) { case 4: // qDebug("palm"); return new CPalm; case 1: // qDebug("utf8"); return new CUtf8; case 2: // qDebug("ucs16be"); return new CUcs16be; case 3: // qDebug("ucs16le"); return new CUcs16le; case 0: // qDebug("ascii"); return new CAscii; default: return new CGeneral8Bit(m_encd-MAX_ENCODING+1); } } HighlightFilter* m_highlightfilter; CFilterChain* getfilter() { CFilterChain * filt = new CFilterChain(getencoding()); if (bstripcr) filt->addfilter(new stripcr); if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); #ifdef __STATIC if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); if (bautofmt && (PreferredMarkup() == cCHM)) { filt->addfilter(new striphtml(m_lastfile)); } #else if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile)); if (bautofmt && (PreferredMarkup() == cCHM)) { ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile); ((striphtml*)f->filter())->setchm(true); filt->addfilter(f); } #endif m_highlightfilter = new HighlightFilter(this); filt->addfilter(m_highlightfilter); if (bdehyphen) filt->addfilter(new dehyphen); if (bunindent) filt->addfilter(new unindent); if (brepara) filt->addfilter(new repara(m_reparastring)); if (bonespace) filt->addfilter(new OnePara); if (bindenter) filt->addfilter(new indenter(bindenter)); if (bdblspce) filt->addfilter(new dblspce); if (bdepluck) filt->addfilter(new DePluck(pluckernextpart)); if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart)); if (brepalm) filt->addfilter(new repalm); if (bkern) filt->addfilter(new kern); if (bremap) filt->addfilter(new remap); if (bmakebold) filt->addfilter(new embolden); if (bfulljust) filt->addfilter(new FullJust); int r,g,b; m_default_bg.rgb(&r, &g, &b); if (r != 255 || g != 255 || b != 255) filt->addfilter(new setbg(r,g,b)); m_default_fg.rgb(&r, &g, &b); if (r != 0 || g != 0 || b != 0) filt->addfilter(new setfg(r,g,b)); // if (bNegative) filt->addfilter(new makeNegative); if (bInverse) filt->addfilter(new makeInverse); return filt; } private slots: void dopageup(); void lineDown(); void lineUp(); void dopagedn(); void goHome(); void goBack(); void goForward(); void doscroll(); void paintEvent( QPaintEvent * ); #ifdef DOUBLEBUFFER void resizeEvent( QResizeEvent * p ); #endif void keyPressEvent(QKeyEvent*); private: // void drawIt( QPainter * ); void redrawall(); void drawFonts(); void DrawStraight(QPainter* p, int w, int h); QColor m_scrollcolor, m_scrollbarcolor; void setTwoTouch(bool _b); void init(); void mousePressEvent( QMouseEvent* ); void mouseReleaseEvent( QMouseEvent* ); // void mouseDoubleClickEvent( QMouseEvent* ); QString m_string, m_fontname, m_reparastring; void setfont(); //myoutput stuff private: #ifdef SPECIALSCROLL int m_scrolldy; #endif bool mouseUpOn; linkType getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*&); bool m_twotouch, m_touchone; size_t m_startpos, m_startoffset; void dopageup(unsigned int); long real_delay(); int m_textsize; int m_lastwidth, m_lastheight; CBufferFace<CDrawBuffer*> textarray; CBufferFace<size_t> locnarray; unsigned int numlines; // bool m_showlast; bool bstripcr, btextfmt, bstriphtml, bdehyphen, bdepluck, bdejpluck, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace, bfulljust, /*bNegative,*/ bInverse; bool bkern, brepalm; bool m_bpagemode, m_bMonoSpaced, m_continuousDocument; unsigned char bindenter; QString m_lastfile; size_t m_lastposn; bool bDoUpdates; public: void setDoUpdates(bool b) { bDoUpdates = b; } void setStripCR(bool b) { bstripcr = b; } void NavUp(); void NavDown(); tchar getch() { return buffdoc.getch(); } bool synch(size_t, size_t); bool tight; bool load_file(const char *newfile, unsigned int lcn=0); BuffDoc buffdoc; CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } bool locate(unsigned long n); void jumpto(unsigned long n) { buffdoc.locate(n); } unsigned long locate() { return buffdoc.locate(); } unsigned long explocate() { return buffdoc.explocate(); } unsigned long pagelocate() { return locnarray[0]; } unsigned long mylastpos; void getNextLink(); void setfilter(CFilterChain *f) { buffdoc.setfilter(f); if (bDoUpdates) locate(pagelocate()); } void restore() { jumpto(mylastpos); } void goUp(); void refresh(bool full = false); void goDown(); // bool bold; int textsize() { return m_textsize; } void textsize(int ts) { m_textsize = ts; } bool fillbuffer(int ru = 0, int ht = -1, int newht = -1); void CalculateScrollParameters(); unsigned int screenlines(); void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } static const char *fonts[]; // unsigned int *fontsizes; int m_ascent, m_descent, m_linespacing; int m_topmargin, m_bottommargin; int m_abstopmargin, m_absbottommargin; QFontMetrics* m_fm; QString firstword(); bool hyphenate; void reset_bg() { int r,g,b; m_default_bg.rgb(&r, &g, &b); if (bInverse) { r = 255-r; g = 255-g; b = 255-b; } m_bg.setRgb(r,g,b); /* int h,s,v; m_bg.hsv(&h, &s, &v); if (bNegative) { v = 255-v; m_bg.setHsv(h,s,v); } diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp index ec7a29c..876b65a 100644 --- a/noncore/apps/opie-reader/QTReaderApp.cpp +++ b/noncore/apps/opie-reader/QTReaderApp.cpp @@ -1,470 +1,468 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. Allrights reserved. ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include "useqpe.h" #include <qregexp.h> #include <qclipboard.h> #include <qwidgetstack.h> #ifdef USEQPE #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #endif #include <qmenubar.h> #include <qtoolbar.h> #ifdef USEQPE #include <qpe/menubutton.h> #endif #include <qcombobox.h> #include <qpopupmenu.h> #include <qaction.h> #include <qapplication.h> #include <qlineedit.h> #include <qtoolbutton.h> #include <qspinbox.h> #include <qobjectlist.h> #include <qstatusbar.h> #ifdef USEQPE #include <qpe/global.h> #include <qpe/applnk.h> #endif #include <qfileinfo.h> #include <stdlib.h> //getenv #include <qprogressbar.h> #ifdef USEQPE #include <qpe/config.h> #endif #include <qbuttongroup.h> #include <qradiobutton.h> #ifdef USEQPE #include <qpe/qcopenvelope_qws.h> #endif #include "QTReader.h" #include "GraphicWin.h" #include "Bkmks.h" #include "cbkmkselector.h" #include "infowin.h" #include "ToolbarPrefs.h" #include "Prefs.h" #include "CAnnoEdit.h" #include "QFloatBar.h" #include "FixedFont.h" #include "URLDialog.h" #include "util.h" #include <qfontdatabase.h> #ifdef USEQPE #include <qpe/resource.h> #ifdef OPIE //#include <qpe/applnk.h> #include <opie2/ofiledialog.h> using namespace Opie::Ui; #else #include "fileBrowser.h" #endif #else #include "qfiledialog.h" #endif #include "QTReaderApp.h" #include "CDrawBuffer.h" #include "Filedata.h" -#include "useqpe.h" #include "names.h" #include "CEncoding_tables.h" #include "CloseDialog.h" #include "ButtonPrefs.h" bool CheckVersion(int&, int&, char&); #ifdef _WINDOWS #define PICDIR "c:\\uqtreader\\pics\\" #else #ifdef USEQPE #define USEMSGS #define PICDIR "opie-reader/" #else //#define PICDIR "/home/tim/uqtreader/pics/" QString picdir() { QString hd(getenv("READERDIR")); return hd + "/pics"; } #define PICDIR picdir() #endif #endif unsigned long QTReaderApp::m_uid = 0; void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); } #ifdef USEQPE #define geticon(iconname) Resource::loadPixmap( iconname ) #define getmyicon(iconname) Resource::loadPixmap( PICDIR iconname ) #else //#define geticon(iconname) QPixmap(PICDIR iconname ".png") #define geticon(iconname) QPixmap(PICDIR +"/"+iconname+".png") #define getmyicon(iconname) geticon(iconname) //#define geticon(iconname) QIconSet( QPixmap(PICDIR iconname) ) #endif #ifndef _WINDOWS #include <unistd.h> #endif #include <stddef.h> #ifndef _WINDOWS #include <dirent.h> #endif void QTReaderApp::listBkmkFiles() { bkmkselector->clear(); bkmkselector->setText("Cancel"); #ifndef USEQPE int cnt = 0; QDir d = QDir::home(); // "/" if ( !d.cd(APPDIR) ) { // "/tmp" qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); d = QDir::home(); d.mkdir(APPDIR); d.cd(APPDIR); } d.setFilter( QDir::Files | QDir::NoSymLinks ); // d.setSorting( QDir::Size | QDir::Reversed ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); // create list iterator QFileInfo *fi; // pointer for traversing while ( (fi=it.current()) ) { // for each file... bkmkselector->insertItem(fi->fileName()); cnt++; //qDebug( "%10li %s", fi->size(), fi->fileName().data() ); ++it; // goto next list element } #else /* USEQPE */ int cnt = 0; DIR *d; d = opendir((const char *)Global::applicationFileName(APPDIR,"")); while(1) { struct dirent* de; struct stat buf; de = readdir(d); if (de == NULL) break; if (lstat((const char *)Global::applicationFileName(APPDIR,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) { bkmkselector->insertItem(de->d_name); cnt++; } } closedir(d); #endif if (cnt > 0) { //tjw menu->hide(); editorStack->raiseWidget( bkmkselector ); hidetoolbars(); m_nBkmkAction = cRmBkmkFile; } else QMessageBox::information(this, PROGNAME, "No bookmark files"); } void QTReaderApp::hidetoolbars() { if (m_scrollbar != NULL) m_scrollbar->hide(); if (m_prog != NULL) m_prog->hide(); #ifdef USEQPE menubar->hide(); #endif if (m_scrollbar != NULL) m_scrollbar->hide(); if (fileBar != NULL) fileBar->hide(); if (viewBar != NULL) viewBar->hide(); if (navBar != NULL) navBar->hide(); if (markBar != NULL) markBar->hide(); if (m_fontVisible) m_fontBar->hide(); if (regVisible) { #ifdef USEQPE Global::hideInputMethod(); #endif regBar->hide(); } if (searchVisible) { #ifdef USEQPE Global::hideInputMethod(); #endif searchBar->hide(); } } QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), m_dontSave(false), fileBar(NULL), navBar(NULL), viewBar(NULL), markBar(NULL), m_scrollbar(NULL), m_localscroll(2), m_hidebars(false), m_kmapchanged(false) { { setKeyCompression ( true ); #ifndef USEQPE QDir d = QDir::home(); // "/" d.cd(APPDIR); QFileInfo fi(d, ".keymap"); FILE* f = fopen((const char *)fi.absFilePath(), "r"); #else /* USEQPE */ FILE* f = fopen((const char *)Global::applicationFileName(APPDIR,".keymap"), "r"); #endif /* USEQPE */ if (f != NULL) { uint cnt; if ((fread(&cnt, sizeof(cnt), 1, f) != 0) && (cnt == KEYMAPVERSION)) { if (fread(&cnt, sizeof(cnt), 1, f) == 0) cnt = 0; for (uint i = 0; i != cnt; i++) { orKey key; int data; fread(&key, sizeof(key), 1, f); fread(&data, sizeof(data), 1, f); kmap[key] = data; } } fclose(f); } } m_url_clipboard = false; m_url_localfile = false; m_url_globalfile = false; ftime(&m_lastkeytime); //// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); //// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); m_bcloseDisabled = true; m_disableesckey = false; pBkmklist = NULL; pOpenlist = NULL; // doc = 0; m_fBkmksChanged = false; QString lang = getenv( "LANG" ); QString rot = getenv( "QWS_DISPLAY" ); /* int m_rot = 0; if (rot.contains("Rot90")) { m_rot = 90; } else if (rot.contains("Rot180")) { m_rot = 180; } else if (rot.contains("Rot270")) { m_rot = 270; } // qDebug("Initial Rotation(%d):%s", m_rot, (const char*)rot); */ m_autogenstr = "^ *[A-Z].*[a-z] *$"; #ifdef USEQPE setIcon( Resource::loadPixmap( PICDIR "uqtreader") ); #else setIcon( QPixmap (PICDIR + "/uqtreader.png") ); #endif /* USEQPE */ // QPEToolBar *bar = new QPEToolBar( this ); // menubar = new QPEToolBar( this ); #ifdef USEQPE Config config( APPDIR ); #else QDir d = QDir::home(); // "/" if ( !d.cd(APPDIR) ) { // "/tmp" qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); d = QDir::home(); d.mkdir(APPDIR); d.cd(APPDIR); } QFileInfo fi(d, INIFILE); // qDebug("Path:%s", (const char*)fi.absFilePath()); Config config(fi.absFilePath()); #endif config.setGroup("Toolbar"); m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", false); m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", 1); m_tbposition = (ToolBarDock)config.readNumEntry("Position", 2); m_qtscroll = config.readNumEntry("QTScrollBar", false); m_localscroll = config.readNumEntry("LocalScrollBar", false); // fileBar = new QToolBar("File", this); // QToolBar* viewBar = new QToolBar("File", this); // QToolBar* navBar = new QToolBar("File", this); // QToolBar* markBar = new QToolBar("File", this); #ifdef USEQPE menubar = new QToolBar("Menus", this, m_tbposition); mb = new QPEMenuBar( menubar ); #else mb = new QMenuBar( this ); #endif #ifdef USEQPE QPopupMenu* tmp = new QPopupMenu(mb); mb->insertItem( geticon( "AppsIcon" ), tmp ); #else QMenuBar* tmp = mb; #endif QPopupMenu *file = new QPopupMenu( mb ); tmp->insertItem( tr( "File" ), file ); QPopupMenu *navigation = new QPopupMenu(mb); tmp->insertItem( tr( "Navigation" ), navigation ); QPopupMenu *view = new QPopupMenu( mb ); tmp->insertItem( tr( "View" ), view ); QPopupMenu *marks = new QPopupMenu( this ); tmp->insertItem( tr( "Marks" ), marks ); QPopupMenu *settings = new QPopupMenu( this ); tmp->insertItem( tr( "Settings" ), settings ); // addToolBar(menubar, "Menus",QMainWindow::Top); // addToolBar(fileBar, "Toolbar",QMainWindow::Top); // QPopupMenu *edit = new QPopupMenu( this ); /* QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); a->addTo( bar ); a->addTo( file ); */ QWidget* widge = new QWidget(this); setCentralWidget( widge ); QVBoxLayout* vlayout = new QVBoxLayout(widge); m_layout = new QBoxLayout(QBoxLayout::LeftToRight); m_prog = new QLabel(widge); vlayout->addLayout(m_layout, 1); vlayout->addWidget(m_prog); editorStack = new QWidgetStack( widge ); // setCentralWidget( editorStack ); searchVisible = FALSE; regVisible = FALSE; m_fontVisible = false; m_buttonprefs = new CButtonPrefs(&kmap, this); editorStack->addWidget(m_buttonprefs, get_unique_id()); connect( m_buttonprefs, SIGNAL( Closed() ), this, SLOT( infoClose() ) ); m_annoWin = new CAnnoEdit(editorStack); editorStack->addWidget(m_annoWin, get_unique_id()); connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) ); connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) ); m_infoWin = new infowin(editorStack); editorStack->addWidget(m_infoWin, get_unique_id()); connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); m_graphicwin = new GraphicWin(editorStack); editorStack->addWidget(m_graphicwin, get_unique_id()); connect( m_graphicwin, SIGNAL( Closed() ), this, SLOT( infoClose() ) ); // bkmkselector = new QListBox(editorStack, "Bookmarks"); bkmkselector = new CBkmkSelector(editorStack, "Bookmarks"); // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) ); connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) ); connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) ); editorStack->addWidget( bkmkselector, get_unique_id() ); /* importSelector = new FileSelector( "*", editorStack, "importselector", false ); connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) ); editorStack->addWidget( importSelector, get_unique_id() ); // don't need the close visible, it is redundant... importSelector->setCloseVisible( FALSE ); */ // qDebug("Reading file list"); readfilelist(); reader = new QTReader( editorStack ); reader->setDoUpdates(false); #ifdef USEQPE ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold); #endif // qDebug("Reading config"); // Config config( APPDIR ); config.setGroup( "View" ); m_debounce = config.readNumEntry("Debounce", 0); m_buttonprefs->Debounce(m_debounce); #ifdef USEQPE m_bFloatingDialog = config.readBoolEntry("FloatDialogs", false); #else m_bFloatingDialog = config.readBoolEntry("FloatDialogs", true); #endif reader->setStripCR(config.readBoolEntry( "StripCr", true )); reader->bfulljust = config.readBoolEntry( "FullJust", false ); /* bool btmp = config.readBoolEntry("Negative", false); if (btmp) reader->setNegative(); */ reader->bInverse = config.readBoolEntry("Inverse", false); reader->m_fontControl.FixGraphics(config.readBoolEntry( "FixGraphics", false )); reader->setextraspace(config.readNumEntry( "ExtraSpace", 0 )); reader->setlead(config.readNumEntry( "ExtraLead", 0 )); reader->btextfmt = config.readBoolEntry( "TextFmt", false ); reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); reader->bpeanut = config.readBoolEntry( "Peanut", false ); reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); reader->bdepluck = config.readBoolEntry( "Depluck", false ); reader->bdejpluck = config.readBoolEntry( "Dejpluck", false ); reader->bonespace = config.readBoolEntry( "OneSpace", false ); reader->bunindent = config.readBoolEntry( "Unindent", false ); reader->brepara = config.readBoolEntry( "Repara", false ); reader->m_reparastring = config.readEntry( "ReparaString", "\\n{[\\n \\t]}"); m_bgtype = (bground)config.readNumEntry( "BackgroundType" , 0 ); m_themename = config.readEntry("Theme", QString::null ); diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h index 5ecc42d..ad47fc9 100644 --- a/noncore/apps/opie-reader/QTReaderApp.h +++ b/noncore/apps/opie-reader/QTReaderApp.h @@ -1,413 +1,412 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef __QTREADERAPP_H #define __QTREADERAPP_H //#define _SCROLLPIPE //#define __ISEARCH //#define MAX_ENCODING 6 #define MAX_ACTIONS 5 -#include "useqpe.h" #include <sys/timeb.h> #include <qmainwindow.h> #include "CExpander.h" #include "CEncoding.h" #include <qlist.h> //#include <qpe/filemanager.h> #include <qmap.h> #include <qlineedit.h> #include <qstack.h> #include <qlistbox.h> #ifdef USEQPE #include <qpe/qpeapplication.h> #endif #include "orkey.h" //#include "Queue.h" #include "BGType.h" class QBoxLayout; class QWidgetStack; class QToolButton; class QPopupMenu; class QToolBar; #ifdef USEQPE class QPEToolBar; class QPEMenuBar; #endif class QScrollBar; class CBkmkSelector; class QProgressBar; class QAction; class CAnnoEdit; class QFloatBar; class CDrawBuffer; class QTReader; class QImage; class Config; class CButtonPrefs; #ifdef USEQPE enum ToolbarPolicy { cesSingle = 0, cesMenuTool, cesMultiple }; #else enum ToolbarPolicy { cesMenuTool = 0, cesMultiple }; #endif enum regedit_type { cAutoGen, cAddBkmk, cJump, cMonoSpace, cSetTarget, #ifdef _SCROLLPIPE cSetPipeTarget, #endif cSetConfigName, cMargin, cExtraSpace, cExtraLead, cRepara }; enum bkmk_action { cOpenFile, cGotoBkmk, cDelBkmk, cRmBkmkFile, cLdConfig, cRmConfig, cExportLinks, cLdTheme }; enum fontselector_action { cChooseFont, cChooseEncoding }; #ifdef __ISEARCH struct searchrecord { QString s; size_t pos; searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {} }; #endif class infowin; class GraphicWin; class QTReaderApp : public QMainWindow { Q_OBJECT QColor getcolour(int c); QMap<orKey, int> kmap; unsigned long m_savedpos; int m_debounce; bool m_kmapchanged; bground m_bgtype; timeb m_lastkeytime; QScrollBar* m_scrollbar; QScrollBar* scrollbar; int m_qtscroll, m_localscroll; bool m_hidebars, m_scrollishidden, m_statusishidden; QBoxLayout *m_layout; QLabel* m_prog; bool m_annoIsEditing; bool m_propogatefontchange, m_bFloatingDialog; bool m_url_clipboard, m_url_localfile, m_url_globalfile; CButtonPrefs* m_buttonprefs; fontselector_action m_fontAction; void doAction(QKeyEvent* e); public: QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~QTReaderApp(); void hideEvent(QHideEvent*) { #ifdef USEQPE if (m_grabkeyboard) { ((QPEApplication*)qApp)->ungrabKeyboard(); } #endif suspend(); } #ifdef USEQPE void showEvent(QShowEvent*) { if (m_grabkeyboard) { ((QPEApplication*)qApp)->grabKeyboard(); } } #endif void suspend(); void openFile( const QString & ); protected: void setfontHelper(const QString& lcn, int size = 0); QAction* m_bkmkAvail, *m_actFullscreen; CAnnoEdit* m_annoWin; Bkmk* m_anno; int m_scrollcolor, m_scrollbarcolor, m_background, m_foreground; // void resizeEvent(QResizeEvent* e); void closeEvent( QCloseEvent *e ); #ifdef NEWFULLSCREEN void resizeEvent(QResizeEvent *); void focusInEvent(QFocusEvent*); void enableFullscreen(); #endif void readbkmks(); void do_mono(const QString&); void do_jump(const QString&); void do_reparastring(const QString&); void do_settarget(const QString&); #ifdef _SCROLLPIPE // void do_setpipetarget(const QString&); #endif void do_saveconfig(const QString&, bool); bool readconfig(const QString&, const QString&, bool); bool PopulateConfig(const char*, bool usedirs = false); ActionTypes ActNameToInt(const QString&); #ifdef USEQPE bool m_grabkeyboard; #endif bool m_doAnnotation; bool m_doDictionary; bool m_doClipboard; bool m_fullscreen; bool m_loadedconfig; public: void saveprefs(); public slots: void setBackgroundBitmap(); void UpdateStatus(); void setScrollState(bool _b); void handlekey(QKeyEvent* e); void forceopen(const QString& filename); void setDocument(const QString&); private slots: #ifdef _SCRIPT // void RunScript(); #endif void actionscroll(int v); void SaveConfig(); void LoadTheme(); void LoadConfig(); void TidyConfig(); void ExportLinks(); void zoomin(); void zoomout(); void chooseencoding(); void setfullscreen(bool sfs); void setrotated(bool sfs); void setinverted(bool sfs); void setgrab(bool sfs); // void setcontinuous(bool sfs); void setTwoTouch(bool _b); void restoreFocus(); void OnAnnotation(bool _b) { m_doAnnotation = _b; } void OnDictionary(bool _b) { m_doDictionary = _b; } void OnClipboard(bool _b) { m_doClipboard = _b; } void OnWordSelected(const QString&, size_t, size_t, const QString&); void OnURLSelected(const QString& href, const size_t tgt); void showgraphic(QImage&); void addAnno(const QString&, const QString&, size_t, size_t); void addAnno(const QString&, const QString&); void addanno(); void showAnnotation(); void do_setencoding(int i); void do_setfont(const QString&); // void buttonActionSelected(QAction*); void msgHandler(const QCString&, const QByteArray&); void monospace(bool); void jump(); void reparastring(); void settarget(); #ifdef _SCROLLPIPE // void setpipetarget(); // void setpause(bool); #endif // void setspacing(); void setfont(); void clearBkmkList(); void listBkmkFiles(); void editMark(); void autoScroll(bool); void addbkmk(); void savebkmks(); // void importFiles(); void showprefs(); void showtoolbarprefs(); void showbuttonprefs(); void infoClose(); // void oldFile(); void showinfo(); // void indentplus(); // void indentminus(); void fileOpen(); void fileClose(); void editCopy(); void editFind(); void gotoStart(); void gotoEnd(); void pageup(); void pagedn(); void findNext(); void findClose(); void regClose(); #ifdef __ISEARCH // void search( const QString& ); #else void search(); #endif void showEditTools(); // void stripcr(bool); // void setfulljust(bool); // void onespace(bool); // void repalm(bool); // void peanut(bool _b); // void remap(bool); // void embolden(bool); // void autofmt(bool); // void textfmt(bool); // void striphtml(bool); // void dehyphen(bool); // void depluck(bool); // void dejpluck(bool); // void unindent(bool); // void repara(bool); // void dblspce(bool); void pagemode(bool); // void gotobkmk(const QString& bm); void gotobkmk(int); void cancelbkmk(); void do_gotomark(); void do_delmark(); void do_autogen(); void do_regaction(); void OnRedraw(); private: void setscrollcolour(); void setscrollbarcolour(); void writeUrl(const QString& file, const QString& href); QAction *m_preferences_action, *m_open_action, *m_close_action; QAction *m_info_action, *m_touch_action, *m_find_action, *m_start_action; QAction *m_end_action, *m_jump_action, *m_pageline_action; QAction *m_pageup_action, *m_pagedn_action, *m_back_action; QAction *m_home_action, *m_forward_action, *m_zoomin_action; QAction *m_zoomout_action, *m_setfont_action, *m_mark_action; QAction *m_annotate_action, *m_goto_action, *m_delete_action; QAction *m_autogen_action, *m_clear_action, *m_save_action; QAction *m_tidy_action, *m_startBlock_action, *m_endBlock_action; QAction *m_setenc_action, *m_setmono_action, *m_saveconfig_action; QAction *m_loadconfig_action, *m_loadtheme_action, *m_toolbarprefs_action, *m_tidyconfig_action; QAction *m_exportlinks_action, *m_rotate_action, *m_buttonprefs_action, *m_inverse_action; QAction *m_repara_action; #ifdef USEQPE QAction *m_grab_action; #endif void addtoolbars(Config* config); ToolbarPolicy m_tbpol, m_tbpolsave; ToolBarDock m_tbposition; bool m_tbmove, m_tbmovesave; QToolBar* filebar(); QToolBar* viewbar(); QToolBar* navbar(); QToolBar* markbar(); void hidetoolbars(); void addfilebar(Config* _config, const QString& key, QAction* a); void addviewbar(Config* _config, const QString& key, QAction* a); void addnavbar(Config* _config, const QString& key, QAction* a); void addmarkbar(Config* _config, const QString& key, QAction* a); bool checkbar(Config* _config, const QString& key); #ifdef _SCRIPT void SaveScript(const char* sname); #endif /* void setstate(unsigned char* _sd, unsigned short _sdlen); void getstate(unsigned char*& data, unsigned short& len); */ void fileOpen2(); void readfilelist(); void savefilelist(); void updatefileinfo(); bool openfrombkmk(Bkmk*); QString m_targetapp, m_targetmsg, m_statusstring, m_themename; bool listbkmk(CList<Bkmk>*, const QString& _lab = QString::null); QString usefilebrowser(); void do_regedit(); void colorChanged( const QColor &c ); void clear(); void updateCaption(); void do_autogen(const QString&); void do_addbkmk(const QString&); bool findNextBookmark(size_t start); private: QAction* m_scrollButton; QAction* m_buttonAction[MAX_ACTIONS]; CBkmkSelector* bkmkselector; // ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget, //m_upTarget, m_downTarget; //bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll; bool m_bcloseDisabled, m_disableesckey; diff --git a/noncore/apps/opie-reader/ToolbarPrefs.cpp b/noncore/apps/opie-reader/ToolbarPrefs.cpp index 5cf220a..56c4e9b 100644 --- a/noncore/apps/opie-reader/ToolbarPrefs.cpp +++ b/noncore/apps/opie-reader/ToolbarPrefs.cpp @@ -1,393 +1,392 @@ /**************************************************************************** ** Form implementation generated from reading ui file 'Prefs.ui' ** ** Created: Tue Feb 11 23:53:35 2003 ** by: The User Interface Compiler (uic) ** ** WARNING! All changes made in this file will be lost! ****************************************************************************/ -#include "useqpe.h" #include "ToolbarPrefs.h" #include <qcheckbox.h> #include <qlabel.h> #include <qpushbutton.h> #include <qspinbox.h> #include <qlayout.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qcombobox.h> #include <qbuttongroup.h> #include <qlineedit.h> #ifdef USEQPE #include <qpe/menubutton.h> #endif CBarPrefs::CBarPrefs(const QString& appdir, bool fs, QWidget* parent, const char* name) : QDialog(parent, name, true), config( appdir ) { setCaption(tr( "Toolbar Settings" ) ); QTabWidget* td = new QTabWidget(this); misc = new CMiscBarPrefs(this); filebar = new CFileBarPrefs(config, this); navbar = new CNavBarPrefs(config, this); viewbar = new CViewBarPrefs(config, this); markbar = new CMarkBarPrefs(config, this); indbar = new CIndBarPrefs(config, this); td->addTab(filebar, tr("File")); td->addTab(navbar, tr("Navigation")); td->addTab(viewbar, tr("View")); td->addTab(markbar, tr("Marks")); td->addTab(indbar, tr("Indicators")); td->addTab(misc, tr("Policy")); QVBoxLayout* v = new QVBoxLayout(this); v->addWidget(td); if (fs) showMaximized(); } /* CBarPrefs1::CBarPrefs1( Config& _config, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ), config(_config) { config.setGroup( "Toolbar" ); QVBoxLayout* vb = new QVBoxLayout(this); QGroupBox* bg = new QGroupBox(3, Qt::Horizontal, "File", this); vb->addWidget(bg); open = new QCheckBox( tr("Open"), bg ); open->setChecked(config.readBoolEntry( "Open", false )); connect(open, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); close = new QCheckBox( tr("Close"), bg ); close->setChecked(config.readBoolEntry( "Close", false )); connect(close, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); info = new QCheckBox( tr("Info"), bg ); info->setChecked(config.readBoolEntry( "Info", false )); connect(info, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); twotouch = new QCheckBox( tr("Two/One\nTouch"), bg ); twotouch->setChecked(config.readBoolEntry( "Two/One Touch", false )); connect(twotouch, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); find = new QCheckBox( tr("Find"), bg ); find->setChecked(config.readBoolEntry( "Find", false )); connect(find, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); bg = new QGroupBox(2, Qt::Horizontal, "Navigation", this); vb->addWidget(bg); scroll = new QCheckBox( tr("Scroll"), bg ); scroll->setChecked(config.readBoolEntry( "Scroll", false )); connect(scroll, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); navigation = new QCheckBox( tr("Back/Home/Forward"), bg ); navigation->setChecked(config.readBoolEntry( "Back/Home/Forward", false )); connect(navigation, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); page = new QCheckBox( tr("Page\nUp/Down"), bg ); page->setChecked(config.readBoolEntry( "Page Up/Down", false )); connect(page, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); startend = new QCheckBox( tr("Goto Start/End"), bg ); startend->setChecked(config.readBoolEntry( "Goto Start/End", false )); connect(startend, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); jump = new QCheckBox( tr("Jump"), bg ); jump->setChecked(config.readBoolEntry( "Jump", false )); connect(jump, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); pageline = new QCheckBox( tr("Page/Line Scroll"), bg ); pageline->setChecked(config.readBoolEntry( "Page/Line Scroll", false )); connect(pageline, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); m_isChanged = false; } void CBarPrefs1::saveall() { config.setGroup( "Toolbar" ); config.writeEntry( "Open", open->isChecked()); config.writeEntry( "Close", close->isChecked()); config.writeEntry( "Info", info->isChecked()); config.writeEntry( "Two/One Touch", twotouch->isChecked()); config.writeEntry( "Find", find->isChecked()); config.writeEntry( "Scroll", scroll->isChecked()); config.writeEntry( "Back/Home/Forward", navigation->isChecked()); config.writeEntry( "Page Up/Down", page->isChecked()); config.writeEntry( "Goto Start/End", startend->isChecked()); config.writeEntry( "Jump", jump->isChecked()); config.writeEntry( "Page/Line Scroll", pageline->isChecked()); } CBarPrefs1::~CBarPrefs1() { } */ /* CBarPrefs2::CBarPrefs2( Config& _config, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ), config(_config) { QVBoxLayout* vb = new QVBoxLayout(this); QGroupBox* bg = new QGroupBox(3, Qt::Horizontal, "View", this); vb->addWidget(bg); config.setGroup( "Toolbar" ); fullscreen = new QCheckBox( tr("Fullscreen"), bg ); fullscreen->setChecked(config.readBoolEntry( "Fullscreen", false )); connect(fullscreen, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); rotate = new QCheckBox( tr("Rotate"), bg ); rotate->setChecked(config.readBoolEntry( "Rotate", false )); connect(rotate, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); invert = new QCheckBox( tr("Invert"), bg ); invert->setChecked(config.readBoolEntry( "Invert Action", false )); connect(invert, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); zoom = new QCheckBox( tr("Zoom"), bg ); zoom->setChecked(config.readBoolEntry( "Zoom In/Out", false )); connect(zoom, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); setfont = new QCheckBox( tr("Set Font"), bg ); setfont->setChecked(config.readBoolEntry( "Set Font", false )); connect(setfont, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); encoding = new QCheckBox( tr("Encoding"), bg ); encoding->setChecked(config.readBoolEntry("Encoding Select", false)); connect(encoding, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); ideogram = new QCheckBox( tr("Ideogram"), bg ); ideogram->setChecked(config.readBoolEntry("Ideogram Mode", false)); connect(ideogram, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); bg = new QGroupBox(3, Qt::Horizontal, "Marks", this); vb->addWidget(bg); mark = new QCheckBox( tr("Bookmark"), bg ); mark->setChecked(config.readBoolEntry( "Mark", false )); connect(mark, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); annotate = new QCheckBox( tr("Annotate"), bg ); annotate->setChecked(config.readBoolEntry( "Annotate", false )); connect(annotate, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); go_to = new QCheckBox( tr("Goto"), bg ); go_to->setChecked(config.readBoolEntry( "Goto", false )); connect(go_to, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); Delete = new QCheckBox( tr("Delete"), bg ); Delete->setChecked(config.readBoolEntry( "Delete", false )); connect(Delete, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); autogen = new QCheckBox( tr("Autogen"), bg ); autogen->setChecked(config.readBoolEntry( "Autogen", false )); connect(autogen, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); clear = new QCheckBox( tr("Clear"), bg ); clear->setChecked(config.readBoolEntry( "Clear", false )); connect(clear, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); save = new QCheckBox( tr("Save"), bg ); save->setChecked(config.readBoolEntry( "Save", false )); connect(save, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); tidy = new QCheckBox( tr("Tidy"), bg ); tidy->setChecked(config.readBoolEntry( "Tidy", false )); connect(tidy, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); block = new QCheckBox( tr("Mark/Copy"), bg ); block->setChecked(config.readBoolEntry( "Start/Copy Block", false )); connect(block, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); bg = new QGroupBox(1, Qt::Horizontal, "Indicators", this); vb->addWidget(bg); indannotate = new QCheckBox( tr("Annotation"), bg ); indannotate->setChecked(config.readBoolEntry( "Annotation indicator", false )); connect(indannotate, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); m_isChanged = false; } void CBarPrefs2::saveall() { config.setGroup( "Toolbar" ); config.writeEntry( "Fullscreen", fullscreen->isChecked()); config.writeEntry( "Rotate", rotate->isChecked()); config.writeEntry( "Invert Action", invert->isChecked()); config.writeEntry( "Zoom In/Out", zoom->isChecked()); config.writeEntry( "Set Font", setfont->isChecked()); config.writeEntry("Encoding Select", encoding->isChecked()); config.writeEntry("Ideogram Mode", ideogram->isChecked()); config.writeEntry( "Mark", mark->isChecked()); config.writeEntry( "Annotate", annotate->isChecked()); config.writeEntry( "Goto", go_to->isChecked()); config.writeEntry( "Delete", Delete->isChecked()); config.writeEntry( "Autogen", autogen->isChecked()); config.writeEntry( "Clear", clear->isChecked()); config.writeEntry( "Save", save->isChecked()); config.writeEntry( "Tidy", tidy->isChecked()); config.writeEntry( "Start/Copy Block", block->isChecked()); config.writeEntry( "Annotation indicator", indannotate->isChecked()); } CBarPrefs2::~CBarPrefs2() { } */ CFileBarPrefs::CFileBarPrefs( Config& _config, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ), config(_config) { config.setGroup( "Toolbar" ); QVBoxLayout* vb = new QVBoxLayout(this); QGroupBox* bg = new QGroupBox(2, Qt::Horizontal, "File", this); vb->addWidget(bg); open = new QCheckBox( tr("Open"), bg ); open->setChecked(config.readBoolEntry( "Open", false )); connect(open, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); close = new QCheckBox( tr("Close"), bg ); close->setChecked(config.readBoolEntry( "Close", false )); connect(close, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); info = new QCheckBox( tr("Info"), bg ); info->setChecked(config.readBoolEntry( "Info", false )); connect(info, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); twotouch = new QCheckBox( tr("Two/One\nTouch"), bg ); twotouch->setChecked(config.readBoolEntry( "Two/One Touch", false )); connect(twotouch, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); find = new QCheckBox( tr("Find"), bg ); find->setChecked(config.readBoolEntry( "Find", false )); connect(find, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); m_isChanged = false; } void CFileBarPrefs::saveall() { config.setGroup( "Toolbar" ); config.writeEntry( "Open", open->isChecked()); config.writeEntry( "Close", close->isChecked()); config.writeEntry( "Info", info->isChecked()); config.writeEntry( "Two/One Touch", twotouch->isChecked()); config.writeEntry( "Find", find->isChecked()); } CFileBarPrefs::~CFileBarPrefs() { } CNavBarPrefs::CNavBarPrefs( Config& _config, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ), config(_config) { config.setGroup( "Toolbar" ); QVBoxLayout* vb = new QVBoxLayout(this); QGroupBox* bg = new QGroupBox(2, Qt::Horizontal, "Navigation", this); vb->addWidget(bg); scroll = new QCheckBox( tr("Scroll"), bg ); scroll->setChecked(config.readBoolEntry( "Scroll", false )); connect(scroll, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); navback = new QCheckBox( tr("Back"), bg ); navback->setChecked(config.readBoolEntry( "Back", false )); connect(navback, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); navhome = new QCheckBox( tr("Home"), bg ); navhome->setChecked(config.readBoolEntry( "Home", false )); connect(navhome, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); navforward = new QCheckBox( tr("Forward"), bg ); navforward->setChecked(config.readBoolEntry( "Forward", false )); connect(navforward, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); pageup = new QCheckBox( tr("Page Up"), bg ); pageup->setChecked(config.readBoolEntry( "Page Up", false )); connect(pageup, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); pagedown = new QCheckBox( tr("Page Down"), bg ); pagedown->setChecked(config.readBoolEntry( "Page Down", false )); connect(pagedown, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); gotostart = new QCheckBox( tr("Goto Start"), bg ); gotostart->setChecked(config.readBoolEntry( "Goto Start", false )); connect(gotostart, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); gotoend = new QCheckBox( tr("Goto End"), bg ); gotoend->setChecked(config.readBoolEntry( "Goto End", false )); connect(gotoend, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); jump = new QCheckBox( tr("Jump"), bg ); jump->setChecked(config.readBoolEntry( "Jump", false )); connect(jump, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); pageline = new QCheckBox( tr("Page/Line Scroll"), bg ); pageline->setChecked(config.readBoolEntry( "Page/Line Scroll", false )); connect(pageline, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); m_isChanged = false; } void CNavBarPrefs::saveall() { config.setGroup( "Toolbar" ); config.writeEntry( "Scroll", scroll->isChecked()); config.writeEntry( "Back", navback->isChecked()); config.writeEntry( "Home", navhome->isChecked()); config.writeEntry( "Forward", navforward->isChecked()); config.writeEntry( "Page Up", pageup->isChecked()); config.writeEntry( "Page Down", pagedown->isChecked()); config.writeEntry( "Goto Start", gotostart->isChecked()); config.writeEntry( "Goto End", gotoend->isChecked()); config.writeEntry( "Jump", jump->isChecked()); config.writeEntry( "Page/Line Scroll", pageline->isChecked()); } CNavBarPrefs::~CNavBarPrefs() { } CViewBarPrefs::CViewBarPrefs( Config& _config, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ), config(_config) { QVBoxLayout* vb = new QVBoxLayout(this); QGroupBox* bg = new QGroupBox(2, Qt::Horizontal, "View", this); vb->addWidget(bg); config.setGroup( "Toolbar" ); fullscreen = new QCheckBox( tr("Fullscreen"), bg ); fullscreen->setChecked(config.readBoolEntry( "Fullscreen", false )); connect(fullscreen, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); rotate = new QCheckBox( tr("Rotate"), bg ); rotate->setChecked(config.readBoolEntry( "Rotate", false )); connect(rotate, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); invert = new QCheckBox( tr("Invert"), bg ); invert->setChecked(config.readBoolEntry( "Invert Action", false )); connect(invert, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); zoomin = new QCheckBox( tr("Zoom In"), bg ); zoomin->setChecked(config.readBoolEntry( "Zoom In", false )); connect(zoomin, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); zoomout = new QCheckBox( tr("Zoom Out"), bg ); zoomout->setChecked(config.readBoolEntry( "Zoom Out", false )); connect(zoomout, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); setfont = new QCheckBox( tr("Set Font"), bg ); setfont->setChecked(config.readBoolEntry( "Set Font", false )); connect(setfont, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); encoding = new QCheckBox( tr("Encoding"), bg ); encoding->setChecked(config.readBoolEntry("Encoding Select", false)); connect(encoding, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); ideogram = new QCheckBox( tr("Ideogram"), bg ); ideogram->setChecked(config.readBoolEntry("Ideogram Mode", false)); connect(ideogram, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); m_isChanged = false; } void CViewBarPrefs::saveall() { config.setGroup( "Toolbar" ); config.writeEntry( "Fullscreen", fullscreen->isChecked()); config.writeEntry( "Rotate", rotate->isChecked()); config.writeEntry( "Invert Action", invert->isChecked()); config.writeEntry( "Zoom In", zoomin->isChecked()); config.writeEntry( "Zoom Out", zoomout->isChecked()); config.writeEntry( "Set Font", setfont->isChecked()); config.writeEntry("Encoding Select", encoding->isChecked()); config.writeEntry("Ideogram Mode", ideogram->isChecked()); } CViewBarPrefs::~CViewBarPrefs() { } CMarkBarPrefs::CMarkBarPrefs( Config& _config, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ), config(_config) { QVBoxLayout* vb = new QVBoxLayout(this); QGroupBox* bg = new QGroupBox(2, Qt::Horizontal, "Marks", this); vb->addWidget(bg); mark = new QCheckBox( tr("Bookmark"), bg ); mark->setChecked(config.readBoolEntry( "Mark", false )); connect(mark, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); annotate = new QCheckBox( tr("Annotate"), bg ); annotate->setChecked(config.readBoolEntry( "Annotate", false )); connect(annotate, SIGNAL(stateChanged(int)), this, SLOT( isChanged(int) ) ); go_to = new QCheckBox( tr("Goto"), bg ); diff --git a/noncore/apps/opie-reader/ToolbarPrefs.h b/noncore/apps/opie-reader/ToolbarPrefs.h index a2686e5..0bdae6b 100644 --- a/noncore/apps/opie-reader/ToolbarPrefs.h +++ b/noncore/apps/opie-reader/ToolbarPrefs.h @@ -1,269 +1,267 @@ /**************************************************************************** ** Form interface generated from reading ui file 'Prefs.ui' ** ** Created: Tue Feb 11 23:53:32 2003 ** by: The User Interface Compiler (uic) ** ** WARNING! All changes made in this file will be lost! ****************************************************************************/ #ifndef CTOOLBARPREFS_H #define CTOOLBARPREFS_H -#include "useqpe.h" #include <qvariant.h> #include <qwidget.h> #include <qtabdialog.h> #include <qtabwidget.h> #include <qspinbox.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlineedit.h> #ifdef USEQPE #include <qpe/menubutton.h> #include <qpe/config.h> #else #include "preferences.h" #endif -//#include "opie.h" //#ifdef OPIE #define USECOMBO //#endif class QVBoxLayout; class QHBoxLayout; class QGridLayout; //class QCheckBox; class QLabel; //class QSpinBox; /* class CBarPrefs1 : public QWidget { Q_OBJECT Config& config; QCheckBox *open, *close, *info, *twotouch,*find,*scroll,*navigation,*page,*startend,*jump,*pageline; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CBarPrefs1( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CBarPrefs1(); void saveall(); bool isChanged() { return m_isChanged; } }; */ class CFileBarPrefs : public QWidget { Q_OBJECT Config& config; QCheckBox *open, *close, *info, *twotouch, *find, *scroll; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CFileBarPrefs( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CFileBarPrefs(); void saveall(); bool isChanged() { return m_isChanged; } }; class CNavBarPrefs : public QWidget { Q_OBJECT Config& config; QCheckBox *scroll, *navback, *navhome, *navforward; QCheckBox *pageup, *pagedown, *gotostart, *gotoend, *jump, *pageline; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CNavBarPrefs( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CNavBarPrefs(); void saveall(); bool isChanged() { return m_isChanged; } }; /* class CBarPrefs2 : public QWidget { Q_OBJECT Config& config; QCheckBox *fullscreen, *zoom, *setfont, *mark, *annotate, *go_to, *Delete, *autogen, *clear, *save, *tidy, *block, *indannotate, *encoding, *ideogram; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CBarPrefs2( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CBarPrefs2(); void saveall(); bool isChanged() { return m_isChanged; } }; */ class CViewBarPrefs : public QWidget { Q_OBJECT Config& config; QCheckBox *fullscreen, *rotate, *zoomin, *zoomout, *setfont, *encoding, *ideogram, *invert; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CViewBarPrefs( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CViewBarPrefs(); void saveall(); bool isChanged() { return m_isChanged; } }; class CMarkBarPrefs : public QWidget { Q_OBJECT Config& config; QCheckBox *mark, *annotate, *go_to, *Delete, *autogen, *clear, *save, *tidy, *startblock, *copyblock; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CMarkBarPrefs( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CMarkBarPrefs(); void saveall(); bool isChanged() { return m_isChanged; } }; class CIndBarPrefs : public QWidget { Q_OBJECT Config& config; QCheckBox *indannotate; bool m_isChanged; private slots: void isChanged(int _v) { m_isChanged = true; } public: CIndBarPrefs( Config&, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CIndBarPrefs(); void saveall(); bool isChanged() { return m_isChanged; } }; class CMiscBarPrefs : public QWidget { public: CMiscBarPrefs( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~CMiscBarPrefs(); #ifdef USECOMBO QComboBox *tbpolicy, *tbposition, *qtscroll, *localscroll; #else MenuButton *tbpolicy, *tbposition, *qtscroll, *localscroll; #endif QCheckBox *tbmovable, *floating; }; class CBarPrefs : public QDialog { Q_OBJECT ; CMiscBarPrefs* misc; CFileBarPrefs* filebar; CNavBarPrefs* navbar; CViewBarPrefs* viewbar; CMarkBarPrefs* markbar; CIndBarPrefs* indbar; Config config; void keyPressEvent(QKeyEvent* e) { switch (e->key()) { case Key_Escape: e->accept(); reject(); break; case Key_Space: case Key_Return: e->accept(); accept(); break; default: QWidget::keyPressEvent(e); } } public: CBarPrefs(const QString& appdir, bool fs = true, QWidget* parent = 0, const char* name = 0); ~CBarPrefs() { if (result()) { if (navbar->isChanged()) navbar->saveall(); if (filebar->isChanged()) filebar->saveall(); if (viewbar->isChanged()) viewbar->saveall(); if (markbar->isChanged()) markbar->saveall(); if (indbar->isChanged()) indbar->saveall(); } } bool isChanged() { return ( filebar->isChanged() || navbar->isChanged() || viewbar->isChanged() || markbar->isChanged() || indbar->isChanged() ); } bool floating() { return misc->floating->isChecked(); } void floating(bool v) { misc->floating->setChecked(v); } int tbpolicy() { return misc->tbpolicy->currentItem(); } int qtscroll() { return misc->qtscroll->currentItem(); } int localscroll() { return misc->localscroll->currentItem(); } #ifdef USECOMBO void tbpolicy(int v) { misc->tbpolicy->setCurrentItem(v); } void qtscroll(int v) { misc->qtscroll->setCurrentItem(v); } void localscroll(int v) { misc->localscroll->setCurrentItem(v); } #else void tbpolicy(int v) { misc->tbpolicy->select(v); } void qtscroll(int v) { misc->qtscroll->select(v); } void localscroll(int v) { misc->localscroll->select(v); } #endif bool tbmovable() { return misc->tbmovable->isChecked(); } void tbmovable(bool v) { misc->tbmovable->setChecked(v); } int tbposition() { return misc->tbposition->currentItem(); } #ifdef USECOMBO void tbposition(int v) { misc->tbposition->setCurrentItem(v); } #else void tbposition(int v) { misc->tbposition->select(v); } #endif }; #endif // CPREFS_H diff --git a/noncore/apps/opie-reader/URLDialog.h b/noncore/apps/opie-reader/URLDialog.h index 1bcc4bd..792d13a 100644 --- a/noncore/apps/opie-reader/URLDialog.h +++ b/noncore/apps/opie-reader/URLDialog.h @@ -1,65 +1,64 @@ /**************************************************************************** ** Form interface generated from reading ui file 'Prefs.ui' ** ** Created: Tue Feb 11 23:53:32 2003 ** by: The User Interface Compiler (uic) ** ** WARNING! All changes made in this file will be lost! ****************************************************************************/ #ifndef __URLDIALOG_H #define __URLDIALOG_H -#include "useqpe.h" #include <qvariant.h> #include <qwidget.h> #include <qtabdialog.h> #include <qtabwidget.h> #include <qspinbox.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlineedit.h> //#include <qpe/menubutton.h> #include <qvbuttongroup.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; //class QCheckBox; class QLabel; //class QSpinBox; class CURLDialog : public QDialog { Q_OBJECT QCheckBox *m_localfile, *m_globalfile, *m_clipboard; #ifndef USEQPE void keyPressEvent(QKeyEvent* e) { switch (e->key()) { case Key_Escape: e->accept(); reject(); break; case Key_Space: case Key_Return: e->accept(); accept(); break; default: QWidget::keyPressEvent(e); } } #endif public: CURLDialog(const QString&, bool fs = true, QWidget* parent = 0, const char* name = 0); ~CURLDialog() {} bool clipboard() { return m_clipboard->isChecked(); } bool localfile() { return m_localfile->isChecked(); } bool globalfile() { return m_globalfile->isChecked(); } void clipboard(bool _b) { m_clipboard->setChecked(_b); } void localfile(bool _b) { m_localfile->setChecked(_b); } void globalfile(bool _b) { m_globalfile->setChecked(_b); } }; #endif // CPREFS_H diff --git a/noncore/apps/opie-reader/WeaselCodec/WeaselCodec.pro b/noncore/apps/opie-reader/WeaselCodec/WeaselCodec.pro index 61e7dc9..f20bdc6 100644 --- a/noncore/apps/opie-reader/WeaselCodec/WeaselCodec.pro +++ b/noncore/apps/opie-reader/WeaselCodec/WeaselCodec.pro @@ -1,17 +1,17 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = ztxt.h SOURCES = ztxt.cpp INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/codecs TARGET = Weasel LIBS += -lreader_pdb -lreader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h index 06e3bf8..199c7da 100644 --- a/noncore/apps/opie-reader/ZText.h +++ b/noncore/apps/opie-reader/ZText.h @@ -1,116 +1,115 @@ #ifndef __Text_h #define __Text_h #include <stdio.h> #include <zlib.h> #include <sys/stat.h> -#include "useqpe.h" #include "CExpander.h" class Text: public CExpander { gzFile file; unsigned long fsize; public: void suspend() { #ifdef USEQPE if (!bSuspended) { bSuspended = true; suspos = gztell(file); gzclose(file); file = NULL; sustime = time(NULL); } #endif } void unsuspend() { #ifdef USEQPE if (bSuspended) { bSuspended = false; if (sustime != ((time_t)-1)) { int delay = time(NULL) - sustime; if (delay < 10) sleep(10-delay); } file = gzopen(fname, "rb"); for (int i = 0; file == NULL && i < 5; i++) { sleep(5); file = gzopen(fname, "rb"); } if (file == NULL) { QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); exit(0); } suspos = gzseek(file, suspos, SEEK_SET); } #endif } Text() : file(NULL) {}; virtual ~Text() { if (file != NULL) { #ifdef USEQPE unsuspend(); #endif gzclose(file); } } int OpenFile(const char *src) { if (file != NULL) gzclose(file); struct stat _stat; stat(src,&_stat); fsize = _stat.st_size; return ((file = gzopen(src,"rb")) == NULL); } int getch() { #ifdef USEQPE unsuspend(); #endif return gzgetc(file); } unsigned int locate() { #ifdef USEQPE unsuspend(); #endif return gztell(file); } void locate(unsigned int n) { #ifdef USEQPE unsuspend(); #endif gzseek(file,n,SEEK_SET); } bool hasrandomaccess() { return true; } void sizes(unsigned long& _file, unsigned long& _text) { _text = _file = fsize; FILE* f = fopen(fname, "rb"); if (f != NULL) { unsigned char mn[2]; fread(mn, 1, 2, f); if ((mn[0] == 31) && (mn[1] == 139)) { int tmp = sizeof(_text); fseek(f,-tmp,SEEK_END); fread(&_text, sizeof(_text), 1, f); } fclose(f); } } MarkupType PreferredMarkup() { return cTEXT; } QString about() { return QString("Text/gzipped text codec (c) Tim Wentford"); } }; #endif diff --git a/noncore/apps/opie-reader/codeclib/codeclib.pro b/noncore/apps/opie-reader/codeclib/codeclib.pro index 6adcda8..c24767b 100644 --- a/noncore/apps/opie-reader/codeclib/codeclib.pro +++ b/noncore/apps/opie-reader/codeclib/codeclib.pro @@ -1,17 +1,17 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = pdb.h SOURCES = CExpander.cpp CBuffer.cpp StyleConsts.cpp \ hrule.cpp Navigation.cpp Bkmks.cpp INTERFACES = DESTDIR = $(OPIEDIR)/lib TARGET = reader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/ebookcodec.h b/noncore/apps/opie-reader/ebookcodec.h index b341e55..f6e2daf 100644 --- a/noncore/apps/opie-reader/ebookcodec.h +++ b/noncore/apps/opie-reader/ebookcodec.h @@ -1,120 +1,118 @@ #include "CExpander.h" #include <qfileinfo.h> #include <qdir.h> -#include "useqpe.h" #ifdef USEQPE #include <qpe/global.h> #endif #include "util.h" -#include "static.h" #ifndef __STATIC #include <dlfcn.h> class ebookcodec : public CExpander_Interface { CExpander *codec; void *handle; int status; public: QString about() { return QString("Plug-in ebook codec interface (c) Tim Wentford\n")+codec->about(); } ebookcodec(const QString& _s) : codec(NULL), handle(NULL), status(0) { QString codecpath(QTReaderUtil::getPluginPath()); codecpath += _s; if (QFile::exists(codecpath)) { qDebug("Codec:%s", (const char*)codecpath); handle = dlopen(codecpath, RTLD_LAZY); if (handle == 0) { /* QString wrn(dlerror()); QString fmt; while (wrn.length() > 10) { fmt += wrn.left(10); fmt += '\n'; wrn = wrn.right(wrn.length()-10); } fmt += wrn; QMessageBox::warning(NULL, PROGNAME, fmt); */ qDebug("Can't find codec:%s", dlerror()); status = -10; return; } CExpander* (*newcodec)(); newcodec = (CExpander* (*)())dlsym(handle, "newcodec"); if (newcodec == NULL) { qDebug("Can't find newcodec"); status = -20; return; } codec = (*newcodec)(); } else { qDebug("Can't find codec"); } if (codec == NULL) { qDebug("Can't do newcodec"); status = -30; return; } } virtual ~ebookcodec() { if (codec != NULL) delete codec; if (handle != NULL) dlclose(handle); } size_t getHome() { return codec->getHome(); } #ifdef USEQPE void suspend() { codec->suspend(); } void unsuspend() { codec->unsuspend(); } void suspend(FILE*& fin) { codec->suspend(fin); } void unsuspend(FILE*& fin) { codec->unsuspend(fin); } #endif unsigned int locate() { return codec->locate(); } void locate(unsigned int n) { codec->locate(n); } bool hasrandomaccess() { return codec->hasrandomaccess(); } void sizes(unsigned long& file, unsigned long& text) { codec->sizes(file, text); //qDebug("Codec sizes:(%u, %u)", file, text); } CList<Bkmk>* getbkmklist() { return codec->getbkmklist(); } void getch(tchar& ch, CStyle& sty, unsigned long& pos) { codec->getch(ch, sty, pos); } int getch() { return codec->getch(); } linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) { return codec->hyperlink(n, noff, wrd, nm); } MarkupType PreferredMarkup() { return codec->PreferredMarkup(); } void saveposn(size_t posn) { codec->saveposn(posn); } void writeposn(size_t posn) { codec->writeposn(posn); } linkType forward(size_t& loc) { return codec->forward(loc); } linkType back(size_t& loc) { return codec->back(loc); } bool hasnavigation() { return codec->hasnavigation(); } void start2endSection() { codec->start2endSection(); } QImage* getPicture(unsigned long tgt) { return codec->getPicture(tgt); } void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { return codec->setSaveData(data, len, src, srclen); } void putSaveData(unsigned char*& src, unsigned short& srclen) { codec->putSaveData(src, srclen); } void setContinuous(bool _b) { codec->setContinuous(_b); } void setwidth(int w) { codec->setwidth(w); } unsigned long startSection() { return codec->startSection(); } unsigned long endSection() { return codec->endSection(); } int openfile(const char *src) { //qDebug("ebook openfile:%s", src); return (status != 0) ? status : codec->openfile(src); } int getwidth() { return codec->getwidth(); } QImage* getPicture(const QString& href) { return codec->getPicture(href); } bool getFile(const QString& href) { return codec->getFile(href); } }; #endif diff --git a/noncore/apps/opie-reader/iSiloCodec/iSiloCodec.pro b/noncore/apps/opie-reader/iSiloCodec/iSiloCodec.pro index 78d5a49..5cf075e 100644 --- a/noncore/apps/opie-reader/iSiloCodec/iSiloCodec.pro +++ b/noncore/apps/opie-reader/iSiloCodec/iSiloCodec.pro @@ -1,19 +1,19 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll #HEADERS = Aportis.h SOURCES = iSilo.cpp INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/codecs TARGET = iSilo LIBS += -lreader_pdb -lreader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/main.cpp b/noncore/apps/opie-reader/main.cpp index 3e1f5e7..af276da 100644 --- a/noncore/apps/opie-reader/main.cpp +++ b/noncore/apps/opie-reader/main.cpp @@ -1,50 +1,49 @@ -#include "useqpe.h" #ifdef USEQPE #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #include "QTReaderApp.h" #include "signal.h" #include "stdio.h" #include "time.h" #ifdef USEQPE QTReaderApp* app = NULL; void handler(int signum) { if (app != NULL) { app->suspend(); app->saveprefs(); } signal(signum, handler); } #endif int main( int argc, char ** argv ) { #ifdef USEQPE signal(SIGCONT, handler); QPEApplication a( argc, argv ); QTReaderApp m; a.showMainDocumentWidget( &m ); app = &m; #else QApplication a( argc, argv ); QTReaderApp m; a.setMainWidget( &m ); if (argc > 1) { m.setDocument(argv[1]); } #endif return a.exec(); } diff --git a/noncore/apps/opie-reader/pdb.cpp b/noncore/apps/opie-reader/pdb.cpp index 39551cc..6719af4 100644 --- a/noncore/apps/opie-reader/pdb.cpp +++ b/noncore/apps/opie-reader/pdb.cpp @@ -1,90 +1,89 @@ #include "pdb.h" #ifdef _WINDOWS #include <winsock2.h> #endif -#include "useqpe.h" #ifdef USEQPE void Cpdb::suspend() { CExpander::suspend(fin); } void Cpdb::unsuspend() { CExpander::unsuspend(fin); } #endif Cpdb::~Cpdb() { if (fin != NULL) { #ifdef USEQPE unsuspend(); #endif fclose(fin); } } size_t Cpdb::recordpos(int n) { UInt16 mxn = ntohs(head.recordList.numRecords); if (n >= mxn) { return file_length; } else { size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; fseek(fin, dataoffset, SEEK_SET); RecordListType hdr; fread(&hdr, 1, sizeof(hdr), fin); return ntohl(hdr.nextRecordListID); } } size_t Cpdb::recordlength(int n) { return recordpos(n+1)-recordpos(n); } void Cpdb::gotorecordnumber(int n) { fseek(fin, recordpos(n), SEEK_SET); } bool Cpdb::openpdbfile(const char *src) { //qDebug("cpdb openfile:%s", src); // printf("In openfile\n"); // printf("closing fin:%x\n",fin); if (fin != NULL) fclose(fin); // printf("opening fin\n"); fin = fopen(src,"rb"); if (fin==0) { return false; } // just holds the first few chars of the file // char buf[0x100]; struct stat _stat; stat(src,&_stat); file_length = _stat.st_size; // fseek(fin,0,SEEK_END); // file_length = ftell(fin); fseek(fin,0,SEEK_SET); fread(&head, 1, sizeof(head), fin); qDebug("Database name:%s", head.name); qDebug("Total number of records:%u", ntohs(head.recordList.numRecords)); return true; } diff --git a/noncore/apps/opie-reader/pdb.h b/noncore/apps/opie-reader/pdb.h index 7a6580d..7458919 100644 --- a/noncore/apps/opie-reader/pdb.h +++ b/noncore/apps/opie-reader/pdb.h @@ -1,101 +1,100 @@ /* * This header file defines some structures and types normally found in the * Palm SDK. However, I don't want to require the presense of the SDK for a * small utility since most Palm owners won't have it. * * $Id$ * */ #ifndef __PDB_H__ #define __PDB_H__ #ifndef _WINDOWS #include <netinet/in.h> #endif #include <stdio.h> -#include "useqpe.h" #include "CExpander.h" /* Normal Palm typedefs */ typedef unsigned char UInt8; typedef unsigned short UInt16; typedef signed short Int16; typedef unsigned long UInt32; typedef UInt32 LocalID; /* Max length of DB name */ #define dmDBNameLength 0x20 /************************************************************ * Structure of a Record entry *************************************************************/ typedef struct { LocalID localChunkID; // local chunkID of a record UInt8 attributes; // record attributes; UInt8 uniqueID[3]; // unique ID of record; should // not be 0 for a legal record. } RecordEntryType; /************************************************************ * Structure of a record list extension. This is used if all * the database record/resource entries of a database can't fit into * the database header. *************************************************************/ typedef struct { LocalID nextRecordListID; // local chunkID of next list UInt16 numRecords; // number of records in this list UInt16 firstEntry; // array of Record/Rsrc entries // starts here } RecordListType; /************************************************************ * Structure of a Database Header *************************************************************/ typedef struct { UInt8 name[dmDBNameLength]; // name of database UInt16 attributes; // database attributes UInt16 version; // version of database UInt32 creationDate; // creation date of database UInt32 modificationDate; // latest modification date UInt32 lastBackupDate; // latest backup date UInt32 modificationNumber; // modification number of database LocalID appInfoID; // application specific info LocalID sortInfoID; // app specific sorting info UInt32 type; // database type UInt32 creator; // database creator UInt32 uniqueIDSeed; // used to generate unique IDs. // Note that only the low order // 3 bytes of this is used (in // RecordEntryType.uniqueID). // We are keeping 4 bytes for // alignment purposes. RecordListType recordList; // first record list } DatabaseHdrType; class Cpdb : public CExpander { protected: size_t file_length; FILE* fin; size_t recordpos(int); size_t recordlength(int); void gotorecordnumber(int); DatabaseHdrType head; bool openpdbfile(const char* src); Cpdb() : fin(NULL) {} ~Cpdb(); #ifdef USEQPE void suspend(); void unsuspend(); #endif public: virtual void sizes(unsigned long& _file, unsigned long& _text) = 0; }; #endif diff --git a/noncore/apps/opie-reader/pdblib/pdblib.pro b/noncore/apps/opie-reader/pdblib/pdblib.pro index cb861a8..830d988 100644 --- a/noncore/apps/opie-reader/pdblib/pdblib.pro +++ b/noncore/apps/opie-reader/pdblib/pdblib.pro @@ -1,16 +1,16 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = pdb.h SOURCES = pdb.cpp INTERFACES = DESTDIR = $(OPIEDIR)/lib TARGET = reader_pdb -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/plucker.cpp b/noncore/apps/opie-reader/plucker.cpp index d1ccd6f..4ea807a 100644 --- a/noncore/apps/opie-reader/plucker.cpp +++ b/noncore/apps/opie-reader/plucker.cpp @@ -1,231 +1,229 @@ -#include "useqpe.h" #include <stdio.h> #include <string.h> #include <qmessagebox.h> #include <qpixmap.h> #ifdef USEQPE #include <qpe/qcopenvelope_qws.h> #endif #ifdef LOCALPICTURES #include <qscrollview.h> #endif #ifdef USEQPE #include <qpe/global.h> #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #include <qclipboard.h> #include "plucker.h" #include "Aportis.h" #include "Palm2QImage.h" -#include "static.h" struct CPlucker_dataRecord { UInt16 uid; UInt16 nParagraphs; UInt16 size; UInt8 type; UInt8 reserved; }; int CPlucker::HeaderSize() { return sizeof(CPlucker_dataRecord); } void CPlucker::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved) { CPlucker_dataRecord thishdr; fread(&thishdr, 1, HeaderSize(), fin); uid = ntohs(thishdr.uid); nParagraphs = ntohs(thishdr.nParagraphs); size = ntohs(thishdr.size); type = thishdr.type; reserved = thishdr.reserved; } CPlucker::CPlucker() { /*printf("constructing:%x\n",fin);*/ EOPPhase = 0; } bool CPlucker::CorrectDecoder() { return (memcmp(&head.type, "DataPlkr", 8) == 0); } int CPlucker::bgetch() { int ch = EOF; if (bufferpos >= buffercontent) { if (isEndOfSection(bufferrec)) { if (!m_continuous) return EOF; } if (bufferrec >= ntohs(head.recordList.numRecords) - 1) { return EOF; } if (!expand(bufferrec+1)) { return EOF; } mystyle.unset(); if (m_ParaOffsets[m_nextParaIndex] == 0) { while (m_ParaOffsets[m_nextParaIndex+1] == 0) { // qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); m_nextParaIndex++; } } mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); // qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); ch = 10; if (m_continuous) EOPPhase = 4; } else if (bufferpos == m_nextPara) { while (bufferpos == m_nextPara) { UInt16 attr = m_ParaAttrs[m_nextParaIndex]; m_nextParaIndex++; // qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); if (m_nextParaIndex == m_nParas) { m_nextPara = -1; } else { m_nextPara += m_ParaOffsets[m_nextParaIndex]; } } mystyle.unset(); mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); // qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7); if (m_lastBreak == locate()) { currentpos++; ch = expandedtextbuffer[bufferpos++]; } else { ch = 10; } } else { currentpos++; ch = expandedtextbuffer[bufferpos++]; } return ch; } tchar CPlucker::getch(bool fast) { mystyle.clearPicture(); if (EOPPhase > 0) { int ch = 10; switch (EOPPhase) { case 4: if (!fast) mystyle.setPicture(false, hRule(100,5)); mystyle.setCentreJustify(); ch = '#'; break; case 3: mystyle.setFontSize(3); ch = 10; break; case 2: ch = 10; break; case 1: mystyle.unset(); default: ch = 10; } EOPPhase--; return ch; } return getch_base(fast); } QImage* CPlucker::imagefromdata(UInt8* imgbuffer, UInt32 imgsize) { QImage* qimage = Palm2QImage(imgbuffer, imgsize); delete [] imgbuffer; return qimage; } void CPlucker::start2endSection() // to plucker base { m_currentstart = NEFstartSection(); m_currentend = NEFendSection(); } unsigned long CPlucker::NEFstartSection() // virtual in plucker base - differs only in obsoleted nef so move implementation { //inefficient - Should calc start/end of section on entry to section? UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; unsigned long textlength = currentpos-bufferpos; for (UInt16 recptr = bufferrec-1; recptr >= 1; recptr--) { gotorecordnumber(recptr); //qDebug("recptr:%u", recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { if ((thishdr_reserved && continuation_bit) == 0) break; textlength -= thishdr_size; //qDebug("Textlength:%u, reserved:%u, recptr:%u", textlength, thishdr_reserved, recptr); } } return textlength; } unsigned long CPlucker::NEFendSection() // virtual in plucker base - differs only in obsoleted nef so move implementation { //inefficient - Should calc start/end of section on entry to section? unsigned long textlength = currentpos-bufferpos+buffercontent; gotorecordnumber(bufferrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if ((thishdr_reserved && continuation_bit) != 0) { for (UInt16 recptr = bufferrec+1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); // qDebug("recptr %u bufferrec %u type %u m_reserved %u", recptr, bufferrec, typ if (thishdr_type < 2) { textlength += thishdr_size; if ((thishdr_reserved && continuation_bit) == 0) break; } } } return textlength; } #ifndef __STATIC extern "C" { CExpander* newcodec() { return new CPlucker; } } #endif diff --git a/noncore/apps/opie-reader/plucker_base.cpp b/noncore/apps/opie-reader/plucker_base.cpp index 0b7fae8..d7d538f 100644 --- a/noncore/apps/opie-reader/plucker_base.cpp +++ b/noncore/apps/opie-reader/plucker_base.cpp @@ -1,408 +1,406 @@ -#include "useqpe.h" #include "usenef.h" #include <stdio.h> #include <string.h> #include <qmessagebox.h> #include <qpixmap.h> #ifdef USEQPE #include <qpe/qcopenvelope_qws.h> #endif /* USEQPE */ #ifdef LOCALPICTURES #include <qscrollview.h> #endif #ifdef USEQPE #include <qpe/global.h> #endif /* USEQPE */ #include <qclipboard.h> #ifndef USEQPE #include <qapplication.h> #else /* USEQPE */ #include <qpe/qpeapplication.h> #endif /* USEQPE */ #include <qimage.h> -#include "static.h" #include "plucker_base.h" #include "Aportis.h" #include "hrule.h" #include "util.h" const UInt8 CPlucker_base::continuation_bit = 1; CPlucker_base::CPlucker_base() : #ifdef LOCALPICTURES m_viewer(NULL), m_picture(NULL), #endif expandedtextbuffer(NULL), compressedtextbuffer(NULL), bufferrec(-1), m_offset(0) //, urls(NULL) { /*printf("constructing:%x\n",fin);*/ } void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) { if (type%2 == 0) { fread(buffer, reclen, sizeof(char), fin); } else { UInt8* readbuffer = NULL; if (reclen > compressedbuffersize) { readbuffer = new UInt8[reclen]; } else { readbuffer = compressedtextbuffer; } if (readbuffer != NULL) { fread(readbuffer, reclen, sizeof(char), fin); (*m_decompress)(readbuffer, reclen, buffer, buffersize); if (reclen > compressedbuffersize) { delete [] readbuffer; } } } } void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text) { _file = file_length; if (textlength == 0) { for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) textlength += thishdr_size; } } _text = textlength; //ntohl(hdr0.size); } char* CPlucker_base::geturl(UInt16 tgt) { char * pRet = NULL; gotorecordnumber(0); fread(&hdr0, 1, 6, fin); unsigned int nrecs = ntohs(hdr0.nRecords); //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); UInt16 urlid = 0; bool urlsfound = false; char* urls = NULL; size_t urlsize = 0; for (unsigned int i = 0; i < nrecs; i++) { UInt16 id, name; fread(&name, 1, sizeof(name), fin); fread(&id, 1, sizeof(id), fin); //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); if (ntohs(name) == 2) { urlsfound = true; urlid = id; //qDebug("Found url index:%d", ntohs(urlid)); } // //qDebug("%x", id); } if (urlsfound) { unsigned short recptr = finduid(ntohs(urlid)); if (recptr != 0) { gotorecordnumber(recptr); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); UInt16 urlctr = 0; while (1) { UInt16 tctr; fread(&tctr, 1, sizeof(tctr), fin); fread(&urlid, 1, sizeof(urlid), fin); tctr = ntohs(tctr); //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr); if (tctr >= tgt) { break; } urlctr = tctr; } //qDebug("urls are in %d", ntohs(urlid)); recptr = finduid(ntohs(urlid)); if (recptr != 0) { UInt32 reclen = recordlength(recptr) - HeaderSize(); gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); //qDebug("Found urls:%x",thishdr_type); urlsize = thishdr_size; urls = new char[urlsize]; Expand(reclen, thishdr_type, (UInt8*)urls, urlsize); char* ptr = urls; int rn = urlctr+1; while (ptr - urls < urlsize) { if (rn == tgt) { //qDebug("URL:%s", ptr); int len = strlen(ptr)+1; pRet = new char[len]; memcpy(pRet, ptr, len); break; } ptr += strlen(ptr)+1; rn++; } delete [] urls; } } } else { pRet = NULL; } return pRet; } CPlucker_base::~CPlucker_base() { if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; #ifdef LOCALPICTURES if (m_viewer != NULL) delete m_viewer; #endif } int CPlucker_base::getch() { return getch(false); } void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) { pos = locate(); ch = getch(false); sty = mystyle; } unsigned int CPlucker_base::locate() { return currentpos; /* UInt16 thisrec = 1; unsigned long locpos = 0; gotorecordnumber(thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (thisrec < bufferrec) { GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) locpos += thishdr_size; thisrec++; gotorecordnumber(thisrec); } return locpos+bufferpos; */ } void CPlucker_base::locate(unsigned int n) { // clock_t start = clock(); if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) { currentpos -= bufferpos; expand(bufferrec); while (currentpos < n && bufferpos < buffercontent) getch_base(true); return; } /* UInt32 textlength = currentpos - bufferpos; UInt16 recptr = bufferrec; if (n < textlength/2) { textlength = 0; UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size = buffercontent; UInt8 thishdr_type, thishdr_reserved; for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { textlength += thishdr_size; if (textlength > n) { textlength -= thishdr_size; break; } } } } else if (n < textlength) { UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (n < textlength && recptr > 1) { recptr--; gotorecordnumber(recptr); //qDebug("recptr:%u", recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { textlength -= thishdr_size; } } } else { UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size = buffercontent; UInt8 thishdr_type, thishdr_reserved; while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) { textlength += thishdr_size; recptr++; gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (!(thishdr_type < 2)) { thishdr_size = 0; } } } */ UInt16 thisrec = 0; unsigned long locpos = 0; unsigned long bs = 0; UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; do { thisrec++; locpos += bs; gotorecordnumber(thisrec); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type < 2) { bs = thishdr_size; } else { bs = 0; } } while (locpos + bs <= n); // qDebug("Time(2): %u", clock()-start); /* if (recptr != thisrec) { qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size = buffercontent; UInt8 thishdr_type, thishdr_reserved; for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved); } // QApplication::exit ( 100 ); } */ currentpos = locpos; expand(thisrec); while (currentpos < n && bufferpos < buffercontent) getch_base(true); /* // This is faster but the alignment attribute doesn't get set 8^( bufferpos = n-locpos; currentpos = n; while (bufferpos >= m_nextPara && m_nextPara >= 0) { UInt16 attr = m_ParaAttrs[m_nextParaIndex]; m_nextParaIndex++; if (m_nextParaIndex == m_nParas) { m_nextPara = -1; } else { m_nextPara += m_ParaOffsets[m_nextParaIndex]; } } */ } bool CPlucker_base::expand(int thisrec) { mystyle.unset(); if (bufferrec != thisrec) { size_t reclen = recordlength(thisrec); gotorecordnumber(thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (1) { GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); if (thishdr_type < 2) break; //qDebug("Skipping paragraph of type %d", thishdr_type); if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; reclen = recordlength(thisrec); gotorecordnumber(thisrec); } m_nParas = thishdr_nParagraphs; m_bufferisreserved = (thishdr_reserved != 0); //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); uid = thishdr_uid; // gotorecordnumber(thisrec); // fread(expandedtextbuffer,1,10,fin); for (int i = 0; i < m_nParas; i++) { UInt16 ubytes, attrs; fread(&ubytes, 1, sizeof(ubytes), fin); fread(&attrs, 1, sizeof(attrs), fin); m_ParaOffsets[i] = ntohs(ubytes); m_ParaAttrs[i] = ntohs(attrs); // //qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); } reclen -= HeaderSize()+4*m_nParas; buffercontent = thishdr_size; if (thishdr_size > buffersize) { delete [] expandedtextbuffer; buffersize = thishdr_size; expandedtextbuffer = new UInt8[buffersize]; } Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); bufferrec = thisrec; } if (m_nParas > 0) { m_nextPara = m_ParaOffsets[0]; //qDebug("First offset = %u", m_nextPara); m_nextParaIndex = 0; } @@ -978,434 +976,433 @@ linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& QMessageBox::information(NULL, QString(PROGNAME), QString("Mailto links\nnot yet supported (2)")); } else { if (thishdr_type > 3 && thishdr_type != 15) { QMessageBox::information(NULL, QString(PROGNAME), QString("External links\nnot yet supported (2)") ); return eNone; } else { #ifdef LOCALPICTURES showimg(tuid); #else return ePicture; #endif } } return eNone; } /* if (thishdr_type == 2 || thishdr_type == 3) { expandimg(thisrec); } */ else { expand(thisrec); unsigned int paraoffset = offset; // unsigned int noff = 0; if (n != 0) { if (n >= m_nParas) { QMessageBox::information(NULL, QString(PROGNAME), QString("Error in link\nPara # too big") ); return eNone; } unsigned int noff = 0; for (unsigned int i = 0; i < n; i++) noff += m_ParaOffsets[i]; paraoffset += noff; } if (paraoffset > thishdr_size) { QMessageBox::information(NULL, QString(PROGNAME), QString("Error in link\nOffset too big") ); return eNone; } while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true); //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos); /* // This is faster but the alignment doesn't get set mystyle.unset(); bufferpos = n; currentpos += n; while (bufferpos >= m_nextPara && m_nextPara >= 0) { UInt16 attr = m_ParaAttrs[m_nextParaIndex]; m_nextParaIndex++; if (m_nextParaIndex == m_nParas) { m_nextPara = -1; } else { m_nextPara += m_ParaOffsets[m_nextParaIndex]; } } */ } return eLink; } tchar CPlucker_base::getch_base(bool fast) { int ch = bgetch(); while (ch == 0) { ch = bgetch(); // //qDebug("Function:%x", ch); switch (ch) { case 0x38: // //qDebug("Break:%u", locate()); if (m_lastBreak == locate()) { ch = bgetch(); } else { ch = 10; } m_lastBreak = locate(); break; case 0x0a: case 0x0c: { unsigned long ln = 0; int skip = ch & 7; for (int i = 0; i < 2; i++) { int ch = bgetch(); ln = (ln << 8) + ch; // //qDebug("ch:%d, ln:%u", ch, ln); } if (skip == 2) { ln <<= 16; } else { for (int i = 0; i < 2; i++) { int ch = bgetch(); ln = (ln << 8) + ch; // //qDebug("ch:%d, ln:%u", ch, ln); } } // //qDebug("ln:%u", ln); mystyle.setLink(true); mystyle.setData(ln); // mystyle.setColour(255, 0, 0); bool hasseen = false; for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) { if (*it == ln) { hasseen = true; break; } } if (hasseen) { mystyle.setStrikethru(); } else { mystyle.setUnderline(); } mystyle.setOffset(m_offset); m_offset = 0; ch = bgetch(); } break; case 0x08: ch = bgetch(); // mystyle.setColour(0, 0, 0); mystyle.unsetUnderline(); mystyle.unsetStrikethru(); mystyle.setLink(false); mystyle.setData(0); break; case 0x40: mystyle.setItalic(); ch = bgetch(); break; case 0x48: mystyle.unsetItalic(); ch = bgetch(); break; case 0x11: { ch = bgetch(); // //qDebug("Font:%d",ch); mystyle.setVOffset(0); mystyle.unsetMono(); mystyle.unsetBold(); switch (ch) { case 0: mystyle.setFontSize(0); break; case 1: mystyle.setFontSize(3); mystyle.setBold(); break; case 2: mystyle.setFontSize(2); mystyle.setBold(); break; case 3: mystyle.setFontSize(1); mystyle.setBold(); break; case 4: mystyle.setFontSize(0); mystyle.setBold(); break; case 5: mystyle.setFontSize(0); mystyle.setBold(); break; case 6: mystyle.setFontSize(0); mystyle.setBold(); break; case 7: mystyle.setFontSize(0); mystyle.setBold(); break; case 8: // should be fixed width //qDebug("Trying fixed width"); mystyle.setFontSize(0); mystyle.setMono(); break; case 9: // mystyle.setFontSize(mystyle.getFontSize()); mystyle.setFontSize(-1); break; case 10: mystyle.setFontSize(-2); mystyle.setVOffset(1); break; case 11: mystyle.setFontSize(-2); mystyle.setVOffset(-1); break; default: qDebug("Unrecognised font"); break; } ch = bgetch(); } break; case 0x29: ch = bgetch(); switch (ch) { case 0: mystyle.setLeftJustify(); // //qDebug("left"); break; case 1: mystyle.setRightJustify(); // //qDebug("right"); break; case 2: mystyle.setCentreJustify(); // //qDebug("centre"); break; case 3: mystyle.setFullJustify(); // //qDebug("full"); break; } ch = bgetch(); break; case 0x53: { int r = bgetch(); int g = bgetch(); int b = bgetch(); mystyle.setColour(r,g,b); ch = bgetch(); } break; case 0x1a: case 0x5c: { bool hasalternate = (ch == 0x5c); UInt16 ir = bgetch(); ir = (ir << 8) + bgetch(); if (hasalternate) { //qDebug("Alternate image:%x", ir); UInt16 ir2 = bgetch(); ir2 = (ir2 << 8) + bgetch(); if (!fast) mystyle.setPicture(true, expandimg(ir2, true), true, ir << 16); #ifdef LOCALPICTURES UInt32 ln = ir; ln <<= 16; mystyle.setLink(true); mystyle.setData(ln); #endif } else { if (!fast) mystyle.setPicture(true, expandimg(ir)); } // if (mystyle.getLink()) qDebug("Picture link!"); ch = '#'; } // ch = bgetch(); break; case 0x33: { UInt8 h = bgetch(); UInt8 wc = bgetch(); UInt8 pc = bgetch(); UInt16 w = wc; // //qDebug("h,w,pc [%u, %u, %u]", h, w, pc); if (w == 0) { w = (m_scrWidth*(unsigned long)pc)/100; } if (w == 0) w = m_scrWidth; mystyle.setPicture(false, hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue())); // if (mystyle.getLink()) //qDebug("hRule link!"); ch = '#'; } break; case 0x60: mystyle.setUnderline(); ch = bgetch(); break; case 0x68: mystyle.unsetUnderline(); ch = bgetch(); break; case 0x22: ch = bgetch(); mystyle.setLeftMargin(ch); // //qDebug("Left margin:%d", ch); ch = bgetch(); mystyle.setRightMargin(ch); // //qDebug("Right margin:%d", ch); ch = bgetch(); break; case 0x70: mystyle.setStrikethru(); ch = bgetch(); break; case 0x78: mystyle.unsetStrikethru(); ch = bgetch(); break; case 0x83: { int tlen = bgetch(); ch = bgetch(); ch <<= 8; ch |= (tchar)bgetch(); for (int i = 0; i < tlen; i++) bgetch(); //qDebug("Function 83"); } break; case 0x9a: { m_offset = 255*bgetch(); m_offset += bgetch(); qDebug("Found offset:%u", m_offset); ch = bgetch(); } break; case 0x85: default: qDebug("Function:%x NOT IMPLEMENTED", ch); { int skip = ch & 7; for (int i = 0; i < skip; i++) { ch = bgetch(); //qDebug("Arg %d, %d", i, ch); } ch = bgetch(); } } } if (m_lastIsBreak && !mystyle.isMono()) { while (ch == ' ') { ch = getch(false); } } m_lastIsBreak = (ch == 10); return (ch == EOF) ? UEOF : ch; } -#include "static.h" #if defined(__STATIC) && defined(USENEF) #include "Model.h" void (*CPlucker_base::getdecompressor(const QString& _s))(UInt8*, size_t, UInt8*, size_t) { if (_s == "PluckerDecompress3") { return PluckerDecompress3; } if (_s == "PluckerDecompress4") { return PluckerDecompress4; } return NULL; } #else #include "qfileinfo.h" #include <dlfcn.h> void (*CPlucker_base::getdecompressor(const QString& _s))(UInt8*, size_t, UInt8*, size_t) { QString codecpath(QTReaderUtil::getPluginPath("support")); codecpath += "/libpluckerdecompress.so"; qDebug("Codec:%s", (const char*)codecpath); if (QFile::exists(codecpath)) { qDebug("Codec:%s", (const char*)codecpath); void* handle = dlopen(codecpath, RTLD_LAZY); if (handle == 0) { qDebug("Can't find codec:%s", dlerror()); return NULL; } return (void (*)(UInt8*, size_t, UInt8*, size_t))dlsym(handle, _s); } return NULL; } #endif QString CPlucker_base::about() { QString abt = "Plucker base codec (c) Tim Wentford"; if (m_decompress != UnDoc && m_decompress != UnZip) { abt += "\nSpecial decompression (c) Tim Wentford"; } return abt; } diff --git a/noncore/apps/opie-reader/pluckerbaselib/pluckerbaselib.pro b/noncore/apps/opie-reader/pluckerbaselib/pluckerbaselib.pro index bee1a2d..7c2f31e 100644 --- a/noncore/apps/opie-reader/pluckerbaselib/pluckerbaselib.pro +++ b/noncore/apps/opie-reader/pluckerbaselib/pluckerbaselib.pro @@ -1,18 +1,18 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = pdb.h \ util.h SOURCES = plucker_base.cpp INTERFACES = DESTDIR = $(OPIEDIR)/lib TARGET = reader_pluckerbase LIBS += -ldl -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/ppm_expander.cpp b/noncore/apps/opie-reader/ppm_expander.cpp index ea5b955..2a4318b 100644 --- a/noncore/apps/opie-reader/ppm_expander.cpp +++ b/noncore/apps/opie-reader/ppm_expander.cpp @@ -1,116 +1,115 @@ /* * Interface pour le programme de compression * (c) 1995 Fabrice Bellard */ #include <stdlib.h> //#include <unistd.h> #include <stdio.h> #include <string.h> #include <time.h> -#include "static.h" /*************************************************************************** * Interface avec les routines de compression */ #define METHOD_NB 2 /* nombre total de méthodes de compression */ #define METHOD_STORE 0 #define METHOD_PPM 1 #define DEFAULT_SUFFIX ".st" /* extension par défault */ /* signature en début de fichier */ #define STAT_MAGIC_SIZE 4 char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'}; #include "ppm_expander.h" ppm_expander::~ppm_expander() { if (needppmend) ppm.PPM_End(); ppm.arith.Arith_DecodeEnd(); if (buf_in!=NULL) delete [] buf_in; if (buf_out!=NULL) delete [] buf_out; if (my_read_buf != NULL) delete my_read_buf; if (my_file_in != NULL) fclose(my_file_in); } int ppm_expander::OpenFile(const char* infile) { my_file_in=fopen(infile,"rb"); my_read_buf = new PPM_ReadBuf(my_file_in); return home(); } void ppm_expander::sizes(unsigned long& file, unsigned long& text) { struct stat _stat; fstat(fileno(my_file_in),&_stat); file = _stat.st_size; text = numblocks*blocksize; } int ppm_expander::home() { fseek(my_file_in,0, SEEK_SET); unsigned char header[STAT_MAGIC_SIZE]; size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in); if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) { return 1; } if (len!=(STAT_MAGIC_SIZE)) { return 1; } if (fread(&maxnode,sizeof(maxnode),1,my_file_in) != 1) return 1; if (fread(&blocksize,sizeof(blocksize),1,my_file_in) != 1) return 1; if (fread(&numblocks,sizeof(numblocks),1,my_file_in) != 1) return 1; //fprintf(stderr,"<%u,%u,%u>\n",maxnode,blocksize,numblocks); locate(0,0); outbytes = 0; return 0; } void ppm_expander::locate(unsigned int n) { locate(n/blocksize, n%blocksize); outbytes = n; } void ppm_expander::locate(unsigned short block, unsigned int n) { if (needppmend) { ppm.PPM_End(); needppmend = false; } size_t fpos; fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET); fread(&fpos,sizeof(fpos),1,my_file_in); fseek(my_file_in,fpos,SEEK_SET); ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize); int err=ppm.PPM_Init(maxnode); needppmend = true; curblock = block; for (int i = 0; i < n; i++) getch(); } int ppm_expander::getch() { if (curblock >= numblocks) return EOF; int c=ppm.PPM_Decode(); if (c == SYM_EOF) { if (++curblock >= numblocks) return EOF; locate(curblock,0); c = ppm.PPM_Decode(); } outbytes++; return (c==SYM_EOF) ? EOF : c; } #ifndef __STATIC extern "C" { CExpander* newcodec() { return new ppm_expander; } } #endif diff --git a/noncore/apps/opie-reader/ppm_expander.h b/noncore/apps/opie-reader/ppm_expander.h index a1a3b60..ccc89c2 100644 --- a/noncore/apps/opie-reader/ppm_expander.h +++ b/noncore/apps/opie-reader/ppm_expander.h @@ -1,62 +1,61 @@ #ifndef __ppm_expander_h #define __ppm_expander_h -#include "useqpe.h" #include "CExpander.h" #include <sys/stat.h> #include "utypes.h" #include "ppm.h" #include "arith.h" #define SYM_EOF 256 class ppm_expander : public CExpander { UCHAR *buf_in,*buf_out; unsigned int bufsize; unsigned int outbytes; unsigned long blocksize; unsigned short numblocks; unsigned short curblock; unsigned short maxnode; bool needppmend; int home(); FILE* my_file_in; PPM_ReadBuf* my_read_buf; ppm_worker ppm; public: QString about() { return QString("ppms Codec (c) Tim Wentford\nCompression code (c) Fabrice Bellard"); } #ifdef USEQPE void suspend() { CExpander::suspend(my_file_in); } void unsuspend() { CExpander::unsuspend(my_file_in); } #endif ppm_expander() : needppmend(false), my_file_in(NULL), my_read_buf(NULL) { bufsize = 1024; buf_in = new UCHAR[bufsize]; buf_out = new UCHAR[bufsize]; outbytes = 0; } int OpenFile(const char* infile); int getch(); void locate(unsigned short block, unsigned int n); virtual ~ppm_expander(); unsigned int locate() { return outbytes; } void locate(unsigned int n); bool hasrandomaccess() { return (numblocks > 1); } void sizes(unsigned long& file, unsigned long& text); MarkupType PreferredMarkup() { return cTEXT; } }; #endif diff --git a/noncore/apps/opie-reader/ppmsCodec/ppmsCodec.pro b/noncore/apps/opie-reader/ppmsCodec/ppmsCodec.pro index 8699d3b..d6ec97b 100644 --- a/noncore/apps/opie-reader/ppmsCodec/ppmsCodec.pro +++ b/noncore/apps/opie-reader/ppmsCodec/ppmsCodec.pro @@ -1,19 +1,19 @@ DEFINES += OPIE USEQPE VPATH = .. TEMPLATE = lib CONFIG = qt warn_on release dll HEADERS = Aportis.h SOURCES = ppm_expander.cpp \ ppm.cpp \ arith_d.cpp INTERFACES = DESTDIR = $(OPIEDIR)/plugins/reader/codecs TARGET = ppms LIBS += -lreader_codec -INCLUDEPATH += ../OREADERINC $(OPIEDIR)/include -DEPENDPATH += ../OREADERINC $(OPIEDIR)/include +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/opie-reader/preferences.cpp b/noncore/apps/opie-reader/preferences.cpp index b9397cf..0f59a22 100755 --- a/noncore/apps/opie-reader/preferences.cpp +++ b/noncore/apps/opie-reader/preferences.cpp @@ -1,105 +1,104 @@ -#include "useqpe.h" #ifndef USEQPE #include "preferences.h" #include <qfile.h> #include <qtextstream.h> Config::Config(const QString& _fn) : fname(_fn) { // qDebug("Config::Config:%s", (const char*)fname); QFile fl(fname); if (fl.open(IO_ReadOnly)) { QTextStream t(&fl); QString key, value; while (!t.eof()) { QString data = t.readLine(); int colon = data.find(':'); if (colon > 0) { QString key = data.left(colon); QString value = data.right(data.length()-colon-1); values[key] = value; } } fl.close(); } // read entries into values } Config::~Config() { // qDebug("Config::~Config:%s", (const char*)fname); QFile fl(fname); if (fl.open(IO_WriteOnly)) { QTextStream t(&fl); for (QMap<QString,QString>::Iterator iter = values.begin(); iter != values.end(); iter++) { t << iter.key() << ':' << iter.data() << '\n'; } fl.close(); } } QString Config::readEntry(const QString& key, const QString& deflt) { QMap<QString,QString>::Iterator iter = values.find(key); if (iter != values.end()) { return iter.data(); } else { return deflt; } } bool Config::readBoolEntry(const QString& key, const bool deflt) { bool ok; QMap<QString,QString>::Iterator iter = values.find(key); if (iter != values.end()) { int ret = iter.data().toInt(&ok); return ((ok) ? !!ret : deflt); } else { return deflt; } } int Config::readNumEntry(const QString& key, const int deflt) { bool ok; QMap<QString,QString>::Iterator iter = values.find(key); if (iter != values.end()) { int ret = iter.data().toInt(&ok); return ((ok) ? ret : deflt); } else { return deflt; } } void Config::writeEntry(const QString& key, const QString& value) { values[key] = value; } void Config::writeEntry(const QString& key, const bool value) { values[key] = (value) ? "1" : "0"; } void Config::writeEntry(const QString& key, const int value) { QString rhs; rhs.setNum(value); values[key] = rhs; } #endif diff --git a/noncore/apps/opie-reader/preferences.h b/noncore/apps/opie-reader/preferences.h index 69d1774..aeb2a84 100644 --- a/noncore/apps/opie-reader/preferences.h +++ b/noncore/apps/opie-reader/preferences.h @@ -1,27 +1,26 @@ -#include "useqpe.h" #ifndef USEQPE #ifndef __PREFERENCES_H #define __PREFERENCES_H #include <qstring.h> #include <qmap.h> class Config { QMap<QString, QString> values; QString fname; public: Config(const QString& fname); ~Config();
void setGroup(const QString& s) { } QString readEntry(const QString&, const QString&); bool readBoolEntry(const QString&, const bool); int readNumEntry(const QString&, const int); void writeEntry(const QString&, const QString&); void writeEntry(const QString&, const bool); void writeEntry(const QString&, const int); }; #endif // PREFERENCES #endif diff --git a/noncore/apps/opie-reader/static.h b/noncore/apps/opie-reader/static.h deleted file mode 100644 index e69de29..0000000 --- a/noncore/apps/opie-reader/static.h +++ b/dev/null diff --git a/noncore/apps/opie-reader/striphtml.cpp b/noncore/apps/opie-reader/striphtml.cpp index 9cd6a0d..e86402b 100644 --- a/noncore/apps/opie-reader/striphtml.cpp +++ b/noncore/apps/opie-reader/striphtml.cpp @@ -1,389 +1,388 @@ #include <qmap.h> #include <qfileinfo.h> #include <qtextstream.h> #include <qdir.h> -#include "useqpe.h" #ifdef USEQPE #include <qpe/global.h> #endif #include "CDrawBuffer.h" #include "striphtml.h" #include "hrule.h" #include "util.h" #include <qregexp.h> #include <qimage.h> #include <qpixmap.h> //#include <qprogressdialog.h> //#include <qapplication.h> static unsigned char h2i(unsigned char c) { unsigned char ret = 0; if ('0' <= c && c <= '9') { ret = c - '0'; } else if ('a' <= c && c <= 'f') { ret = c - 'a' + 10; } return ret; } static void parse_color(const QString& attr, unsigned char& r, unsigned char& g, unsigned char& b) { r = g = b = 0; if (attr.length() >= 7 && attr[0] == '#') { r = h2i(attr[1].unicode()); r = 16*r + h2i(attr[2].unicode()); g = h2i(attr[3].unicode()); g = 16*g + h2i(attr[4].unicode()); b = h2i(attr[5].unicode()); b = 16*b + h2i(attr[6].unicode()); } else if (attr == "red") { r = 255; } else if (attr == "green") { g = 255; } else if (attr == "blue") { b = 255; } else if (attr == "white") { r = g = b = 255; } else if (attr == "black") { r = g = b = 0; } else { qDebug("Don't understand colour \"%s\"", (const char*)attr); } } CNavigation_base<htmlmark> striphtml::m_nav; void striphtml::skipblock(const QString& _ent) { tchar ch = '>'; CStyle dummy; QString ent; unsigned long pos; do { while (ch != '<' && ch != UEOF) { mygetch(ch, dummy, pos); } ch = skip_ws(); ent = getname(ch, " >").lower(); qDebug("Skipblock:%s", (const char*)ent); } while (ent != _ent && ch != UEOF); } void striphtml::locate(unsigned int n) { m_inblock = false; text_q = ""; forcecentre = false; ignorespace = false; while (!stylestack.isEmpty()) stylestack.pop(); currentstyle.unset(); qDebug("striphtml:locating:%u", n); parent->locate(n); } int striphtml::getpara(CBuffer& buff, unsigned long& startpos) { tchar ch; CStyle sty; unsigned long pos; int i = 0; parent->getch(ch, sty, startpos); pos = startpos; while (1) { if (ch == 10 && !isPre) { ch = ' '; } if (ch == UEOF) { // qDebug("EOF:%d:%u", i, pos); buff[i] = 0; if (i == 0) { i = -1; } return i; } else if (ch == '<') { tchar ch2 = skip_ws(); QString ent = getname(ch2, " >"); ent = ent.lower(); // qDebug("ent:%s", (const char*)ent); if (ent == "a") { buff[i++] = '<'; buff[i++] = 'a'; buff[i++] = ch2; // buff[i] = 0; qDebug("ANCHOR:%s", (const char*)toQString(buff.data())); } else if (ent == "/a") { buff[i++] = '<'; buff[i++] = '/'; buff[i++] = 'a'; buff[i++] = ch2; // buff[i] = 0; qDebug("/ANCHOR:%s", (const char*)toQString(buff.data())); } else if (ent == "div") { // buff[i] = 0; qDebug("DIV:%s", (const char*)toQString(buff.data())); if (i == 0) { buff[i++] = '<'; buff[i++] = 'd'; buff[i++] = 'i'; buff[i++] = 'v'; buff[i++] = ' '; buff[i++] = ch2; while (ch2 != '>' && ch2 != UEOF && i < 2048) { parent->getch(ch2, sty, pos); buff[i++] = ch2; } } else { locate(pos); } buff[i++] = 0; // qDebug("DIV:%s", (const char*)toQString(buff.data())); return i; } else if (ent == "p" || (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1)) { buff[i++] = 0; while (ch2 != '>' && ch2 != UEOF) { parent->getch(ch2, sty, pos); } return i; } else { while (ch2 != '>' && ch2 != UEOF) { parent->getch(ch2, sty, pos); } } } else { buff[i++] = ch; } parent->getch(ch, sty, pos); } } QString striphtml::dehtml(const QString& _info) { QString info; for (int i = 0; i < _info.length(); i++) { tchar ch = _info[i]; if (ch == '%') { ch = 0; for (int j = 0; j < 2; j++) { ch <<= 4; tchar ch1 = _info[++i]; if ('0' <= ch1 && ch1 <= '9') { ch += ch1 - '0'; } else if ('a' <= ch1 && ch1 <= 'f') { ch += ch1 - 'a' + 10; } else if ('A' <= ch1 && ch1 <= 'F') { ch += ch1 - 'A' + 10; } } } info += ch; } return info; } bool striphtml::findanchor(const QString& _info) { // QProgressDialog dlg("Finding link...", QString::null, 0, NULL, "progress", true); // QProgressBar dlg(0); #if defined(USEQPE) || defined(_WINDOWS) QString info; for (int i = 0; i < _info.length(); i++) { tchar ch = _info[i]; if (QString(".^$[]*+?").find(ch) != -1) { info += '\\'; } info += ch; } #else QString info = QRegExp::escape(_info); #endif qDebug("Adjusted searchstring:%s", (const char*)info); QString sname("<[Aa][^>]*[ \t]+[Nn][Aa][Mm][Ee][ \t]*=[ \t]*\"?"); sname += info + "\"?[ \t>]"; QString sid("<[A-Za-z][^>]*[ \t]+[Ii][Dd][ \t]*=[ \t]*\"?"); sid += info+"\"?[ \t>]"; #ifdef USEQPE QRegExp name(sname); QRegExp id(sid); #else QRegExp name(sname+"|"+sid); #endif bool ret = true; locate(0); unsigned long pos = 0; unsigned long startpos = 0; int offset; CBuffer test; qDebug("striphtml::findanchor"); // dlg.show(); if (getpara(test, pos) >= 0) { while (1) { // qApp->processEvents(); if ((offset = name.match(toQString(test.data()))) != -1) break; #ifdef USEQPE if ((offset = id.match(toQString(test.data()))) != -1) break; #endif if (getpara(test, pos) < 0) { locate(startpos); qDebug("Not found"); return false; } } locate(pos); qDebug("Found"); ret = true; } else { locate(startpos); qDebug("Not found"); ret = false; } return ret; } striphtml::striphtml(const QString& _s) : entmap(NULL), isPre(false), currentid(0), lastch(0), currentfile(_s), indent(0), forcecentre(false), m_inblock(false), m_bchm(false), ignorespace(false) { href2filepos = new QMap<QString, unsigned long>; id2href = new QMap<unsigned long, QString>; } striphtml::~striphtml() { if (entmap != NULL) delete entmap; delete href2filepos; delete id2href; } void striphtml::initentmap() { entmap = new QMap<QString, tchar>; QString fname(QTReaderUtil::getPluginPath("data")); QFileInfo fi; fi.setFile(fname, "HTMLentities"); if (fi.exists()) { fname = fi.absFilePath(); QFile fl(fname); if (fl.open(IO_ReadOnly)) { QTextStream t(&fl); QString key, value; while (!t.eof()) { QString data = t.readLine(); int colon = data.find(':'); if (colon > 0) { QString key = data.left(colon); QString value = data.right(data.length()-colon-1); bool ok; int ret = value.toInt(&ok); if (ok) { (*entmap)[key] = ret; } } } fl.close(); } } } unsigned short striphtml::skip_ws() { tchar ch; CStyle sty; unsigned long dummy; do { mygetch(ch, sty, dummy); } while (ch < 33 && ch != UEOF); return ch; } unsigned short striphtml::skip_ws_end() { unsigned long dummy; return skip_ws_end(dummy); } unsigned short striphtml::skip_ws_end(unsigned long& pos) { tchar ch; CStyle sty; do { mygetch(ch, sty, pos); } while (ch != '>' && ch != UEOF); return ch; } QString striphtml::getname(tchar& ch, const QString& nd) { QString nm = ""; // nm += ch; CStyle sty; unsigned long dummy; while (1) { // if ( QChar(ch).isLetterOrNumber() ) if (ch != UEOF && nd.find(ch, 0, false) == -1 && nm.length() < 2048) { diff --git a/noncore/apps/opie-reader/useqpe.h b/noncore/apps/opie-reader/useqpe.h deleted file mode 100644 index e69de29..0000000 --- a/noncore/apps/opie-reader/useqpe.h +++ b/dev/null diff --git a/noncore/apps/opie-reader/ztxt.cpp b/noncore/apps/opie-reader/ztxt.cpp index 79c5fa4..35db05e 100644 --- a/noncore/apps/opie-reader/ztxt.cpp +++ b/noncore/apps/opie-reader/ztxt.cpp @@ -1,174 +1,173 @@ #include <stdio.h> #include <string.h> #include "ztxt.h" #include "my_list.h" #include "Bkmks.h" -#include "static.h" ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } int ztxt::OpenFile(const char *src) { if (!Cpdb::openpdbfile(src)) { return -1; } //printf("Okay %u\n", 4); if (head.type != ZTXT_ID) return -1; gotorecordnumber(0); fread(&hdr0, 1, sizeof(hdr0), fin); //printf("Okay %u\n", 5); buffersize = ntohl(hdr0.size); compressedtextbuffer = new UInt8[buffersize]; expandedtextbuffer = new UInt8[buffersize]; //printf("Okay %u\n", 6); home(); //printf("Okay %u\n", 7); // printf("Returning 0\n"); return 0; } int ztxt::getch() { if (bufferpos >= buffercontent) { size_t reclen = recordlength(++bufferrec); if (reclen == 0) return -1; gotorecordnumber(bufferrec); fread(compressedtextbuffer, reclen, sizeof(char), fin); zstream.next_in = compressedtextbuffer; zstream.next_out = expandedtextbuffer; zstream.avail_out = buffersize; zstream.avail_in = reclen; int ret = inflate(&zstream, Z_SYNC_FLUSH); buffercontent = buffersize - zstream.avail_out; bufferpos = 0; } currentpos++; return expandedtextbuffer[bufferpos++]; } unsigned int ztxt::locate() { return currentpos; } void ztxt::locate(unsigned int n) { if (hasrandomaccess()) { bufferrec = n / ntohs(hdr0.recordSize) + 1; if (bufferrec == 1) { inflateEnd(&zstream); } size_t reclen = recordlength(bufferrec); if (reclen == 0) return; gotorecordnumber(bufferrec); fread(compressedtextbuffer, reclen, sizeof(char), fin); zstream.next_in = compressedtextbuffer; zstream.next_out = expandedtextbuffer; zstream.avail_out = buffersize; zstream.avail_in = reclen; if (bufferrec == 1) { zstream.zalloc = Z_NULL; zstream.zfree = Z_NULL; zstream.opaque = Z_NULL; inflateInit(&zstream); } int ret = inflate(&zstream, Z_SYNC_FLUSH); buffercontent = buffersize - zstream.avail_out; bufferpos = 0; currentpos = n - n % ntohs(hdr0.recordSize); while (currentpos < n) getch(); } else { home(); while (currentpos < n && getch() != EOF); } } void ztxt::home() { if (bInit) { inflateEnd(&zstream); } bInit = true; size_t reclen = recordlength(1); gotorecordnumber(1); fread(compressedtextbuffer, reclen, sizeof(char), fin); zstream.next_in = compressedtextbuffer; zstream.next_out = expandedtextbuffer; zstream.avail_out = buffersize; zstream.avail_in = reclen; zstream.zalloc = Z_NULL; zstream.zfree = Z_NULL; zstream.opaque = Z_NULL; // printf("Initialising\n"); inflateInit(&zstream); int ret = inflate(&zstream, Z_SYNC_FLUSH); // printf("Inflate : %d\n", ret); bufferpos = 0; bufferrec = 1; currentpos = 0; buffercontent = buffersize - zstream.avail_out; // printf("buffercontent:%u\n", buffercontent); } CList<Bkmk>* ztxt::getbkmklist() { UInt16 recno = ntohs(hdr0.bookmarkRecord); // printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks)); if (recno == 0) return NULL; CList<Bkmk>* t = new CList<Bkmk>; size_t cur = ftell(fin); gotorecordnumber(recno); for (int i = 0; i < ntohs(hdr0.numBookmarks); i++) { zTXTbkmk bkmk; if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; // printf("Bookmark number:%d:%.20s\n", i, bkmk.title); tchar title[MAX_BMRK_LENGTH]; for (int j = 0; j < MAX_BMRK_LENGTH; j++) { title[j] = bkmk.title[j]; } t->push_back(Bkmk(title, NULL, ntohl(bkmk.offset))); } fseek(fin, cur, SEEK_SET); return t; } #ifndef __STATIC extern "C" { CExpander* newcodec() { return new ztxt; } } #endif |